Skip to content

Commit

Permalink
Simplified indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 12, 2018
1 parent 7c08b0a commit be0f05d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
4 changes: 3 additions & 1 deletion cli/IndexerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private function doIndex($alt_output = false)
$grav = Grav::instance();
$grav->fireEvent('onPluginsInitialized');

$this->output->write(TNTSearchPlugin::indexJob($alt_output));
list($status, $msg, $output) = TNTSearchPlugin::indexJob();

$this->output->write($output);
$this->output->writeln('');
}
}
Expand Down
38 changes: 12 additions & 26 deletions tntsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,15 @@ public function onAdminTaskExecute(Event $e)

// disable warnings
error_reporting(1);
// disable execution time
set_time_limit(0);

$phpBinaryFinder = new PhpExecutableFinder();
$php = $phpBinaryFinder->find();
$command = 'cd ' . GRAV_ROOT . ';' . $php . ' bin/plugin tntsearch index --alt';
$process = new Process($command);
list($status, $msg, $output) = $this->indexJob();

$process->run();

if (!$process->isSuccessful()) {
$json_response = [
'status' => 'error',
'message' => '<i class="fa fa-exclamation-circle"></i> ' . $process->getErrorOutput()
];

} else {
$json_response = [
'status' => 'success',
'message' => '<i class="fa fa-book"></i> ' . $process->getOutput()
];
}
$json_response = [
'status' => $status ? 'success' : 'error',
'message' => $msg
];

echo json_encode($json_response);
exit;
Expand Down Expand Up @@ -436,7 +425,7 @@ public static function getSearchObjectType($options = [])
}
}

public static function indexJob($alt_output = false)
public static function indexJob()
{
$grav = Grav::instance();

Expand Down Expand Up @@ -465,14 +454,11 @@ public static function indexJob($alt_output = false)

$output = ob_get_clean();

// Alternative output
if ($alt_output) {
$gtnt = static::getSearchObjectType();
list($status, $msg) = static::getIndexCount($gtnt);
return $msg;
}
// Reset and get index count and status
$gtnt = static::getSearchObjectType();
list($status, $msg) = static::getIndexCount($gtnt);

return $output;
return [$status, $msg, $output];
}

}

0 comments on commit be0f05d

Please sign in to comment.