Completed
Pull Request — master (#3838)
by Vars
12:18
created
apps/workflowengine/appinfo/routes.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
  */
21 21
 
22 22
 return [
23
-	'routes' => [
24
-		['name' => 'flowOperations#getOperations', 'url' => '/operations', 'verb' => 'GET'],
25
-		['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
26
-		['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
27
-		['name' => 'flowOperations#deleteOperation', 'url' => '/operations/{id}', 'verb' => 'DELETE'],
28
-		['name' => 'requestTime#getTimezones', 'url' => '/timezones', 'verb' => 'GET'],
29
-	]
23
+    'routes' => [
24
+        ['name' => 'flowOperations#getOperations', 'url' => '/operations', 'verb' => 'GET'],
25
+        ['name' => 'flowOperations#addOperation', 'url' => '/operations', 'verb' => 'POST'],
26
+        ['name' => 'flowOperations#updateOperation', 'url' => '/operations/{id}', 'verb' => 'PUT'],
27
+        ['name' => 'flowOperations#deleteOperation', 'url' => '/operations/{id}', 'verb' => 'DELETE'],
28
+        ['name' => 'requestTime#getTimezones', 'url' => '/timezones', 'verb' => 'GET'],
29
+    ]
30 30
 ];
Please login to merge, or discard this patch.
apps/testing/locking/fakedblockingprovider.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -27,44 +27,44 @@
 block discarded – undo
27 27
 use OCP\ILogger;
28 28
 
29 29
 class FakeDBLockingProvider extends \OC\Lock\DBLockingProvider {
30
-	// Lock for 10 hours just to be sure
31
-	const TTL = 36000;
30
+    // Lock for 10 hours just to be sure
31
+    const TTL = 36000;
32 32
 
33
-	/**
34
-	 * Need a new child, because parent::connection is private instead of protected...
35
-	 * @var IDBConnection
36
-	 */
37
-	protected $db;
33
+    /**
34
+     * Need a new child, because parent::connection is private instead of protected...
35
+     * @var IDBConnection
36
+     */
37
+    protected $db;
38 38
 
39
-	/**
40
-	 * @param \OCP\IDBConnection $connection
41
-	 * @param \OCP\ILogger $logger
42
-	 * @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory
43
-	 */
44
-	public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory) {
45
-		parent::__construct($connection, $logger, $timeFactory);
46
-		$this->db = $connection;
47
-	}
39
+    /**
40
+     * @param \OCP\IDBConnection $connection
41
+     * @param \OCP\ILogger $logger
42
+     * @param \OCP\AppFramework\Utility\ITimeFactory $timeFactory
43
+     */
44
+    public function __construct(IDBConnection $connection, ILogger $logger, ITimeFactory $timeFactory) {
45
+        parent::__construct($connection, $logger, $timeFactory);
46
+        $this->db = $connection;
47
+    }
48 48
 
49 49
 
50
-	/**
51
-	 * @param string $path
52
-	 * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
53
-	 */
54
-	public function releaseLock($path, $type) {
55
-		// we DONT keep shared locks till the end of the request
56
-		if ($type === self::LOCK_SHARED) {
57
-			$this->db->executeUpdate(
58
-				'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
59
-				[$path]
60
-			);
61
-		}
50
+    /**
51
+     * @param string $path
52
+     * @param int $type self::LOCK_SHARED or self::LOCK_EXCLUSIVE
53
+     */
54
+    public function releaseLock($path, $type) {
55
+        // we DONT keep shared locks till the end of the request
56
+        if ($type === self::LOCK_SHARED) {
57
+            $this->db->executeUpdate(
58
+                'UPDATE `*PREFIX*file_locks` SET `lock` = 0 WHERE `key` = ? AND `lock` = 1',
59
+                [$path]
60
+            );
61
+        }
62 62
 
63
-		parent::releaseLock($path, $type);
64
-	}
63
+        parent::releaseLock($path, $type);
64
+    }
65 65
 
66
-	public function __destruct() {
67
-		// Prevent cleaning up at the end of the live time.
68
-		// parent::__destruct();
69
-	}
66
+    public function __destruct() {
67
+        // Prevent cleaning up at the end of the live time.
68
+        // parent::__destruct();
69
+    }
70 70
 }
Please login to merge, or discard this patch.
apps/testing/lib/Config.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -27,45 +27,45 @@
 block discarded – undo
27 27
 
28 28
 class Config {
29 29
 
30
-	/** @var IConfig */
31
-	private $config;
30
+    /** @var IConfig */
31
+    private $config;
32 32
 
33
-	/** @var IRequest */
34
-	private $request;
33
+    /** @var IRequest */
34
+    private $request;
35 35
 
36
-	/**
37
-	 * @param IConfig $config
38
-	 * @param IRequest $request
39
-	 */
40
-	public function __construct(IConfig $config, IRequest $request) {
41
-		$this->config = $config;
42
-		$this->request = $request;
43
-	}
36
+    /**
37
+     * @param IConfig $config
38
+     * @param IRequest $request
39
+     */
40
+    public function __construct(IConfig $config, IRequest $request) {
41
+        $this->config = $config;
42
+        $this->request = $request;
43
+    }
44 44
 
45
-	/**
46
-	 * @param array $parameters
47
-	 * @return \OC_OCS_Result
48
-	 */
49
-	public function setAppValue($parameters) {
50
-		$app = $parameters['appid'];
51
-		$configKey = $parameters['configkey'];
45
+    /**
46
+     * @param array $parameters
47
+     * @return \OC_OCS_Result
48
+     */
49
+    public function setAppValue($parameters) {
50
+        $app = $parameters['appid'];
51
+        $configKey = $parameters['configkey'];
52 52
 
53
-		$value = $this->request->getParam('value');
54
-		$this->config->setAppValue($app, $configKey, $value);
53
+        $value = $this->request->getParam('value');
54
+        $this->config->setAppValue($app, $configKey, $value);
55 55
 
56
-		return new \OC_OCS_Result();
57
-	}
56
+        return new \OC_OCS_Result();
57
+    }
58 58
 
59
-	/**
60
-	 * @param array $parameters
61
-	 * @return \OC_OCS_Result
62
-	 */
63
-	public function deleteAppValue($parameters) {
64
-		$app = $parameters['appid'];
65
-		$configKey = $parameters['configkey'];
59
+    /**
60
+     * @param array $parameters
61
+     * @return \OC_OCS_Result
62
+     */
63
+    public function deleteAppValue($parameters) {
64
+        $app = $parameters['appid'];
65
+        $configKey = $parameters['configkey'];
66 66
 
67
-		$this->config->deleteAppValue($app, $configKey);
67
+        $this->config->deleteAppValue($app, $configKey);
68 68
 
69
-		return new \OC_OCS_Result();
70
-	}
69
+        return new \OC_OCS_Result();
70
+    }
71 71
 }
Please login to merge, or discard this patch.
apps/testing/lib/Application.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,18 +25,18 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
29
-		$appName = 'testing';
30
-		parent::__construct($appName, $urlParams);
28
+    public function __construct (array $urlParams = array()) {
29
+        $appName = 'testing';
30
+        parent::__construct($appName, $urlParams);
31 31
 
32
-		$c = $this->getContainer();
33
-		$config = $c->getServer()->getConfig();
34
-		if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
-			$userManager = $c->getServer()->getUserManager();
32
+        $c = $this->getContainer();
33
+        $config = $c->getServer()->getConfig();
34
+        if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') {
35
+            $userManager = $c->getServer()->getUserManager();
36 36
 
37
-			// replace all user backends with this one
38
-			$userManager->clearBackends();
39
-			$userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
-		}
41
-	}
37
+            // replace all user backends with this one
38
+            $userManager->clearBackends();
39
+            $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class));
40
+        }
41
+    }
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@
 block discarded – undo
25 25
 use OCA\Testing\AlternativeHomeUserBackend;
26 26
 
27 27
 class Application extends App {
28
-	public function __construct (array $urlParams = array()) {
28
+	public function __construct(array $urlParams = array()) {
29 29
 		$appName = 'testing';
30 30
 		parent::__construct($appName, $urlParams);
31 31
 
Please login to merge, or discard this patch.
apps/testing/lib/AlternativeHomeUserBackend.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -34,23 +34,23 @@
 block discarded – undo
34 34
  *	]
35 35
  */
36 36
 class AlternativeHomeUserBackend extends \OC\User\Database {
37
-	public function __construct() {
38
-		parent::__construct();
39
-	}
40
-	/**
41
-	 * get the user's home directory
42
-	 * @param string $uid the username
43
-	 * @return string|false
44
-	 */
45
-	public function getHome($uid) {
46
-		if ($this->userExists($uid)) {
47
-			// workaround to avoid killing the admin
48
-			if ($uid !== 'admin') {
49
-				$uid = md5($uid);
50
-			}
51
-			return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
52
-		}
37
+    public function __construct() {
38
+        parent::__construct();
39
+    }
40
+    /**
41
+     * get the user's home directory
42
+     * @param string $uid the username
43
+     * @return string|false
44
+     */
45
+    public function getHome($uid) {
46
+        if ($this->userExists($uid)) {
47
+            // workaround to avoid killing the admin
48
+            if ($uid !== 'admin') {
49
+                $uid = md5($uid);
50
+            }
51
+            return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
52
+        }
53 53
 
54
-		return false;
55
-	}
54
+        return false;
55
+    }
56 56
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 			if ($uid !== 'admin') {
49 49
 				$uid = md5($uid);
50 50
 			}
51
-			return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid;
51
+			return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/'.$uid;
52 52
 		}
53 53
 
54 54
 		return false;
Please login to merge, or discard this patch.
apps/testing/appinfo/routes.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,31 +27,31 @@
 block discarded – undo
27 27
 use OCP\API;
28 28
 
29 29
 $config = new Config(
30
-	\OC::$server->getConfig(),
31
-	\OC::$server->getRequest()
30
+    \OC::$server->getConfig(),
31
+    \OC::$server->getRequest()
32 32
 );
33 33
 
34 34
 API::register(
35
-	'post',
36
-	'/apps/testing/api/v1/app/{appid}/{configkey}',
37
-	[$config, 'setAppValue'],
38
-	'testing',
39
-	API::ADMIN_AUTH
35
+    'post',
36
+    '/apps/testing/api/v1/app/{appid}/{configkey}',
37
+    [$config, 'setAppValue'],
38
+    'testing',
39
+    API::ADMIN_AUTH
40 40
 );
41 41
 
42 42
 API::register(
43
-	'delete',
44
-	'/apps/testing/api/v1/app/{appid}/{configkey}',
45
-	[$config, 'deleteAppValue'],
46
-	'testing',
47
-	API::ADMIN_AUTH
43
+    'delete',
44
+    '/apps/testing/api/v1/app/{appid}/{configkey}',
45
+    [$config, 'deleteAppValue'],
46
+    'testing',
47
+    API::ADMIN_AUTH
48 48
 );
49 49
 
50 50
 $locking = new Provisioning(
51
-	\OC::$server->getLockingProvider(),
52
-	\OC::$server->getDatabaseConnection(),
53
-	\OC::$server->getConfig(),
54
-	\OC::$server->getRequest()
51
+    \OC::$server->getLockingProvider(),
52
+    \OC::$server->getDatabaseConnection(),
53
+    \OC::$server->getConfig(),
54
+    \OC::$server->getRequest()
55 55
 );
56 56
 API::register('get', '/apps/testing/api/v1/lockprovisioning', [$locking, 'isLockingEnabled'], 'files_lockprovisioning', API::ADMIN_AUTH);
57 57
 API::register('get', '/apps/testing/api/v1/lockprovisioning/{type}/{user}', [$locking, 'isLocked'], 'files_lockprovisioning', API::ADMIN_AUTH);
Please login to merge, or discard this patch.
apps/federatedfilesharing/templates/settings-admin.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -5,16 +5,16 @@  discard block
 block discarded – undo
5 5
 ?>
6 6
 
7 7
 <div id="fileSharingSettings" class="followupsection">
8
-	<h3><?php p($l->t('Federated Cloud Sharing'));?></h3>
8
+	<h3><?php p($l->t('Federated Cloud Sharing')); ?></h3>
9 9
 	<a target="_blank" rel="noreferrer" class="icon-info svg"
10
-		title="<?php p($l->t('Open documentation'));?>"
10
+		title="<?php p($l->t('Open documentation')); ?>"
11 11
 		href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a>
12 12
 
13 13
 	<p>
14 14
 		<input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox"
15 15
 			   value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
16 16
 		<label for="outgoingServer2serverShareEnabled">
17
-			<?php p($l->t('Allow users on this server to send shares to other servers'));?>
17
+			<?php p($l->t('Allow users on this server to send shares to other servers')); ?>
18 18
 		</label>
19 19
 	</p>
20 20
 
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 		<input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox"
23 23
 			   value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
24 24
 		<label for="incomingServer2serverShareEnabled">
25
-			<?php p($l->t('Allow users on this server to receive shares from other servers'));?>
25
+			<?php p($l->t('Allow users on this server to receive shares from other servers')); ?>
26 26
 		</label><br/>
27 27
 	</p>
28 28
 	<p>
29 29
 		<input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox"
30 30
 			   value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> />
31 31
 		<label for="lookupServerEnabled">
32
-			<?php p($l->t('Search global and public address book for users'));?>
32
+			<?php p($l->t('Search global and public address book for users')); ?>
33 33
 		</label><br/>
34 34
 	</p>
35 35
 </div>
Please login to merge, or discard this patch.
Braces   +12 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,10 @@  discard block
 block discarded – undo
12 12
 
13 13
 	<p>
14 14
 		<input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox"
15
-			   value="1" <?php if ($_['outgoingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
15
+			   value="1" <?php if ($_['outgoingServer2serverShareEnabled']) {
16
+    print_unescaped('checked="checked"');
17
+}
18
+?> />
16 19
 		<label for="outgoingServer2serverShareEnabled">
17 20
 			<?php p($l->t('Allow users on this server to send shares to other servers'));?>
18 21
 		</label>
@@ -20,14 +23,20 @@  discard block
 block discarded – undo
20 23
 
21 24
 	<p>
22 25
 		<input type="checkbox" name="incoming_server2server_share_enabled" id="incomingServer2serverShareEnabled" class="checkbox"
23
-			   value="1" <?php if ($_['incomingServer2serverShareEnabled']) print_unescaped('checked="checked"'); ?> />
26
+			   value="1" <?php if ($_['incomingServer2serverShareEnabled']) {
27
+    print_unescaped('checked="checked"');
28
+}
29
+?> />
24 30
 		<label for="incomingServer2serverShareEnabled">
25 31
 			<?php p($l->t('Allow users on this server to receive shares from other servers'));?>
26 32
 		</label><br/>
27 33
 	</p>
28 34
 	<p>
29 35
 		<input type="checkbox" name="lookupServerEnabled" id="lookupServerEnabled" class="checkbox"
30
-			   value="1" <?php if ($_['lookupServerEnabled']) print_unescaped('checked="checked"'); ?> />
36
+			   value="1" <?php if ($_['lookupServerEnabled']) {
37
+    print_unescaped('checked="checked"');
38
+}
39
+?> />
31 40
 		<label for="lookupServerEnabled">
32 41
 			<?php p($l->t('Search global and public address book for users'));?>
33 42
 		</label><br/>
Please login to merge, or discard this patch.
apps/federatedfilesharing/settings-personal.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 $isIE8 = false;
36 36
 preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
37 37
 if (count($matches) > 0 && $matches[1] <= 9) {
38
-	$isIE8 = true;
38
+    $isIE8 = true;
39 39
 }
40 40
 
41 41
 $cloudID = \OC::$server->getUserSession()->getUser()->getCloudId();
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
 $color = $theme->getMailHeaderColor();
46 46
 $textColor = "#ffffff";
47 47
 if(\OC::$server->getAppManager()->isEnabledForUser("theming")) {
48
-	$logoPath = $theme->getLogo();
49
-	try {
50
-		$util = \OC::$server->query("\OCA\Theming\Util");
51
-		if($util->invertTextColor($color)) {
52
-			$textColor = "#000000";
53
-		}
54
-	} catch (OCP\AppFramework\QueryException $e) {
48
+    $logoPath = $theme->getLogo();
49
+    try {
50
+        $util = \OC::$server->query("\OCA\Theming\Util");
51
+        if($util->invertTextColor($color)) {
52
+            $textColor = "#000000";
53
+        }
54
+    } catch (OCP\AppFramework\QueryException $e) {
55 55
 		
56
-	}
56
+    }
57 57
 }
58 58
 
59 59
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -39,16 +39,16 @@
 block discarded – undo
39 39
 }
40 40
 
41 41
 $cloudID = \OC::$server->getUserSession()->getUser()->getCloudId();
42
-$url = 'https://nextcloud.com/federation#' . $cloudID;
42
+$url = 'https://nextcloud.com/federation#'.$cloudID;
43 43
 $logoPath = \OC::$server->getURLGenerator()->imagePath('core', 'logo-icon.svg');
44 44
 $theme = \OC::$server->getThemingDefaults();
45 45
 $color = $theme->getMailHeaderColor();
46 46
 $textColor = "#ffffff";
47
-if(\OC::$server->getAppManager()->isEnabledForUser("theming")) {
47
+if (\OC::$server->getAppManager()->isEnabledForUser("theming")) {
48 48
 	$logoPath = $theme->getLogo();
49 49
 	try {
50 50
 		$util = \OC::$server->query("\OCA\Theming\Util");
51
-		if($util->invertTextColor($color)) {
51
+		if ($util->invertTextColor($color)) {
52 52
 			$textColor = "#000000";
53 53
 		}
54 54
 	} catch (OCP\AppFramework\QueryException $e) {
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Notifications.php 2 patches
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -32,279 +32,279 @@
 block discarded – undo
32 32
 use OCP\Http\Client\IClientService;
33 33
 
34 34
 class Notifications {
35
-	const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
36
-
37
-	/** @var AddressHandler */
38
-	private $addressHandler;
39
-
40
-	/** @var IClientService */
41
-	private $httpClientService;
42
-
43
-	/** @var DiscoveryManager */
44
-	private $discoveryManager;
45
-
46
-	/** @var IJobList  */
47
-	private $jobList;
48
-
49
-	/**
50
-	 * @param AddressHandler $addressHandler
51
-	 * @param IClientService $httpClientService
52
-	 * @param DiscoveryManager $discoveryManager
53
-	 * @param IJobList $jobList
54
-	 */
55
-	public function __construct(
56
-		AddressHandler $addressHandler,
57
-		IClientService $httpClientService,
58
-		DiscoveryManager $discoveryManager,
59
-		IJobList $jobList
60
-	) {
61
-		$this->addressHandler = $addressHandler;
62
-		$this->httpClientService = $httpClientService;
63
-		$this->discoveryManager = $discoveryManager;
64
-		$this->jobList = $jobList;
65
-	}
66
-
67
-	/**
68
-	 * send server-to-server share to remote server
69
-	 *
70
-	 * @param string $token
71
-	 * @param string $shareWith
72
-	 * @param string $name
73
-	 * @param int $remote_id
74
-	 * @param string $owner
75
-	 * @param string $ownerFederatedId
76
-	 * @param string $sharedBy
77
-	 * @param string $sharedByFederatedId
78
-	 * @return bool
79
-	 * @throws \OC\HintException
80
-	 * @throws \OC\ServerNotAvailableException
81
-	 */
82
-	public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) {
83
-
84
-		list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
85
-
86
-		if ($user && $remote) {
87
-			$local = $this->addressHandler->generateRemoteURL();
88
-
89
-			$fields = array(
90
-				'shareWith' => $user,
91
-				'token' => $token,
92
-				'name' => $name,
93
-				'remoteId' => $remote_id,
94
-				'owner' => $owner,
95
-				'ownerFederatedId' => $ownerFederatedId,
96
-				'sharedBy' => $sharedBy,
97
-				'sharedByFederatedId' => $sharedByFederatedId,
98
-				'remote' => $local,
99
-			);
100
-
101
-			$result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
102
-			$status = json_decode($result['result'], true);
103
-
104
-			if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
105
-				\OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
106
-				return true;
107
-			}
108
-
109
-		}
110
-
111
-		return false;
112
-	}
113
-
114
-	/**
115
-	 * ask owner to re-share the file with the given user
116
-	 *
117
-	 * @param string $token
118
-	 * @param int $id remote Id
119
-	 * @param int $shareId internal share Id
120
-	 * @param string $remote remote address of the owner
121
-	 * @param string $shareWith
122
-	 * @param int $permission
123
-	 * @return bool
124
-	 * @throws \OC\HintException
125
-	 * @throws \OC\ServerNotAvailableException
126
-	 */
127
-	public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) {
128
-
129
-		$fields = array(
130
-			'shareWith' => $shareWith,
131
-			'token' => $token,
132
-			'permission' => $permission,
133
-			'remoteId' => $shareId
134
-		);
135
-
136
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
137
-		$status = json_decode($result['result'], true);
138
-
139
-		$httpRequestSuccessful = $result['success'];
140
-		$ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
141
-		$validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
142
-		$validRemoteId = isset($status['ocs']['data']['remoteId']);
143
-
144
-		if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
145
-			return [
146
-				$status['ocs']['data']['token'],
147
-				(int)$status['ocs']['data']['remoteId']
148
-			];
149
-		}
150
-
151
-		return false;
152
-	}
153
-
154
-	/**
155
-	 * send server-to-server unshare to remote server
156
-	 *
157
-	 * @param string $remote url
158
-	 * @param int $id share id
159
-	 * @param string $token
160
-	 * @return bool
161
-	 */
162
-	public function sendRemoteUnShare($remote, $id, $token) {
163
-		$this->sendUpdateToRemote($remote, $id, $token, 'unshare');
164
-	}
165
-
166
-	/**
167
-	 * send server-to-server unshare to remote server
168
-	 *
169
-	 * @param string $remote url
170
-	 * @param int $id share id
171
-	 * @param string $token
172
-	 * @return bool
173
-	 */
174
-	public function sendRevokeShare($remote, $id, $token) {
175
-		$this->sendUpdateToRemote($remote, $id, $token, 'revoke');
176
-	}
177
-
178
-	/**
179
-	 * send notification to remote server if the permissions was changed
180
-	 *
181
-	 * @param string $remote
182
-	 * @param int $remoteId
183
-	 * @param string $token
184
-	 * @param int $permissions
185
-	 * @return bool
186
-	 */
187
-	public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
188
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
189
-	}
190
-
191
-	/**
192
-	 * forward accept reShare to remote server
193
-	 *
194
-	 * @param string $remote
195
-	 * @param int $remoteId
196
-	 * @param string $token
197
-	 */
198
-	public function sendAcceptShare($remote, $remoteId, $token) {
199
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
200
-	}
201
-
202
-	/**
203
-	 * forward decline reShare to remote server
204
-	 *
205
-	 * @param string $remote
206
-	 * @param int $remoteId
207
-	 * @param string $token
208
-	 */
209
-	public function sendDeclineShare($remote, $remoteId, $token) {
210
-		$this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
211
-	}
212
-
213
-	/**
214
-	 * inform remote server whether server-to-server share was accepted/declined
215
-	 *
216
-	 * @param string $remote
217
-	 * @param string $token
218
-	 * @param int $remoteId Share id on the remote host
219
-	 * @param string $action possible actions: accept, decline, unshare, revoke, permissions
220
-	 * @param array $data
221
-	 * @param int $try
222
-	 * @return boolean
223
-	 */
224
-	public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
225
-
226
-		$fields = array('token' => $token);
227
-		foreach ($data as $key => $value) {
228
-			$fields[$key] = $value;
229
-		}
230
-
231
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields);
232
-		$status = json_decode($result['result'], true);
233
-
234
-		if ($result['success'] &&
235
-			($status['ocs']['meta']['statuscode'] === 100 ||
236
-				$status['ocs']['meta']['statuscode'] === 200
237
-			)
238
-		) {
239
-			return true;
240
-		} elseif ($try === 0) {
241
-			// only add new job on first try
242
-			$this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
243
-				[
244
-					'remote' => $remote,
245
-					'remoteId' => $remoteId,
246
-					'token' => $token,
247
-					'action' => $action,
248
-					'data' => json_encode($data),
249
-					'try' => $try,
250
-					'lastRun' => $this->getTimestamp()
251
-				]
252
-			);
253
-		}
254
-
255
-		return false;
256
-	}
257
-
258
-
259
-	/**
260
-	 * return current timestamp
261
-	 *
262
-	 * @return int
263
-	 */
264
-	protected function getTimestamp() {
265
-		return time();
266
-	}
267
-
268
-	/**
269
-	 * try http post with the given protocol, if no protocol is given we pick
270
-	 * the secure one (https)
271
-	 *
272
-	 * @param string $remoteDomain
273
-	 * @param string $urlSuffix
274
-	 * @param array $fields post parameters
275
-	 * @return array
276
-	 * @throws \Exception
277
-	 */
278
-	protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
279
-		$client = $this->httpClientService->newClient();
280
-
281
-		if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
282
-			$remoteDomain = 'https://' . $remoteDomain;
283
-		}
284
-
285
-		$result = [
286
-			'success' => false,
287
-			'result' => '',
288
-		];
289
-
290
-		$endpoint = $this->discoveryManager->getShareEndpoint($remoteDomain);
291
-		try {
292
-			$response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
293
-				'body' => $fields,
294
-				'timeout' => 10,
295
-				'connect_timeout' => 10,
296
-			]);
297
-			$result['result'] = $response->getBody();
298
-			$result['success'] = true;
299
-		} catch (\Exception $e) {
300
-			// if flat re-sharing is not supported by the remote server
301
-			// we re-throw the exception and fall back to the old behaviour.
302
-			// (flat re-shares has been introduced in Nextcloud 9.1)
303
-			if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
304
-				throw $e;
305
-			}
306
-		}
307
-
308
-		return $result;
309
-	}
35
+    const RESPONSE_FORMAT = 'json'; // default response format for ocs calls
36
+
37
+    /** @var AddressHandler */
38
+    private $addressHandler;
39
+
40
+    /** @var IClientService */
41
+    private $httpClientService;
42
+
43
+    /** @var DiscoveryManager */
44
+    private $discoveryManager;
45
+
46
+    /** @var IJobList  */
47
+    private $jobList;
48
+
49
+    /**
50
+     * @param AddressHandler $addressHandler
51
+     * @param IClientService $httpClientService
52
+     * @param DiscoveryManager $discoveryManager
53
+     * @param IJobList $jobList
54
+     */
55
+    public function __construct(
56
+        AddressHandler $addressHandler,
57
+        IClientService $httpClientService,
58
+        DiscoveryManager $discoveryManager,
59
+        IJobList $jobList
60
+    ) {
61
+        $this->addressHandler = $addressHandler;
62
+        $this->httpClientService = $httpClientService;
63
+        $this->discoveryManager = $discoveryManager;
64
+        $this->jobList = $jobList;
65
+    }
66
+
67
+    /**
68
+     * send server-to-server share to remote server
69
+     *
70
+     * @param string $token
71
+     * @param string $shareWith
72
+     * @param string $name
73
+     * @param int $remote_id
74
+     * @param string $owner
75
+     * @param string $ownerFederatedId
76
+     * @param string $sharedBy
77
+     * @param string $sharedByFederatedId
78
+     * @return bool
79
+     * @throws \OC\HintException
80
+     * @throws \OC\ServerNotAvailableException
81
+     */
82
+    public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) {
83
+
84
+        list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
85
+
86
+        if ($user && $remote) {
87
+            $local = $this->addressHandler->generateRemoteURL();
88
+
89
+            $fields = array(
90
+                'shareWith' => $user,
91
+                'token' => $token,
92
+                'name' => $name,
93
+                'remoteId' => $remote_id,
94
+                'owner' => $owner,
95
+                'ownerFederatedId' => $ownerFederatedId,
96
+                'sharedBy' => $sharedBy,
97
+                'sharedByFederatedId' => $sharedByFederatedId,
98
+                'remote' => $local,
99
+            );
100
+
101
+            $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields);
102
+            $status = json_decode($result['result'], true);
103
+
104
+            if ($result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200)) {
105
+                \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]);
106
+                return true;
107
+            }
108
+
109
+        }
110
+
111
+        return false;
112
+    }
113
+
114
+    /**
115
+     * ask owner to re-share the file with the given user
116
+     *
117
+     * @param string $token
118
+     * @param int $id remote Id
119
+     * @param int $shareId internal share Id
120
+     * @param string $remote remote address of the owner
121
+     * @param string $shareWith
122
+     * @param int $permission
123
+     * @return bool
124
+     * @throws \OC\HintException
125
+     * @throws \OC\ServerNotAvailableException
126
+     */
127
+    public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) {
128
+
129
+        $fields = array(
130
+            'shareWith' => $shareWith,
131
+            'token' => $token,
132
+            'permission' => $permission,
133
+            'remoteId' => $shareId
134
+        );
135
+
136
+        $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
137
+        $status = json_decode($result['result'], true);
138
+
139
+        $httpRequestSuccessful = $result['success'];
140
+        $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200;
141
+        $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']);
142
+        $validRemoteId = isset($status['ocs']['data']['remoteId']);
143
+
144
+        if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
145
+            return [
146
+                $status['ocs']['data']['token'],
147
+                (int)$status['ocs']['data']['remoteId']
148
+            ];
149
+        }
150
+
151
+        return false;
152
+    }
153
+
154
+    /**
155
+     * send server-to-server unshare to remote server
156
+     *
157
+     * @param string $remote url
158
+     * @param int $id share id
159
+     * @param string $token
160
+     * @return bool
161
+     */
162
+    public function sendRemoteUnShare($remote, $id, $token) {
163
+        $this->sendUpdateToRemote($remote, $id, $token, 'unshare');
164
+    }
165
+
166
+    /**
167
+     * send server-to-server unshare to remote server
168
+     *
169
+     * @param string $remote url
170
+     * @param int $id share id
171
+     * @param string $token
172
+     * @return bool
173
+     */
174
+    public function sendRevokeShare($remote, $id, $token) {
175
+        $this->sendUpdateToRemote($remote, $id, $token, 'revoke');
176
+    }
177
+
178
+    /**
179
+     * send notification to remote server if the permissions was changed
180
+     *
181
+     * @param string $remote
182
+     * @param int $remoteId
183
+     * @param string $token
184
+     * @param int $permissions
185
+     * @return bool
186
+     */
187
+    public function sendPermissionChange($remote, $remoteId, $token, $permissions) {
188
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]);
189
+    }
190
+
191
+    /**
192
+     * forward accept reShare to remote server
193
+     *
194
+     * @param string $remote
195
+     * @param int $remoteId
196
+     * @param string $token
197
+     */
198
+    public function sendAcceptShare($remote, $remoteId, $token) {
199
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept');
200
+    }
201
+
202
+    /**
203
+     * forward decline reShare to remote server
204
+     *
205
+     * @param string $remote
206
+     * @param int $remoteId
207
+     * @param string $token
208
+     */
209
+    public function sendDeclineShare($remote, $remoteId, $token) {
210
+        $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline');
211
+    }
212
+
213
+    /**
214
+     * inform remote server whether server-to-server share was accepted/declined
215
+     *
216
+     * @param string $remote
217
+     * @param string $token
218
+     * @param int $remoteId Share id on the remote host
219
+     * @param string $action possible actions: accept, decline, unshare, revoke, permissions
220
+     * @param array $data
221
+     * @param int $try
222
+     * @return boolean
223
+     */
224
+    public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) {
225
+
226
+        $fields = array('token' => $token);
227
+        foreach ($data as $key => $value) {
228
+            $fields[$key] = $value;
229
+        }
230
+
231
+        $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields);
232
+        $status = json_decode($result['result'], true);
233
+
234
+        if ($result['success'] &&
235
+            ($status['ocs']['meta']['statuscode'] === 100 ||
236
+                $status['ocs']['meta']['statuscode'] === 200
237
+            )
238
+        ) {
239
+            return true;
240
+        } elseif ($try === 0) {
241
+            // only add new job on first try
242
+            $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
243
+                [
244
+                    'remote' => $remote,
245
+                    'remoteId' => $remoteId,
246
+                    'token' => $token,
247
+                    'action' => $action,
248
+                    'data' => json_encode($data),
249
+                    'try' => $try,
250
+                    'lastRun' => $this->getTimestamp()
251
+                ]
252
+            );
253
+        }
254
+
255
+        return false;
256
+    }
257
+
258
+
259
+    /**
260
+     * return current timestamp
261
+     *
262
+     * @return int
263
+     */
264
+    protected function getTimestamp() {
265
+        return time();
266
+    }
267
+
268
+    /**
269
+     * try http post with the given protocol, if no protocol is given we pick
270
+     * the secure one (https)
271
+     *
272
+     * @param string $remoteDomain
273
+     * @param string $urlSuffix
274
+     * @param array $fields post parameters
275
+     * @return array
276
+     * @throws \Exception
277
+     */
278
+    protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields) {
279
+        $client = $this->httpClientService->newClient();
280
+
281
+        if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
282
+            $remoteDomain = 'https://' . $remoteDomain;
283
+        }
284
+
285
+        $result = [
286
+            'success' => false,
287
+            'result' => '',
288
+        ];
289
+
290
+        $endpoint = $this->discoveryManager->getShareEndpoint($remoteDomain);
291
+        try {
292
+            $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
293
+                'body' => $fields,
294
+                'timeout' => 10,
295
+                'connect_timeout' => 10,
296
+            ]);
297
+            $result['result'] = $response->getBody();
298
+            $result['success'] = true;
299
+        } catch (\Exception $e) {
300
+            // if flat re-sharing is not supported by the remote server
301
+            // we re-throw the exception and fall back to the old behaviour.
302
+            // (flat re-shares has been introduced in Nextcloud 9.1)
303
+            if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) {
304
+                throw $e;
305
+            }
306
+        }
307
+
308
+        return $result;
309
+    }
310 310
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			'remoteId' => $shareId
134 134
 		);
135 135
 
136
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields);
136
+		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$id.'/reshare', $fields);
137 137
 		$status = json_decode($result['result'], true);
138 138
 
139 139
 		$httpRequestSuccessful = $result['success'];
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 		if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) {
145 145
 			return [
146 146
 				$status['ocs']['data']['token'],
147
-				(int)$status['ocs']['data']['remoteId']
147
+				(int) $status['ocs']['data']['remoteId']
148 148
 			];
149 149
 		}
150 150
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 			$fields[$key] = $value;
229 229
 		}
230 230
 
231
-		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields);
231
+		$result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/'.$remoteId.'/'.$action, $fields);
232 232
 		$status = json_decode($result['result'], true);
233 233
 
234 234
 		if ($result['success'] &&
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		$client = $this->httpClientService->newClient();
280 280
 
281 281
 		if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) {
282
-			$remoteDomain = 'https://' . $remoteDomain;
282
+			$remoteDomain = 'https://'.$remoteDomain;
283 283
 		}
284 284
 
285 285
 		$result = [
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
 		$endpoint = $this->discoveryManager->getShareEndpoint($remoteDomain);
291 291
 		try {
292
-			$response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [
292
+			$response = $client->post($remoteDomain.$endpoint.$urlSuffix.'?format='.self::RESPONSE_FORMAT, [
293 293
 				'body' => $fields,
294 294
 				'timeout' => 10,
295 295
 				'connect_timeout' => 10,
Please login to merge, or discard this patch.