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

Commit

Permalink
Throw error on not found remote shares (when accepting / refusing)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Aug 24, 2016
1 parent 6e20d2f commit 2010759
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions core/src/plugins/core.ocs/src/ActionsController.php
Expand Up @@ -23,6 +23,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Pydio\Cache\Core\CacheStreamLayer;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Model\Context;
use Pydio\Core\Model\ContextInterface;
use Pydio\Core\Services\ConfService;
Expand Down Expand Up @@ -51,13 +52,15 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$remoteShareId = InputFilter::sanitize($httpVars["remote_share_id"], InputFilter::SANITIZE_ALPHANUM);
$store = new SQLStore();
$remoteShare = $store->remoteShareById($remoteShareId);
if($remoteShare !== null){
$client = new OCSClient();
$client->acceptInvitation($remoteShare);
$remoteShare->setStatus(OCS_INVITATION_STATUS_ACCEPTED);
$store->storeRemoteShare($remoteShare);
if($remoteShare === null){
throw new PydioException("Cannot find remote share with ID ".$remoteShareId);
}


$client = new OCSClient();
$client->acceptInvitation($remoteShare);
$remoteShare->setStatus(OCS_INVITATION_STATUS_ACCEPTED);
$store->storeRemoteShare($remoteShare);

$urlBase = $ctx->getUrlBase();

CacheStreamLayer::clearDirCache($urlBase);
Expand All @@ -73,17 +76,19 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
$remoteShareId = InputFilter::sanitize($httpVars["remote_share_id"], InputFilter::SANITIZE_ALPHANUM);
$store = new SQLStore();
$remoteShare = $store->remoteShareById($remoteShareId);
if($remoteShare !== null){
$client = new OCSClient();
try {
$client->declineInvitation($remoteShare);
} catch (\Exception $e) {
// If the reject fails, we still want the share to be removed from the db
Logger::error(__CLASS__,"Exception",$e->getMessage());
}
$store->deleteRemoteShare($remoteShare);
ConfService::getInstance()->invalidateLoadedRepositories();
if($remoteShare === null){
throw new PydioException("Cannot find remote share with ID ".$remoteShareId);
}

$client = new OCSClient();
try {
$client->declineInvitation($remoteShare);
} catch (\Exception $e) {
// If the reject fails, we still want the share to be removed from the db
Logger::error(__CLASS__,"Exception",$e->getMessage());
}
$store->deleteRemoteShare($remoteShare);
ConfService::getInstance()->invalidateLoadedRepositories();

$urlBase = $ctx->getUrlBase();

Expand Down

0 comments on commit 2010759

Please sign in to comment.