Permalink
Browse files

Pass context for hooks without nodes or tasks.

  • Loading branch information...
1 parent 2cf2a73 commit b547569be3aa189450884a4c34ed8cefcd3128b9 @cdujeu cdujeu committed Jun 6, 2016
Showing with 238 additions and 142 deletions.
  1. +24 −0 core/src/core/src/pydio/Core/Model/Context.php
  2. +12 −0 core/src/core/src/pydio/Core/Model/ContextInterface.php
  3. +20 −17 core/src/plugins/access.fs/class.fsAccessDriver.php
  4. +1 −1 core/src/plugins/access.inbox/class.inboxAccessDriver.php
  5. +17 −12 core/src/plugins/action.antivirus/class.AntivirusScanner.php
  6. +1 −1 core/src/plugins/action.compression/class.PluginCompression.php
  7. +3 −3 core/src/plugins/action.powerfs/class.PowerFSController.php
  8. +6 −6 core/src/plugins/action.share/src/ShareCenter.php
  9. +2 −2 core/src/plugins/auth.multi/class.multiAuthDriver.php
  10. +4 −3 core/src/plugins/cache.doctrine/class.DoctrineCacheDriver.php
  11. +8 −0 core/src/plugins/core.access/src/Model/AJXP_Node.php
  12. +2 −4 core/src/plugins/core.conf/class.AbstractConfDriver.php
  13. +5 −6 core/src/plugins/core.index/class.AbstractSearchEngineIndexer.php
  14. +2 −2 core/src/plugins/core.index/class.CoreIndexer.php
  15. +13 −11 core/src/plugins/core.mq/class.MqManager.php
  16. +6 −5 core/src/plugins/core.notifications/class.AJXP_NotificationCenter.php
  17. +9 −1 core/src/plugins/core.tasks/src/Task.php
  18. +2 −2 core/src/plugins/core.tasks/src/TaskService.php
  19. +6 −3 core/src/plugins/editor.diaporama/class.ImagePreviewer.php
  20. +20 −11 core/src/plugins/editor.imagick/class.IMagickPreviewer.php
  21. +2 −1 core/src/plugins/feed.sql/class.AJXP_SqlFeedStore.php
  22. +1 −1 core/src/plugins/gui.ajax/class.AJXP_ClientDriver.php
  23. +7 −9 core/src/plugins/index.elasticsearch/class.AjxpElasticSearch.php
  24. +28 −30 core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php
  25. +6 −4 core/src/plugins/mailer.phpmailer-lite/class.PhpMailLiteMailer.php
  26. +25 −2 core/src/plugins/meta.quota/class.QuotaComputer.php
  27. +1 −1 core/src/plugins/meta.syncable/class.ChangesTracker.php
  28. +5 −4 core/src/plugins/shorten.multi/class.multiShortener.php
@@ -82,6 +82,30 @@ public static function fromGlobalServices(){
}
/**
+ * @return Context
+ */
+ public static function emptyContext(){
+ return new Context();
+ }
+
+ /**
+ * @param $userId
+ * @return ContextInterface
+ */
+ public function withUserId($userId){
+ return new Context($userId, $this->repositoryId);
+ }
+
+ /**
+ * @param $repositoryId
+ * @return ContextInterface
+ */
+ public function withRepositoryId($repositoryId){
+ return new Context($this->userId, $repositoryId);
+ }
+
+
+ /**
* @return boolean
*/
public function hasUser()
@@ -86,4 +86,16 @@ public function resetRepository();
* @return string
*/
public function getStringIdentifier();
+
+ /**
+ * @param $userId
+ * @return ContextInterface
+ */
+ public function withUserId($userId);
+
+ /**
+ * @param $repositoryId
+ * @return ContextInterface
+ */
+ public function withRepositoryId($repositoryId);
}
@@ -922,7 +922,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
if(!empty($taskId)) {
TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_COMPLETE, "");
- Controller::applyHook("msg.instant", array($nodesDiffs->toXML(), $this->repository->getId()));
+ Controller::applyHook("msg.instant", array($ctx, $nodesDiffs->toXML()));
}
break;
@@ -1201,14 +1201,22 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
break;
}
+ $metaData = array();
+ if (RecycleBinManager::recycleEnabled() && $dir == "") {
+ $metaData["repo_has_recycle"] = "true";
+ }
+ $parentAjxpNode = new AJXP_Node($nonPatchedPath, $metaData);
+ $parentAjxpNode->loadNodeInfo(false, true, ($lsOptions["l"]?"all":"minimal"));
+ Controller::applyHook("node.read", array(&$parentAjxpNode));
+
$streamIsSeekable = AJXP_MetaStreamWrapper::wrapperIsSeekable($path);
$sharedHandle = null; $handle = null;
if($streamIsSeekable){
$handle = opendir($path);
$sharedHandle = $handle;
}
- $countFiles = $this->countFiles($path, !$lsOptions["f"], false, $sharedHandle);
+ $countFiles = $this->countFiles($parentAjxpNode, !$lsOptions["f"], false, $sharedHandle);
if(isSet($sharedHandle)){
rewind($handle);
}
@@ -1225,13 +1233,6 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$offset = $limitPerPage = 0;
}
- $metaData = array();
- if (RecycleBinManager::recycleEnabled() && $dir == "") {
- $metaData["repo_has_recycle"] = "true";
- }
- $parentAjxpNode = new AJXP_Node($nonPatchedPath, $metaData);
- $parentAjxpNode->loadNodeInfo(false, true, ($lsOptions["l"]?"all":"minimal"));
- Controller::applyHook("node.read", array(&$parentAjxpNode));
$nodesList->setParentNode($parentAjxpNode);
if (isSet($totalPages) && isSet($crtPage) && ($totalPages > 1 || ! Utils::userAgentIsNativePydioApp())) {
$remoteOptions = null;
@@ -1242,7 +1243,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
"currentOrderDir"=> isSet($orderDirection)?$orderDirection:$defaultDirection
);
}
- $foldersCounts = $this->countFiles($path, TRUE, false, $sharedHandle);
+ $foldersCounts = $this->countFiles($parentAjxpNode, TRUE, false, $sharedHandle);
if(isSet($sharedHandle)) {
rewind($sharedHandle);
}
@@ -1346,7 +1347,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
*/
foreach ($fullList["d"] as &$nodeDir) {
if($breakNow){
- $nodeDir->mergeMetadata(array("ajxp_has_children" => $this->countFiles($nodeDir->getUrl(), false, true)?"true":"false"));
+ $nodeDir->mergeMetadata(array("ajxp_has_children" => $this->countFiles($nodeDir, false, true)?"true":"false"));
$nodesList->addBranch($nodeDir);
continue;
}
@@ -1477,7 +1478,7 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
$metaData["filename"] = $ajxpNode->getPath();
if (RecycleBinManager::recycleEnabled() && $ajxpNode->getPath() == RecycleBinManager::getRelativeRecycle()) {
- $recycleIcon = ($this->countFiles($ajxpNode->getUrl(), false, true)>0?"trashcan_full.png":"trashcan.png");
+ $recycleIcon = ($this->countFiles($ajxpNode, false, true)>0?"trashcan_full.png":"trashcan.png");
$metaData["icon"] = $recycleIcon;
$metaData["mimestring"] = $mess[122];
$ajxpNode->setLabel($mess[122]);
@@ -1824,8 +1825,9 @@ public function readFile($filePathOrData, $headerType="plain", $localName="", $d
}
}
- public function countFiles($dirName, $foldersOnly = false, $nonEmptyCheckOnly = false, $dirHANDLE = null)
+ public function countFiles(AJXP_Node $dirNode, $foldersOnly = false, $nonEmptyCheckOnly = false, $dirHANDLE = null)
{
+ $dirName = $dirNode->getUrl();
if(is_resource($dirHANDLE)){
$handle = $dirHANDLE;
}else{
@@ -1834,17 +1836,17 @@ public function countFiles($dirName, $foldersOnly = false, $nonEmptyCheckOnly =
if ($handle === false) {
throw new \Exception("Error while trying to open directory ".$dirName);
}
- if ($foldersOnly && !AJXP_MetaStreamWrapper::wrapperIsRemote($dirName)) {
+ if ($foldersOnly && !$dirNode->wrapperIsRemote()) {
if($dirHANDLE == null || !is_resource($dirHANDLE)){
closedir($handle);
}
- $path = AJXP_MetaStreamWrapper::getRealFSReference($dirName, true);
+ $path = $dirNode->getRealFile();
$dirs = glob($path."/*", GLOB_ONLYDIR|GLOB_NOSORT);
if($dirs === false) return 0;
return count($dirs);
}
$count = 0;
- $showHiddenFiles = $this->getFilteredOption("SHOW_HIDDEN_FILES", $this->repository);
+ $showHiddenFiles = $this->getContextualOption($dirNode->getContext(), "SHOW_HIDDEN_FILES");
while (false !== ($file = readdir($handle))) {
if($file != "." && $file !=".."
&& !(Utils::isHidden($file) && !$showHiddenFiles)){
@@ -2139,7 +2141,8 @@ public function delete($selectedFiles, &$logMessages, $taskId = null)
TaskService::getInstance()->updateTaskStatus($taskId, Task::STATUS_COMPLETE, "Done");
$nodesDiff = new NodesDiff();
$nodesDiff->remove($selectedFiles);
- Controller::applyHook("msg.instant", array($nodesDiff->toXML(), $this->repository->getId()));
+ $t = TaskService::getInstance()->getTaskById($taskId);
+ Controller::applyHook("msg.instant", array($t->getContext(), $nodesDiff->toXML()));
}
return null;
}
@@ -72,7 +72,7 @@ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
}
}
- public function loadRepositoryInfo(&$data){
+ public function loadRepositoryInfo(ContextInterface $ctx, &$data){
$allNodes = self::getNodes(false, false);
$data['access.inbox'] = array(
'files' => count($allNodes)
@@ -42,12 +42,12 @@ public function scanFile ($oldNode = null, $newNode = null)
$this->scanLater();
return ;
} else {
- $this->scanNow();
+ $this->scanNow($newNode);
return ;
}
} else {
if ($this->inList()==true) {
- $this->scanNow();
+ $this->scanNow($newNode);
return ;
} else {
if ($trace === false) {return;}
@@ -82,10 +82,11 @@ private function inList()
/**
* This function immediatly scans the file, it calls the antivirus command
+ * @param AJXP_Node $nodeObject
*/
- private function scanNow()
+ private function scanNow($nodeObject)
{
- $command = $this->getFilteredOption("COMMAND");
+ $command = $this->getContextualOption($nodeObject->getContext(), "COMMAND");
$command = str_replace('$' . 'FILE', escapeshellarg($this->path), $command);
ob_start();
@@ -180,19 +181,21 @@ public function setFileExtension ($nodeObject)
/**
* This function initializes the extension list
+ * @param AJXP_Node $nodeObject
*/
- public function setExtensionScan()
+ public function setExtensionScan($nodeObject)
{
- $this->extension_scan = $this->getFilteredOption("EXT");
+ $this->extension_scan = $this->getContextualOption($nodeObject->getContext(), "EXT");
return ;
}
/**
* this function initializes attribute scan_all
+ * @param AJXP_Node $nodeObject
*/
- public function setScanAll()
+ public function setScanAll($nodeObject)
{
- $extension = $this->getFilteredOption("EXT");
+ $extension = $this->getContextualOption($nodeObject->getContext(), "EXT");
if (substr($extension, 0, 2) == "*/") {
$this->scan_all = true;
} else {
@@ -203,19 +206,21 @@ public function setScanAll()
/**
* this function initializes the trace folder
+ * @param AJXP_Node $nodeObject
*/
- public function setScanDiffFolder ()
+ public function setScanDiffFolder ($nodeObject)
{
- $this->scan_diff_folder = $this->getFilteredOption("PATH");
+ $this->scan_diff_folder = $this->getContextualOption($nodeObject->getContext(), "PATH");
return ;
}
/**
* this function initializes max size of the scanned file
+ * @param AJXP_Node $nodeObject
*/
- public function setScanMaxSize ()
+ public function setScanMaxSize ($nodeObject)
{
- $this->scan_max_size = Utils::convertBytes($this->getFilteredOption("SIZE"));
+ $this->scan_max_size = Utils::convertBytes($this->getContextualOption($nodeObject->getContext(), "SIZE"));
return ;
}
@@ -253,7 +253,7 @@ public function receiveAction(\Psr\Http\Message\ServerRequestInterface &$request
$newNode = new AJXP_Node($currentDirUrl . $onlyFileName);
$nodesDiff = new NodesDiff();
$nodesDiff->add($newNode);
- Controller::applyHook("msg.instant", array($nodesDiff->toXML(), $repository->getId()));
+ Controller::applyHook("msg.instant", array($ctx, $nodesDiff->toXML()));
$indexRequest = Controller::executableRequest($requestInterface->getAttribute("ctx"), "index", ["file" => $newNode->getPath()]);
Controller::run($indexRequest);
break;
@@ -77,7 +77,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$archive = Utils::getAjxpTmpDir().DIRECTORY_SEPARATOR.$httpVars["ope_id"]."_".Utils::sanitize(Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME);
/** @var \Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver $fsDriver */
- $fsDriver = PluginsService::getInstance()->getUniqueActivePluginForType("access");
+ $fsDriver = PluginsService::getInstance($ctx)->getUniqueActivePluginForType("access");
$archiveName = $httpVars["archive_name"];
if (is_file($archive)) {
$response = $response->withBody(new \Pydio\Core\Http\Response\AsyncResponseStream(function() use($fsDriver, $archive, $archiveName){
@@ -178,12 +178,12 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$newNode = new \Pydio\Access\Core\Model\AJXP_Node($urlBase.$dir."/".$archiveName);
$nodesDiff = new \Pydio\Access\Core\Model\NodesDiff();
$nodesDiff->add($newNode);
- Controller::applyHook("msg.instant", array($nodesDiff->toXML(), $repository->getId()));
+ Controller::applyHook("msg.instant", array($ctx, $nodesDiff->toXML()));
}else{
$archiveName = str_replace("'", "\'", $originalArchiveParam);
$jsCode = " PydioApi.getClient().downloadSelection(null, $('download_form'), 'postcompress_download', {ope_id:'".$opeId."',archive_name:'".$archiveName."'}); ";
$actionTrigger = BgActionTrigger::createForJsAction($jsCode, $mess["powerfs.3"]);
- Controller::applyHook("msg.instant", array($actionTrigger->toXML(), $repository->getId()));
+ Controller::applyHook("msg.instant", array($ctx, $actionTrigger->toXML()));
}
@@ -642,15 +642,15 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
}
- Controller::applyHook("msg.instant", array("<reload_shared_elements/>", $ajxpNode->getRepositoryId()));
+ Controller::applyHook("msg.instant", array( $ajxpNode->getContext(), "<reload_shared_elements/>"));
/*
* Send IM to inform that node has been shared or unshared.
* Should be done only if share scope is public.
*/
if($shareScope == "public"){
$ajxpNode->loadNodeInfo();
$content = XMLWriter::writeNodesDiff(["UPDATE" => array($ajxpNode->getPath() => $ajxpNode)]);
- Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()]));
+ Controller::applyHook("msg.instant", array($ajxpNode->getContext(), $content, null, null, [$ajxpNode->getPath()]));
}
if(!isSet($httpVars["return_json"])){
@@ -820,12 +820,12 @@ public function switchAction(ServerRequestInterface &$requestInterface, Response
$x = new SerializableResponseStream([new UserMessage($mess["share_center.216"])]);
$responseInterface = $responseInterface->withBody($x);
- Controller::applyHook("msg.instant", array("<reload_shared_elements/>", $ajxpNode->getRepositoryId()));
+ Controller::applyHook("msg.instant", array($ajxpNode->getContext(), "<reload_shared_elements/>"));
if(isSet($httpVars["share_scope"]) && $httpVars["share_scope"] == "public"){
$ajxpNode->loadNodeInfo();
$content = XMLWriter::writeNodesDiff(["UPDATE" => [$ajxpNode->getPath() => $ajxpNode]]);
- Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()]));
+ Controller::applyHook("msg.instant", array($ajxpNode->getContext(), $content, null, null, [$ajxpNode->getPath()]));
}
}
@@ -1494,7 +1494,7 @@ public function createSharedMinisite($httpVars, &$update)
$existingShortForm = $shareObject->getShortFormUrl();
if(empty($existingShortForm)){
$shortForm = "";
- Controller::applyHook("url.shorten", array($url, &$shortForm));
+ Controller::applyHook("url.shorten", array($this->currentContext, $url, &$shortForm));
if(!empty($shortForm)){
$shareObject->setShortFormUrl($shortForm);
$shareObject->save();
@@ -1708,7 +1708,7 @@ public function shareNode(ContextInterface $ctx, $ajxpNode, $httpVars, &$update)
$existingShortForm = $shareObject->getShortFormUrl();
if(empty($existingShortForm)){
$shortForm = "";
- Controller::applyHook("url.shorten", array($url, &$shortForm));
+ Controller::applyHook("url.shorten", array($ctx, $url, &$shortForm));
if(!empty($shortForm)){
$shareObject->setShortFormUrl($shortForm);
$shareObject->save();
@@ -323,7 +323,7 @@ public function checkPassword($login, $pass, $seed)
if ($this->drivers[$this->masterName]->userExists($login)) {
// check master, and refresh slave if necessary
if ($this->drivers[$this->masterName]->checkPassword($login, $pass, $seed)) {
- if($this->getFilteredOption("CACHE_MASTER_USERS_TO_SLAVE")){
+ if($this->getContextualOption(\Pydio\Core\Model\Context::emptyContext(), "CACHE_MASTER_USERS_TO_SLAVE")){
if ($this->drivers[$this->slaveName]->userExists($login)) {
$this->drivers[$this->slaveName]->changePassword($login, $pass);
} else {
@@ -332,7 +332,7 @@ public function checkPassword($login, $pass, $seed)
}
return true;
} else {
- if(!$this->getFilteredOption("CACHE_MASTER_USERS_TO_SLAVE") && $this->drivers[$this->slaveName]->userExists($login)){
+ if(!$this->getContextualOption(\Pydio\Core\Model\Context::emptyContext(), "CACHE_MASTER_USERS_TO_SLAVE") && $this->drivers[$this->slaveName]->userExists($login)){
// User may in fact be a SLAVE user
return $this->drivers[$this->slaveName]->checkPassword($login, $pass, $seed);
}
@@ -108,9 +108,10 @@ public function init(ContextInterface $ctx, $options = [])
}
private function initCacheWithNamespace($namespace){
- $cacheDriver = null;
- $driverOptions = $this->getFilteredOption("DRIVER");
- $cachePrefix = $this->getFilteredOption("CACHE_PREFIX");
+ $cacheDriver = null;
+ $emptyContext = \Pydio\Core\Model\Context::emptyContext();
+ $driverOptions = $this->getContextualOption($emptyContext, "DRIVER");
+ $cachePrefix = $this->getContextualOption($emptyContext, "CACHE_PREFIX");
if(!is_array($driverOptions) || !isset($driverOptions['driver'])){
return null;
@@ -472,6 +472,14 @@ public function getRealFile()
}
/**
+ * Check if node wrapper is local or remote
+ * @return bool
+ */
+ public function wrapperIsRemote(){
+ return AJXP_MetaStreamWrapper::wrapperIsRemote($this->_url);
+ }
+
+ /**
* @return string URL of the node in the form ajxp.protocol://repository_id/path/to/node
*/
public function getUrl()
Oops, something went wrong.

0 comments on commit b547569

Please sign in to comment.