diff --git a/code/tasks/SolrReindexJob.php b/code/tasks/SolrReindexJob.php index 10f0883..93ab209 100644 --- a/code/tasks/SolrReindexJob.php +++ b/code/tasks/SolrReindexJob.php @@ -10,7 +10,7 @@ if (class_exists('AbstractQueuedJob')) { class SolrReindexJob extends AbstractQueuedJob { - static $at_a_time = 100; + private static $at_a_time = 100; public function __construct($type = null) { if (!$type && isset($_GET['type'])) { @@ -41,7 +41,10 @@ public function process() { } $class = $this->reindexType; - $pages = $class::get()->filter('ID:GreaterThan', $this->lastIndexedID)->sort('ID ASC')->limit('0, ' . self::$at_a_time); + $pages = $class::get(); + $pages = $pages->filter(array('ID:GreaterThan' => $this->lastIndexedID)); + $pages = $pages->limit(Config::inst()->get(__CLASS__, 'at_a_time')); + $pages = $pages->sort('ID ASC'); if (ClassInfo::exists('Subsite')) { Subsite::$disable_subsite_filter = false; diff --git a/code/tasks/SolrReindexTask.php b/code/tasks/SolrReindexTask.php index 158a306..c3f8f73 100644 --- a/code/tasks/SolrReindexTask.php +++ b/code/tasks/SolrReindexTask.php @@ -51,17 +51,20 @@ public function run($request) { $job = new SolrReindexJob($type); $svc = singleton('QueuedJobService'); $svc->queueJob($job); - echo "

Reindexing job for $type has been queued

"; + $this->log("Reindexing job for $type has been queued"); } else { $mode = Versioned::get_reading_mode(); Versioned::reading_stage('Stage'); // get the holders first, see if we have any that AREN'T in the root (ie we've already partitioned everything...) - $pages = DataObject::get($type); + $pages = $type::get(); + $pages = $pages->filter(array('ClassName' => $type)); /* @var $search SolrSearchService */ - + $this->log("------------------------------"); + $this->log("Start reindexing job for $type (Count: ".$pages->count()."):"); + $this->log("------------------------------"); foreach ($pages as $page) { // Make sure the current page is not orphaned. @@ -82,14 +85,14 @@ public function run($request) { $live = Versioned::get_one_by_stage($page->ClassName, 'Live', "\"$baseTable\".\"ID\" = $page->ID"); if ($live) { $search->index($live, 'Live'); - echo "

Reindexed Live version of $live->Title

\n"; + $this->log("Reindexed Live version of $live->Title"); } - echo "

Reindexed (#$page->ID) $page->Title

\n"; + $this->log("Reindexed (#$page->ID) $page->Title"); $count ++; } else { $search->index($page); - echo "

Reindexed $type ID#$page->ID

\n"; + $this->log("Reindexed $type ID#$page->ID"); $count ++; } } @@ -98,6 +101,12 @@ public function run($request) { } } - echo "Reindex complete, $count objects re-indexed
"; + $this->log("------------------------------"); + $this->log("Reindex complete, $count objects re-indexed"); + $this->log("------------------------------"); + } + + protected function log($message) { + DB::alteration_message($message); } }