@@ -64,7 +64,11 @@ public function reindexElastic(string $datasetId, bool $returnParams = false, bo
6464 }
6565
6666 if (DatasetVersion::where ('dataset_id ' , $ datasetId )->count () === 0 ) {
67- throw new \Exception ("Error: DatasetVersion is missing for dataset ID= $ datasetId. " );
67+ return null ;
68+ // This has been removed pending further investigation of the behaviour of the observers under GMI deletion.
69+ // There's a non-zero chance we'll end up with a dataset hanging around for a moment in the index
70+ // with no metadata associated, but that shouldn't cause upsets.
71+ // throw new \Exception("Error: DatasetVersion is missing for dataset ID=$datasetId.");
6872 }
6973
7074 $ metadata = $ datasetMatch ->latestVersion ()->metadata ;
@@ -171,21 +175,25 @@ public function reindexElasticDataProvider(string $teamId, bool $returnParams =
171175 $ toolNames = [];
172176 foreach ($ datasets as $ dataset ) {
173177 $ dataset ->setAttribute ('spatialCoverage ' , $ dataset ->allSpatialCoverages );
174- $ datasetVersionIds [] = $ dataset ->latestVersion ()->id ;
175- $ metadata = $ dataset ->latestVersion ()->metadata ;
176- $ datasetTitles [] = $ metadata ['metadata ' ]['summary ' ]['shortTitle ' ];
177- $ types = explode (';,; ' , $ metadata ['metadata ' ]['summary ' ]['datasetType ' ]);
178- foreach ($ types as $ t ) {
179- if (!in_array ($ t , $ dataTypes )) {
180- $ dataTypes [] = $ t ;
181- }
182- }
183178 foreach ($ dataset ['spatialCoverage ' ] as $ loc ) {
184179 if (!in_array ($ loc ['region ' ], $ locations )) {
185180 $ locations [] = $ loc ['region ' ];
186181 }
187182 }
188183
184+ $ latestVersion = $ dataset ->latestVersion ();
185+ if ($ latestVersion ) {
186+ $ datasetVersionIds [] = $ latestVersion ->id ;
187+ $ metadata = $ latestVersion ->metadata ;
188+ $ datasetTitles [] = $ metadata ['metadata ' ]['summary ' ]['shortTitle ' ];
189+ $ types = explode (';,; ' , $ metadata ['metadata ' ]['summary ' ]['datasetType ' ]);
190+ foreach ($ types as $ t ) {
191+ if (!in_array ($ t , $ dataTypes )) {
192+ $ dataTypes [] = $ t ;
193+ }
194+ }
195+ }
196+
189197 unset($ metadata ); // Only because it's potentially massive.
190198 }
191199 usort ($ datasetTitles , 'strcasecmp ' );
0 commit comments