Passed
Push — master ( 9f70c6...30a595 )
by John
15:26 queued 13s
created
lib/public/Security/ICrypto.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -37,31 +37,31 @@
 block discarded – undo
37 37
  */
38 38
 interface ICrypto {
39 39
 
40
-	/**
41
-	 * @param string $message The message to authenticate
42
-	 * @param string $password Password to use (defaults to `secret` in config.php)
43
-	 * @return string Calculated HMAC
44
-	 * @since 8.0.0
45
-	 */
46
-	public function calculateHMAC(string $message, string $password = ''): string;
40
+    /**
41
+     * @param string $message The message to authenticate
42
+     * @param string $password Password to use (defaults to `secret` in config.php)
43
+     * @return string Calculated HMAC
44
+     * @since 8.0.0
45
+     */
46
+    public function calculateHMAC(string $message, string $password = ''): string;
47 47
 
48
-	/**
49
-	 * Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
50
-	 * @param string $plaintext
51
-	 * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
52
-	 * @return string Authenticated ciphertext
53
-	 * @since 8.0.0
54
-	 */
55
-	public function encrypt(string $plaintext, string $password = ''): string;
48
+    /**
49
+     * Encrypts a value and adds an HMAC (Encrypt-Then-MAC)
50
+     * @param string $plaintext
51
+     * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
52
+     * @return string Authenticated ciphertext
53
+     * @since 8.0.0
54
+     */
55
+    public function encrypt(string $plaintext, string $password = ''): string;
56 56
 
57
-	/**
58
-	 * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
59
-	 * @param string $authenticatedCiphertext
60
-	 * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
61
-	 * @return string plaintext
62
-	 * @throws \Exception If the HMAC does not match
63
-	 * @throws \Exception If the decryption failed
64
-	 * @since 8.0.0
65
-	 */
66
-	public function decrypt(string $authenticatedCiphertext, string $password = ''): string;
57
+    /**
58
+     * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac)
59
+     * @param string $authenticatedCiphertext
60
+     * @param string $password Password to encrypt, if not specified the secret from config.php will be taken
61
+     * @return string plaintext
62
+     * @throws \Exception If the HMAC does not match
63
+     * @throws \Exception If the decryption failed
64
+     * @since 8.0.0
65
+     */
66
+    public function decrypt(string $authenticatedCiphertext, string $password = ''): string;
67 67
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/Version1008Date20181114084440.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -33,27 +33,27 @@
 block discarded – undo
33 33
 class Version1008Date20181114084440 extends SimpleMigrationStep {
34 34
 
35 35
 
36
-	/**
37
-	 * @param IOutput $output
38
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
-	 * @param array $options
40
-	 * @return null|ISchemaWrapper
41
-	 */
42
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
43
-		/** @var ISchemaWrapper $schema */
44
-		$schema = $schemaClosure();
45
-
46
-		if ($schema->hasTable('calendarchanges')) {
47
-			$calendarChangesTable = $schema->getTable('calendarchanges');
48
-			if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) {
49
-				$calendarChangesTable->dropIndex('calendarid_calendartype_synctoken');
50
-			}
51
-
52
-			if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) {
53
-				$calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken');
54
-			}
55
-		}
56
-
57
-		return $schema;
58
-	}
36
+    /**
37
+     * @param IOutput $output
38
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
+     * @param array $options
40
+     * @return null|ISchemaWrapper
41
+     */
42
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
43
+        /** @var ISchemaWrapper $schema */
44
+        $schema = $schemaClosure();
45
+
46
+        if ($schema->hasTable('calendarchanges')) {
47
+            $calendarChangesTable = $schema->getTable('calendarchanges');
48
+            if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) {
49
+                $calendarChangesTable->dropIndex('calendarid_calendartype_synctoken');
50
+            }
51
+
52
+            if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) {
53
+                $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken');
54
+            }
55
+        }
56
+
57
+        return $schema;
58
+    }
59 59
 }
Please login to merge, or discard this patch.
lib/public/Authentication/TwoFactorAuth/IActivatableByAdmin.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,15 +37,15 @@
 block discarded – undo
37 37
  */
38 38
 interface IActivatableByAdmin extends IProvider {
39 39
 
40
-	/**
41
-	 * Enable this provider for the given user.
42
-	 *
43
-	 * @param IUser $user the user to activate this provider for
44
-	 *
45
-	 * @return void
46
-	 *
47
-	 * @since 15.0.0
48
-	 */
49
-	public function enableFor(IUser $user);
40
+    /**
41
+     * Enable this provider for the given user.
42
+     *
43
+     * @param IUser $user the user to activate this provider for
44
+     *
45
+     * @return void
46
+     *
47
+     * @since 15.0.0
48
+     */
49
+    public function enableFor(IUser $user);
50 50
 
51 51
 }
Please login to merge, or discard this patch.
lib/public/Authentication/TwoFactorAuth/IDeactivatableByAdmin.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -37,15 +37,15 @@
 block discarded – undo
37 37
  */
38 38
 interface IDeactivatableByAdmin extends IProvider {
39 39
 
40
-	/**
41
-	 * Disable this provider for the given user.
42
-	 *
43
-	 * @param IUser $user the user to deactivate this provider for
44
-	 *
45
-	 * @return void
46
-	 *
47
-	 * @since 15.0.0
48
-	 */
49
-	public function disableFor(IUser $user);
40
+    /**
41
+     * Disable this provider for the given user.
42
+     *
43
+     * @param IUser $user the user to deactivate this provider for
44
+     *
45
+     * @return void
46
+     *
47
+     * @since 15.0.0
48
+     */
49
+    public function disableFor(IUser $user);
50 50
 
51 51
 }
Please login to merge, or discard this patch.
lib/private/RichObjectStrings/Validator.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -38,87 +38,87 @@
 block discarded – undo
38 38
  */
39 39
 class Validator implements IValidator {
40 40
 
41
-	/** @var Definitions */
42
-	protected $definitions;
43
-
44
-	/** @var array[] */
45
-	protected $requiredParameters = [];
46
-
47
-	/**
48
-	 * Constructor
49
-	 *
50
-	 * @param Definitions $definitions
51
-	 */
52
-	public function __construct(Definitions $definitions) {
53
-		$this->definitions = $definitions;
54
-	}
55
-
56
-	/**
57
-	 * @param string $subject
58
-	 * @param array[] $parameters
59
-	 * @throws InvalidObjectExeption
60
-	 * @since 11.0.0
61
-	 */
62
-	public function validate($subject, array $parameters) {
63
-		$matches = [];
64
-		$result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches);
65
-
66
-		if ($result === false) {
67
-			throw new InvalidObjectExeption();
68
-		}
69
-
70
-		if (!empty($matches[1])) {
71
-			foreach ($matches[1] as $parameter) {
72
-				if (!isset($parameters[$parameter])) {
73
-					throw new InvalidObjectExeption('Parameter is undefined');
74
-				}
75
-			}
76
-		}
77
-
78
-		foreach ($parameters as $parameter) {
79
-			if (!\is_array($parameter)) {
80
-				throw new InvalidObjectExeption('Parameter is malformed');
81
-			}
82
-
83
-			$this->validateParameter($parameter);
84
-		}
85
-	}
86
-
87
-	/**
88
-	 * @param array $parameter
89
-	 * @throws InvalidObjectExeption
90
-	 */
91
-	protected function validateParameter(array $parameter) {
92
-		if (!isset($parameter['type'])) {
93
-			throw new InvalidObjectExeption('Object type is undefined');
94
-		}
95
-
96
-		$definition = $this->definitions->getDefinition($parameter['type']);
97
-		$requiredParameters = $this->getRequiredParameters($parameter['type'], $definition);
98
-
99
-		$missingKeys = array_diff($requiredParameters, array_keys($parameter));
100
-		if (!empty($missingKeys)) {
101
-			throw new InvalidObjectExeption('Object is invalid');
102
-		}
103
-	}
104
-
105
-	/**
106
-	 * @param string $type
107
-	 * @param array $definition
108
-	 * @return string[]
109
-	 */
110
-	protected function getRequiredParameters($type, array $definition) {
111
-		if (isset($this->requiredParameters[$type])) {
112
-			return $this->requiredParameters[$type];
113
-		}
114
-
115
-		$this->requiredParameters[$type] = [];
116
-		foreach ($definition['parameters'] as $parameter => $data) {
117
-			if ($data['required']) {
118
-				$this->requiredParameters[$type][] = $parameter;
119
-			}
120
-		}
121
-
122
-		return $this->requiredParameters[$type];
123
-	}
41
+    /** @var Definitions */
42
+    protected $definitions;
43
+
44
+    /** @var array[] */
45
+    protected $requiredParameters = [];
46
+
47
+    /**
48
+     * Constructor
49
+     *
50
+     * @param Definitions $definitions
51
+     */
52
+    public function __construct(Definitions $definitions) {
53
+        $this->definitions = $definitions;
54
+    }
55
+
56
+    /**
57
+     * @param string $subject
58
+     * @param array[] $parameters
59
+     * @throws InvalidObjectExeption
60
+     * @since 11.0.0
61
+     */
62
+    public function validate($subject, array $parameters) {
63
+        $matches = [];
64
+        $result = preg_match_all('/\{([a-z0-9]+)\}/i', $subject, $matches);
65
+
66
+        if ($result === false) {
67
+            throw new InvalidObjectExeption();
68
+        }
69
+
70
+        if (!empty($matches[1])) {
71
+            foreach ($matches[1] as $parameter) {
72
+                if (!isset($parameters[$parameter])) {
73
+                    throw new InvalidObjectExeption('Parameter is undefined');
74
+                }
75
+            }
76
+        }
77
+
78
+        foreach ($parameters as $parameter) {
79
+            if (!\is_array($parameter)) {
80
+                throw new InvalidObjectExeption('Parameter is malformed');
81
+            }
82
+
83
+            $this->validateParameter($parameter);
84
+        }
85
+    }
86
+
87
+    /**
88
+     * @param array $parameter
89
+     * @throws InvalidObjectExeption
90
+     */
91
+    protected function validateParameter(array $parameter) {
92
+        if (!isset($parameter['type'])) {
93
+            throw new InvalidObjectExeption('Object type is undefined');
94
+        }
95
+
96
+        $definition = $this->definitions->getDefinition($parameter['type']);
97
+        $requiredParameters = $this->getRequiredParameters($parameter['type'], $definition);
98
+
99
+        $missingKeys = array_diff($requiredParameters, array_keys($parameter));
100
+        if (!empty($missingKeys)) {
101
+            throw new InvalidObjectExeption('Object is invalid');
102
+        }
103
+    }
104
+
105
+    /**
106
+     * @param string $type
107
+     * @param array $definition
108
+     * @return string[]
109
+     */
110
+    protected function getRequiredParameters($type, array $definition) {
111
+        if (isset($this->requiredParameters[$type])) {
112
+            return $this->requiredParameters[$type];
113
+        }
114
+
115
+        $this->requiredParameters[$type] = [];
116
+        foreach ($definition['parameters'] as $parameter => $data) {
117
+            if ($data['required']) {
118
+                $this->requiredParameters[$type][] = $parameter;
119
+            }
120
+        }
121
+
122
+        return $this->requiredParameters[$type];
123
+    }
124 124
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Migration/Version010401Date20181207190718.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -31,68 +31,68 @@
 block discarded – undo
31 31
 
32 32
 class Version010401Date20181207190718 extends SimpleMigrationStep {
33 33
 
34
-	/**
35
-	 * @param IOutput $output
36
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
-	 * @param array $options
38
-	 * @return null|ISchemaWrapper
39
-	 */
40
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
41
-		/** @var ISchemaWrapper $schema */
42
-		$schema = $schemaClosure();
34
+    /**
35
+     * @param IOutput $output
36
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
37
+     * @param array $options
38
+     * @return null|ISchemaWrapper
39
+     */
40
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
41
+        /** @var ISchemaWrapper $schema */
42
+        $schema = $schemaClosure();
43 43
 
44
-		if (!$schema->hasTable('oauth2_clients')) {
45
-			$table = $schema->createTable('oauth2_clients');
46
-			$table->addColumn('id', 'integer', [
47
-				'autoincrement' => true,
48
-				'notnull' => true,
49
-				'unsigned' => true,
50
-			]);
51
-			$table->addColumn('name', 'string', [
52
-				'notnull' => true,
53
-				'length' => 64,
54
-			]);
55
-			$table->addColumn('redirect_uri', 'string', [
56
-				'notnull' => true,
57
-				'length' => 2000,
58
-			]);
59
-			$table->addColumn('client_identifier', 'string', [
60
-				'notnull' => true,
61
-				'length' => 64,
62
-			]);
63
-			$table->addColumn('secret', 'string', [
64
-				'notnull' => true,
65
-				'length' => 64,
66
-			]);
67
-			$table->setPrimaryKey(['id']);
68
-			$table->addIndex(['client_identifier'], 'oauth2_client_id_idx');
69
-		}
44
+        if (!$schema->hasTable('oauth2_clients')) {
45
+            $table = $schema->createTable('oauth2_clients');
46
+            $table->addColumn('id', 'integer', [
47
+                'autoincrement' => true,
48
+                'notnull' => true,
49
+                'unsigned' => true,
50
+            ]);
51
+            $table->addColumn('name', 'string', [
52
+                'notnull' => true,
53
+                'length' => 64,
54
+            ]);
55
+            $table->addColumn('redirect_uri', 'string', [
56
+                'notnull' => true,
57
+                'length' => 2000,
58
+            ]);
59
+            $table->addColumn('client_identifier', 'string', [
60
+                'notnull' => true,
61
+                'length' => 64,
62
+            ]);
63
+            $table->addColumn('secret', 'string', [
64
+                'notnull' => true,
65
+                'length' => 64,
66
+            ]);
67
+            $table->setPrimaryKey(['id']);
68
+            $table->addIndex(['client_identifier'], 'oauth2_client_id_idx');
69
+        }
70 70
 
71
-		if (!$schema->hasTable('oauth2_access_tokens')) {
72
-			$table = $schema->createTable('oauth2_access_tokens');
73
-			$table->addColumn('id', 'integer', [
74
-				'autoincrement' => true,
75
-				'notnull' => true,
76
-				'unsigned' => true,
77
-			]);
78
-			$table->addColumn('token_id', 'integer', [
79
-				'notnull' => true,
80
-			]);
81
-			$table->addColumn('client_id', 'integer', [
82
-				'notnull' => true,
83
-			]);
84
-			$table->addColumn('hashed_code', 'string', [
85
-				'notnull' => true,
86
-				'length' => 128,
87
-			]);
88
-			$table->addColumn('encrypted_token', 'string', [
89
-				'notnull' => true,
90
-				'length' => 786,
91
-			]);
92
-			$table->setPrimaryKey(['id']);
93
-			$table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
94
-			$table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
95
-		}
96
-		return $schema;
97
-	}
71
+        if (!$schema->hasTable('oauth2_access_tokens')) {
72
+            $table = $schema->createTable('oauth2_access_tokens');
73
+            $table->addColumn('id', 'integer', [
74
+                'autoincrement' => true,
75
+                'notnull' => true,
76
+                'unsigned' => true,
77
+            ]);
78
+            $table->addColumn('token_id', 'integer', [
79
+                'notnull' => true,
80
+            ]);
81
+            $table->addColumn('client_id', 'integer', [
82
+                'notnull' => true,
83
+            ]);
84
+            $table->addColumn('hashed_code', 'string', [
85
+                'notnull' => true,
86
+                'length' => 128,
87
+            ]);
88
+            $table->addColumn('encrypted_token', 'string', [
89
+                'notnull' => true,
90
+                'length' => 786,
91
+            ]);
92
+            $table->setPrimaryKey(['id']);
93
+            $table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
94
+            $table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
95
+        }
96
+        return $schema;
97
+    }
98 98
 }
Please login to merge, or discard this patch.
lib/private/Files/AppData/AppData.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 			throw new \RuntimeException('no instance id!');
76 76
 		}
77 77
 
78
-		return 'appdata_' . $instanceId;
78
+		return 'appdata_'.$instanceId;
79 79
 	}
80 80
 
81 81
 	private function getAppDataRootFolder(): Folder {
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 			$name = $this->getAppDataFolderName();
104 104
 
105 105
 			try {
106
-				$this->folder = $this->rootFolder->get($name . '/' . $this->appId);
106
+				$this->folder = $this->rootFolder->get($name.'/'.$this->appId);
107 107
 			} catch (NotFoundException $e) {
108 108
 				$appDataRootFolder = $this->getAppDataRootFolder();
109 109
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 					try {
114 114
 						$this->folder = $appDataRootFolder->newFolder($this->appId);
115 115
 					} catch (NotPermittedException $e) {
116
-						throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
116
+						throw new \RuntimeException('Could not get appdata folder for '.$this->appId);
117 117
 					}
118 118
 				}
119 119
 			}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	}
124 124
 
125 125
 	public function getFolder(string $name): ISimpleFolder {
126
-		$key = $this->appId . '/' . $name;
126
+		$key = $this->appId.'/'.$name;
127 127
 		if ($cachedFolder = $this->folders->get($key)) {
128 128
 			if ($cachedFolder instanceof \Exception) {
129 129
 				throw $cachedFolder;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 			if ($name === '/') {
137 137
 				$node = $this->getAppDataFolder();
138 138
 			} else {
139
-				$path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name;
139
+				$path = $this->getAppDataFolderName().'/'.$this->appId.'/'.$name;
140 140
 				$node = $this->rootFolder->get($path);
141 141
 			}
142 142
 		} catch (NotFoundException $e) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	}
152 152
 
153 153
 	public function newFolder(string $name): ISimpleFolder {
154
-		$key = $this->appId . '/' . $name;
154
+		$key = $this->appId.'/'.$name;
155 155
 		$folder = $this->getAppDataFolder()->newFolder($name);
156 156
 
157 157
 		$simpleFolder = new SimpleFolder($folder);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	public function getDirectoryListing(): array {
163 163
 		$listing = $this->getAppDataFolder()->getDirectoryListing();
164 164
 
165
-		$fileListing = array_map(function (Node $folder) {
165
+		$fileListing = array_map(function(Node $folder) {
166 166
 			if ($folder instanceof Folder) {
167 167
 				return new SimpleFolder($folder);
168 168
 			}
Please login to merge, or discard this patch.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -40,143 +40,143 @@
 block discarded – undo
40 40
 
41 41
 class AppData implements IAppData {
42 42
 
43
-	/** @var IRootFolder */
44
-	private $rootFolder;
45
-
46
-	/** @var SystemConfig */
47
-	private $config;
48
-
49
-	/** @var string */
50
-	private $appId;
51
-
52
-	/** @var Folder */
53
-	private $folder;
54
-
55
-	/** @var (ISimpleFolder|NotFoundException)[]|CappedMemoryCache */
56
-	private $folders;
57
-
58
-	/**
59
-	 * AppData constructor.
60
-	 *
61
-	 * @param IRootFolder $rootFolder
62
-	 * @param SystemConfig $systemConfig
63
-	 * @param string $appId
64
-	 */
65
-	public function __construct(IRootFolder $rootFolder,
66
-								SystemConfig $systemConfig,
67
-								string $appId) {
68
-		$this->rootFolder = $rootFolder;
69
-		$this->config = $systemConfig;
70
-		$this->appId = $appId;
71
-		$this->folders = new CappedMemoryCache();
72
-	}
73
-
74
-	private function getAppDataFolderName() {
75
-		$instanceId = $this->config->getValue('instanceid', null);
76
-		if ($instanceId === null) {
77
-			throw new \RuntimeException('no instance id!');
78
-		}
79
-
80
-		return 'appdata_' . $instanceId;
81
-	}
82
-
83
-	private function getAppDataRootFolder(): Folder {
84
-		$name = $this->getAppDataFolderName();
85
-
86
-		try {
87
-			/** @var Folder $node */
88
-			$node = $this->rootFolder->get($name);
89
-			return $node;
90
-		} catch (NotFoundException $e) {
91
-			try {
92
-				return $this->rootFolder->newFolder($name);
93
-			} catch (NotPermittedException $e) {
94
-				throw new \RuntimeException('Could not get appdata folder');
95
-			}
96
-		}
97
-	}
98
-
99
-	/**
100
-	 * @return Folder
101
-	 * @throws \RuntimeException
102
-	 */
103
-	private function getAppDataFolder(): Folder {
104
-		if ($this->folder === null) {
105
-			$name = $this->getAppDataFolderName();
106
-
107
-			try {
108
-				$this->folder = $this->rootFolder->get($name . '/' . $this->appId);
109
-			} catch (NotFoundException $e) {
110
-				$appDataRootFolder = $this->getAppDataRootFolder();
111
-
112
-				try {
113
-					$this->folder = $appDataRootFolder->get($this->appId);
114
-				} catch (NotFoundException $e) {
115
-					try {
116
-						$this->folder = $appDataRootFolder->newFolder($this->appId);
117
-					} catch (NotPermittedException $e) {
118
-						throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
119
-					}
120
-				}
121
-			}
122
-		}
123
-
124
-		return $this->folder;
125
-	}
126
-
127
-	public function getFolder(string $name): ISimpleFolder {
128
-		$key = $this->appId . '/' . $name;
129
-		if ($cachedFolder = $this->folders->get($key)) {
130
-			if ($cachedFolder instanceof \Exception) {
131
-				throw $cachedFolder;
132
-			} else {
133
-				return $cachedFolder;
134
-			}
135
-		}
136
-		try {
137
-			// Hardening if somebody wants to retrieve '/'
138
-			if ($name === '/') {
139
-				$node = $this->getAppDataFolder();
140
-			} else {
141
-				$path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name;
142
-				$node = $this->rootFolder->get($path);
143
-			}
144
-		} catch (NotFoundException $e) {
145
-			$this->folders->set($key, $e);
146
-			throw $e;
147
-		}
148
-
149
-		/** @var Folder $node */
150
-		$folder = new SimpleFolder($node);
151
-		$this->folders->set($key, $folder);
152
-		return $folder;
153
-	}
154
-
155
-	public function newFolder(string $name): ISimpleFolder {
156
-		$key = $this->appId . '/' . $name;
157
-		$folder = $this->getAppDataFolder()->newFolder($name);
158
-
159
-		$simpleFolder = new SimpleFolder($folder);
160
-		$this->folders->set($key, $simpleFolder);
161
-		return $simpleFolder;
162
-	}
163
-
164
-	public function getDirectoryListing(): array {
165
-		$listing = $this->getAppDataFolder()->getDirectoryListing();
166
-
167
-		$fileListing = array_map(function (Node $folder) {
168
-			if ($folder instanceof Folder) {
169
-				return new SimpleFolder($folder);
170
-			}
171
-			return null;
172
-		}, $listing);
173
-
174
-		$fileListing = array_filter($fileListing);
175
-
176
-		return array_values($fileListing);
177
-	}
178
-
179
-	public function getId(): int {
180
-		return $this->getAppDataFolder()->getId();
181
-	}
43
+    /** @var IRootFolder */
44
+    private $rootFolder;
45
+
46
+    /** @var SystemConfig */
47
+    private $config;
48
+
49
+    /** @var string */
50
+    private $appId;
51
+
52
+    /** @var Folder */
53
+    private $folder;
54
+
55
+    /** @var (ISimpleFolder|NotFoundException)[]|CappedMemoryCache */
56
+    private $folders;
57
+
58
+    /**
59
+     * AppData constructor.
60
+     *
61
+     * @param IRootFolder $rootFolder
62
+     * @param SystemConfig $systemConfig
63
+     * @param string $appId
64
+     */
65
+    public function __construct(IRootFolder $rootFolder,
66
+                                SystemConfig $systemConfig,
67
+                                string $appId) {
68
+        $this->rootFolder = $rootFolder;
69
+        $this->config = $systemConfig;
70
+        $this->appId = $appId;
71
+        $this->folders = new CappedMemoryCache();
72
+    }
73
+
74
+    private function getAppDataFolderName() {
75
+        $instanceId = $this->config->getValue('instanceid', null);
76
+        if ($instanceId === null) {
77
+            throw new \RuntimeException('no instance id!');
78
+        }
79
+
80
+        return 'appdata_' . $instanceId;
81
+    }
82
+
83
+    private function getAppDataRootFolder(): Folder {
84
+        $name = $this->getAppDataFolderName();
85
+
86
+        try {
87
+            /** @var Folder $node */
88
+            $node = $this->rootFolder->get($name);
89
+            return $node;
90
+        } catch (NotFoundException $e) {
91
+            try {
92
+                return $this->rootFolder->newFolder($name);
93
+            } catch (NotPermittedException $e) {
94
+                throw new \RuntimeException('Could not get appdata folder');
95
+            }
96
+        }
97
+    }
98
+
99
+    /**
100
+     * @return Folder
101
+     * @throws \RuntimeException
102
+     */
103
+    private function getAppDataFolder(): Folder {
104
+        if ($this->folder === null) {
105
+            $name = $this->getAppDataFolderName();
106
+
107
+            try {
108
+                $this->folder = $this->rootFolder->get($name . '/' . $this->appId);
109
+            } catch (NotFoundException $e) {
110
+                $appDataRootFolder = $this->getAppDataRootFolder();
111
+
112
+                try {
113
+                    $this->folder = $appDataRootFolder->get($this->appId);
114
+                } catch (NotFoundException $e) {
115
+                    try {
116
+                        $this->folder = $appDataRootFolder->newFolder($this->appId);
117
+                    } catch (NotPermittedException $e) {
118
+                        throw new \RuntimeException('Could not get appdata folder for ' . $this->appId);
119
+                    }
120
+                }
121
+            }
122
+        }
123
+
124
+        return $this->folder;
125
+    }
126
+
127
+    public function getFolder(string $name): ISimpleFolder {
128
+        $key = $this->appId . '/' . $name;
129
+        if ($cachedFolder = $this->folders->get($key)) {
130
+            if ($cachedFolder instanceof \Exception) {
131
+                throw $cachedFolder;
132
+            } else {
133
+                return $cachedFolder;
134
+            }
135
+        }
136
+        try {
137
+            // Hardening if somebody wants to retrieve '/'
138
+            if ($name === '/') {
139
+                $node = $this->getAppDataFolder();
140
+            } else {
141
+                $path = $this->getAppDataFolderName() . '/' . $this->appId . '/' . $name;
142
+                $node = $this->rootFolder->get($path);
143
+            }
144
+        } catch (NotFoundException $e) {
145
+            $this->folders->set($key, $e);
146
+            throw $e;
147
+        }
148
+
149
+        /** @var Folder $node */
150
+        $folder = new SimpleFolder($node);
151
+        $this->folders->set($key, $folder);
152
+        return $folder;
153
+    }
154
+
155
+    public function newFolder(string $name): ISimpleFolder {
156
+        $key = $this->appId . '/' . $name;
157
+        $folder = $this->getAppDataFolder()->newFolder($name);
158
+
159
+        $simpleFolder = new SimpleFolder($folder);
160
+        $this->folders->set($key, $simpleFolder);
161
+        return $simpleFolder;
162
+    }
163
+
164
+    public function getDirectoryListing(): array {
165
+        $listing = $this->getAppDataFolder()->getDirectoryListing();
166
+
167
+        $fileListing = array_map(function (Node $folder) {
168
+            if ($folder instanceof Folder) {
169
+                return new SimpleFolder($folder);
170
+            }
171
+            return null;
172
+        }, $listing);
173
+
174
+        $fileListing = array_filter($fileListing);
175
+
176
+        return array_values($fileListing);
177
+    }
178
+
179
+    public function getId(): int {
180
+        return $this->getAppDataFolder()->getId();
181
+    }
182 182
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Command/ShowRemnants.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,8 +89,8 @@
 block discarded – undo
89 89
 				'displayName' => $user->getDisplayName(),
90 90
 				'uid' => $user->getUID(),
91 91
 				'dn' => $user->getDN(),
92
-				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
93
-				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
92
+				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool) $input->getOption('short-date')),
93
+				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool) $input->getOption('short-date')),
94 94
 				'homePath' => $user->getHomePath(),
95 95
 				'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
96 96
 			];
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,73 +36,73 @@
 block discarded – undo
36 36
 use Symfony\Component\Console\Output\OutputInterface;
37 37
 
38 38
 class ShowRemnants extends Command {
39
-	/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
-	protected $dui;
39
+    /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
+    protected $dui;
41 41
 
42
-	/** @var \OCP\IDateTimeFormatter */
43
-	protected $dateFormatter;
42
+    /** @var \OCP\IDateTimeFormatter */
43
+    protected $dateFormatter;
44 44
 
45
-	/**
46
-	 * @param DeletedUsersIndex $dui
47
-	 * @param IDateTimeFormatter $dateFormatter
48
-	 */
49
-	public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
-		$this->dui = $dui;
51
-		$this->dateFormatter = $dateFormatter;
52
-		parent::__construct();
53
-	}
45
+    /**
46
+     * @param DeletedUsersIndex $dui
47
+     * @param IDateTimeFormatter $dateFormatter
48
+     */
49
+    public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
+        $this->dui = $dui;
51
+        $this->dateFormatter = $dateFormatter;
52
+        parent::__construct();
53
+    }
54 54
 
55
-	protected function configure() {
56
-		$this
57
-			->setName('ldap:show-remnants')
58
-			->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
-			->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
-			->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
-	}
55
+    protected function configure() {
56
+        $this
57
+            ->setName('ldap:show-remnants')
58
+            ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
+            ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
+            ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
+    }
62 62
 
63
-	protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
-		if (!($timestamp > 0)) {
65
-			return $default;
66
-		}
67
-		if ($showShortDate) {
68
-			return date('Y-m-d', $timestamp);
69
-		}
70
-		return $this->dateFormatter->formatDate($timestamp);
71
-	}
63
+    protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
+        if (!($timestamp > 0)) {
65
+            return $default;
66
+        }
67
+        if ($showShortDate) {
68
+            return date('Y-m-d', $timestamp);
69
+        }
70
+        return $this->dateFormatter->formatDate($timestamp);
71
+    }
72 72
 
73
-	/**
74
-	 * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
-	 *
76
-	 * {@inheritdoc}
77
-	 */
78
-	protected function execute(InputInterface $input, OutputInterface $output): int {
79
-		/** @var \Symfony\Component\Console\Helper\Table $table */
80
-		$table = new Table($output);
81
-		$table->setHeaders([
82
-			'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
-			'Detected on', 'Dir', 'Sharer'
84
-		]);
85
-		$rows = [];
86
-		$resultSet = $this->dui->getUsers();
87
-		foreach ($resultSet as $user) {
88
-			$rows[] = [
89
-				'ocName' => $user->getOCName(),
90
-				'displayName' => $user->getDisplayName(),
91
-				'uid' => $user->getUID(),
92
-				'dn' => $user->getDN(),
93
-				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
-				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
-				'homePath' => $user->getHomePath(),
96
-				'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
-			];
98
-		}
73
+    /**
74
+     * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
+     *
76
+     * {@inheritdoc}
77
+     */
78
+    protected function execute(InputInterface $input, OutputInterface $output): int {
79
+        /** @var \Symfony\Component\Console\Helper\Table $table */
80
+        $table = new Table($output);
81
+        $table->setHeaders([
82
+            'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
+            'Detected on', 'Dir', 'Sharer'
84
+        ]);
85
+        $rows = [];
86
+        $resultSet = $this->dui->getUsers();
87
+        foreach ($resultSet as $user) {
88
+            $rows[] = [
89
+                'ocName' => $user->getOCName(),
90
+                'displayName' => $user->getDisplayName(),
91
+                'uid' => $user->getUID(),
92
+                'dn' => $user->getDN(),
93
+                'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
+                'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
+                'homePath' => $user->getHomePath(),
96
+                'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
+            ];
98
+        }
99 99
 
100
-		if ($input->getOption('json')) {
101
-			$output->writeln(json_encode($rows));
102
-		} else {
103
-			$table->setRows($rows);
104
-			$table->render();
105
-		}
106
-		return 0;
107
-	}
100
+        if ($input->getOption('json')) {
101
+            $output->writeln(json_encode($rows));
102
+        } else {
103
+            $table->setRows($rows);
104
+            $table->render();
105
+        }
106
+        return 0;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/ChunkCleanup.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -37,59 +37,59 @@
 block discarded – undo
37 37
 
38 38
 class ChunkCleanup implements IRepairStep {
39 39
 
40
-	/** @var IConfig */
41
-	private $config;
42
-	/** @var IUserManager */
43
-	private $userManager;
44
-	/** @var IRootFolder */
45
-	private $rootFolder;
46
-	/** @var IJobList */
47
-	private $jobList;
40
+    /** @var IConfig */
41
+    private $config;
42
+    /** @var IUserManager */
43
+    private $userManager;
44
+    /** @var IRootFolder */
45
+    private $rootFolder;
46
+    /** @var IJobList */
47
+    private $jobList;
48 48
 
49
-	public function __construct(IConfig $config,
50
-								IUserManager $userManager,
51
-								IRootFolder $rootFolder,
52
-								IJobList $jobList) {
53
-		$this->config = $config;
54
-		$this->userManager = $userManager;
55
-		$this->rootFolder = $rootFolder;
56
-		$this->jobList = $jobList;
57
-	}
49
+    public function __construct(IConfig $config,
50
+                                IUserManager $userManager,
51
+                                IRootFolder $rootFolder,
52
+                                IJobList $jobList) {
53
+        $this->config = $config;
54
+        $this->userManager = $userManager;
55
+        $this->rootFolder = $rootFolder;
56
+        $this->jobList = $jobList;
57
+    }
58 58
 
59
-	public function getName(): string {
60
-		return 'Chunk cleanup scheduler';
61
-	}
59
+    public function getName(): string {
60
+        return 'Chunk cleanup scheduler';
61
+    }
62 62
 
63
-	public function run(IOutput $output) {
64
-		// If we already ran this onec there is no need to run it again
65
-		if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') {
66
-			$output->info('Cleanup not required');
67
-		}
63
+    public function run(IOutput $output) {
64
+        // If we already ran this onec there is no need to run it again
65
+        if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') {
66
+            $output->info('Cleanup not required');
67
+        }
68 68
 
69
-		$output->startProgress();
70
-		// Loop over all seen users
71
-		$this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
72
-			try {
73
-				$userFolder = $this->rootFolder->getUserFolder($user->getUID());
74
-				$userRoot = $userFolder->getParent();
75
-				/** @var Folder $uploadFolder */
76
-				$uploadFolder = $userRoot->get('uploads');
77
-			} catch (NotFoundException $e) {
78
-				// No folder so skipping
79
-				return;
80
-			}
69
+        $output->startProgress();
70
+        // Loop over all seen users
71
+        $this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
72
+            try {
73
+                $userFolder = $this->rootFolder->getUserFolder($user->getUID());
74
+                $userRoot = $userFolder->getParent();
75
+                /** @var Folder $uploadFolder */
76
+                $uploadFolder = $userRoot->get('uploads');
77
+            } catch (NotFoundException $e) {
78
+                // No folder so skipping
79
+                return;
80
+            }
81 81
 
82
-			// Insert a cleanup job for each folder we find
83
-			$uploads = $uploadFolder->getDirectoryListing();
84
-			foreach ($uploads as $upload) {
85
-				$this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]);
86
-			}
87
-			$output->advance();
88
-		});
89
-		$output->finishProgress();
82
+            // Insert a cleanup job for each folder we find
83
+            $uploads = $uploadFolder->getDirectoryListing();
84
+            foreach ($uploads as $upload) {
85
+                $this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]);
86
+            }
87
+            $output->advance();
88
+        });
89
+        $output->finishProgress();
90 90
 
91 91
 
92
-		$this->config->setAppValue('dav', 'chunks_migrated', '1');
93
-	}
92
+        $this->config->setAppValue('dav', 'chunks_migrated', '1');
93
+    }
94 94
 
95 95
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 
69 69
 		$output->startProgress();
70 70
 		// Loop over all seen users
71
-		$this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
71
+		$this->userManager->callForSeenUsers(function(IUser $user) use ($output) {
72 72
 			try {
73 73
 				$userFolder = $this->rootFolder->getUserFolder($user->getUID());
74 74
 				$userRoot = $userFolder->getParent();
Please login to merge, or discard this patch.