Permalink
Browse files

Fix sharing and watches.

  • Loading branch information...
1 parent b8282a9 commit a5c78730f9091b157b65d60add5bfdfdd9237724 @cdujeu cdujeu committed Jun 10, 2016
@@ -364,7 +364,7 @@ private static function applyCallback($context, $callback, &$variableArgs, $defe
*/
private static function handleRequest($callback, ServerRequestInterface &$request, ResponseInterface &$response){
- list($plugInstance, $methodName) = self::parseCallback($callback);
+ list($plugInstance, $methodName) = self::parseCallback($request->getAttribute("ctx"), $callback);
$reflectMethod = new \ReflectionMethod($plugInstance, $methodName);
$reflectParams = $reflectMethod->getParameters();
@@ -400,15 +400,15 @@ private static function handleRequest($callback, ServerRequestInterface &$reques
* @throws PydioException
* @return array
*/
- private static function parseCallback($callback){
+ private static function parseCallback(ContextInterface $ctx, $callback){
if(is_array($callback)){
$plugId = $callback["pluginId"];
$methodName = $callback["methodName"];
}else{
$plugId = $callback->getAttribute("pluginId");
$methodName = $callback->getAttribute("methodName");
}
- $plugInstance = PluginsService::findPluginById($plugId);
+ $plugInstance = PluginsService::getInstance($ctx)->getPluginById($plugId);
if(empty($plugInstance) || !method_exists($plugInstance, $methodName)){
throw new PydioException("Cannot find method $methodName for plugin $plugId!");
}
@@ -22,6 +22,7 @@
use Pydio\Access\Core\Model\Repository;
use Pydio\Core\Controller\Controller;
+use Pydio\Core\Model\Context;
use Pydio\Core\Model\FilteredRepositoriesList;
use Pydio\Core\Model\RepositoryInterface;
use Pydio\Core\Model\UserInterface;
@@ -420,13 +421,13 @@ private function createRepositoryFromArrayInst($index, $repository)
*/
private function addRepositoryInst($oRepository)
{
- Controller::applyHook("workspace.before_create", array($oRepository));
+ Controller::applyHook("workspace.before_create", array(Context::fromGlobalServices(), $oRepository));
$confStorage = ConfService::getConfStorageImpl();
$res = $confStorage->saveRepository($oRepository);
if ($res == -1) {
return $res;
}
- Controller::applyHook("workspace.after_create", array($oRepository));
+ Controller::applyHook("workspace.after_create", array(Context::fromGlobalServices(), $oRepository));
AJXP_Logger::info(__CLASS__,"Create Repository", array("repo_name"=>$oRepository->getDisplay()));
CacheService::save(AJXP_CACHE_SERVICE_NS_SHARED, "repository:".$oRepository->getId(), $oRepository);
// TODO ?
@@ -459,13 +460,13 @@ private function getRepositoryByAliasInstDefaults($repoAlias)
*/
private function replaceRepositoryInst($oldId, $oRepositoryObject)
{
- Controller::applyHook("workspace.before_update", array($oRepositoryObject));
+ Controller::applyHook("workspace.before_update", array(Context::fromGlobalServices(), $oRepositoryObject));
$confStorage = ConfService::getConfStorageImpl();
$res = $confStorage->saveRepository($oRepositoryObject, true);
if ($res == -1) {
return -1;
}
- Controller::applyHook("workspace.after_update", array($oRepositoryObject));
+ Controller::applyHook("workspace.after_update", array(Context::fromGlobalServices(), $oRepositoryObject));
AJXP_Logger::info(__CLASS__,"Edit Repository", array("repo_name"=>$oRepositoryObject->getDisplay()));
// TODO ?
//$this->invalidateLoadedRepositories();
@@ -480,7 +481,7 @@ private function replaceRepositoryInst($oldId, $oRepositoryObject)
*/
private function deleteRepositoryInst($repoId)
{
- Controller::applyHook("workspace.before_delete", array($repoId));
+ Controller::applyHook("workspace.before_delete", array(Context::fromGlobalServices(), $repoId));
$confStorage = ConfService::getConfStorageImpl();
$shares = $confStorage->listRepositoriesWithCriteria(array("parent_uuid" => $repoId));
$toDelete = array();
@@ -494,7 +495,7 @@ private function deleteRepositoryInst($repoId)
foreach($toDelete as $deleteId){
$this->deleteRepositoryInst($deleteId);
}
- Controller::applyHook("workspace.after_delete", array($repoId));
+ Controller::applyHook("workspace.after_delete", array(Context::fromGlobalServices(), $repoId));
AJXP_Logger::info(__CLASS__,"Delete Repository", array("repo_id"=>$repoId));
// TODO ?
//$this->invalidateLoadedRepositories();
@@ -2576,7 +2576,7 @@ protected function getDriverLabel($pluginId, &$labels){
if(isSet($labels[$pluginId])){
return $labels[$pluginId];
}
- $plugin = PluginsService::findPluginById("access.".$pluginId);
+ $plugin = PluginsService::getInstance(Context::emptyContext())->getPluginById("access.".$pluginId);
if(!is_object($plugin)) {
$label = "access.$plugin (plugin disabled!)";
}else{
@@ -2169,7 +2169,7 @@ public function recursivePurge($dirName, $hardPurgeTime, $softPurgeTime = 0)
$handle=opendir($dirName);
$shareCenter = false;
if(class_exists("\\Pydio\\Share\\ShareCenter")){
- $shareCenter = \Pydio\Share\ShareCenter::getShareCenter();
+ $shareCenter = \Pydio\Share\ShareCenter::getShareCenter(AJXP_Node::contextFromUrl($dirName));
}
if($handle === false){
$this->logError(__FUNCTION__, "Cannot open folder ".$dirName);
@@ -27,6 +27,7 @@
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Core\Model\UserSelection;
+use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
@@ -47,9 +48,21 @@
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Class LegacyPubliclet
+ * Model for links generated in old versions of Pydio when they
+ * were stored in small php files on disk instead of inside Database
+ *
+ * @package Pydio\Share\Legacy
+ */
class LegacyPubliclet
{
+ /**
+ * @param $data
+ * @param $hash
+ * @param null $message
+ */
private static function renderError($data, $hash, $message = null){
MinisiteRenderer::renderError($data, $hash, $message);
}
@@ -96,7 +109,7 @@ public static function publicletToJson(ContextInterface $ctx, $shareId, $shareMe
$link = $publicAccessManager->buildPublicLink($shareId);
}
if ($watcher != false && $node != null) {
- $result = array();
+ $result = [];
$elementWatch = $watcher->hasWatchOnNode(
$node,
$ctx->getUser()->getId(),
@@ -107,7 +120,7 @@ public static function publicletToJson(ContextInterface $ctx, $shareId, $shareMe
$elementWatch = false;
}
}
- $jsonData = array_merge(array(
+ $jsonData = array_merge([
"element_id" => $shareId,
"publiclet_link" => $link,
"download_counter" => 0,
@@ -116,7 +129,7 @@ public static function publicletToJson(ContextInterface $ctx, $shareId, $shareMe
"has_password" => (!empty($pData["PASSWORD"])),
"element_watch" => $elementWatch,
"is_expired" => ShareLink::isShareExpired($pData)
- ), $shareMeta);
+ ], $shareMeta);
return $jsonData;
}
@@ -205,7 +218,7 @@ public static function migrateLegacyMeta(ContextInterface $ctx, $shareCenter, $s
try{
$link = new ShareLink($shareStore);
$link->setOwnerId($userName);
- $parameters = array("custom_handle" => $element, "simple_right_download" => true);
+ $parameters = ["custom_handle" => $element, "simple_right_download" => true];
if(isSet($publiclet["EXPIRE_TIME"])) $parameters["expiration"] = $publiclet["EXPIRE_TIME"];
if(isSet($publiclet["DOWNLOAD_LIMIT"])) $parameters["downloadlimit"] = $publiclet["DOWNLOAD_LIMIT"];
$link->parseHttpVars($parameters);
@@ -217,12 +230,14 @@ public static function migrateLegacyMeta(ContextInterface $ctx, $shareCenter, $s
/**
* @var AbstractAccessDriver $driverInstance
*/
- $driverInstance = PluginsService::findPlugin("access", $parentRepositoryObject->getAccessType());
+ $currentContext = new Context($userName);
+ $currentContext->setRepositoryObject($parentRepositoryObject);
+ $driverInstance = PluginsService::getInstance($currentContext)->findPlugin("access", $parentRepositoryObject->getAccessType());
if(empty($driverInstance)){
print("\n-- ERROR: Cannot find driver instance!");
continue;
}
- $options = $driverInstance->makeSharedRepositoryOptions(["file" => "/"], $parentRepositoryObject);
+ $options = $driverInstance->makeSharedRepositoryOptions($currentContext, ["file" => "/"]);
$options["SHARE_ACCESS"] = "private";
$newRepo = $parentRepositoryObject->createSharedChild(
basename($filePath),
@@ -268,7 +283,7 @@ public static function migrateLegacyMeta(ContextInterface $ctx, $shareCenter, $s
}
// UPDATE METADATA
- $meta["ajxp_shared"] = ["shares" => [$element => array("type" => "minisite")]];
+ $meta["ajxp_shared"] = ["shares" => [$element => ["type" => "minisite"]]];
}catch(\Exception $e){
print("\n-- ERROR: ".$e->getMessage());
@@ -292,7 +307,7 @@ public static function migrateLegacyMeta(ContextInterface $ctx, $shareCenter, $s
if($repo !== null){
print("\n--Shared repository: just metadata");
// Shared repo, migrating the meta should be enough
- $meta["ajxp_shared"] = array("shares" => [$element => array("type" => "repository")]);
+ $meta["ajxp_shared"] = ["shares" => [$element => ["type" => "repository"]]];
}
}
}
@@ -31,6 +31,7 @@
use Pydio\Access\Core\Model\NodesList;
use Pydio\Access\Core\Model\Repository;
use Pydio\Access\Core\Model\UserSelection;
+use Pydio\Core\Controller\CliRunner;
use Pydio\Core\Http\Message\UserMessage;
use Pydio\Core\Http\Response\SerializableResponseStream;
use Pydio\Core\Model\Context;
@@ -188,6 +189,11 @@ protected function parseSpecificContributions(ContextInterface $ctx, \DOMNode &$
/**************************/
/* PUBLIC LINKS ROUTER
/**************************/
+ /**
+ * @param $serverBase
+ * @param $route
+ * @param $params
+ */
public static function publicRoute($serverBase, $route, $params){
if(isSet($params["hash"])){
@@ -256,10 +262,21 @@ protected function getAuthorization(ContextInterface $ctx, $nodeType, $shareType
/**
* @return ShareCenter
*/
- public static function getShareCenter(){
- return PluginsService::findPluginById("action.share");
+ public static function getShareCenter(ContextInterface $ctx = null){
+ if($ctx === null){
+ $ctx = Context::emptyContext();
+ }
+ /** @var ShareCenter $shareCenter */
+ $shareCenter = PluginsService::getInstance($ctx)->getPluginById("action.share");
+ if(empty($shareCenter->currentContext)){
+ $shareCenter->currentContext = $ctx;
+ }
+ return $shareCenter;
}
+ /**
+ * @return bool
+ */
public static function currentContextIsLinkDownload(){
return (isSet($_GET["dl"]) && isSet($_GET["dl"]) == "true");
}
@@ -393,8 +410,14 @@ protected function checkRepoWithSameLabel($label, $editingRepo = null){
return false;
}
+ /**
+ * @param $childRepoId
+ * @param $userId
+ * @param bool $toggle
+ * @param null $parentUserId
+ */
protected function toggleWatchOnSharedRepository($childRepoId, $userId, $toggle = true, $parentUserId = null){
- if ($this->watcher === false || !$this->currentContext->hasUser() == null) {
+ if ($this->watcher === false || !$this->currentContext->hasUser()) {
return;
}
$rootNode = new AJXP_Node("pydio://".$userId."@".$childRepoId."/");
@@ -1118,6 +1141,13 @@ private function findMirrorNodesInShares($node, $direction){
return $result;
}
+ /**
+ * @param null $fromMirrors
+ * @param null $toMirrors
+ * @param bool $copy
+ * @param null $direction
+ * @throws \Exception
+ */
private function applyForwardEvent($fromMirrors = null, $toMirrors = null, $copy = false, $direction = null){
if($fromMirrors === null){
// Create
@@ -1171,7 +1201,7 @@ public function forwardEventToShares($fromNode=null, $toNode=null, $copy = false
$refNode = ($fromNode != null ? $fromNode : $toNode);// cannot be both null
if(empty($direction) && $this->getContextualOption($refNode->getContext(), "FORK_EVENT_FORWARDING")){
- OCS::applyActionInBackground(
+ CliRunner::applyActionInBackground(
$refNode->getContext(),
"forward_change_event",
array(
@@ -1207,6 +1237,11 @@ public function forwardEventToShares($fromNode=null, $toNode=null, $copy = false
}
}
+ /**
+ * @param $actionName
+ * @param $httpVars
+ * @param $fileVars
+ */
public function forwardEventToSharesAction($actionName, $httpVars, $fileVars){
$fromMirrors = null;
@@ -1260,7 +1295,7 @@ public static function loadShareByHash($hash){
if(isSet($_GET["lang"])){
LocaleService::setLanguage($_GET["lang"]);
}
- $shareCenter = self::getShareCenter();
+ $shareCenter = self::getShareCenter(Context::emptyContext());
$data = $shareCenter->getShareStore()->loadShare($hash);
$mess = LocaleService::getMessages();
if($data === false){
@@ -1298,7 +1333,7 @@ public static function loadShareByHash($hash){
*/
public static function loadPubliclet($data)
{
- $shareCenter = self::getShareCenter();
+ $shareCenter = self::getShareCenter(Context::emptyContext());
$options = $shareCenter->getConfigs();
$shareStore = $shareCenter->getShareStore();
LegacyPubliclet::render($data, $options, $shareStore);
@@ -33,22 +33,46 @@
use Pydio\Core\Controller\XMLWriter;
use Pydio\Core\Controller\HTMLWriter;
use Pydio\Core\PluginFramework\PluginsService;
+use Pydio\Share\ShareCenter;
defined('AJXP_EXEC') or die('Access not allowed');
+/**
+ * Class MinisiteRenderer
+ * View class to load a share and display it as a minisite
+ *
+ * @package Pydio\Share\View
+ */
class MinisiteRenderer
{
+ /**
+ * Render a simple error instead of the minisite
+ * @param $data
+ * @param string $hash
+ * @param null $error
+ */
public static function renderError($data, $hash = '', $error = null){
self::loadMinisite($data, $hash, $error);
}
+ /**
+ * Load the minisite
+ *
+ * @param $data
+ * @param string $hash
+ * @param null $error
+ * @throws \Exception
+ * @throws \Pydio\Core\Exception\LoginException
+ * @throws \Pydio\Core\Exception\WorkspaceNotFoundException
+ */
public static function loadMinisite($data, $hash = '', $error = null)
{
$repository = $data["REPOSITORY"];
$confs = [];
- PluginsService::getInstance(Context::emptyContext())->initActivePlugins();
- $shareCenter = PluginsService::findPlugin("action", "share");
+ $ctx = Context::emptyContext();
+ PluginsService::getInstance($ctx)->initActivePlugins();
+ $shareCenter = ShareCenter::getShareCenter($ctx);
if($shareCenter !== false){
$confs = $shareCenter->getConfigs();
}
@@ -90,7 +114,7 @@ public static function loadMinisite($data, $hash = '', $error = null)
}
// UPDATE TEMPLATE
$html = file_get_contents(AJXP_INSTALL_PATH."/".AJXP_PLUGINS_FOLDER."/action.share/res/minisite.php");
- Controller::applyHook("tpl.filter_html", array(Context::emptyContext(), &$html));
+ Controller::applyHook("tpl.filter_html", [$ctx, &$html]);
$html = XMLWriter::replaceAjxpXmlKeywords($html);
$html = str_replace("AJXP_MINISITE_LOGO", $minisiteLogo, $html);
$html = str_replace("AJXP_APPLICATION_TITLE", ConfService::getCoreConf("APPLICATION_TITLE"), $html);
@@ -102,7 +126,7 @@ public static function loadMinisite($data, $hash = '', $error = null)
$html = str_replace('AJXP_HASH_LOAD_ERROR', isSet($error)?$error:'', $html);
$html = str_replace("AJXP_TEMPLATE_NAME", $templateName, $html);
$html = str_replace("AJXP_LINK_HASH", $hash, $html);
- $guiConfigs = PluginsService::findPluginById("gui.ajax")->getConfigs();
+ $guiConfigs = PluginsService::getInstance($ctx)->findPluginById("gui.ajax")->getConfigs();
$html = str_replace("AJXP_THEME", $guiConfigs["GUI_THEME"] , $html);
if(isSet($_GET["dl"]) && isSet($_GET["file"])){
@@ -64,7 +64,7 @@ public function init(ContextInterface $ctx, $options = [])
$options = $def["OPTIONS"];
$options["TRANSMIT_CLEAR_PASS"] = $this->options["TRANSMIT_CLEAR_PASS"];
$options["LOGIN_REDIRECT"] = $this->options["LOGIN_REDIRECT"];
- $instance = PluginsService::findPlugin("auth", $name);
+ $instance = PluginsService::getInstance($ctx)->getPluginByTypeName("auth", $name);
if (!is_object($instance)) {
throw new Exception("Cannot find plugin $name for type 'auth'");
}
Oops, something went wrong.

0 comments on commit a5c7873

Please sign in to comment.