Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Update solr reindex to use config value, Update SolrReindexTask t… #55

Merged
merged 1 commit into from Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions code/tasks/SolrReindexJob.php
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 16 additions & 7 deletions code/tasks/SolrReindexTask.php
Expand Up @@ -51,17 +51,20 @@ public function run($request) {
$job = new SolrReindexJob($type);
$svc = singleton('QueuedJobService');
$svc->queueJob($job);
echo "<p>Reindexing job for $type has been queued</p>";
$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.
Expand All @@ -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 "<p>Reindexed Live version of $live->Title</p>\n";
$this->log("Reindexed Live version of $live->Title");
}

echo "<p>Reindexed (#$page->ID) $page->Title</p>\n";
$this->log("Reindexed (#$page->ID) $page->Title");
$count ++;
} else {
$search->index($page);
echo "<p>Reindexed $type ID#$page->ID</p>\n";
$this->log("Reindexed $type ID#$page->ID");
$count ++;
}
}
Expand All @@ -98,6 +101,12 @@ public function run($request) {
}
}

echo "Reindex complete, $count objects re-indexed<br/>";
$this->log("------------------------------");
$this->log("Reindex complete, $count objects re-indexed");
$this->log("------------------------------");
}

protected function log($message) {
DB::alteration_message($message);
}
}