Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Change methods static to non-static. Remove dependency to PluginsServ…
Browse files Browse the repository at this point in the history
…ice in Repository, by moving streamWrapper detection to AJXP_MetaStreamWrapper. Remove unnecessary calls to detectStreamWrapper() in all editors / meta plugins.
  • Loading branch information
cdujeu committed Jun 2, 2016
1 parent a3e77b5 commit 4af6e81
Show file tree
Hide file tree
Showing 27 changed files with 154 additions and 193 deletions.
22 changes: 13 additions & 9 deletions core/src/core/src/pydio/Core/Model/RepositoryInterface.php
Expand Up @@ -22,6 +22,7 @@

defined('AJXP_EXEC') or die('Access not allowed');

use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\Filter\ContentFilter;


Expand All @@ -33,6 +34,17 @@
*/
interface RepositoryInterface
{

/**
* @return AbstractAccessDriver
*/
public function getDriverInstance();

/**
* @param AbstractAccessDriver $driverInstance
*/
public function setDriverInstance($driverInstance);

/**
* @param ContentFilter $contentFilter
*/
Expand Down Expand Up @@ -101,15 +113,7 @@ public function setSlug($slug = null);
* @return \DOMElement|\DOMNodeList|string
*/
public function getClientSettings();

/**
* Find the streamWrapper declared by the access driver
* @param bool $register
* @param array $streams
* @return bool
*/
public function detectStreamWrapper($register = false, &$streams = null);


/**
* Add options
* @param $oName
Expand Down
127 changes: 59 additions & 68 deletions core/src/core/src/pydio/Core/PluginFramework/PluginsService.php
Expand Up @@ -58,35 +58,6 @@ class PluginsService
/* STATIC FUNCTIONS */
/*********************************/

/**
* Build the XML Registry if not already built, and return it.
* @static
* @param bool $extendedVersion
* @return \DOMDocument The registry
*/
public static function getXmlRegistry($extendedVersion = true)
{
$self = self::getInstance();
if (!isSet($self->xmlRegistry) || ($self->registryVersion == "light" && $extendedVersion)) {
$self->buildXmlRegistry( $extendedVersion );
$self->registryVersion = ($extendedVersion ? "extended":"light");
}
return $self->xmlRegistry;
}

/**
* Replace the current xml registry
* @static
* @param $registry
* @param bool $extendedVersion
*/
public static function updateXmlRegistry($registry, $extendedVersion = true)
{
$self = self::getInstance();
$self->xmlRegistry = $registry;
$self->registryVersion = ($extendedVersion? "extended" : "light");
}

/**
* Search all plugins manifest with an XPath query, and return either the Nodes, or directly an XML string.
* @param string $query
Expand Down Expand Up @@ -147,21 +118,7 @@ public static function clearPluginsCache(){
}

/**
* Add a plugin to the list of active plugins
* @static
* @param string $type
* @param string $name
* @param bool $active
* @param Plugin $updateInstance
* @return void
*/
public static function setPluginActive($type, $name, $active=true, $updateInstance = null)
{
self::getInstance()->setPluginActiveInst($type, $name, $active, $updateInstance);
}

/**
*
* Find a plugin by its type/name
* @param string $type
* @param string $name
* @return Plugin
Expand Down Expand Up @@ -224,6 +181,36 @@ public static function searchManifestsWithCache($query, $callback, $typeChecker
/* PUBLIC FUNCTIONS */
/*********************************/


/**
* Build the XML Registry if not already built, and return it.
* @static
* @param bool $extendedVersion
* @return \DOMDocument The registry
*/
public function getXmlRegistry($extendedVersion = true)
{
$self = self::getInstance();
if (!isSet($self->xmlRegistry) || ($self->registryVersion == "light" && $extendedVersion)) {
$self->buildXmlRegistry( $extendedVersion );
$self->registryVersion = ($extendedVersion ? "extended":"light");
}
return $self->xmlRegistry;
}

/**
* Replace the current xml registry
* @static
* @param $registry
* @param bool $extendedVersion
*/
public function updateXmlRegistry($registry, $extendedVersion = true)
{
$self = self::getInstance();
$self->xmlRegistry = $registry;
$self->registryVersion = ($extendedVersion? "extended" : "light");
}

/**
* @param string $plugType
* @param string $plugName
Expand All @@ -240,7 +227,8 @@ public function getPluginByTypeName($plugType, $plugName)

/**
* Loads the full registry, from the cache only
*
* @param AbstractCacheDriver
* @return bool
*/
public function loadPluginsRegistryFromCache($cacheStorage = null) {

Expand All @@ -252,6 +240,8 @@ public function loadPluginsRegistryFromCache($cacheStorage = null) {
if($this->_loadRegistryFromCache()){
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -392,6 +382,25 @@ public function storeToPluginQueriesCache($key, $value)
/*********************************/
/* PUBLIC: ACTIVE PLUGINS */
/*********************************/

/**
* Set the service in defer mode : do not rebuild
* registry on each plugin activation
*/
public function deferBuildingRegistry(){
$this->tmpDeferRegistryBuild = true;
}

/**
* If service was in defer mode, now build the registry
*/
public function flushDeferredRegistryBuilding(){
$this->tmpDeferRegistryBuild = false;
if (isSet($this->xmlRegistry)) {
$this->buildXmlRegistry(($this->registryVersion == "extended"));
}
}

/**
* Load the plugins list, and set active the plugins automatically,
* except for the specific types that declare a "core.*" plugin. In that case,
Expand Down Expand Up @@ -420,7 +429,7 @@ public function initActivePlugins()
try {
$pObject->performChecks();
if(!$pObject->isEnabled() || $pObject->hasMissingExtensions()) continue;
$this->setPluginActiveInst($pObject->getType(), $pObject->getName(), true);
$this->setPluginActive($pObject->getType(), $pObject->getName(), true);
} catch (\Exception $e) {
//$this->errors[$pName] = "[$pName] ".$e->getMessage();
}
Expand All @@ -429,14 +438,14 @@ public function initActivePlugins()
}

/**
* Instance implementation of the setPluginActive
* Add a plugin to the list of active plugins
* @param $type
* @param $name
* @param bool $active
* @param Plugin $updateInstance
* @return void
*/
public function setPluginActiveInst($type, $name, $active=true, $updateInstance = null)
public function setPluginActive($type, $name, $active=true, $updateInstance = null)
{
if ($active) {
// Check active plugin dependencies
Expand Down Expand Up @@ -468,24 +477,6 @@ public function setPluginActiveInst($type, $name, $active=true, $updateInstance
}
}

/**
* Set the service in defer mode : do not rebuild
* registry on each plugin activation
*/
public function deferBuildingRegistry(){
$this->tmpDeferRegistryBuild = true;
}

/**
* If service was in defer mode, now build the registry
*/
public function flushDeferredRegistryBuilding(){
$this->tmpDeferRegistryBuild = false;
if (isSet($this->xmlRegistry)) {
$this->buildXmlRegistry(($this->registryVersion == "extended"));
}
}

/**
* Some type require only one active plugin at a time
* @param $type
Expand All @@ -499,10 +490,10 @@ public function setPluginUniqueActiveForType($type, $name, $updateInstance = nul
$originalValue = $this->tmpDeferRegistryBuild;
$this->tmpDeferRegistryBuild = true;
foreach ($typePlugs as $plugName => $plugObject) {
$this->setPluginActiveInst($type, $plugName, false);
$this->setPluginActive($type, $plugName, false);
}
$this->tmpDeferRegistryBuild = $originalValue;
$this->setPluginActiveInst($type, $name, true, $updateInstance);
$this->setPluginActive($type, $name, true, $updateInstance);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions core/src/core/src/pydio/Core/Services/ConfService.php
Expand Up @@ -22,6 +22,7 @@

use DOMXPath;
use Pydio\Access\Core\AbstractAccessDriver;
use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\Repository;
use Pydio\Auth\Core\AbstractAuthDriver;
use Pydio\Cache\Core\AbstractCacheDriver;
Expand Down Expand Up @@ -233,6 +234,7 @@ public static function clearAllCaches(){
public static function instanciatePluginFromGlobalParams($globalsArray, $interfaceCheck = "")
{
$plugin = false;
$pService = PluginsService::getInstance();

if (is_string($globalsArray)) {
$globalsArray = array("instance_name" => $globalsArray);
Expand All @@ -242,7 +244,7 @@ public static function instanciatePluginFromGlobalParams($globalsArray, $interfa
$pName = $globalsArray["instance_name"];
unset($globalsArray["instance_name"]);

$plugin = PluginsService::getInstance()->softLoad($pName, $globalsArray);
$plugin = $pService->softLoad($pName, $globalsArray);
$plugin->performChecks();
}

Expand All @@ -252,7 +254,7 @@ public static function instanciatePluginFromGlobalParams($globalsArray, $interfa
}
}
if ($plugin !== false) {
PluginsService::getInstance()->setPluginActive($plugin->getType(), $plugin->getName(), true, $plugin);
$pService->setPluginActive($plugin->getType(), $plugin->getName(), true, $plugin);
}
return $plugin;

Expand Down Expand Up @@ -379,13 +381,15 @@ public static function reloadServicesAndActivePlugins(){

public static function getFilteredXMLRegistry($extendedVersion = true, $clone = false, $useCache = false){

$pluginService = PluginsService::getInstance();

if($useCache){
$cacheKey = self::getRegistryCacheKey($extendedVersion);
$cachedXml = CacheService::fetch(AJXP_CACHE_SERVICE_NS_SHARED, $cacheKey);
if($cachedXml !== false){
$registry = new \DOMDocument("1.0", "utf-8");
$registry->loadXML($cachedXml);
PluginsService::updateXmlRegistry($registry, $extendedVersion);
$pluginService->updateXmlRegistry($registry, $extendedVersion);
if($clone){
return $registry->cloneNode(true);
}else{
Expand All @@ -394,10 +398,10 @@ public static function getFilteredXMLRegistry($extendedVersion = true, $clone =
}
}

$registry = PluginsService::getXmlRegistry($extendedVersion);
$registry = $pluginService->getXmlRegistry($extendedVersion);
$changes = self::filterRegistryFromRole($registry);
if($changes){
PluginsService::updateXmlRegistry($registry, $extendedVersion);
$pluginService->updateXmlRegistry($registry, $extendedVersion);
}

if($useCache && isSet($cacheKey)){
Expand Down Expand Up @@ -981,7 +985,7 @@ public function detectRepositoryStreamsInst($register = false)
$streams = array();
$currentRepos = $this->getLoadedRepositories();
foreach ($currentRepos as $repository) {
$repository->detectStreamWrapper($register, $streams);
AJXP_MetaStreamWrapper::detectWrapperForRepository($repository,$register, $streams);
}
return $streams;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/access.inbox/class.inboxAccessDriver.php
Expand Up @@ -20,6 +20,7 @@
*/
namespace Pydio\Access\Driver\StreamProvider\Inbox;

use Pydio\Access\Core\AJXP_MetaStreamWrapper;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Access\Driver\StreamProvider\FS\fsAccessDriver;
Expand Down Expand Up @@ -87,7 +88,7 @@ public static function getNodeData($nodePath){
$node->getRepository()->driverInstance = null;
try{
ConfService::loadDriverForRepository($node->getRepository());
$node->getRepository()->detectStreamWrapper(true);
AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
if($node->getRepository()->hasContentFilter()){
$node->setLeaf(true);
}
Expand Down Expand Up @@ -166,8 +167,7 @@ public static function getNodes($checkStats = false, $touch = true){
$ext = "error";
$meta["ajxp_mime"] = "error";
}
$node->getRepository()->detectStreamWrapper(true);

AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
$stat = @stat($url);
if($stat === false){
$ext = "error";
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/access.inbox/class.inboxAccessWrapper.php
Expand Up @@ -149,7 +149,7 @@ public static function translateURL($path){
}catch (\Exception $e){

}
$node->getRepository()->detectStreamWrapper(true);
AJXP_MetaStreamWrapper::detectWrapperForRepository($node->getRepository(), true);
}
return $url;
}
Expand Down
3 changes: 0 additions & 3 deletions core/src/plugins/action.timestamp/class.TimestampCreator.php
Expand Up @@ -39,9 +39,6 @@ public function switchAction(\Psr\Http\Message\ServerRequestInterface $requestIn

//Get active repository
$repository = ConfService::getRepository();
if (!$repository->detectStreamWrapper(true)) {
return false;
}
$selection = new UserSelection($repository, $requestInterface->getParsedBody());
$destStreamURL = $selection->currentBaseUrl();

Expand Down

0 comments on commit 4af6e81

Please sign in to comment.