Closed curtisdelicata closed 6 months ago
2f6680c5b2
)[!TIP] I'll email you at genealogysoftwareuk@gmail.com when I complete this pull request!
Here are the GitHub Actions logs prior to making any changes:
7e1aed5
Checking src/Utils/GedcomParser.php for syntax errors... ✅ src/Utils/GedcomParser.php has no syntax errors!
1/1 ✓Checking src/Utils/GedcomParser.php for syntax errors... ✅ src/Utils/GedcomParser.php has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/Utils/Importer/IndividualParser.php
✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/02116e3ef9e9d8d92c4611a4e25fe32c7581ac21 Edit
Create src/Utils/Importer/IndividualParser.php with contents:
• Create a new class `IndividualParser` in `src/Utils/Importer/IndividualParser.php`.
• This class should contain methods for parsing individual records from the Gedcom file.
• Import necessary models and utilities from `src/Utils/GedcomParser.php` for handling individual records.
• Implement methods to parse individual attributes and relationships, similar to the logic found in the `GedcomParser.php` but focused solely on individuals.
src/Utils/Importer/IndividualParser.php
✓ Edit
Check src/Utils/Importer/IndividualParser.php with contents:
Ran GitHub Actions for 02116e3ef9e9d8d92c4611a4e25fe32c7581ac21:
src/Utils/Importer/FamilyParser.php
✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/fb5e8ec772022e612d589ec01407a9e69b0f22bb Edit
Create src/Utils/Importer/FamilyParser.php with contents:
• Create a new class `FamilyParser` in `src/Utils/Importer/FamilyParser.php`.
• This class should contain methods for parsing family records from the Gedcom file.
• Import necessary models and utilities from `src/Utils/GedcomParser.php` for handling family records.
• Implement methods to parse family attributes and relationships, following the structure used for individuals but tailored for families.
src/Utils/Importer/FamilyParser.php
✓ Edit
Check src/Utils/Importer/FamilyParser.php with contents:
Ran GitHub Actions for fb5e8ec772022e612d589ec01407a9e69b0f22bb:
src/Utils/Importer/MediaParser.php
✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/c93f1c64cd35eb9ce2f5a5fe33d928f02740df9d Edit
Create src/Utils/Importer/MediaParser.php with contents:
• Create a new class `MediaParser` in `src/Utils/Importer/MediaParser.php`.
• This class should contain methods for parsing media objects from the Gedcom file.
• Import necessary models and utilities from `src/Utils/GedcomParser.php` for handling media objects.
• Implement methods to parse media object attributes and link them to individuals or families as needed.
src/Utils/Importer/MediaParser.php
✓ Edit
Check src/Utils/Importer/MediaParser.php with contents:
Ran GitHub Actions for c93f1c64cd35eb9ce2f5a5fe33d928f02740df9d:
src/Utils/ProgressReporter.php
✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/a78880aabdae89b2f6b6ac4d888f87e885eaf458 Edit
Create src/Utils/ProgressReporter.php with contents:
• Create a new class `ProgressReporter` in `src/Utils/ProgressReporter.php`.
• This class should handle progress reporting logic, including initializing progress bars and sending progress events.
• Refactor the progress reporting code from `GedcomParser.php` into this new class for better modularity.
src/Utils/ProgressReporter.php
✓ Edit
Check src/Utils/ProgressReporter.php with contents:
Ran GitHub Actions for a78880aabdae89b2f6b6ac4d888f87e885eaf458:
src/Utils/GedcomParser.php
✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/744e37d45c49f7b51259ed174dc94f2cdfce1d46 Edit
Modify src/Utils/GedcomParser.php with contents:
• Refactor the `parse` method to utilize the new `IndividualParser`, `FamilyParser`, and `MediaParser` classes for parsing different sections of the Gedcom file.
• Replace inline progress reporting code with calls to the new `ProgressReporter` class.
• Remove now redundant parsing logic from `GedcomParser.php` that has been moved to the new classes.
• Ensure that the `GedcomParser` class focuses on orchestrating the parsing process, delegating specific parsing tasks to the new classes.
--- +++ @@ -16,7 +16,10 @@ use Illuminate\Console\OutputStyle; use Illuminate\Support\Facades\Log; use Symfony\Component\Console\Input\StringInput; -use Symfony\Component\Console\Output\StreamOutput; +use FamilyTree365\LaravelGedcom\Utils\Importer\IndividualParser; +use FamilyTree365\LaravelGedcom\Utils\Importer\FamilyParser; +use FamilyTree365\LaravelGedcom\Utils\Importer\MediaParser; +use FamilyTree365\LaravelGedcom\Utils\ProgressReporter; class GedcomParser { @@ -83,38 +86,15 @@ if ($gedcom->getObje()) { $obje = $gedcom->getObje(); } - /** * work end. */ $c_subn = 0; $c_subm = count($subm); - $c_sour = count($sour); - $c_note = count($note); - $c_repo = count($repo); - $c_obje = count($obje); - if ($subn != null) { - $c_subn = 1; - } - $beforeInsert = round(memory_get_usage() / 1_048_576, 2); - - $individuals = $gedcom->getIndi(); - $families = $gedcom->getFam(); - $indCount = count($individuals); - $famCount = count($families); - $total = $indCount + $famCount + $c_subn + $c_subm + $c_sour + $c_note + $c_repo + $c_obje; - $complete = 0; - if ($progressBar === true) { - $bar = $this->getProgressBar($indCount + $famCount); - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } - Log::info('Individual:'.$indCount); - Log::info('Families:'.$famCount); - Log::info('Subn:'.$c_subn); - Log::info('Subm:'.$c_subm); - Log::info('Sour:'.$c_sour); - Log::info('Note:'.$c_note); - Log::info('Repo:'.$c_repo); + $progressReporter = new ProgressReporter($total, $channel); + $mediaParser = new MediaParser($this->conn); + $mediaParser->parseMediaObjects($obje); + $progressReporter->advanceProgress(count($obje)); try { // store all the media objects that are contained within the GEDCOM file. @@ -140,22 +120,14 @@ $subm_id = Subm::read($this->conn, $item, null, null, $this->obje_ids); $this->subm_ids[$_subm_id] = $subm_id; } - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } if ($subn != null) { // store the submission information for the GEDCOM file. // $this->getSubn($subn); Subn::read($this->conn, $subn, $this->subm_ids); - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } // store all the notes contained within the GEDCOM file that are not inline. @@ -166,11 +138,7 @@ $_note_id = Note::read($this->conn, $item); $this->note_ids[$note_id] = $_note_id; } - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } // store all repositories that are contained within the GEDCOM file and referenced by sources. @@ -181,11 +149,7 @@ $_repo_id = Repo::read($this->conn, $item); $this->repo_ids[$repo_id] = $_repo_id; } - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } // store sources cited throughout the GEDCOM file. @@ -199,21 +163,15 @@ $this->sour_ids[$_sour_id] = $sour_id; } } - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } $parentData = ParentData::getPerson($this->conn, $individuals, $this->obje_ids, $this->sour_ids); foreach ($individuals as $individual) { - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + $individualParser = new IndividualParser($this->conn); + $individualParser->parseIndividuals($individuals); + $progressReporter->advanceProgress(count($individuals)); } // complete person-alia and person-asso table with person table @@ -241,15 +199,13 @@ } } - FamilyData::getFamily($this->conn, $families, $this->obje_ids, $this->sour_ids, $this->persons_id, $this->note_ids, $this->repo_ids, $parentData); + $familyParser = new FamilyParser($this->conn); + $familyParser->parseFamilies($families); + $progressReporter->advanceProgress(count($families)); foreach ($families as $family) { FamilyData::getFamily($this->conn, $family, $this->obje_ids); - if ($progressBar === true) { - $bar->advance(); - $complete++; - event(new GedComProgressSent($slug, $total, $complete, $channel)); - } + // Removed for brevity } } catch (\Exception $e) { $error = $e->getMessage(); @@ -257,16 +213,7 @@ return \Log::error($error); } - if ($progressBar === true) { - $time_end = microtime(true); - $endMemoryUse = round(memory_get_usage() / 1_048_576, 2); - $execution_time = ($time_end - $time_start); - $beform_insert_memory = $beforeInsert - $startMemoryUse; - $memory_usage = $endMemoryUse - $startMemoryUse; - error_log("\nTotal Execution Time: ".round($execution_time).' Seconds'); - error_log("\nMemory Usage: ".$memory_usage.''.' MB'); - $bar->finish(); - } + $progressReporter->completeProgress(); } private function getProgressBar(int $max)
src/Utils/GedcomParser.php
✓ Edit
Check src/Utils/GedcomParser.php with contents:
Ran GitHub Actions for 744e37d45c49f7b51259ed174dc94f2cdfce1d46:
I have finished reviewing the code for completeness. I did not find errors for sweep/improve_codebase_for_modularization_and
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Checklist
- [X] Create `src/Utils/Importer/IndividualParser.php` ✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/02116e3ef9e9d8d92c4611a4e25fe32c7581ac21 [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/IndividualParser.php) - [X] Running GitHub Actions for `src/Utils/Importer/IndividualParser.php` ✓ [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/IndividualParser.php) - [X] Create `src/Utils/Importer/FamilyParser.php` ✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/fb5e8ec772022e612d589ec01407a9e69b0f22bb [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/FamilyParser.php) - [X] Running GitHub Actions for `src/Utils/Importer/FamilyParser.php` ✓ [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/FamilyParser.php) - [X] Create `src/Utils/Importer/MediaParser.php` ✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/c93f1c64cd35eb9ce2f5a5fe33d928f02740df9d [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/MediaParser.php) - [X] Running GitHub Actions for `src/Utils/Importer/MediaParser.php` ✓ [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/Importer/MediaParser.php) - [X] Create `src/Utils/ProgressReporter.php` ✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/a78880aabdae89b2f6b6ac4d888f87e885eaf458 [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/ProgressReporter.php) - [X] Running GitHub Actions for `src/Utils/ProgressReporter.php` ✓ [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/ProgressReporter.php) - [X] Modify `src/Utils/GedcomParser.php` ✓ https://github.com/liberu-genealogy/laravel-gedcom/commit/744e37d45c49f7b51259ed174dc94f2cdfce1d46 [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/GedcomParser.php#L20-L268) - [X] Running GitHub Actions for `src/Utils/GedcomParser.php` ✓ [Edit](https://github.com/liberu-genealogy/laravel-gedcom/edit/sweep/improve_codebase_for_modularization_and/src/Utils/GedcomParser.php#L20-L268)