Passed
Push — master ( f0dd71...c56a27 )
by Christoph
11:49 queued 12s
created
apps/files_external/lib/Config/ConfigAdapter.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -47,142 +47,142 @@
 block discarded – undo
47 47
  */
48 48
 class ConfigAdapter implements IMountProvider {
49 49
 
50
-	/** @var UserStoragesService */
51
-	private $userStoragesService;
52
-
53
-	/** @var UserGlobalStoragesService */
54
-	private $userGlobalStoragesService;
55
-	/** @var StorageMigrator  */
56
-	private $migrator;
57
-
58
-	/**
59
-	 * @param UserStoragesService $userStoragesService
60
-	 * @param UserGlobalStoragesService $userGlobalStoragesService
61
-	 * @param StorageMigrator $migrator
62
-	 */
63
-	public function __construct(
64
-		UserStoragesService $userStoragesService,
65
-		UserGlobalStoragesService $userGlobalStoragesService,
66
-		StorageMigrator $migrator
67
-	) {
68
-		$this->userStoragesService = $userStoragesService;
69
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
70
-		$this->migrator = $migrator;
71
-	}
72
-
73
-	/**
74
-	 * Process storage ready for mounting
75
-	 *
76
-	 * @param StorageConfig $storage
77
-	 * @param IUser $user
78
-	 * @throws \OCP\AppFramework\QueryException
79
-	 */
80
-	private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
81
-		foreach ($storage->getBackendOptions() as $option => $value) {
82
-			$storage->setBackendOption($option, \OC_Mount_Config::substitutePlaceholdersInConfig($value, $user->getUID()));
83
-		}
84
-
85
-		$objectStore = $storage->getBackendOption('objectstore');
86
-		if ($objectStore) {
87
-			$objectClass = $objectStore['class'];
88
-			if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
89
-				throw new \InvalidArgumentException('Invalid object store');
90
-			}
91
-			$storage->setBackendOption('objectstore', new $objectClass($objectStore));
92
-		}
93
-
94
-		$storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
95
-		$storage->getBackend()->manipulateStorageConfig($storage, $user);
96
-	}
97
-
98
-	/**
99
-	 * Construct the storage implementation
100
-	 *
101
-	 * @param StorageConfig $storageConfig
102
-	 * @return Storage
103
-	 */
104
-	private function constructStorage(StorageConfig $storageConfig) {
105
-		$class = $storageConfig->getBackend()->getStorageClass();
106
-		$storage = new $class($storageConfig->getBackendOptions());
107
-
108
-		// auth mechanism should fire first
109
-		$storage = $storageConfig->getBackend()->wrapStorage($storage);
110
-		$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
111
-
112
-		return $storage;
113
-	}
114
-
115
-	/**
116
-	 * Get all mountpoints applicable for the user
117
-	 *
118
-	 * @param \OCP\IUser $user
119
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
120
-	 * @return \OCP\Files\Mount\IMountPoint[]
121
-	 */
122
-	public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123
-		$this->migrator->migrateUser($user);
124
-
125
-		$this->userStoragesService->setUser($user);
126
-		$this->userGlobalStoragesService->setUser($user);
127
-
128
-		$storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser();
129
-
130
-		$storages = array_map(function (StorageConfig $storageConfig) use ($user) {
131
-			try {
132
-				$this->prepareStorageConfig($storageConfig, $user);
133
-				return $this->constructStorage($storageConfig);
134
-			} catch (\Exception $e) {
135
-				// propagate exception into filesystem
136
-				return new FailedStorage(['exception' => $e]);
137
-			}
138
-		}, $storageConfigs);
139
-
140
-
141
-		\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
142
-			return $storage->getId();
143
-		}, $storages));
144
-
145
-		$availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
146
-			try {
147
-				$availability = $storage->getAvailability();
148
-				if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
149
-					$storage = new FailedStorage([
150
-						'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available')
151
-					]);
152
-				}
153
-			} catch (\Exception $e) {
154
-				// propagate exception into filesystem
155
-				$storage = new FailedStorage(['exception' => $e]);
156
-			}
157
-			return $storage;
158
-		}, $storages, $storageConfigs);
159
-
160
-		$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
161
-			if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
162
-				return new PersonalMount(
163
-					$this->userStoragesService,
164
-					$storageConfig->getId(),
165
-					$storage,
166
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
167
-					null,
168
-					$loader,
169
-					$storageConfig->getMountOptions()
170
-				);
171
-			} else {
172
-				return new ExternalMountPoint(
173
-					$storage,
174
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
175
-					null,
176
-					$loader,
177
-					$storageConfig->getMountOptions(),
178
-					$storageConfig->getId()
179
-				);
180
-			}
181
-		}, $storageConfigs, $availableStorages);
182
-
183
-		$this->userStoragesService->resetUser();
184
-		$this->userGlobalStoragesService->resetUser();
185
-
186
-		return $mounts;
187
-	}
50
+    /** @var UserStoragesService */
51
+    private $userStoragesService;
52
+
53
+    /** @var UserGlobalStoragesService */
54
+    private $userGlobalStoragesService;
55
+    /** @var StorageMigrator  */
56
+    private $migrator;
57
+
58
+    /**
59
+     * @param UserStoragesService $userStoragesService
60
+     * @param UserGlobalStoragesService $userGlobalStoragesService
61
+     * @param StorageMigrator $migrator
62
+     */
63
+    public function __construct(
64
+        UserStoragesService $userStoragesService,
65
+        UserGlobalStoragesService $userGlobalStoragesService,
66
+        StorageMigrator $migrator
67
+    ) {
68
+        $this->userStoragesService = $userStoragesService;
69
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
70
+        $this->migrator = $migrator;
71
+    }
72
+
73
+    /**
74
+     * Process storage ready for mounting
75
+     *
76
+     * @param StorageConfig $storage
77
+     * @param IUser $user
78
+     * @throws \OCP\AppFramework\QueryException
79
+     */
80
+    private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
81
+        foreach ($storage->getBackendOptions() as $option => $value) {
82
+            $storage->setBackendOption($option, \OC_Mount_Config::substitutePlaceholdersInConfig($value, $user->getUID()));
83
+        }
84
+
85
+        $objectStore = $storage->getBackendOption('objectstore');
86
+        if ($objectStore) {
87
+            $objectClass = $objectStore['class'];
88
+            if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
89
+                throw new \InvalidArgumentException('Invalid object store');
90
+            }
91
+            $storage->setBackendOption('objectstore', new $objectClass($objectStore));
92
+        }
93
+
94
+        $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
95
+        $storage->getBackend()->manipulateStorageConfig($storage, $user);
96
+    }
97
+
98
+    /**
99
+     * Construct the storage implementation
100
+     *
101
+     * @param StorageConfig $storageConfig
102
+     * @return Storage
103
+     */
104
+    private function constructStorage(StorageConfig $storageConfig) {
105
+        $class = $storageConfig->getBackend()->getStorageClass();
106
+        $storage = new $class($storageConfig->getBackendOptions());
107
+
108
+        // auth mechanism should fire first
109
+        $storage = $storageConfig->getBackend()->wrapStorage($storage);
110
+        $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
111
+
112
+        return $storage;
113
+    }
114
+
115
+    /**
116
+     * Get all mountpoints applicable for the user
117
+     *
118
+     * @param \OCP\IUser $user
119
+     * @param \OCP\Files\Storage\IStorageFactory $loader
120
+     * @return \OCP\Files\Mount\IMountPoint[]
121
+     */
122
+    public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123
+        $this->migrator->migrateUser($user);
124
+
125
+        $this->userStoragesService->setUser($user);
126
+        $this->userGlobalStoragesService->setUser($user);
127
+
128
+        $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser();
129
+
130
+        $storages = array_map(function (StorageConfig $storageConfig) use ($user) {
131
+            try {
132
+                $this->prepareStorageConfig($storageConfig, $user);
133
+                return $this->constructStorage($storageConfig);
134
+            } catch (\Exception $e) {
135
+                // propagate exception into filesystem
136
+                return new FailedStorage(['exception' => $e]);
137
+            }
138
+        }, $storageConfigs);
139
+
140
+
141
+        \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
142
+            return $storage->getId();
143
+        }, $storages));
144
+
145
+        $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
146
+            try {
147
+                $availability = $storage->getAvailability();
148
+                if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
149
+                    $storage = new FailedStorage([
150
+                        'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available')
151
+                    ]);
152
+                }
153
+            } catch (\Exception $e) {
154
+                // propagate exception into filesystem
155
+                $storage = new FailedStorage(['exception' => $e]);
156
+            }
157
+            return $storage;
158
+        }, $storages, $storageConfigs);
159
+
160
+        $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
161
+            if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
162
+                return new PersonalMount(
163
+                    $this->userStoragesService,
164
+                    $storageConfig->getId(),
165
+                    $storage,
166
+                    '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
167
+                    null,
168
+                    $loader,
169
+                    $storageConfig->getMountOptions()
170
+                );
171
+            } else {
172
+                return new ExternalMountPoint(
173
+                    $storage,
174
+                    '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
175
+                    null,
176
+                    $loader,
177
+                    $storageConfig->getMountOptions(),
178
+                    $storageConfig->getId()
179
+                );
180
+            }
181
+        }, $storageConfigs, $availableStorages);
182
+
183
+        $this->userStoragesService->resetUser();
184
+        $this->userGlobalStoragesService->resetUser();
185
+
186
+        return $mounts;
187
+    }
188 188
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/FTP.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -39,120 +39,120 @@
 block discarded – undo
39 39
 use Icewind\Streams\RetryWrapper;
40 40
 
41 41
 class FTP extends StreamWrapper{
42
-	private $password;
43
-	private $user;
44
-	private $host;
45
-	private $secure;
46
-	private $root;
42
+    private $password;
43
+    private $user;
44
+    private $host;
45
+    private $secure;
46
+    private $root;
47 47
 
48
-	public function __construct($params) {
49
-		if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
50
-			$this->host=$params['host'];
51
-			$this->user=$params['user'];
52
-			$this->password=$params['password'];
53
-			if (isset($params['secure'])) {
54
-				$this->secure = $params['secure'];
55
-			} else {
56
-				$this->secure = false;
57
-			}
58
-			$this->root=isset($params['root'])?$params['root']:'/';
59
-			if ( ! $this->root || $this->root[0]!=='/') {
60
-				$this->root='/'.$this->root;
61
-			}
62
-			if (substr($this->root, -1) !== '/') {
63
-				$this->root .= '/';
64
-			}
65
-		} else {
66
-			throw new \Exception('Creating FTP storage failed');
67
-		}
48
+    public function __construct($params) {
49
+        if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
50
+            $this->host=$params['host'];
51
+            $this->user=$params['user'];
52
+            $this->password=$params['password'];
53
+            if (isset($params['secure'])) {
54
+                $this->secure = $params['secure'];
55
+            } else {
56
+                $this->secure = false;
57
+            }
58
+            $this->root=isset($params['root'])?$params['root']:'/';
59
+            if ( ! $this->root || $this->root[0]!=='/') {
60
+                $this->root='/'.$this->root;
61
+            }
62
+            if (substr($this->root, -1) !== '/') {
63
+                $this->root .= '/';
64
+            }
65
+        } else {
66
+            throw new \Exception('Creating FTP storage failed');
67
+        }
68 68
 		
69
-	}
69
+    }
70 70
 
71
-	public function getId() {
72
-		return 'ftp::' . $this->user . '@' . $this->host . '/' . $this->root;
73
-	}
71
+    public function getId() {
72
+        return 'ftp::' . $this->user . '@' . $this->host . '/' . $this->root;
73
+    }
74 74
 
75
-	/**
76
-	 * construct the ftp url
77
-	 * @param string $path
78
-	 * @return string
79
-	 */
80
-	public function constructUrl($path) {
81
-		$url='ftp';
82
-		if ($this->secure) {
83
-			$url.='s';
84
-		}
85
-		$url.='://'.urlencode($this->user).':'.urlencode($this->password).'@'.$this->host.$this->root.$path;
86
-		return $url;
87
-	}
75
+    /**
76
+     * construct the ftp url
77
+     * @param string $path
78
+     * @return string
79
+     */
80
+    public function constructUrl($path) {
81
+        $url='ftp';
82
+        if ($this->secure) {
83
+            $url.='s';
84
+        }
85
+        $url.='://'.urlencode($this->user).':'.urlencode($this->password).'@'.$this->host.$this->root.$path;
86
+        return $url;
87
+    }
88 88
 
89
-	/**
90
-	 * Unlinks file or directory
91
-	 * @param string $path
92
-	 */
93
-	public function unlink($path) {
94
-		if ($this->is_dir($path)) {
95
-			return $this->rmdir($path);
96
-		}
97
-		else {
98
-			$url = $this->constructUrl($path);
99
-			$result = unlink($url);
100
-			clearstatcache(true, $url);
101
-			return $result;
102
-		}
103
-	}
104
-	public function fopen($path,$mode) {
105
-		switch($mode) {
106
-			case 'r':
107
-			case 'rb':
108
-			case 'w':
109
-			case 'wb':
110
-			case 'a':
111
-			case 'ab':
112
-				//these are supported by the wrapper
113
-				$context = stream_context_create(['ftp' => ['overwrite' => true]]);
114
-				$handle = fopen($this->constructUrl($path), $mode, false, $context);
115
-				return RetryWrapper::wrap($handle);
116
-			case 'r+':
117
-			case 'w+':
118
-			case 'wb+':
119
-			case 'a+':
120
-			case 'x':
121
-			case 'x+':
122
-			case 'c':
123
-			case 'c+':
124
-				//emulate these
125
-				if (strrpos($path, '.')!==false) {
126
-					$ext=substr($path, strrpos($path, '.'));
127
-				} else {
128
-					$ext='';
129
-				}
130
-				$tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
131
-				if ($this->file_exists($path)) {
132
-					$this->getFile($path, $tmpFile);
133
-				}
134
-				$handle = fopen($tmpFile, $mode);
135
-				return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
136
-					$this->writeBack($tmpFile, $path);
137
-				});
138
-		}
139
-		return false;
140
-	}
89
+    /**
90
+     * Unlinks file or directory
91
+     * @param string $path
92
+     */
93
+    public function unlink($path) {
94
+        if ($this->is_dir($path)) {
95
+            return $this->rmdir($path);
96
+        }
97
+        else {
98
+            $url = $this->constructUrl($path);
99
+            $result = unlink($url);
100
+            clearstatcache(true, $url);
101
+            return $result;
102
+        }
103
+    }
104
+    public function fopen($path,$mode) {
105
+        switch($mode) {
106
+            case 'r':
107
+            case 'rb':
108
+            case 'w':
109
+            case 'wb':
110
+            case 'a':
111
+            case 'ab':
112
+                //these are supported by the wrapper
113
+                $context = stream_context_create(['ftp' => ['overwrite' => true]]);
114
+                $handle = fopen($this->constructUrl($path), $mode, false, $context);
115
+                return RetryWrapper::wrap($handle);
116
+            case 'r+':
117
+            case 'w+':
118
+            case 'wb+':
119
+            case 'a+':
120
+            case 'x':
121
+            case 'x+':
122
+            case 'c':
123
+            case 'c+':
124
+                //emulate these
125
+                if (strrpos($path, '.')!==false) {
126
+                    $ext=substr($path, strrpos($path, '.'));
127
+                } else {
128
+                    $ext='';
129
+                }
130
+                $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
131
+                if ($this->file_exists($path)) {
132
+                    $this->getFile($path, $tmpFile);
133
+                }
134
+                $handle = fopen($tmpFile, $mode);
135
+                return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
136
+                    $this->writeBack($tmpFile, $path);
137
+                });
138
+        }
139
+        return false;
140
+    }
141 141
 
142
-	public function writeBack($tmpFile, $path) {
143
-		$this->uploadFile($tmpFile, $path);
144
-		unlink($tmpFile);
145
-	}
142
+    public function writeBack($tmpFile, $path) {
143
+        $this->uploadFile($tmpFile, $path);
144
+        unlink($tmpFile);
145
+    }
146 146
 
147
-	/**
148
-	 * check if php-ftp is installed
149
-	 */
150
-	public static function checkDependencies() {
151
-		if (function_exists('ftp_login')) {
152
-			return true;
153
-		} else {
154
-			return ['ftp'];
155
-		}
156
-	}
147
+    /**
148
+     * check if php-ftp is installed
149
+     */
150
+    public static function checkDependencies() {
151
+        if (function_exists('ftp_login')) {
152
+            return true;
153
+        } else {
154
+            return ['ftp'];
155
+        }
156
+    }
157 157
 
158 158
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/SFTP.php 1 patch
Indentation   +437 added lines, -437 removed lines patch added patch discarded remove patch
@@ -46,441 +46,441 @@
 block discarded – undo
46 46
  * provide access to SFTP servers.
47 47
  */
48 48
 class SFTP extends \OC\Files\Storage\Common {
49
-	private $host;
50
-	private $user;
51
-	private $root;
52
-	private $port = 22;
53
-
54
-	private $auth = [];
55
-
56
-	/**
57
-	 * @var \phpseclib\Net\SFTP
58
-	 */
59
-	protected $client;
60
-
61
-	/**
62
-	 * @param string $host protocol://server:port
63
-	 * @return array [$server, $port]
64
-	 */
65
-	private function splitHost($host) {
66
-		$input = $host;
67
-		if (strpos($host, '://') === false) {
68
-			// add a protocol to fix parse_url behavior with ipv6
69
-			$host = 'http://' . $host;
70
-		}
71
-
72
-		$parsed = parse_url($host);
73
-		if(is_array($parsed) && isset($parsed['port'])) {
74
-			return [$parsed['host'], $parsed['port']];
75
-		} else if (is_array($parsed)) {
76
-			return [$parsed['host'], 22];
77
-		} else {
78
-			return [$input, 22];
79
-		}
80
-	}
81
-
82
-	/**
83
-	 * {@inheritdoc}
84
-	 */
85
-	public function __construct($params) {
86
-		// Register sftp://
87
-		Stream::register();
88
-
89
-		$parsedHost =  $this->splitHost($params['host']);
90
-
91
-		$this->host = $parsedHost[0];
92
-		$this->port = $parsedHost[1];
93
-
94
-		if (!isset($params['user'])) {
95
-			throw new \UnexpectedValueException('no authentication parameters specified');
96
-		}
97
-		$this->user = $params['user'];
98
-
99
-		if (isset($params['public_key_auth'])) {
100
-			$this->auth[] = $params['public_key_auth'];
101
-		}
102
-		if (isset($params['password']) && $params['password'] !== '') {
103
-			$this->auth[] = $params['password'];
104
-		}
105
-
106
-		if ($this->auth === []) {
107
-			throw new \UnexpectedValueException('no authentication parameters specified');
108
-		}
109
-
110
-		$this->root
111
-			= isset($params['root']) ? $this->cleanPath($params['root']) : '/';
112
-
113
-		$this->root = '/' . ltrim($this->root, '/');
114
-		$this->root = rtrim($this->root, '/') . '/';
115
-	}
116
-
117
-	/**
118
-	 * Returns the connection.
119
-	 *
120
-	 * @return \phpseclib\Net\SFTP connected client instance
121
-	 * @throws \Exception when the connection failed
122
-	 */
123
-	public function getConnection() {
124
-		if (!is_null($this->client)) {
125
-			return $this->client;
126
-		}
127
-
128
-		$hostKeys = $this->readHostKeys();
129
-		$this->client = new \phpseclib\Net\SFTP($this->host, $this->port);
130
-
131
-		// The SSH Host Key MUST be verified before login().
132
-		$currentHostKey = $this->client->getServerPublicHostKey();
133
-		if (array_key_exists($this->host, $hostKeys)) {
134
-			if ($hostKeys[$this->host] !== $currentHostKey) {
135
-				throw new \Exception('Host public key does not match known key');
136
-			}
137
-		} else {
138
-			$hostKeys[$this->host] = $currentHostKey;
139
-			$this->writeHostKeys($hostKeys);
140
-		}
141
-
142
-		$login = false;
143
-		foreach ($this->auth as $auth) {
144
-			$login = $this->client->login($this->user, $auth);
145
-			if ($login === true) {
146
-				break;
147
-			}
148
-		}
149
-
150
-		if ($login === false) {
151
-			throw new \Exception('Login failed');
152
-		}
153
-		return $this->client;
154
-	}
155
-
156
-	/**
157
-	 * {@inheritdoc}
158
-	 */
159
-	public function test() {
160
-		if (
161
-			!isset($this->host)
162
-			|| !isset($this->user)
163
-		) {
164
-			return false;
165
-		}
166
-		return $this->getConnection()->nlist() !== false;
167
-	}
168
-
169
-	/**
170
-	 * {@inheritdoc}
171
-	 */
172
-	public function getId() {
173
-		$id = 'sftp::' . $this->user . '@' . $this->host;
174
-		if ($this->port !== 22) {
175
-			$id .= ':' . $this->port;
176
-		}
177
-		// note: this will double the root slash,
178
-		// we should not change it to keep compatible with
179
-		// old storage ids
180
-		$id .= '/' . $this->root;
181
-		return $id;
182
-	}
183
-
184
-	/**
185
-	 * @return string
186
-	 */
187
-	public function getHost() {
188
-		return $this->host;
189
-	}
190
-
191
-	/**
192
-	 * @return string
193
-	 */
194
-	public function getRoot() {
195
-		return $this->root;
196
-	}
197
-
198
-	/**
199
-	 * @return mixed
200
-	 */
201
-	public function getUser() {
202
-		return $this->user;
203
-	}
204
-
205
-	/**
206
-	 * @param string $path
207
-	 * @return string
208
-	 */
209
-	private function absPath($path) {
210
-		return $this->root . $this->cleanPath($path);
211
-	}
212
-
213
-	/**
214
-	 * @return string|false
215
-	 */
216
-	private function hostKeysPath() {
217
-		try {
218
-			$storage_view = \OCP\Files::getStorage('files_external');
219
-			if ($storage_view) {
220
-				return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') .
221
-					$storage_view->getAbsolutePath('') .
222
-					'ssh_hostKeys';
223
-			}
224
-		} catch (\Exception $e) {
225
-		}
226
-		return false;
227
-	}
228
-
229
-	/**
230
-	 * @param $keys
231
-	 * @return bool
232
-	 */
233
-	protected function writeHostKeys($keys) {
234
-		try {
235
-			$keyPath = $this->hostKeysPath();
236
-			if ($keyPath && file_exists($keyPath)) {
237
-				$fp = fopen($keyPath, 'w');
238
-				foreach ($keys as $host => $key) {
239
-					fwrite($fp, $host . '::' . $key . "\n");
240
-				}
241
-				fclose($fp);
242
-				return true;
243
-			}
244
-		} catch (\Exception $e) {
245
-		}
246
-		return false;
247
-	}
248
-
249
-	/**
250
-	 * @return array
251
-	 */
252
-	protected function readHostKeys() {
253
-		try {
254
-			$keyPath = $this->hostKeysPath();
255
-			if (file_exists($keyPath)) {
256
-				$hosts = [];
257
-				$keys = [];
258
-				$lines = file($keyPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
259
-				if ($lines) {
260
-					foreach ($lines as $line) {
261
-						$hostKeyArray = explode("::", $line, 2);
262
-						if (count($hostKeyArray) === 2) {
263
-							$hosts[] = $hostKeyArray[0];
264
-							$keys[] = $hostKeyArray[1];
265
-						}
266
-					}
267
-					return array_combine($hosts, $keys);
268
-				}
269
-			}
270
-		} catch (\Exception $e) {
271
-		}
272
-		return [];
273
-	}
274
-
275
-	/**
276
-	 * {@inheritdoc}
277
-	 */
278
-	public function mkdir($path) {
279
-		try {
280
-			return $this->getConnection()->mkdir($this->absPath($path));
281
-		} catch (\Exception $e) {
282
-			return false;
283
-		}
284
-	}
285
-
286
-	/**
287
-	 * {@inheritdoc}
288
-	 */
289
-	public function rmdir($path) {
290
-		try {
291
-			$result = $this->getConnection()->delete($this->absPath($path), true);
292
-			// workaround: stray stat cache entry when deleting empty folders
293
-			// see https://github.com/phpseclib/phpseclib/issues/706
294
-			$this->getConnection()->clearStatCache();
295
-			return $result;
296
-		} catch (\Exception $e) {
297
-			return false;
298
-		}
299
-	}
300
-
301
-	/**
302
-	 * {@inheritdoc}
303
-	 */
304
-	public function opendir($path) {
305
-		try {
306
-			$list = $this->getConnection()->nlist($this->absPath($path));
307
-			if ($list === false) {
308
-				return false;
309
-			}
310
-
311
-			$id = md5('sftp:' . $path);
312
-			$dirStream = [];
313
-			foreach($list as $file) {
314
-				if ($file !== '.' && $file !== '..') {
315
-					$dirStream[] = $file;
316
-				}
317
-			}
318
-			return IteratorDirectory::wrap($dirStream);
319
-		} catch(\Exception $e) {
320
-			return false;
321
-		}
322
-	}
323
-
324
-	/**
325
-	 * {@inheritdoc}
326
-	 */
327
-	public function filetype($path) {
328
-		try {
329
-			$stat = $this->getConnection()->stat($this->absPath($path));
330
-			if ((int) $stat['type'] === NET_SFTP_TYPE_REGULAR) {
331
-				return 'file';
332
-			}
333
-
334
-			if ((int) $stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
335
-				return 'dir';
336
-			}
337
-		} catch (\Exception $e) {
338
-
339
-		}
340
-		return false;
341
-	}
342
-
343
-	/**
344
-	 * {@inheritdoc}
345
-	 */
346
-	public function file_exists($path) {
347
-		try {
348
-			return $this->getConnection()->stat($this->absPath($path)) !== false;
349
-		} catch (\Exception $e) {
350
-			return false;
351
-		}
352
-	}
353
-
354
-	/**
355
-	 * {@inheritdoc}
356
-	 */
357
-	public function unlink($path) {
358
-		try {
359
-			return $this->getConnection()->delete($this->absPath($path), true);
360
-		} catch (\Exception $e) {
361
-			return false;
362
-		}
363
-	}
364
-
365
-	/**
366
-	 * {@inheritdoc}
367
-	 */
368
-	public function fopen($path, $mode) {
369
-		try {
370
-			$absPath = $this->absPath($path);
371
-			switch($mode) {
372
-				case 'r':
373
-				case 'rb':
374
-					if ( !$this->file_exists($path)) {
375
-						return false;
376
-					}
377
-					SFTPReadStream::register();
378
-					$context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
379
-					$handle = fopen('sftpread://' . trim($absPath, '/'), 'r', false, $context);
380
-					return RetryWrapper::wrap($handle);
381
-				case 'w':
382
-				case 'wb':
383
-					SFTPWriteStream::register();
384
-					$context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
385
-					return fopen('sftpwrite://' . trim($absPath, '/'), 'w', false, $context);
386
-				case 'a':
387
-				case 'ab':
388
-				case 'r+':
389
-				case 'w+':
390
-				case 'wb+':
391
-				case 'a+':
392
-				case 'x':
393
-				case 'x+':
394
-				case 'c':
395
-				case 'c+':
396
-					$context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
397
-					$handle = fopen($this->constructUrl($path), $mode, false, $context);
398
-					return RetryWrapper::wrap($handle);
399
-			}
400
-		} catch (\Exception $e) {
401
-		}
402
-		return false;
403
-	}
404
-
405
-	/**
406
-	 * {@inheritdoc}
407
-	 */
408
-	public function touch($path, $mtime=null) {
409
-		try {
410
-			if (!is_null($mtime)) {
411
-				return false;
412
-			}
413
-			if (!$this->file_exists($path)) {
414
-				$this->getConnection()->put($this->absPath($path), '');
415
-			} else {
416
-				return false;
417
-			}
418
-		} catch (\Exception $e) {
419
-			return false;
420
-		}
421
-		return true;
422
-	}
423
-
424
-	/**
425
-	 * @param string $path
426
-	 * @param string $target
427
-	 * @throws \Exception
428
-	 */
429
-	public function getFile($path, $target) {
430
-		$this->getConnection()->get($path, $target);
431
-	}
432
-
433
-	/**
434
-	 * @param string $path
435
-	 * @param string $target
436
-	 * @throws \Exception
437
-	 */
438
-	public function uploadFile($path, $target) {
439
-		$this->getConnection()->put($target, $path, NET_SFTP_LOCAL_FILE);
440
-	}
441
-
442
-	/**
443
-	 * {@inheritdoc}
444
-	 */
445
-	public function rename($source, $target) {
446
-		try {
447
-			if ($this->file_exists($target)) {
448
-				$this->unlink($target);
449
-			}
450
-			return $this->getConnection()->rename(
451
-				$this->absPath($source),
452
-				$this->absPath($target)
453
-			);
454
-		} catch (\Exception $e) {
455
-			return false;
456
-		}
457
-	}
458
-
459
-	/**
460
-	 * {@inheritdoc}
461
-	 */
462
-	public function stat($path) {
463
-		try {
464
-			$stat = $this->getConnection()->stat($this->absPath($path));
465
-
466
-			$mtime = $stat ? $stat['mtime'] : -1;
467
-			$size = $stat ? $stat['size'] : 0;
468
-
469
-			return ['mtime' => $mtime, 'size' => $size, 'ctime' => -1];
470
-		} catch (\Exception $e) {
471
-			return false;
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * @param string $path
477
-	 * @return string
478
-	 */
479
-	public function constructUrl($path) {
480
-		// Do not pass the password here. We want to use the Net_SFTP object
481
-		// supplied via stream context or fail. We only supply username and
482
-		// hostname because this might show up in logs (they are not used).
483
-		$url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path;
484
-		return $url;
485
-	}
49
+    private $host;
50
+    private $user;
51
+    private $root;
52
+    private $port = 22;
53
+
54
+    private $auth = [];
55
+
56
+    /**
57
+     * @var \phpseclib\Net\SFTP
58
+     */
59
+    protected $client;
60
+
61
+    /**
62
+     * @param string $host protocol://server:port
63
+     * @return array [$server, $port]
64
+     */
65
+    private function splitHost($host) {
66
+        $input = $host;
67
+        if (strpos($host, '://') === false) {
68
+            // add a protocol to fix parse_url behavior with ipv6
69
+            $host = 'http://' . $host;
70
+        }
71
+
72
+        $parsed = parse_url($host);
73
+        if(is_array($parsed) && isset($parsed['port'])) {
74
+            return [$parsed['host'], $parsed['port']];
75
+        } else if (is_array($parsed)) {
76
+            return [$parsed['host'], 22];
77
+        } else {
78
+            return [$input, 22];
79
+        }
80
+    }
81
+
82
+    /**
83
+     * {@inheritdoc}
84
+     */
85
+    public function __construct($params) {
86
+        // Register sftp://
87
+        Stream::register();
88
+
89
+        $parsedHost =  $this->splitHost($params['host']);
90
+
91
+        $this->host = $parsedHost[0];
92
+        $this->port = $parsedHost[1];
93
+
94
+        if (!isset($params['user'])) {
95
+            throw new \UnexpectedValueException('no authentication parameters specified');
96
+        }
97
+        $this->user = $params['user'];
98
+
99
+        if (isset($params['public_key_auth'])) {
100
+            $this->auth[] = $params['public_key_auth'];
101
+        }
102
+        if (isset($params['password']) && $params['password'] !== '') {
103
+            $this->auth[] = $params['password'];
104
+        }
105
+
106
+        if ($this->auth === []) {
107
+            throw new \UnexpectedValueException('no authentication parameters specified');
108
+        }
109
+
110
+        $this->root
111
+            = isset($params['root']) ? $this->cleanPath($params['root']) : '/';
112
+
113
+        $this->root = '/' . ltrim($this->root, '/');
114
+        $this->root = rtrim($this->root, '/') . '/';
115
+    }
116
+
117
+    /**
118
+     * Returns the connection.
119
+     *
120
+     * @return \phpseclib\Net\SFTP connected client instance
121
+     * @throws \Exception when the connection failed
122
+     */
123
+    public function getConnection() {
124
+        if (!is_null($this->client)) {
125
+            return $this->client;
126
+        }
127
+
128
+        $hostKeys = $this->readHostKeys();
129
+        $this->client = new \phpseclib\Net\SFTP($this->host, $this->port);
130
+
131
+        // The SSH Host Key MUST be verified before login().
132
+        $currentHostKey = $this->client->getServerPublicHostKey();
133
+        if (array_key_exists($this->host, $hostKeys)) {
134
+            if ($hostKeys[$this->host] !== $currentHostKey) {
135
+                throw new \Exception('Host public key does not match known key');
136
+            }
137
+        } else {
138
+            $hostKeys[$this->host] = $currentHostKey;
139
+            $this->writeHostKeys($hostKeys);
140
+        }
141
+
142
+        $login = false;
143
+        foreach ($this->auth as $auth) {
144
+            $login = $this->client->login($this->user, $auth);
145
+            if ($login === true) {
146
+                break;
147
+            }
148
+        }
149
+
150
+        if ($login === false) {
151
+            throw new \Exception('Login failed');
152
+        }
153
+        return $this->client;
154
+    }
155
+
156
+    /**
157
+     * {@inheritdoc}
158
+     */
159
+    public function test() {
160
+        if (
161
+            !isset($this->host)
162
+            || !isset($this->user)
163
+        ) {
164
+            return false;
165
+        }
166
+        return $this->getConnection()->nlist() !== false;
167
+    }
168
+
169
+    /**
170
+     * {@inheritdoc}
171
+     */
172
+    public function getId() {
173
+        $id = 'sftp::' . $this->user . '@' . $this->host;
174
+        if ($this->port !== 22) {
175
+            $id .= ':' . $this->port;
176
+        }
177
+        // note: this will double the root slash,
178
+        // we should not change it to keep compatible with
179
+        // old storage ids
180
+        $id .= '/' . $this->root;
181
+        return $id;
182
+    }
183
+
184
+    /**
185
+     * @return string
186
+     */
187
+    public function getHost() {
188
+        return $this->host;
189
+    }
190
+
191
+    /**
192
+     * @return string
193
+     */
194
+    public function getRoot() {
195
+        return $this->root;
196
+    }
197
+
198
+    /**
199
+     * @return mixed
200
+     */
201
+    public function getUser() {
202
+        return $this->user;
203
+    }
204
+
205
+    /**
206
+     * @param string $path
207
+     * @return string
208
+     */
209
+    private function absPath($path) {
210
+        return $this->root . $this->cleanPath($path);
211
+    }
212
+
213
+    /**
214
+     * @return string|false
215
+     */
216
+    private function hostKeysPath() {
217
+        try {
218
+            $storage_view = \OCP\Files::getStorage('files_external');
219
+            if ($storage_view) {
220
+                return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') .
221
+                    $storage_view->getAbsolutePath('') .
222
+                    'ssh_hostKeys';
223
+            }
224
+        } catch (\Exception $e) {
225
+        }
226
+        return false;
227
+    }
228
+
229
+    /**
230
+     * @param $keys
231
+     * @return bool
232
+     */
233
+    protected function writeHostKeys($keys) {
234
+        try {
235
+            $keyPath = $this->hostKeysPath();
236
+            if ($keyPath && file_exists($keyPath)) {
237
+                $fp = fopen($keyPath, 'w');
238
+                foreach ($keys as $host => $key) {
239
+                    fwrite($fp, $host . '::' . $key . "\n");
240
+                }
241
+                fclose($fp);
242
+                return true;
243
+            }
244
+        } catch (\Exception $e) {
245
+        }
246
+        return false;
247
+    }
248
+
249
+    /**
250
+     * @return array
251
+     */
252
+    protected function readHostKeys() {
253
+        try {
254
+            $keyPath = $this->hostKeysPath();
255
+            if (file_exists($keyPath)) {
256
+                $hosts = [];
257
+                $keys = [];
258
+                $lines = file($keyPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
259
+                if ($lines) {
260
+                    foreach ($lines as $line) {
261
+                        $hostKeyArray = explode("::", $line, 2);
262
+                        if (count($hostKeyArray) === 2) {
263
+                            $hosts[] = $hostKeyArray[0];
264
+                            $keys[] = $hostKeyArray[1];
265
+                        }
266
+                    }
267
+                    return array_combine($hosts, $keys);
268
+                }
269
+            }
270
+        } catch (\Exception $e) {
271
+        }
272
+        return [];
273
+    }
274
+
275
+    /**
276
+     * {@inheritdoc}
277
+     */
278
+    public function mkdir($path) {
279
+        try {
280
+            return $this->getConnection()->mkdir($this->absPath($path));
281
+        } catch (\Exception $e) {
282
+            return false;
283
+        }
284
+    }
285
+
286
+    /**
287
+     * {@inheritdoc}
288
+     */
289
+    public function rmdir($path) {
290
+        try {
291
+            $result = $this->getConnection()->delete($this->absPath($path), true);
292
+            // workaround: stray stat cache entry when deleting empty folders
293
+            // see https://github.com/phpseclib/phpseclib/issues/706
294
+            $this->getConnection()->clearStatCache();
295
+            return $result;
296
+        } catch (\Exception $e) {
297
+            return false;
298
+        }
299
+    }
300
+
301
+    /**
302
+     * {@inheritdoc}
303
+     */
304
+    public function opendir($path) {
305
+        try {
306
+            $list = $this->getConnection()->nlist($this->absPath($path));
307
+            if ($list === false) {
308
+                return false;
309
+            }
310
+
311
+            $id = md5('sftp:' . $path);
312
+            $dirStream = [];
313
+            foreach($list as $file) {
314
+                if ($file !== '.' && $file !== '..') {
315
+                    $dirStream[] = $file;
316
+                }
317
+            }
318
+            return IteratorDirectory::wrap($dirStream);
319
+        } catch(\Exception $e) {
320
+            return false;
321
+        }
322
+    }
323
+
324
+    /**
325
+     * {@inheritdoc}
326
+     */
327
+    public function filetype($path) {
328
+        try {
329
+            $stat = $this->getConnection()->stat($this->absPath($path));
330
+            if ((int) $stat['type'] === NET_SFTP_TYPE_REGULAR) {
331
+                return 'file';
332
+            }
333
+
334
+            if ((int) $stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
335
+                return 'dir';
336
+            }
337
+        } catch (\Exception $e) {
338
+
339
+        }
340
+        return false;
341
+    }
342
+
343
+    /**
344
+     * {@inheritdoc}
345
+     */
346
+    public function file_exists($path) {
347
+        try {
348
+            return $this->getConnection()->stat($this->absPath($path)) !== false;
349
+        } catch (\Exception $e) {
350
+            return false;
351
+        }
352
+    }
353
+
354
+    /**
355
+     * {@inheritdoc}
356
+     */
357
+    public function unlink($path) {
358
+        try {
359
+            return $this->getConnection()->delete($this->absPath($path), true);
360
+        } catch (\Exception $e) {
361
+            return false;
362
+        }
363
+    }
364
+
365
+    /**
366
+     * {@inheritdoc}
367
+     */
368
+    public function fopen($path, $mode) {
369
+        try {
370
+            $absPath = $this->absPath($path);
371
+            switch($mode) {
372
+                case 'r':
373
+                case 'rb':
374
+                    if ( !$this->file_exists($path)) {
375
+                        return false;
376
+                    }
377
+                    SFTPReadStream::register();
378
+                    $context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
379
+                    $handle = fopen('sftpread://' . trim($absPath, '/'), 'r', false, $context);
380
+                    return RetryWrapper::wrap($handle);
381
+                case 'w':
382
+                case 'wb':
383
+                    SFTPWriteStream::register();
384
+                    $context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
385
+                    return fopen('sftpwrite://' . trim($absPath, '/'), 'w', false, $context);
386
+                case 'a':
387
+                case 'ab':
388
+                case 'r+':
389
+                case 'w+':
390
+                case 'wb+':
391
+                case 'a+':
392
+                case 'x':
393
+                case 'x+':
394
+                case 'c':
395
+                case 'c+':
396
+                    $context = stream_context_create(['sftp' => ['session' => $this->getConnection()]]);
397
+                    $handle = fopen($this->constructUrl($path), $mode, false, $context);
398
+                    return RetryWrapper::wrap($handle);
399
+            }
400
+        } catch (\Exception $e) {
401
+        }
402
+        return false;
403
+    }
404
+
405
+    /**
406
+     * {@inheritdoc}
407
+     */
408
+    public function touch($path, $mtime=null) {
409
+        try {
410
+            if (!is_null($mtime)) {
411
+                return false;
412
+            }
413
+            if (!$this->file_exists($path)) {
414
+                $this->getConnection()->put($this->absPath($path), '');
415
+            } else {
416
+                return false;
417
+            }
418
+        } catch (\Exception $e) {
419
+            return false;
420
+        }
421
+        return true;
422
+    }
423
+
424
+    /**
425
+     * @param string $path
426
+     * @param string $target
427
+     * @throws \Exception
428
+     */
429
+    public function getFile($path, $target) {
430
+        $this->getConnection()->get($path, $target);
431
+    }
432
+
433
+    /**
434
+     * @param string $path
435
+     * @param string $target
436
+     * @throws \Exception
437
+     */
438
+    public function uploadFile($path, $target) {
439
+        $this->getConnection()->put($target, $path, NET_SFTP_LOCAL_FILE);
440
+    }
441
+
442
+    /**
443
+     * {@inheritdoc}
444
+     */
445
+    public function rename($source, $target) {
446
+        try {
447
+            if ($this->file_exists($target)) {
448
+                $this->unlink($target);
449
+            }
450
+            return $this->getConnection()->rename(
451
+                $this->absPath($source),
452
+                $this->absPath($target)
453
+            );
454
+        } catch (\Exception $e) {
455
+            return false;
456
+        }
457
+    }
458
+
459
+    /**
460
+     * {@inheritdoc}
461
+     */
462
+    public function stat($path) {
463
+        try {
464
+            $stat = $this->getConnection()->stat($this->absPath($path));
465
+
466
+            $mtime = $stat ? $stat['mtime'] : -1;
467
+            $size = $stat ? $stat['size'] : 0;
468
+
469
+            return ['mtime' => $mtime, 'size' => $size, 'ctime' => -1];
470
+        } catch (\Exception $e) {
471
+            return false;
472
+        }
473
+    }
474
+
475
+    /**
476
+     * @param string $path
477
+     * @return string
478
+     */
479
+    public function constructUrl($path) {
480
+        // Do not pass the password here. We want to use the Net_SFTP object
481
+        // supplied via stream context or fail. We only supply username and
482
+        // hostname because this might show up in logs (they are not used).
483
+        $url = 'sftp://' . urlencode($this->user) . '@' . $this->host . ':' . $this->port . $this->root . $path;
484
+        return $url;
485
+    }
486 486
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Backend/Swift.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -34,31 +34,31 @@
 block discarded – undo
34 34
 
35 35
 class Swift extends Backend {
36 36
 
37
-	use LegacyDependencyCheckPolyfill;
37
+    use LegacyDependencyCheckPolyfill;
38 38
 
39
-	public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) {
40
-		$this
41
-			->setIdentifier('swift')
42
-			->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
43
-			->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
44
-			->setText($l->t('OpenStack Object Storage'))
45
-			->addParameters([
46
-				(new DefinitionParameter('service_name', $l->t('Service name')))
47
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
48
-				(new DefinitionParameter('region', $l->t('Region')))
49
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
50
-				new DefinitionParameter('bucket', $l->t('Bucket')),
51
-				(new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
52
-					->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
-			])
54
-			->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
55
-			->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
56
-				if (isset($params['options']['key']) && $params['options']['key']) {
57
-					return $rackspaceAuth;
58
-				}
59
-				return $openstackAuth;
60
-			})
61
-		;
62
-	}
39
+    public function __construct(IL10N $l, OpenStackV2 $openstackAuth, Rackspace $rackspaceAuth) {
40
+        $this
41
+            ->setIdentifier('swift')
42
+            ->addIdentifierAlias('\OC\Files\Storage\Swift') // legacy compat
43
+            ->setStorageClass('\OCA\Files_External\Lib\Storage\Swift')
44
+            ->setText($l->t('OpenStack Object Storage'))
45
+            ->addParameters([
46
+                (new DefinitionParameter('service_name', $l->t('Service name')))
47
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
48
+                (new DefinitionParameter('region', $l->t('Region')))
49
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
50
+                new DefinitionParameter('bucket', $l->t('Bucket')),
51
+                (new DefinitionParameter('timeout', $l->t('Request timeout (seconds)')))
52
+                    ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
53
+            ])
54
+            ->addAuthScheme(AuthMechanism::SCHEME_OPENSTACK)
55
+            ->setLegacyAuthMechanismCallback(function (array $params) use ($openstackAuth, $rackspaceAuth) {
56
+                if (isset($params['options']['key']) && $params['options']['key']) {
57
+                    return $rackspaceAuth;
58
+                }
59
+                return $openstackAuth;
60
+            })
61
+        ;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
apps/files/lib/AppInfo/Application.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -48,63 +48,63 @@
 block discarded – undo
48 48
 
49 49
 class Application extends App {
50 50
 
51
-	public const APP_ID = 'files';
51
+    public const APP_ID = 'files';
52 52
 
53
-	public function __construct(array $urlParams=[]) {
54
-		parent::__construct(self::APP_ID, $urlParams);
55
-		$container = $this->getContainer();
56
-		$server = $container->getServer();
53
+    public function __construct(array $urlParams=[]) {
54
+        parent::__construct(self::APP_ID, $urlParams);
55
+        $container = $this->getContainer();
56
+        $server = $container->getServer();
57 57
 
58
-		/**
59
-		 * Controllers
60
-		 */
61
-		$container->registerService('APIController', function (IContainer $c) use ($server) {
62
-			return new ApiController(
63
-				$c->query('AppName'),
64
-				$c->query('Request'),
65
-				$server->getUserSession(),
66
-				$c->query('TagService'),
67
-				$server->getPreviewManager(),
68
-				$server->getShareManager(),
69
-				$server->getConfig(),
70
-				$server->getUserFolder()
71
-			);
72
-		});
58
+        /**
59
+         * Controllers
60
+         */
61
+        $container->registerService('APIController', function (IContainer $c) use ($server) {
62
+            return new ApiController(
63
+                $c->query('AppName'),
64
+                $c->query('Request'),
65
+                $server->getUserSession(),
66
+                $c->query('TagService'),
67
+                $server->getPreviewManager(),
68
+                $server->getShareManager(),
69
+                $server->getConfig(),
70
+                $server->getUserFolder()
71
+            );
72
+        });
73 73
 
74
-		/**
75
-		 * Services
76
-		 */
77
-		$container->registerService('TagService', function (IContainer $c) use ($server) {
78
-			$homeFolder = $c->query('ServerContainer')->getUserFolder();
79
-			return new TagService(
80
-				$c->query('ServerContainer')->getUserSession(),
81
-				$c->query('ServerContainer')->getActivityManager(),
82
-				$c->query('ServerContainer')->getTagManager()->load(self::APP_ID),
83
-				$homeFolder,
84
-				$server->getEventDispatcher()
85
-			);
86
-		});
74
+        /**
75
+         * Services
76
+         */
77
+        $container->registerService('TagService', function (IContainer $c) use ($server) {
78
+            $homeFolder = $c->query('ServerContainer')->getUserFolder();
79
+            return new TagService(
80
+                $c->query('ServerContainer')->getUserSession(),
81
+                $c->query('ServerContainer')->getActivityManager(),
82
+                $c->query('ServerContainer')->getTagManager()->load(self::APP_ID),
83
+                $homeFolder,
84
+                $server->getEventDispatcher()
85
+            );
86
+        });
87 87
 
88
-		/*
88
+        /*
89 89
 		 * Register capabilities
90 90
 		 */
91
-		$container->registerCapability(Capabilities::class);
91
+        $container->registerCapability(Capabilities::class);
92 92
 
93
-		/**
94
-		 * Register Collaboration ResourceProvider
95
-		 */
96
-		/** @var IProviderManager $providerManager */
97
-		$providerManager = $container->query(IProviderManager::class);
98
-		$providerManager->registerResourceProvider(ResourceProvider::class);
99
-		Listener::register($server->getEventDispatcher());
93
+        /**
94
+         * Register Collaboration ResourceProvider
95
+         */
96
+        /** @var IProviderManager $providerManager */
97
+        $providerManager = $container->query(IProviderManager::class);
98
+        $providerManager->registerResourceProvider(ResourceProvider::class);
99
+        Listener::register($server->getEventDispatcher());
100 100
 
101
-		/** @var IEventDispatcher $dispatcher */
102
-		$dispatcher = $container->query(IEventDispatcher::class);
103
-		$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
104
-		$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
101
+        /** @var IEventDispatcher $dispatcher */
102
+        $dispatcher = $container->query(IEventDispatcher::class);
103
+        $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
104
+        $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarListener::class);
105 105
 
106
-		/** @var \OCP\Notification\IManager $notifications */
107
-		$notifications = $container->query(\OCP\Notification\IManager::class);
108
-		$notifications->registerNotifierService(Notifier::class);
109
-	}
106
+        /** @var \OCP\Notification\IManager $notifications */
107
+        $notifications = $container->query(\OCP\Notification\IManager::class);
108
+        $notifications->registerNotifierService(Notifier::class);
109
+    }
110 110
 }
Please login to merge, or discard this patch.
apps/updatenotification/lib/Controller/APIController.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -37,102 +37,102 @@
 block discarded – undo
37 37
 
38 38
 class APIController extends OCSController {
39 39
 
40
-	/** @var IConfig */
41
-	protected $config;
42
-
43
-	/** @var IAppManager */
44
-	protected $appManager;
45
-
46
-	/** @var AppFetcher */
47
-	protected $appFetcher;
48
-
49
-	/**
50
-	 * @param string $appName
51
-	 * @param IRequest $request
52
-	 * @param IConfig $config
53
-	 * @param IAppManager $appManager
54
-	 * @param AppFetcher $appFetcher
55
-	 */
56
-	public function __construct($appName,
57
-								IRequest $request,
58
-								IConfig $config,
59
-								IAppManager $appManager,
60
-								AppFetcher $appFetcher) {
61
-		parent::__construct($appName, $request);
62
-
63
-		$this->config = $config;
64
-		$this->appManager = $appManager;
65
-		$this->appFetcher = $appFetcher;
66
-	}
67
-
68
-	/**
69
-	 * @param string $newVersion
70
-	 * @return DataResponse
71
-	 */
72
-	public function getAppList(string $newVersion): DataResponse {
73
-		if (!$this->config->getSystemValue('appstoreenabled', true)) {
74
-			return new DataResponse([
75
-				'appstore_disabled' => true,
76
-			], Http::STATUS_NOT_FOUND);
77
-		}
78
-
79
-		// Get list of installed custom apps
80
-		$installedApps = $this->appManager->getInstalledApps();
81
-		$installedApps = array_filter($installedApps, function ($app) {
82
-			try {
83
-				$this->appManager->getAppPath($app);
84
-			} catch (AppPathNotFoundException $e) {
85
-				return false;
86
-			}
87
-			return !$this->appManager->isShipped($app);
88
-		});
89
-
90
-		if (empty($installedApps)) {
91
-			return new DataResponse([
92
-				'missing' => [],
93
-				'available' => [],
94
-			]);
95
-		}
96
-
97
-		$this->appFetcher->setVersion($newVersion, 'future-apps.json', false);
98
-
99
-		// Apps available on the app store for that version
100
-		$availableApps = array_map(function (array $app) {
101
-			return $app['id'];
102
-		}, $this->appFetcher->get());
103
-
104
-		if (empty($availableApps)) {
105
-			return new DataResponse([
106
-				'appstore_disabled' => false,
107
-				'already_on_latest' => false,
108
-			], Http::STATUS_NOT_FOUND);
109
-		}
110
-
111
-		$missing = array_diff($installedApps, $availableApps);
112
-		$missing = array_map([$this, 'getAppDetails'], $missing);
113
-		sort($missing);
114
-
115
-		$available = array_intersect($installedApps, $availableApps);
116
-		$available = array_map([$this, 'getAppDetails'], $available);
117
-		sort($available);
118
-
119
-		return new DataResponse([
120
-			'missing' => $missing,
121
-			'available' => $available,
122
-		]);
123
-	}
124
-
125
-	/**
126
-	 * Get translated app name
127
-	 *
128
-	 * @param string $appId
129
-	 * @return string[]
130
-	 */
131
-	protected function getAppDetails($appId): array {
132
-		$app = $this->appManager->getAppInfo($appId);
133
-		return [
134
-			'appId' => $appId,
135
-			'appName' => $app['name'] ?? $appId,
136
-		];
137
-	}
40
+    /** @var IConfig */
41
+    protected $config;
42
+
43
+    /** @var IAppManager */
44
+    protected $appManager;
45
+
46
+    /** @var AppFetcher */
47
+    protected $appFetcher;
48
+
49
+    /**
50
+     * @param string $appName
51
+     * @param IRequest $request
52
+     * @param IConfig $config
53
+     * @param IAppManager $appManager
54
+     * @param AppFetcher $appFetcher
55
+     */
56
+    public function __construct($appName,
57
+                                IRequest $request,
58
+                                IConfig $config,
59
+                                IAppManager $appManager,
60
+                                AppFetcher $appFetcher) {
61
+        parent::__construct($appName, $request);
62
+
63
+        $this->config = $config;
64
+        $this->appManager = $appManager;
65
+        $this->appFetcher = $appFetcher;
66
+    }
67
+
68
+    /**
69
+     * @param string $newVersion
70
+     * @return DataResponse
71
+     */
72
+    public function getAppList(string $newVersion): DataResponse {
73
+        if (!$this->config->getSystemValue('appstoreenabled', true)) {
74
+            return new DataResponse([
75
+                'appstore_disabled' => true,
76
+            ], Http::STATUS_NOT_FOUND);
77
+        }
78
+
79
+        // Get list of installed custom apps
80
+        $installedApps = $this->appManager->getInstalledApps();
81
+        $installedApps = array_filter($installedApps, function ($app) {
82
+            try {
83
+                $this->appManager->getAppPath($app);
84
+            } catch (AppPathNotFoundException $e) {
85
+                return false;
86
+            }
87
+            return !$this->appManager->isShipped($app);
88
+        });
89
+
90
+        if (empty($installedApps)) {
91
+            return new DataResponse([
92
+                'missing' => [],
93
+                'available' => [],
94
+            ]);
95
+        }
96
+
97
+        $this->appFetcher->setVersion($newVersion, 'future-apps.json', false);
98
+
99
+        // Apps available on the app store for that version
100
+        $availableApps = array_map(function (array $app) {
101
+            return $app['id'];
102
+        }, $this->appFetcher->get());
103
+
104
+        if (empty($availableApps)) {
105
+            return new DataResponse([
106
+                'appstore_disabled' => false,
107
+                'already_on_latest' => false,
108
+            ], Http::STATUS_NOT_FOUND);
109
+        }
110
+
111
+        $missing = array_diff($installedApps, $availableApps);
112
+        $missing = array_map([$this, 'getAppDetails'], $missing);
113
+        sort($missing);
114
+
115
+        $available = array_intersect($installedApps, $availableApps);
116
+        $available = array_map([$this, 'getAppDetails'], $available);
117
+        sort($available);
118
+
119
+        return new DataResponse([
120
+            'missing' => $missing,
121
+            'available' => $available,
122
+        ]);
123
+    }
124
+
125
+    /**
126
+     * Get translated app name
127
+     *
128
+     * @param string $appId
129
+     * @return string[]
130
+     */
131
+    protected function getAppDetails($appId): array {
132
+        $app = $this->appManager->getAppInfo($appId);
133
+        return [
134
+            'appId' => $appId,
135
+            'appName' => $app['name'] ?? $appId,
136
+        ];
137
+    }
138 138
 }
Please login to merge, or discard this patch.
apps/dav/appinfo/app.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -40,66 +40,66 @@  discard block
 block discarded – undo
40 40
 $app->registerHooks();
41 41
 
42 42
 \OC::$server->registerService('CardDAVSyncService', function () use ($app) {
43
-	return $app->getSyncService();
43
+    return $app->getSyncService();
44 44
 });
45 45
 
46 46
 $eventDispatcher = \OC::$server->getEventDispatcher();
47 47
 
48 48
 $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
49
-	function (GenericEvent $event) use ($app) {
50
-		/** @var CardDavBackend $cardDavBackend */
51
-		$cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
52
-		$addressBookUri = $event->getSubject();
53
-		$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
54
-		if (!is_null($addressBook)) {
55
-			$cardDavBackend->deleteAddressBook($addressBook['id']);
56
-		}
57
-	}
49
+    function (GenericEvent $event) use ($app) {
50
+        /** @var CardDavBackend $cardDavBackend */
51
+        $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
52
+        $addressBookUri = $event->getSubject();
53
+        $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
54
+        if (!is_null($addressBook)) {
55
+            $cardDavBackend->deleteAddressBook($addressBook['id']);
56
+        }
57
+    }
58 58
 );
59 59
 
60 60
 $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
61
-	function (GenericEvent $event) use ($app) {
62
-		$jobList = $app->getContainer()->getServer()->getJobList();
63
-		$subscriptionData = $event->getArgument('subscriptionData');
64
-
65
-		/**
66
-		 * Initial subscription refetch
67
-		 * @var RefreshWebcalService $refreshWebcalService
68
-		 */
69
-		$refreshWebcalService = $app->getContainer()->query(RefreshWebcalService::class);
70
-		$refreshWebcalService->refreshSubscription($subscriptionData['principaluri'], $subscriptionData['uri']);
71
-
72
-		$jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
73
-			'principaluri' => $subscriptionData['principaluri'],
74
-			'uri' => $subscriptionData['uri']
75
-		]);
76
-	}
61
+    function (GenericEvent $event) use ($app) {
62
+        $jobList = $app->getContainer()->getServer()->getJobList();
63
+        $subscriptionData = $event->getArgument('subscriptionData');
64
+
65
+        /**
66
+         * Initial subscription refetch
67
+         * @var RefreshWebcalService $refreshWebcalService
68
+         */
69
+        $refreshWebcalService = $app->getContainer()->query(RefreshWebcalService::class);
70
+        $refreshWebcalService->refreshSubscription($subscriptionData['principaluri'], $subscriptionData['uri']);
71
+
72
+        $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
73
+            'principaluri' => $subscriptionData['principaluri'],
74
+            'uri' => $subscriptionData['uri']
75
+        ]);
76
+    }
77 77
 );
78 78
 
79 79
 $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
80
-	function (GenericEvent $event) use ($app) {
81
-		$jobList = $app->getContainer()->getServer()->getJobList();
82
-		$subscriptionData = $event->getArgument('subscriptionData');
83
-
84
-		$jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
85
-			'principaluri' => $subscriptionData['principaluri'],
86
-			'uri' => $subscriptionData['uri']
87
-		]);
88
-
89
-		/** @var \OCA\DAV\CalDAV\CalDavBackend $calDavBackend */
90
-		$calDavBackend = $app->getContainer()->query(\OCA\DAV\CalDAV\CalDavBackend::class);
91
-		$calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
92
-	}
80
+    function (GenericEvent $event) use ($app) {
81
+        $jobList = $app->getContainer()->getServer()->getJobList();
82
+        $subscriptionData = $event->getArgument('subscriptionData');
83
+
84
+        $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
85
+            'principaluri' => $subscriptionData['principaluri'],
86
+            'uri' => $subscriptionData['uri']
87
+        ]);
88
+
89
+        /** @var \OCA\DAV\CalDAV\CalDavBackend $calDavBackend */
90
+        $calDavBackend = $app->getContainer()->query(\OCA\DAV\CalDAV\CalDavBackend::class);
91
+        $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
92
+    }
93 93
 );
94 94
 
95 95
 $eventHandler = function () use ($app) {
96
-	try {
97
-		$job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class);
98
-		$job->run([]);
99
-		$app->getContainer()->getServer()->getJobList()->setLastRun($job);
100
-	} catch(\Exception $ex) {
101
-		$app->getContainer()->getServer()->getLogger()->logException($ex);
102
-	}
96
+    try {
97
+        $job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class);
98
+        $job->run([]);
99
+        $app->getContainer()->getServer()->getJobList()->setLastRun($job);
100
+    } catch(\Exception $ex) {
101
+        $app->getContainer()->getServer()->getLogger()->logException($ex);
102
+    }
103 103
 };
104 104
 
105 105
 $eventDispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
@@ -107,20 +107,20 @@  discard block
 block discarded – undo
107 107
 
108 108
 $cm = \OC::$server->getContactsManager();
109 109
 $cm->register(function () use ($cm, $app) {
110
-	$user = \OC::$server->getUserSession()->getUser();
111
-	if (!is_null($user)) {
112
-		$app->setupContactsProvider($cm, $user->getUID());
113
-	} else {
114
-		$app->setupSystemContactsProvider($cm);
115
-	}
110
+    $user = \OC::$server->getUserSession()->getUser();
111
+    if (!is_null($user)) {
112
+        $app->setupContactsProvider($cm, $user->getUID());
113
+    } else {
114
+        $app->setupSystemContactsProvider($cm);
115
+    }
116 116
 });
117 117
 
118 118
 $calendarManager = \OC::$server->getCalendarManager();
119 119
 $calendarManager->register(function () use ($calendarManager, $app) {
120
-	$user = \OC::$server->getUserSession()->getUser();
121
-	if ($user !== null) {
122
-		$app->setupCalendarProvider($calendarManager, $user->getUID());
123
-	}
120
+    $user = \OC::$server->getUserSession()->getUser();
121
+    if ($user !== null) {
122
+        $app->setupCalendarProvider($calendarManager, $user->getUID());
123
+    }
124 124
 });
125 125
 
126 126
 $app->registerNotifier();
Please login to merge, or discard this patch.
apps/dav/appinfo/v1/webdav.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 // no php execution timeout for webdav
32 32
 if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
33
-	@set_time_limit(0);
33
+    @set_time_limit(0);
34 34
 }
35 35
 ignore_user_abort(true);
36 36
 
@@ -38,39 +38,39 @@  discard block
 block discarded – undo
38 38
 \OC_Util::obEnd();
39 39
 
40 40
 $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
41
-	\OC::$server->getConfig(),
42
-	\OC::$server->getLogger(),
43
-	\OC::$server->getDatabaseConnection(),
44
-	\OC::$server->getUserSession(),
45
-	\OC::$server->getMountManager(),
46
-	\OC::$server->getTagManager(),
47
-	\OC::$server->getRequest(),
48
-	\OC::$server->getPreviewManager(),
49
-	\OC::$server->getEventDispatcher()
41
+    \OC::$server->getConfig(),
42
+    \OC::$server->getLogger(),
43
+    \OC::$server->getDatabaseConnection(),
44
+    \OC::$server->getUserSession(),
45
+    \OC::$server->getMountManager(),
46
+    \OC::$server->getTagManager(),
47
+    \OC::$server->getRequest(),
48
+    \OC::$server->getPreviewManager(),
49
+    \OC::$server->getEventDispatcher()
50 50
 );
51 51
 
52 52
 // Backends
53 53
 $authBackend = new \OCA\DAV\Connector\Sabre\Auth(
54
-	\OC::$server->getSession(),
55
-	\OC::$server->getUserSession(),
56
-	\OC::$server->getRequest(),
57
-	\OC::$server->getTwoFactorAuthManager(),
58
-	\OC::$server->getBruteForceThrottler(),
59
-	'principals/'
54
+    \OC::$server->getSession(),
55
+    \OC::$server->getUserSession(),
56
+    \OC::$server->getRequest(),
57
+    \OC::$server->getTwoFactorAuthManager(),
58
+    \OC::$server->getBruteForceThrottler(),
59
+    'principals/'
60 60
 );
61 61
 $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
62 62
 $bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth(
63
-	\OC::$server->getUserSession(),
64
-	\OC::$server->getSession(),
65
-	\OC::$server->getRequest()
63
+    \OC::$server->getUserSession(),
64
+    \OC::$server->getSession(),
65
+    \OC::$server->getRequest()
66 66
 );
67 67
 $authPlugin->addBackend($bearerAuthPlugin);
68 68
 
69 69
 $requestUri = \OC::$server->getRequest()->getRequestUri();
70 70
 
71 71
 $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () {
72
-	// use the view for the logged in user
73
-	return \OC\Files\Filesystem::getView();
72
+    // use the view for the logged in user
73
+    return \OC\Files\Filesystem::getView();
74 74
 });
75 75
 
76 76
 $dispatcher = \OC::$server->getEventDispatcher();
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 1 patch
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -54,220 +54,220 @@
 block discarded – undo
54 54
 
55 55
 class Application extends App {
56 56
 
57
-	const APP_ID = 'dav';
57
+    const APP_ID = 'dav';
58 58
 
59
-	/**
60
-	 * Application constructor.
61
-	 */
62
-	public function __construct() {
63
-		parent::__construct('dav');
59
+    /**
60
+     * Application constructor.
61
+     */
62
+    public function __construct() {
63
+        parent::__construct('dav');
64 64
 
65
-		$container = $this->getContainer();
66
-		$server = $container->getServer();
65
+        $container = $this->getContainer();
66
+        $server = $container->getServer();
67 67
 
68
-		$container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
69
-			return new PhotoCache(
70
-				$server->getAppDataDir('dav-photocache'),
71
-				$server->getLogger()
72
-			);
73
-		});
68
+        $container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
69
+            return new PhotoCache(
70
+                $server->getAppDataDir('dav-photocache'),
71
+                $server->getLogger()
72
+            );
73
+        });
74 74
 
75
-		/*
75
+        /*
76 76
 		 * Register capabilities
77 77
 		 */
78
-		$container->registerCapability(Capabilities::class);
79
-	}
78
+        $container->registerCapability(Capabilities::class);
79
+    }
80 80
 
81
-	/**
82
-	 * @param IContactsManager $contactsManager
83
-	 * @param string $userID
84
-	 */
85
-	public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
86
-		/** @var ContactsManager $cm */
87
-		$cm = $this->getContainer()->query(ContactsManager::class);
88
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
89
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
90
-	}
81
+    /**
82
+     * @param IContactsManager $contactsManager
83
+     * @param string $userID
84
+     */
85
+    public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
86
+        /** @var ContactsManager $cm */
87
+        $cm = $this->getContainer()->query(ContactsManager::class);
88
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
89
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
90
+    }
91 91
 
92
-	/**
93
-	 * @param IContactsManager $contactsManager
94
-	 */
95
-	public function setupSystemContactsProvider(IContactsManager $contactsManager) {
96
-		/** @var ContactsManager $cm */
97
-		$cm = $this->getContainer()->query(ContactsManager::class);
98
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
99
-		$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
100
-	}
92
+    /**
93
+     * @param IContactsManager $contactsManager
94
+     */
95
+    public function setupSystemContactsProvider(IContactsManager $contactsManager) {
96
+        /** @var ContactsManager $cm */
97
+        $cm = $this->getContainer()->query(ContactsManager::class);
98
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
99
+        $cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
100
+    }
101 101
 
102
-	/**
103
-	 * @param ICalendarManager $calendarManager
104
-	 * @param string $userId
105
-	 */
106
-	public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
107
-		$cm = $this->getContainer()->query(CalendarManager::class);
108
-		$cm->setupCalendarProvider($calendarManager, $userId);
109
-	}
102
+    /**
103
+     * @param ICalendarManager $calendarManager
104
+     * @param string $userId
105
+     */
106
+    public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
107
+        $cm = $this->getContainer()->query(CalendarManager::class);
108
+        $cm->setupCalendarProvider($calendarManager, $userId);
109
+    }
110 110
 
111
-	public function registerHooks() {
112
-		/** @var HookManager $hm */
113
-		$hm = $this->getContainer()->query(HookManager::class);
114
-		$hm->setup();
111
+    public function registerHooks() {
112
+        /** @var HookManager $hm */
113
+        $hm = $this->getContainer()->query(HookManager::class);
114
+        $hm->setup();
115 115
 
116
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
116
+        $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
117 117
 
118
-		// first time login event setup
119
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
120
-			if ($event instanceof GenericEvent) {
121
-				$hm->firstLogin($event->getSubject());
122
-			}
123
-		});
118
+        // first time login event setup
119
+        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
120
+            if ($event instanceof GenericEvent) {
121
+                $hm->firstLogin($event->getSubject());
122
+            }
123
+        });
124 124
 
125
-		$birthdayListener = function ($event) {
126
-			if ($event instanceof GenericEvent) {
127
-				/** @var BirthdayService $b */
128
-				$b = $this->getContainer()->query(BirthdayService::class);
129
-				$b->onCardChanged(
130
-					$event->getArgument('addressBookId'),
131
-					$event->getArgument('cardUri'),
132
-					$event->getArgument('cardData')
133
-				);
134
-			}
135
-		};
125
+        $birthdayListener = function ($event) {
126
+            if ($event instanceof GenericEvent) {
127
+                /** @var BirthdayService $b */
128
+                $b = $this->getContainer()->query(BirthdayService::class);
129
+                $b->onCardChanged(
130
+                    $event->getArgument('addressBookId'),
131
+                    $event->getArgument('cardUri'),
132
+                    $event->getArgument('cardData')
133
+                );
134
+            }
135
+        };
136 136
 
137
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
138
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
139
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
140
-			if ($event instanceof GenericEvent) {
141
-				/** @var BirthdayService $b */
142
-				$b = $this->getContainer()->query(BirthdayService::class);
143
-				$b->onCardDeleted(
144
-					$event->getArgument('addressBookId'),
145
-					$event->getArgument('cardUri')
146
-				);
147
-			}
148
-		});
137
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
138
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
139
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
140
+            if ($event instanceof GenericEvent) {
141
+                /** @var BirthdayService $b */
142
+                $b = $this->getContainer()->query(BirthdayService::class);
143
+                $b->onCardDeleted(
144
+                    $event->getArgument('addressBookId'),
145
+                    $event->getArgument('cardUri')
146
+                );
147
+            }
148
+        });
149 149
 
150
-		$clearPhotoCache = function ($event) {
151
-			if ($event instanceof GenericEvent) {
152
-				/** @var PhotoCache $p */
153
-				$p = $this->getContainer()->query(PhotoCache::class);
154
-				$p->delete(
155
-					$event->getArgument('addressBookId'),
156
-					$event->getArgument('cardUri')
157
-				);
158
-			}
159
-		};
160
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
161
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
150
+        $clearPhotoCache = function ($event) {
151
+            if ($event instanceof GenericEvent) {
152
+                /** @var PhotoCache $p */
153
+                $p = $this->getContainer()->query(PhotoCache::class);
154
+                $p->delete(
155
+                    $event->getArgument('addressBookId'),
156
+                    $event->getArgument('cardUri')
157
+                );
158
+            }
159
+        };
160
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
161
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
162 162
 
163
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
164
-			$user = $event->getSubject();
165
-			$syncService = $this->getContainer()->query(SyncService::class);
166
-			$syncService->updateUser($user);
167
-		});
163
+        $dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
164
+            $user = $event->getSubject();
165
+            $syncService = $this->getContainer()->query(SyncService::class);
166
+            $syncService->updateUser($user);
167
+        });
168 168
 
169
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
170
-			/** @var Backend $backend */
171
-			$backend = $this->getContainer()->query(Backend::class);
172
-			$backend->onCalendarAdd(
173
-				$event->getArgument('calendarData')
174
-			);
175
-		});
176
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
177
-			/** @var Backend $backend */
178
-			$backend = $this->getContainer()->query(Backend::class);
179
-			$backend->onCalendarUpdate(
180
-				$event->getArgument('calendarData'),
181
-				$event->getArgument('shares'),
182
-				$event->getArgument('propertyMutations')
183
-			);
184
-		});
185
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
186
-			/** @var Backend $backend */
187
-			$backend = $this->getContainer()->query(Backend::class);
188
-			$backend->onCalendarDelete(
189
-				$event->getArgument('calendarData'),
190
-				$event->getArgument('shares')
191
-			);
169
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
170
+            /** @var Backend $backend */
171
+            $backend = $this->getContainer()->query(Backend::class);
172
+            $backend->onCalendarAdd(
173
+                $event->getArgument('calendarData')
174
+            );
175
+        });
176
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
177
+            /** @var Backend $backend */
178
+            $backend = $this->getContainer()->query(Backend::class);
179
+            $backend->onCalendarUpdate(
180
+                $event->getArgument('calendarData'),
181
+                $event->getArgument('shares'),
182
+                $event->getArgument('propertyMutations')
183
+            );
184
+        });
185
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
186
+            /** @var Backend $backend */
187
+            $backend = $this->getContainer()->query(Backend::class);
188
+            $backend->onCalendarDelete(
189
+                $event->getArgument('calendarData'),
190
+                $event->getArgument('shares')
191
+            );
192 192
 
193
-			$reminderBackend = $this->getContainer()->query(ReminderBackend::class);
194
-			$reminderBackend->cleanRemindersForCalendar(
195
-				$event->getArgument('calendarId')
196
-			);
197
-		});
198
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
199
-			/** @var Backend $backend */
200
-			$backend = $this->getContainer()->query(Backend::class);
201
-			$backend->onCalendarUpdateShares(
202
-				$event->getArgument('calendarData'),
203
-				$event->getArgument('shares'),
204
-				$event->getArgument('add'),
205
-				$event->getArgument('remove')
206
-			);
193
+            $reminderBackend = $this->getContainer()->query(ReminderBackend::class);
194
+            $reminderBackend->cleanRemindersForCalendar(
195
+                $event->getArgument('calendarId')
196
+            );
197
+        });
198
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
199
+            /** @var Backend $backend */
200
+            $backend = $this->getContainer()->query(Backend::class);
201
+            $backend->onCalendarUpdateShares(
202
+                $event->getArgument('calendarData'),
203
+                $event->getArgument('shares'),
204
+                $event->getArgument('add'),
205
+                $event->getArgument('remove')
206
+            );
207 207
 
208
-			// Here we should recalculate if reminders should be sent to new or old sharees
209
-		});
208
+            // Here we should recalculate if reminders should be sent to new or old sharees
209
+        });
210 210
 
211
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
212
-			/** @var Backend $backend */
213
-			$backend = $this->getContainer()->query(Backend::class);
214
-			$backend->onCalendarPublication(
215
-				$event->getArgument('calendarData'),
216
-				$event->getArgument('public')
217
-			);
218
-		});
211
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
212
+            /** @var Backend $backend */
213
+            $backend = $this->getContainer()->query(Backend::class);
214
+            $backend->onCalendarPublication(
215
+                $event->getArgument('calendarData'),
216
+                $event->getArgument('public')
217
+            );
218
+        });
219 219
 
220
-		$listener = function (GenericEvent $event, $eventName) {
221
-			/** @var Backend $backend */
222
-			$backend = $this->getContainer()->query(Backend::class);
220
+        $listener = function (GenericEvent $event, $eventName) {
221
+            /** @var Backend $backend */
222
+            $backend = $this->getContainer()->query(Backend::class);
223 223
 
224
-			$subject = Event::SUBJECT_OBJECT_ADD;
225
-			if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
226
-				$subject = Event::SUBJECT_OBJECT_UPDATE;
227
-			} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
228
-				$subject = Event::SUBJECT_OBJECT_DELETE;
229
-			}
230
-			$backend->onTouchCalendarObject(
231
-				$subject,
232
-				$event->getArgument('calendarData'),
233
-				$event->getArgument('shares'),
234
-				$event->getArgument('objectData')
235
-			);
224
+            $subject = Event::SUBJECT_OBJECT_ADD;
225
+            if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
226
+                $subject = Event::SUBJECT_OBJECT_UPDATE;
227
+            } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
228
+                $subject = Event::SUBJECT_OBJECT_DELETE;
229
+            }
230
+            $backend->onTouchCalendarObject(
231
+                $subject,
232
+                $event->getArgument('calendarData'),
233
+                $event->getArgument('shares'),
234
+                $event->getArgument('objectData')
235
+            );
236 236
 
237
-			/** @var ReminderService $reminderBackend */
238
-			$reminderService = $this->getContainer()->query(ReminderService::class);
237
+            /** @var ReminderService $reminderBackend */
238
+            $reminderService = $this->getContainer()->query(ReminderService::class);
239 239
 
240
-			$reminderService->onTouchCalendarObject(
241
-				$eventName,
242
-				$event->getArgument('objectData')
243
-			);
244
-		};
245
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
246
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
247
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
248
-	}
240
+            $reminderService->onTouchCalendarObject(
241
+                $eventName,
242
+                $event->getArgument('objectData')
243
+            );
244
+        };
245
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
246
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
247
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
248
+    }
249 249
 
250
-	public function getSyncService() {
251
-		return $this->getContainer()->query(SyncService::class);
252
-	}
250
+    public function getSyncService() {
251
+        return $this->getContainer()->query(SyncService::class);
252
+    }
253 253
 
254
-	public function registerNotifier():void {
255
-		$this->getContainer()
256
-			->getServer()
257
-			->getNotificationManager()
258
-			->registerNotifierService(Notifier::class);
259
-	}
254
+    public function registerNotifier():void {
255
+        $this->getContainer()
256
+            ->getServer()
257
+            ->getNotificationManager()
258
+            ->registerNotifierService(Notifier::class);
259
+    }
260 260
 
261
-	public function registerCalendarReminders():void {
262
-		try {
263
-			/** @var NotificationProviderManager $notificationProviderManager */
264
-			$notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
265
-			$notificationProviderManager->registerProvider(AudioProvider::class);
266
-			$notificationProviderManager->registerProvider(EmailProvider::class);
267
-			$notificationProviderManager->registerProvider(PushProvider::class);
268
-		} catch(\Exception $ex) {
269
-			$this->getContainer()->getServer()->getLogger()->logException($ex);
270
-		}
271
-	}
261
+    public function registerCalendarReminders():void {
262
+        try {
263
+            /** @var NotificationProviderManager $notificationProviderManager */
264
+            $notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
265
+            $notificationProviderManager->registerProvider(AudioProvider::class);
266
+            $notificationProviderManager->registerProvider(EmailProvider::class);
267
+            $notificationProviderManager->registerProvider(PushProvider::class);
268
+        } catch(\Exception $ex) {
269
+            $this->getContainer()->getServer()->getLogger()->logException($ex);
270
+        }
271
+    }
272 272
 
273 273
 }
Please login to merge, or discard this patch.