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

Commit

Permalink
ShareCenter hooks to workspace.after_delete to clean existing shares.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 24, 2016
1 parent 84cc262 commit 24ce349
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
10 changes: 0 additions & 10 deletions core/src/core/src/pydio/Core/Model/Context.php
Expand Up @@ -81,16 +81,6 @@ public static function contextWithObjects($userObject, $repositoryObject){
return $ctx;
}

/**
* @return ContextInterface
*/
public static function fromGlobalServices(){
$ctx = new Context();
//$ctx->setUserObject(AuthService::getLoggedUser());
//$ctx->setRepositoryObject(ConfService::getRepository());
return $ctx;
}

/**
* @return Context
*/
Expand Down
12 changes: 6 additions & 6 deletions core/src/core/src/pydio/Core/Services/RepositoryService.php
Expand Up @@ -432,13 +432,13 @@ private function createRepositoryFromArrayInst($index, $repository)
*/
private function addRepositoryInst($oRepository)
{
Controller::applyHook("workspace.before_create", array(Context::fromGlobalServices(), $oRepository));
Controller::applyHook("workspace.before_create", array(Context::emptyContext(), $oRepository));
$confStorage = ConfService::getConfStorageImpl();
$res = $confStorage->saveRepository($oRepository);
if ($res == -1) {
return $res;
}
Controller::applyHook("workspace.after_create", array(Context::fromGlobalServices(), $oRepository));
Controller::applyHook("workspace.after_create", array(Context::emptyContext(), $oRepository));
Logger::info(__CLASS__,"Create Repository", array("repo_name"=>$oRepository->getDisplay()));
CacheService::saveWithTimestamp(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:".$oRepository->getId(), $oRepository);
return null;
Expand Down Expand Up @@ -469,13 +469,13 @@ private function getRepositoryByAliasInstDefaults($repoAlias)
*/
private function replaceRepositoryInst($oldId, $oRepositoryObject)
{
Controller::applyHook("workspace.before_update", array(Context::fromGlobalServices(), $oRepositoryObject));
Controller::applyHook("workspace.before_update", array(Context::emptyContext(), $oRepositoryObject));
$confStorage = ConfService::getConfStorageImpl();
$res = $confStorage->saveRepository($oRepositoryObject, true);
if ($res == -1) {
return -1;
}
Controller::applyHook("workspace.after_update", array(Context::fromGlobalServices(), $oRepositoryObject));
Controller::applyHook("workspace.after_update", array(Context::emptyContext(), $oRepositoryObject));
Logger::info(__CLASS__,"Edit Repository", array("repo_name"=>$oRepositoryObject->getDisplay()));
CacheService::saveWithTimestamp(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:" . $oRepositoryObject->getId(), $oRepositoryObject);
return 0;
Expand All @@ -488,7 +488,7 @@ private function replaceRepositoryInst($oldId, $oRepositoryObject)
*/
private function deleteRepositoryInst($repoId)
{
Controller::applyHook("workspace.before_delete", array(Context::fromGlobalServices(), $repoId));
Controller::applyHook("workspace.before_delete", array(Context::emptyContext(), $repoId));
$confStorage = ConfService::getConfStorageImpl();
$shares = $confStorage->listRepositoriesWithCriteria(array("parent_uuid" => $repoId));
$toDelete = array();
Expand All @@ -502,7 +502,7 @@ private function deleteRepositoryInst($repoId)
foreach($toDelete as $deleteId){
$this->deleteRepositoryInst($deleteId);
}
Controller::applyHook("workspace.after_delete", array(Context::fromGlobalServices(), $repoId));
Controller::applyHook("workspace.after_delete", array(Context::emptyContext(), $repoId));
Logger::info(__CLASS__,"Delete Repository", array("repo_id"=>$repoId));
CacheService::delete(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:".$repoId);
return 0;
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/action.share/manifest.xml
Expand Up @@ -443,6 +443,7 @@
<serverCallback hookName="node.info.nocache" methodName="nodeSharedMetadata"/>
<serverCallback hookName="node.change" methodName="updateNodeSharedData"/>
<serverCallback hookName="user.after_delete" methodName="cleanUserShares" defer="true"/>
<serverCallback hookName="workspace.after_delete" methodName="cleanWorkspaceShares" defer="true"/>
<serverCallback methodName="forwardEventToShares" hookName="node.change" defer="true"/>
</hooks>
</registry_contributions>
Expand Down
16 changes: 15 additions & 1 deletion core/src/plugins/action.share/src/ShareCenter.php
Expand Up @@ -1166,15 +1166,29 @@ public function updateNodeSharedData($oldNode=null, $newNode=null, $copy = false
/**
* Hook user.after_delete
* make sure to clear orphan shares
* @param ContextInterface $ctx
* @param String $userId
*/
public function cleanUserShares($userId){
public function cleanUserShares($ctx, $userId){
$shares = $this->getShareStore()->listShares($userId);
foreach($shares as $hash => $data){
$this->getShareStore()->deleteShare($data['SHARE_TYPE'], $hash, false, true);
}
}

/**
* Hook workspace.delete
* make sure to clear shares
* @param ContextInterface $ctx
* @param String $workspaceId
*/
public function cleanWorkspaceShares($ctx, $workspaceId){
$shares = $this->getShareStore($ctx)->listShares('', $workspaceId);
foreach($shares as $hash => $data){
$this->getShareStore($ctx)->deleteShare($data['SHARE_TYPE'], $hash, false, true);
}
}


/************************************/
/* EVENTS FORWARDING BETWEEN
Expand Down

0 comments on commit 24ce349

Please sign in to comment.