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