mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 14:05:29 +02:00
1728a62af5
Thanks to Marco Hermo and Brett Tasker for helping with this * Bump framework/cms to ^4.0@dev * WIP Silverstripe 4 compatibility fixes * more replacements and patches to migrate this module to 4.0 * Update composer.json * remove php <5.5 from travis.yml * WIP more SS4 compatibility fixes * WIP fix solr path to use DIR, avoid hardcoded module name * WIP respect current include path * WIP Namespacing and use on SearchIndex class * Namespacing for tests * WIP add namespaces to all classes * Second push of Test changes + namespacing * WIP split Solr files with multiple classes into single file / single class. Adjust namespaces * Fix PHP errors in test * break out search components with multiple classes into individual files and change namespaces * Update namespacing for Search indexes and variants in tests * Batch fixes for tests #2 * Update _config.php to use namespace * Use root namespace in referencing Apache_Solr_Document * Migrate task names so that the name is not fully qualified
102 lines
2.5 KiB
PHP
102 lines
2.5 KiB
PHP
<?php
|
|
namespace SilverStripe\FullTextSearch\Search\Processors;
|
|
if (!interface_exists('QueuedJob')) {
|
|
return;
|
|
}
|
|
|
|
class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implements QueuedJob
|
|
{
|
|
/**
|
|
* The QueuedJob queue to use when processing updates
|
|
* @config
|
|
* @var int
|
|
*/
|
|
private static $reindex_queue = 2; // QueuedJob::QUEUED;
|
|
|
|
protected $messages = array();
|
|
|
|
public function triggerProcessing()
|
|
{
|
|
parent::triggerProcessing();
|
|
singleton('QueuedJobService')->queueJob($this);
|
|
}
|
|
|
|
public function getTitle()
|
|
{
|
|
return "FullTextSearch Update Job";
|
|
}
|
|
|
|
public function getSignature()
|
|
{
|
|
return md5(get_class($this) . time() . mt_rand(0, 100000));
|
|
}
|
|
|
|
public function getJobType()
|
|
{
|
|
return Config::inst()->get('SearchUpdateQueuedJobProcessor', 'reindex_queue');
|
|
}
|
|
|
|
public function jobFinished()
|
|
{
|
|
return $this->currentBatch >= count($this->batches);
|
|
}
|
|
|
|
public function setup()
|
|
{
|
|
// NOP
|
|
}
|
|
|
|
public function prepareForRestart()
|
|
{
|
|
// NOP
|
|
}
|
|
|
|
public function afterComplete()
|
|
{
|
|
// Once indexing is complete, commit later in order to avoid solr limits
|
|
// see http://stackoverflow.com/questions/7512945/how-to-fix-exceeded-limit-of-maxwarmingsearchers
|
|
SearchUpdateCommitJobProcessor::queue();
|
|
}
|
|
|
|
public function getJobData()
|
|
{
|
|
$data = new stdClass();
|
|
$data->totalSteps = count($this->batches);
|
|
$data->currentStep = $this->currentBatch;
|
|
$data->isComplete = $this->jobFinished();
|
|
$data->messages = $this->messages;
|
|
|
|
$data->jobData = new stdClass();
|
|
$data->jobData->batches = $this->batches;
|
|
$data->jobData->currentBatch = $this->currentBatch;
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages)
|
|
{
|
|
$this->isComplete = $isComplete;
|
|
$this->messages = $messages;
|
|
|
|
$this->batches = $jobData->batches;
|
|
$this->currentBatch = $jobData->currentBatch;
|
|
}
|
|
|
|
public function addMessage($message, $severity='INFO')
|
|
{
|
|
$severity = strtoupper($severity);
|
|
$this->messages[] = '[' . date('Y-m-d H:i:s') . "][$severity] $message";
|
|
}
|
|
|
|
public function process()
|
|
{
|
|
$result = parent::process();
|
|
|
|
if ($this->jobFinished()) {
|
|
$this->addMessage("All batched updates complete. Queuing commit job");
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|