Completed
Push — stable10 ( e55881...b0ab3b )
by Joas
36:13 queued 35:48
created
lib/private/Diagnostics/NullEventLogger.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,30 +29,30 @@
 block discarded – undo
29 29
  * Dummy event logger that doesn't actually log anything
30 30
  */
31 31
 class NullEventLogger implements IEventLogger {
32
-	/**
33
-	 * Mark the start of an event
34
-	 *
35
-	 * @param $id
36
-	 * @param $description
37
-	 */
38
-	public function start($id, $description) {
39
-	}
32
+    /**
33
+     * Mark the start of an event
34
+     *
35
+     * @param $id
36
+     * @param $description
37
+     */
38
+    public function start($id, $description) {
39
+    }
40 40
 
41
-	/**
42
-	 * Mark the end of an event
43
-	 *
44
-	 * @param $id
45
-	 */
46
-	public function end($id) {
47
-	}
41
+    /**
42
+     * Mark the end of an event
43
+     *
44
+     * @param $id
45
+     */
46
+    public function end($id) {
47
+    }
48 48
 
49
-	public function log($id, $description, $start, $end) {
50
-	}
49
+    public function log($id, $description, $start, $end) {
50
+    }
51 51
 
52
-	/**
53
-	 * @return \OCP\Diagnostics\IEvent[]
54
-	 */
55
-	public function getEvents() {
56
-		return array();
57
-	}
52
+    /**
53
+     * @return \OCP\Diagnostics\IEvent[]
54
+     */
55
+    public function getEvents() {
56
+        return array();
57
+    }
58 58
 }
Please login to merge, or discard this patch.
lib/private/Config.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -39,227 +39,227 @@
 block discarded – undo
39 39
  * configuration file of ownCloud.
40 40
  */
41 41
 class Config {
42
-	/** @var array Associative array ($key => $value) */
43
-	protected $cache = array();
44
-	/** @var string */
45
-	protected $configDir;
46
-	/** @var string */
47
-	protected $configFilePath;
48
-	/** @var string */
49
-	protected $configFileName;
42
+    /** @var array Associative array ($key => $value) */
43
+    protected $cache = array();
44
+    /** @var string */
45
+    protected $configDir;
46
+    /** @var string */
47
+    protected $configFilePath;
48
+    /** @var string */
49
+    protected $configFileName;
50 50
 
51
-	/**
52
-	 * @param string $configDir Path to the config dir, needs to end with '/'
53
-	 * @param string $fileName (Optional) Name of the config file. Defaults to config.php
54
-	 */
55
-	public function __construct($configDir, $fileName = 'config.php') {
56
-		$this->configDir = $configDir;
57
-		$this->configFilePath = $this->configDir.$fileName;
58
-		$this->configFileName = $fileName;
59
-		$this->readData();
60
-	}
51
+    /**
52
+     * @param string $configDir Path to the config dir, needs to end with '/'
53
+     * @param string $fileName (Optional) Name of the config file. Defaults to config.php
54
+     */
55
+    public function __construct($configDir, $fileName = 'config.php') {
56
+        $this->configDir = $configDir;
57
+        $this->configFilePath = $this->configDir.$fileName;
58
+        $this->configFileName = $fileName;
59
+        $this->readData();
60
+    }
61 61
 
62
-	/**
63
-	 * Lists all available config keys
64
-	 *
65
-	 * Please note that it does not return the values.
66
-	 *
67
-	 * @return array an array of key names
68
-	 */
69
-	public function getKeys() {
70
-		return array_keys($this->cache);
71
-	}
62
+    /**
63
+     * Lists all available config keys
64
+     *
65
+     * Please note that it does not return the values.
66
+     *
67
+     * @return array an array of key names
68
+     */
69
+    public function getKeys() {
70
+        return array_keys($this->cache);
71
+    }
72 72
 
73
-	/**
74
-	 * Gets a value from config.php
75
-	 *
76
-	 * If it does not exist, $default will be returned.
77
-	 *
78
-	 * @param string $key key
79
-	 * @param mixed $default = null default value
80
-	 * @return mixed the value or $default
81
-	 */
82
-	public function getValue($key, $default = null) {
83
-		if (isset($this->cache[$key])) {
84
-			return $this->cache[$key];
85
-		}
73
+    /**
74
+     * Gets a value from config.php
75
+     *
76
+     * If it does not exist, $default will be returned.
77
+     *
78
+     * @param string $key key
79
+     * @param mixed $default = null default value
80
+     * @return mixed the value or $default
81
+     */
82
+    public function getValue($key, $default = null) {
83
+        if (isset($this->cache[$key])) {
84
+            return $this->cache[$key];
85
+        }
86 86
 
87
-		return $default;
88
-	}
87
+        return $default;
88
+    }
89 89
 
90
-	/**
91
-	 * Sets and deletes values and writes the config.php
92
-	 *
93
-	 * @param array $configs Associative array with `key => value` pairs
94
-	 *                       If value is null, the config key will be deleted
95
-	 */
96
-	public function setValues(array $configs) {
97
-		$needsUpdate = false;
98
-		foreach ($configs as $key => $value) {
99
-			if ($value !== null) {
100
-				$needsUpdate |= $this->set($key, $value);
101
-			} else {
102
-				$needsUpdate |= $this->delete($key);
103
-			}
104
-		}
90
+    /**
91
+     * Sets and deletes values and writes the config.php
92
+     *
93
+     * @param array $configs Associative array with `key => value` pairs
94
+     *                       If value is null, the config key will be deleted
95
+     */
96
+    public function setValues(array $configs) {
97
+        $needsUpdate = false;
98
+        foreach ($configs as $key => $value) {
99
+            if ($value !== null) {
100
+                $needsUpdate |= $this->set($key, $value);
101
+            } else {
102
+                $needsUpdate |= $this->delete($key);
103
+            }
104
+        }
105 105
 
106
-		if ($needsUpdate) {
107
-			// Write changes
108
-			$this->writeData();
109
-		}
110
-	}
106
+        if ($needsUpdate) {
107
+            // Write changes
108
+            $this->writeData();
109
+        }
110
+    }
111 111
 
112
-	/**
113
-	 * Sets the value and writes it to config.php if required
114
-	 *
115
-	 * @param string $key key
116
-	 * @param mixed $value value
117
-	 */
118
-	public function setValue($key, $value) {
119
-		if ($this->set($key, $value)) {
120
-			// Write changes
121
-			$this->writeData();
122
-		}
123
-	}
112
+    /**
113
+     * Sets the value and writes it to config.php if required
114
+     *
115
+     * @param string $key key
116
+     * @param mixed $value value
117
+     */
118
+    public function setValue($key, $value) {
119
+        if ($this->set($key, $value)) {
120
+            // Write changes
121
+            $this->writeData();
122
+        }
123
+    }
124 124
 
125
-	/**
126
-	 * This function sets the value
127
-	 *
128
-	 * @param string $key key
129
-	 * @param mixed $value value
130
-	 * @return bool True if the file needs to be updated, false otherwise
131
-	 */
132
-	protected function set($key, $value) {
133
-		if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) {
134
-			// Add change
135
-			$this->cache[$key] = $value;
136
-			return true;
137
-		}
125
+    /**
126
+     * This function sets the value
127
+     *
128
+     * @param string $key key
129
+     * @param mixed $value value
130
+     * @return bool True if the file needs to be updated, false otherwise
131
+     */
132
+    protected function set($key, $value) {
133
+        if (!isset($this->cache[$key]) || $this->cache[$key] !== $value) {
134
+            // Add change
135
+            $this->cache[$key] = $value;
136
+            return true;
137
+        }
138 138
 
139
-		return false;
140
-	}
139
+        return false;
140
+    }
141 141
 
142
-	/**
143
-	 * Removes a key from the config and removes it from config.php if required
144
-	 * @param string $key
145
-	 */
146
-	public function deleteKey($key) {
147
-		if ($this->delete($key)) {
148
-			// Write changes
149
-			$this->writeData();
150
-		}
151
-	}
142
+    /**
143
+     * Removes a key from the config and removes it from config.php if required
144
+     * @param string $key
145
+     */
146
+    public function deleteKey($key) {
147
+        if ($this->delete($key)) {
148
+            // Write changes
149
+            $this->writeData();
150
+        }
151
+    }
152 152
 
153
-	/**
154
-	 * This function removes a key from the config
155
-	 *
156
-	 * @param string $key
157
-	 * @return bool True if the file needs to be updated, false otherwise
158
-	 */
159
-	protected function delete($key) {
160
-		if (isset($this->cache[$key])) {
161
-			// Delete key from cache
162
-			unset($this->cache[$key]);
163
-			return true;
164
-		}
165
-		return false;
166
-	}
153
+    /**
154
+     * This function removes a key from the config
155
+     *
156
+     * @param string $key
157
+     * @return bool True if the file needs to be updated, false otherwise
158
+     */
159
+    protected function delete($key) {
160
+        if (isset($this->cache[$key])) {
161
+            // Delete key from cache
162
+            unset($this->cache[$key]);
163
+            return true;
164
+        }
165
+        return false;
166
+    }
167 167
 
168
-	/**
169
-	 * Loads the config file
170
-	 *
171
-	 * Reads the config file and saves it to the cache
172
-	 *
173
-	 * @throws \Exception If no lock could be acquired or the config file has not been found
174
-	 */
175
-	private function readData() {
176
-		// Default config should always get loaded
177
-		$configFiles = array($this->configFilePath);
168
+    /**
169
+     * Loads the config file
170
+     *
171
+     * Reads the config file and saves it to the cache
172
+     *
173
+     * @throws \Exception If no lock could be acquired or the config file has not been found
174
+     */
175
+    private function readData() {
176
+        // Default config should always get loaded
177
+        $configFiles = array($this->configFilePath);
178 178
 
179
-		// Add all files in the config dir ending with the same file name
180
-		$extra = glob($this->configDir.'*.'.$this->configFileName);
181
-		if (is_array($extra)) {
182
-			natsort($extra);
183
-			$configFiles = array_merge($configFiles, $extra);
184
-		}
179
+        // Add all files in the config dir ending with the same file name
180
+        $extra = glob($this->configDir.'*.'.$this->configFileName);
181
+        if (is_array($extra)) {
182
+            natsort($extra);
183
+            $configFiles = array_merge($configFiles, $extra);
184
+        }
185 185
 
186
-		// Include file and merge config
187
-		foreach ($configFiles as $file) {
188
-			$fileExistsAndIsReadable = file_exists($file) && is_readable($file);
189
-			$filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false;
190
-			if($file === $this->configFilePath &&
191
-				$filePointer === false) {
192
-				// Opening the main config might not be possible, e.g. if the wrong
193
-				// permissions are set (likely on a new installation)
194
-				continue;
195
-			}
186
+        // Include file and merge config
187
+        foreach ($configFiles as $file) {
188
+            $fileExistsAndIsReadable = file_exists($file) && is_readable($file);
189
+            $filePointer = $fileExistsAndIsReadable ? fopen($file, 'r') : false;
190
+            if($file === $this->configFilePath &&
191
+                $filePointer === false) {
192
+                // Opening the main config might not be possible, e.g. if the wrong
193
+                // permissions are set (likely on a new installation)
194
+                continue;
195
+            }
196 196
 
197
-			// Try to acquire a file lock
198
-			if(!flock($filePointer, LOCK_SH)) {
199
-				throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $file));
200
-			}
197
+            // Try to acquire a file lock
198
+            if(!flock($filePointer, LOCK_SH)) {
199
+                throw new \Exception(sprintf('Could not acquire a shared lock on the config file %s', $file));
200
+            }
201 201
 
202
-			unset($CONFIG);
203
-			include $file;
204
-			if(isset($CONFIG) && is_array($CONFIG)) {
205
-				$this->cache = array_merge($this->cache, $CONFIG);
206
-			}
202
+            unset($CONFIG);
203
+            include $file;
204
+            if(isset($CONFIG) && is_array($CONFIG)) {
205
+                $this->cache = array_merge($this->cache, $CONFIG);
206
+            }
207 207
 
208
-			// Close the file pointer and release the lock
209
-			flock($filePointer, LOCK_UN);
210
-			fclose($filePointer);
211
-		}
212
-	}
208
+            // Close the file pointer and release the lock
209
+            flock($filePointer, LOCK_UN);
210
+            fclose($filePointer);
211
+        }
212
+    }
213 213
 
214
-	/**
215
-	 * Writes the config file
216
-	 *
217
-	 * Saves the config to the config file.
218
-	 *
219
-	 * @throws HintException If the config file cannot be written to
220
-	 * @throws \Exception If no file lock can be acquired
221
-	 */
222
-	private function writeData() {
223
-		// Create a php file ...
224
-		$content = "<?php\n";
225
-		$content .= '$CONFIG = ';
226
-		$content .= var_export($this->cache, true);
227
-		$content .= ";\n";
214
+    /**
215
+     * Writes the config file
216
+     *
217
+     * Saves the config to the config file.
218
+     *
219
+     * @throws HintException If the config file cannot be written to
220
+     * @throws \Exception If no file lock can be acquired
221
+     */
222
+    private function writeData() {
223
+        // Create a php file ...
224
+        $content = "<?php\n";
225
+        $content .= '$CONFIG = ';
226
+        $content .= var_export($this->cache, true);
227
+        $content .= ";\n";
228 228
 
229
-		touch ($this->configFilePath);
230
-		$filePointer = fopen($this->configFilePath, 'r+');
229
+        touch ($this->configFilePath);
230
+        $filePointer = fopen($this->configFilePath, 'r+');
231 231
 
232
-		// Prevent others not to read the config
233
-		chmod($this->configFilePath, 0640);
232
+        // Prevent others not to read the config
233
+        chmod($this->configFilePath, 0640);
234 234
 
235
-		// File does not exist, this can happen when doing a fresh install
236
-		if(!is_resource ($filePointer)) {
237
-			// TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order
238
-			// currently this breaks app routes but also could have other side effects especially during setup and exception handling
239
-			$url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions');
240
-			throw new HintException(
241
-				"Can't write into config directory!",
242
-				'This can usually be fixed by '
243
-				.'<a href="' . $url . '" target="_blank" rel="noreferrer">giving the webserver write access to the config directory</a>.');
244
-		}
235
+        // File does not exist, this can happen when doing a fresh install
236
+        if(!is_resource ($filePointer)) {
237
+            // TODO fix this via DI once it is very clear that this doesn't cause side effects due to initialization order
238
+            // currently this breaks app routes but also could have other side effects especially during setup and exception handling
239
+            $url = \OC::$server->getURLGenerator()->linkToDocs('admin-dir_permissions');
240
+            throw new HintException(
241
+                "Can't write into config directory!",
242
+                'This can usually be fixed by '
243
+                .'<a href="' . $url . '" target="_blank" rel="noreferrer">giving the webserver write access to the config directory</a>.');
244
+        }
245 245
 
246
-		// Try to acquire a file lock
247
-		if(!flock($filePointer, LOCK_EX)) {
248
-			throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath));
249
-		}
246
+        // Try to acquire a file lock
247
+        if(!flock($filePointer, LOCK_EX)) {
248
+            throw new \Exception(sprintf('Could not acquire an exclusive lock on the config file %s', $this->configFilePath));
249
+        }
250 250
 
251
-		// Write the config and release the lock
252
-		ftruncate ($filePointer, 0);
253
-		fwrite($filePointer, $content);
254
-		fflush($filePointer);
255
-		flock($filePointer, LOCK_UN);
256
-		fclose($filePointer);
251
+        // Write the config and release the lock
252
+        ftruncate ($filePointer, 0);
253
+        fwrite($filePointer, $content);
254
+        fflush($filePointer);
255
+        flock($filePointer, LOCK_UN);
256
+        fclose($filePointer);
257 257
 
258
-		// Try invalidating the opcache just for the file we wrote...
259
-		if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) {
260
-			// But if that doesn't work, clear the whole cache.
261
-			\OC_Util::clearOpcodeCache();
262
-		}
263
-	}
258
+        // Try invalidating the opcache just for the file we wrote...
259
+        if (!\OC_Util::deleteFromOpcodeCache($this->configFilePath)) {
260
+            // But if that doesn't work, clear the whole cache.
261
+            \OC_Util::clearOpcodeCache();
262
+        }
263
+    }
264 264
 }
265 265
 
Please login to merge, or discard this patch.
lib/private/DateTimeZone.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -29,100 +29,100 @@
 block discarded – undo
29 29
 use OCP\ISession;
30 30
 
31 31
 class DateTimeZone implements IDateTimeZone {
32
-	/** @var IConfig */
33
-	protected $config;
32
+    /** @var IConfig */
33
+    protected $config;
34 34
 
35
-	/** @var ISession */
36
-	protected $session;
35
+    /** @var ISession */
36
+    protected $session;
37 37
 
38
-	/**
39
-	 * Constructor
40
-	 *
41
-	 * @param IConfig $config
42
-	 * @param ISession $session
43
-	 */
44
-	public function __construct(IConfig $config, ISession $session) {
45
-		$this->config = $config;
46
-		$this->session = $session;
47
-	}
38
+    /**
39
+     * Constructor
40
+     *
41
+     * @param IConfig $config
42
+     * @param ISession $session
43
+     */
44
+    public function __construct(IConfig $config, ISession $session) {
45
+        $this->config = $config;
46
+        $this->session = $session;
47
+    }
48 48
 
49
-	/**
50
-	 * Get the timezone of the current user, based on his session information and config data
51
-	 *
52
-	 * @param bool|int $timestamp
53
-	 * @return \DateTimeZone
54
-	 */
55
-	public function getTimeZone($timestamp = false) {
56
-		$timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
57
-		if ($timeZone === null) {
58
-			if ($this->session->exists('timezone')) {
59
-				return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
60
-			}
61
-			$timeZone = $this->getDefaultTimeZone();
62
-		}
49
+    /**
50
+     * Get the timezone of the current user, based on his session information and config data
51
+     *
52
+     * @param bool|int $timestamp
53
+     * @return \DateTimeZone
54
+     */
55
+    public function getTimeZone($timestamp = false) {
56
+        $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null);
57
+        if ($timeZone === null) {
58
+            if ($this->session->exists('timezone')) {
59
+                return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp);
60
+            }
61
+            $timeZone = $this->getDefaultTimeZone();
62
+        }
63 63
 
64
-		try {
65
-			return new \DateTimeZone($timeZone);
66
-		} catch (\Exception $e) {
67
-			\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
68
-			return new \DateTimeZone($this->getDefaultTimeZone());
69
-		}
70
-	}
64
+        try {
65
+            return new \DateTimeZone($timeZone);
66
+        } catch (\Exception $e) {
67
+            \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG);
68
+            return new \DateTimeZone($this->getDefaultTimeZone());
69
+        }
70
+    }
71 71
 
72
-	/**
73
-	 * Guess the DateTimeZone for a given offset
74
-	 *
75
-	 * We first try to find a Etc/GMT* timezone, if that does not exist,
76
-	 * we try to find it manually, before falling back to UTC.
77
-	 *
78
-	 * @param mixed $offset
79
-	 * @param bool|int $timestamp
80
-	 * @return \DateTimeZone
81
-	 */
82
-	protected function guessTimeZoneFromOffset($offset, $timestamp) {
83
-		try {
84
-			// Note: the timeZone name is the inverse to the offset,
85
-			// so a positive offset means negative timeZone
86
-			// and the other way around.
87
-			if ($offset > 0) {
88
-				$timeZone = 'Etc/GMT-' . $offset;
89
-			} else {
90
-				$timeZone = 'Etc/GMT+' . abs($offset);
91
-			}
72
+    /**
73
+     * Guess the DateTimeZone for a given offset
74
+     *
75
+     * We first try to find a Etc/GMT* timezone, if that does not exist,
76
+     * we try to find it manually, before falling back to UTC.
77
+     *
78
+     * @param mixed $offset
79
+     * @param bool|int $timestamp
80
+     * @return \DateTimeZone
81
+     */
82
+    protected function guessTimeZoneFromOffset($offset, $timestamp) {
83
+        try {
84
+            // Note: the timeZone name is the inverse to the offset,
85
+            // so a positive offset means negative timeZone
86
+            // and the other way around.
87
+            if ($offset > 0) {
88
+                $timeZone = 'Etc/GMT-' . $offset;
89
+            } else {
90
+                $timeZone = 'Etc/GMT+' . abs($offset);
91
+            }
92 92
 
93
-			return new \DateTimeZone($timeZone);
94
-		} catch (\Exception $e) {
95
-			// If the offset has no Etc/GMT* timezone,
96
-			// we try to guess one timezone that has the same offset
97
-			foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
98
-				$dtz = new \DateTimeZone($timeZone);
99
-				$dateTime = new \DateTime();
93
+            return new \DateTimeZone($timeZone);
94
+        } catch (\Exception $e) {
95
+            // If the offset has no Etc/GMT* timezone,
96
+            // we try to guess one timezone that has the same offset
97
+            foreach (\DateTimeZone::listIdentifiers() as $timeZone) {
98
+                $dtz = new \DateTimeZone($timeZone);
99
+                $dateTime = new \DateTime();
100 100
 
101
-				if ($timestamp !== false) {
102
-					$dateTime->setTimestamp($timestamp);
103
-				}
101
+                if ($timestamp !== false) {
102
+                    $dateTime->setTimestamp($timestamp);
103
+                }
104 104
 
105
-				$dtOffset = $dtz->getOffset($dateTime);
106
-				if ($dtOffset == 3600 * $offset) {
107
-					return $dtz;
108
-				}
109
-			}
105
+                $dtOffset = $dtz->getOffset($dateTime);
106
+                if ($dtOffset == 3600 * $offset) {
107
+                    return $dtz;
108
+                }
109
+            }
110 110
 
111
-			// No timezone found, fallback to UTC
112
-			\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
113
-			return new \DateTimeZone($this->getDefaultTimeZone());
114
-		}
115
-	}
111
+            // No timezone found, fallback to UTC
112
+            \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG);
113
+            return new \DateTimeZone($this->getDefaultTimeZone());
114
+        }
115
+    }
116 116
 
117
-	/**
118
-	 * Get the default timezone of the server
119
-	 *
120
-	 * Falls back to UTC if it is not yet set.
121
-	 * 
122
-	 * @return string
123
-	 */
124
-	protected function getDefaultTimeZone() {
125
-		$serverTimeZone = date_default_timezone_get();
126
-		return $serverTimeZone ?: 'UTC';
127
-	}
117
+    /**
118
+     * Get the default timezone of the server
119
+     *
120
+     * Falls back to UTC if it is not yet set.
121
+     * 
122
+     * @return string
123
+     */
124
+    protected function getDefaultTimeZone() {
125
+        $serverTimeZone = date_default_timezone_get();
126
+        return $serverTimeZone ?: 'UTC';
127
+    }
128 128
 }
Please login to merge, or discard this patch.
lib/private/Tagging/TagMapper.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -33,47 +33,47 @@
 block discarded – undo
33 33
  */
34 34
 class TagMapper extends Mapper {
35 35
 
36
-	/**
37
-	* Constructor.
38
-	*
39
-	* @param IDBConnection $db Instance of the Db abstraction layer.
40
-	*/
41
-	public function __construct(IDBConnection $db) {
42
-		parent::__construct($db, 'vcategory', 'OC\Tagging\Tag');
43
-	}
36
+    /**
37
+     * Constructor.
38
+     *
39
+     * @param IDBConnection $db Instance of the Db abstraction layer.
40
+     */
41
+    public function __construct(IDBConnection $db) {
42
+        parent::__construct($db, 'vcategory', 'OC\Tagging\Tag');
43
+    }
44 44
 
45
-	/**
46
-	* Load tags from the database.
47
-	*
48
-	* @param array|string $owners The user(s) whose tags we are going to load.
49
-	* @param string $type The type of item for which we are loading tags.
50
-	* @return array An array of Tag objects.
51
-	*/
52
-	public function loadTags($owners, $type) {
53
-		if(!is_array($owners)) {
54
-			$owners = array($owners);
55
-		}
45
+    /**
46
+     * Load tags from the database.
47
+     *
48
+     * @param array|string $owners The user(s) whose tags we are going to load.
49
+     * @param string $type The type of item for which we are loading tags.
50
+     * @return array An array of Tag objects.
51
+     */
52
+    public function loadTags($owners, $type) {
53
+        if(!is_array($owners)) {
54
+            $owners = array($owners);
55
+        }
56 56
 
57
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
-			. 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`';
59
-		return $this->findEntities($sql, array_merge($owners, array($type)));
60
-	}
57
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
58
+            . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`';
59
+        return $this->findEntities($sql, array_merge($owners, array($type)));
60
+    }
61 61
 
62
-	/**
63
-	* Check if a given Tag object already exists in the database.
64
-	*
65
-	* @param Tag $tag The tag to look for in the database.
66
-	* @return bool
67
-	*/
68
-	public function tagExists($tag) {
69
-		$sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
70
-			. 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71
-		try {
72
-			$this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName()));
73
-		} catch (DoesNotExistException $e) {
74
-			return false;
75
-		}
76
-		return true;
77
-	}
62
+    /**
63
+     * Check if a given Tag object already exists in the database.
64
+     *
65
+     * @param Tag $tag The tag to look for in the database.
66
+     * @return bool
67
+     */
68
+    public function tagExists($tag) {
69
+        $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` '
70
+            . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?';
71
+        try {
72
+            $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName()));
73
+        } catch (DoesNotExistException $e) {
74
+            return false;
75
+        }
76
+        return true;
77
+    }
78 78
 }
79 79
 
Please login to merge, or discard this patch.
lib/private/Tagging/Tag.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,54 +37,54 @@
 block discarded – undo
37 37
  */
38 38
 class Tag extends Entity {
39 39
 
40
-	protected $owner;
41
-	protected $type;
42
-	protected $name;
40
+    protected $owner;
41
+    protected $type;
42
+    protected $name;
43 43
 
44
-	/**
45
-	* Constructor.
46
-	*
47
-	* @param string $owner The tag's owner
48
-	* @param string $type The type of item this tag is used for
49
-	* @param string $name The tag's name
50
-	*/
51
-	public function __construct($owner = null, $type = null, $name = null) {
52
-		$this->setOwner($owner);
53
-		$this->setType($type);
54
-		$this->setName($name);
55
-	}
44
+    /**
45
+     * Constructor.
46
+     *
47
+     * @param string $owner The tag's owner
48
+     * @param string $type The type of item this tag is used for
49
+     * @param string $name The tag's name
50
+     */
51
+    public function __construct($owner = null, $type = null, $name = null) {
52
+        $this->setOwner($owner);
53
+        $this->setType($type);
54
+        $this->setName($name);
55
+    }
56 56
 
57
-	/**
58
-	 * Transform a database columnname to a property
59
-	 *
60
-	 * @param string $columnName the name of the column
61
-	 * @return string the property name
62
-	 * @todo migrate existing database columns to the correct names
63
-	 * to be able to drop this direct mapping
64
-	 */
65
-	public function columnToProperty($columnName){
66
-		if ($columnName === 'category') {
67
-		    return 'name';
68
-		} elseif ($columnName === 'uid') {
69
-		    return 'owner';
70
-		} else {
71
-		    return parent::columnToProperty($columnName);
72
-		}
73
-	}
57
+    /**
58
+     * Transform a database columnname to a property
59
+     *
60
+     * @param string $columnName the name of the column
61
+     * @return string the property name
62
+     * @todo migrate existing database columns to the correct names
63
+     * to be able to drop this direct mapping
64
+     */
65
+    public function columnToProperty($columnName){
66
+        if ($columnName === 'category') {
67
+            return 'name';
68
+        } elseif ($columnName === 'uid') {
69
+            return 'owner';
70
+        } else {
71
+            return parent::columnToProperty($columnName);
72
+        }
73
+    }
74 74
 
75
-	/**
76
-	 * Transform a property to a database column name
77
-	 *
78
-	 * @param string $property the name of the property
79
-	 * @return string the column name
80
-	 */
81
-	public function propertyToColumn($property){
82
-		if ($property === 'name') {
83
-		    return 'category';
84
-		} elseif ($property === 'owner') {
85
-		    return 'uid';
86
-		} else {
87
-		    return parent::propertyToColumn($property);
88
-		}
89
-	}
75
+    /**
76
+     * Transform a property to a database column name
77
+     *
78
+     * @param string $property the name of the property
79
+     * @return string the column name
80
+     */
81
+    public function propertyToColumn($property){
82
+        if ($property === 'name') {
83
+            return 'category';
84
+        } elseif ($property === 'owner') {
85
+            return 'uid';
86
+        } else {
87
+            return parent::propertyToColumn($property);
88
+        }
89
+    }
90 90
 }
Please login to merge, or discard this patch.
lib/private/Route/Route.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -32,127 +32,127 @@
 block discarded – undo
32 32
 use Symfony\Component\Routing\Route as SymfonyRoute;
33 33
 
34 34
 class Route extends SymfonyRoute implements IRoute {
35
-	/**
36
-	 * Specify the method when this route is to be used
37
-	 *
38
-	 * @param string $method HTTP method (uppercase)
39
-	 * @return \OC\Route\Route
40
-	 */
41
-	public function method($method) {
42
-		$this->setMethods($method);
43
-		return $this;
44
-	}
35
+    /**
36
+     * Specify the method when this route is to be used
37
+     *
38
+     * @param string $method HTTP method (uppercase)
39
+     * @return \OC\Route\Route
40
+     */
41
+    public function method($method) {
42
+        $this->setMethods($method);
43
+        return $this;
44
+    }
45 45
 
46
-	/**
47
-	 * Specify POST as the method to use with this route
48
-	 * @return \OC\Route\Route
49
-	 */
50
-	public function post() {
51
-		$this->method('POST');
52
-		return $this;
53
-	}
46
+    /**
47
+     * Specify POST as the method to use with this route
48
+     * @return \OC\Route\Route
49
+     */
50
+    public function post() {
51
+        $this->method('POST');
52
+        return $this;
53
+    }
54 54
 
55
-	/**
56
-	 * Specify GET as the method to use with this route
57
-	 * @return \OC\Route\Route
58
-	 */
59
-	public function get() {
60
-		$this->method('GET');
61
-		return $this;
62
-	}
55
+    /**
56
+     * Specify GET as the method to use with this route
57
+     * @return \OC\Route\Route
58
+     */
59
+    public function get() {
60
+        $this->method('GET');
61
+        return $this;
62
+    }
63 63
 
64
-	/**
65
-	 * Specify PUT as the method to use with this route
66
-	 * @return \OC\Route\Route
67
-	 */
68
-	public function put() {
69
-		$this->method('PUT');
70
-		return $this;
71
-	}
64
+    /**
65
+     * Specify PUT as the method to use with this route
66
+     * @return \OC\Route\Route
67
+     */
68
+    public function put() {
69
+        $this->method('PUT');
70
+        return $this;
71
+    }
72 72
 
73
-	/**
74
-	 * Specify DELETE as the method to use with this route
75
-	 * @return \OC\Route\Route
76
-	 */
77
-	public function delete() {
78
-		$this->method('DELETE');
79
-		return $this;
80
-	}
73
+    /**
74
+     * Specify DELETE as the method to use with this route
75
+     * @return \OC\Route\Route
76
+     */
77
+    public function delete() {
78
+        $this->method('DELETE');
79
+        return $this;
80
+    }
81 81
 
82
-	/**
83
-	 * Specify PATCH as the method to use with this route
84
-	 * @return \OC\Route\Route
85
-	 */
86
-	public function patch() {
87
-		$this->method('PATCH');
88
-		return $this;
89
-	}
82
+    /**
83
+     * Specify PATCH as the method to use with this route
84
+     * @return \OC\Route\Route
85
+     */
86
+    public function patch() {
87
+        $this->method('PATCH');
88
+        return $this;
89
+    }
90 90
 
91
-	/**
92
-	 * Defaults to use for this route
93
-	 *
94
-	 * @param array $defaults The defaults
95
-	 * @return \OC\Route\Route
96
-	 */
97
-	public function defaults($defaults) {
98
-		$action = $this->getDefault('action');
99
-		$this->setDefaults($defaults);
100
-		if (isset($defaults['action'])) {
101
-			$action = $defaults['action'];
102
-		}
103
-		$this->action($action);
104
-		return $this;
105
-	}
91
+    /**
92
+     * Defaults to use for this route
93
+     *
94
+     * @param array $defaults The defaults
95
+     * @return \OC\Route\Route
96
+     */
97
+    public function defaults($defaults) {
98
+        $action = $this->getDefault('action');
99
+        $this->setDefaults($defaults);
100
+        if (isset($defaults['action'])) {
101
+            $action = $defaults['action'];
102
+        }
103
+        $this->action($action);
104
+        return $this;
105
+    }
106 106
 
107
-	/**
108
-	 * Requirements for this route
109
-	 *
110
-	 * @param array $requirements The requirements
111
-	 * @return \OC\Route\Route
112
-	 */
113
-	public function requirements($requirements) {
114
-		$method = $this->getMethods();
115
-		$this->setRequirements($requirements);
116
-		if (isset($requirements['_method'])) {
117
-			$method = $requirements['_method'];
118
-		}
119
-		if ($method) {
120
-			$this->method($method);
121
-		}
122
-		return $this;
123
-	}
107
+    /**
108
+     * Requirements for this route
109
+     *
110
+     * @param array $requirements The requirements
111
+     * @return \OC\Route\Route
112
+     */
113
+    public function requirements($requirements) {
114
+        $method = $this->getMethods();
115
+        $this->setRequirements($requirements);
116
+        if (isset($requirements['_method'])) {
117
+            $method = $requirements['_method'];
118
+        }
119
+        if ($method) {
120
+            $this->method($method);
121
+        }
122
+        return $this;
123
+    }
124 124
 
125
-	/**
126
-	 * The action to execute when this route matches
127
-	 *
128
-	 * @param string|callable $class the class or a callable
129
-	 * @param string $function the function to use with the class
130
-	 * @return \OC\Route\Route
131
-	 *
132
-	 * This function is called with $class set to a callable or
133
-	 * to the class with $function
134
-	 */
135
-	public function action($class, $function = null) {
136
-		$action = array($class, $function);
137
-		if (is_null($function)) {
138
-			$action = $class;
139
-		}
140
-		$this->setDefault('action', $action);
141
-		return $this;
142
-	}
125
+    /**
126
+     * The action to execute when this route matches
127
+     *
128
+     * @param string|callable $class the class or a callable
129
+     * @param string $function the function to use with the class
130
+     * @return \OC\Route\Route
131
+     *
132
+     * This function is called with $class set to a callable or
133
+     * to the class with $function
134
+     */
135
+    public function action($class, $function = null) {
136
+        $action = array($class, $function);
137
+        if (is_null($function)) {
138
+            $action = $class;
139
+        }
140
+        $this->setDefault('action', $action);
141
+        return $this;
142
+    }
143 143
 
144
-	/**
145
-	 * The action to execute when this route matches, includes a file like
146
-	 * it is called directly
147
-	 * @param string $file
148
-	 * @return void
149
-	 */
150
-	public function actionInclude($file) {
151
-		$function = create_function('$param',
152
-			'unset($param["_route"]);'
153
-			.'$_GET=array_merge($_GET, $param);'
154
-			.'unset($param);'
155
-			.'require_once "'.$file.'";');
156
-		$this->action($function);
157
-	}
144
+    /**
145
+     * The action to execute when this route matches, includes a file like
146
+     * it is called directly
147
+     * @param string $file
148
+     * @return void
149
+     */
150
+    public function actionInclude($file) {
151
+        $function = create_function('$param',
152
+            'unset($param["_route"]);'
153
+            .'$_GET=array_merge($_GET, $param);'
154
+            .'unset($param);'
155
+            .'require_once "'.$file.'";');
156
+        $this->action($function);
157
+    }
158 158
 }
Please login to merge, or discard this patch.
lib/private/Route/CachingRouter.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -28,38 +28,38 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 class CachingRouter extends Router {
31
-	/**
32
-	 * @var \OCP\ICache
33
-	 */
34
-	protected $cache;
31
+    /**
32
+     * @var \OCP\ICache
33
+     */
34
+    protected $cache;
35 35
 
36
-	/**
37
-	 * @param \OCP\ICache $cache
38
-	 * @param ILogger $logger
39
-	 */
40
-	public function __construct($cache, ILogger $logger) {
41
-		$this->cache = $cache;
42
-		parent::__construct($logger);
43
-	}
36
+    /**
37
+     * @param \OCP\ICache $cache
38
+     * @param ILogger $logger
39
+     */
40
+    public function __construct($cache, ILogger $logger) {
41
+        $this->cache = $cache;
42
+        parent::__construct($logger);
43
+    }
44 44
 
45
-	/**
46
-	 * Generate url based on $name and $parameters
47
-	 *
48
-	 * @param string $name Name of the route to use.
49
-	 * @param array $parameters Parameters for the route
50
-	 * @param bool $absolute
51
-	 * @return string
52
-	 */
53
-	public function generate($name, $parameters = array(), $absolute = false) {
54
-		asort($parameters);
55
-		$key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute);
56
-		$cachedKey = $this->cache->get($key);
57
-		if ($cachedKey) {
58
-			return $cachedKey;
59
-		} else {
60
-			$url = parent::generate($name, $parameters, $absolute);
61
-			$this->cache->set($key, $url, 3600);
62
-			return $url;
63
-		}
64
-	}
45
+    /**
46
+     * Generate url based on $name and $parameters
47
+     *
48
+     * @param string $name Name of the route to use.
49
+     * @param array $parameters Parameters for the route
50
+     * @param bool $absolute
51
+     * @return string
52
+     */
53
+    public function generate($name, $parameters = array(), $absolute = false) {
54
+        asort($parameters);
55
+        $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute);
56
+        $cachedKey = $this->cache->get($key);
57
+        if ($cachedKey) {
58
+            return $cachedKey;
59
+        } else {
60
+            $url = parent::generate($name, $parameters, $absolute);
61
+            $this->cache->set($key, $url, 3600);
62
+            return $url;
63
+        }
64
+    }
65 65
 }
Please login to merge, or discard this patch.
lib/private/TagManager.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -40,53 +40,53 @@
 block discarded – undo
40 40
 
41 41
 class TagManager implements \OCP\ITagManager {
42 42
 
43
-	/**
44
-	 * User session
45
-	 *
46
-	 * @var \OCP\IUserSession
47
-	 */
48
-	private $userSession;
43
+    /**
44
+     * User session
45
+     *
46
+     * @var \OCP\IUserSession
47
+     */
48
+    private $userSession;
49 49
 
50
-	/**
51
-	 * TagMapper
52
-	 *
53
-	 * @var TagMapper
54
-	 */
55
-	private $mapper;
50
+    /**
51
+     * TagMapper
52
+     *
53
+     * @var TagMapper
54
+     */
55
+    private $mapper;
56 56
 
57
-	/**
58
-	* Constructor.
59
-	*
60
-	* @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
-	* @param \OCP\IUserSession $userSession the user session
62
-	*/
63
-	public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
-		$this->mapper = $mapper;
65
-		$this->userSession = $userSession;
57
+    /**
58
+     * Constructor.
59
+     *
60
+     * @param TagMapper $mapper Instance of the TagMapper abstraction layer.
61
+     * @param \OCP\IUserSession $userSession the user session
62
+     */
63
+    public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) {
64
+        $this->mapper = $mapper;
65
+        $this->userSession = $userSession;
66 66
 
67
-	}
67
+    }
68 68
 
69
-	/**
70
-	* Create a new \OCP\ITags instance and load tags from db.
71
-	*
72
-	* @see \OCP\ITags
73
-	* @param string $type The type identifier e.g. 'contact' or 'event'.
74
-	* @param array $defaultTags An array of default tags to be used if none are stored.
75
-	* @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
-	* @param string $userId user for which to retrieve the tags, defaults to the currently
77
-	* logged in user
78
-	* @return \OCP\ITags
79
-	*/
80
-	public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
-		if (is_null($userId)) {
82
-			$user = $this->userSession->getUser();
83
-			if ($user === null) {
84
-				// nothing we can do without a user
85
-				return null;
86
-			}
87
-			$userId = $this->userSession->getUser()->getUId();
88
-		}
89
-		return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
-	}
69
+    /**
70
+     * Create a new \OCP\ITags instance and load tags from db.
71
+     *
72
+     * @see \OCP\ITags
73
+     * @param string $type The type identifier e.g. 'contact' or 'event'.
74
+     * @param array $defaultTags An array of default tags to be used if none are stored.
75
+     * @param boolean $includeShared Whether to include tags for items shared with this user by others.
76
+     * @param string $userId user for which to retrieve the tags, defaults to the currently
77
+     * logged in user
78
+     * @return \OCP\ITags
79
+     */
80
+    public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) {
81
+        if (is_null($userId)) {
82
+            $user = $this->userSession->getUser();
83
+            if ($user === null) {
84
+                // nothing we can do without a user
85
+                return null;
86
+            }
87
+            $userId = $this->userSession->getUser()->getUId();
88
+        }
89
+        return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared);
90
+    }
91 91
 
92 92
 }
Please login to merge, or discard this patch.
lib/private/ContactsManager.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -27,164 +27,164 @@
 block discarded – undo
27 27
 
28 28
 namespace OC {
29 29
 
30
-	class ContactsManager implements \OCP\Contacts\IManager {
31
-
32
-		/**
33
-		 * This function is used to search and find contacts within the users address books.
34
-		 * In case $pattern is empty all contacts will be returned.
35
-		 *
36
-		 * @param string $pattern which should match within the $searchProperties
37
-		 * @param array $searchProperties defines the properties within the query pattern should match
38
-		 * @param array $options - for future use. One should always have options!
39
-		 * @return array an array of contacts which are arrays of key-value-pairs
40
-		 */
41
-		public function search($pattern, $searchProperties = array(), $options = array()) {
42
-			$this->loadAddressBooks();
43
-			$result = array();
44
-			foreach($this->addressBooks as $addressBook) {
45
-				$r = $addressBook->search($pattern, $searchProperties, $options);
46
-				$contacts = array();
47
-				foreach($r as $c){
48
-					$c['addressbook-key'] = $addressBook->getKey();
49
-					$contacts[] = $c;
50
-				}
51
-				$result = array_merge($result, $contacts);
52
-			}
53
-
54
-			return $result;
55
-		}
56
-
57
-		/**
58
-		 * This function can be used to delete the contact identified by the given id
59
-		 *
60
-		 * @param object $id the unique identifier to a contact
61
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
-		 * @return bool successful or not
63
-		 */
64
-		public function delete($id, $addressBookKey) {
65
-			$addressBook = $this->getAddressBook($addressBookKey);
66
-			if (!$addressBook) {
67
-				return null;
68
-			}
69
-
70
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
-				return $addressBook->delete($id);
72
-			}
73
-
74
-			return null;
75
-		}
76
-
77
-		/**
78
-		 * This function is used to create a new contact if 'id' is not given or not present.
79
-		 * Otherwise the contact will be updated by replacing the entire data set.
80
-		 *
81
-		 * @param array $properties this array if key-value-pairs defines a contact
82
-		 * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
-		 * @return array representing the contact just created or updated
84
-		 */
85
-		public function createOrUpdate($properties, $addressBookKey) {
86
-			$addressBook = $this->getAddressBook($addressBookKey);
87
-			if (!$addressBook) {
88
-				return null;
89
-			}
90
-
91
-			if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
-				return $addressBook->createOrUpdate($properties);
93
-			}
94
-
95
-			return null;
96
-		}
97
-
98
-		/**
99
-		 * Check if contacts are available (e.g. contacts app enabled)
100
-		 *
101
-		 * @return bool true if enabled, false if not
102
-		 */
103
-		public function isEnabled() {
104
-			return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
-		}
106
-
107
-		/**
108
-		 * @param \OCP\IAddressBook $addressBook
109
-		 */
110
-		public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
-			$this->addressBooks[$addressBook->getKey()] = $addressBook;
112
-		}
113
-
114
-		/**
115
-		 * @param \OCP\IAddressBook $addressBook
116
-		 */
117
-		public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
-			unset($this->addressBooks[$addressBook->getKey()]);
119
-		}
120
-
121
-		/**
122
-		 * @return array
123
-		 */
124
-		public function getAddressBooks() {
125
-			$this->loadAddressBooks();
126
-			$result = array();
127
-			foreach($this->addressBooks as $addressBook) {
128
-				$result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
-			}
130
-
131
-			return $result;
132
-		}
133
-
134
-		/**
135
-		 * removes all registered address book instances
136
-		 */
137
-		public function clear() {
138
-			$this->addressBooks = array();
139
-			$this->addressBookLoaders = array();
140
-		}
141
-
142
-		/**
143
-		 * @var \OCP\IAddressBook[] which holds all registered address books
144
-		 */
145
-		private $addressBooks = array();
146
-
147
-		/**
148
-		 * @var \Closure[] to call to load/register address books
149
-		 */
150
-		private $addressBookLoaders = array();
151
-
152
-		/**
153
-		 * In order to improve lazy loading a closure can be registered which will be called in case
154
-		 * address books are actually requested
155
-		 *
156
-		 * @param \Closure $callable
157
-		 */
158
-		public function register(\Closure $callable)
159
-		{
160
-			$this->addressBookLoaders[] = $callable;
161
-		}
162
-
163
-		/**
164
-		 * Get (and load when needed) the address book for $key
165
-		 *
166
-		 * @param string $addressBookKey
167
-		 * @return \OCP\IAddressBook
168
-		 */
169
-		protected function getAddressBook($addressBookKey)
170
-		{
171
-			$this->loadAddressBooks();
172
-			if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
-				return null;
174
-			}
175
-
176
-			return $this->addressBooks[$addressBookKey];
177
-		}
178
-
179
-		/**
180
-		 * Load all address books registered with 'register'
181
-		 */
182
-		protected function loadAddressBooks()
183
-		{
184
-			foreach($this->addressBookLoaders as $callable) {
185
-				$callable($this);
186
-			}
187
-			$this->addressBookLoaders = array();
188
-		}
189
-	}
30
+    class ContactsManager implements \OCP\Contacts\IManager {
31
+
32
+        /**
33
+         * This function is used to search and find contacts within the users address books.
34
+         * In case $pattern is empty all contacts will be returned.
35
+         *
36
+         * @param string $pattern which should match within the $searchProperties
37
+         * @param array $searchProperties defines the properties within the query pattern should match
38
+         * @param array $options - for future use. One should always have options!
39
+         * @return array an array of contacts which are arrays of key-value-pairs
40
+         */
41
+        public function search($pattern, $searchProperties = array(), $options = array()) {
42
+            $this->loadAddressBooks();
43
+            $result = array();
44
+            foreach($this->addressBooks as $addressBook) {
45
+                $r = $addressBook->search($pattern, $searchProperties, $options);
46
+                $contacts = array();
47
+                foreach($r as $c){
48
+                    $c['addressbook-key'] = $addressBook->getKey();
49
+                    $contacts[] = $c;
50
+                }
51
+                $result = array_merge($result, $contacts);
52
+            }
53
+
54
+            return $result;
55
+        }
56
+
57
+        /**
58
+         * This function can be used to delete the contact identified by the given id
59
+         *
60
+         * @param object $id the unique identifier to a contact
61
+         * @param string $addressBookKey identifier of the address book in which the contact shall be deleted
62
+         * @return bool successful or not
63
+         */
64
+        public function delete($id, $addressBookKey) {
65
+            $addressBook = $this->getAddressBook($addressBookKey);
66
+            if (!$addressBook) {
67
+                return null;
68
+            }
69
+
70
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
71
+                return $addressBook->delete($id);
72
+            }
73
+
74
+            return null;
75
+        }
76
+
77
+        /**
78
+         * This function is used to create a new contact if 'id' is not given or not present.
79
+         * Otherwise the contact will be updated by replacing the entire data set.
80
+         *
81
+         * @param array $properties this array if key-value-pairs defines a contact
82
+         * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated
83
+         * @return array representing the contact just created or updated
84
+         */
85
+        public function createOrUpdate($properties, $addressBookKey) {
86
+            $addressBook = $this->getAddressBook($addressBookKey);
87
+            if (!$addressBook) {
88
+                return null;
89
+            }
90
+
91
+            if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
92
+                return $addressBook->createOrUpdate($properties);
93
+            }
94
+
95
+            return null;
96
+        }
97
+
98
+        /**
99
+         * Check if contacts are available (e.g. contacts app enabled)
100
+         *
101
+         * @return bool true if enabled, false if not
102
+         */
103
+        public function isEnabled() {
104
+            return !empty($this->addressBooks) || !empty($this->addressBookLoaders);
105
+        }
106
+
107
+        /**
108
+         * @param \OCP\IAddressBook $addressBook
109
+         */
110
+        public function registerAddressBook(\OCP\IAddressBook $addressBook) {
111
+            $this->addressBooks[$addressBook->getKey()] = $addressBook;
112
+        }
113
+
114
+        /**
115
+         * @param \OCP\IAddressBook $addressBook
116
+         */
117
+        public function unregisterAddressBook(\OCP\IAddressBook $addressBook) {
118
+            unset($this->addressBooks[$addressBook->getKey()]);
119
+        }
120
+
121
+        /**
122
+         * @return array
123
+         */
124
+        public function getAddressBooks() {
125
+            $this->loadAddressBooks();
126
+            $result = array();
127
+            foreach($this->addressBooks as $addressBook) {
128
+                $result[$addressBook->getKey()] = $addressBook->getDisplayName();
129
+            }
130
+
131
+            return $result;
132
+        }
133
+
134
+        /**
135
+         * removes all registered address book instances
136
+         */
137
+        public function clear() {
138
+            $this->addressBooks = array();
139
+            $this->addressBookLoaders = array();
140
+        }
141
+
142
+        /**
143
+         * @var \OCP\IAddressBook[] which holds all registered address books
144
+         */
145
+        private $addressBooks = array();
146
+
147
+        /**
148
+         * @var \Closure[] to call to load/register address books
149
+         */
150
+        private $addressBookLoaders = array();
151
+
152
+        /**
153
+         * In order to improve lazy loading a closure can be registered which will be called in case
154
+         * address books are actually requested
155
+         *
156
+         * @param \Closure $callable
157
+         */
158
+        public function register(\Closure $callable)
159
+        {
160
+            $this->addressBookLoaders[] = $callable;
161
+        }
162
+
163
+        /**
164
+         * Get (and load when needed) the address book for $key
165
+         *
166
+         * @param string $addressBookKey
167
+         * @return \OCP\IAddressBook
168
+         */
169
+        protected function getAddressBook($addressBookKey)
170
+        {
171
+            $this->loadAddressBooks();
172
+            if (!array_key_exists($addressBookKey, $this->addressBooks)) {
173
+                return null;
174
+            }
175
+
176
+            return $this->addressBooks[$addressBookKey];
177
+        }
178
+
179
+        /**
180
+         * Load all address books registered with 'register'
181
+         */
182
+        protected function loadAddressBooks()
183
+        {
184
+            foreach($this->addressBookLoaders as $callable) {
185
+                $callable($this);
186
+            }
187
+            $this->addressBookLoaders = array();
188
+        }
189
+    }
190 190
 }
Please login to merge, or discard this patch.