Permalink
Browse files

ShareCenter hooks to workspace.after_delete to clean existing shares.

  • Loading branch information...
1 parent 84cc262 commit 24ce349df924e588ea0ce5f7f9dcf78f6f7e2006 @cdujeu cdujeu committed Sep 24, 2016
@@ -82,16 +82,6 @@ public static function contextWithObjects($userObject, $repositoryObject){
}
/**
- * @return ContextInterface
- */
- public static function fromGlobalServices(){
- $ctx = new Context();
- //$ctx->setUserObject(AuthService::getLoggedUser());
- //$ctx->setRepositoryObject(ConfService::getRepository());
- return $ctx;
- }
-
- /**
* @return Context
*/
public static function emptyContext(){
@@ -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;
@@ -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;
@@ -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();
@@ -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;
@@ -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>
@@ -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

0 comments on commit 24ce349

Please sign in to comment.