Passed
Push — master ( 4a4262...32927f )
by Roeland
24:24 queued 11:41
created
lib/private/Encryption/Exceptions/EncryptionHeaderToLargeException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 use OCP\Encryption\Exceptions\GenericEncryptionException;
28 28
 
29 29
 class EncryptionHeaderToLargeException extends GenericEncryptionException {
30
-	public function __construct() {
31
-		parent::__construct('max header size exceeded');
32
-	}
30
+    public function __construct() {
31
+        parent::__construct('max header size exceeded');
32
+    }
33 33
 }
Please login to merge, or discard this patch.
lib/private/Encryption/File.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
 		// always add owner to the list of users with access to the file
74 74
 		$userIds = [$owner];
75 75
 
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
76
+		if (!$this->util->isFile($owner.'/'.$ownerPath)) {
77 77
 			return ['users' => $userIds, 'public' => false];
78 78
 		}
79 79
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -33,95 +33,95 @@
 block discarded – undo
33 33
 
34 34
 class File implements \OCP\Encryption\IFile {
35 35
 
36
-	/** @var Util */
37
-	protected $util;
38
-
39
-	/** @var IRootFolder */
40
-	private $rootFolder;
41
-
42
-	/** @var IManager */
43
-	private $shareManager;
44
-
45
-	/**
46
-	 * cache results of already checked folders
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $cache;
51
-
52
-	public function __construct(Util $util,
53
-								IRootFolder $rootFolder,
54
-								IManager $shareManager) {
55
-		$this->util = $util;
56
-		$this->cache = new CappedMemoryCache();
57
-		$this->rootFolder = $rootFolder;
58
-		$this->shareManager = $shareManager;
59
-	}
60
-
61
-
62
-	/**
63
-	 * get list of users with access to the file
64
-	 *
65
-	 * @param string $path to the file
66
-	 * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
-	 */
68
-	public function getAccessList($path) {
69
-
70
-		// Make sure that a share key is generated for the owner too
71
-		list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
-
73
-		// always add owner to the list of users with access to the file
74
-		$userIds = [$owner];
75
-
76
-		if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
-			return ['users' => $userIds, 'public' => false];
78
-		}
79
-
80
-		$ownerPath = substr($ownerPath, strlen('/files'));
81
-		$userFolder = $this->rootFolder->getUserFolder($owner);
82
-		try {
83
-			$file = $userFolder->get($ownerPath);
84
-		} catch (NotFoundException $e) {
85
-			$file = null;
86
-		}
87
-		$ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
-
89
-		// first get the shares for the parent and cache the result so that we don't
90
-		// need to check all parents for every file
91
-		$parent = dirname($ownerPath);
92
-		$parentNode = $userFolder->get($parent);
93
-		if (isset($this->cache[$parent])) {
94
-			$resultForParents = $this->cache[$parent];
95
-		} else {
96
-			$resultForParents = $this->shareManager->getAccessList($parentNode);
97
-			$this->cache[$parent] = $resultForParents;
98
-		}
99
-		$userIds = array_merge($userIds, $resultForParents['users']);
100
-		$public = $resultForParents['public'] || $resultForParents['remote'];
101
-
102
-
103
-		// Find out who, if anyone, is sharing the file
104
-		if ($file !== null) {
105
-			$resultForFile = $this->shareManager->getAccessList($file, false);
106
-			$userIds = array_merge($userIds, $resultForFile['users']);
107
-			$public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
-		}
109
-
110
-		// check if it is a group mount
111
-		if (\OCP\App::isEnabled("files_external")) {
112
-			$mounts = \OC_Mount_Config::getSystemMountPoints();
113
-			foreach ($mounts as $mount) {
114
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
-					$userIds = array_merge($userIds, $mountedFor);
117
-				}
118
-			}
119
-		}
120
-
121
-		// Remove duplicate UIDs
122
-		$uniqueUserIds = array_unique($userIds);
123
-
124
-		return ['users' => $uniqueUserIds, 'public' => $public];
125
-	}
36
+    /** @var Util */
37
+    protected $util;
38
+
39
+    /** @var IRootFolder */
40
+    private $rootFolder;
41
+
42
+    /** @var IManager */
43
+    private $shareManager;
44
+
45
+    /**
46
+     * cache results of already checked folders
47
+     *
48
+     * @var array
49
+     */
50
+    protected $cache;
51
+
52
+    public function __construct(Util $util,
53
+                                IRootFolder $rootFolder,
54
+                                IManager $shareManager) {
55
+        $this->util = $util;
56
+        $this->cache = new CappedMemoryCache();
57
+        $this->rootFolder = $rootFolder;
58
+        $this->shareManager = $shareManager;
59
+    }
60
+
61
+
62
+    /**
63
+     * get list of users with access to the file
64
+     *
65
+     * @param string $path to the file
66
+     * @return array  ['users' => $uniqueUserIds, 'public' => $public]
67
+     */
68
+    public function getAccessList($path) {
69
+
70
+        // Make sure that a share key is generated for the owner too
71
+        list($owner, $ownerPath) = $this->util->getUidAndFilename($path);
72
+
73
+        // always add owner to the list of users with access to the file
74
+        $userIds = [$owner];
75
+
76
+        if (!$this->util->isFile($owner . '/' . $ownerPath)) {
77
+            return ['users' => $userIds, 'public' => false];
78
+        }
79
+
80
+        $ownerPath = substr($ownerPath, strlen('/files'));
81
+        $userFolder = $this->rootFolder->getUserFolder($owner);
82
+        try {
83
+            $file = $userFolder->get($ownerPath);
84
+        } catch (NotFoundException $e) {
85
+            $file = null;
86
+        }
87
+        $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
88
+
89
+        // first get the shares for the parent and cache the result so that we don't
90
+        // need to check all parents for every file
91
+        $parent = dirname($ownerPath);
92
+        $parentNode = $userFolder->get($parent);
93
+        if (isset($this->cache[$parent])) {
94
+            $resultForParents = $this->cache[$parent];
95
+        } else {
96
+            $resultForParents = $this->shareManager->getAccessList($parentNode);
97
+            $this->cache[$parent] = $resultForParents;
98
+        }
99
+        $userIds = array_merge($userIds, $resultForParents['users']);
100
+        $public = $resultForParents['public'] || $resultForParents['remote'];
101
+
102
+
103
+        // Find out who, if anyone, is sharing the file
104
+        if ($file !== null) {
105
+            $resultForFile = $this->shareManager->getAccessList($file, false);
106
+            $userIds = array_merge($userIds, $resultForFile['users']);
107
+            $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
108
+        }
109
+
110
+        // check if it is a group mount
111
+        if (\OCP\App::isEnabled("files_external")) {
112
+            $mounts = \OC_Mount_Config::getSystemMountPoints();
113
+            foreach ($mounts as $mount) {
114
+                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
115
+                    $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
116
+                    $userIds = array_merge($userIds, $mountedFor);
117
+                }
118
+            }
119
+        }
120
+
121
+        // Remove duplicate UIDs
122
+        $uniqueUserIds = array_unique($userIds);
123
+
124
+        return ['users' => $uniqueUserIds, 'public' => $public];
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
lib/private/Encryption/Update.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -33,159 +33,159 @@
 block discarded – undo
33 33
  */
34 34
 class Update {
35 35
 
36
-	/** @var \OC\Files\View */
37
-	protected $view;
38
-
39
-	/** @var \OC\Encryption\Util */
40
-	protected $util;
41
-
42
-	/** @var \OC\Files\Mount\Manager */
43
-	protected $mountManager;
44
-
45
-	/** @var \OC\Encryption\Manager */
46
-	protected $encryptionManager;
47
-
48
-	/** @var string */
49
-	protected $uid;
50
-
51
-	/** @var \OC\Encryption\File */
52
-	protected $file;
53
-
54
-	/**
55
-	 *
56
-	 * @param \OC\Files\View $view
57
-	 * @param \OC\Encryption\Util $util
58
-	 * @param \OC\Files\Mount\Manager $mountManager
59
-	 * @param \OC\Encryption\Manager $encryptionManager
60
-	 * @param \OC\Encryption\File $file
61
-	 * @param string $uid
62
-	 */
63
-	public function __construct(
64
-			View $view,
65
-			Util $util,
66
-			Mount\Manager $mountManager,
67
-			Manager $encryptionManager,
68
-			File $file,
69
-			$uid
70
-		) {
71
-		$this->view = $view;
72
-		$this->util = $util;
73
-		$this->mountManager = $mountManager;
74
-		$this->encryptionManager = $encryptionManager;
75
-		$this->file = $file;
76
-		$this->uid = $uid;
77
-	}
78
-
79
-	/**
80
-	 * hook after file was shared
81
-	 *
82
-	 * @param array $params
83
-	 */
84
-	public function postShared($params) {
85
-		if ($this->encryptionManager->isEnabled()) {
86
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
-				$path = Filesystem::getPath($params['fileSource']);
88
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
90
-				$this->update($absPath);
91
-			}
92
-		}
93
-	}
94
-
95
-	/**
96
-	 * hook after file was unshared
97
-	 *
98
-	 * @param array $params
99
-	 */
100
-	public function postUnshared($params) {
101
-		if ($this->encryptionManager->isEnabled()) {
102
-			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
-				$path = Filesystem::getPath($params['fileSource']);
104
-				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
106
-				$this->update($absPath);
107
-			}
108
-		}
109
-	}
110
-
111
-	/**
112
-	 * inform encryption module that a file was restored from the trash bin,
113
-	 * e.g. to update the encryption keys
114
-	 *
115
-	 * @param array $params
116
-	 */
117
-	public function postRestore($params) {
118
-		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
-			$this->update($path);
121
-		}
122
-	}
123
-
124
-	/**
125
-	 * inform encryption module that a file was renamed,
126
-	 * e.g. to update the encryption keys
127
-	 *
128
-	 * @param array $params
129
-	 */
130
-	public function postRename($params) {
131
-		$source = $params['oldpath'];
132
-		$target = $params['newpath'];
133
-		if (
134
-			$this->encryptionManager->isEnabled() &&
135
-			dirname($source) !== dirname($target)
136
-		) {
137
-			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
139
-			$this->update($absPath);
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * get owner and path relative to data/<owner>/files
145
-	 *
146
-	 * @param string $path path to file for current user
147
-	 * @return array ['owner' => $owner, 'path' => $path]
148
-	 * @throw \InvalidArgumentException
149
-	 */
150
-	protected function getOwnerPath($path) {
151
-		$info = Filesystem::getFileInfo($path);
152
-		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
154
-		$path = $view->getPath($info->getId());
155
-		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
-		}
158
-
159
-		return [$owner, $path];
160
-	}
161
-
162
-	/**
163
-	 * notify encryption module about added/removed users from a file/folder
164
-	 *
165
-	 * @param string $path relative to data/
166
-	 * @throws Exceptions\ModuleDoesNotExistsException
167
-	 */
168
-	public function update($path) {
169
-		$encryptionModule = $this->encryptionManager->getEncryptionModule();
170
-
171
-		// if the encryption module doesn't encrypt the files on a per-user basis
172
-		// we have nothing to do here.
173
-		if ($encryptionModule->needDetailedAccessList() === false) {
174
-			return;
175
-		}
176
-
177
-		// if a folder was shared, get a list of all (sub-)folders
178
-		if ($this->view->is_dir($path)) {
179
-			$allFiles = $this->util->getAllFiles($path);
180
-		} else {
181
-			$allFiles = [$path];
182
-		}
183
-
184
-
185
-
186
-		foreach ($allFiles as $file) {
187
-			$usersSharing = $this->file->getAccessList($file);
188
-			$encryptionModule->update($file, $this->uid, $usersSharing);
189
-		}
190
-	}
36
+    /** @var \OC\Files\View */
37
+    protected $view;
38
+
39
+    /** @var \OC\Encryption\Util */
40
+    protected $util;
41
+
42
+    /** @var \OC\Files\Mount\Manager */
43
+    protected $mountManager;
44
+
45
+    /** @var \OC\Encryption\Manager */
46
+    protected $encryptionManager;
47
+
48
+    /** @var string */
49
+    protected $uid;
50
+
51
+    /** @var \OC\Encryption\File */
52
+    protected $file;
53
+
54
+    /**
55
+     *
56
+     * @param \OC\Files\View $view
57
+     * @param \OC\Encryption\Util $util
58
+     * @param \OC\Files\Mount\Manager $mountManager
59
+     * @param \OC\Encryption\Manager $encryptionManager
60
+     * @param \OC\Encryption\File $file
61
+     * @param string $uid
62
+     */
63
+    public function __construct(
64
+            View $view,
65
+            Util $util,
66
+            Mount\Manager $mountManager,
67
+            Manager $encryptionManager,
68
+            File $file,
69
+            $uid
70
+        ) {
71
+        $this->view = $view;
72
+        $this->util = $util;
73
+        $this->mountManager = $mountManager;
74
+        $this->encryptionManager = $encryptionManager;
75
+        $this->file = $file;
76
+        $this->uid = $uid;
77
+    }
78
+
79
+    /**
80
+     * hook after file was shared
81
+     *
82
+     * @param array $params
83
+     */
84
+    public function postShared($params) {
85
+        if ($this->encryptionManager->isEnabled()) {
86
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87
+                $path = Filesystem::getPath($params['fileSource']);
88
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
89
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
90
+                $this->update($absPath);
91
+            }
92
+        }
93
+    }
94
+
95
+    /**
96
+     * hook after file was unshared
97
+     *
98
+     * @param array $params
99
+     */
100
+    public function postUnshared($params) {
101
+        if ($this->encryptionManager->isEnabled()) {
102
+            if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103
+                $path = Filesystem::getPath($params['fileSource']);
104
+                list($owner, $ownerPath) = $this->getOwnerPath($path);
105
+                $absPath = '/' . $owner . '/files/' . $ownerPath;
106
+                $this->update($absPath);
107
+            }
108
+        }
109
+    }
110
+
111
+    /**
112
+     * inform encryption module that a file was restored from the trash bin,
113
+     * e.g. to update the encryption keys
114
+     *
115
+     * @param array $params
116
+     */
117
+    public function postRestore($params) {
118
+        if ($this->encryptionManager->isEnabled()) {
119
+            $path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
120
+            $this->update($path);
121
+        }
122
+    }
123
+
124
+    /**
125
+     * inform encryption module that a file was renamed,
126
+     * e.g. to update the encryption keys
127
+     *
128
+     * @param array $params
129
+     */
130
+    public function postRename($params) {
131
+        $source = $params['oldpath'];
132
+        $target = $params['newpath'];
133
+        if (
134
+            $this->encryptionManager->isEnabled() &&
135
+            dirname($source) !== dirname($target)
136
+        ) {
137
+            list($owner, $ownerPath) = $this->getOwnerPath($target);
138
+            $absPath = '/' . $owner . '/files/' . $ownerPath;
139
+            $this->update($absPath);
140
+        }
141
+    }
142
+
143
+    /**
144
+     * get owner and path relative to data/<owner>/files
145
+     *
146
+     * @param string $path path to file for current user
147
+     * @return array ['owner' => $owner, 'path' => $path]
148
+     * @throw \InvalidArgumentException
149
+     */
150
+    protected function getOwnerPath($path) {
151
+        $info = Filesystem::getFileInfo($path);
152
+        $owner = Filesystem::getOwner($path);
153
+        $view = new View('/' . $owner . '/files');
154
+        $path = $view->getPath($info->getId());
155
+        if ($path === null) {
156
+            throw new \InvalidArgumentException('No file found for ' . $info->getId());
157
+        }
158
+
159
+        return [$owner, $path];
160
+    }
161
+
162
+    /**
163
+     * notify encryption module about added/removed users from a file/folder
164
+     *
165
+     * @param string $path relative to data/
166
+     * @throws Exceptions\ModuleDoesNotExistsException
167
+     */
168
+    public function update($path) {
169
+        $encryptionModule = $this->encryptionManager->getEncryptionModule();
170
+
171
+        // if the encryption module doesn't encrypt the files on a per-user basis
172
+        // we have nothing to do here.
173
+        if ($encryptionModule->needDetailedAccessList() === false) {
174
+            return;
175
+        }
176
+
177
+        // if a folder was shared, get a list of all (sub-)folders
178
+        if ($this->view->is_dir($path)) {
179
+            $allFiles = $this->util->getAllFiles($path);
180
+        } else {
181
+            $allFiles = [$path];
182
+        }
183
+
184
+
185
+
186
+        foreach ($allFiles as $file) {
187
+            $usersSharing = $this->file->getAccessList($file);
188
+            $encryptionModule->update($file, $this->uid, $usersSharing);
189
+        }
190
+    }
191 191
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
87 87
 				$path = Filesystem::getPath($params['fileSource']);
88 88
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
89
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
89
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
90 90
 				$this->update($absPath);
91 91
 			}
92 92
 		}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {
103 103
 				$path = Filesystem::getPath($params['fileSource']);
104 104
 				list($owner, $ownerPath) = $this->getOwnerPath($path);
105
-				$absPath = '/' . $owner . '/files/' . $ownerPath;
105
+				$absPath = '/'.$owner.'/files/'.$ownerPath;
106 106
 				$this->update($absPath);
107 107
 			}
108 108
 		}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 */
117 117
 	public function postRestore($params) {
118 118
 		if ($this->encryptionManager->isEnabled()) {
119
-			$path = Filesystem::normalizePath('/' . $this->uid . '/files/' . $params['filePath']);
119
+			$path = Filesystem::normalizePath('/'.$this->uid.'/files/'.$params['filePath']);
120 120
 			$this->update($path);
121 121
 		}
122 122
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 			dirname($source) !== dirname($target)
136 136
 		) {
137 137
 			list($owner, $ownerPath) = $this->getOwnerPath($target);
138
-			$absPath = '/' . $owner . '/files/' . $ownerPath;
138
+			$absPath = '/'.$owner.'/files/'.$ownerPath;
139 139
 			$this->update($absPath);
140 140
 		}
141 141
 	}
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 	protected function getOwnerPath($path) {
151 151
 		$info = Filesystem::getFileInfo($path);
152 152
 		$owner = Filesystem::getOwner($path);
153
-		$view = new View('/' . $owner . '/files');
153
+		$view = new View('/'.$owner.'/files');
154 154
 		$path = $view->getPath($info->getId());
155 155
 		if ($path === null) {
156
-			throw new \InvalidArgumentException('No file found for ' . $info->getId());
156
+			throw new \InvalidArgumentException('No file found for '.$info->getId());
157 157
 		}
158 158
 
159 159
 		return [$owner, $path];
Please login to merge, or discard this patch.
lib/private/TempManager.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68 68
 		if ($postFix !== '') {
69
-			$postFix = '.' . ltrim($postFix, '.');
69
+			$postFix = '.'.ltrim($postFix, '.');
70 70
 			$postFix = str_replace(['\\', '/'], '', $postFix);
71 71
 			$absolutePath .= '-';
72 72
 		}
73 73
 
74
-		return $absolutePath . $postFix;
74
+		return $absolutePath.$postFix;
75 75
 	}
76 76
 
77 77
 	/**
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			$this->current[] = $uniqueFileName;
128 128
 
129 129
 			// Build a name without postfix
130
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
130
+			$path = $this->buildFileNameWithSuffix($uniqueFileName.'-folder', $postFix);
131 131
 			mkdir($path, 0700);
132 132
 			$this->current[] = $path;
133 133
 
134
-			return $path . '/';
134
+			return $path.'/';
135 135
 		} else {
136 136
 			$this->log->warning(
137 137
 				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		if ($dh) {
191 191
 			while (($file = readdir($dh)) !== false) {
192 192
 				if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
-					$path = $this->tmpBaseDir . '/' . $file;
193
+					$path = $this->tmpBaseDir.'/'.$file;
194 194
 					$mtime = filemtime($path);
195 195
 					if ($mtime < $cutOfTime) {
196 196
 						$files[] = $path;
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -35,245 +35,245 @@
 block discarded – undo
35 35
 use OCP\ITempManager;
36 36
 
37 37
 class TempManager implements ITempManager {
38
-	/** @var string[] Current temporary files and folders, used for cleanup */
39
-	protected $current = [];
40
-	/** @var string i.e. /tmp on linux systems */
41
-	protected $tmpBaseDir;
42
-	/** @var ILogger */
43
-	protected $log;
44
-	/** @var IConfig */
45
-	protected $config;
38
+    /** @var string[] Current temporary files and folders, used for cleanup */
39
+    protected $current = [];
40
+    /** @var string i.e. /tmp on linux systems */
41
+    protected $tmpBaseDir;
42
+    /** @var ILogger */
43
+    protected $log;
44
+    /** @var IConfig */
45
+    protected $config;
46 46
 
47
-	/** Prefix */
48
-	public const TMP_PREFIX = 'oc_tmp_';
47
+    /** Prefix */
48
+    public const TMP_PREFIX = 'oc_tmp_';
49 49
 
50
-	/**
51
-	 * @param \OCP\ILogger $logger
52
-	 * @param \OCP\IConfig $config
53
-	 */
54
-	public function __construct(ILogger $logger, IConfig $config) {
55
-		$this->log = $logger;
56
-		$this->config = $config;
57
-		$this->tmpBaseDir = $this->getTempBaseDir();
58
-	}
50
+    /**
51
+     * @param \OCP\ILogger $logger
52
+     * @param \OCP\IConfig $config
53
+     */
54
+    public function __construct(ILogger $logger, IConfig $config) {
55
+        $this->log = $logger;
56
+        $this->config = $config;
57
+        $this->tmpBaseDir = $this->getTempBaseDir();
58
+    }
59 59
 
60
-	/**
61
-	 * Builds the filename with suffix and removes potential dangerous characters
62
-	 * such as directory separators.
63
-	 *
64
-	 * @param string $absolutePath Absolute path to the file / folder
65
-	 * @param string $postFix Postfix appended to the temporary file name, may be user controlled
66
-	 * @return string
67
-	 */
68
-	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
69
-		if ($postFix !== '') {
70
-			$postFix = '.' . ltrim($postFix, '.');
71
-			$postFix = str_replace(['\\', '/'], '', $postFix);
72
-			$absolutePath .= '-';
73
-		}
60
+    /**
61
+     * Builds the filename with suffix and removes potential dangerous characters
62
+     * such as directory separators.
63
+     *
64
+     * @param string $absolutePath Absolute path to the file / folder
65
+     * @param string $postFix Postfix appended to the temporary file name, may be user controlled
66
+     * @return string
67
+     */
68
+    private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
69
+        if ($postFix !== '') {
70
+            $postFix = '.' . ltrim($postFix, '.');
71
+            $postFix = str_replace(['\\', '/'], '', $postFix);
72
+            $absolutePath .= '-';
73
+        }
74 74
 
75
-		return $absolutePath . $postFix;
76
-	}
75
+        return $absolutePath . $postFix;
76
+    }
77 77
 
78
-	/**
79
-	 * Create a temporary file and return the path
80
-	 *
81
-	 * @param string $postFix Postfix appended to the temporary file name
82
-	 * @return string
83
-	 */
84
-	public function getTemporaryFile($postFix = '') {
85
-		if (is_writable($this->tmpBaseDir)) {
86
-			// To create an unique file and prevent the risk of race conditions
87
-			// or duplicated temporary files by other means such as collisions
88
-			// we need to create the file using `tempnam` and append a possible
89
-			// postfix to it later
90
-			$file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
91
-			$this->current[] = $file;
78
+    /**
79
+     * Create a temporary file and return the path
80
+     *
81
+     * @param string $postFix Postfix appended to the temporary file name
82
+     * @return string
83
+     */
84
+    public function getTemporaryFile($postFix = '') {
85
+        if (is_writable($this->tmpBaseDir)) {
86
+            // To create an unique file and prevent the risk of race conditions
87
+            // or duplicated temporary files by other means such as collisions
88
+            // we need to create the file using `tempnam` and append a possible
89
+            // postfix to it later
90
+            $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
91
+            $this->current[] = $file;
92 92
 
93
-			// If a postfix got specified sanitize it and create a postfixed
94
-			// temporary file
95
-			if ($postFix !== '') {
96
-				$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
97
-				touch($fileNameWithPostfix);
98
-				chmod($fileNameWithPostfix, 0600);
99
-				$this->current[] = $fileNameWithPostfix;
100
-				return $fileNameWithPostfix;
101
-			}
93
+            // If a postfix got specified sanitize it and create a postfixed
94
+            // temporary file
95
+            if ($postFix !== '') {
96
+                $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
97
+                touch($fileNameWithPostfix);
98
+                chmod($fileNameWithPostfix, 0600);
99
+                $this->current[] = $fileNameWithPostfix;
100
+                return $fileNameWithPostfix;
101
+            }
102 102
 
103
-			return $file;
104
-		} else {
105
-			$this->log->warning(
106
-				'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
107
-				[
108
-					'dir' => $this->tmpBaseDir,
109
-				]
110
-			);
111
-			return false;
112
-		}
113
-	}
103
+            return $file;
104
+        } else {
105
+            $this->log->warning(
106
+                'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
107
+                [
108
+                    'dir' => $this->tmpBaseDir,
109
+                ]
110
+            );
111
+            return false;
112
+        }
113
+    }
114 114
 
115
-	/**
116
-	 * Create a temporary folder and return the path
117
-	 *
118
-	 * @param string $postFix Postfix appended to the temporary folder name
119
-	 * @return string
120
-	 */
121
-	public function getTemporaryFolder($postFix = '') {
122
-		if (is_writable($this->tmpBaseDir)) {
123
-			// To create an unique directory and prevent the risk of race conditions
124
-			// or duplicated temporary files by other means such as collisions
125
-			// we need to create the file using `tempnam` and append a possible
126
-			// postfix to it later
127
-			$uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
128
-			$this->current[] = $uniqueFileName;
115
+    /**
116
+     * Create a temporary folder and return the path
117
+     *
118
+     * @param string $postFix Postfix appended to the temporary folder name
119
+     * @return string
120
+     */
121
+    public function getTemporaryFolder($postFix = '') {
122
+        if (is_writable($this->tmpBaseDir)) {
123
+            // To create an unique directory and prevent the risk of race conditions
124
+            // or duplicated temporary files by other means such as collisions
125
+            // we need to create the file using `tempnam` and append a possible
126
+            // postfix to it later
127
+            $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
128
+            $this->current[] = $uniqueFileName;
129 129
 
130
-			// Build a name without postfix
131
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
132
-			mkdir($path, 0700);
133
-			$this->current[] = $path;
130
+            // Build a name without postfix
131
+            $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
132
+            mkdir($path, 0700);
133
+            $this->current[] = $path;
134 134
 
135
-			return $path . '/';
136
-		} else {
137
-			$this->log->warning(
138
-				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
139
-				[
140
-					'dir' => $this->tmpBaseDir,
141
-				]
142
-			);
143
-			return false;
144
-		}
145
-	}
135
+            return $path . '/';
136
+        } else {
137
+            $this->log->warning(
138
+                'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
139
+                [
140
+                    'dir' => $this->tmpBaseDir,
141
+                ]
142
+            );
143
+            return false;
144
+        }
145
+    }
146 146
 
147
-	/**
148
-	 * Remove the temporary files and folders generated during this request
149
-	 */
150
-	public function clean() {
151
-		$this->cleanFiles($this->current);
152
-	}
147
+    /**
148
+     * Remove the temporary files and folders generated during this request
149
+     */
150
+    public function clean() {
151
+        $this->cleanFiles($this->current);
152
+    }
153 153
 
154
-	/**
155
-	 * @param string[] $files
156
-	 */
157
-	protected function cleanFiles($files) {
158
-		foreach ($files as $file) {
159
-			if (file_exists($file)) {
160
-				try {
161
-					\OC_Helper::rmdirr($file);
162
-				} catch (\UnexpectedValueException $ex) {
163
-					$this->log->warning(
164
-						"Error deleting temporary file/folder: {file} - Reason: {error}",
165
-						[
166
-							'file' => $file,
167
-							'error' => $ex->getMessage(),
168
-						]
169
-					);
170
-				}
171
-			}
172
-		}
173
-	}
154
+    /**
155
+     * @param string[] $files
156
+     */
157
+    protected function cleanFiles($files) {
158
+        foreach ($files as $file) {
159
+            if (file_exists($file)) {
160
+                try {
161
+                    \OC_Helper::rmdirr($file);
162
+                } catch (\UnexpectedValueException $ex) {
163
+                    $this->log->warning(
164
+                        "Error deleting temporary file/folder: {file} - Reason: {error}",
165
+                        [
166
+                            'file' => $file,
167
+                            'error' => $ex->getMessage(),
168
+                        ]
169
+                    );
170
+                }
171
+            }
172
+        }
173
+    }
174 174
 
175
-	/**
176
-	 * Remove old temporary files and folders that were failed to be cleaned
177
-	 */
178
-	public function cleanOld() {
179
-		$this->cleanFiles($this->getOldFiles());
180
-	}
175
+    /**
176
+     * Remove old temporary files and folders that were failed to be cleaned
177
+     */
178
+    public function cleanOld() {
179
+        $this->cleanFiles($this->getOldFiles());
180
+    }
181 181
 
182
-	/**
183
-	 * Get all temporary files and folders generated by oc older than an hour
184
-	 *
185
-	 * @return string[]
186
-	 */
187
-	protected function getOldFiles() {
188
-		$cutOfTime = time() - 3600;
189
-		$files = [];
190
-		$dh = opendir($this->tmpBaseDir);
191
-		if ($dh) {
192
-			while (($file = readdir($dh)) !== false) {
193
-				if (substr($file, 0, 7) === self::TMP_PREFIX) {
194
-					$path = $this->tmpBaseDir . '/' . $file;
195
-					$mtime = filemtime($path);
196
-					if ($mtime < $cutOfTime) {
197
-						$files[] = $path;
198
-					}
199
-				}
200
-			}
201
-		}
202
-		return $files;
203
-	}
182
+    /**
183
+     * Get all temporary files and folders generated by oc older than an hour
184
+     *
185
+     * @return string[]
186
+     */
187
+    protected function getOldFiles() {
188
+        $cutOfTime = time() - 3600;
189
+        $files = [];
190
+        $dh = opendir($this->tmpBaseDir);
191
+        if ($dh) {
192
+            while (($file = readdir($dh)) !== false) {
193
+                if (substr($file, 0, 7) === self::TMP_PREFIX) {
194
+                    $path = $this->tmpBaseDir . '/' . $file;
195
+                    $mtime = filemtime($path);
196
+                    if ($mtime < $cutOfTime) {
197
+                        $files[] = $path;
198
+                    }
199
+                }
200
+            }
201
+        }
202
+        return $files;
203
+    }
204 204
 
205
-	/**
206
-	 * Get the temporary base directory configured on the server
207
-	 *
208
-	 * @return string Path to the temporary directory or null
209
-	 * @throws \UnexpectedValueException
210
-	 */
211
-	public function getTempBaseDir() {
212
-		if ($this->tmpBaseDir) {
213
-			return $this->tmpBaseDir;
214
-		}
205
+    /**
206
+     * Get the temporary base directory configured on the server
207
+     *
208
+     * @return string Path to the temporary directory or null
209
+     * @throws \UnexpectedValueException
210
+     */
211
+    public function getTempBaseDir() {
212
+        if ($this->tmpBaseDir) {
213
+            return $this->tmpBaseDir;
214
+        }
215 215
 
216
-		$directories = [];
217
-		if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
218
-			$directories[] = $temp;
219
-		}
220
-		if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) {
221
-			$directories[] = $temp;
222
-		}
223
-		if ($temp = getenv('TMP')) {
224
-			$directories[] = $temp;
225
-		}
226
-		if ($temp = getenv('TEMP')) {
227
-			$directories[] = $temp;
228
-		}
229
-		if ($temp = getenv('TMPDIR')) {
230
-			$directories[] = $temp;
231
-		}
232
-		if ($temp = sys_get_temp_dir()) {
233
-			$directories[] = $temp;
234
-		}
216
+        $directories = [];
217
+        if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
218
+            $directories[] = $temp;
219
+        }
220
+        if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) {
221
+            $directories[] = $temp;
222
+        }
223
+        if ($temp = getenv('TMP')) {
224
+            $directories[] = $temp;
225
+        }
226
+        if ($temp = getenv('TEMP')) {
227
+            $directories[] = $temp;
228
+        }
229
+        if ($temp = getenv('TMPDIR')) {
230
+            $directories[] = $temp;
231
+        }
232
+        if ($temp = sys_get_temp_dir()) {
233
+            $directories[] = $temp;
234
+        }
235 235
 
236
-		foreach ($directories as $dir) {
237
-			if ($this->checkTemporaryDirectory($dir)) {
238
-				return $dir;
239
-			}
240
-		}
236
+        foreach ($directories as $dir) {
237
+            if ($this->checkTemporaryDirectory($dir)) {
238
+                return $dir;
239
+            }
240
+        }
241 241
 
242
-		$temp = tempnam(dirname(__FILE__), '');
243
-		if (file_exists($temp)) {
244
-			unlink($temp);
245
-			return dirname($temp);
246
-		}
247
-		throw new \UnexpectedValueException('Unable to detect system temporary directory');
248
-	}
242
+        $temp = tempnam(dirname(__FILE__), '');
243
+        if (file_exists($temp)) {
244
+            unlink($temp);
245
+            return dirname($temp);
246
+        }
247
+        throw new \UnexpectedValueException('Unable to detect system temporary directory');
248
+    }
249 249
 
250
-	/**
251
-	 * Check if a temporary directory is ready for use
252
-	 *
253
-	 * @param mixed $directory
254
-	 * @return bool
255
-	 */
256
-	private function checkTemporaryDirectory($directory) {
257
-		// suppress any possible errors caused by is_writable
258
-		// checks missing or invalid path or characters, wrong permissions etc
259
-		try {
260
-			if (is_writable($directory)) {
261
-				return true;
262
-			}
263
-		} catch (\Exception $e) {
264
-		}
265
-		$this->log->warning('Temporary directory {dir} is not present or writable',
266
-			['dir' => $directory]
267
-		);
268
-		return false;
269
-	}
250
+    /**
251
+     * Check if a temporary directory is ready for use
252
+     *
253
+     * @param mixed $directory
254
+     * @return bool
255
+     */
256
+    private function checkTemporaryDirectory($directory) {
257
+        // suppress any possible errors caused by is_writable
258
+        // checks missing or invalid path or characters, wrong permissions etc
259
+        try {
260
+            if (is_writable($directory)) {
261
+                return true;
262
+            }
263
+        } catch (\Exception $e) {
264
+        }
265
+        $this->log->warning('Temporary directory {dir} is not present or writable',
266
+            ['dir' => $directory]
267
+        );
268
+        return false;
269
+    }
270 270
 
271
-	/**
272
-	 * Override the temporary base directory
273
-	 *
274
-	 * @param string $directory
275
-	 */
276
-	public function overrideTempBaseDir($directory) {
277
-		$this->tmpBaseDir = $directory;
278
-	}
271
+    /**
272
+     * Override the temporary base directory
273
+     *
274
+     * @param string $directory
275
+     */
276
+    public function overrideTempBaseDir($directory) {
277
+        $this->tmpBaseDir = $directory;
278
+    }
279 279
 }
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
@@ -36,54 +36,54 @@
 block discarded – undo
36 36
  * @method void setName(string $name)
37 37
  */
38 38
 class Tag extends Entity {
39
-	protected $owner;
40
-	protected $type;
41
-	protected $name;
39
+    protected $owner;
40
+    protected $type;
41
+    protected $name;
42 42
 
43
-	/**
44
-	 * Constructor.
45
-	 *
46
-	 * @param string $owner The tag's owner
47
-	 * @param string $type The type of item this tag is used for
48
-	 * @param string $name The tag's name
49
-	 */
50
-	public function __construct($owner = null, $type = null, $name = null) {
51
-		$this->setOwner($owner);
52
-		$this->setType($type);
53
-		$this->setName($name);
54
-	}
43
+    /**
44
+     * Constructor.
45
+     *
46
+     * @param string $owner The tag's owner
47
+     * @param string $type The type of item this tag is used for
48
+     * @param string $name The tag's name
49
+     */
50
+    public function __construct($owner = null, $type = null, $name = null) {
51
+        $this->setOwner($owner);
52
+        $this->setType($type);
53
+        $this->setName($name);
54
+    }
55 55
 
56
-	/**
57
-	 * Transform a database columnname to a property
58
-	 *
59
-	 * @param string $columnName the name of the column
60
-	 * @return string the property name
61
-	 * @todo migrate existing database columns to the correct names
62
-	 * to be able to drop this direct mapping
63
-	 */
64
-	public function columnToProperty($columnName) {
65
-		if ($columnName === 'category') {
66
-			return 'name';
67
-		} elseif ($columnName === 'uid') {
68
-			return 'owner';
69
-		} else {
70
-			return parent::columnToProperty($columnName);
71
-		}
72
-	}
56
+    /**
57
+     * Transform a database columnname to a property
58
+     *
59
+     * @param string $columnName the name of the column
60
+     * @return string the property name
61
+     * @todo migrate existing database columns to the correct names
62
+     * to be able to drop this direct mapping
63
+     */
64
+    public function columnToProperty($columnName) {
65
+        if ($columnName === 'category') {
66
+            return 'name';
67
+        } elseif ($columnName === 'uid') {
68
+            return 'owner';
69
+        } else {
70
+            return parent::columnToProperty($columnName);
71
+        }
72
+    }
73 73
 
74
-	/**
75
-	 * Transform a property to a database column name
76
-	 *
77
-	 * @param string $property the name of the property
78
-	 * @return string the column name
79
-	 */
80
-	public function propertyToColumn($property) {
81
-		if ($property === 'name') {
82
-			return 'category';
83
-		} elseif ($property === 'owner') {
84
-			return 'uid';
85
-		} else {
86
-			return parent::propertyToColumn($property);
87
-		}
88
-	}
74
+    /**
75
+     * Transform a property to a database column name
76
+     *
77
+     * @param string $property the name of the property
78
+     * @return string the column name
79
+     */
80
+    public function propertyToColumn($property) {
81
+        if ($property === 'name') {
82
+            return 'category';
83
+        } elseif ($property === 'owner') {
84
+            return 'uid';
85
+        } else {
86
+            return parent::propertyToColumn($property);
87
+        }
88
+    }
89 89
 }
Please login to merge, or discard this patch.
Middleware/Security/Exceptions/StrictCookieMissingException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
  * @package OC\AppFramework\Middleware\Security\Exceptions
33 33
  */
34 34
 class StrictCookieMissingException extends SecurityException {
35
-	public function __construct() {
36
-		parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
-	}
35
+    public function __construct() {
36
+        parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED);
37
+    }
38 38
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/RootCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
 		if (isset($this->entityTypeCollections[$name])) {
148 148
 			return $this->entityTypeCollections[$name];
149 149
 		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
150
+		throw new NotFound('Entity type "'.$name.'" not found."');
151 151
 	}
152 152
 
153 153
 	/**
Please login to merge, or discard this patch.
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -37,176 +37,176 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection implements ICollection {
39 39
 
40
-	/** @var EntityTypeCollection[]|null */
41
-	private $entityTypeCollections;
42
-
43
-	/** @var ICommentsManager */
44
-	protected $commentsManager;
45
-
46
-	/** @var string */
47
-	protected $name = 'comments';
48
-
49
-	/** @var ILogger */
50
-	protected $logger;
51
-
52
-	/** @var IUserManager */
53
-	protected $userManager;
54
-
55
-	/** @var IUserSession */
56
-	protected $userSession;
57
-
58
-	/** @var EventDispatcherInterface */
59
-	protected $dispatcher;
60
-
61
-	/**
62
-	 * @param ICommentsManager $commentsManager
63
-	 * @param IUserManager $userManager
64
-	 * @param IUserSession $userSession
65
-	 * @param EventDispatcherInterface $dispatcher
66
-	 * @param ILogger $logger
67
-	 */
68
-	public function __construct(
69
-		ICommentsManager $commentsManager,
70
-		IUserManager $userManager,
71
-		IUserSession $userSession,
72
-		EventDispatcherInterface $dispatcher,
73
-		ILogger $logger) {
74
-		$this->commentsManager = $commentsManager;
75
-		$this->logger = $logger;
76
-		$this->userManager = $userManager;
77
-		$this->userSession = $userSession;
78
-		$this->dispatcher = $dispatcher;
79
-	}
80
-
81
-	/**
82
-	 * initializes the collection. At this point of time, we need the logged in
83
-	 * user. Since it is not the case when the instance is created, we cannot
84
-	 * have this in the constructor.
85
-	 *
86
-	 * @throws NotAuthenticated
87
-	 */
88
-	protected function initCollections() {
89
-		if ($this->entityTypeCollections !== null) {
90
-			return;
91
-		}
92
-		$user = $this->userSession->getUser();
93
-		if (is_null($user)) {
94
-			throw new NotAuthenticated();
95
-		}
96
-
97
-		$event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
98
-		$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
99
-
100
-		$this->entityTypeCollections = [];
101
-		foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
102
-			$this->entityTypeCollections[$entity] = new EntityTypeCollection(
103
-				$entity,
104
-				$this->commentsManager,
105
-				$this->userManager,
106
-				$this->userSession,
107
-				$this->logger,
108
-				$entityExistsFunction
109
-			);
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Creates a new file in the directory
115
-	 *
116
-	 * @param string $name Name of the file
117
-	 * @param resource|string $data Initial payload
118
-	 * @return null|string
119
-	 * @throws Forbidden
120
-	 */
121
-	public function createFile($name, $data = null) {
122
-		throw new Forbidden('Cannot create comments by id');
123
-	}
124
-
125
-	/**
126
-	 * Creates a new subdirectory
127
-	 *
128
-	 * @param string $name
129
-	 * @throws Forbidden
130
-	 */
131
-	public function createDirectory($name) {
132
-		throw new Forbidden('Permission denied to create collections');
133
-	}
134
-
135
-	/**
136
-	 * Returns a specific child node, referenced by its name
137
-	 *
138
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
139
-	 * exist.
140
-	 *
141
-	 * @param string $name
142
-	 * @return \Sabre\DAV\INode
143
-	 * @throws NotFound
144
-	 */
145
-	public function getChild($name) {
146
-		$this->initCollections();
147
-		if (isset($this->entityTypeCollections[$name])) {
148
-			return $this->entityTypeCollections[$name];
149
-		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
151
-	}
152
-
153
-	/**
154
-	 * Returns an array with all the child nodes
155
-	 *
156
-	 * @return \Sabre\DAV\INode[]
157
-	 */
158
-	public function getChildren() {
159
-		$this->initCollections();
160
-		return $this->entityTypeCollections;
161
-	}
162
-
163
-	/**
164
-	 * Checks if a child-node with the specified name exists
165
-	 *
166
-	 * @param string $name
167
-	 * @return bool
168
-	 */
169
-	public function childExists($name) {
170
-		$this->initCollections();
171
-		return isset($this->entityTypeCollections[$name]);
172
-	}
173
-
174
-	/**
175
-	 * Deleted the current node
176
-	 *
177
-	 * @throws Forbidden
178
-	 */
179
-	public function delete() {
180
-		throw new Forbidden('Permission denied to delete this collection');
181
-	}
182
-
183
-	/**
184
-	 * Returns the name of the node.
185
-	 *
186
-	 * This is used to generate the url.
187
-	 *
188
-	 * @return string
189
-	 */
190
-	public function getName() {
191
-		return $this->name;
192
-	}
193
-
194
-	/**
195
-	 * Renames the node
196
-	 *
197
-	 * @param string $name The new name
198
-	 * @throws Forbidden
199
-	 */
200
-	public function setName($name) {
201
-		throw new Forbidden('Permission denied to rename this collection');
202
-	}
203
-
204
-	/**
205
-	 * Returns the last modification time, as a unix timestamp
206
-	 *
207
-	 * @return int
208
-	 */
209
-	public function getLastModified() {
210
-		return null;
211
-	}
40
+    /** @var EntityTypeCollection[]|null */
41
+    private $entityTypeCollections;
42
+
43
+    /** @var ICommentsManager */
44
+    protected $commentsManager;
45
+
46
+    /** @var string */
47
+    protected $name = 'comments';
48
+
49
+    /** @var ILogger */
50
+    protected $logger;
51
+
52
+    /** @var IUserManager */
53
+    protected $userManager;
54
+
55
+    /** @var IUserSession */
56
+    protected $userSession;
57
+
58
+    /** @var EventDispatcherInterface */
59
+    protected $dispatcher;
60
+
61
+    /**
62
+     * @param ICommentsManager $commentsManager
63
+     * @param IUserManager $userManager
64
+     * @param IUserSession $userSession
65
+     * @param EventDispatcherInterface $dispatcher
66
+     * @param ILogger $logger
67
+     */
68
+    public function __construct(
69
+        ICommentsManager $commentsManager,
70
+        IUserManager $userManager,
71
+        IUserSession $userSession,
72
+        EventDispatcherInterface $dispatcher,
73
+        ILogger $logger) {
74
+        $this->commentsManager = $commentsManager;
75
+        $this->logger = $logger;
76
+        $this->userManager = $userManager;
77
+        $this->userSession = $userSession;
78
+        $this->dispatcher = $dispatcher;
79
+    }
80
+
81
+    /**
82
+     * initializes the collection. At this point of time, we need the logged in
83
+     * user. Since it is not the case when the instance is created, we cannot
84
+     * have this in the constructor.
85
+     *
86
+     * @throws NotAuthenticated
87
+     */
88
+    protected function initCollections() {
89
+        if ($this->entityTypeCollections !== null) {
90
+            return;
91
+        }
92
+        $user = $this->userSession->getUser();
93
+        if (is_null($user)) {
94
+            throw new NotAuthenticated();
95
+        }
96
+
97
+        $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
98
+        $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
99
+
100
+        $this->entityTypeCollections = [];
101
+        foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
102
+            $this->entityTypeCollections[$entity] = new EntityTypeCollection(
103
+                $entity,
104
+                $this->commentsManager,
105
+                $this->userManager,
106
+                $this->userSession,
107
+                $this->logger,
108
+                $entityExistsFunction
109
+            );
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Creates a new file in the directory
115
+     *
116
+     * @param string $name Name of the file
117
+     * @param resource|string $data Initial payload
118
+     * @return null|string
119
+     * @throws Forbidden
120
+     */
121
+    public function createFile($name, $data = null) {
122
+        throw new Forbidden('Cannot create comments by id');
123
+    }
124
+
125
+    /**
126
+     * Creates a new subdirectory
127
+     *
128
+     * @param string $name
129
+     * @throws Forbidden
130
+     */
131
+    public function createDirectory($name) {
132
+        throw new Forbidden('Permission denied to create collections');
133
+    }
134
+
135
+    /**
136
+     * Returns a specific child node, referenced by its name
137
+     *
138
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
139
+     * exist.
140
+     *
141
+     * @param string $name
142
+     * @return \Sabre\DAV\INode
143
+     * @throws NotFound
144
+     */
145
+    public function getChild($name) {
146
+        $this->initCollections();
147
+        if (isset($this->entityTypeCollections[$name])) {
148
+            return $this->entityTypeCollections[$name];
149
+        }
150
+        throw new NotFound('Entity type "' . $name . '" not found."');
151
+    }
152
+
153
+    /**
154
+     * Returns an array with all the child nodes
155
+     *
156
+     * @return \Sabre\DAV\INode[]
157
+     */
158
+    public function getChildren() {
159
+        $this->initCollections();
160
+        return $this->entityTypeCollections;
161
+    }
162
+
163
+    /**
164
+     * Checks if a child-node with the specified name exists
165
+     *
166
+     * @param string $name
167
+     * @return bool
168
+     */
169
+    public function childExists($name) {
170
+        $this->initCollections();
171
+        return isset($this->entityTypeCollections[$name]);
172
+    }
173
+
174
+    /**
175
+     * Deleted the current node
176
+     *
177
+     * @throws Forbidden
178
+     */
179
+    public function delete() {
180
+        throw new Forbidden('Permission denied to delete this collection');
181
+    }
182
+
183
+    /**
184
+     * Returns the name of the node.
185
+     *
186
+     * This is used to generate the url.
187
+     *
188
+     * @return string
189
+     */
190
+    public function getName() {
191
+        return $this->name;
192
+    }
193
+
194
+    /**
195
+     * Renames the node
196
+     *
197
+     * @param string $name The new name
198
+     * @throws Forbidden
199
+     */
200
+    public function setName($name) {
201
+        throw new Forbidden('Permission denied to rename this collection');
202
+    }
203
+
204
+    /**
205
+     * Returns the last modification time, as a unix timestamp
206
+     *
207
+     * @return int
208
+     */
209
+    public function getLastModified() {
210
+        return null;
211
+    }
212 212
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/EntityTypeCollection.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -43,84 +43,84 @@
 block discarded – undo
43 43
  */
44 44
 class EntityTypeCollection extends RootCollection {
45 45
 
46
-	/** @var ILogger */
47
-	protected $logger;
46
+    /** @var ILogger */
47
+    protected $logger;
48 48
 
49
-	/** @var IUserManager */
50
-	protected $userManager;
49
+    /** @var IUserManager */
50
+    protected $userManager;
51 51
 
52
-	/** @var \Closure */
53
-	protected $childExistsFunction;
52
+    /** @var \Closure */
53
+    protected $childExistsFunction;
54 54
 
55
-	/**
56
-	 * @param string $name
57
-	 * @param ICommentsManager $commentsManager
58
-	 * @param IUserManager $userManager
59
-	 * @param IUserSession $userSession
60
-	 * @param ILogger $logger
61
-	 * @param \Closure $childExistsFunction
62
-	 */
63
-	public function __construct(
64
-		$name,
65
-		ICommentsManager $commentsManager,
66
-		IUserManager $userManager,
67
-		IUserSession $userSession,
68
-		ILogger $logger,
69
-		\Closure $childExistsFunction
70
-	) {
71
-		$name = trim($name);
72
-		if (empty($name) || !is_string($name)) {
73
-			throw new \InvalidArgumentException('"name" parameter must be non-empty string');
74
-		}
75
-		$this->name = $name;
76
-		$this->commentsManager = $commentsManager;
77
-		$this->logger = $logger;
78
-		$this->userManager = $userManager;
79
-		$this->userSession = $userSession;
80
-		$this->childExistsFunction = $childExistsFunction;
81
-	}
55
+    /**
56
+     * @param string $name
57
+     * @param ICommentsManager $commentsManager
58
+     * @param IUserManager $userManager
59
+     * @param IUserSession $userSession
60
+     * @param ILogger $logger
61
+     * @param \Closure $childExistsFunction
62
+     */
63
+    public function __construct(
64
+        $name,
65
+        ICommentsManager $commentsManager,
66
+        IUserManager $userManager,
67
+        IUserSession $userSession,
68
+        ILogger $logger,
69
+        \Closure $childExistsFunction
70
+    ) {
71
+        $name = trim($name);
72
+        if (empty($name) || !is_string($name)) {
73
+            throw new \InvalidArgumentException('"name" parameter must be non-empty string');
74
+        }
75
+        $this->name = $name;
76
+        $this->commentsManager = $commentsManager;
77
+        $this->logger = $logger;
78
+        $this->userManager = $userManager;
79
+        $this->userSession = $userSession;
80
+        $this->childExistsFunction = $childExistsFunction;
81
+    }
82 82
 
83
-	/**
84
-	 * Returns a specific child node, referenced by its name
85
-	 *
86
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
87
-	 * exist.
88
-	 *
89
-	 * @param string $name
90
-	 * @return \Sabre\DAV\INode
91
-	 * @throws NotFound
92
-	 */
93
-	public function getChild($name) {
94
-		if (!$this->childExists($name)) {
95
-			throw new NotFound('Entity does not exist or is not available');
96
-		}
97
-		return new EntityCollection(
98
-			$name,
99
-			$this->name,
100
-			$this->commentsManager,
101
-			$this->userManager,
102
-			$this->userSession,
103
-			$this->logger
104
-		);
105
-	}
83
+    /**
84
+     * Returns a specific child node, referenced by its name
85
+     *
86
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
87
+     * exist.
88
+     *
89
+     * @param string $name
90
+     * @return \Sabre\DAV\INode
91
+     * @throws NotFound
92
+     */
93
+    public function getChild($name) {
94
+        if (!$this->childExists($name)) {
95
+            throw new NotFound('Entity does not exist or is not available');
96
+        }
97
+        return new EntityCollection(
98
+            $name,
99
+            $this->name,
100
+            $this->commentsManager,
101
+            $this->userManager,
102
+            $this->userSession,
103
+            $this->logger
104
+        );
105
+    }
106 106
 
107
-	/**
108
-	 * Returns an array with all the child nodes
109
-	 *
110
-	 * @return \Sabre\DAV\INode[]
111
-	 * @throws MethodNotAllowed
112
-	 */
113
-	public function getChildren() {
114
-		throw new MethodNotAllowed('No permission to list folder contents');
115
-	}
107
+    /**
108
+     * Returns an array with all the child nodes
109
+     *
110
+     * @return \Sabre\DAV\INode[]
111
+     * @throws MethodNotAllowed
112
+     */
113
+    public function getChildren() {
114
+        throw new MethodNotAllowed('No permission to list folder contents');
115
+    }
116 116
 
117
-	/**
118
-	 * Checks if a child-node with the specified name exists
119
-	 *
120
-	 * @param string $name
121
-	 * @return bool
122
-	 */
123
-	public function childExists($name) {
124
-		return call_user_func($this->childExistsFunction, $name);
125
-	}
117
+    /**
118
+     * Checks if a child-node with the specified name exists
119
+     *
120
+     * @param string $name
121
+     * @return bool
122
+     */
123
+    public function childExists($name) {
124
+        return call_user_func($this->childExistsFunction, $name);
125
+    }
126 126
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/Sharing/FilesDropPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 		$path = array_pop($path);
78 78
 
79 79
 		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
80
-		$url = $request->getBaseUrl() . $newName;
80
+		$url = $request->getBaseUrl().$newName;
81 81
 		$request->setUrl($url);
82 82
 	}
83 83
 }
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -35,51 +35,51 @@
 block discarded – undo
35 35
  */
36 36
 class FilesDropPlugin extends ServerPlugin {
37 37
 
38
-	/** @var View */
39
-	private $view;
38
+    /** @var View */
39
+    private $view;
40 40
 
41
-	/** @var bool */
42
-	private $enabled = false;
41
+    /** @var bool */
42
+    private $enabled = false;
43 43
 
44
-	/**
45
-	 * @param View $view
46
-	 */
47
-	public function setView($view) {
48
-		$this->view = $view;
49
-	}
44
+    /**
45
+     * @param View $view
46
+     */
47
+    public function setView($view) {
48
+        $this->view = $view;
49
+    }
50 50
 
51
-	public function enable() {
52
-		$this->enabled = true;
53
-	}
51
+    public function enable() {
52
+        $this->enabled = true;
53
+    }
54 54
 
55 55
 
56
-	/**
57
-	 * This initializes the plugin.
58
-	 *
59
-	 * @param \Sabre\DAV\Server $server Sabre server
60
-	 *
61
-	 * @return void
62
-	 * @throws MethodNotAllowed
63
-	 */
64
-	public function initialize(\Sabre\DAV\Server $server) {
65
-		$server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
66
-		$this->enabled = false;
67
-	}
56
+    /**
57
+     * This initializes the plugin.
58
+     *
59
+     * @param \Sabre\DAV\Server $server Sabre server
60
+     *
61
+     * @return void
62
+     * @throws MethodNotAllowed
63
+     */
64
+    public function initialize(\Sabre\DAV\Server $server) {
65
+        $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
66
+        $this->enabled = false;
67
+    }
68 68
 
69
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
70
-		if (!$this->enabled) {
71
-			return;
72
-		}
69
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
70
+        if (!$this->enabled) {
71
+            return;
72
+        }
73 73
 
74
-		if ($request->getMethod() !== 'PUT') {
75
-			throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
-		}
74
+        if ($request->getMethod() !== 'PUT') {
75
+            throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
+        }
77 77
 
78
-		$path = explode('/', $request->getPath());
79
-		$path = array_pop($path);
78
+        $path = explode('/', $request->getPath());
79
+        $path = array_pop($path);
80 80
 
81
-		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
-		$url = $request->getBaseUrl() . $newName;
83
-		$request->setUrl($url);
84
-	}
81
+        $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
+        $url = $request->getBaseUrl() . $newName;
83
+        $request->setUrl($url);
84
+    }
85 85
 }
Please login to merge, or discard this patch.