@@ -32,60 +32,60 @@ |
||
32 | 32 | use OCP\User\Backend\IPasswordConfirmationBackend; |
33 | 33 | |
34 | 34 | class PasswordConfirmationMiddleware extends Middleware { |
35 | - /** @var ControllerMethodReflector */ |
|
36 | - private $reflector; |
|
37 | - /** @var ISession */ |
|
38 | - private $session; |
|
39 | - /** @var IUserSession */ |
|
40 | - private $userSession; |
|
41 | - /** @var ITimeFactory */ |
|
42 | - private $timeFactory; |
|
43 | - /** @var array */ |
|
44 | - private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
35 | + /** @var ControllerMethodReflector */ |
|
36 | + private $reflector; |
|
37 | + /** @var ISession */ |
|
38 | + private $session; |
|
39 | + /** @var IUserSession */ |
|
40 | + private $userSession; |
|
41 | + /** @var ITimeFactory */ |
|
42 | + private $timeFactory; |
|
43 | + /** @var array */ |
|
44 | + private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; |
|
45 | 45 | |
46 | - /** |
|
47 | - * PasswordConfirmationMiddleware constructor. |
|
48 | - * |
|
49 | - * @param ControllerMethodReflector $reflector |
|
50 | - * @param ISession $session |
|
51 | - * @param IUserSession $userSession |
|
52 | - * @param ITimeFactory $timeFactory |
|
53 | - */ |
|
54 | - public function __construct(ControllerMethodReflector $reflector, |
|
55 | - ISession $session, |
|
56 | - IUserSession $userSession, |
|
57 | - ITimeFactory $timeFactory) { |
|
58 | - $this->reflector = $reflector; |
|
59 | - $this->session = $session; |
|
60 | - $this->userSession = $userSession; |
|
61 | - $this->timeFactory = $timeFactory; |
|
62 | - } |
|
46 | + /** |
|
47 | + * PasswordConfirmationMiddleware constructor. |
|
48 | + * |
|
49 | + * @param ControllerMethodReflector $reflector |
|
50 | + * @param ISession $session |
|
51 | + * @param IUserSession $userSession |
|
52 | + * @param ITimeFactory $timeFactory |
|
53 | + */ |
|
54 | + public function __construct(ControllerMethodReflector $reflector, |
|
55 | + ISession $session, |
|
56 | + IUserSession $userSession, |
|
57 | + ITimeFactory $timeFactory) { |
|
58 | + $this->reflector = $reflector; |
|
59 | + $this->session = $session; |
|
60 | + $this->userSession = $userSession; |
|
61 | + $this->timeFactory = $timeFactory; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param Controller $controller |
|
66 | - * @param string $methodName |
|
67 | - * @throws NotConfirmedException |
|
68 | - */ |
|
69 | - public function beforeController($controller, $methodName) { |
|
70 | - if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
71 | - $user = $this->userSession->getUser(); |
|
72 | - $backendClassName = ''; |
|
73 | - if ($user !== null) { |
|
74 | - $backend = $user->getBackend(); |
|
75 | - if ($backend instanceof IPasswordConfirmationBackend) { |
|
76 | - if (!$backend->canConfirmPassword($user->getUID())) { |
|
77 | - return; |
|
78 | - } |
|
79 | - } |
|
64 | + /** |
|
65 | + * @param Controller $controller |
|
66 | + * @param string $methodName |
|
67 | + * @throws NotConfirmedException |
|
68 | + */ |
|
69 | + public function beforeController($controller, $methodName) { |
|
70 | + if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) { |
|
71 | + $user = $this->userSession->getUser(); |
|
72 | + $backendClassName = ''; |
|
73 | + if ($user !== null) { |
|
74 | + $backend = $user->getBackend(); |
|
75 | + if ($backend instanceof IPasswordConfirmationBackend) { |
|
76 | + if (!$backend->canConfirmPassword($user->getUID())) { |
|
77 | + return; |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - $backendClassName = $user->getBackendClassName(); |
|
82 | - } |
|
81 | + $backendClassName = $user->getBackendClassName(); |
|
82 | + } |
|
83 | 83 | |
84 | - $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
85 | - // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
86 | - if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
87 | - throw new NotConfirmedException(); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
84 | + $lastConfirm = (int) $this->session->get('last-password-confirm'); |
|
85 | + // we can't check the password against a SAML backend, so skip password confirmation in this case |
|
86 | + if (!isset($this->excludedUserBackEnds[$backendClassName]) && $lastConfirm < ($this->timeFactory->getTime() - (30 * 60 + 15))) { // allow 15 seconds delay |
|
87 | + throw new NotConfirmedException(); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | 91 | } |
@@ -170,7 +170,7 @@ |
||
170 | 170 | )) |
171 | 171 | ->andWhere($update->expr()->like( |
172 | 172 | $update->func()->lower('name'), |
173 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
173 | + $update->createNamedParameter('%'.$this->dbConnection->escapeLikeParameter('.'.$ext)) |
|
174 | 174 | )); |
175 | 175 | return $update->execute(); |
176 | 176 | } |
@@ -33,148 +33,148 @@ |
||
33 | 33 | * @package OC\Files\Type |
34 | 34 | */ |
35 | 35 | class Loader implements IMimeTypeLoader { |
36 | - /** @var IDBConnection */ |
|
37 | - private $dbConnection; |
|
38 | - |
|
39 | - /** @var array [id => mimetype] */ |
|
40 | - protected $mimetypes; |
|
41 | - |
|
42 | - /** @var array [mimetype => id] */ |
|
43 | - protected $mimetypeIds; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param IDBConnection $dbConnection |
|
47 | - */ |
|
48 | - public function __construct(IDBConnection $dbConnection) { |
|
49 | - $this->dbConnection = $dbConnection; |
|
50 | - $this->mimetypes = []; |
|
51 | - $this->mimetypeIds = []; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Get a mimetype from its ID |
|
56 | - * |
|
57 | - * @param int $id |
|
58 | - * @return string|null |
|
59 | - */ |
|
60 | - public function getMimetypeById($id) { |
|
61 | - if (!$this->mimetypes) { |
|
62 | - $this->loadMimetypes(); |
|
63 | - } |
|
64 | - if (isset($this->mimetypes[$id])) { |
|
65 | - return $this->mimetypes[$id]; |
|
66 | - } |
|
67 | - return null; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
72 | - * |
|
73 | - * @param string $mimetype |
|
74 | - * @return int |
|
75 | - */ |
|
76 | - public function getId($mimetype) { |
|
77 | - if (!$this->mimetypeIds) { |
|
78 | - $this->loadMimetypes(); |
|
79 | - } |
|
80 | - if (isset($this->mimetypeIds[$mimetype])) { |
|
81 | - return $this->mimetypeIds[$mimetype]; |
|
82 | - } |
|
83 | - return $this->store($mimetype); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Test if a mimetype exists in the database |
|
88 | - * |
|
89 | - * @param string $mimetype |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function exists($mimetype) { |
|
93 | - if (!$this->mimetypeIds) { |
|
94 | - $this->loadMimetypes(); |
|
95 | - } |
|
96 | - return isset($this->mimetypeIds[$mimetype]); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Clear all loaded mimetypes, allow for re-loading |
|
101 | - */ |
|
102 | - public function reset() { |
|
103 | - $this->mimetypes = []; |
|
104 | - $this->mimetypeIds = []; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Store a mimetype in the DB |
|
109 | - * |
|
110 | - * @param string $mimetype |
|
111 | - * @param int inserted ID |
|
112 | - */ |
|
113 | - protected function store($mimetype) { |
|
114 | - $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
115 | - 'mimetype' => $mimetype |
|
116 | - ]); |
|
117 | - |
|
118 | - $fetch = $this->dbConnection->getQueryBuilder(); |
|
119 | - $fetch->select('id') |
|
120 | - ->from('mimetypes') |
|
121 | - ->where( |
|
122 | - $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
123 | - )); |
|
124 | - |
|
125 | - $result = $fetch->execute(); |
|
126 | - $row = $result->fetch(); |
|
127 | - $result->closeCursor(); |
|
128 | - |
|
129 | - if (!$row) { |
|
130 | - throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
131 | - } |
|
132 | - |
|
133 | - $this->mimetypes[$row['id']] = $mimetype; |
|
134 | - $this->mimetypeIds[$mimetype] = $row['id']; |
|
135 | - return $row['id']; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Load all mimetypes from DB |
|
140 | - */ |
|
141 | - private function loadMimetypes() { |
|
142 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
143 | - $qb->select('id', 'mimetype') |
|
144 | - ->from('mimetypes'); |
|
145 | - |
|
146 | - $result = $qb->execute(); |
|
147 | - $results = $result->fetchAll(); |
|
148 | - $result->closeCursor(); |
|
149 | - |
|
150 | - foreach ($results as $row) { |
|
151 | - $this->mimetypes[$row['id']] = $row['mimetype']; |
|
152 | - $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Update filecache mimetype based on file extension |
|
158 | - * |
|
159 | - * @param string $ext file extension |
|
160 | - * @param int $mimeTypeId |
|
161 | - * @return int number of changed rows |
|
162 | - */ |
|
163 | - public function updateFilecache($ext, $mimeTypeId) { |
|
164 | - $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
165 | - $update = $this->dbConnection->getQueryBuilder(); |
|
166 | - $update->update('filecache') |
|
167 | - ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
168 | - ->where($update->expr()->neq( |
|
169 | - 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
170 | - )) |
|
171 | - ->andWhere($update->expr()->neq( |
|
172 | - 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
173 | - )) |
|
174 | - ->andWhere($update->expr()->like( |
|
175 | - $update->func()->lower('name'), |
|
176 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
177 | - )); |
|
178 | - return $update->execute(); |
|
179 | - } |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $dbConnection; |
|
38 | + |
|
39 | + /** @var array [id => mimetype] */ |
|
40 | + protected $mimetypes; |
|
41 | + |
|
42 | + /** @var array [mimetype => id] */ |
|
43 | + protected $mimetypeIds; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param IDBConnection $dbConnection |
|
47 | + */ |
|
48 | + public function __construct(IDBConnection $dbConnection) { |
|
49 | + $this->dbConnection = $dbConnection; |
|
50 | + $this->mimetypes = []; |
|
51 | + $this->mimetypeIds = []; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Get a mimetype from its ID |
|
56 | + * |
|
57 | + * @param int $id |
|
58 | + * @return string|null |
|
59 | + */ |
|
60 | + public function getMimetypeById($id) { |
|
61 | + if (!$this->mimetypes) { |
|
62 | + $this->loadMimetypes(); |
|
63 | + } |
|
64 | + if (isset($this->mimetypes[$id])) { |
|
65 | + return $this->mimetypes[$id]; |
|
66 | + } |
|
67 | + return null; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
72 | + * |
|
73 | + * @param string $mimetype |
|
74 | + * @return int |
|
75 | + */ |
|
76 | + public function getId($mimetype) { |
|
77 | + if (!$this->mimetypeIds) { |
|
78 | + $this->loadMimetypes(); |
|
79 | + } |
|
80 | + if (isset($this->mimetypeIds[$mimetype])) { |
|
81 | + return $this->mimetypeIds[$mimetype]; |
|
82 | + } |
|
83 | + return $this->store($mimetype); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Test if a mimetype exists in the database |
|
88 | + * |
|
89 | + * @param string $mimetype |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function exists($mimetype) { |
|
93 | + if (!$this->mimetypeIds) { |
|
94 | + $this->loadMimetypes(); |
|
95 | + } |
|
96 | + return isset($this->mimetypeIds[$mimetype]); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Clear all loaded mimetypes, allow for re-loading |
|
101 | + */ |
|
102 | + public function reset() { |
|
103 | + $this->mimetypes = []; |
|
104 | + $this->mimetypeIds = []; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Store a mimetype in the DB |
|
109 | + * |
|
110 | + * @param string $mimetype |
|
111 | + * @param int inserted ID |
|
112 | + */ |
|
113 | + protected function store($mimetype) { |
|
114 | + $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
115 | + 'mimetype' => $mimetype |
|
116 | + ]); |
|
117 | + |
|
118 | + $fetch = $this->dbConnection->getQueryBuilder(); |
|
119 | + $fetch->select('id') |
|
120 | + ->from('mimetypes') |
|
121 | + ->where( |
|
122 | + $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
123 | + )); |
|
124 | + |
|
125 | + $result = $fetch->execute(); |
|
126 | + $row = $result->fetch(); |
|
127 | + $result->closeCursor(); |
|
128 | + |
|
129 | + if (!$row) { |
|
130 | + throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
131 | + } |
|
132 | + |
|
133 | + $this->mimetypes[$row['id']] = $mimetype; |
|
134 | + $this->mimetypeIds[$mimetype] = $row['id']; |
|
135 | + return $row['id']; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Load all mimetypes from DB |
|
140 | + */ |
|
141 | + private function loadMimetypes() { |
|
142 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
143 | + $qb->select('id', 'mimetype') |
|
144 | + ->from('mimetypes'); |
|
145 | + |
|
146 | + $result = $qb->execute(); |
|
147 | + $results = $result->fetchAll(); |
|
148 | + $result->closeCursor(); |
|
149 | + |
|
150 | + foreach ($results as $row) { |
|
151 | + $this->mimetypes[$row['id']] = $row['mimetype']; |
|
152 | + $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Update filecache mimetype based on file extension |
|
158 | + * |
|
159 | + * @param string $ext file extension |
|
160 | + * @param int $mimeTypeId |
|
161 | + * @return int number of changed rows |
|
162 | + */ |
|
163 | + public function updateFilecache($ext, $mimeTypeId) { |
|
164 | + $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
165 | + $update = $this->dbConnection->getQueryBuilder(); |
|
166 | + $update->update('filecache') |
|
167 | + ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
168 | + ->where($update->expr()->neq( |
|
169 | + 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
170 | + )) |
|
171 | + ->andWhere($update->expr()->neq( |
|
172 | + 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
173 | + )) |
|
174 | + ->andWhere($update->expr()->like( |
|
175 | + $update->func()->lower('name'), |
|
176 | + $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
177 | + )); |
|
178 | + return $update->execute(); |
|
179 | + } |
|
180 | 180 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105112049 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source_copy'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source_copy'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105104833 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -33,27 +33,27 @@ |
||
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 | } |
@@ -31,68 +31,68 @@ |
||
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 | } |
@@ -89,8 +89,8 @@ |
||
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 | ]; |
@@ -36,73 +36,73 @@ |
||
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 | } |
@@ -37,59 +37,59 @@ |
||
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 | } |
@@ -68,7 +68,7 @@ |
||
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(); |
@@ -29,21 +29,21 @@ |
||
29 | 29 | use OCP\IUserSession; |
30 | 30 | |
31 | 31 | class CleanupService { |
32 | - /** @var IUserSession */ |
|
33 | - private $userSession; |
|
34 | - /** @var IJobList */ |
|
35 | - private $jobList; |
|
32 | + /** @var IUserSession */ |
|
33 | + private $userSession; |
|
34 | + /** @var IJobList */ |
|
35 | + private $jobList; |
|
36 | 36 | |
37 | - public function __construct(IUserSession $userSession, IJobList $jobList) { |
|
38 | - $this->userSession = $userSession; |
|
39 | - $this->jobList = $jobList; |
|
40 | - } |
|
37 | + public function __construct(IUserSession $userSession, IJobList $jobList) { |
|
38 | + $this->userSession = $userSession; |
|
39 | + $this->jobList = $jobList; |
|
40 | + } |
|
41 | 41 | |
42 | - public function addJob(string $folder) { |
|
43 | - $this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
44 | - } |
|
42 | + public function addJob(string $folder) { |
|
43 | + $this->jobList->add(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
44 | + } |
|
45 | 45 | |
46 | - public function removeJob(string $folder) { |
|
47 | - $this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
48 | - } |
|
46 | + public function removeJob(string $folder) { |
|
47 | + $this->jobList->remove(UploadCleanup::class, ['uid' => $this->userSession->getUser()->getUID(), 'folder' => $folder]); |
|
48 | + } |
|
49 | 49 | } |