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

Commit 24ce349

Browse files
committed
ShareCenter hooks to workspace.after_delete to clean existing shares.
1 parent 84cc262 commit 24ce349

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

core/src/core/src/pydio/Core/Model/Context.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ public static function contextWithObjects($userObject, $repositoryObject){
8181
return $ctx;
8282
}
8383

84-
/**
85-
* @return ContextInterface
86-
*/
87-
public static function fromGlobalServices(){
88-
$ctx = new Context();
89-
//$ctx->setUserObject(AuthService::getLoggedUser());
90-
//$ctx->setRepositoryObject(ConfService::getRepository());
91-
return $ctx;
92-
}
93-
9484
/**
9585
* @return Context
9686
*/

core/src/core/src/pydio/Core/Services/RepositoryService.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,13 @@ private function createRepositoryFromArrayInst($index, $repository)
432432
*/
433433
private function addRepositoryInst($oRepository)
434434
{
435-
Controller::applyHook("workspace.before_create", array(Context::fromGlobalServices(), $oRepository));
435+
Controller::applyHook("workspace.before_create", array(Context::emptyContext(), $oRepository));
436436
$confStorage = ConfService::getConfStorageImpl();
437437
$res = $confStorage->saveRepository($oRepository);
438438
if ($res == -1) {
439439
return $res;
440440
}
441-
Controller::applyHook("workspace.after_create", array(Context::fromGlobalServices(), $oRepository));
441+
Controller::applyHook("workspace.after_create", array(Context::emptyContext(), $oRepository));
442442
Logger::info(__CLASS__,"Create Repository", array("repo_name"=>$oRepository->getDisplay()));
443443
CacheService::saveWithTimestamp(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:".$oRepository->getId(), $oRepository);
444444
return null;
@@ -469,13 +469,13 @@ private function getRepositoryByAliasInstDefaults($repoAlias)
469469
*/
470470
private function replaceRepositoryInst($oldId, $oRepositoryObject)
471471
{
472-
Controller::applyHook("workspace.before_update", array(Context::fromGlobalServices(), $oRepositoryObject));
472+
Controller::applyHook("workspace.before_update", array(Context::emptyContext(), $oRepositoryObject));
473473
$confStorage = ConfService::getConfStorageImpl();
474474
$res = $confStorage->saveRepository($oRepositoryObject, true);
475475
if ($res == -1) {
476476
return -1;
477477
}
478-
Controller::applyHook("workspace.after_update", array(Context::fromGlobalServices(), $oRepositoryObject));
478+
Controller::applyHook("workspace.after_update", array(Context::emptyContext(), $oRepositoryObject));
479479
Logger::info(__CLASS__,"Edit Repository", array("repo_name"=>$oRepositoryObject->getDisplay()));
480480
CacheService::saveWithTimestamp(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:" . $oRepositoryObject->getId(), $oRepositoryObject);
481481
return 0;
@@ -488,7 +488,7 @@ private function replaceRepositoryInst($oldId, $oRepositoryObject)
488488
*/
489489
private function deleteRepositoryInst($repoId)
490490
{
491-
Controller::applyHook("workspace.before_delete", array(Context::fromGlobalServices(), $repoId));
491+
Controller::applyHook("workspace.before_delete", array(Context::emptyContext(), $repoId));
492492
$confStorage = ConfService::getConfStorageImpl();
493493
$shares = $confStorage->listRepositoriesWithCriteria(array("parent_uuid" => $repoId));
494494
$toDelete = array();
@@ -502,7 +502,7 @@ private function deleteRepositoryInst($repoId)
502502
foreach($toDelete as $deleteId){
503503
$this->deleteRepositoryInst($deleteId);
504504
}
505-
Controller::applyHook("workspace.after_delete", array(Context::fromGlobalServices(), $repoId));
505+
Controller::applyHook("workspace.after_delete", array(Context::emptyContext(), $repoId));
506506
Logger::info(__CLASS__,"Delete Repository", array("repo_id"=>$repoId));
507507
CacheService::delete(AJXP_CACHE_SERVICE_NS_SHARED, "pydio:repository:".$repoId);
508508
return 0;

core/src/plugins/action.share/manifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
<serverCallback hookName="node.info.nocache" methodName="nodeSharedMetadata"/>
444444
<serverCallback hookName="node.change" methodName="updateNodeSharedData"/>
445445
<serverCallback hookName="user.after_delete" methodName="cleanUserShares" defer="true"/>
446+
<serverCallback hookName="workspace.after_delete" methodName="cleanWorkspaceShares" defer="true"/>
446447
<serverCallback methodName="forwardEventToShares" hookName="node.change" defer="true"/>
447448
</hooks>
448449
</registry_contributions>

core/src/plugins/action.share/src/ShareCenter.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,15 +1166,29 @@ public function updateNodeSharedData($oldNode=null, $newNode=null, $copy = false
11661166
/**
11671167
* Hook user.after_delete
11681168
* make sure to clear orphan shares
1169+
* @param ContextInterface $ctx
11691170
* @param String $userId
11701171
*/
1171-
public function cleanUserShares($userId){
1172+
public function cleanUserShares($ctx, $userId){
11721173
$shares = $this->getShareStore()->listShares($userId);
11731174
foreach($shares as $hash => $data){
11741175
$this->getShareStore()->deleteShare($data['SHARE_TYPE'], $hash, false, true);
11751176
}
11761177
}
11771178

1179+
/**
1180+
* Hook workspace.delete
1181+
* make sure to clear shares
1182+
* @param ContextInterface $ctx
1183+
* @param String $workspaceId
1184+
*/
1185+
public function cleanWorkspaceShares($ctx, $workspaceId){
1186+
$shares = $this->getShareStore($ctx)->listShares('', $workspaceId);
1187+
foreach($shares as $hash => $data){
1188+
$this->getShareStore($ctx)->deleteShare($data['SHARE_TYPE'], $hash, false, true);
1189+
}
1190+
}
1191+
11781192

11791193
/************************************/
11801194
/* EVENTS FORWARDING BETWEEN

0 commit comments

Comments
 (0)