Permalink
Browse files

Create Indexer namespace

  • Loading branch information...
1 parent 32ea833 commit 5d6660e154886ca1e4e375b4ac5e8fa58177ce1f @cdujeu cdujeu committed Jun 22, 2016
@@ -1,4 +1,28 @@
<?php
+/*
+ * Copyright 2007-2016 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
+ * This file is part of Pydio.
+ *
+ * Pydio is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pydio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Pydio. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * The latest code can be found at <http://pyd.io/>.
+ */
+
+namespace Pydio\Access\Indexer\Core;
+
+use DOMNode;
+use DOMXPath;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Utils\StatHelper;
@@ -7,38 +31,38 @@
use Pydio\Meta\Core\AbstractMetaSource;
/**
- * Created by PhpStorm.
- * User: charles
- * Date: 15/04/2015
- * Time: 14:52
+ * Class AbstractSearchEngineIndexer
+ * @package Pydio\Access\Indexer\Core
*/
-
-abstract class AbstractSearchEngineIndexer extends AbstractMetaSource {
+abstract class AbstractSearchEngineIndexer extends AbstractMetaSource
+{
/**
* @param DOMNode $contribNode
*/
- public function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode){
+ public function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$contribNode)
+ {
parent::parseSpecificContributions($ctx, $contribNode);
- if($this->getContextualOption($ctx, "HIDE_MYSHARES_SECTION") !== true) return;
- if($contribNode->nodeName != "client_configs") return ;
- $actionXpath=new DOMXPath($contribNode->ownerDocument);
+ if ($this->getContextualOption($ctx, "HIDE_MYSHARES_SECTION") !== true) return;
+ if ($contribNode->nodeName != "client_configs") return;
+ $actionXpath = new DOMXPath($contribNode->ownerDocument);
$nodeList = $actionXpath->query('component_config[@className="AjxpPane::navigation_scroller"]', $contribNode);
- if(!$nodeList->length) return ;
+ if (!$nodeList->length) return;
$contribNode->removeChild($nodeList->item(0));
}
/**
* @param AJXP_Node $ajxpNode
* @return null|string
*/
- protected function extractIndexableContent($ajxpNode){
+ protected function extractIndexableContent($ajxpNode)
+ {
$ext = strtolower(pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION));
- if (in_array($ext, explode(",",$this->getContextualOption($ajxpNode->getContext(), "PARSE_CONTENT_TXT")))) {
+ if (in_array($ext, explode(",", $this->getContextualOption($ajxpNode->getContext(), "PARSE_CONTENT_TXT")))) {
return file_get_contents($ajxpNode->getUrl());
}
- $unoconv = $this->getContextualOption($ajxpNode->getContext(),"UNOCONV");
+ $unoconv = $this->getContextualOption($ajxpNode->getContext(), "UNOCONV");
$pipe = false;
if (!empty($unoconv) && in_array($ext, array("doc", "odt", "xls", "ods"))) {
$targetExt = "txt";
@@ -49,10 +73,10 @@ protected function extractIndexableContent($ajxpNode){
$pipe = true;
}
$realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
- $unoconv = "HOME=".Utils::getAjxpTmpDir()." ".$unoconv." --stdout -f $targetExt ".escapeshellarg($realFile);
+ $unoconv = "HOME=" . Utils::getAjxpTmpDir() . " " . $unoconv . " --stdout -f $targetExt " . escapeshellarg($realFile);
if ($pipe) {
$newTarget = str_replace(".$ext", ".pdf", $realFile);
- $unoconv.= " > $newTarget";
+ $unoconv .= " > $newTarget";
register_shutdown_function("unlink", $newTarget);
}
$output = array();
@@ -72,7 +96,7 @@ protected function extractIndexableContent($ajxpNode){
if ($pipe && isset($newTarget) && is_file($newTarget)) {
$realFile = $newTarget;
}
- $cmd = $pdftotext." ".escapeshellarg($realFile)." -";
+ $cmd = $pdftotext . " " . escapeshellarg($realFile) . " -";
$output = array();
exec($cmd, $output, $return);
$out = implode("\n", $output);
@@ -94,34 +118,34 @@ protected function filterSearchRangesKeywords($query)
$t2 = date("Ymd");
$query = str_replace("AJXP_SEARCH_RANGE_TODAY", "[$t1 TO $t2]", $query);
} else if (strpos($query, "AJXP_SEARCH_RANGE_YESTERDAY") !== false) {
- $t1 = date("Ymd", mktime(0,0,0,date('m'), date('d')-1, date('Y')));
- $t2 = date("Ymd", mktime(0,0,0,date('m'), date('d')-1, date('Y')));
+ $t1 = date("Ymd", mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')));
+ $t2 = date("Ymd", mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')));
$query = str_replace("AJXP_SEARCH_RANGE_YESTERDAY", "[$t1 TO $t2]", $query);
} else if (strpos($query, "AJXP_SEARCH_RANGE_LAST_WEEK") !== false) {
- $t1 = date("Ymd", mktime(0,0,0,date('m'), date('d')-7, date('Y')));
- $t2 = date("Ymd", mktime(0,0,0,date('m'), date('d'), date('Y')));
+ $t1 = date("Ymd", mktime(0, 0, 0, date('m'), date('d') - 7, date('Y')));
+ $t2 = date("Ymd", mktime(0, 0, 0, date('m'), date('d'), date('Y')));
$query = str_replace("AJXP_SEARCH_RANGE_LAST_WEEK", "[$t1 TO $t2]", $query);
} else if (strpos($query, "AJXP_SEARCH_RANGE_LAST_MONTH") !== false) {
- $t1 = date("Ymd", mktime(0,0,0,date('m')-1, date('d'), date('Y')));
- $t2 = date("Ymd", mktime(0,0,0,date('m'), date('d'), date('Y')));
+ $t1 = date("Ymd", mktime(0, 0, 0, date('m') - 1, date('d'), date('Y')));
+ $t2 = date("Ymd", mktime(0, 0, 0, date('m'), date('d'), date('Y')));
$query = str_replace("AJXP_SEARCH_RANGE_LAST_MONTH", "[$t1 TO $t2]", $query);
} else if (strpos($query, "AJXP_SEARCH_RANGE_LAST_YEAR") !== false) {
- $t1 = date("Ymd", mktime(0,0,0,date('m'), date('d'), date('Y')-1));
- $t2 = date("Ymd", mktime(0,0,0,date('m'), date('d'), date('Y')));
+ $t1 = date("Ymd", mktime(0, 0, 0, date('m'), date('d'), date('Y') - 1));
+ $t2 = date("Ymd", mktime(0, 0, 0, date('m'), date('d'), date('Y')));
$query = str_replace("AJXP_SEARCH_RANGE_LAST_YEAR", "[$t1 TO $t2]", $query);
}
$split = array_map("trim", explode("AND", $query));
- foreach($split as $s){
+ foreach ($split as $s) {
list($k, $v) = explode(":", $s, 2);
- if($k == "ajxp_bytesize"){
+ if ($k == "ajxp_bytesize") {
//list($from, $to) = sscanf($v, "[%s TO %s]");
preg_match('/\[(.*) TO (.*)\]/', $v, $matches);
$oldSize = $s;
- $newSize = "ajxp_bytesize:[".intval(StatHelper::convertBytes($matches[1]))." TO ".intval(StatHelper::convertBytes($matches[2]))."]";
+ $newSize = "ajxp_bytesize:[" . intval(StatHelper::convertBytes($matches[1])) . " TO " . intval(StatHelper::convertBytes($matches[2])) . "]";
}
}
- if(isSet($newSize) && isSet($oldSize)){
+ if (isSet($newSize) && isSet($oldSize)) {
$query = str_replace($oldSize, $newSize, $query);
}
@@ -132,13 +156,14 @@ protected function filterSearchRangesKeywords($query)
* @param ContextInterface $ctx
* @return string
*/
- protected function buildSpecificId(ContextInterface $ctx){
+ protected function buildSpecificId(ContextInterface $ctx)
+ {
$specificId = "";
$specKey = $this->getContextualOption($ctx, "repository_specific_keywords");
if (!empty($specKey)) {
- $specificId = "-".str_replace(array(",", "/"), array("-", "__"), VarsFilter::filter($specKey, $ctx));
+ $specificId = "-" . str_replace(array(",", "/"), array("-", "__"), VarsFilter::filter($specKey, $ctx));
}
- return $ctx->getRepositoryId().$specificId;
+ return $ctx->getRepositoryId() . $specificId;
}
}
@@ -18,6 +18,9 @@
*
* The latest code can be found at <http://pyd.io/>.
*/
+
+namespace Pydio\Access\Indexer\Core;
+
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\UserSelection;
use Pydio\Core\Model\ContextInterface;
@@ -33,18 +36,32 @@
defined('AJXP_EXEC') or die( 'Access not allowed');
+/**
+ * Class CoreIndexer
+ * @package Pydio\Access\Indexer\Core
+ */
class CoreIndexer extends Plugin {
private $verboseIndexation = false;
private $currentTaskId;
+ /**
+ * @param string $message
+ */
public function debug($message = ""){
$this->logDebug("core.indexer", $message);
if($this->verboseIndexation && ConfService::currentContextIsCommandLine()){
print($message."\n");
}
}
+ /**
+ * @param \Psr\Http\Message\ServerRequestInterface $requestInterface
+ * @param \Psr\Http\Message\ResponseInterface $responseInterface
+ * @return null|\Psr\Http\Message\ResponseInterface
+ * @throws \Exception
+ * @throws \Pydio\Core\Exception\PydioException
+ */
public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInterface, \Psr\Http\Message\ResponseInterface &$responseInterface)
{
@@ -87,13 +104,13 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInt
if($this->currentTaskId){
TaskService::getInstance()->updateTaskStatus($this->currentTaskId, Task::STATUS_COMPLETE, "Done");
}
- }catch (Exception $e){
+ }catch (\Exception $e){
$this->debug("Error Indexing Node ".$node->getUrl()." (".$e->getMessage().")");
}
}else{
try{
$this->recursiveIndexation($ctx, $node);
- }catch (Exception $e){
+ }catch (\Exception $e){
$this->debug("Indexation of ".$node->getUrl()." interrupted by error: (".$e->getMessage().")");
}
}
@@ -107,7 +124,7 @@ public function applyAction(\Psr\Http\Message\ServerRequestInterface $requestInt
*
* @param \Pydio\Access\Core\Model\AJXP_Node $node
* @param int $depth
- * @throws Exception
+ * @throws \Exception
*/
public function recursiveIndexation(ContextInterface $ctx, $node, $depth = 0)
{
@@ -123,7 +140,7 @@ public function recursiveIndexation(ContextInterface $ctx, $node, $depth = 0)
$this->debug("Interrupting indexation! - node.index.recursive.end - ". $node->getUrl());
Controller::applyHook("node.index.recursive.end", array($node));
$this->releaseStatus($repository, $user);
- throw new Exception("User interrupted");
+ throw new \Exception("User interrupted");
}
}
@@ -134,7 +151,7 @@ public function recursiveIndexation(ContextInterface $ctx, $node, $depth = 0)
if($node->getPath() != "/"){
try {
Controller::applyHook("node.index", array($node));
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->debug("Error Indexing Node ".$url." (".$e->getMessage().")");
}
}
@@ -152,7 +169,7 @@ public function recursiveIndexation(ContextInterface $ctx, $node, $depth = 0)
try {
$this->debug("Indexing Node ".$childUrl);
Controller::applyHook("node.index", array($childNode));
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$this->debug("Error Indexing Node ".$childUrl." (".$e->getMessage().")");
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ajxp_plugin label="CONF_MESSAGE[Indexation]" description="CONF_MESSAGE[Indexation plugins]" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="file:../core.ajaxplorer/ajxp_registry.xsd">
- <class_definition classname="CoreIndexer" filename="plugins/core.index/class.CoreIndexer.php"/>
+ <class_definition classname="Pydio\Access\Indexer\Core\CoreIndexer" filename="plugins/core.index/CoreIndexer.php"/>
<client_settings>
<resources>
<i18n namespace="core.index" path="plugins/core.index/i18n"/>
@@ -148,20 +148,6 @@
}.bind(this));
}
- static enqueueActionTask(label, action, parameters = {}, nodes = [], flags = Task.FLAG_STOPPABLE){
- let task = {
- label: label,
- flags: flags,
- status: 1,
- statusMessage : '',
- action: action,
- parameters: parameters,
- nodes: nodes
- };
- TaskAPI.createTask(new Task(task));
- }
-
-
getTasks(forceRefresh = false){
if(this._tasksList == undefined || forceRefresh){
this._tasksList = new Map();
@@ -176,10 +162,36 @@
global.pydio.notify("poller.frequency", {});
}
}.bind(this));
+ // Add local tasks
+ if(this._localTasks){
+ this._localTasks.forEach(function(lT){
+ this._tasksList.set(lT.getId(), lT);
+ }.bind(this));
+ }
}
return this._tasksList;
}
+ static enqueueActionTask(label, action, parameters = {}, nodes = [], flags = Task.FLAG_STOPPABLE){
+ let task = {
+ label: label,
+ flags: flags,
+ status: 1,
+ statusMessage : '',
+ action: action,
+ parameters: parameters,
+ nodes: nodes
+ };
+ TaskAPI.createTask(new Task(task));
+ }
+
+ static enqueueLocalTask(task){
+ if(!this._localTasks) {
+ this._localTasks = new Map();
+ }
+ this._localTasks.set(task.getId(), task);
+ }
+
}
var TaskAction = React.createClass({
Oops, something went wrong.

0 comments on commit 5d6660e

Please sign in to comment.