tethys/app/Observers/DatasetObserver.php

102 lines
2.4 KiB
PHP
Raw Normal View History

2019-02-12 11:21:35 +00:00
<?php
namespace App\Observers;
//php artisan make:observer DatasetObserver --model=Models\Dataset
use App\Models\Dataset;
use Illuminate\Support\Facades\Log;
2019-02-14 14:09:11 +00:00
use App\Library\Search\SolariumAdapter;
2019-02-12 11:21:35 +00:00
class DatasetObserver
{
/**
* Handle the dataset "created" event.
*
* @param \App\Models\Dataset $dataset
* @return void
*/
public function created(Dataset $dataset)
{
//
}
/**
* Handle the dataset "updated" event.
*
* @param \App\Models\Dataset $dataset
* @return void
*/
public function updated(Dataset $dataset)
{
// only index Opus_Document instances
if (false === ($dataset instanceof Dataset)) {
return;
}
2019-02-14 14:09:11 +00:00
if ($dataset->server_state !== 'published') {
// if ($dataset->getServerState() !== 'temporary') {
// $this->removeDocumentFromIndexById($model->getId());
// }
return;
}
2019-02-12 11:21:35 +00:00
$this->addDatasetToIndex($dataset);
}
/**
* Handle the dataset "deleted" event.
*
* @param \App\Models\Dataset $dataset
* @return void
*/
public function deleted(Dataset $dataset)
{
//
}
/**
* Handle the dataset "restored" event.
*
* @param \App\Models\Dataset $dataset
* @return void
*/
public function restored(Dataset $dataset)
{
//
}
/**
* Handle the dataset "force deleted" event.
*
* @param \App\Models\Dataset $dataset
* @return void
*/
public function forceDeleted(Dataset $dataset)
{
//
}
/**
* Helper method to add dataset to index.
*
* @param Opus_Document $document
* @return void
*/
private function addDatasetToIndex(Dataset $dataset)
{
$datasetId = $dataset->id;
2019-02-14 14:09:11 +00:00
Log::debug(__METHOD__ . ': ' . 'Adding index job for dataset ' . $datasetId . '.');
try {
// Opus_Search_Service::selectIndexingService('onDocumentChange')
$service = new SolariumAdapter("solr", config('solarium'));
$service->addDatasetsToIndex($dataset);
} catch (Opus_Search_Exception $e) {
Log::debug(__METHOD__ . ': ' . 'Indexing document ' . $documentId . ' failed: ' . $e->getMessage());
} catch (InvalidArgumentException $e) {
Log::warning(__METHOD__ . ': ' . $e->getMessage());
}
2019-02-12 11:21:35 +00:00
}
}