diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2016-04-05 12:33:15 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2016-04-08 11:32:04 +0200 |
commit | fbd5c28c39ff5ba338a95e2ca18e72b436eb9515 (patch) | |
tree | 6b3bc124962fad79799974f0c5d81196f1b65e4d /apps/federatedfilesharing/lib | |
parent | 1576a9a10b63b5d4a02a3721678613d5825730a8 (diff) | |
download | nextcloud-server-fbd5c28c39ff5ba338a95e2ca18e72b436eb9515.tar.gz nextcloud-server-fbd5c28c39ff5ba338a95e2ca18e72b436eb9515.zip |
re-try to send unshare notification if remote server is not available
Diffstat (limited to 'apps/federatedfilesharing/lib')
-rw-r--r-- | apps/federatedfilesharing/lib/notifications.php | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/apps/federatedfilesharing/lib/notifications.php b/apps/federatedfilesharing/lib/notifications.php index 4ec21e81cc7..9cdc7760361 100644 --- a/apps/federatedfilesharing/lib/notifications.php +++ b/apps/federatedfilesharing/lib/notifications.php @@ -23,6 +23,7 @@ namespace OCA\FederatedFileSharing; +use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClientService; class Notifications { @@ -30,24 +31,32 @@ class Notifications { /** @var AddressHandler */ private $addressHandler; + /** @var IClientService */ private $httpClientService; + /** @var DiscoveryManager */ private $discoveryManager; + /** @var IJobList */ + private $jobList; + /** * @param AddressHandler $addressHandler * @param IClientService $httpClientService * @param DiscoveryManager $discoveryManager + * @param IJobList $jobList */ public function __construct( AddressHandler $addressHandler, IClientService $httpClientService, - DiscoveryManager $discoveryManager + DiscoveryManager $discoveryManager, + IJobList $jobList ) { $this->addressHandler = $addressHandler; $this->httpClientService = $httpClientService; $this->discoveryManager = $discoveryManager; + $this->jobList = $jobList; } /** @@ -97,16 +106,45 @@ class Notifications { * @param string $remote url * @param int $id share id * @param string $token + * @param int $try how often did we already tried to send the un-share request * @return bool */ - public function sendRemoteUnShare($remote, $id, $token) { + public function sendRemoteUnShare($remote, $id, $token, $try = 0) { $url = rtrim($remote, '/'); $fields = array('token' => $token, 'format' => 'json'); $url = $this->addressHandler->removeProtocolFromUrl($url); $result = $this->tryHttpPostToShareEndpoint($url, '/'.$id.'/unshare', $fields); $status = json_decode($result['result'], true); - return ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)); + if ($result['success'] && + ($status['ocs']['meta']['statuscode'] === 100 || + $status['ocs']['meta']['statuscode'] === 200 + ) + ) { + return true; + } elseif ($try === 0) { + // only add new job on first try + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\UnShare', + [ + 'remote' => $remote, + 'id' => $id, + 'token' => $token, + 'try' => $try, + 'lastRun' => $this->getTimestamp() + ] + ); + } + + return false; + } + + /** + * return current timestamp + * + * @return int + */ + protected function getTimestamp() { + return time(); } /** @@ -117,7 +155,7 @@ class Notifications { * @param array $fields post parameters * @return array */ - private function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) { $client = $this->httpClientService->newClient(); $protocol = 'https://'; $result = [ |