Permalink
Browse files

Use new TaskService inside CoreIndexer.

  • Loading branch information...
1 parent f926af2 commit 6cef16886d8686a15e4a9adfd68303dc6a3e8941 @cdujeu cdujeu committed May 19, 2016
@@ -69,7 +69,12 @@ public function add($nodes){
* @param string|null $originalPath
*/
public function update($nodes, $originalPath = null){
- if(!is_array($nodes)) $nodes = [$originalPath => $nodes];
+ if(!is_array($nodes)) {
+ if($originalPath === null){
+ $originalPath = $nodes->getPath();
+ }
+ $nodes = [$originalPath => $nodes];
+ }
$this->updated = array_merge($this->updated, $nodes);
}
@@ -28,13 +28,15 @@
use Pydio\Core\Controller\XMLWriter;
use Pydio\Core\PluginFramework\Plugin;
use Pydio\Core\Utils\TextEncoder;
+use Pydio\Tasks\Task;
+use Pydio\Tasks\TaskService;
defined('AJXP_EXEC') or die( 'Access not allowed');
class CoreIndexer extends Plugin {
private $verboseIndexation = false;
-
+ private $currentTaskId;
public function debug($message = ""){
$this->logDebug("core.indexer", $message);
@@ -43,9 +45,12 @@ public function debug($message = ""){
}
}
- public function applyAction($actionName, $httpVars, $fileVars)
+ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface $responseInterface)
{
$messages = ConfService::getMessages();
+ $actionName = $requestInterface->getAttribute("action");
+ $httpVars = $requestInterface->getParsedBody();
+ $this->currentTaskId = $requestInterface->getAttribute("pydio-task-id") OR null;
if ($actionName == "index") {
@@ -62,15 +67,15 @@ public function applyAction($actionName, $httpVars, $fileVars)
}
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
- Controller::applyActionInBackground($repositoryId, "index", $httpVars);
+ $task = TaskService::getInstance()->enqueueActionAsTask("index", $httpVars, "", "", [$nodes[0]->getUrl()]);
+ $task->setFlags(Task::FLAG_STOPPABLE | Task::FLAG_RESUMABLE);
+ Controller::applyTaskInBackground($task);
XMLWriter::header();
- XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repositoryId), sprintf($messages["core.index.8"], $nodes[0]->getPath()), true, 2);
if(!isSet($httpVars["inner_apply"])){
XMLWriter::close();
}
return null;
}
-
// GIVE BACK THE HAND TO USER
session_write_close();
@@ -82,6 +87,9 @@ public function applyAction($actionName, $httpVars, $fileVars)
try{
$this->debug("Indexing - node.index ".$node->getUrl());
Controller::applyHook("node.index", array($node));
+ if($this->currentTaskId){
+ TaskService::getInstance()->updateTaskStatus($this->currentTaskId, Task::STATUS_COMPLETE, "Done");
+ }
}catch (Exception $e){
$this->debug("Error Indexing Node ".$node->getUrl()." (".$e->getMessage().")");
}
@@ -172,7 +180,7 @@ public function recursiveIndexation($node, $depth = 0)
}
if($depth == 0){
$this->debug("End indexation - node.index.recursive.end - ". memory_get_usage(true) ." - ". $node->getUrl());
- $this->setIndexStatus("RUNNING", "Indexation finished, cleaning...", $repository, $user);
+ $this->setIndexStatus("RUNNING", "Indexation finished, cleaning...", $repository, $user, false);
Controller::applyHook("node.index.recursive.end", array($node));
$this->releaseStatus($repository, $user);
$this->debug("End indexation - After node.index.recursive.end - ". memory_get_usage(true) ." - ". $node->getUrl());
@@ -202,9 +210,13 @@ protected function buildIndexLockKey($repository, $user){
* @param String $message
* @param Repository $repository
* @param AbstractAjxpUser $user
+ * @param boolean $stoppable
*/
- protected function setIndexStatus($status, $message, $repository, $user)
+ protected function setIndexStatus($status, $message, $repository, $user, $stoppable = true)
{
+ if(isSet($this->currentTaskId)){
+ TaskService::getInstance()->updateTaskStatus($this->currentTaskId, Task::STATUS_RUNNING, $message, $stoppable);
+ }
$iPath = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/indexes";
if(!is_dir($iPath)) mkdir($iPath,0755, true);
$f = $iPath."/.indexation_status-".$this->buildIndexLockKey($repository, $user);
@@ -233,6 +245,9 @@ protected function getIndexStatus($repository, $user)
*/
protected function releaseStatus($repository, $user)
{
+ if(isSet($this->currentTaskId)){
+ TaskService::getInstance()->updateTaskStatus($this->currentTaskId, Task::STATUS_COMPLETE, "Done");
+ }
$f = (defined('AJXP_SHARED_CACHE_DIR')?AJXP_SHARED_CACHE_DIR:AJXP_CACHE_DIR)."/indexes/.indexation_status-".$this->buildIndexLockKey($repository, $user);
$this->debug("Removing file ".$f);
@unlink($f);
@@ -255,6 +270,10 @@ protected function requireInterrupt($repository, $user)
*/
protected function isInterruptRequired($repository, $user)
{
+ if(isSet($this->currentTaskId)){
+ $task = TaskService::getInstance()->getTaskById($this->currentTaskId);
+ return ($task->getStatus() == Task::STATUS_PAUSED);
+ }
list($status, $message) = $this->getIndexStatus($repository, $user);
return ($status == "INTERRUPT");
}
@@ -25,9 +25,10 @@
if(!pydio.getUserSelection().isEmpty()){
crtDir = pydio.getUserSelection().getUniqueNode().getPath();
}
- var bgManager = pydio.getController().getBackgroundTasksManager();
- bgManager.queueAction("index", {file:crtDir}, MessageHash["index.lucene.8"].replace('%s', crtDir));
- bgManager.next();
+ //var bgManager = pydio.getController().getBackgroundTasksManager();
+ //bgManager.queueAction("index", {file:crtDir}, MessageHash["index.lucene.8"].replace('%s', crtDir));
+ //bgManager.next();
+ PydioTasks.Store.enqueueActionTask("Indexation", "index", {file:crtDir}, [crtDir]);
]]></clientCallback>
<serverCallback methodName="applyAction" restParams="/file+" developerComment="Trigger re-indexation of a directory, recursively">
<input_param name="file" type="string" description="Folder to index (can be empty for root)"/>

0 comments on commit 6cef168

Please sign in to comment.