@@ -31,25 +31,25 @@ |
||
| 31 | 31 | |
| 32 | 32 | interface GedcomRecordFactoriesInterface { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Add (or replace) a factory for a specific type, e.g. 'INDI', 'FAM' ... |
|
| 36 | - */ |
|
| 37 | - public function setFactory(string $type, GedcomRecordFactory $factory): void; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Get an instance of a GedcomRecord object. For single records, |
|
| 41 | - * we just receive the XREF. For bulk records (such as lists |
|
| 42 | - * and search results) we can receive the GEDCOM data as well. |
|
| 43 | - * |
|
| 44 | - * @param string $xref |
|
| 45 | - * @param Tree $tree |
|
| 46 | - * @param string|null $gedcom |
|
| 47 | - * |
|
| 48 | - * @throws Exception |
|
| 49 | - * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
| 50 | - */ |
|
| 51 | - public function getInstance(string $xref, Tree $tree, string $gedcom = null); |
|
| 52 | - |
|
| 53 | - public function clearCache(): void; |
|
| 34 | + /** |
|
| 35 | + * Add (or replace) a factory for a specific type, e.g. 'INDI', 'FAM' ... |
|
| 36 | + */ |
|
| 37 | + public function setFactory(string $type, GedcomRecordFactory $factory): void; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Get an instance of a GedcomRecord object. For single records, |
|
| 41 | + * we just receive the XREF. For bulk records (such as lists |
|
| 42 | + * and search results) we can receive the GEDCOM data as well. |
|
| 43 | + * |
|
| 44 | + * @param string $xref |
|
| 45 | + * @param Tree $tree |
|
| 46 | + * @param string|null $gedcom |
|
| 47 | + * |
|
| 48 | + * @throws Exception |
|
| 49 | + * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
| 50 | + */ |
|
| 51 | + public function getInstance(string $xref, Tree $tree, string $gedcom = null); |
|
| 52 | + |
|
| 53 | + public function clearCache(): void; |
|
| 54 | 54 | |
| 55 | 55 | } |
@@ -29,7 +29,8 @@ |
||
| 29 | 29 | use Fisharebest\Webtrees\Repository; |
| 30 | 30 | use Fisharebest\Webtrees\Source; |
| 31 | 31 | |
| 32 | -interface GedcomRecordFactoriesInterface { |
|
| 32 | +interface GedcomRecordFactoriesInterface |
|
| 33 | +{ |
|
| 33 | 34 | |
| 34 | 35 | /** |
| 35 | 36 | * Add (or replace) a factory for a specific type, e.g. 'INDI', 'FAM' ... |
@@ -24,6 +24,6 @@ |
||
| 24 | 24 | |
| 25 | 25 | interface GedcomRecordFactory { |
| 26 | 26 | |
| 27 | - public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
|
| 27 | + public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -22,7 +22,8 @@ |
||
| 22 | 22 | use Fisharebest\Webtrees\GedcomRecord; |
| 23 | 23 | use Fisharebest\Webtrees\Tree; |
| 24 | 24 | |
| 25 | -interface GedcomRecordFactory { |
|
| 25 | +interface GedcomRecordFactory |
|
| 26 | +{ |
|
| 26 | 27 | |
| 27 | 28 | public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
| 28 | 29 | |
@@ -190,7 +190,7 @@ |
||
| 190 | 190 | |
| 191 | 191 | public static function retrieveGedcomRecord(string $xref, int $tree_id): ?string |
| 192 | 192 | { |
| 193 | - return self::fetchGedcomRecord($xref, $tree_id); |
|
| 193 | + return self::fetchGedcomRecord($xref, $tree_id); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -36,50 +36,50 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | class GedcomRecordFactories implements GedcomRecordFactoriesInterface { |
| 38 | 38 | |
| 39 | - /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
|
| 40 | - protected $gedcom_record_cache; |
|
| 39 | + /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
|
| 40 | + protected $gedcom_record_cache; |
|
| 41 | 41 | |
| 42 | - /** @var stdClass[][] Fetch all pending edits in one database query */ |
|
| 43 | - protected $pending_record_cache; |
|
| 42 | + /** @var stdClass[][] Fetch all pending edits in one database query */ |
|
| 43 | + protected $pending_record_cache; |
|
| 44 | 44 | |
| 45 | - protected $factories = []; |
|
| 45 | + protected $factories = []; |
|
| 46 | 46 | |
| 47 | - public function __construct() { |
|
| 48 | - } |
|
| 47 | + public function __construct() { |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function setFactory(string $type, GedcomRecordFactory $factory): void |
|
| 51 | - { |
|
| 52 | - $this->factories[$type] = $factory; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get an instance of a GedcomRecord object. For single records, |
|
| 57 | - * we just receive the XREF. For bulk records (such as lists |
|
| 58 | - * and search results) we can receive the GEDCOM data as well. |
|
| 59 | - * |
|
| 60 | - * @param string $xref |
|
| 61 | - * @param Tree $tree |
|
| 62 | - * @param string|null $gedcom |
|
| 63 | - * |
|
| 64 | - * @throws Exception |
|
| 65 | - * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
| 66 | - */ |
|
| 67 | - public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
| 50 | + public function setFactory(string $type, GedcomRecordFactory $factory): void |
|
| 51 | + { |
|
| 52 | + $this->factories[$type] = $factory; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get an instance of a GedcomRecord object. For single records, |
|
| 57 | + * we just receive the XREF. For bulk records (such as lists |
|
| 58 | + * and search results) we can receive the GEDCOM data as well. |
|
| 59 | + * |
|
| 60 | + * @param string $xref |
|
| 61 | + * @param Tree $tree |
|
| 62 | + * @param string|null $gedcom |
|
| 63 | + * |
|
| 64 | + * @throws Exception |
|
| 65 | + * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
| 66 | + */ |
|
| 67 | + public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
| 68 | 68 | $tree_id = $tree->id(); |
| 69 | 69 | |
| 70 | 70 | // Is this record already in the cache? |
| 71 | 71 | if (isset($this->gedcom_record_cache[$xref][$tree_id])) { |
| 72 | - return $this->gedcom_record_cache[$xref][$tree_id]; |
|
| 72 | + return $this->gedcom_record_cache[$xref][$tree_id]; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Do we need to fetch the record from the database? |
| 76 | 76 | if ($gedcom === null) { |
| 77 | - $gedcom = GedcomRecord::retrieveGedcomRecord($xref, $tree_id); |
|
| 77 | + $gedcom = GedcomRecord::retrieveGedcomRecord($xref, $tree_id); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // If we can edit, then we also need to be able to see pending records. |
| 81 | 81 | if (Auth::isEditor($tree)) { |
| 82 | - if (!isset($this->pending_record_cache[$tree_id])) { |
|
| 82 | + if (!isset($this->pending_record_cache[$tree_id])) { |
|
| 83 | 83 | // Fetch all pending records in one database query |
| 84 | 84 | $this->pending_record_cache[$tree_id] = []; |
| 85 | 85 | $rows = DB::table('change') |
@@ -90,80 +90,80 @@ discard block |
||
| 90 | 90 | ->get(); |
| 91 | 91 | |
| 92 | 92 | foreach ($rows as $row) { |
| 93 | - $this->pending_record_cache[$tree_id][$row->xref] = $row->new_gedcom; |
|
| 93 | + $this->pending_record_cache[$tree_id][$row->xref] = $row->new_gedcom; |
|
| 94 | + } |
|
| 94 | 95 | } |
| 95 | - } |
|
| 96 | 96 | |
| 97 | - $pending = $this->pending_record_cache[$tree_id][$xref] ?? null; |
|
| 97 | + $pending = $this->pending_record_cache[$tree_id][$xref] ?? null; |
|
| 98 | 98 | } else { |
| 99 | - // There are no pending changes for this record |
|
| 100 | - $pending = null; |
|
| 99 | + // There are no pending changes for this record |
|
| 100 | + $pending = null; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | // No such record exists |
| 104 | 104 | if ($gedcom === null && $pending === null) { |
| 105 | - return null; |
|
| 105 | + return null; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // No such record, but a pending creation exists |
| 109 | 109 | if ($gedcom === null) { |
| 110 | - $gedcom = ''; |
|
| 110 | + $gedcom = ''; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // Create the object |
| 114 | 114 | if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@ (' . Gedcom::REGEX_TAG . ')/', $gedcom . $pending, $match)) { |
| 115 | - $xref = $match[1]; // Collation - we may have requested I123 and found i123 |
|
| 116 | - $type = $match[2]; |
|
| 115 | + $xref = $match[1]; // Collation - we may have requested I123 and found i123 |
|
| 116 | + $type = $match[2]; |
|
| 117 | 117 | } elseif (preg_match('/^0 (HEAD|TRLR)/', $gedcom . $pending, $match)) { |
| 118 | - $xref = $match[1]; |
|
| 119 | - $type = $match[1]; |
|
| 118 | + $xref = $match[1]; |
|
| 119 | + $type = $match[1]; |
|
| 120 | 120 | } elseif ($gedcom . $pending) { |
| 121 | - throw new Exception('Unrecognized GEDCOM record: ' . $gedcom); |
|
| 121 | + throw new Exception('Unrecognized GEDCOM record: ' . $gedcom); |
|
| 122 | 122 | } else { |
| 123 | - // A record with both pending creation and pending deletion |
|
| 124 | - $type = static::RECORD_TYPE; |
|
| 123 | + // A record with both pending creation and pending deletion |
|
| 124 | + $type = static::RECORD_TYPE; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $factory = $this->factories[$type] ?? null; |
| 128 | 128 | if ($factory !== null) { |
| 129 | - $record = $factory->createRecord($xref, $gedcom, $pending, $tree); |
|
| 129 | + $record = $factory->createRecord($xref, $gedcom, $pending, $tree); |
|
| 130 | 130 | |
| 131 | - // Store it in the cache |
|
| 132 | - $this->gedcom_record_cache[$xref][$tree_id] = $record; |
|
| 131 | + // Store it in the cache |
|
| 132 | + $this->gedcom_record_cache[$xref][$tree_id] = $record; |
|
| 133 | 133 | |
| 134 | - return $record; |
|
| 134 | + return $record; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | switch ($type) { |
| 138 | - case Individual::RECORD_TYPE: |
|
| 138 | + case Individual::RECORD_TYPE: |
|
| 139 | 139 | $record = new Individual($xref, $gedcom, $pending, $tree); |
| 140 | - break; |
|
| 140 | + break; |
|
| 141 | 141 | |
| 142 | - case Family::RECORD_TYPE: |
|
| 142 | + case Family::RECORD_TYPE: |
|
| 143 | 143 | $record = new Family($xref, $gedcom, $pending, $tree); |
| 144 | - break; |
|
| 144 | + break; |
|
| 145 | 145 | |
| 146 | - case Source::RECORD_TYPE: |
|
| 146 | + case Source::RECORD_TYPE: |
|
| 147 | 147 | $record = new Source($xref, $gedcom, $pending, $tree); |
| 148 | - break; |
|
| 148 | + break; |
|
| 149 | 149 | |
| 150 | - case Media::RECORD_TYPE: |
|
| 150 | + case Media::RECORD_TYPE: |
|
| 151 | 151 | $record = new Media($xref, $gedcom, $pending, $tree); |
| 152 | - break; |
|
| 152 | + break; |
|
| 153 | 153 | |
| 154 | - case Repository::RECORD_TYPE: |
|
| 154 | + case Repository::RECORD_TYPE: |
|
| 155 | 155 | $record = new Repository($xref, $gedcom, $pending, $tree); |
| 156 | - break; |
|
| 156 | + break; |
|
| 157 | 157 | |
| 158 | - case Note::RECORD_TYPE: |
|
| 158 | + case Note::RECORD_TYPE: |
|
| 159 | 159 | $record = new Note($xref, $gedcom, $pending, $tree); |
| 160 | - break; |
|
| 160 | + break; |
|
| 161 | 161 | |
| 162 | - case Submitter::RECORD_TYPE: |
|
| 162 | + case Submitter::RECORD_TYPE: |
|
| 163 | 163 | $record = new Submitter($xref, $gedcom, $pending, $tree); |
| 164 | - break; |
|
| 164 | + break; |
|
| 165 | 165 | |
| 166 | - default: |
|
| 166 | + default: |
|
| 167 | 167 | $record = new GedcomRecord($xref, $gedcom, $pending, $tree); |
| 168 | 168 | break; |
| 169 | 169 | } |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | $this->gedcom_record_cache[$xref][$tree_id] = $record; |
| 173 | 173 | |
| 174 | 174 | return $record; |
| 175 | - } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - public function clearCache(): void { |
|
| 177 | + public function clearCache(): void { |
|
| 178 | 178 | // Clear the cache |
| 179 | 179 | $this->gedcom_record_cache = []; |
| 180 | 180 | $this->pending_record_cache = []; |
| 181 | - } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | } |
@@ -34,7 +34,8 @@ discard block |
||
| 34 | 34 | use Fisharebest\Webtrees\Submitter; |
| 35 | 35 | use stdClass; |
| 36 | 36 | |
| 37 | -class GedcomRecordFactories implements GedcomRecordFactoriesInterface { |
|
| 37 | +class GedcomRecordFactories implements GedcomRecordFactoriesInterface |
|
| 38 | +{ |
|
| 38 | 39 | |
| 39 | 40 | /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
| 40 | 41 | protected $gedcom_record_cache; |
@@ -44,7 +45,8 @@ discard block |
||
| 44 | 45 | |
| 45 | 46 | protected $factories = []; |
| 46 | 47 | |
| 47 | - public function __construct() { |
|
| 48 | + public function __construct() |
|
| 49 | + { |
|
| 48 | 50 | } |
| 49 | 51 | |
| 50 | 52 | public function setFactory(string $type, GedcomRecordFactory $factory): void |
@@ -64,7 +66,8 @@ discard block |
||
| 64 | 66 | * @throws Exception |
| 65 | 67 | * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
| 66 | 68 | */ |
| 67 | - public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
| 69 | + public function getInstance(string $xref, Tree $tree, string $gedcom = null) |
|
| 70 | + { |
|
| 68 | 71 | $tree_id = $tree->id(); |
| 69 | 72 | |
| 70 | 73 | // Is this record already in the cache? |