Completed
Push — stable13 ( 2d5d8b...1a016f )
by Roeland
17:00
created
apps/dav/lib/CardDAV/Converter.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -119,9 +119,9 @@
 block discarded – undo
119 119
 		$elements = explode(' ', $fullName);
120 120
 		$result = ['', '', '', '', ''];
121 121
 		if (count($elements) > 2) {
122
-			$result[0] = implode(' ', array_slice($elements, count($elements)-1));
122
+			$result[0] = implode(' ', array_slice($elements, count($elements) - 1));
123 123
 			$result[1] = $elements[0];
124
-			$result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
124
+			$result[2] = implode(' ', array_slice($elements, 1, count($elements) - 2));
125 125
 		} elseif (count($elements) === 2) {
126 126
 			$result[0] = $elements[1];
127 127
 			$result[1] = $elements[0];
Please login to merge, or discard this patch.
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -31,123 +31,123 @@
 block discarded – undo
31 31
 
32 32
 class Converter {
33 33
 
34
-	/** @var AccountManager */
35
-	private $accountManager;
36
-
37
-	/**
38
-	 * Converter constructor.
39
-	 *
40
-	 * @param AccountManager $accountManager
41
-	 */
42
-	public function __construct(AccountManager $accountManager) {
43
-		$this->accountManager = $accountManager;
44
-	}
45
-
46
-	/**
47
-	 * @param IUser $user
48
-	 * @return VCard|null
49
-	 */
50
-	public function createCardFromUser(IUser $user) {
51
-
52
-		$userData = $this->accountManager->getUser($user);
53
-
54
-		$uid = $user->getUID();
55
-		$cloudId = $user->getCloudId();
56
-		$image = $this->getAvatarImage($user);
57
-
58
-		$vCard = new VCard();
59
-		$vCard->VERSION = '3.0';
60
-		$vCard->UID = $uid;
61
-
62
-		$publish = false;
63
-
64
-		if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) {
65
-			$userData[AccountManager::PROPERTY_AVATAR]['value'] = true;
66
-		}
67
-
68
-		foreach ($userData as $property => $value) {
69
-
70
-			$shareWithTrustedServers =
71
-				$value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
72
-				$value['scope'] === AccountManager::VISIBILITY_PUBLIC;
73
-
74
-			$emptyValue = !isset($value['value']) || $value['value'] === '';
75
-
76
-			if ($shareWithTrustedServers && !$emptyValue) {
77
-				$publish = true;
78
-				switch ($property) {
79
-					case AccountManager::PROPERTY_DISPLAYNAME:
80
-						$vCard->add(new Text($vCard, 'FN', $value['value']));
81
-						$vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
82
-						break;
83
-					case AccountManager::PROPERTY_AVATAR:
84
-						if ($image !== null) {
85
-							$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
86
-						}
87
-						break;
88
-					case AccountManager::PROPERTY_EMAIL:
89
-						$vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
90
-						break;
91
-					case AccountManager::PROPERTY_WEBSITE:
92
-						$vCard->add(new Text($vCard, 'URL', $value['value']));
93
-						break;
94
-					case AccountManager::PROPERTY_PHONE:
95
-						$vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
96
-						break;
97
-					case AccountManager::PROPERTY_ADDRESS:
98
-						$vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
99
-						break;
100
-					case AccountManager::PROPERTY_TWITTER:
101
-						$vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
102
-						break;
103
-				}
104
-			}
105
-		}
106
-
107
-		if ($publish && !empty($cloudId)) {
108
-			$vCard->add(new Text($vCard, 'CLOUD', $cloudId));
109
-			$vCard->validate();
110
-			return $vCard;
111
-		}
112
-
113
-		return null;
114
-	}
115
-
116
-	/**
117
-	 * @param string $fullName
118
-	 * @return string[]
119
-	 */
120
-	public function splitFullName($fullName) {
121
-		// Very basic western style parsing. I'm not gonna implement
122
-		// https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;)
123
-
124
-		$elements = explode(' ', $fullName);
125
-		$result = ['', '', '', '', ''];
126
-		if (count($elements) > 2) {
127
-			$result[0] = implode(' ', array_slice($elements, count($elements)-1));
128
-			$result[1] = $elements[0];
129
-			$result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
130
-		} elseif (count($elements) === 2) {
131
-			$result[0] = $elements[1];
132
-			$result[1] = $elements[0];
133
-		} else {
134
-			$result[0] = $elements[0];
135
-		}
136
-
137
-		return $result;
138
-	}
139
-
140
-	/**
141
-	 * @param IUser $user
142
-	 * @return null|IImage
143
-	 */
144
-	private function getAvatarImage(IUser $user) {
145
-		try {
146
-			$image = $user->getAvatarImage(-1);
147
-			return $image;
148
-		} catch (\Exception $ex) {
149
-			return null;
150
-		}
151
-	}
34
+    /** @var AccountManager */
35
+    private $accountManager;
36
+
37
+    /**
38
+     * Converter constructor.
39
+     *
40
+     * @param AccountManager $accountManager
41
+     */
42
+    public function __construct(AccountManager $accountManager) {
43
+        $this->accountManager = $accountManager;
44
+    }
45
+
46
+    /**
47
+     * @param IUser $user
48
+     * @return VCard|null
49
+     */
50
+    public function createCardFromUser(IUser $user) {
51
+
52
+        $userData = $this->accountManager->getUser($user);
53
+
54
+        $uid = $user->getUID();
55
+        $cloudId = $user->getCloudId();
56
+        $image = $this->getAvatarImage($user);
57
+
58
+        $vCard = new VCard();
59
+        $vCard->VERSION = '3.0';
60
+        $vCard->UID = $uid;
61
+
62
+        $publish = false;
63
+
64
+        if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) {
65
+            $userData[AccountManager::PROPERTY_AVATAR]['value'] = true;
66
+        }
67
+
68
+        foreach ($userData as $property => $value) {
69
+
70
+            $shareWithTrustedServers =
71
+                $value['scope'] === AccountManager::VISIBILITY_CONTACTS_ONLY ||
72
+                $value['scope'] === AccountManager::VISIBILITY_PUBLIC;
73
+
74
+            $emptyValue = !isset($value['value']) || $value['value'] === '';
75
+
76
+            if ($shareWithTrustedServers && !$emptyValue) {
77
+                $publish = true;
78
+                switch ($property) {
79
+                    case AccountManager::PROPERTY_DISPLAYNAME:
80
+                        $vCard->add(new Text($vCard, 'FN', $value['value']));
81
+                        $vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
82
+                        break;
83
+                    case AccountManager::PROPERTY_AVATAR:
84
+                        if ($image !== null) {
85
+                            $vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
86
+                        }
87
+                        break;
88
+                    case AccountManager::PROPERTY_EMAIL:
89
+                        $vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
90
+                        break;
91
+                    case AccountManager::PROPERTY_WEBSITE:
92
+                        $vCard->add(new Text($vCard, 'URL', $value['value']));
93
+                        break;
94
+                    case AccountManager::PROPERTY_PHONE:
95
+                        $vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
96
+                        break;
97
+                    case AccountManager::PROPERTY_ADDRESS:
98
+                        $vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
99
+                        break;
100
+                    case AccountManager::PROPERTY_TWITTER:
101
+                        $vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
102
+                        break;
103
+                }
104
+            }
105
+        }
106
+
107
+        if ($publish && !empty($cloudId)) {
108
+            $vCard->add(new Text($vCard, 'CLOUD', $cloudId));
109
+            $vCard->validate();
110
+            return $vCard;
111
+        }
112
+
113
+        return null;
114
+    }
115
+
116
+    /**
117
+     * @param string $fullName
118
+     * @return string[]
119
+     */
120
+    public function splitFullName($fullName) {
121
+        // Very basic western style parsing. I'm not gonna implement
122
+        // https://github.com/android/platform_packages_providers_contactsprovider/blob/master/src/com/android/providers/contacts/NameSplitter.java ;)
123
+
124
+        $elements = explode(' ', $fullName);
125
+        $result = ['', '', '', '', ''];
126
+        if (count($elements) > 2) {
127
+            $result[0] = implode(' ', array_slice($elements, count($elements)-1));
128
+            $result[1] = $elements[0];
129
+            $result[2] = implode(' ', array_slice($elements, 1, count($elements)-2));
130
+        } elseif (count($elements) === 2) {
131
+            $result[0] = $elements[1];
132
+            $result[1] = $elements[0];
133
+        } else {
134
+            $result[0] = $elements[0];
135
+        }
136
+
137
+        return $result;
138
+    }
139
+
140
+    /**
141
+     * @param IUser $user
142
+     * @return null|IImage
143
+     */
144
+    private function getAvatarImage(IUser $user) {
145
+        try {
146
+            $image = $user->getAvatarImage(-1);
147
+            return $image;
148
+        } catch (\Exception $ex) {
149
+            return null;
150
+        }
151
+    }
152 152
 
153 153
 }
Please login to merge, or discard this patch.
apps/federation/lib/SyncFederationAddressBooks.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -30,64 +30,64 @@
 block discarded – undo
30 30
 
31 31
 class SyncFederationAddressBooks {
32 32
 
33
-	/** @var DbHandler */
34
-	protected $dbHandler;
33
+    /** @var DbHandler */
34
+    protected $dbHandler;
35 35
 
36
-	/** @var SyncService */
37
-	private $syncService;
36
+    /** @var SyncService */
37
+    private $syncService;
38 38
 
39
-	/** @var  DiscoveryService */
40
-	private $ocsDiscoveryService;
39
+    /** @var  DiscoveryService */
40
+    private $ocsDiscoveryService;
41 41
 
42
-	/**
43
-	 * @param DbHandler $dbHandler
44
-	 * @param SyncService $syncService
45
-	 * @param IDiscoveryService $ocsDiscoveryService
46
-	 */
47
-	public function __construct(DbHandler $dbHandler,
48
-								SyncService $syncService,
49
-								IDiscoveryService $ocsDiscoveryService
50
-	) {
51
-		$this->syncService = $syncService;
52
-		$this->dbHandler = $dbHandler;
53
-		$this->ocsDiscoveryService = $ocsDiscoveryService;
54
-	}
42
+    /**
43
+     * @param DbHandler $dbHandler
44
+     * @param SyncService $syncService
45
+     * @param IDiscoveryService $ocsDiscoveryService
46
+     */
47
+    public function __construct(DbHandler $dbHandler,
48
+                                SyncService $syncService,
49
+                                IDiscoveryService $ocsDiscoveryService
50
+    ) {
51
+        $this->syncService = $syncService;
52
+        $this->dbHandler = $dbHandler;
53
+        $this->ocsDiscoveryService = $ocsDiscoveryService;
54
+    }
55 55
 
56
-	/**
57
-	 * @param \Closure $callback
58
-	 */
59
-	public function syncThemAll(\Closure $callback) {
56
+    /**
57
+     * @param \Closure $callback
58
+     */
59
+    public function syncThemAll(\Closure $callback) {
60 60
 
61
-		$trustedServers = $this->dbHandler->getAllServer();
62
-		foreach ($trustedServers as $trustedServer) {
63
-			$url = $trustedServer['url'];
64
-			$callback($url, null);
65
-			$sharedSecret = $trustedServer['shared_secret'];
66
-			$syncToken = $trustedServer['sync_token'];
61
+        $trustedServers = $this->dbHandler->getAllServer();
62
+        foreach ($trustedServers as $trustedServer) {
63
+            $url = $trustedServer['url'];
64
+            $callback($url, null);
65
+            $sharedSecret = $trustedServer['shared_secret'];
66
+            $syncToken = $trustedServer['sync_token'];
67 67
 
68
-			$endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
69
-			$cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
70
-			$addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
68
+            $endPoints = $this->ocsDiscoveryService->discover($url, 'FEDERATED_SHARING');
69
+            $cardDavUser = isset($endPoints['carddav-user']) ? $endPoints['carddav-user'] : 'system';
70
+            $addressBookUrl = isset($endPoints['system-address-book']) ? trim($endPoints['system-address-book'], '/') : 'remote.php/dav/addressbooks/system/system/system';
71 71
 
72
-			if (is_null($sharedSecret)) {
73
-				continue;
74
-			}
75
-			$targetBookId = $trustedServer['url_hash'];
76
-			$targetPrincipal = "principals/system/system";
77
-			$targetBookProperties = [
78
-					'{DAV:}displayname' => $url
79
-			];
80
-			try {
81
-				$newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
82
-				if ($newToken !== $syncToken) {
83
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
84
-				}
85
-			} catch (\Exception $ex) {
86
-				if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
87
-					$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
88
-				}
89
-				$callback($url, $ex);
90
-			}
91
-		}
92
-	}
72
+            if (is_null($sharedSecret)) {
73
+                continue;
74
+            }
75
+            $targetBookId = $trustedServer['url_hash'];
76
+            $targetPrincipal = "principals/system/system";
77
+            $targetBookProperties = [
78
+                    '{DAV:}displayname' => $url
79
+            ];
80
+            try {
81
+                $newToken = $this->syncService->syncRemoteAddressBook($url, $cardDavUser, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetBookProperties);
82
+                if ($newToken !== $syncToken) {
83
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
84
+                }
85
+            } catch (\Exception $ex) {
86
+                if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
87
+                    $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_ACCESS_REVOKED);
88
+                }
89
+                $callback($url, $ex);
90
+            }
91
+        }
92
+    }
93 93
 }
Please login to merge, or discard this patch.
core/Command/Check.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@
 block discarded – undo
28 28
 use Symfony\Component\Console\Output\OutputInterface;
29 29
 
30 30
 class Check extends Base {
31
-	/**
32
-	 * @var SystemConfig
33
-	 */
34
-	private $config;
31
+    /**
32
+     * @var SystemConfig
33
+     */
34
+    private $config;
35 35
 
36
-	public function __construct(SystemConfig $config) {
37
-		parent::__construct();
38
-		$this->config = $config;
39
-	}
36
+    public function __construct(SystemConfig $config) {
37
+        parent::__construct();
38
+        $this->config = $config;
39
+    }
40 40
 
41
-	protected function configure() {
42
-		parent::configure();
41
+    protected function configure() {
42
+        parent::configure();
43 43
 
44
-		$this
45
-			->setName('check')
46
-			->setDescription('check dependencies of the server environment')
47
-		;
48
-	}
44
+        $this
45
+            ->setName('check')
46
+            ->setDescription('check dependencies of the server environment')
47
+        ;
48
+    }
49 49
 
50
-	protected function execute(InputInterface $input, OutputInterface $output) {
51
-		$errors = \OC_Util::checkServer($this->config);
52
-		if (!empty($errors)) {
53
-			$errors = array_map(function($item) {
54
-				return (string) $item['error'];
55
-			}, $errors);
50
+    protected function execute(InputInterface $input, OutputInterface $output) {
51
+        $errors = \OC_Util::checkServer($this->config);
52
+        if (!empty($errors)) {
53
+            $errors = array_map(function($item) {
54
+                return (string) $item['error'];
55
+            }, $errors);
56 56
 
57
-			$this->writeArrayInOutputFormat($input, $output, $errors);
58
-			return 1;
59
-		}
60
-		return 0;
61
-	}
57
+            $this->writeArrayInOutputFormat($input, $output, $errors);
58
+            return 1;
59
+        }
60
+        return 0;
61
+    }
62 62
 }
Please login to merge, or discard this patch.
lib/private/Setup/Sqlite.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,10 +33,10 @@
 block discarded – undo
33 33
 	}
34 34
 
35 35
 	public function setupDatabase($username) {
36
-		$datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
36
+		$datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT.'/data');
37 37
 
38 38
 		//delete the old sqlite database first, might cause infinte loops otherwise
39
-		if(file_exists("$datadir/owncloud.db")) {
39
+		if (file_exists("$datadir/owncloud.db")) {
40 40
 			unlink("$datadir/owncloud.db");
41 41
 		}
42 42
 		//in case of sqlite, we can always fill the database
Please login to merge, or discard this patch.
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,23 +23,23 @@
 block discarded – undo
23 23
 namespace OC\Setup;
24 24
 
25 25
 class Sqlite extends AbstractDatabase {
26
-	public $dbprettyname = 'Sqlite';
26
+    public $dbprettyname = 'Sqlite';
27 27
 
28
-	public function validate($config) {
29
-		return array();
30
-	}
28
+    public function validate($config) {
29
+        return array();
30
+    }
31 31
 
32
-	public function initialize($config) {
33
-	}
32
+    public function initialize($config) {
33
+    }
34 34
 
35
-	public function setupDatabase($username) {
36
-		$datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
35
+    public function setupDatabase($username) {
36
+        $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data');
37 37
 
38
-		//delete the old sqlite database first, might cause infinte loops otherwise
39
-		if(file_exists("$datadir/owncloud.db")) {
40
-			unlink("$datadir/owncloud.db");
41
-		}
42
-		//in case of sqlite, we can always fill the database
43
-		error_log("creating sqlite db");
44
-	}
38
+        //delete the old sqlite database first, might cause infinte loops otherwise
39
+        if(file_exists("$datadir/owncloud.db")) {
40
+            unlink("$datadir/owncloud.db");
41
+        }
42
+        //in case of sqlite, we can always fill the database
43
+        error_log("creating sqlite db");
44
+    }
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/DummyGetResponsePlugin.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,33 +39,33 @@
 block discarded – undo
39 39
  * @package OCA\DAV\Connector\Sabre
40 40
  */
41 41
 class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin {
42
-	/** @var \Sabre\DAV\Server */
43
-	protected $server;
42
+    /** @var \Sabre\DAV\Server */
43
+    protected $server;
44 44
 
45
-	/**
46
-	 * @param \Sabre\DAV\Server $server
47
-	 * @return void
48
-	 */
49
-	function initialize(\Sabre\DAV\Server $server) {
50
-		$this->server = $server;
51
-		$this->server->on('method:GET', [$this, 'httpGet'], 200);
52
-	}
45
+    /**
46
+     * @param \Sabre\DAV\Server $server
47
+     * @return void
48
+     */
49
+    function initialize(\Sabre\DAV\Server $server) {
50
+        $this->server = $server;
51
+        $this->server->on('method:GET', [$this, 'httpGet'], 200);
52
+    }
53 53
 
54
-	/**
55
-	 * @param RequestInterface $request
56
-	 * @param ResponseInterface $response
57
-	 * @return false
58
-	 */
59
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
60
-		$string = 'This is the WebDAV interface. It can only be accessed by ' .
61
-			'WebDAV clients such as the Nextcloud desktop sync client.';
62
-		$stream = fopen('php://memory','r+');
63
-		fwrite($stream, $string);
64
-		rewind($stream);
54
+    /**
55
+     * @param RequestInterface $request
56
+     * @param ResponseInterface $response
57
+     * @return false
58
+     */
59
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
60
+        $string = 'This is the WebDAV interface. It can only be accessed by ' .
61
+            'WebDAV clients such as the Nextcloud desktop sync client.';
62
+        $stream = fopen('php://memory','r+');
63
+        fwrite($stream, $string);
64
+        rewind($stream);
65 65
 
66
-		$response->setStatus(200);
67
-		$response->setBody($stream);
66
+        $response->setStatus(200);
67
+        $response->setBody($stream);
68 68
 
69
-		return false;
70
-	}
69
+        return false;
70
+    }
71 71
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@
 block discarded – undo
57 57
 	 * @return false
58 58
 	 */
59 59
 	function httpGet(RequestInterface $request, ResponseInterface $response) {
60
-		$string = 'This is the WebDAV interface. It can only be accessed by ' .
60
+		$string = 'This is the WebDAV interface. It can only be accessed by '.
61 61
 			'WebDAV clients such as the Nextcloud desktop sync client.';
62
-		$stream = fopen('php://memory','r+');
62
+		$stream = fopen('php://memory', 'r+');
63 63
 		fwrite($stream, $string);
64 64
 		rewind($stream);
65 65
 
Please login to merge, or discard this patch.
lib/private/Migration/ConsoleOutput.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -37,57 +37,57 @@
 block discarded – undo
37 37
  */
38 38
 class ConsoleOutput implements IOutput {
39 39
 
40
-	/** @var OutputInterface */
41
-	private $output;
40
+    /** @var OutputInterface */
41
+    private $output;
42 42
 
43
-	/** @var ProgressBar */
44
-	private $progressBar;
43
+    /** @var ProgressBar */
44
+    private $progressBar;
45 45
 
46
-	public function __construct(OutputInterface $output) {
47
-		$this->output = $output;
48
-	}
46
+    public function __construct(OutputInterface $output) {
47
+        $this->output = $output;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $message
52
-	 */
53
-	public function info($message) {
54
-		$this->output->writeln("<info>$message</info>");
55
-	}
50
+    /**
51
+     * @param string $message
52
+     */
53
+    public function info($message) {
54
+        $this->output->writeln("<info>$message</info>");
55
+    }
56 56
 
57
-	/**
58
-	 * @param string $message
59
-	 */
60
-	public function warning($message) {
61
-		$this->output->writeln("<comment>$message</comment>");
62
-	}
57
+    /**
58
+     * @param string $message
59
+     */
60
+    public function warning($message) {
61
+        $this->output->writeln("<comment>$message</comment>");
62
+    }
63 63
 
64
-	/**
65
-	 * @param int $max
66
-	 */
67
-	public function startProgress($max = 0) {
68
-		if (!is_null($this->progressBar)) {
69
-			$this->progressBar->finish();
70
-		}
71
-		$this->progressBar = new ProgressBar($this->output);
72
-		$this->progressBar->start($max);
73
-	}
64
+    /**
65
+     * @param int $max
66
+     */
67
+    public function startProgress($max = 0) {
68
+        if (!is_null($this->progressBar)) {
69
+            $this->progressBar->finish();
70
+        }
71
+        $this->progressBar = new ProgressBar($this->output);
72
+        $this->progressBar->start($max);
73
+    }
74 74
 
75
-	/**
76
-	 * @param int $step
77
-	 * @param string $description
78
-	 */
79
-	public function advance($step = 1, $description = '') {
80
-		if (!is_null($this->progressBar)) {
81
-			$this->progressBar = new ProgressBar($this->output);
82
-			$this->progressBar->start();
83
-		}
84
-		$this->progressBar->advance($step);
85
-	}
75
+    /**
76
+     * @param int $step
77
+     * @param string $description
78
+     */
79
+    public function advance($step = 1, $description = '') {
80
+        if (!is_null($this->progressBar)) {
81
+            $this->progressBar = new ProgressBar($this->output);
82
+            $this->progressBar->start();
83
+        }
84
+        $this->progressBar->advance($step);
85
+    }
86 86
 
87
-	public function finishProgress() {
88
-		if (is_null($this->progressBar)) {
89
-			return;
90
-		}
91
-		$this->progressBar->finish();
92
-	}
87
+    public function finishProgress() {
88
+        if (is_null($this->progressBar)) {
89
+            return;
90
+        }
91
+        $this->progressBar->finish();
92
+    }
93 93
 }
Please login to merge, or discard this patch.
core/Command/Encryption/EncryptAll.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -34,102 +34,102 @@
 block discarded – undo
34 34
 
35 35
 class EncryptAll extends Command {
36 36
 
37
-	/** @var IManager */
38
-	protected $encryptionManager;
39
-
40
-	/** @var  IAppManager */
41
-	protected $appManager;
42
-
43
-	/** @var IConfig */
44
-	protected $config;
45
-
46
-	/** @var  QuestionHelper */
47
-	protected $questionHelper;
48
-
49
-	/** @var bool */
50
-	protected $wasTrashbinEnabled;
51
-
52
-	/** @var  bool */
53
-	protected $wasMaintenanceModeEnabled;
54
-
55
-	/**
56
-	 * @param IManager $encryptionManager
57
-	 * @param IAppManager $appManager
58
-	 * @param IConfig $config
59
-	 * @param QuestionHelper $questionHelper
60
-	 */
61
-	public function __construct(
62
-		IManager $encryptionManager,
63
-		IAppManager $appManager,
64
-		IConfig $config,
65
-		QuestionHelper $questionHelper
66
-	) {
67
-		parent::__construct();
68
-		$this->appManager = $appManager;
69
-		$this->encryptionManager = $encryptionManager;
70
-		$this->config = $config;
71
-		$this->questionHelper = $questionHelper;
72
-	}
73
-
74
-	/**
75
-	 * Set maintenance mode and disable the trashbin app
76
-	 */
77
-	protected function forceMaintenanceAndTrashbin() {
78
-		$this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
79
-		$this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
80
-		$this->config->setSystemValue('maintenance', true);
81
-		$this->appManager->disableApp('files_trashbin');
82
-	}
83
-
84
-	/**
85
-	 * Reset the maintenance mode and re-enable the trashbin app
86
-	 */
87
-	protected function resetMaintenanceAndTrashbin() {
88
-		$this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled);
89
-		if ($this->wasTrashbinEnabled) {
90
-			$this->appManager->enableApp('files_trashbin');
91
-		}
92
-	}
93
-
94
-	protected function configure() {
95
-		parent::configure();
96
-
97
-		$this->setName('encryption:encrypt-all');
98
-		$this->setDescription('Encrypt all files for all users');
99
-		$this->setHelp(
100
-			'This will encrypt all files for all users. '
101
-			. 'Please make sure that no user access his files during this process!'
102
-		);
103
-	}
104
-
105
-	protected function execute(InputInterface $input, OutputInterface $output) {
106
-
107
-		if ($this->encryptionManager->isEnabled() === false) {
108
-			throw new \Exception('Server side encryption is not enabled');
109
-		}
110
-
111
-		$output->writeln("\n");
112
-		$output->writeln('You are about to encrypt all files stored in your Nextcloud installation.');
113
-		$output->writeln('Depending on the number of available files, and their size, this may take quite some time.');
114
-		$output->writeln('Please ensure that no user accesses their files during this time!');
115
-		$output->writeln('Note: The encryption module you use determines which files get encrypted.');
116
-		$output->writeln('');
117
-		$question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
118
-		if ($this->questionHelper->ask($input, $output, $question)) {
119
-			$this->forceMaintenanceAndTrashbin();
120
-
121
-			try {
122
-				$defaultModule = $this->encryptionManager->getEncryptionModule();
123
-				$defaultModule->encryptAll($input, $output);
124
-			} catch (\Exception $ex) {
125
-				$this->resetMaintenanceAndTrashbin();
126
-				throw $ex;
127
-			}
128
-
129
-			$this->resetMaintenanceAndTrashbin();
130
-		} else {
131
-			$output->writeln('aborted');
132
-		}
133
-	}
37
+    /** @var IManager */
38
+    protected $encryptionManager;
39
+
40
+    /** @var  IAppManager */
41
+    protected $appManager;
42
+
43
+    /** @var IConfig */
44
+    protected $config;
45
+
46
+    /** @var  QuestionHelper */
47
+    protected $questionHelper;
48
+
49
+    /** @var bool */
50
+    protected $wasTrashbinEnabled;
51
+
52
+    /** @var  bool */
53
+    protected $wasMaintenanceModeEnabled;
54
+
55
+    /**
56
+     * @param IManager $encryptionManager
57
+     * @param IAppManager $appManager
58
+     * @param IConfig $config
59
+     * @param QuestionHelper $questionHelper
60
+     */
61
+    public function __construct(
62
+        IManager $encryptionManager,
63
+        IAppManager $appManager,
64
+        IConfig $config,
65
+        QuestionHelper $questionHelper
66
+    ) {
67
+        parent::__construct();
68
+        $this->appManager = $appManager;
69
+        $this->encryptionManager = $encryptionManager;
70
+        $this->config = $config;
71
+        $this->questionHelper = $questionHelper;
72
+    }
73
+
74
+    /**
75
+     * Set maintenance mode and disable the trashbin app
76
+     */
77
+    protected function forceMaintenanceAndTrashbin() {
78
+        $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin');
79
+        $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);
80
+        $this->config->setSystemValue('maintenance', true);
81
+        $this->appManager->disableApp('files_trashbin');
82
+    }
83
+
84
+    /**
85
+     * Reset the maintenance mode and re-enable the trashbin app
86
+     */
87
+    protected function resetMaintenanceAndTrashbin() {
88
+        $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled);
89
+        if ($this->wasTrashbinEnabled) {
90
+            $this->appManager->enableApp('files_trashbin');
91
+        }
92
+    }
93
+
94
+    protected function configure() {
95
+        parent::configure();
96
+
97
+        $this->setName('encryption:encrypt-all');
98
+        $this->setDescription('Encrypt all files for all users');
99
+        $this->setHelp(
100
+            'This will encrypt all files for all users. '
101
+            . 'Please make sure that no user access his files during this process!'
102
+        );
103
+    }
104
+
105
+    protected function execute(InputInterface $input, OutputInterface $output) {
106
+
107
+        if ($this->encryptionManager->isEnabled() === false) {
108
+            throw new \Exception('Server side encryption is not enabled');
109
+        }
110
+
111
+        $output->writeln("\n");
112
+        $output->writeln('You are about to encrypt all files stored in your Nextcloud installation.');
113
+        $output->writeln('Depending on the number of available files, and their size, this may take quite some time.');
114
+        $output->writeln('Please ensure that no user accesses their files during this time!');
115
+        $output->writeln('Note: The encryption module you use determines which files get encrypted.');
116
+        $output->writeln('');
117
+        $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false);
118
+        if ($this->questionHelper->ask($input, $output, $question)) {
119
+            $this->forceMaintenanceAndTrashbin();
120
+
121
+            try {
122
+                $defaultModule = $this->encryptionManager->getEncryptionModule();
123
+                $defaultModule->encryptAll($input, $output);
124
+            } catch (\Exception $ex) {
125
+                $this->resetMaintenanceAndTrashbin();
126
+                throw $ex;
127
+            }
128
+
129
+            $this->resetMaintenanceAndTrashbin();
130
+        } else {
131
+            $output->writeln('aborted');
132
+        }
133
+    }
134 134
 
135 135
 }
Please login to merge, or discard this patch.
lib/private/App/AppManager.php 3 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	/**
122 122
 	 * List all installed apps
123 123
 	 *
124
-	 * @return string[]
124
+	 * @return integer[]
125 125
 	 */
126 126
 	public function getInstalledApps() {
127 127
 		return array_keys($this->getInstalledAppsValues());
@@ -382,6 +382,9 @@  discard block
 block discarded – undo
382 382
 		return in_array($appId, $this->shippedApps, true);
383 383
 	}
384 384
 
385
+	/**
386
+	 * @param string $appId
387
+	 */
385 388
 	private function isAlwaysEnabled($appId) {
386 389
 		$alwaysEnabled = $this->getAlwaysEnabledApps();
387 390
 		return in_array($appId, $alwaysEnabled, true);
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 			$values = $this->appConfig->getValues(false, 'enabled');
107 107
 
108 108
 			$alwaysEnabledApps = $this->getAlwaysEnabledApps();
109
-			foreach($alwaysEnabledApps as $appId) {
109
+			foreach ($alwaysEnabledApps as $appId) {
110 110
 				$values[$appId] = 'yes';
111 111
 			}
112 112
 
113
-			$this->installedAppsCache = array_filter($values, function ($value) {
113
+			$this->installedAppsCache = array_filter($values, function($value) {
114 114
 				return $value !== 'no';
115 115
 			});
116 116
 			ksort($this->installedAppsCache);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public function getEnabledAppsForUser(IUser $user) {
137 137
 		$apps = $this->getInstalledAppsValues();
138
-		$appsForUser = array_filter($apps, function ($enabled) use ($user) {
138
+		$appsForUser = array_filter($apps, function($enabled) use ($user) {
139 139
 			return $this->checkAppForUser($enabled, $user);
140 140
 		});
141 141
 		return array_keys($appsForUser);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 		} elseif ($user === null) {
175 175
 			return false;
176 176
 		} else {
177
-			if(empty($enabled)){
177
+			if (empty($enabled)) {
178 178
 				return false;
179 179
 			}
180 180
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 
183 183
 			if (!is_array($groupIds)) {
184 184
 				$jsonError = json_last_error();
185
-				\OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
185
+				\OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: '.print_r($enabled, true).' - json error code: '.$jsonError, ['app' => 'lib']);
186 186
 				return false;
187 187
 			}
188 188
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 			}
257 257
 		}
258 258
 
259
-		$groupIds = array_map(function ($group) {
259
+		$groupIds = array_map(function($group) {
260 260
 			/** @var \OCP\IGroup $group */
261 261
 			return $group->getGID();
262 262
 		}, $groups);
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	public function getAppPath($appId) {
297 297
 		$appPath = \OC_App::getAppPath($appId);
298
-		if($appPath === false) {
299
-			throw new AppPathNotFoundException('Could not find path for ' . $appId);
298
+		if ($appPath === false) {
299
+			throw new AppPathNotFoundException('Could not find path for '.$appId);
300 300
 		}
301 301
 		return $appPath;
302 302
 	}
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 
390 390
 	private function loadShippedJson() {
391 391
 		if ($this->shippedApps === null) {
392
-			$shippedJson = \OC::$SERVERROOT . '/core/shipped.json';
392
+			$shippedJson = \OC::$SERVERROOT.'/core/shipped.json';
393 393
 			if (!file_exists($shippedJson)) {
394 394
 				throw new \Exception("File not found: $shippedJson");
395 395
 			}
Please login to merge, or discard this patch.
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -44,367 +44,367 @@
 block discarded – undo
44 44
 
45 45
 class AppManager implements IAppManager {
46 46
 
47
-	/**
48
-	 * Apps with these types can not be enabled for certain groups only
49
-	 * @var string[]
50
-	 */
51
-	protected $protectedAppTypes = [
52
-		'filesystem',
53
-		'prelogin',
54
-		'authentication',
55
-		'logging',
56
-		'prevent_group_restriction',
57
-	];
58
-
59
-	/** @var IUserSession */
60
-	private $userSession;
61
-
62
-	/** @var IAppConfig */
63
-	private $appConfig;
64
-
65
-	/** @var IGroupManager */
66
-	private $groupManager;
67
-
68
-	/** @var ICacheFactory */
69
-	private $memCacheFactory;
70
-
71
-	/** @var EventDispatcherInterface */
72
-	private $dispatcher;
73
-
74
-	/** @var string[] $appId => $enabled */
75
-	private $installedAppsCache;
76
-
77
-	/** @var string[] */
78
-	private $shippedApps;
79
-
80
-	/** @var string[] */
81
-	private $alwaysEnabled;
82
-
83
-	/**
84
-	 * @param IUserSession $userSession
85
-	 * @param IAppConfig $appConfig
86
-	 * @param IGroupManager $groupManager
87
-	 * @param ICacheFactory $memCacheFactory
88
-	 * @param EventDispatcherInterface $dispatcher
89
-	 */
90
-	public function __construct(IUserSession $userSession,
91
-								IAppConfig $appConfig,
92
-								IGroupManager $groupManager,
93
-								ICacheFactory $memCacheFactory,
94
-								EventDispatcherInterface $dispatcher) {
95
-		$this->userSession = $userSession;
96
-		$this->appConfig = $appConfig;
97
-		$this->groupManager = $groupManager;
98
-		$this->memCacheFactory = $memCacheFactory;
99
-		$this->dispatcher = $dispatcher;
100
-	}
101
-
102
-	/**
103
-	 * @return string[] $appId => $enabled
104
-	 */
105
-	private function getInstalledAppsValues() {
106
-		if (!$this->installedAppsCache) {
107
-			$values = $this->appConfig->getValues(false, 'enabled');
108
-
109
-			$alwaysEnabledApps = $this->getAlwaysEnabledApps();
110
-			foreach($alwaysEnabledApps as $appId) {
111
-				$values[$appId] = 'yes';
112
-			}
113
-
114
-			$this->installedAppsCache = array_filter($values, function ($value) {
115
-				return $value !== 'no';
116
-			});
117
-			ksort($this->installedAppsCache);
118
-		}
119
-		return $this->installedAppsCache;
120
-	}
121
-
122
-	/**
123
-	 * List all installed apps
124
-	 *
125
-	 * @return string[]
126
-	 */
127
-	public function getInstalledApps() {
128
-		return array_keys($this->getInstalledAppsValues());
129
-	}
130
-
131
-	/**
132
-	 * List all apps enabled for a user
133
-	 *
134
-	 * @param \OCP\IUser $user
135
-	 * @return string[]
136
-	 */
137
-	public function getEnabledAppsForUser(IUser $user) {
138
-		$apps = $this->getInstalledAppsValues();
139
-		$appsForUser = array_filter($apps, function ($enabled) use ($user) {
140
-			return $this->checkAppForUser($enabled, $user);
141
-		});
142
-		return array_keys($appsForUser);
143
-	}
144
-
145
-	/**
146
-	 * Check if an app is enabled for user
147
-	 *
148
-	 * @param string $appId
149
-	 * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used
150
-	 * @return bool
151
-	 */
152
-	public function isEnabledForUser($appId, $user = null) {
153
-		if ($this->isAlwaysEnabled($appId)) {
154
-			return true;
155
-		}
156
-		if ($user === null) {
157
-			$user = $this->userSession->getUser();
158
-		}
159
-		$installedApps = $this->getInstalledAppsValues();
160
-		if (isset($installedApps[$appId])) {
161
-			return $this->checkAppForUser($installedApps[$appId], $user);
162
-		} else {
163
-			return false;
164
-		}
165
-	}
166
-
167
-	/**
168
-	 * @param string $enabled
169
-	 * @param IUser $user
170
-	 * @return bool
171
-	 */
172
-	private function checkAppForUser($enabled, $user) {
173
-		if ($enabled === 'yes') {
174
-			return true;
175
-		} elseif ($user === null) {
176
-			return false;
177
-		} else {
178
-			if(empty($enabled)){
179
-				return false;
180
-			}
181
-
182
-			$groupIds = json_decode($enabled);
183
-
184
-			if (!is_array($groupIds)) {
185
-				$jsonError = json_last_error();
186
-				\OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
187
-				return false;
188
-			}
189
-
190
-			$userGroups = $this->groupManager->getUserGroupIds($user);
191
-			foreach ($userGroups as $groupId) {
192
-				if (in_array($groupId, $groupIds, true)) {
193
-					return true;
194
-				}
195
-			}
196
-			return false;
197
-		}
198
-	}
199
-
200
-	/**
201
-	 * Check if an app is installed in the instance
202
-	 *
203
-	 * @param string $appId
204
-	 * @return bool
205
-	 */
206
-	public function isInstalled($appId) {
207
-		$installedApps = $this->getInstalledAppsValues();
208
-		return isset($installedApps[$appId]);
209
-	}
210
-
211
-	/**
212
-	 * Enable an app for every user
213
-	 *
214
-	 * @param string $appId
215
-	 * @throws AppPathNotFoundException
216
-	 */
217
-	public function enableApp($appId) {
218
-		// Check if app exists
219
-		$this->getAppPath($appId);
220
-
221
-		$this->installedAppsCache[$appId] = 'yes';
222
-		$this->appConfig->setValue($appId, 'enabled', 'yes');
223
-		$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
224
-			ManagerEvent::EVENT_APP_ENABLE, $appId
225
-		));
226
-		$this->clearAppsCache();
227
-	}
228
-
229
-	/**
230
-	 * Whether a list of types contains a protected app type
231
-	 *
232
-	 * @param string[] $types
233
-	 * @return bool
234
-	 */
235
-	public function hasProtectedAppType($types) {
236
-		if (empty($types)) {
237
-			return false;
238
-		}
239
-
240
-		$protectedTypes = array_intersect($this->protectedAppTypes, $types);
241
-		return !empty($protectedTypes);
242
-	}
243
-
244
-	/**
245
-	 * Enable an app only for specific groups
246
-	 *
247
-	 * @param string $appId
248
-	 * @param \OCP\IGroup[] $groups
249
-	 * @throws \Exception if app can't be enabled for groups
250
-	 */
251
-	public function enableAppForGroups($appId, $groups) {
252
-		$info = $this->getAppInfo($appId);
253
-		if (!empty($info['types'])) {
254
-			$protectedTypes = array_intersect($this->protectedAppTypes, $info['types']);
255
-			if (!empty($protectedTypes)) {
256
-				throw new \Exception("$appId can't be enabled for groups.");
257
-			}
258
-		}
259
-
260
-		$groupIds = array_map(function ($group) {
261
-			/** @var \OCP\IGroup $group */
262
-			return $group->getGID();
263
-		}, $groups);
264
-		$this->installedAppsCache[$appId] = json_encode($groupIds);
265
-		$this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
266
-		$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
267
-			ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
268
-		));
269
-		$this->clearAppsCache();
270
-	}
271
-
272
-	/**
273
-	 * Disable an app for every user
274
-	 *
275
-	 * @param string $appId
276
-	 * @throws \Exception if app can't be disabled
277
-	 */
278
-	public function disableApp($appId) {
279
-		if ($this->isAlwaysEnabled($appId)) {
280
-			throw new \Exception("$appId can't be disabled.");
281
-		}
282
-		unset($this->installedAppsCache[$appId]);
283
-		$this->appConfig->setValue($appId, 'enabled', 'no');
284
-		$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
285
-			ManagerEvent::EVENT_APP_DISABLE, $appId
286
-		));
287
-		$this->clearAppsCache();
288
-	}
289
-
290
-	/**
291
-	 * Get the directory for the given app.
292
-	 *
293
-	 * @param string $appId
294
-	 * @return string
295
-	 * @throws AppPathNotFoundException if app folder can't be found
296
-	 */
297
-	public function getAppPath($appId) {
298
-		$appPath = \OC_App::getAppPath($appId);
299
-		if($appPath === false) {
300
-			throw new AppPathNotFoundException('Could not find path for ' . $appId);
301
-		}
302
-		return $appPath;
303
-	}
304
-
305
-	/**
306
-	 * Clear the cached list of apps when enabling/disabling an app
307
-	 */
308
-	public function clearAppsCache() {
309
-		$settingsMemCache = $this->memCacheFactory->createDistributed('settings');
310
-		$settingsMemCache->clear('listApps');
311
-	}
312
-
313
-	/**
314
-	 * Returns a list of apps that need upgrade
315
-	 *
316
-	 * @param string $version Nextcloud version as array of version components
317
-	 * @return array list of app info from apps that need an upgrade
318
-	 *
319
-	 * @internal
320
-	 */
321
-	public function getAppsNeedingUpgrade($version) {
322
-		$appsToUpgrade = [];
323
-		$apps = $this->getInstalledApps();
324
-		foreach ($apps as $appId) {
325
-			$appInfo = $this->getAppInfo($appId);
326
-			$appDbVersion = $this->appConfig->getValue($appId, 'installed_version');
327
-			if ($appDbVersion
328
-				&& isset($appInfo['version'])
329
-				&& version_compare($appInfo['version'], $appDbVersion, '>')
330
-				&& \OC_App::isAppCompatible($version, $appInfo)
331
-			) {
332
-				$appsToUpgrade[] = $appInfo;
333
-			}
334
-		}
335
-
336
-		return $appsToUpgrade;
337
-	}
338
-
339
-	/**
340
-	 * Returns the app information from "appinfo/info.xml".
341
-	 *
342
-	 * @param string $appId app id
343
-	 *
344
-	 * @return array app info
345
-	 *
346
-	 * @internal
347
-	 */
348
-	public function getAppInfo($appId) {
349
-		$appInfo = \OC_App::getAppInfo($appId);
350
-		if (!isset($appInfo['version'])) {
351
-			// read version from separate file
352
-			$appInfo['version'] = \OC_App::getAppVersion($appId);
353
-		}
354
-		return $appInfo;
355
-	}
356
-
357
-	/**
358
-	 * Returns a list of apps incompatible with the given version
359
-	 *
360
-	 * @param string $version Nextcloud version as array of version components
361
-	 *
362
-	 * @return array list of app info from incompatible apps
363
-	 *
364
-	 * @internal
365
-	 */
366
-	public function getIncompatibleApps($version) {
367
-		$apps = $this->getInstalledApps();
368
-		$incompatibleApps = array();
369
-		foreach ($apps as $appId) {
370
-			$info = $this->getAppInfo($appId);
371
-			if (!\OC_App::isAppCompatible($version, $info)) {
372
-				$incompatibleApps[] = $info;
373
-			}
374
-		}
375
-		return $incompatibleApps;
376
-	}
377
-
378
-	/**
379
-	 * @inheritdoc
380
-	 */
381
-	public function isShipped($appId) {
382
-		$this->loadShippedJson();
383
-		return in_array($appId, $this->shippedApps, true);
384
-	}
385
-
386
-	private function isAlwaysEnabled($appId) {
387
-		$alwaysEnabled = $this->getAlwaysEnabledApps();
388
-		return in_array($appId, $alwaysEnabled, true);
389
-	}
390
-
391
-	private function loadShippedJson() {
392
-		if ($this->shippedApps === null) {
393
-			$shippedJson = \OC::$SERVERROOT . '/core/shipped.json';
394
-			if (!file_exists($shippedJson)) {
395
-				throw new \Exception("File not found: $shippedJson");
396
-			}
397
-			$content = json_decode(file_get_contents($shippedJson), true);
398
-			$this->shippedApps = $content['shippedApps'];
399
-			$this->alwaysEnabled = $content['alwaysEnabled'];
400
-		}
401
-	}
402
-
403
-	/**
404
-	 * @inheritdoc
405
-	 */
406
-	public function getAlwaysEnabledApps() {
407
-		$this->loadShippedJson();
408
-		return $this->alwaysEnabled;
409
-	}
47
+    /**
48
+     * Apps with these types can not be enabled for certain groups only
49
+     * @var string[]
50
+     */
51
+    protected $protectedAppTypes = [
52
+        'filesystem',
53
+        'prelogin',
54
+        'authentication',
55
+        'logging',
56
+        'prevent_group_restriction',
57
+    ];
58
+
59
+    /** @var IUserSession */
60
+    private $userSession;
61
+
62
+    /** @var IAppConfig */
63
+    private $appConfig;
64
+
65
+    /** @var IGroupManager */
66
+    private $groupManager;
67
+
68
+    /** @var ICacheFactory */
69
+    private $memCacheFactory;
70
+
71
+    /** @var EventDispatcherInterface */
72
+    private $dispatcher;
73
+
74
+    /** @var string[] $appId => $enabled */
75
+    private $installedAppsCache;
76
+
77
+    /** @var string[] */
78
+    private $shippedApps;
79
+
80
+    /** @var string[] */
81
+    private $alwaysEnabled;
82
+
83
+    /**
84
+     * @param IUserSession $userSession
85
+     * @param IAppConfig $appConfig
86
+     * @param IGroupManager $groupManager
87
+     * @param ICacheFactory $memCacheFactory
88
+     * @param EventDispatcherInterface $dispatcher
89
+     */
90
+    public function __construct(IUserSession $userSession,
91
+                                IAppConfig $appConfig,
92
+                                IGroupManager $groupManager,
93
+                                ICacheFactory $memCacheFactory,
94
+                                EventDispatcherInterface $dispatcher) {
95
+        $this->userSession = $userSession;
96
+        $this->appConfig = $appConfig;
97
+        $this->groupManager = $groupManager;
98
+        $this->memCacheFactory = $memCacheFactory;
99
+        $this->dispatcher = $dispatcher;
100
+    }
101
+
102
+    /**
103
+     * @return string[] $appId => $enabled
104
+     */
105
+    private function getInstalledAppsValues() {
106
+        if (!$this->installedAppsCache) {
107
+            $values = $this->appConfig->getValues(false, 'enabled');
108
+
109
+            $alwaysEnabledApps = $this->getAlwaysEnabledApps();
110
+            foreach($alwaysEnabledApps as $appId) {
111
+                $values[$appId] = 'yes';
112
+            }
113
+
114
+            $this->installedAppsCache = array_filter($values, function ($value) {
115
+                return $value !== 'no';
116
+            });
117
+            ksort($this->installedAppsCache);
118
+        }
119
+        return $this->installedAppsCache;
120
+    }
121
+
122
+    /**
123
+     * List all installed apps
124
+     *
125
+     * @return string[]
126
+     */
127
+    public function getInstalledApps() {
128
+        return array_keys($this->getInstalledAppsValues());
129
+    }
130
+
131
+    /**
132
+     * List all apps enabled for a user
133
+     *
134
+     * @param \OCP\IUser $user
135
+     * @return string[]
136
+     */
137
+    public function getEnabledAppsForUser(IUser $user) {
138
+        $apps = $this->getInstalledAppsValues();
139
+        $appsForUser = array_filter($apps, function ($enabled) use ($user) {
140
+            return $this->checkAppForUser($enabled, $user);
141
+        });
142
+        return array_keys($appsForUser);
143
+    }
144
+
145
+    /**
146
+     * Check if an app is enabled for user
147
+     *
148
+     * @param string $appId
149
+     * @param \OCP\IUser $user (optional) if not defined, the currently logged in user will be used
150
+     * @return bool
151
+     */
152
+    public function isEnabledForUser($appId, $user = null) {
153
+        if ($this->isAlwaysEnabled($appId)) {
154
+            return true;
155
+        }
156
+        if ($user === null) {
157
+            $user = $this->userSession->getUser();
158
+        }
159
+        $installedApps = $this->getInstalledAppsValues();
160
+        if (isset($installedApps[$appId])) {
161
+            return $this->checkAppForUser($installedApps[$appId], $user);
162
+        } else {
163
+            return false;
164
+        }
165
+    }
166
+
167
+    /**
168
+     * @param string $enabled
169
+     * @param IUser $user
170
+     * @return bool
171
+     */
172
+    private function checkAppForUser($enabled, $user) {
173
+        if ($enabled === 'yes') {
174
+            return true;
175
+        } elseif ($user === null) {
176
+            return false;
177
+        } else {
178
+            if(empty($enabled)){
179
+                return false;
180
+            }
181
+
182
+            $groupIds = json_decode($enabled);
183
+
184
+            if (!is_array($groupIds)) {
185
+                $jsonError = json_last_error();
186
+                \OC::$server->getLogger()->warning('AppManger::checkAppForUser - can\'t decode group IDs: ' . print_r($enabled, true) . ' - json error code: ' . $jsonError, ['app' => 'lib']);
187
+                return false;
188
+            }
189
+
190
+            $userGroups = $this->groupManager->getUserGroupIds($user);
191
+            foreach ($userGroups as $groupId) {
192
+                if (in_array($groupId, $groupIds, true)) {
193
+                    return true;
194
+                }
195
+            }
196
+            return false;
197
+        }
198
+    }
199
+
200
+    /**
201
+     * Check if an app is installed in the instance
202
+     *
203
+     * @param string $appId
204
+     * @return bool
205
+     */
206
+    public function isInstalled($appId) {
207
+        $installedApps = $this->getInstalledAppsValues();
208
+        return isset($installedApps[$appId]);
209
+    }
210
+
211
+    /**
212
+     * Enable an app for every user
213
+     *
214
+     * @param string $appId
215
+     * @throws AppPathNotFoundException
216
+     */
217
+    public function enableApp($appId) {
218
+        // Check if app exists
219
+        $this->getAppPath($appId);
220
+
221
+        $this->installedAppsCache[$appId] = 'yes';
222
+        $this->appConfig->setValue($appId, 'enabled', 'yes');
223
+        $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
224
+            ManagerEvent::EVENT_APP_ENABLE, $appId
225
+        ));
226
+        $this->clearAppsCache();
227
+    }
228
+
229
+    /**
230
+     * Whether a list of types contains a protected app type
231
+     *
232
+     * @param string[] $types
233
+     * @return bool
234
+     */
235
+    public function hasProtectedAppType($types) {
236
+        if (empty($types)) {
237
+            return false;
238
+        }
239
+
240
+        $protectedTypes = array_intersect($this->protectedAppTypes, $types);
241
+        return !empty($protectedTypes);
242
+    }
243
+
244
+    /**
245
+     * Enable an app only for specific groups
246
+     *
247
+     * @param string $appId
248
+     * @param \OCP\IGroup[] $groups
249
+     * @throws \Exception if app can't be enabled for groups
250
+     */
251
+    public function enableAppForGroups($appId, $groups) {
252
+        $info = $this->getAppInfo($appId);
253
+        if (!empty($info['types'])) {
254
+            $protectedTypes = array_intersect($this->protectedAppTypes, $info['types']);
255
+            if (!empty($protectedTypes)) {
256
+                throw new \Exception("$appId can't be enabled for groups.");
257
+            }
258
+        }
259
+
260
+        $groupIds = array_map(function ($group) {
261
+            /** @var \OCP\IGroup $group */
262
+            return $group->getGID();
263
+        }, $groups);
264
+        $this->installedAppsCache[$appId] = json_encode($groupIds);
265
+        $this->appConfig->setValue($appId, 'enabled', json_encode($groupIds));
266
+        $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
267
+            ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
268
+        ));
269
+        $this->clearAppsCache();
270
+    }
271
+
272
+    /**
273
+     * Disable an app for every user
274
+     *
275
+     * @param string $appId
276
+     * @throws \Exception if app can't be disabled
277
+     */
278
+    public function disableApp($appId) {
279
+        if ($this->isAlwaysEnabled($appId)) {
280
+            throw new \Exception("$appId can't be disabled.");
281
+        }
282
+        unset($this->installedAppsCache[$appId]);
283
+        $this->appConfig->setValue($appId, 'enabled', 'no');
284
+        $this->dispatcher->dispatch(ManagerEvent::EVENT_APP_DISABLE, new ManagerEvent(
285
+            ManagerEvent::EVENT_APP_DISABLE, $appId
286
+        ));
287
+        $this->clearAppsCache();
288
+    }
289
+
290
+    /**
291
+     * Get the directory for the given app.
292
+     *
293
+     * @param string $appId
294
+     * @return string
295
+     * @throws AppPathNotFoundException if app folder can't be found
296
+     */
297
+    public function getAppPath($appId) {
298
+        $appPath = \OC_App::getAppPath($appId);
299
+        if($appPath === false) {
300
+            throw new AppPathNotFoundException('Could not find path for ' . $appId);
301
+        }
302
+        return $appPath;
303
+    }
304
+
305
+    /**
306
+     * Clear the cached list of apps when enabling/disabling an app
307
+     */
308
+    public function clearAppsCache() {
309
+        $settingsMemCache = $this->memCacheFactory->createDistributed('settings');
310
+        $settingsMemCache->clear('listApps');
311
+    }
312
+
313
+    /**
314
+     * Returns a list of apps that need upgrade
315
+     *
316
+     * @param string $version Nextcloud version as array of version components
317
+     * @return array list of app info from apps that need an upgrade
318
+     *
319
+     * @internal
320
+     */
321
+    public function getAppsNeedingUpgrade($version) {
322
+        $appsToUpgrade = [];
323
+        $apps = $this->getInstalledApps();
324
+        foreach ($apps as $appId) {
325
+            $appInfo = $this->getAppInfo($appId);
326
+            $appDbVersion = $this->appConfig->getValue($appId, 'installed_version');
327
+            if ($appDbVersion
328
+                && isset($appInfo['version'])
329
+                && version_compare($appInfo['version'], $appDbVersion, '>')
330
+                && \OC_App::isAppCompatible($version, $appInfo)
331
+            ) {
332
+                $appsToUpgrade[] = $appInfo;
333
+            }
334
+        }
335
+
336
+        return $appsToUpgrade;
337
+    }
338
+
339
+    /**
340
+     * Returns the app information from "appinfo/info.xml".
341
+     *
342
+     * @param string $appId app id
343
+     *
344
+     * @return array app info
345
+     *
346
+     * @internal
347
+     */
348
+    public function getAppInfo($appId) {
349
+        $appInfo = \OC_App::getAppInfo($appId);
350
+        if (!isset($appInfo['version'])) {
351
+            // read version from separate file
352
+            $appInfo['version'] = \OC_App::getAppVersion($appId);
353
+        }
354
+        return $appInfo;
355
+    }
356
+
357
+    /**
358
+     * Returns a list of apps incompatible with the given version
359
+     *
360
+     * @param string $version Nextcloud version as array of version components
361
+     *
362
+     * @return array list of app info from incompatible apps
363
+     *
364
+     * @internal
365
+     */
366
+    public function getIncompatibleApps($version) {
367
+        $apps = $this->getInstalledApps();
368
+        $incompatibleApps = array();
369
+        foreach ($apps as $appId) {
370
+            $info = $this->getAppInfo($appId);
371
+            if (!\OC_App::isAppCompatible($version, $info)) {
372
+                $incompatibleApps[] = $info;
373
+            }
374
+        }
375
+        return $incompatibleApps;
376
+    }
377
+
378
+    /**
379
+     * @inheritdoc
380
+     */
381
+    public function isShipped($appId) {
382
+        $this->loadShippedJson();
383
+        return in_array($appId, $this->shippedApps, true);
384
+    }
385
+
386
+    private function isAlwaysEnabled($appId) {
387
+        $alwaysEnabled = $this->getAlwaysEnabledApps();
388
+        return in_array($appId, $alwaysEnabled, true);
389
+    }
390
+
391
+    private function loadShippedJson() {
392
+        if ($this->shippedApps === null) {
393
+            $shippedJson = \OC::$SERVERROOT . '/core/shipped.json';
394
+            if (!file_exists($shippedJson)) {
395
+                throw new \Exception("File not found: $shippedJson");
396
+            }
397
+            $content = json_decode(file_get_contents($shippedJson), true);
398
+            $this->shippedApps = $content['shippedApps'];
399
+            $this->alwaysEnabled = $content['alwaysEnabled'];
400
+        }
401
+    }
402
+
403
+    /**
404
+     * @inheritdoc
405
+     */
406
+    public function getAlwaysEnabledApps() {
407
+        $this->loadShippedJson();
408
+        return $this->alwaysEnabled;
409
+    }
410 410
 }
Please login to merge, or discard this patch.
lib/public/App/IAppManager.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -34,103 +34,103 @@
 block discarded – undo
34 34
  * @since 8.0.0
35 35
  */
36 36
 interface IAppManager {
37
-	/**
38
-	 * Check if an app is enabled for user
39
-	 *
40
-	 * @param string $appId
41
-	 * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used
42
-	 * @return bool
43
-	 * @since 8.0.0
44
-	 */
45
-	public function isEnabledForUser($appId, $user = null);
37
+    /**
38
+     * Check if an app is enabled for user
39
+     *
40
+     * @param string $appId
41
+     * @param \OCP\IUser $user (optional) if not defined, the currently loggedin user will be used
42
+     * @return bool
43
+     * @since 8.0.0
44
+     */
45
+    public function isEnabledForUser($appId, $user = null);
46 46
 
47
-	/**
48
-	 * Check if an app is installed in the instance
49
-	 *
50
-	 * @param string $appId
51
-	 * @return bool
52
-	 * @since 8.0.0
53
-	 */
54
-	public function isInstalled($appId);
47
+    /**
48
+     * Check if an app is installed in the instance
49
+     *
50
+     * @param string $appId
51
+     * @return bool
52
+     * @since 8.0.0
53
+     */
54
+    public function isInstalled($appId);
55 55
 
56
-	/**
57
-	 * Enable an app for every user
58
-	 *
59
-	 * @param string $appId
60
-	 * @throws AppPathNotFoundException
61
-	 * @since 8.0.0
62
-	 */
63
-	public function enableApp($appId);
56
+    /**
57
+     * Enable an app for every user
58
+     *
59
+     * @param string $appId
60
+     * @throws AppPathNotFoundException
61
+     * @since 8.0.0
62
+     */
63
+    public function enableApp($appId);
64 64
 
65
-	/**
66
-	 * Whether a list of types contains a protected app type
67
-	 *
68
-	 * @param string[] $types
69
-	 * @return bool
70
-	 * @since 12.0.0
71
-	 */
72
-	public function hasProtectedAppType($types);
65
+    /**
66
+     * Whether a list of types contains a protected app type
67
+     *
68
+     * @param string[] $types
69
+     * @return bool
70
+     * @since 12.0.0
71
+     */
72
+    public function hasProtectedAppType($types);
73 73
 
74
-	/**
75
-	 * Enable an app only for specific groups
76
-	 *
77
-	 * @param string $appId
78
-	 * @param \OCP\IGroup[] $groups
79
-	 * @since 8.0.0
80
-	 */
81
-	public function enableAppForGroups($appId, $groups);
74
+    /**
75
+     * Enable an app only for specific groups
76
+     *
77
+     * @param string $appId
78
+     * @param \OCP\IGroup[] $groups
79
+     * @since 8.0.0
80
+     */
81
+    public function enableAppForGroups($appId, $groups);
82 82
 
83
-	/**
84
-	 * Disable an app for every user
85
-	 *
86
-	 * @param string $appId
87
-	 * @since 8.0.0
88
-	 */
89
-	public function disableApp($appId);
83
+    /**
84
+     * Disable an app for every user
85
+     *
86
+     * @param string $appId
87
+     * @since 8.0.0
88
+     */
89
+    public function disableApp($appId);
90 90
 
91
-	/**
92
-	 * Get the directory for the given app.
93
-	 *
94
-	 * @param string $appId
95
-	 * @return string
96
-	 * @since 11.0.0
97
-	 * @throws AppPathNotFoundException
98
-	 */
99
-	public function getAppPath($appId);
91
+    /**
92
+     * Get the directory for the given app.
93
+     *
94
+     * @param string $appId
95
+     * @return string
96
+     * @since 11.0.0
97
+     * @throws AppPathNotFoundException
98
+     */
99
+    public function getAppPath($appId);
100 100
 
101
-	/**
102
-	 * List all apps enabled for a user
103
-	 *
104
-	 * @param \OCP\IUser $user
105
-	 * @return string[]
106
-	 * @since 8.1.0
107
-	 */
108
-	public function getEnabledAppsForUser(IUser $user);
101
+    /**
102
+     * List all apps enabled for a user
103
+     *
104
+     * @param \OCP\IUser $user
105
+     * @return string[]
106
+     * @since 8.1.0
107
+     */
108
+    public function getEnabledAppsForUser(IUser $user);
109 109
 
110
-	/**
111
-	 * List all installed apps
112
-	 *
113
-	 * @return string[]
114
-	 * @since 8.1.0
115
-	 */
116
-	public function getInstalledApps();
110
+    /**
111
+     * List all installed apps
112
+     *
113
+     * @return string[]
114
+     * @since 8.1.0
115
+     */
116
+    public function getInstalledApps();
117 117
 
118
-	/**
119
-	 * Clear the cached list of apps when enabling/disabling an app
120
-	 * @since 8.1.0
121
-	 */
122
-	public function clearAppsCache();
118
+    /**
119
+     * Clear the cached list of apps when enabling/disabling an app
120
+     * @since 8.1.0
121
+     */
122
+    public function clearAppsCache();
123 123
 
124
-	/**
125
-	 * @param string $appId
126
-	 * @return boolean
127
-	 * @since 9.0.0
128
-	 */
129
-	public function isShipped($appId);
124
+    /**
125
+     * @param string $appId
126
+     * @return boolean
127
+     * @since 9.0.0
128
+     */
129
+    public function isShipped($appId);
130 130
 
131
-	/**
132
-	 * @return string[]
133
-	 * @since 9.0.0
134
-	 */
135
-	public function getAlwaysEnabledApps();
131
+    /**
132
+     * @return string[]
133
+     * @since 9.0.0
134
+     */
135
+    public function getAlwaysEnabledApps();
136 136
 }
Please login to merge, or discard this patch.