Passed
Push — master ( f0dd71...c56a27 )
by Christoph
11:49 queued 12s
created
apps/dav/lib/CardDAV/Converter.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -31,122 +31,122 @@
 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
-			return $user->getAvatarImage(-1);
147
-		} catch (\Exception $ex) {
148
-			return null;
149
-		}
150
-	}
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
+            return $user->getAvatarImage(-1);
147
+        } catch (\Exception $ex) {
148
+            return null;
149
+        }
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/UserStoragesService.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -40,104 +40,104 @@
 block discarded – undo
40 40
  * (aka personal storages)
41 41
  */
42 42
 class UserStoragesService extends StoragesService {
43
-	use UserTrait;
43
+    use UserTrait;
44 44
 
45
-	/**
46
-	 * Create a user storages service
47
-	 *
48
-	 * @param BackendService $backendService
49
-	 * @param DBConfigService $dbConfig
50
-	 * @param IUserSession $userSession user session
51
-	 * @param IUserMountCache $userMountCache
52
-	 */
53
-	public function __construct(
54
-		BackendService $backendService,
55
-		DBConfigService $dbConfig,
56
-		IUserSession $userSession,
57
-		IUserMountCache $userMountCache
58
-	) {
59
-		$this->userSession = $userSession;
60
-		parent::__construct($backendService, $dbConfig, $userMountCache);
61
-	}
45
+    /**
46
+     * Create a user storages service
47
+     *
48
+     * @param BackendService $backendService
49
+     * @param DBConfigService $dbConfig
50
+     * @param IUserSession $userSession user session
51
+     * @param IUserMountCache $userMountCache
52
+     */
53
+    public function __construct(
54
+        BackendService $backendService,
55
+        DBConfigService $dbConfig,
56
+        IUserSession $userSession,
57
+        IUserMountCache $userMountCache
58
+    ) {
59
+        $this->userSession = $userSession;
60
+        parent::__construct($backendService, $dbConfig, $userMountCache);
61
+    }
62 62
 
63
-	protected function readDBConfig() {
64
-		return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
65
-	}
63
+    protected function readDBConfig() {
64
+        return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
65
+    }
66 66
 
67
-	/**
68
-	 * Triggers $signal for all applicable users of the given
69
-	 * storage
70
-	 *
71
-	 * @param StorageConfig $storage storage data
72
-	 * @param string $signal signal to trigger
73
-	 */
74
-	protected function triggerHooks(StorageConfig $storage, $signal) {
75
-		$user = $this->getUser()->getUID();
67
+    /**
68
+     * Triggers $signal for all applicable users of the given
69
+     * storage
70
+     *
71
+     * @param StorageConfig $storage storage data
72
+     * @param string $signal signal to trigger
73
+     */
74
+    protected function triggerHooks(StorageConfig $storage, $signal) {
75
+        $user = $this->getUser()->getUID();
76 76
 
77
-		// trigger hook for the current user
78
-		$this->triggerApplicableHooks(
79
-			$signal,
80
-			$storage->getMountPoint(),
81
-			\OC_Mount_Config::MOUNT_TYPE_USER,
82
-			[$user]
83
-		);
84
-	}
77
+        // trigger hook for the current user
78
+        $this->triggerApplicableHooks(
79
+            $signal,
80
+            $storage->getMountPoint(),
81
+            \OC_Mount_Config::MOUNT_TYPE_USER,
82
+            [$user]
83
+        );
84
+    }
85 85
 
86
-	/**
87
-	 * Triggers signal_create_mount or signal_delete_mount to
88
-	 * accommodate for additions/deletions in applicableUsers
89
-	 * and applicableGroups fields.
90
-	 *
91
-	 * @param StorageConfig $oldStorage old storage data
92
-	 * @param StorageConfig $newStorage new storage data
93
-	 */
94
-	protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
95
-		// if mount point changed, it's like a deletion + creation
96
-		if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
97
-			$this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
98
-			$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
99
-		}
100
-	}
86
+    /**
87
+     * Triggers signal_create_mount or signal_delete_mount to
88
+     * accommodate for additions/deletions in applicableUsers
89
+     * and applicableGroups fields.
90
+     *
91
+     * @param StorageConfig $oldStorage old storage data
92
+     * @param StorageConfig $newStorage new storage data
93
+     */
94
+    protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) {
95
+        // if mount point changed, it's like a deletion + creation
96
+        if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) {
97
+            $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount);
98
+            $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
99
+        }
100
+    }
101 101
 
102
-	protected function getType() {
103
-		return DBConfigService::MOUNT_TYPE_PERSONAl;
104
-	}
102
+    protected function getType() {
103
+        return DBConfigService::MOUNT_TYPE_PERSONAl;
104
+    }
105 105
 
106
-	/**
107
-	 * Add new storage to the configuration
108
-	 *
109
-	 * @param StorageConfig $newStorage storage attributes
110
-	 *
111
-	 * @return StorageConfig storage config, with added id
112
-	 */
113
-	public function addStorage(StorageConfig $newStorage) {
114
-		$newStorage->setApplicableUsers([$this->getUser()->getUID()]);
115
-		return parent::addStorage($newStorage);
116
-	}
106
+    /**
107
+     * Add new storage to the configuration
108
+     *
109
+     * @param StorageConfig $newStorage storage attributes
110
+     *
111
+     * @return StorageConfig storage config, with added id
112
+     */
113
+    public function addStorage(StorageConfig $newStorage) {
114
+        $newStorage->setApplicableUsers([$this->getUser()->getUID()]);
115
+        return parent::addStorage($newStorage);
116
+    }
117 117
 
118
-	/**
119
-	 * Update storage to the configuration
120
-	 *
121
-	 * @param StorageConfig $updatedStorage storage attributes
122
-	 *
123
-	 * @return StorageConfig storage config
124
-	 * @throws NotFoundException if the given storage does not exist in the config
125
-	 */
126
-	public function updateStorage(StorageConfig $updatedStorage) {
127
-		$updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
128
-		return parent::updateStorage($updatedStorage);
129
-	}
118
+    /**
119
+     * Update storage to the configuration
120
+     *
121
+     * @param StorageConfig $updatedStorage storage attributes
122
+     *
123
+     * @return StorageConfig storage config
124
+     * @throws NotFoundException if the given storage does not exist in the config
125
+     */
126
+    public function updateStorage(StorageConfig $updatedStorage) {
127
+        $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
128
+        return parent::updateStorage($updatedStorage);
129
+    }
130 130
 
131
-	/**
132
-	 * Get the visibility type for this controller, used in validation
133
-	 *
134
-	 * @return string BackendService::VISIBILITY_* constants
135
-	 */
136
-	public function getVisibilityType() {
137
-		return BackendService::VISIBILITY_PERSONAL;
138
-	}
131
+    /**
132
+     * Get the visibility type for this controller, used in validation
133
+     *
134
+     * @return string BackendService::VISIBILITY_* constants
135
+     */
136
+    public function getVisibilityType() {
137
+        return BackendService::VISIBILITY_PERSONAL;
138
+    }
139 139
 
140
-	protected function isApplicable(StorageConfig $config) {
141
-		return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
142
-	}
140
+    protected function isApplicable(StorageConfig $config) {
141
+        return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl;
142
+    }
143 143
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Util.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -37,166 +37,166 @@
 block discarded – undo
37 37
 use OCP\PreConditionNotMetException;
38 38
 
39 39
 class Util {
40
-	/**
41
-	 * @var View
42
-	 */
43
-	private $files;
44
-	/**
45
-	 * @var Crypt
46
-	 */
47
-	private $crypt;
48
-	/**
49
-	 * @var ILogger
50
-	 */
51
-	private $logger;
52
-	/**
53
-	 * @var bool|IUser
54
-	 */
55
-	private $user;
56
-	/**
57
-	 * @var IConfig
58
-	 */
59
-	private $config;
60
-	/**
61
-	 * @var IUserManager
62
-	 */
63
-	private $userManager;
64
-
65
-	/**
66
-	 * Util constructor.
67
-	 *
68
-	 * @param View $files
69
-	 * @param Crypt $crypt
70
-	 * @param ILogger $logger
71
-	 * @param IUserSession $userSession
72
-	 * @param IConfig $config
73
-	 * @param IUserManager $userManager
74
-	 */
75
-	public function __construct(View $files,
76
-								Crypt $crypt,
77
-								ILogger $logger,
78
-								IUserSession $userSession,
79
-								IConfig $config,
80
-								IUserManager $userManager
81
-	) {
82
-		$this->files = $files;
83
-		$this->crypt = $crypt;
84
-		$this->logger = $logger;
85
-		$this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false;
86
-		$this->config = $config;
87
-		$this->userManager = $userManager;
88
-	}
89
-
90
-	/**
91
-	 * check if recovery key is enabled for user
92
-	 *
93
-	 * @param string $uid
94
-	 * @return bool
95
-	 */
96
-	public function isRecoveryEnabledForUser($uid) {
97
-		$recoveryMode = $this->config->getUserValue($uid,
98
-			'encryption',
99
-			'recoveryEnabled',
100
-			'0');
101
-
102
-		return ($recoveryMode === '1');
103
-	}
104
-
105
-	/**
106
-	 * check if the home storage should be encrypted
107
-	 *
108
-	 * @return bool
109
-	 */
110
-	public function shouldEncryptHomeStorage() {
111
-		$encryptHomeStorage = $this->config->getAppValue(
112
-			'encryption',
113
-			'encryptHomeStorage',
114
-			'1'
115
-		);
116
-
117
-		return ($encryptHomeStorage === '1');
118
-	}
119
-
120
-	/**
121
-	 * set the home storage encryption on/off
122
-	 *
123
-	 * @param bool $encryptHomeStorage
124
-	 */
125
-	public function setEncryptHomeStorage($encryptHomeStorage) {
126
-		$value = $encryptHomeStorage ? '1' : '0';
127
-		$this->config->setAppValue(
128
-			'encryption',
129
-			'encryptHomeStorage',
130
-			$value
131
-		);
132
-	}
133
-
134
-	/**
135
-	 * check if master key is enabled
136
-	 *
137
-	 * @return bool
138
-	 */
139
-	public function isMasterKeyEnabled() {
140
-		$userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1');
141
-		return ($userMasterKey === '1');
142
-	}
143
-
144
-	/**
145
-	 * @param $enabled
146
-	 * @return bool
147
-	 */
148
-	public function setRecoveryForUser($enabled) {
149
-		$value = $enabled ? '1' : '0';
150
-
151
-		try {
152
-			$this->config->setUserValue($this->user->getUID(),
153
-				'encryption',
154
-				'recoveryEnabled',
155
-				$value);
156
-			return true;
157
-		} catch (PreConditionNotMetException $e) {
158
-			return false;
159
-		}
160
-	}
161
-
162
-	/**
163
-	 * @param string $uid
164
-	 * @return bool
165
-	 */
166
-	public function userHasFiles($uid) {
167
-		return $this->files->file_exists($uid . '/files');
168
-	}
169
-
170
-	/**
171
-	 * get owner from give path, path relative to data/ expected
172
-	 *
173
-	 * @param string $path relative to data/
174
-	 * @return string
175
-	 * @throws \BadMethodCallException
176
-	 */
177
-	public function getOwner($path) {
178
-		$owner = '';
179
-		$parts = explode('/', $path, 3);
180
-		if (count($parts) > 1) {
181
-			$owner = $parts[1];
182
-			if ($this->userManager->userExists($owner) === false) {
183
-				throw new \BadMethodCallException('Unknown user: ' .
184
-				'method expects path to a user folder relative to the data folder');
185
-			}
186
-
187
-		}
188
-
189
-		return $owner;
190
-	}
191
-
192
-	/**
193
-	 * get storage of path
194
-	 *
195
-	 * @param string $path
196
-	 * @return \OC\Files\Storage\Storage
197
-	 */
198
-	public function getStorage($path) {
199
-		return $this->files->getMount($path)->getStorage();
200
-	}
40
+    /**
41
+     * @var View
42
+     */
43
+    private $files;
44
+    /**
45
+     * @var Crypt
46
+     */
47
+    private $crypt;
48
+    /**
49
+     * @var ILogger
50
+     */
51
+    private $logger;
52
+    /**
53
+     * @var bool|IUser
54
+     */
55
+    private $user;
56
+    /**
57
+     * @var IConfig
58
+     */
59
+    private $config;
60
+    /**
61
+     * @var IUserManager
62
+     */
63
+    private $userManager;
64
+
65
+    /**
66
+     * Util constructor.
67
+     *
68
+     * @param View $files
69
+     * @param Crypt $crypt
70
+     * @param ILogger $logger
71
+     * @param IUserSession $userSession
72
+     * @param IConfig $config
73
+     * @param IUserManager $userManager
74
+     */
75
+    public function __construct(View $files,
76
+                                Crypt $crypt,
77
+                                ILogger $logger,
78
+                                IUserSession $userSession,
79
+                                IConfig $config,
80
+                                IUserManager $userManager
81
+    ) {
82
+        $this->files = $files;
83
+        $this->crypt = $crypt;
84
+        $this->logger = $logger;
85
+        $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false;
86
+        $this->config = $config;
87
+        $this->userManager = $userManager;
88
+    }
89
+
90
+    /**
91
+     * check if recovery key is enabled for user
92
+     *
93
+     * @param string $uid
94
+     * @return bool
95
+     */
96
+    public function isRecoveryEnabledForUser($uid) {
97
+        $recoveryMode = $this->config->getUserValue($uid,
98
+            'encryption',
99
+            'recoveryEnabled',
100
+            '0');
101
+
102
+        return ($recoveryMode === '1');
103
+    }
104
+
105
+    /**
106
+     * check if the home storage should be encrypted
107
+     *
108
+     * @return bool
109
+     */
110
+    public function shouldEncryptHomeStorage() {
111
+        $encryptHomeStorage = $this->config->getAppValue(
112
+            'encryption',
113
+            'encryptHomeStorage',
114
+            '1'
115
+        );
116
+
117
+        return ($encryptHomeStorage === '1');
118
+    }
119
+
120
+    /**
121
+     * set the home storage encryption on/off
122
+     *
123
+     * @param bool $encryptHomeStorage
124
+     */
125
+    public function setEncryptHomeStorage($encryptHomeStorage) {
126
+        $value = $encryptHomeStorage ? '1' : '0';
127
+        $this->config->setAppValue(
128
+            'encryption',
129
+            'encryptHomeStorage',
130
+            $value
131
+        );
132
+    }
133
+
134
+    /**
135
+     * check if master key is enabled
136
+     *
137
+     * @return bool
138
+     */
139
+    public function isMasterKeyEnabled() {
140
+        $userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1');
141
+        return ($userMasterKey === '1');
142
+    }
143
+
144
+    /**
145
+     * @param $enabled
146
+     * @return bool
147
+     */
148
+    public function setRecoveryForUser($enabled) {
149
+        $value = $enabled ? '1' : '0';
150
+
151
+        try {
152
+            $this->config->setUserValue($this->user->getUID(),
153
+                'encryption',
154
+                'recoveryEnabled',
155
+                $value);
156
+            return true;
157
+        } catch (PreConditionNotMetException $e) {
158
+            return false;
159
+        }
160
+    }
161
+
162
+    /**
163
+     * @param string $uid
164
+     * @return bool
165
+     */
166
+    public function userHasFiles($uid) {
167
+        return $this->files->file_exists($uid . '/files');
168
+    }
169
+
170
+    /**
171
+     * get owner from give path, path relative to data/ expected
172
+     *
173
+     * @param string $path relative to data/
174
+     * @return string
175
+     * @throws \BadMethodCallException
176
+     */
177
+    public function getOwner($path) {
178
+        $owner = '';
179
+        $parts = explode('/', $path, 3);
180
+        if (count($parts) > 1) {
181
+            $owner = $parts[1];
182
+            if ($this->userManager->userExists($owner) === false) {
183
+                throw new \BadMethodCallException('Unknown user: ' .
184
+                'method expects path to a user folder relative to the data folder');
185
+            }
186
+
187
+        }
188
+
189
+        return $owner;
190
+    }
191
+
192
+    /**
193
+     * get storage of path
194
+     *
195
+     * @param string $path
196
+     * @return \OC\Files\Storage\Storage
197
+     */
198
+    public function getStorage($path) {
199
+        return $this->files->getMount($path)->getStorage();
200
+    }
201 201
 
202 202
 }
Please login to merge, or discard this patch.
core/Command/Config/Import.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -33,193 +33,193 @@
 block discarded – undo
33 33
 use Symfony\Component\Console\Output\OutputInterface;
34 34
 
35 35
 class Import extends Command implements CompletionAwareInterface  {
36
-	protected $validRootKeys = ['system', 'apps'];
37
-
38
-	/** @var IConfig */
39
-	protected $config;
40
-
41
-	/**
42
-	 * @param IConfig $config
43
-	 */
44
-	public function __construct(IConfig $config) {
45
-		parent::__construct();
46
-		$this->config = $config;
47
-	}
48
-
49
-	protected function configure() {
50
-		$this
51
-			->setName('config:import')
52
-			->setDescription('Import a list of configs')
53
-			->addArgument(
54
-				'file',
55
-				InputArgument::OPTIONAL,
56
-				'File with the json array to import'
57
-			)
58
-		;
59
-	}
60
-
61
-	protected function execute(InputInterface $input, OutputInterface $output) {
62
-		$importFile = $input->getArgument('file');
63
-		if ($importFile !== null) {
64
-			$content = $this->getArrayFromFile($importFile);
65
-		} else {
66
-			$content = $this->getArrayFromStdin();
67
-		}
68
-
69
-		try {
70
-			$configs = $this->validateFileContent($content);
71
-		} catch (\UnexpectedValueException $e) {
72
-			$output->writeln('<error>' . $e->getMessage(). '</error>');
73
-			return;
74
-		}
75
-
76
-		if (!empty($configs['system'])) {
77
-			$this->config->setSystemValues($configs['system']);
78
-		}
79
-
80
-		if (!empty($configs['apps'])) {
81
-			foreach ($configs['apps'] as $app => $appConfigs) {
82
-				foreach ($appConfigs as $key => $value) {
83
-					if ($value === null) {
84
-						$this->config->deleteAppValue($app, $key);
85
-					} else {
86
-						$this->config->setAppValue($app, $key, $value);
87
-					}
88
-				}
89
-			}
90
-		}
91
-
92
-		$output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>');
93
-	}
94
-
95
-	/**
96
-	 * Get the content from stdin ("config:import < file.json")
97
-	 *
98
-	 * @return string
99
-	 */
100
-	protected function getArrayFromStdin() {
101
-		// Read from stdin. stream_set_blocking is used to prevent blocking
102
-		// when nothing is passed via stdin.
103
-		stream_set_blocking(STDIN, 0);
104
-		$content = file_get_contents('php://stdin');
105
-		stream_set_blocking(STDIN, 1);
106
-		return $content;
107
-	}
108
-
109
-	/**
110
-	 * Get the content of the specified file ("config:import file.json")
111
-	 *
112
-	 * @param string $importFile
113
-	 * @return string
114
-	 */
115
-	protected function getArrayFromFile($importFile) {
116
-		return file_get_contents($importFile);
117
-	}
118
-
119
-	/**
120
-	 * @param string $content
121
-	 * @return array
122
-	 * @throws \UnexpectedValueException when the array is invalid
123
-	 */
124
-	protected function validateFileContent($content) {
125
-		$decodedContent = json_decode($content, true);
126
-		if (!is_array($decodedContent) || empty($decodedContent)) {
127
-			throw new \UnexpectedValueException('The file must contain a valid json array');
128
-		}
129
-
130
-		$this->validateArray($decodedContent);
131
-
132
-		return $decodedContent;
133
-	}
134
-
135
-	/**
136
-	 * Validates that the array only contains `system` and `apps`
137
-	 *
138
-	 * @param array $array
139
-	 */
140
-	protected function validateArray($array) {
141
-		$arrayKeys = array_keys($array);
142
-		$additionalKeys = array_diff($arrayKeys, $this->validRootKeys);
143
-		$commonKeys = array_intersect($arrayKeys, $this->validRootKeys);
144
-		if (!empty($additionalKeys)) {
145
-			throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys));
146
-		}
147
-		if (empty($commonKeys)) {
148
-			throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys));
149
-		}
150
-
151
-		if (isset($array['system'])) {
152
-			if (is_array($array['system'])) {
153
-				foreach ($array['system'] as $name => $value) {
154
-					$this->checkTypeRecursively($value, $name);
155
-				}
156
-			} else {
157
-				throw new \UnexpectedValueException('The system config array is not an array');
158
-			}
159
-		}
160
-
161
-		if (isset($array['apps'])) {
162
-			if (is_array($array['apps'])) {
163
-				$this->validateAppsArray($array['apps']);
164
-			} else {
165
-				throw new \UnexpectedValueException('The apps config array is not an array');
166
-			}
167
-		}
168
-	}
169
-
170
-	/**
171
-	 * @param mixed $configValue
172
-	 * @param string $configName
173
-	 */
174
-	protected function checkTypeRecursively($configValue, $configName) {
175
-		if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) {
176
-			throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.');
177
-		}
178
-		if (is_array($configValue)) {
179
-			foreach ($configValue as $key => $value) {
180
-				$this->checkTypeRecursively($value, $configName);
181
-			}
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * Validates that app configs are only integers and strings
187
-	 *
188
-	 * @param array $array
189
-	 */
190
-	protected function validateAppsArray($array) {
191
-		foreach ($array as $app => $configs) {
192
-			foreach ($configs as $name => $value) {
193
-				if (!is_int($value) && !is_string($value) && !is_null($value)) {
194
-					throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.');
195
-				}
196
-			}
197
-		}
198
-	}
199
-
200
-	/**
201
-	 * @param string $optionName
202
-	 * @param CompletionContext $context
203
-	 * @return string[]
204
-	 */
205
-	public function completeOptionValues($optionName, CompletionContext $context) {
206
-		return [];
207
-	}
208
-
209
-	/**
210
-	 * @param string $argumentName
211
-	 * @param CompletionContext $context
212
-	 * @return string[]
213
-	 */
214
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
215
-		if ($argumentName === 'file') {
216
-			$helper = new ShellPathCompletion(
217
-				$this->getName(),
218
-				'file',
219
-				Completion::TYPE_ARGUMENT
220
-			);
221
-			return $helper->run();
222
-		}
223
-		return [];
224
-	}
36
+    protected $validRootKeys = ['system', 'apps'];
37
+
38
+    /** @var IConfig */
39
+    protected $config;
40
+
41
+    /**
42
+     * @param IConfig $config
43
+     */
44
+    public function __construct(IConfig $config) {
45
+        parent::__construct();
46
+        $this->config = $config;
47
+    }
48
+
49
+    protected function configure() {
50
+        $this
51
+            ->setName('config:import')
52
+            ->setDescription('Import a list of configs')
53
+            ->addArgument(
54
+                'file',
55
+                InputArgument::OPTIONAL,
56
+                'File with the json array to import'
57
+            )
58
+        ;
59
+    }
60
+
61
+    protected function execute(InputInterface $input, OutputInterface $output) {
62
+        $importFile = $input->getArgument('file');
63
+        if ($importFile !== null) {
64
+            $content = $this->getArrayFromFile($importFile);
65
+        } else {
66
+            $content = $this->getArrayFromStdin();
67
+        }
68
+
69
+        try {
70
+            $configs = $this->validateFileContent($content);
71
+        } catch (\UnexpectedValueException $e) {
72
+            $output->writeln('<error>' . $e->getMessage(). '</error>');
73
+            return;
74
+        }
75
+
76
+        if (!empty($configs['system'])) {
77
+            $this->config->setSystemValues($configs['system']);
78
+        }
79
+
80
+        if (!empty($configs['apps'])) {
81
+            foreach ($configs['apps'] as $app => $appConfigs) {
82
+                foreach ($appConfigs as $key => $value) {
83
+                    if ($value === null) {
84
+                        $this->config->deleteAppValue($app, $key);
85
+                    } else {
86
+                        $this->config->setAppValue($app, $key, $value);
87
+                    }
88
+                }
89
+            }
90
+        }
91
+
92
+        $output->writeln('<info>Config successfully imported from: ' . $importFile . '</info>');
93
+    }
94
+
95
+    /**
96
+     * Get the content from stdin ("config:import < file.json")
97
+     *
98
+     * @return string
99
+     */
100
+    protected function getArrayFromStdin() {
101
+        // Read from stdin. stream_set_blocking is used to prevent blocking
102
+        // when nothing is passed via stdin.
103
+        stream_set_blocking(STDIN, 0);
104
+        $content = file_get_contents('php://stdin');
105
+        stream_set_blocking(STDIN, 1);
106
+        return $content;
107
+    }
108
+
109
+    /**
110
+     * Get the content of the specified file ("config:import file.json")
111
+     *
112
+     * @param string $importFile
113
+     * @return string
114
+     */
115
+    protected function getArrayFromFile($importFile) {
116
+        return file_get_contents($importFile);
117
+    }
118
+
119
+    /**
120
+     * @param string $content
121
+     * @return array
122
+     * @throws \UnexpectedValueException when the array is invalid
123
+     */
124
+    protected function validateFileContent($content) {
125
+        $decodedContent = json_decode($content, true);
126
+        if (!is_array($decodedContent) || empty($decodedContent)) {
127
+            throw new \UnexpectedValueException('The file must contain a valid json array');
128
+        }
129
+
130
+        $this->validateArray($decodedContent);
131
+
132
+        return $decodedContent;
133
+    }
134
+
135
+    /**
136
+     * Validates that the array only contains `system` and `apps`
137
+     *
138
+     * @param array $array
139
+     */
140
+    protected function validateArray($array) {
141
+        $arrayKeys = array_keys($array);
142
+        $additionalKeys = array_diff($arrayKeys, $this->validRootKeys);
143
+        $commonKeys = array_intersect($arrayKeys, $this->validRootKeys);
144
+        if (!empty($additionalKeys)) {
145
+            throw new \UnexpectedValueException('Found invalid entries in root: ' . implode(', ', $additionalKeys));
146
+        }
147
+        if (empty($commonKeys)) {
148
+            throw new \UnexpectedValueException('At least one key of the following is expected: ' . implode(', ', $this->validRootKeys));
149
+        }
150
+
151
+        if (isset($array['system'])) {
152
+            if (is_array($array['system'])) {
153
+                foreach ($array['system'] as $name => $value) {
154
+                    $this->checkTypeRecursively($value, $name);
155
+                }
156
+            } else {
157
+                throw new \UnexpectedValueException('The system config array is not an array');
158
+            }
159
+        }
160
+
161
+        if (isset($array['apps'])) {
162
+            if (is_array($array['apps'])) {
163
+                $this->validateAppsArray($array['apps']);
164
+            } else {
165
+                throw new \UnexpectedValueException('The apps config array is not an array');
166
+            }
167
+        }
168
+    }
169
+
170
+    /**
171
+     * @param mixed $configValue
172
+     * @param string $configName
173
+     */
174
+    protected function checkTypeRecursively($configValue, $configName) {
175
+        if (!is_array($configValue) && !is_bool($configValue) && !is_int($configValue) && !is_string($configValue) && !is_null($configValue)) {
176
+            throw new \UnexpectedValueException('Invalid system config value for "' . $configName . '". Only arrays, bools, integers, strings and null (delete) are allowed.');
177
+        }
178
+        if (is_array($configValue)) {
179
+            foreach ($configValue as $key => $value) {
180
+                $this->checkTypeRecursively($value, $configName);
181
+            }
182
+        }
183
+    }
184
+
185
+    /**
186
+     * Validates that app configs are only integers and strings
187
+     *
188
+     * @param array $array
189
+     */
190
+    protected function validateAppsArray($array) {
191
+        foreach ($array as $app => $configs) {
192
+            foreach ($configs as $name => $value) {
193
+                if (!is_int($value) && !is_string($value) && !is_null($value)) {
194
+                    throw new \UnexpectedValueException('Invalid app config value for "' . $app . '":"' . $name . '". Only integers, strings and null (delete) are allowed.');
195
+                }
196
+            }
197
+        }
198
+    }
199
+
200
+    /**
201
+     * @param string $optionName
202
+     * @param CompletionContext $context
203
+     * @return string[]
204
+     */
205
+    public function completeOptionValues($optionName, CompletionContext $context) {
206
+        return [];
207
+    }
208
+
209
+    /**
210
+     * @param string $argumentName
211
+     * @param CompletionContext $context
212
+     * @return string[]
213
+     */
214
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
215
+        if ($argumentName === 'file') {
216
+            $helper = new ShellPathCompletion(
217
+                $this->getName(),
218
+                'file',
219
+                Completion::TYPE_ARGUMENT
220
+            );
221
+            return $helper->run();
222
+        }
223
+        return [];
224
+    }
225 225
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Version/VersionParser.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -29,56 +29,56 @@
 block discarded – undo
29 29
  * @package OC\App\AppStore
30 30
  */
31 31
 class VersionParser {
32
-	/**
33
-	 * @param string $versionString
34
-	 * @return bool
35
-	 */
36
-	private function isValidVersionString($versionString) {
37
-		return (bool)preg_match('/^[0-9.]+$/', $versionString);
38
-	}
32
+    /**
33
+     * @param string $versionString
34
+     * @return bool
35
+     */
36
+    private function isValidVersionString($versionString) {
37
+        return (bool)preg_match('/^[0-9.]+$/', $versionString);
38
+    }
39 39
 
40
-	/**
41
-	 * Returns the version for a version string
42
-	 *
43
-	 * @param string $versionSpec
44
-	 * @return Version
45
-	 * @throws \Exception If the version cannot be parsed
46
-	 */
47
-	public function getVersion($versionSpec) {
48
-		// * indicates that the version is compatible with all versions
49
-		if($versionSpec === '*') {
50
-			return new Version('', '');
51
-		}
40
+    /**
41
+     * Returns the version for a version string
42
+     *
43
+     * @param string $versionSpec
44
+     * @return Version
45
+     * @throws \Exception If the version cannot be parsed
46
+     */
47
+    public function getVersion($versionSpec) {
48
+        // * indicates that the version is compatible with all versions
49
+        if($versionSpec === '*') {
50
+            return new Version('', '');
51
+        }
52 52
 
53
-		// Count the amount of =, if it is one then it's either maximum or minimum
54
-		// version. If it is two then it is maximum and minimum.
55
-		$versionElements = explode(' ', $versionSpec);
56
-		$firstVersion = isset($versionElements[0]) ? $versionElements[0] : '';
57
-		$firstVersionNumber = substr($firstVersion, 2);
58
-		$secondVersion = isset($versionElements[1]) ? $versionElements[1] : '';
59
-		$secondVersionNumber = substr($secondVersion, 2);
53
+        // Count the amount of =, if it is one then it's either maximum or minimum
54
+        // version. If it is two then it is maximum and minimum.
55
+        $versionElements = explode(' ', $versionSpec);
56
+        $firstVersion = isset($versionElements[0]) ? $versionElements[0] : '';
57
+        $firstVersionNumber = substr($firstVersion, 2);
58
+        $secondVersion = isset($versionElements[1]) ? $versionElements[1] : '';
59
+        $secondVersionNumber = substr($secondVersion, 2);
60 60
 
61
-		switch(count($versionElements)) {
62
-			case 1:
63
-				if(!$this->isValidVersionString($firstVersionNumber)) {
64
-					break;
65
-				}
66
-				if(strpos($firstVersion, '>') === 0) {
67
-					return new Version($firstVersionNumber, '');
68
-				}
69
-				return new Version('', $firstVersionNumber);
70
-			case 2:
71
-				if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
72
-					break;
73
-				}
74
-				return new Version($firstVersionNumber, $secondVersionNumber);
75
-		}
61
+        switch(count($versionElements)) {
62
+            case 1:
63
+                if(!$this->isValidVersionString($firstVersionNumber)) {
64
+                    break;
65
+                }
66
+                if(strpos($firstVersion, '>') === 0) {
67
+                    return new Version($firstVersionNumber, '');
68
+                }
69
+                return new Version('', $firstVersionNumber);
70
+            case 2:
71
+                if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
72
+                    break;
73
+                }
74
+                return new Version($firstVersionNumber, $secondVersionNumber);
75
+        }
76 76
 
77
-		throw new \Exception(
78
-			sprintf(
79
-				'Version cannot be parsed: %s',
80
-				$versionSpec
81
-			)
82
-		);
83
-	}
77
+        throw new \Exception(
78
+            sprintf(
79
+                'Version cannot be parsed: %s',
80
+                $versionSpec
81
+            )
82
+        );
83
+    }
84 84
 }
Please login to merge, or discard this patch.
lib/private/Memcache/Redis.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -31,151 +31,151 @@
 block discarded – undo
31 31
 use OCP\IMemcacheTTL;
32 32
 
33 33
 class Redis extends Cache implements IMemcacheTTL {
34
-	/**
35
-	 * @var \Redis $cache
36
-	 */
37
-	private static $cache = null;
38
-
39
-	public function __construct($prefix = '') {
40
-		parent::__construct($prefix);
41
-		if (is_null(self::$cache)) {
42
-			self::$cache = \OC::$server->getGetRedisFactory()->getInstance();
43
-		}
44
-	}
45
-
46
-	/**
47
-	 * entries in redis get namespaced to prevent collisions between ownCloud instances and users
48
-	 */
49
-	protected function getNameSpace() {
50
-		return $this->prefix;
51
-	}
52
-
53
-	public function get($key) {
54
-		$result = self::$cache->get($this->getNameSpace() . $key);
55
-		if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) {
56
-			return null;
57
-		} else {
58
-			return json_decode($result, true);
59
-		}
60
-	}
61
-
62
-	public function set($key, $value, $ttl = 0) {
63
-		if ($ttl > 0) {
64
-			return self::$cache->setex($this->getNameSpace() . $key, $ttl, json_encode($value));
65
-		} else {
66
-			return self::$cache->set($this->getNameSpace() . $key, json_encode($value));
67
-		}
68
-	}
69
-
70
-	public function hasKey($key) {
71
-		return self::$cache->exists($this->getNameSpace() . $key);
72
-	}
73
-
74
-	public function remove($key) {
75
-		if (self::$cache->del($this->getNameSpace() . $key)) {
76
-			return true;
77
-		} else {
78
-			return false;
79
-		}
80
-	}
81
-
82
-	public function clear($prefix = '') {
83
-		$prefix = $this->getNameSpace() . $prefix . '*';
84
-		$keys = self::$cache->keys($prefix);
85
-		$deleted = self::$cache->del($keys);
86
-
87
-		return count($keys) === $deleted;
88
-	}
89
-
90
-	/**
91
-	 * Set a value in the cache if it's not already stored
92
-	 *
93
-	 * @param string $key
94
-	 * @param mixed $value
95
-	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
96
-	 * @return bool
97
-	 */
98
-	public function add($key, $value, $ttl = 0) {
99
-		// don't encode ints for inc/dec
100
-		if (!is_int($value)) {
101
-			$value = json_encode($value);
102
-		}
103
-		return self::$cache->setnx($this->getPrefix() . $key, $value);
104
-	}
105
-
106
-	/**
107
-	 * Increase a stored number
108
-	 *
109
-	 * @param string $key
110
-	 * @param int $step
111
-	 * @return int | bool
112
-	 */
113
-	public function inc($key, $step = 1) {
114
-		return self::$cache->incrBy($this->getNameSpace() . $key, $step);
115
-	}
116
-
117
-	/**
118
-	 * Decrease a stored number
119
-	 *
120
-	 * @param string $key
121
-	 * @param int $step
122
-	 * @return int | bool
123
-	 */
124
-	public function dec($key, $step = 1) {
125
-		if (!$this->hasKey($key)) {
126
-			return false;
127
-		}
128
-		return self::$cache->decrBy($this->getNameSpace() . $key, $step);
129
-	}
130
-
131
-	/**
132
-	 * Compare and set
133
-	 *
134
-	 * @param string $key
135
-	 * @param mixed $old
136
-	 * @param mixed $new
137
-	 * @return bool
138
-	 */
139
-	public function cas($key, $old, $new) {
140
-		if (!is_int($new)) {
141
-			$new = json_encode($new);
142
-		}
143
-		self::$cache->watch($this->getNameSpace() . $key);
144
-		if ($this->get($key) === $old) {
145
-			$result = self::$cache->multi()
146
-				->set($this->getNameSpace() . $key, $new)
147
-				->exec();
148
-			return $result !== false;
149
-		}
150
-		self::$cache->unwatch();
151
-		return false;
152
-	}
153
-
154
-	/**
155
-	 * Compare and delete
156
-	 *
157
-	 * @param string $key
158
-	 * @param mixed $old
159
-	 * @return bool
160
-	 */
161
-	public function cad($key, $old) {
162
-		self::$cache->watch($this->getNameSpace() . $key);
163
-		if ($this->get($key) === $old) {
164
-			$result = self::$cache->multi()
165
-				->del($this->getNameSpace() . $key)
166
-				->exec();
167
-			return $result !== false;
168
-		}
169
-		self::$cache->unwatch();
170
-		return false;
171
-	}
172
-
173
-	public function setTTL($key, $ttl) {
174
-		self::$cache->expire($this->getNameSpace() . $key, $ttl);
175
-	}
176
-
177
-	static public function isAvailable() {
178
-		return \OC::$server->getGetRedisFactory()->isAvailable();
179
-	}
34
+    /**
35
+     * @var \Redis $cache
36
+     */
37
+    private static $cache = null;
38
+
39
+    public function __construct($prefix = '') {
40
+        parent::__construct($prefix);
41
+        if (is_null(self::$cache)) {
42
+            self::$cache = \OC::$server->getGetRedisFactory()->getInstance();
43
+        }
44
+    }
45
+
46
+    /**
47
+     * entries in redis get namespaced to prevent collisions between ownCloud instances and users
48
+     */
49
+    protected function getNameSpace() {
50
+        return $this->prefix;
51
+    }
52
+
53
+    public function get($key) {
54
+        $result = self::$cache->get($this->getNameSpace() . $key);
55
+        if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) {
56
+            return null;
57
+        } else {
58
+            return json_decode($result, true);
59
+        }
60
+    }
61
+
62
+    public function set($key, $value, $ttl = 0) {
63
+        if ($ttl > 0) {
64
+            return self::$cache->setex($this->getNameSpace() . $key, $ttl, json_encode($value));
65
+        } else {
66
+            return self::$cache->set($this->getNameSpace() . $key, json_encode($value));
67
+        }
68
+    }
69
+
70
+    public function hasKey($key) {
71
+        return self::$cache->exists($this->getNameSpace() . $key);
72
+    }
73
+
74
+    public function remove($key) {
75
+        if (self::$cache->del($this->getNameSpace() . $key)) {
76
+            return true;
77
+        } else {
78
+            return false;
79
+        }
80
+    }
81
+
82
+    public function clear($prefix = '') {
83
+        $prefix = $this->getNameSpace() . $prefix . '*';
84
+        $keys = self::$cache->keys($prefix);
85
+        $deleted = self::$cache->del($keys);
86
+
87
+        return count($keys) === $deleted;
88
+    }
89
+
90
+    /**
91
+     * Set a value in the cache if it's not already stored
92
+     *
93
+     * @param string $key
94
+     * @param mixed $value
95
+     * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
96
+     * @return bool
97
+     */
98
+    public function add($key, $value, $ttl = 0) {
99
+        // don't encode ints for inc/dec
100
+        if (!is_int($value)) {
101
+            $value = json_encode($value);
102
+        }
103
+        return self::$cache->setnx($this->getPrefix() . $key, $value);
104
+    }
105
+
106
+    /**
107
+     * Increase a stored number
108
+     *
109
+     * @param string $key
110
+     * @param int $step
111
+     * @return int | bool
112
+     */
113
+    public function inc($key, $step = 1) {
114
+        return self::$cache->incrBy($this->getNameSpace() . $key, $step);
115
+    }
116
+
117
+    /**
118
+     * Decrease a stored number
119
+     *
120
+     * @param string $key
121
+     * @param int $step
122
+     * @return int | bool
123
+     */
124
+    public function dec($key, $step = 1) {
125
+        if (!$this->hasKey($key)) {
126
+            return false;
127
+        }
128
+        return self::$cache->decrBy($this->getNameSpace() . $key, $step);
129
+    }
130
+
131
+    /**
132
+     * Compare and set
133
+     *
134
+     * @param string $key
135
+     * @param mixed $old
136
+     * @param mixed $new
137
+     * @return bool
138
+     */
139
+    public function cas($key, $old, $new) {
140
+        if (!is_int($new)) {
141
+            $new = json_encode($new);
142
+        }
143
+        self::$cache->watch($this->getNameSpace() . $key);
144
+        if ($this->get($key) === $old) {
145
+            $result = self::$cache->multi()
146
+                ->set($this->getNameSpace() . $key, $new)
147
+                ->exec();
148
+            return $result !== false;
149
+        }
150
+        self::$cache->unwatch();
151
+        return false;
152
+    }
153
+
154
+    /**
155
+     * Compare and delete
156
+     *
157
+     * @param string $key
158
+     * @param mixed $old
159
+     * @return bool
160
+     */
161
+    public function cad($key, $old) {
162
+        self::$cache->watch($this->getNameSpace() . $key);
163
+        if ($this->get($key) === $old) {
164
+            $result = self::$cache->multi()
165
+                ->del($this->getNameSpace() . $key)
166
+                ->exec();
167
+            return $result !== false;
168
+        }
169
+        self::$cache->unwatch();
170
+        return false;
171
+    }
172
+
173
+    public function setTTL($key, $ttl) {
174
+        self::$cache->expire($this->getNameSpace() . $key, $ttl);
175
+    }
176
+
177
+    static public function isAvailable() {
178
+        return \OC::$server->getGetRedisFactory()->isAvailable();
179
+    }
180 180
 }
181 181
 
Please login to merge, or discard this patch.
apps/files/lib/App.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -28,40 +28,40 @@
 block discarded – undo
28 28
 namespace OCA\Files;
29 29
 
30 30
 class App {
31
-	/**
32
-	 * @var \OCP\INavigationManager
33
-	 */
34
-	private static $navigationManager;
31
+    /**
32
+     * @var \OCP\INavigationManager
33
+     */
34
+    private static $navigationManager;
35 35
 
36
-	/**
37
-	 * Returns the app's navigation manager
38
-	 *
39
-	 * @return \OCP\INavigationManager
40
-	 */
41
-	public static function getNavigationManager() {
42
-		// TODO: move this into a service in the Application class
43
-		if (self::$navigationManager === null) {
44
-			self::$navigationManager = new \OC\NavigationManager(
45
-				\OC::$server->getAppManager(),
46
-				\OC::$server->getURLGenerator(),
47
-				\OC::$server->getL10NFactory(),
48
-				\OC::$server->getUserSession(),
49
-				\OC::$server->getGroupManager(),
50
-				\OC::$server->getConfig()
51
-			);
52
-			self::$navigationManager->clear(false);
53
-		}
54
-		return self::$navigationManager;
55
-	}
36
+    /**
37
+     * Returns the app's navigation manager
38
+     *
39
+     * @return \OCP\INavigationManager
40
+     */
41
+    public static function getNavigationManager() {
42
+        // TODO: move this into a service in the Application class
43
+        if (self::$navigationManager === null) {
44
+            self::$navigationManager = new \OC\NavigationManager(
45
+                \OC::$server->getAppManager(),
46
+                \OC::$server->getURLGenerator(),
47
+                \OC::$server->getL10NFactory(),
48
+                \OC::$server->getUserSession(),
49
+                \OC::$server->getGroupManager(),
50
+                \OC::$server->getConfig()
51
+            );
52
+            self::$navigationManager->clear(false);
53
+        }
54
+        return self::$navigationManager;
55
+    }
56 56
 
57
-	public static function extendJsConfig($settings) {
58
-		$appConfig = json_decode($settings['array']['oc_appconfig'], true);
57
+    public static function extendJsConfig($settings) {
58
+        $appConfig = json_decode($settings['array']['oc_appconfig'], true);
59 59
 
60
-		$maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
61
-		$appConfig['files'] = [
62
-			'max_chunk_size' => $maxChunkSize
63
-		];
60
+        $maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
61
+        $appConfig['files'] = [
62
+            'max_chunk_size' => $maxChunkSize
63
+        ];
64 64
 
65
-		$settings['array']['oc_appconfig'] = json_encode($appConfig);
66
-	}
65
+        $settings['array']['oc_appconfig'] = json_encode($appConfig);
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/user_ldap/templates/settings.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -5,46 +5,46 @@  discard block
 block discarded – undo
5 5
 vendor_style('user_ldap', 'ui-multiselect/jquery.multiselect');
6 6
 
7 7
 script('user_ldap', [
8
-	'wizard/controller',
9
-	'wizard/configModel',
10
-	'wizard/view',
11
-	'wizard/wizardObject',
12
-	'wizard/wizardTabGeneric',
13
-	'wizard/wizardTabElementary',
14
-	'wizard/wizardTabAbstractFilter',
15
-	'wizard/wizardTabUserFilter',
16
-	'wizard/wizardTabLoginFilter',
17
-	'wizard/wizardTabGroupFilter',
18
-	'wizard/wizardTabAdvanced',
19
-	'wizard/wizardTabExpert',
20
-	'wizard/wizardDetectorQueue',
21
-	'wizard/wizardDetectorGeneric',
22
-	'wizard/wizardDetectorPort',
23
-	'wizard/wizardDetectorBaseDN',
24
-	'wizard/wizardDetectorFeatureAbstract',
25
-	'wizard/wizardDetectorUserObjectClasses',
26
-	'wizard/wizardDetectorGroupObjectClasses',
27
-	'wizard/wizardDetectorGroupsForUsers',
28
-	'wizard/wizardDetectorGroupsForGroups',
29
-	'wizard/wizardDetectorSimpleRequestAbstract',
30
-	'wizard/wizardDetectorFilterUser',
31
-	'wizard/wizardDetectorFilterLogin',
32
-	'wizard/wizardDetectorFilterGroup',
33
-	'wizard/wizardDetectorUserCount',
34
-	'wizard/wizardDetectorGroupCount',
35
-	'wizard/wizardDetectorEmailAttribute',
36
-	'wizard/wizardDetectorUserDisplayNameAttribute',
37
-	'wizard/wizardDetectorUserGroupAssociation',
38
-	'wizard/wizardDetectorAvailableAttributes',
39
-	'wizard/wizardDetectorTestAbstract',
40
-	'wizard/wizardDetectorTestLoginName',
41
-	'wizard/wizardDetectorTestBaseDN',
42
-	'wizard/wizardDetectorTestConfiguration',
43
-	'wizard/wizardDetectorClearUserMappings',
44
-	'wizard/wizardDetectorClearGroupMappings',
45
-	'wizard/wizardFilterOnType',
46
-	'wizard/wizardFilterOnTypeFactory',
47
-	'wizard/wizard'
8
+    'wizard/controller',
9
+    'wizard/configModel',
10
+    'wizard/view',
11
+    'wizard/wizardObject',
12
+    'wizard/wizardTabGeneric',
13
+    'wizard/wizardTabElementary',
14
+    'wizard/wizardTabAbstractFilter',
15
+    'wizard/wizardTabUserFilter',
16
+    'wizard/wizardTabLoginFilter',
17
+    'wizard/wizardTabGroupFilter',
18
+    'wizard/wizardTabAdvanced',
19
+    'wizard/wizardTabExpert',
20
+    'wizard/wizardDetectorQueue',
21
+    'wizard/wizardDetectorGeneric',
22
+    'wizard/wizardDetectorPort',
23
+    'wizard/wizardDetectorBaseDN',
24
+    'wizard/wizardDetectorFeatureAbstract',
25
+    'wizard/wizardDetectorUserObjectClasses',
26
+    'wizard/wizardDetectorGroupObjectClasses',
27
+    'wizard/wizardDetectorGroupsForUsers',
28
+    'wizard/wizardDetectorGroupsForGroups',
29
+    'wizard/wizardDetectorSimpleRequestAbstract',
30
+    'wizard/wizardDetectorFilterUser',
31
+    'wizard/wizardDetectorFilterLogin',
32
+    'wizard/wizardDetectorFilterGroup',
33
+    'wizard/wizardDetectorUserCount',
34
+    'wizard/wizardDetectorGroupCount',
35
+    'wizard/wizardDetectorEmailAttribute',
36
+    'wizard/wizardDetectorUserDisplayNameAttribute',
37
+    'wizard/wizardDetectorUserGroupAssociation',
38
+    'wizard/wizardDetectorAvailableAttributes',
39
+    'wizard/wizardDetectorTestAbstract',
40
+    'wizard/wizardDetectorTestLoginName',
41
+    'wizard/wizardDetectorTestBaseDN',
42
+    'wizard/wizardDetectorTestConfiguration',
43
+    'wizard/wizardDetectorClearUserMappings',
44
+    'wizard/wizardDetectorClearGroupMappings',
45
+    'wizard/wizardFilterOnType',
46
+    'wizard/wizardFilterOnTypeFactory',
47
+    'wizard/wizard'
48 48
 ]);
49 49
 
50 50
 style('user_ldap', 'settings');
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 		<li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li>
68 68
 	</ul>
69 69
 	<?php
70
-	if(!function_exists('ldap_connect')) {
71
-		print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>');
72
-	}
73
-	?>
70
+    if(!function_exists('ldap_connect')) {
71
+        print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>');
72
+    }
73
+    ?>
74 74
 	<?php require_once __DIR__ . '/part.wizard-server.php'; ?>
75 75
 	<?php require_once __DIR__ . '/part.wizard-userfilter.php'; ?>
76 76
 	<?php require_once __DIR__ . '/part.wizard-loginfilter.php'; ?>
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/AmazonS3/AccessKey.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -31,18 +31,18 @@
 block discarded – undo
31 31
  */
32 32
 class AccessKey extends AuthMechanism {
33 33
 
34
-	const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey';
34
+    const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey';
35 35
 
36
-	public function __construct(IL10N $l) {
37
-		$this
38
-			->setIdentifier('amazons3::accesskey')
39
-			->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY)
40
-			->setText($l->t('Access key'))
41
-			->addParameters([
42
-				new DefinitionParameter('key', $l->t('Access key')),
43
-				(new DefinitionParameter('secret', $l->t('Secret key')))
44
-					->setType(DefinitionParameter::VALUE_PASSWORD),
45
-			]);
46
-	}
36
+    public function __construct(IL10N $l) {
37
+        $this
38
+            ->setIdentifier('amazons3::accesskey')
39
+            ->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY)
40
+            ->setText($l->t('Access key'))
41
+            ->addParameters([
42
+                new DefinitionParameter('key', $l->t('Access key')),
43
+                (new DefinitionParameter('secret', $l->t('Secret key')))
44
+                    ->setType(DefinitionParameter::VALUE_PASSWORD),
45
+            ]);
46
+    }
47 47
 
48 48
 }
Please login to merge, or discard this patch.