silverstripe-fulltextsearch/src/Solr/Reindex/Jobs/SolrReindexQueuedJob.php

103 lines
2.3 KiB
PHP
Raw Normal View History

<?php
2017-04-21 02:27:01 +02:00
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
if (!interface_exists('SilverStripe\QueuedJobs\Services\QueuedJob')) {
2015-11-21 07:19:20 +01:00
return;
}
/**
* Represents a queuedjob which invokes a reindex
*/
2015-11-21 07:19:20 +01:00
class SolrReindexQueuedJob extends SolrReindexQueuedJobBase
{
/**
* Size of each batch to run
*
* @var int
*/
protected $batchSize;
2015-11-21 07:19:20 +01:00
/**
* Name of devtask Which invoked this
* Not necessary for re-index processing performed entirely by queuedjobs
*
* @var string
*/
protected $taskName;
2015-11-21 07:19:20 +01:00
/**
* List of classes to filter
*
* @var array|string
*/
protected $classes;
2015-11-21 07:19:20 +01:00
public function __construct($batchSize = null, $taskName = null, $classes = null)
{
$this->batchSize = $batchSize;
$this->taskName = $taskName;
$this->classes = $classes;
parent::__construct();
}
2015-11-21 07:19:20 +01:00
public function getJobData()
{
$data = parent::getJobData();
2015-11-21 07:19:20 +01:00
// Custom data
$data->jobData->batchSize = $this->batchSize;
$data->jobData->taskName = $this->taskName;
$data->jobData->classes = $this->classes;
return $data;
}
2015-11-21 07:19:20 +01:00
public function setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages)
{
parent::setJobData($totalSteps, $currentStep, $isComplete, $jobData, $messages);
2015-11-21 07:19:20 +01:00
// Custom data
$this->batchSize = $jobData->batchSize;
$this->taskName = $jobData->taskName;
$this->classes = $jobData->classes;
}
2015-11-21 07:19:20 +01:00
public function getSignature()
{
return __CLASS__;
}
2015-11-21 07:19:20 +01:00
public function getTitle()
{
return 'Solr Reindex Job';
}
2015-11-21 07:19:20 +01:00
public function process()
{
$logger = $this->getLogger();
if ($this->jobFinished()) {
$logger->notice("reindex already complete");
return;
}
2015-11-21 07:19:20 +01:00
// Send back to processor
$logger->info("Beginning init of reindex");
$this
->getHandler()
->runReindex($logger, $this->batchSize, $this->taskName, $this->classes);
$logger->info("Completed init of reindex");
$this->isComplete = true;
}
2015-11-21 07:19:20 +01:00
/**
* Get size of batch
*
* @return int
*/
public function getBatchSize()
{
return $this->batchSize;
}
}