@@ -34,156 +34,156 @@ |
||
34 | 34 | |
35 | 35 | class RemoteController extends OCSController { |
36 | 36 | |
37 | - /** @var Manager */ |
|
38 | - private $externalManager; |
|
39 | - |
|
40 | - /** @var ILogger */ |
|
41 | - private $logger; |
|
42 | - |
|
43 | - /** |
|
44 | - * @NoAdminRequired |
|
45 | - * |
|
46 | - * Remote constructor. |
|
47 | - * |
|
48 | - * @param string $appName |
|
49 | - * @param IRequest $request |
|
50 | - * @param Manager $externalManager |
|
51 | - */ |
|
52 | - public function __construct($appName, |
|
53 | - IRequest $request, |
|
54 | - Manager $externalManager, |
|
55 | - ILogger $logger) { |
|
56 | - parent::__construct($appName, $request); |
|
57 | - |
|
58 | - $this->externalManager = $externalManager; |
|
59 | - $this->logger = $logger; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @NoAdminRequired |
|
64 | - * |
|
65 | - * Get list of pending remote shares |
|
66 | - * |
|
67 | - * @return DataResponse |
|
68 | - */ |
|
69 | - public function getOpenShares() { |
|
70 | - return new DataResponse($this->externalManager->getOpenShares()); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @NoAdminRequired |
|
75 | - * |
|
76 | - * Accept a remote share |
|
77 | - * |
|
78 | - * @param int $id |
|
79 | - * @return DataResponse |
|
80 | - * @throws OCSNotFoundException |
|
81 | - */ |
|
82 | - public function acceptShare($id) { |
|
83 | - if ($this->externalManager->acceptShare($id)) { |
|
84 | - return new DataResponse(); |
|
85 | - } |
|
86 | - |
|
87 | - $this->logger->error('Could not accept federated share with id: ' . $id, |
|
88 | - ['app' => 'files_sharing']); |
|
89 | - |
|
90 | - throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @NoAdminRequired |
|
95 | - * |
|
96 | - * Decline a remote share |
|
97 | - * |
|
98 | - * @param int $id |
|
99 | - * @return DataResponse |
|
100 | - * @throws OCSNotFoundException |
|
101 | - */ |
|
102 | - public function declineShare($id) { |
|
103 | - if ($this->externalManager->declineShare($id)) { |
|
104 | - return new DataResponse(); |
|
105 | - } |
|
106 | - |
|
107 | - // Make sure the user has no notification for something that does not exist anymore. |
|
108 | - $this->externalManager->processNotification($id); |
|
109 | - |
|
110 | - throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param array $share Share with info from the share_external table |
|
115 | - * @return array enriched share info with data from the filecache |
|
116 | - */ |
|
117 | - private static function extendShareInfo($share) { |
|
118 | - $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
119 | - $info = $view->getFileInfo($share['mountpoint']); |
|
120 | - |
|
121 | - $share['mimetype'] = $info->getMimetype(); |
|
122 | - $share['mtime'] = $info->getMTime(); |
|
123 | - $share['permissions'] = $info->getPermissions(); |
|
124 | - $share['type'] = $info->getType(); |
|
125 | - $share['file_id'] = $info->getId(); |
|
126 | - |
|
127 | - return $share; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @NoAdminRequired |
|
132 | - * |
|
133 | - * List accepted remote shares |
|
134 | - * |
|
135 | - * @return DataResponse |
|
136 | - */ |
|
137 | - public function getShares() { |
|
138 | - $shares = $this->externalManager->getAcceptedShares(); |
|
139 | - $shares = array_map('self::extendShareInfo', $shares); |
|
140 | - |
|
141 | - return new DataResponse($shares); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @NoAdminRequired |
|
146 | - * |
|
147 | - * Get info of a remote share |
|
148 | - * |
|
149 | - * @param int $id |
|
150 | - * @return DataResponse |
|
151 | - * @throws OCSNotFoundException |
|
152 | - */ |
|
153 | - public function getShare($id) { |
|
154 | - $shareInfo = $this->externalManager->getShare($id); |
|
155 | - |
|
156 | - if ($shareInfo === false) { |
|
157 | - throw new OCSNotFoundException('share does not exist'); |
|
158 | - } else { |
|
159 | - $shareInfo = self::extendShareInfo($shareInfo); |
|
160 | - return new DataResponse($shareInfo); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @NoAdminRequired |
|
166 | - * |
|
167 | - * Unshare a remote share |
|
168 | - * |
|
169 | - * @param int $id |
|
170 | - * @return DataResponse |
|
171 | - * @throws OCSNotFoundException |
|
172 | - * @throws OCSForbiddenException |
|
173 | - */ |
|
174 | - public function unshare($id) { |
|
175 | - $shareInfo = $this->externalManager->getShare($id); |
|
176 | - |
|
177 | - if ($shareInfo === false) { |
|
178 | - throw new OCSNotFoundException('Share does not exist'); |
|
179 | - } |
|
180 | - |
|
181 | - $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
182 | - |
|
183 | - if ($this->externalManager->removeShare($mountPoint) === true) { |
|
184 | - return new DataResponse(); |
|
185 | - } else { |
|
186 | - throw new OCSForbiddenException('Could not unshare'); |
|
187 | - } |
|
188 | - } |
|
37 | + /** @var Manager */ |
|
38 | + private $externalManager; |
|
39 | + |
|
40 | + /** @var ILogger */ |
|
41 | + private $logger; |
|
42 | + |
|
43 | + /** |
|
44 | + * @NoAdminRequired |
|
45 | + * |
|
46 | + * Remote constructor. |
|
47 | + * |
|
48 | + * @param string $appName |
|
49 | + * @param IRequest $request |
|
50 | + * @param Manager $externalManager |
|
51 | + */ |
|
52 | + public function __construct($appName, |
|
53 | + IRequest $request, |
|
54 | + Manager $externalManager, |
|
55 | + ILogger $logger) { |
|
56 | + parent::__construct($appName, $request); |
|
57 | + |
|
58 | + $this->externalManager = $externalManager; |
|
59 | + $this->logger = $logger; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @NoAdminRequired |
|
64 | + * |
|
65 | + * Get list of pending remote shares |
|
66 | + * |
|
67 | + * @return DataResponse |
|
68 | + */ |
|
69 | + public function getOpenShares() { |
|
70 | + return new DataResponse($this->externalManager->getOpenShares()); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @NoAdminRequired |
|
75 | + * |
|
76 | + * Accept a remote share |
|
77 | + * |
|
78 | + * @param int $id |
|
79 | + * @return DataResponse |
|
80 | + * @throws OCSNotFoundException |
|
81 | + */ |
|
82 | + public function acceptShare($id) { |
|
83 | + if ($this->externalManager->acceptShare($id)) { |
|
84 | + return new DataResponse(); |
|
85 | + } |
|
86 | + |
|
87 | + $this->logger->error('Could not accept federated share with id: ' . $id, |
|
88 | + ['app' => 'files_sharing']); |
|
89 | + |
|
90 | + throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @NoAdminRequired |
|
95 | + * |
|
96 | + * Decline a remote share |
|
97 | + * |
|
98 | + * @param int $id |
|
99 | + * @return DataResponse |
|
100 | + * @throws OCSNotFoundException |
|
101 | + */ |
|
102 | + public function declineShare($id) { |
|
103 | + if ($this->externalManager->declineShare($id)) { |
|
104 | + return new DataResponse(); |
|
105 | + } |
|
106 | + |
|
107 | + // Make sure the user has no notification for something that does not exist anymore. |
|
108 | + $this->externalManager->processNotification($id); |
|
109 | + |
|
110 | + throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param array $share Share with info from the share_external table |
|
115 | + * @return array enriched share info with data from the filecache |
|
116 | + */ |
|
117 | + private static function extendShareInfo($share) { |
|
118 | + $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
119 | + $info = $view->getFileInfo($share['mountpoint']); |
|
120 | + |
|
121 | + $share['mimetype'] = $info->getMimetype(); |
|
122 | + $share['mtime'] = $info->getMTime(); |
|
123 | + $share['permissions'] = $info->getPermissions(); |
|
124 | + $share['type'] = $info->getType(); |
|
125 | + $share['file_id'] = $info->getId(); |
|
126 | + |
|
127 | + return $share; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @NoAdminRequired |
|
132 | + * |
|
133 | + * List accepted remote shares |
|
134 | + * |
|
135 | + * @return DataResponse |
|
136 | + */ |
|
137 | + public function getShares() { |
|
138 | + $shares = $this->externalManager->getAcceptedShares(); |
|
139 | + $shares = array_map('self::extendShareInfo', $shares); |
|
140 | + |
|
141 | + return new DataResponse($shares); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @NoAdminRequired |
|
146 | + * |
|
147 | + * Get info of a remote share |
|
148 | + * |
|
149 | + * @param int $id |
|
150 | + * @return DataResponse |
|
151 | + * @throws OCSNotFoundException |
|
152 | + */ |
|
153 | + public function getShare($id) { |
|
154 | + $shareInfo = $this->externalManager->getShare($id); |
|
155 | + |
|
156 | + if ($shareInfo === false) { |
|
157 | + throw new OCSNotFoundException('share does not exist'); |
|
158 | + } else { |
|
159 | + $shareInfo = self::extendShareInfo($shareInfo); |
|
160 | + return new DataResponse($shareInfo); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @NoAdminRequired |
|
166 | + * |
|
167 | + * Unshare a remote share |
|
168 | + * |
|
169 | + * @param int $id |
|
170 | + * @return DataResponse |
|
171 | + * @throws OCSNotFoundException |
|
172 | + * @throws OCSForbiddenException |
|
173 | + */ |
|
174 | + public function unshare($id) { |
|
175 | + $shareInfo = $this->externalManager->getShare($id); |
|
176 | + |
|
177 | + if ($shareInfo === false) { |
|
178 | + throw new OCSNotFoundException('Share does not exist'); |
|
179 | + } |
|
180 | + |
|
181 | + $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
182 | + |
|
183 | + if ($this->externalManager->removeShare($mountPoint) === true) { |
|
184 | + return new DataResponse(); |
|
185 | + } else { |
|
186 | + throw new OCSForbiddenException('Could not unshare'); |
|
187 | + } |
|
188 | + } |
|
189 | 189 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return new DataResponse(); |
85 | 85 | } |
86 | 86 | |
87 | - $this->logger->error('Could not accept federated share with id: ' . $id, |
|
87 | + $this->logger->error('Could not accept federated share with id: '.$id, |
|
88 | 88 | ['app' => 'files_sharing']); |
89 | 89 | |
90 | 90 | throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @return array enriched share info with data from the filecache |
116 | 116 | */ |
117 | 117 | private static function extendShareInfo($share) { |
118 | - $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
118 | + $view = new \OC\Files\View('/'.\OC_User::getUser().'/files/'); |
|
119 | 119 | $info = $view->getFileInfo($share['mountpoint']); |
120 | 120 | |
121 | 121 | $share['mimetype'] = $info->getMimetype(); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | throw new OCSNotFoundException('Share does not exist'); |
179 | 179 | } |
180 | 180 | |
181 | - $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
181 | + $mountPoint = '/'.\OC_User::getUser().'/files'.$shareInfo['mountpoint']; |
|
182 | 182 | |
183 | 183 | if ($this->externalManager->removeShare($mountPoint) === true) { |
184 | 184 | return new DataResponse(); |
@@ -25,18 +25,18 @@ |
||
25 | 25 | use OCA\Testing\AlternativeHomeUserBackend; |
26 | 26 | |
27 | 27 | class Application extends App { |
28 | - public function __construct (array $urlParams = array()) { |
|
29 | - $appName = 'testing'; |
|
30 | - parent::__construct($appName, $urlParams); |
|
28 | + public function __construct (array $urlParams = array()) { |
|
29 | + $appName = 'testing'; |
|
30 | + parent::__construct($appName, $urlParams); |
|
31 | 31 | |
32 | - $c = $this->getContainer(); |
|
33 | - $config = $c->getServer()->getConfig(); |
|
34 | - if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') { |
|
35 | - $userManager = $c->getServer()->getUserManager(); |
|
32 | + $c = $this->getContainer(); |
|
33 | + $config = $c->getServer()->getConfig(); |
|
34 | + if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') { |
|
35 | + $userManager = $c->getServer()->getUserManager(); |
|
36 | 36 | |
37 | - // replace all user backends with this one |
|
38 | - $userManager->clearBackends(); |
|
39 | - $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class)); |
|
40 | - } |
|
41 | - } |
|
37 | + // replace all user backends with this one |
|
38 | + $userManager->clearBackends(); |
|
39 | + $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class)); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | use OCA\Testing\AlternativeHomeUserBackend; |
26 | 26 | |
27 | 27 | class Application extends App { |
28 | - public function __construct (array $urlParams = array()) { |
|
28 | + public function __construct(array $urlParams = array()) { |
|
29 | 29 | $appName = 'testing'; |
30 | 30 | parent::__construct($appName, $urlParams); |
31 | 31 |
@@ -29,39 +29,39 @@ |
||
29 | 29 | |
30 | 30 | class ConfigController extends OCSController { |
31 | 31 | |
32 | - /** @var IConfig */ |
|
33 | - private $config; |
|
32 | + /** @var IConfig */ |
|
33 | + private $config; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $appName |
|
37 | - * @param IRequest $request |
|
38 | - * @param IConfig $config |
|
39 | - */ |
|
40 | - public function __construct($appName, |
|
41 | - IRequest $request, |
|
42 | - IConfig $config) { |
|
43 | - parent::__construct($appName, $request); |
|
44 | - $this->config = $config; |
|
45 | - } |
|
35 | + /** |
|
36 | + * @param string $appName |
|
37 | + * @param IRequest $request |
|
38 | + * @param IConfig $config |
|
39 | + */ |
|
40 | + public function __construct($appName, |
|
41 | + IRequest $request, |
|
42 | + IConfig $config) { |
|
43 | + parent::__construct($appName, $request); |
|
44 | + $this->config = $config; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $appid |
|
49 | - * @param string $configkey |
|
50 | - * @param string $value |
|
51 | - * @return DataResponse |
|
52 | - */ |
|
53 | - public function setAppValue($appid, $configkey, $value) { |
|
54 | - $this->config->setAppValue($appid, $configkey, $value); |
|
55 | - return new DataResponse(); |
|
56 | - } |
|
47 | + /** |
|
48 | + * @param string $appid |
|
49 | + * @param string $configkey |
|
50 | + * @param string $value |
|
51 | + * @return DataResponse |
|
52 | + */ |
|
53 | + public function setAppValue($appid, $configkey, $value) { |
|
54 | + $this->config->setAppValue($appid, $configkey, $value); |
|
55 | + return new DataResponse(); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $appid |
|
60 | - * @param string $configkey |
|
61 | - * @return DataResponse |
|
62 | - */ |
|
63 | - public function deleteAppValue($appid, $configkey) { |
|
64 | - $this->config->deleteAppValue($appid, $configkey); |
|
65 | - return new DataResponse(); |
|
66 | - } |
|
58 | + /** |
|
59 | + * @param string $appid |
|
60 | + * @param string $configkey |
|
61 | + * @return DataResponse |
|
62 | + */ |
|
63 | + public function deleteAppValue($appid, $configkey) { |
|
64 | + $this->config->deleteAppValue($appid, $configkey); |
|
65 | + return new DataResponse(); |
|
66 | + } |
|
67 | 67 | } |
@@ -39,208 +39,208 @@ |
||
39 | 39 | |
40 | 40 | class LockingController extends OCSController { |
41 | 41 | |
42 | - /** @var ILockingProvider */ |
|
43 | - protected $lockingProvider; |
|
44 | - |
|
45 | - /** @var FakeDBLockingProvider */ |
|
46 | - protected $fakeDBLockingProvider; |
|
47 | - |
|
48 | - /** @var IDBConnection */ |
|
49 | - protected $connection; |
|
50 | - |
|
51 | - /** @var IConfig */ |
|
52 | - protected $config; |
|
53 | - |
|
54 | - /** @var IRootFolder */ |
|
55 | - protected $rootFolder; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $appName |
|
59 | - * @param IRequest $request |
|
60 | - * @param ILockingProvider $lockingProvider |
|
61 | - * @param FakeDBLockingProvider $fakeDBLockingProvider |
|
62 | - * @param IDBConnection $connection |
|
63 | - * @param IConfig $config |
|
64 | - * @param IRootFolder $rootFolder |
|
65 | - */ |
|
66 | - public function __construct($appName, |
|
67 | - IRequest $request, |
|
68 | - ILockingProvider $lockingProvider, |
|
69 | - FakeDBLockingProvider $fakeDBLockingProvider, |
|
70 | - IDBConnection $connection, |
|
71 | - IConfig $config, |
|
72 | - IRootFolder $rootFolder) { |
|
73 | - parent::__construct($appName, $request); |
|
74 | - |
|
75 | - $this->lockingProvider = $lockingProvider; |
|
76 | - $this->fakeDBLockingProvider = $fakeDBLockingProvider; |
|
77 | - $this->connection = $connection; |
|
78 | - $this->config = $config; |
|
79 | - $this->rootFolder = $rootFolder; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @return ILockingProvider |
|
84 | - * @throws \RuntimeException |
|
85 | - */ |
|
86 | - protected function getLockingProvider() { |
|
87 | - if ($this->lockingProvider instanceof DBLockingProvider) { |
|
88 | - return $this->fakeDBLockingProvider; |
|
89 | - } |
|
90 | - throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider'); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $user |
|
95 | - * @param string $path |
|
96 | - * @return string |
|
97 | - * @throws NotFoundException |
|
98 | - */ |
|
99 | - protected function getPath($user, $path) { |
|
100 | - $node = $this->rootFolder->getUserFolder($user)->get($path); |
|
101 | - return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return DataResponse |
|
106 | - * @throws OCSException |
|
107 | - */ |
|
108 | - public function isLockingEnabled() { |
|
109 | - try { |
|
110 | - $this->getLockingProvider(); |
|
111 | - return new DataResponse(); |
|
112 | - } catch (\RuntimeException $e) { |
|
113 | - throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param int $type |
|
119 | - * @param string $user |
|
120 | - * @param string $path |
|
121 | - * @return DataResponse |
|
122 | - * @throws OCSException |
|
123 | - */ |
|
124 | - public function acquireLock($type, $user, $path) { |
|
125 | - try { |
|
126 | - $path = $this->getPath($user, $path); |
|
127 | - } catch (NoUserException $e) { |
|
128 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
129 | - } catch (NotFoundException $e) { |
|
130 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
131 | - } |
|
132 | - |
|
133 | - $lockingProvider = $this->getLockingProvider(); |
|
134 | - |
|
135 | - try { |
|
136 | - $lockingProvider->acquireLock($path, $type); |
|
137 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
138 | - return new DataResponse(); |
|
139 | - } catch (LockedException $e) { |
|
140 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @param int $type |
|
146 | - * @param string $user |
|
147 | - * @param string $path |
|
148 | - * @return DataResponse |
|
149 | - * @throws OCSException |
|
150 | - */ |
|
151 | - public function changeLock($type, $user, $path) { |
|
152 | - try { |
|
153 | - $path = $this->getPath($user, $path); |
|
154 | - } catch (NoUserException $e) { |
|
155 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
156 | - } catch (NotFoundException $e) { |
|
157 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
158 | - } |
|
159 | - |
|
160 | - $lockingProvider = $this->getLockingProvider(); |
|
161 | - |
|
162 | - try { |
|
163 | - $lockingProvider->changeLock($path, $type); |
|
164 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
165 | - return new DataResponse(); |
|
166 | - } catch (LockedException $e) { |
|
167 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param int $type |
|
173 | - * @param string $user |
|
174 | - * @param string $path |
|
175 | - * @return DataResponse |
|
176 | - * @throws OCSException |
|
177 | - */ |
|
178 | - public function releaseLock($type, $user, $path) { |
|
179 | - try { |
|
180 | - $path = $this->getPath($user, $path); |
|
181 | - } catch (NoUserException $e) { |
|
182 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
183 | - } catch (NotFoundException $e) { |
|
184 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
185 | - } |
|
186 | - |
|
187 | - $lockingProvider = $this->getLockingProvider(); |
|
188 | - |
|
189 | - try { |
|
190 | - $lockingProvider->releaseLock($path, $type); |
|
191 | - $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
192 | - return new DataResponse(); |
|
193 | - } catch (LockedException $e) { |
|
194 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param int $type |
|
200 | - * @param string $user |
|
201 | - * @param string $path |
|
202 | - * @return DataResponse |
|
203 | - * @throws OCSException |
|
204 | - */ |
|
205 | - public function isLocked($type, $user, $path) { |
|
206 | - try { |
|
207 | - $path = $this->getPath($user, $path); |
|
208 | - } catch (NoUserException $e) { |
|
209 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
210 | - } catch (NotFoundException $e) { |
|
211 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
212 | - } |
|
213 | - |
|
214 | - $lockingProvider = $this->getLockingProvider(); |
|
215 | - |
|
216 | - if ($lockingProvider->isLocked($path, $type)) { |
|
217 | - return new DataResponse(); |
|
218 | - } |
|
219 | - |
|
220 | - throw new OCSException('', Http::STATUS_LOCKED); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param int $type |
|
225 | - * @return DataResponse |
|
226 | - */ |
|
227 | - public function releaseAll($type = null) { |
|
228 | - $lockingProvider = $this->getLockingProvider(); |
|
229 | - |
|
230 | - foreach ($this->config->getAppKeys('testing') as $lock) { |
|
231 | - if (strpos($lock, 'locking_') === 0) { |
|
232 | - $path = substr($lock, strlen('locking_')); |
|
233 | - |
|
234 | - if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
235 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
236 | - } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
237 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
238 | - } else { |
|
239 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - return new DataResponse(); |
|
245 | - } |
|
42 | + /** @var ILockingProvider */ |
|
43 | + protected $lockingProvider; |
|
44 | + |
|
45 | + /** @var FakeDBLockingProvider */ |
|
46 | + protected $fakeDBLockingProvider; |
|
47 | + |
|
48 | + /** @var IDBConnection */ |
|
49 | + protected $connection; |
|
50 | + |
|
51 | + /** @var IConfig */ |
|
52 | + protected $config; |
|
53 | + |
|
54 | + /** @var IRootFolder */ |
|
55 | + protected $rootFolder; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $appName |
|
59 | + * @param IRequest $request |
|
60 | + * @param ILockingProvider $lockingProvider |
|
61 | + * @param FakeDBLockingProvider $fakeDBLockingProvider |
|
62 | + * @param IDBConnection $connection |
|
63 | + * @param IConfig $config |
|
64 | + * @param IRootFolder $rootFolder |
|
65 | + */ |
|
66 | + public function __construct($appName, |
|
67 | + IRequest $request, |
|
68 | + ILockingProvider $lockingProvider, |
|
69 | + FakeDBLockingProvider $fakeDBLockingProvider, |
|
70 | + IDBConnection $connection, |
|
71 | + IConfig $config, |
|
72 | + IRootFolder $rootFolder) { |
|
73 | + parent::__construct($appName, $request); |
|
74 | + |
|
75 | + $this->lockingProvider = $lockingProvider; |
|
76 | + $this->fakeDBLockingProvider = $fakeDBLockingProvider; |
|
77 | + $this->connection = $connection; |
|
78 | + $this->config = $config; |
|
79 | + $this->rootFolder = $rootFolder; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @return ILockingProvider |
|
84 | + * @throws \RuntimeException |
|
85 | + */ |
|
86 | + protected function getLockingProvider() { |
|
87 | + if ($this->lockingProvider instanceof DBLockingProvider) { |
|
88 | + return $this->fakeDBLockingProvider; |
|
89 | + } |
|
90 | + throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider'); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $user |
|
95 | + * @param string $path |
|
96 | + * @return string |
|
97 | + * @throws NotFoundException |
|
98 | + */ |
|
99 | + protected function getPath($user, $path) { |
|
100 | + $node = $this->rootFolder->getUserFolder($user)->get($path); |
|
101 | + return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return DataResponse |
|
106 | + * @throws OCSException |
|
107 | + */ |
|
108 | + public function isLockingEnabled() { |
|
109 | + try { |
|
110 | + $this->getLockingProvider(); |
|
111 | + return new DataResponse(); |
|
112 | + } catch (\RuntimeException $e) { |
|
113 | + throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param int $type |
|
119 | + * @param string $user |
|
120 | + * @param string $path |
|
121 | + * @return DataResponse |
|
122 | + * @throws OCSException |
|
123 | + */ |
|
124 | + public function acquireLock($type, $user, $path) { |
|
125 | + try { |
|
126 | + $path = $this->getPath($user, $path); |
|
127 | + } catch (NoUserException $e) { |
|
128 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
129 | + } catch (NotFoundException $e) { |
|
130 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
131 | + } |
|
132 | + |
|
133 | + $lockingProvider = $this->getLockingProvider(); |
|
134 | + |
|
135 | + try { |
|
136 | + $lockingProvider->acquireLock($path, $type); |
|
137 | + $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
138 | + return new DataResponse(); |
|
139 | + } catch (LockedException $e) { |
|
140 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @param int $type |
|
146 | + * @param string $user |
|
147 | + * @param string $path |
|
148 | + * @return DataResponse |
|
149 | + * @throws OCSException |
|
150 | + */ |
|
151 | + public function changeLock($type, $user, $path) { |
|
152 | + try { |
|
153 | + $path = $this->getPath($user, $path); |
|
154 | + } catch (NoUserException $e) { |
|
155 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
156 | + } catch (NotFoundException $e) { |
|
157 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
158 | + } |
|
159 | + |
|
160 | + $lockingProvider = $this->getLockingProvider(); |
|
161 | + |
|
162 | + try { |
|
163 | + $lockingProvider->changeLock($path, $type); |
|
164 | + $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
165 | + return new DataResponse(); |
|
166 | + } catch (LockedException $e) { |
|
167 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param int $type |
|
173 | + * @param string $user |
|
174 | + * @param string $path |
|
175 | + * @return DataResponse |
|
176 | + * @throws OCSException |
|
177 | + */ |
|
178 | + public function releaseLock($type, $user, $path) { |
|
179 | + try { |
|
180 | + $path = $this->getPath($user, $path); |
|
181 | + } catch (NoUserException $e) { |
|
182 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
183 | + } catch (NotFoundException $e) { |
|
184 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
185 | + } |
|
186 | + |
|
187 | + $lockingProvider = $this->getLockingProvider(); |
|
188 | + |
|
189 | + try { |
|
190 | + $lockingProvider->releaseLock($path, $type); |
|
191 | + $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
192 | + return new DataResponse(); |
|
193 | + } catch (LockedException $e) { |
|
194 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param int $type |
|
200 | + * @param string $user |
|
201 | + * @param string $path |
|
202 | + * @return DataResponse |
|
203 | + * @throws OCSException |
|
204 | + */ |
|
205 | + public function isLocked($type, $user, $path) { |
|
206 | + try { |
|
207 | + $path = $this->getPath($user, $path); |
|
208 | + } catch (NoUserException $e) { |
|
209 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
210 | + } catch (NotFoundException $e) { |
|
211 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
212 | + } |
|
213 | + |
|
214 | + $lockingProvider = $this->getLockingProvider(); |
|
215 | + |
|
216 | + if ($lockingProvider->isLocked($path, $type)) { |
|
217 | + return new DataResponse(); |
|
218 | + } |
|
219 | + |
|
220 | + throw new OCSException('', Http::STATUS_LOCKED); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param int $type |
|
225 | + * @return DataResponse |
|
226 | + */ |
|
227 | + public function releaseAll($type = null) { |
|
228 | + $lockingProvider = $this->getLockingProvider(); |
|
229 | + |
|
230 | + foreach ($this->config->getAppKeys('testing') as $lock) { |
|
231 | + if (strpos($lock, 'locking_') === 0) { |
|
232 | + $path = substr($lock, strlen('locking_')); |
|
233 | + |
|
234 | + if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
235 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
236 | + } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
237 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
238 | + } else { |
|
239 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + return new DataResponse(); |
|
245 | + } |
|
246 | 246 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function getPath($user, $path) { |
100 | 100 | $node = $this->rootFolder->getUserFolder($user)->get($path); |
101 | - return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
101 | + return 'files/'.md5($node->getStorage()->getId().'::'.trim($node->getInternalPath(), '/')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | try { |
136 | 136 | $lockingProvider->acquireLock($path, $type); |
137 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
137 | + $this->config->setAppValue('testing', 'locking_'.$path, $type); |
|
138 | 138 | return new DataResponse(); |
139 | 139 | } catch (LockedException $e) { |
140 | 140 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | |
162 | 162 | try { |
163 | 163 | $lockingProvider->changeLock($path, $type); |
164 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
164 | + $this->config->setAppValue('testing', 'locking_'.$path, $type); |
|
165 | 165 | return new DataResponse(); |
166 | 166 | } catch (LockedException $e) { |
167 | 167 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | try { |
190 | 190 | $lockingProvider->releaseLock($path, $type); |
191 | - $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
191 | + $this->config->deleteAppValue('testing', 'locking_'.$path); |
|
192 | 192 | return new DataResponse(); |
193 | 193 | } catch (LockedException $e) { |
194 | 194 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | if (strpos($lock, 'locking_') === 0) { |
232 | 232 | $path = substr($lock, strlen('locking_')); |
233 | 233 | |
234 | - if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
234 | + if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
235 | 235 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
236 | - } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
236 | + } else if ($type === ILockingProvider::LOCK_SHARED && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
237 | 237 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
238 | 238 | } else { |
239 | 239 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
@@ -33,12 +33,12 @@ |
||
33 | 33 | */ |
34 | 34 | interface ICallbackResponse { |
35 | 35 | |
36 | - /** |
|
37 | - * Outputs the content that should be printed |
|
38 | - * |
|
39 | - * @param IOutput $output a small wrapper that handles output |
|
40 | - * @since 8.1.0 |
|
41 | - */ |
|
42 | - public function callback(IOutput $output); |
|
36 | + /** |
|
37 | + * Outputs the content that should be printed |
|
38 | + * |
|
39 | + * @param IOutput $output a small wrapper that handles output |
|
40 | + * @since 8.1.0 |
|
41 | + */ |
|
42 | + public function callback(IOutput $output); |
|
43 | 43 | |
44 | 44 | } |
@@ -33,193 +33,193 @@ |
||
33 | 33 | use OCP\IMemcache; |
34 | 34 | |
35 | 35 | class Memcached extends Cache implements IMemcache { |
36 | - use CASTrait; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var \Memcached $cache |
|
40 | - */ |
|
41 | - private static $cache = null; |
|
42 | - |
|
43 | - use CADTrait; |
|
44 | - |
|
45 | - public function __construct($prefix = '') { |
|
46 | - parent::__construct($prefix); |
|
47 | - if (is_null(self::$cache)) { |
|
48 | - self::$cache = new \Memcached(); |
|
49 | - |
|
50 | - $defaultOptions = [ |
|
51 | - \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
52 | - \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
53 | - \Memcached::OPT_SEND_TIMEOUT => 50, |
|
54 | - \Memcached::OPT_RECV_TIMEOUT => 50, |
|
55 | - \Memcached::OPT_POLL_TIMEOUT => 50, |
|
56 | - |
|
57 | - // Enable compression |
|
58 | - \Memcached::OPT_COMPRESSION => true, |
|
59 | - |
|
60 | - // Turn on consistent hashing |
|
61 | - \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
62 | - |
|
63 | - // Enable Binary Protocol |
|
64 | - //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
65 | - ]; |
|
66 | - // by default enable igbinary serializer if available |
|
67 | - if (\Memcached::HAVE_IGBINARY) { |
|
68 | - $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
69 | - \Memcached::SERIALIZER_IGBINARY; |
|
70 | - } |
|
71 | - $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
72 | - if (is_array($options)) { |
|
73 | - $options = $options + $defaultOptions; |
|
74 | - self::$cache->setOptions($options); |
|
75 | - } else { |
|
76 | - throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
77 | - } |
|
78 | - |
|
79 | - $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
80 | - if (!$servers) { |
|
81 | - $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
82 | - if ($server) { |
|
83 | - $servers = [$server]; |
|
84 | - } else { |
|
85 | - $servers = [['localhost', 11211]]; |
|
86 | - } |
|
87 | - } |
|
88 | - self::$cache->addServers($servers); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
94 | - */ |
|
95 | - protected function getNameSpace() { |
|
96 | - return $this->prefix; |
|
97 | - } |
|
98 | - |
|
99 | - public function get($key) { |
|
100 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
101 | - if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
102 | - return null; |
|
103 | - } else { |
|
104 | - return $result; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - public function set($key, $value, $ttl = 0) { |
|
109 | - if ($ttl > 0) { |
|
110 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
111 | - } else { |
|
112 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
113 | - } |
|
114 | - if ($result !== true) { |
|
115 | - $this->verifyReturnCode(); |
|
116 | - } |
|
117 | - return $result; |
|
118 | - } |
|
119 | - |
|
120 | - public function hasKey($key) { |
|
121 | - self::$cache->get($this->getNameSpace() . $key); |
|
122 | - return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
123 | - } |
|
124 | - |
|
125 | - public function remove($key) { |
|
126 | - $result= self::$cache->delete($this->getNameSpace() . $key); |
|
127 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
128 | - $this->verifyReturnCode(); |
|
129 | - } |
|
130 | - return $result; |
|
131 | - } |
|
132 | - |
|
133 | - public function clear($prefix = '') { |
|
134 | - $prefix = $this->getNameSpace() . $prefix; |
|
135 | - $allKeys = self::$cache->getAllKeys(); |
|
136 | - if ($allKeys === false) { |
|
137 | - // newer Memcached doesn't like getAllKeys(), flush everything |
|
138 | - self::$cache->flush(); |
|
139 | - return true; |
|
140 | - } |
|
141 | - $keys = array(); |
|
142 | - $prefixLength = strlen($prefix); |
|
143 | - foreach ($allKeys as $key) { |
|
144 | - if (substr($key, 0, $prefixLength) === $prefix) { |
|
145 | - $keys[] = $key; |
|
146 | - } |
|
147 | - } |
|
148 | - if (method_exists(self::$cache, 'deleteMulti')) { |
|
149 | - self::$cache->deleteMulti($keys); |
|
150 | - } else { |
|
151 | - foreach ($keys as $key) { |
|
152 | - self::$cache->delete($key); |
|
153 | - } |
|
154 | - } |
|
155 | - return true; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Set a value in the cache if it's not already stored |
|
160 | - * |
|
161 | - * @param string $key |
|
162 | - * @param mixed $value |
|
163 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
164 | - * @return bool |
|
165 | - * @throws \Exception |
|
166 | - */ |
|
167 | - public function add($key, $value, $ttl = 0) { |
|
168 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
169 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
170 | - $this->verifyReturnCode(); |
|
171 | - } |
|
172 | - return $result; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Increase a stored number |
|
177 | - * |
|
178 | - * @param string $key |
|
179 | - * @param int $step |
|
180 | - * @return int | bool |
|
181 | - */ |
|
182 | - public function inc($key, $step = 1) { |
|
183 | - $this->add($key, 0); |
|
184 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
185 | - |
|
186 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
187 | - return false; |
|
188 | - } |
|
189 | - |
|
190 | - return $result; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Decrease a stored number |
|
195 | - * |
|
196 | - * @param string $key |
|
197 | - * @param int $step |
|
198 | - * @return int | bool |
|
199 | - */ |
|
200 | - public function dec($key, $step = 1) { |
|
201 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
202 | - |
|
203 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - return $result; |
|
208 | - } |
|
209 | - |
|
210 | - static public function isAvailable() { |
|
211 | - return extension_loaded('memcached'); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @throws \Exception |
|
216 | - */ |
|
217 | - private function verifyReturnCode() { |
|
218 | - $code = self::$cache->getResultCode(); |
|
219 | - if ($code === \Memcached::RES_SUCCESS) { |
|
220 | - return; |
|
221 | - } |
|
222 | - $message = self::$cache->getResultMessage(); |
|
223 | - throw new \Exception("Error $code interacting with memcached : $message"); |
|
224 | - } |
|
36 | + use CASTrait; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var \Memcached $cache |
|
40 | + */ |
|
41 | + private static $cache = null; |
|
42 | + |
|
43 | + use CADTrait; |
|
44 | + |
|
45 | + public function __construct($prefix = '') { |
|
46 | + parent::__construct($prefix); |
|
47 | + if (is_null(self::$cache)) { |
|
48 | + self::$cache = new \Memcached(); |
|
49 | + |
|
50 | + $defaultOptions = [ |
|
51 | + \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
52 | + \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
53 | + \Memcached::OPT_SEND_TIMEOUT => 50, |
|
54 | + \Memcached::OPT_RECV_TIMEOUT => 50, |
|
55 | + \Memcached::OPT_POLL_TIMEOUT => 50, |
|
56 | + |
|
57 | + // Enable compression |
|
58 | + \Memcached::OPT_COMPRESSION => true, |
|
59 | + |
|
60 | + // Turn on consistent hashing |
|
61 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
62 | + |
|
63 | + // Enable Binary Protocol |
|
64 | + //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
65 | + ]; |
|
66 | + // by default enable igbinary serializer if available |
|
67 | + if (\Memcached::HAVE_IGBINARY) { |
|
68 | + $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
69 | + \Memcached::SERIALIZER_IGBINARY; |
|
70 | + } |
|
71 | + $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
72 | + if (is_array($options)) { |
|
73 | + $options = $options + $defaultOptions; |
|
74 | + self::$cache->setOptions($options); |
|
75 | + } else { |
|
76 | + throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
77 | + } |
|
78 | + |
|
79 | + $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
80 | + if (!$servers) { |
|
81 | + $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
82 | + if ($server) { |
|
83 | + $servers = [$server]; |
|
84 | + } else { |
|
85 | + $servers = [['localhost', 11211]]; |
|
86 | + } |
|
87 | + } |
|
88 | + self::$cache->addServers($servers); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
94 | + */ |
|
95 | + protected function getNameSpace() { |
|
96 | + return $this->prefix; |
|
97 | + } |
|
98 | + |
|
99 | + public function get($key) { |
|
100 | + $result = self::$cache->get($this->getNameSpace() . $key); |
|
101 | + if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
102 | + return null; |
|
103 | + } else { |
|
104 | + return $result; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + public function set($key, $value, $ttl = 0) { |
|
109 | + if ($ttl > 0) { |
|
110 | + $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
111 | + } else { |
|
112 | + $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
113 | + } |
|
114 | + if ($result !== true) { |
|
115 | + $this->verifyReturnCode(); |
|
116 | + } |
|
117 | + return $result; |
|
118 | + } |
|
119 | + |
|
120 | + public function hasKey($key) { |
|
121 | + self::$cache->get($this->getNameSpace() . $key); |
|
122 | + return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
123 | + } |
|
124 | + |
|
125 | + public function remove($key) { |
|
126 | + $result= self::$cache->delete($this->getNameSpace() . $key); |
|
127 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
128 | + $this->verifyReturnCode(); |
|
129 | + } |
|
130 | + return $result; |
|
131 | + } |
|
132 | + |
|
133 | + public function clear($prefix = '') { |
|
134 | + $prefix = $this->getNameSpace() . $prefix; |
|
135 | + $allKeys = self::$cache->getAllKeys(); |
|
136 | + if ($allKeys === false) { |
|
137 | + // newer Memcached doesn't like getAllKeys(), flush everything |
|
138 | + self::$cache->flush(); |
|
139 | + return true; |
|
140 | + } |
|
141 | + $keys = array(); |
|
142 | + $prefixLength = strlen($prefix); |
|
143 | + foreach ($allKeys as $key) { |
|
144 | + if (substr($key, 0, $prefixLength) === $prefix) { |
|
145 | + $keys[] = $key; |
|
146 | + } |
|
147 | + } |
|
148 | + if (method_exists(self::$cache, 'deleteMulti')) { |
|
149 | + self::$cache->deleteMulti($keys); |
|
150 | + } else { |
|
151 | + foreach ($keys as $key) { |
|
152 | + self::$cache->delete($key); |
|
153 | + } |
|
154 | + } |
|
155 | + return true; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Set a value in the cache if it's not already stored |
|
160 | + * |
|
161 | + * @param string $key |
|
162 | + * @param mixed $value |
|
163 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
164 | + * @return bool |
|
165 | + * @throws \Exception |
|
166 | + */ |
|
167 | + public function add($key, $value, $ttl = 0) { |
|
168 | + $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
169 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
170 | + $this->verifyReturnCode(); |
|
171 | + } |
|
172 | + return $result; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Increase a stored number |
|
177 | + * |
|
178 | + * @param string $key |
|
179 | + * @param int $step |
|
180 | + * @return int | bool |
|
181 | + */ |
|
182 | + public function inc($key, $step = 1) { |
|
183 | + $this->add($key, 0); |
|
184 | + $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
185 | + |
|
186 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
187 | + return false; |
|
188 | + } |
|
189 | + |
|
190 | + return $result; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Decrease a stored number |
|
195 | + * |
|
196 | + * @param string $key |
|
197 | + * @param int $step |
|
198 | + * @return int | bool |
|
199 | + */ |
|
200 | + public function dec($key, $step = 1) { |
|
201 | + $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
202 | + |
|
203 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + return $result; |
|
208 | + } |
|
209 | + |
|
210 | + static public function isAvailable() { |
|
211 | + return extension_loaded('memcached'); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @throws \Exception |
|
216 | + */ |
|
217 | + private function verifyReturnCode() { |
|
218 | + $code = self::$cache->getResultCode(); |
|
219 | + if ($code === \Memcached::RES_SUCCESS) { |
|
220 | + return; |
|
221 | + } |
|
222 | + $message = self::$cache->getResultMessage(); |
|
223 | + throw new \Exception("Error $code interacting with memcached : $message"); |
|
224 | + } |
|
225 | 225 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function get($key) { |
100 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
100 | + $result = self::$cache->get($this->getNameSpace().$key); |
|
101 | 101 | if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
102 | 102 | return null; |
103 | 103 | } else { |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | |
108 | 108 | public function set($key, $value, $ttl = 0) { |
109 | 109 | if ($ttl > 0) { |
110 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
110 | + $result = self::$cache->set($this->getNameSpace().$key, $value, $ttl); |
|
111 | 111 | } else { |
112 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
112 | + $result = self::$cache->set($this->getNameSpace().$key, $value); |
|
113 | 113 | } |
114 | 114 | if ($result !== true) { |
115 | 115 | $this->verifyReturnCode(); |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | public function hasKey($key) { |
121 | - self::$cache->get($this->getNameSpace() . $key); |
|
121 | + self::$cache->get($this->getNameSpace().$key); |
|
122 | 122 | return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
123 | 123 | } |
124 | 124 | |
125 | 125 | public function remove($key) { |
126 | - $result= self::$cache->delete($this->getNameSpace() . $key); |
|
126 | + $result = self::$cache->delete($this->getNameSpace().$key); |
|
127 | 127 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
128 | 128 | $this->verifyReturnCode(); |
129 | 129 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | public function clear($prefix = '') { |
134 | - $prefix = $this->getNameSpace() . $prefix; |
|
134 | + $prefix = $this->getNameSpace().$prefix; |
|
135 | 135 | $allKeys = self::$cache->getAllKeys(); |
136 | 136 | if ($allKeys === false) { |
137 | 137 | // newer Memcached doesn't like getAllKeys(), flush everything |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @throws \Exception |
166 | 166 | */ |
167 | 167 | public function add($key, $value, $ttl = 0) { |
168 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
168 | + $result = self::$cache->add($this->getPrefix().$key, $value, $ttl); |
|
169 | 169 | if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
170 | 170 | $this->verifyReturnCode(); |
171 | 171 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function inc($key, $step = 1) { |
183 | 183 | $this->add($key, 0); |
184 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
184 | + $result = self::$cache->increment($this->getPrefix().$key, $step); |
|
185 | 185 | |
186 | 186 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
187 | 187 | return false; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return int | bool |
199 | 199 | */ |
200 | 200 | public function dec($key, $step = 1) { |
201 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
201 | + $result = self::$cache->decrement($this->getPrefix().$key, $step); |
|
202 | 202 | |
203 | 203 | if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
204 | 204 | return false; |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | |
61 | 61 | $remoteStorages = $this->getRemoteStorages(); |
62 | 62 | |
63 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
63 | + $output->writeln(count($remoteStorages).' remote storage(s) need(s) to be checked'); |
|
64 | 64 | |
65 | 65 | $remoteShareIds = $this->getRemoteShareIds(); |
66 | 66 | |
67 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
67 | + $output->writeln(count($remoteShareIds).' remote share(s) exist'); |
|
68 | 68 | |
69 | 69 | foreach ($remoteShareIds as $id => $remoteShareId) { |
70 | 70 | if (isset($remoteStorages[$remoteShareId])) { |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | ->where($queryBuilder->expr()->like( |
143 | 143 | 'id', |
144 | 144 | // match all 'shared::' + 32 characters storages |
145 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
145 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::').str_repeat('_', 32)), |
|
146 | 146 | IQueryBuilder::PARAM_STR) |
147 | 147 | ) |
148 | 148 | ->andWhere($queryBuilder->expr()->notLike( |
149 | 149 | 'id', |
150 | 150 | // but not the ones starting with a '/', they are for normal shares |
151 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
151 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/').'%'), |
|
152 | 152 | IQueryBuilder::PARAM_STR) |
153 | 153 | )->orderBy('numeric_id'); |
154 | 154 | $query = $queryBuilder->execute(); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $remoteShareIds = []; |
173 | 173 | |
174 | 174 | while ($row = $query->fetch()) { |
175 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
175 | + $remoteShareIds[$row['id']] = 'shared::'.md5($row['share_token'].'@'.$row['remote']); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | return $remoteShareIds; |
@@ -37,147 +37,147 @@ |
||
37 | 37 | */ |
38 | 38 | class CleanupRemoteStorages extends Command { |
39 | 39 | |
40 | - /** |
|
41 | - * @var IDBConnection |
|
42 | - */ |
|
43 | - protected $connection; |
|
44 | - |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('sharing:cleanup-remote-storages') |
|
53 | - ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
54 | - ->addOption( |
|
55 | - 'dry-run', |
|
56 | - null, |
|
57 | - InputOption::VALUE_NONE, |
|
58 | - 'only show which storages would be deleted' |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
63 | - |
|
64 | - $remoteStorages = $this->getRemoteStorages(); |
|
65 | - |
|
66 | - $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
67 | - |
|
68 | - $remoteShareIds = $this->getRemoteShareIds(); |
|
69 | - |
|
70 | - $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
71 | - |
|
72 | - foreach ($remoteShareIds as $id => $remoteShareId) { |
|
73 | - if (isset($remoteStorages[$remoteShareId])) { |
|
74 | - if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
75 | - $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
76 | - } |
|
77 | - |
|
78 | - unset($remoteStorages[$remoteShareId]); |
|
79 | - } else { |
|
80 | - $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - if (empty($remoteStorages)) { |
|
85 | - $output->writeln('<info>no storages deleted</info>'); |
|
86 | - } else { |
|
87 | - $dryRun = $input->getOption('dry-run'); |
|
88 | - foreach ($remoteStorages as $id => $numericId) { |
|
89 | - if ($dryRun) { |
|
90 | - $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
91 | - $this->countFiles($numericId, $output); |
|
92 | - } else { |
|
93 | - $this->deleteStorage($id, $numericId, $output); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - public function countFiles($numericId, OutputInterface $output) { |
|
100 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
101 | - $queryBuilder->select($queryBuilder->func()->count('fileid')) |
|
102 | - ->from('filecache') |
|
103 | - ->where($queryBuilder->expr()->eq( |
|
104 | - 'storage', |
|
105 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
106 | - IQueryBuilder::PARAM_STR) |
|
107 | - ); |
|
108 | - $result = $queryBuilder->execute(); |
|
109 | - $count = $result->fetchColumn(); |
|
110 | - $output->writeln("$count files can be deleted for storage $numericId"); |
|
111 | - } |
|
112 | - |
|
113 | - public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
114 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
115 | - $queryBuilder->delete('storages') |
|
116 | - ->where($queryBuilder->expr()->eq( |
|
117 | - 'id', |
|
118 | - $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
119 | - IQueryBuilder::PARAM_STR) |
|
120 | - ); |
|
121 | - $output->write("deleting $id [$numericId] ... "); |
|
122 | - $count = $queryBuilder->execute(); |
|
123 | - $output->writeln("deleted $count storage"); |
|
124 | - $this->deleteFiles($numericId, $output); |
|
125 | - } |
|
126 | - |
|
127 | - public function deleteFiles($numericId, OutputInterface $output) { |
|
128 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
129 | - $queryBuilder->delete('filecache') |
|
130 | - ->where($queryBuilder->expr()->eq( |
|
131 | - 'storage', |
|
132 | - $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
133 | - IQueryBuilder::PARAM_STR) |
|
134 | - ); |
|
135 | - $output->write("deleting files for storage $numericId ... "); |
|
136 | - $count = $queryBuilder->execute(); |
|
137 | - $output->writeln("deleted $count files"); |
|
138 | - } |
|
139 | - |
|
140 | - public function getRemoteStorages() { |
|
141 | - |
|
142 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
143 | - $queryBuilder->select(['id', 'numeric_id']) |
|
144 | - ->from('storages') |
|
145 | - ->where($queryBuilder->expr()->like( |
|
146 | - 'id', |
|
147 | - // match all 'shared::' + 32 characters storages |
|
148 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
149 | - IQueryBuilder::PARAM_STR) |
|
150 | - ) |
|
151 | - ->andWhere($queryBuilder->expr()->notLike( |
|
152 | - 'id', |
|
153 | - // but not the ones starting with a '/', they are for normal shares |
|
154 | - $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
155 | - IQueryBuilder::PARAM_STR) |
|
156 | - )->orderBy('numeric_id'); |
|
157 | - $query = $queryBuilder->execute(); |
|
158 | - |
|
159 | - $remoteStorages = []; |
|
160 | - |
|
161 | - while ($row = $query->fetch()) { |
|
162 | - $remoteStorages[$row['id']] = $row['numeric_id']; |
|
163 | - } |
|
164 | - |
|
165 | - return $remoteStorages; |
|
166 | - } |
|
167 | - |
|
168 | - public function getRemoteShareIds() { |
|
169 | - |
|
170 | - $queryBuilder = $this->connection->getQueryBuilder(); |
|
171 | - $queryBuilder->select(['id', 'share_token', 'remote']) |
|
172 | - ->from('share_external'); |
|
173 | - $query = $queryBuilder->execute(); |
|
174 | - |
|
175 | - $remoteShareIds = []; |
|
176 | - |
|
177 | - while ($row = $query->fetch()) { |
|
178 | - $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
179 | - } |
|
180 | - |
|
181 | - return $remoteShareIds; |
|
182 | - } |
|
40 | + /** |
|
41 | + * @var IDBConnection |
|
42 | + */ |
|
43 | + protected $connection; |
|
44 | + |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('sharing:cleanup-remote-storages') |
|
53 | + ->setDescription('Cleanup shared storage entries that have no matching entry in the shares_external table') |
|
54 | + ->addOption( |
|
55 | + 'dry-run', |
|
56 | + null, |
|
57 | + InputOption::VALUE_NONE, |
|
58 | + 'only show which storages would be deleted' |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
63 | + |
|
64 | + $remoteStorages = $this->getRemoteStorages(); |
|
65 | + |
|
66 | + $output->writeln(count($remoteStorages) . ' remote storage(s) need(s) to be checked'); |
|
67 | + |
|
68 | + $remoteShareIds = $this->getRemoteShareIds(); |
|
69 | + |
|
70 | + $output->writeln(count($remoteShareIds) . ' remote share(s) exist'); |
|
71 | + |
|
72 | + foreach ($remoteShareIds as $id => $remoteShareId) { |
|
73 | + if (isset($remoteStorages[$remoteShareId])) { |
|
74 | + if ($input->getOption('dry-run') || $output->isVerbose()) { |
|
75 | + $output->writeln("<info>$remoteShareId belongs to remote share $id</info>"); |
|
76 | + } |
|
77 | + |
|
78 | + unset($remoteStorages[$remoteShareId]); |
|
79 | + } else { |
|
80 | + $output->writeln("<comment>$remoteShareId for share $id has no matching storage, yet</comment>"); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + if (empty($remoteStorages)) { |
|
85 | + $output->writeln('<info>no storages deleted</info>'); |
|
86 | + } else { |
|
87 | + $dryRun = $input->getOption('dry-run'); |
|
88 | + foreach ($remoteStorages as $id => $numericId) { |
|
89 | + if ($dryRun) { |
|
90 | + $output->writeln("<error>$id [$numericId] can be deleted</error>"); |
|
91 | + $this->countFiles($numericId, $output); |
|
92 | + } else { |
|
93 | + $this->deleteStorage($id, $numericId, $output); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + public function countFiles($numericId, OutputInterface $output) { |
|
100 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
101 | + $queryBuilder->select($queryBuilder->func()->count('fileid')) |
|
102 | + ->from('filecache') |
|
103 | + ->where($queryBuilder->expr()->eq( |
|
104 | + 'storage', |
|
105 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
106 | + IQueryBuilder::PARAM_STR) |
|
107 | + ); |
|
108 | + $result = $queryBuilder->execute(); |
|
109 | + $count = $result->fetchColumn(); |
|
110 | + $output->writeln("$count files can be deleted for storage $numericId"); |
|
111 | + } |
|
112 | + |
|
113 | + public function deleteStorage($id, $numericId, OutputInterface $output) { |
|
114 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
115 | + $queryBuilder->delete('storages') |
|
116 | + ->where($queryBuilder->expr()->eq( |
|
117 | + 'id', |
|
118 | + $queryBuilder->createNamedParameter($id, IQueryBuilder::PARAM_STR), |
|
119 | + IQueryBuilder::PARAM_STR) |
|
120 | + ); |
|
121 | + $output->write("deleting $id [$numericId] ... "); |
|
122 | + $count = $queryBuilder->execute(); |
|
123 | + $output->writeln("deleted $count storage"); |
|
124 | + $this->deleteFiles($numericId, $output); |
|
125 | + } |
|
126 | + |
|
127 | + public function deleteFiles($numericId, OutputInterface $output) { |
|
128 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
129 | + $queryBuilder->delete('filecache') |
|
130 | + ->where($queryBuilder->expr()->eq( |
|
131 | + 'storage', |
|
132 | + $queryBuilder->createNamedParameter($numericId, IQueryBuilder::PARAM_STR), |
|
133 | + IQueryBuilder::PARAM_STR) |
|
134 | + ); |
|
135 | + $output->write("deleting files for storage $numericId ... "); |
|
136 | + $count = $queryBuilder->execute(); |
|
137 | + $output->writeln("deleted $count files"); |
|
138 | + } |
|
139 | + |
|
140 | + public function getRemoteStorages() { |
|
141 | + |
|
142 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
143 | + $queryBuilder->select(['id', 'numeric_id']) |
|
144 | + ->from('storages') |
|
145 | + ->where($queryBuilder->expr()->like( |
|
146 | + 'id', |
|
147 | + // match all 'shared::' + 32 characters storages |
|
148 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::') . str_repeat('_', 32)), |
|
149 | + IQueryBuilder::PARAM_STR) |
|
150 | + ) |
|
151 | + ->andWhere($queryBuilder->expr()->notLike( |
|
152 | + 'id', |
|
153 | + // but not the ones starting with a '/', they are for normal shares |
|
154 | + $queryBuilder->createNamedParameter($this->connection->escapeLikeParameter('shared::/') . '%'), |
|
155 | + IQueryBuilder::PARAM_STR) |
|
156 | + )->orderBy('numeric_id'); |
|
157 | + $query = $queryBuilder->execute(); |
|
158 | + |
|
159 | + $remoteStorages = []; |
|
160 | + |
|
161 | + while ($row = $query->fetch()) { |
|
162 | + $remoteStorages[$row['id']] = $row['numeric_id']; |
|
163 | + } |
|
164 | + |
|
165 | + return $remoteStorages; |
|
166 | + } |
|
167 | + |
|
168 | + public function getRemoteShareIds() { |
|
169 | + |
|
170 | + $queryBuilder = $this->connection->getQueryBuilder(); |
|
171 | + $queryBuilder->select(['id', 'share_token', 'remote']) |
|
172 | + ->from('share_external'); |
|
173 | + $query = $queryBuilder->execute(); |
|
174 | + |
|
175 | + $remoteShareIds = []; |
|
176 | + |
|
177 | + while ($row = $query->fetch()) { |
|
178 | + $remoteShareIds[$row['id']] = 'shared::' . md5($row['share_token'] . '@' . $row['remote']); |
|
179 | + } |
|
180 | + |
|
181 | + return $remoteShareIds; |
|
182 | + } |
|
183 | 183 | } |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
56 | 56 | */ |
57 | - public function __call($name,$arguments) { |
|
58 | - return call_user_func_array(array($this->statement,$name), $arguments); |
|
57 | + public function __call($name, $arguments) { |
|
58 | + return call_user_func_array(array($this->statement, $name), $arguments); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @param array $input |
65 | 65 | * @return \OC_DB_StatementWrapper|int|bool |
66 | 66 | */ |
67 | - public function execute($input= []) { |
|
67 | + public function execute($input = []) { |
|
68 | 68 | $this->lastArguments = $input; |
69 | 69 | if (count($input) > 0) { |
70 | 70 | $result = $this->statement->execute($input); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param integer|null $length max length when using an OUT bind |
114 | 114 | * @return boolean |
115 | 115 | */ |
116 | - public function bindParam($column, &$variable, $type = null, $length = null){ |
|
116 | + public function bindParam($column, &$variable, $type = null, $length = null) { |
|
117 | 117 | return $this->statement->bindParam($column, $variable, $type, $length); |
118 | 118 | } |
119 | 119 | } |
@@ -37,83 +37,83 @@ |
||
37 | 37 | * @method array fetchAll(integer $fetchMode = null); |
38 | 38 | */ |
39 | 39 | class OC_DB_StatementWrapper { |
40 | - /** |
|
41 | - * @var \Doctrine\DBAL\Driver\Statement |
|
42 | - */ |
|
43 | - private $statement = null; |
|
44 | - private $isManipulation = false; |
|
45 | - private $lastArguments = array(); |
|
40 | + /** |
|
41 | + * @var \Doctrine\DBAL\Driver\Statement |
|
42 | + */ |
|
43 | + private $statement = null; |
|
44 | + private $isManipulation = false; |
|
45 | + private $lastArguments = array(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param boolean $isManipulation |
|
49 | - */ |
|
50 | - public function __construct($statement, $isManipulation) { |
|
51 | - $this->statement = $statement; |
|
52 | - $this->isManipulation = $isManipulation; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @param boolean $isManipulation |
|
49 | + */ |
|
50 | + public function __construct($statement, $isManipulation) { |
|
51 | + $this->statement = $statement; |
|
52 | + $this->isManipulation = $isManipulation; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | - */ |
|
58 | - public function __call($name,$arguments) { |
|
59 | - return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | - } |
|
55 | + /** |
|
56 | + * pass all other function directly to the \Doctrine\DBAL\Driver\Statement |
|
57 | + */ |
|
58 | + public function __call($name,$arguments) { |
|
59 | + return call_user_func_array(array($this->statement,$name), $arguments); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * make execute return the result instead of a bool |
|
64 | - * |
|
65 | - * @param array $input |
|
66 | - * @return \OC_DB_StatementWrapper|int|bool |
|
67 | - */ |
|
68 | - public function execute($input= []) { |
|
69 | - $this->lastArguments = $input; |
|
70 | - if (count($input) > 0) { |
|
71 | - $result = $this->statement->execute($input); |
|
72 | - } else { |
|
73 | - $result = $this->statement->execute(); |
|
74 | - } |
|
62 | + /** |
|
63 | + * make execute return the result instead of a bool |
|
64 | + * |
|
65 | + * @param array $input |
|
66 | + * @return \OC_DB_StatementWrapper|int|bool |
|
67 | + */ |
|
68 | + public function execute($input= []) { |
|
69 | + $this->lastArguments = $input; |
|
70 | + if (count($input) > 0) { |
|
71 | + $result = $this->statement->execute($input); |
|
72 | + } else { |
|
73 | + $result = $this->statement->execute(); |
|
74 | + } |
|
75 | 75 | |
76 | - if ($result === false) { |
|
77 | - return false; |
|
78 | - } |
|
79 | - if ($this->isManipulation) { |
|
80 | - return $this->statement->rowCount(); |
|
81 | - } else { |
|
82 | - return $this; |
|
83 | - } |
|
84 | - } |
|
76 | + if ($result === false) { |
|
77 | + return false; |
|
78 | + } |
|
79 | + if ($this->isManipulation) { |
|
80 | + return $this->statement->rowCount(); |
|
81 | + } else { |
|
82 | + return $this; |
|
83 | + } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * provide an alias for fetch |
|
88 | - * |
|
89 | - * @return mixed |
|
90 | - */ |
|
91 | - public function fetchRow() { |
|
92 | - return $this->statement->fetch(); |
|
93 | - } |
|
86 | + /** |
|
87 | + * provide an alias for fetch |
|
88 | + * |
|
89 | + * @return mixed |
|
90 | + */ |
|
91 | + public function fetchRow() { |
|
92 | + return $this->statement->fetch(); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Provide a simple fetchOne. |
|
97 | - * |
|
98 | - * fetch single column from the next row |
|
99 | - * @param int $column the column number to fetch |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function fetchOne($column = 0) { |
|
103 | - return $this->statement->fetchColumn($column); |
|
104 | - } |
|
95 | + /** |
|
96 | + * Provide a simple fetchOne. |
|
97 | + * |
|
98 | + * fetch single column from the next row |
|
99 | + * @param int $column the column number to fetch |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function fetchOne($column = 0) { |
|
103 | + return $this->statement->fetchColumn($column); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | - * SQL statement that was use to prepare the statement. |
|
109 | - * |
|
110 | - * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | - * @param mixed $variable The variable to bind |
|
112 | - * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | - * @param integer|null $length max length when using an OUT bind |
|
114 | - * @return boolean |
|
115 | - */ |
|
116 | - public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | - return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | - } |
|
106 | + /** |
|
107 | + * Binds a PHP variable to a corresponding named or question mark placeholder in the |
|
108 | + * SQL statement that was use to prepare the statement. |
|
109 | + * |
|
110 | + * @param mixed $column Either the placeholder name or the 1-indexed placeholder index |
|
111 | + * @param mixed $variable The variable to bind |
|
112 | + * @param integer|null $type one of the PDO::PARAM_* constants |
|
113 | + * @param integer|null $length max length when using an OUT bind |
|
114 | + * @return boolean |
|
115 | + */ |
|
116 | + public function bindParam($column, &$variable, $type = null, $length = null){ |
|
117 | + return $this->statement->bindParam($column, $variable, $type, $length); |
|
118 | + } |
|
119 | 119 | } |
@@ -29,179 +29,179 @@ |
||
29 | 29 | |
30 | 30 | class MigrationSchemaChecker extends NodeVisitorAbstract { |
31 | 31 | |
32 | - /** @var string */ |
|
33 | - protected $schemaVariableName = null; |
|
34 | - /** @var array */ |
|
35 | - protected $tableVariableNames = []; |
|
36 | - /** @var array */ |
|
37 | - public $errors = []; |
|
32 | + /** @var string */ |
|
33 | + protected $schemaVariableName = null; |
|
34 | + /** @var array */ |
|
35 | + protected $tableVariableNames = []; |
|
36 | + /** @var array */ |
|
37 | + public $errors = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Node $node |
|
41 | - * @return void |
|
42 | - * |
|
43 | - * @suppress PhanUndeclaredProperty |
|
44 | - */ |
|
45 | - public function enterNode(Node $node) { |
|
46 | - /** |
|
47 | - * Check tables |
|
48 | - */ |
|
49 | - if ($this->schemaVariableName !== null && |
|
50 | - $node instanceof Node\Expr\Assign && |
|
51 | - $node->var instanceof Node\Expr\Variable && |
|
52 | - $node->expr instanceof Node\Expr\MethodCall && |
|
53 | - $node->expr->var instanceof Node\Expr\Variable && |
|
54 | - $node->expr->var->name === $this->schemaVariableName) { |
|
39 | + /** |
|
40 | + * @param Node $node |
|
41 | + * @return void |
|
42 | + * |
|
43 | + * @suppress PhanUndeclaredProperty |
|
44 | + */ |
|
45 | + public function enterNode(Node $node) { |
|
46 | + /** |
|
47 | + * Check tables |
|
48 | + */ |
|
49 | + if ($this->schemaVariableName !== null && |
|
50 | + $node instanceof Node\Expr\Assign && |
|
51 | + $node->var instanceof Node\Expr\Variable && |
|
52 | + $node->expr instanceof Node\Expr\MethodCall && |
|
53 | + $node->expr->var instanceof Node\Expr\Variable && |
|
54 | + $node->expr->var->name === $this->schemaVariableName) { |
|
55 | 55 | |
56 | - if ($node->expr->name === 'createTable') { |
|
57 | - if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
58 | - if (!$this->checkNameLength($node->expr->args[0]->value->value)) { |
|
59 | - $this->errors[] = [ |
|
60 | - 'line' => $node->getLine(), |
|
61 | - 'disallowedToken' => $node->expr->args[0]->value->value, |
|
62 | - 'reason' => 'Table name is too long (max. 27)', |
|
63 | - ]; |
|
64 | - } else { |
|
65 | - $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
66 | - } |
|
67 | - } |
|
68 | - } else if ($node->expr->name === 'getTable') { |
|
69 | - if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
70 | - $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
71 | - } |
|
72 | - } |
|
73 | - } else if ($this->schemaVariableName !== null && |
|
74 | - $node instanceof Node\Expr\MethodCall && |
|
75 | - $node->var instanceof Node\Expr\Variable && |
|
76 | - $node->var->name === $this->schemaVariableName) { |
|
56 | + if ($node->expr->name === 'createTable') { |
|
57 | + if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
58 | + if (!$this->checkNameLength($node->expr->args[0]->value->value)) { |
|
59 | + $this->errors[] = [ |
|
60 | + 'line' => $node->getLine(), |
|
61 | + 'disallowedToken' => $node->expr->args[0]->value->value, |
|
62 | + 'reason' => 'Table name is too long (max. 27)', |
|
63 | + ]; |
|
64 | + } else { |
|
65 | + $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
66 | + } |
|
67 | + } |
|
68 | + } else if ($node->expr->name === 'getTable') { |
|
69 | + if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
70 | + $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
71 | + } |
|
72 | + } |
|
73 | + } else if ($this->schemaVariableName !== null && |
|
74 | + $node instanceof Node\Expr\MethodCall && |
|
75 | + $node->var instanceof Node\Expr\Variable && |
|
76 | + $node->var->name === $this->schemaVariableName) { |
|
77 | 77 | |
78 | - if ($node->name === 'renameTable') { |
|
79 | - $this->errors[] = [ |
|
80 | - 'line' => $node->getLine(), |
|
81 | - 'disallowedToken' => 'Deprecated method', |
|
82 | - 'reason' => sprintf( |
|
83 | - '`$%s->renameTable()` must not be used', |
|
84 | - $node->var->name |
|
85 | - ), |
|
86 | - ]; |
|
87 | - } |
|
78 | + if ($node->name === 'renameTable') { |
|
79 | + $this->errors[] = [ |
|
80 | + 'line' => $node->getLine(), |
|
81 | + 'disallowedToken' => 'Deprecated method', |
|
82 | + 'reason' => sprintf( |
|
83 | + '`$%s->renameTable()` must not be used', |
|
84 | + $node->var->name |
|
85 | + ), |
|
86 | + ]; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Check columns and Indexes |
|
91 | - */ |
|
92 | - } else if (!empty($this->tableVariableNames) && |
|
93 | - $node instanceof Node\Expr\MethodCall && |
|
94 | - $node->var instanceof Node\Expr\Variable && |
|
95 | - isset($this->tableVariableNames[$node->var->name])) { |
|
89 | + /** |
|
90 | + * Check columns and Indexes |
|
91 | + */ |
|
92 | + } else if (!empty($this->tableVariableNames) && |
|
93 | + $node instanceof Node\Expr\MethodCall && |
|
94 | + $node->var instanceof Node\Expr\Variable && |
|
95 | + isset($this->tableVariableNames[$node->var->name])) { |
|
96 | 96 | |
97 | - if ($node->name === 'addColumn' || $node->name === 'changeColumn') { |
|
98 | - if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) { |
|
99 | - if (!$this->checkNameLength($node->args[0]->value->value)) { |
|
100 | - $this->errors[] = [ |
|
101 | - 'line' => $node->getLine(), |
|
102 | - 'disallowedToken' => $node->args[0]->value->value, |
|
103 | - 'reason' => sprintf( |
|
104 | - 'Column name is too long on table `%s` (max. 27)', |
|
105 | - $this->tableVariableNames[$node->var->name] |
|
106 | - ), |
|
107 | - ]; |
|
108 | - } |
|
97 | + if ($node->name === 'addColumn' || $node->name === 'changeColumn') { |
|
98 | + if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) { |
|
99 | + if (!$this->checkNameLength($node->args[0]->value->value)) { |
|
100 | + $this->errors[] = [ |
|
101 | + 'line' => $node->getLine(), |
|
102 | + 'disallowedToken' => $node->args[0]->value->value, |
|
103 | + 'reason' => sprintf( |
|
104 | + 'Column name is too long on table `%s` (max. 27)', |
|
105 | + $this->tableVariableNames[$node->var->name] |
|
106 | + ), |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | |
110 | - // On autoincrement the max length of the table name is 21 instead of 27 |
|
111 | - if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) { |
|
112 | - /** @var Node\Expr\Array_ $options */ |
|
113 | - $options = $node->args[2]->value; |
|
114 | - if ($this->checkColumnForAutoincrement($options)) { |
|
115 | - if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) { |
|
116 | - $this->errors[] = [ |
|
117 | - 'line' => $node->getLine(), |
|
118 | - 'disallowedToken' => $this->tableVariableNames[$node->var->name], |
|
119 | - 'reason' => 'Table name is too long because of autoincrement (max. 21)', |
|
120 | - ]; |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } else if ($node->name === 'addIndex' || |
|
126 | - $node->name === 'addUniqueIndex' || |
|
127 | - $node->name === 'renameIndex' || |
|
128 | - $node->name === 'setPrimaryKey') { |
|
129 | - if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) { |
|
130 | - if (!$this->checkNameLength($node->args[1]->value->value)) { |
|
131 | - $this->errors[] = [ |
|
132 | - 'line' => $node->getLine(), |
|
133 | - 'disallowedToken' => $node->args[1]->value->value, |
|
134 | - 'reason' => sprintf( |
|
135 | - 'Index name is too long on table `%s` (max. 27)', |
|
136 | - $this->tableVariableNames[$node->var->name] |
|
137 | - ), |
|
138 | - ]; |
|
139 | - } |
|
140 | - } |
|
141 | - } else if ($node->name === 'addForeignKeyConstraint') { |
|
142 | - if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) { |
|
143 | - if (!$this->checkNameLength($node->args[4]->value->value)) { |
|
144 | - $this->errors[] = [ |
|
145 | - 'line' => $node->getLine(), |
|
146 | - 'disallowedToken' => $node->args[4]->value->value, |
|
147 | - 'reason' => sprintf( |
|
148 | - 'Constraint name is too long on table `%s` (max. 27)', |
|
149 | - $this->tableVariableNames[$node->var->name] |
|
150 | - ), |
|
151 | - ]; |
|
152 | - } |
|
153 | - } |
|
154 | - } else if ($node->name === 'renameColumn') { |
|
155 | - $this->errors[] = [ |
|
156 | - 'line' => $node->getLine(), |
|
157 | - 'disallowedToken' => 'Deprecated method', |
|
158 | - 'reason' => sprintf( |
|
159 | - '`$%s->renameColumn()` must not be used', |
|
160 | - $node->var->name |
|
161 | - ), |
|
162 | - ]; |
|
163 | - } |
|
110 | + // On autoincrement the max length of the table name is 21 instead of 27 |
|
111 | + if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) { |
|
112 | + /** @var Node\Expr\Array_ $options */ |
|
113 | + $options = $node->args[2]->value; |
|
114 | + if ($this->checkColumnForAutoincrement($options)) { |
|
115 | + if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) { |
|
116 | + $this->errors[] = [ |
|
117 | + 'line' => $node->getLine(), |
|
118 | + 'disallowedToken' => $this->tableVariableNames[$node->var->name], |
|
119 | + 'reason' => 'Table name is too long because of autoincrement (max. 21)', |
|
120 | + ]; |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } else if ($node->name === 'addIndex' || |
|
126 | + $node->name === 'addUniqueIndex' || |
|
127 | + $node->name === 'renameIndex' || |
|
128 | + $node->name === 'setPrimaryKey') { |
|
129 | + if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) { |
|
130 | + if (!$this->checkNameLength($node->args[1]->value->value)) { |
|
131 | + $this->errors[] = [ |
|
132 | + 'line' => $node->getLine(), |
|
133 | + 'disallowedToken' => $node->args[1]->value->value, |
|
134 | + 'reason' => sprintf( |
|
135 | + 'Index name is too long on table `%s` (max. 27)', |
|
136 | + $this->tableVariableNames[$node->var->name] |
|
137 | + ), |
|
138 | + ]; |
|
139 | + } |
|
140 | + } |
|
141 | + } else if ($node->name === 'addForeignKeyConstraint') { |
|
142 | + if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) { |
|
143 | + if (!$this->checkNameLength($node->args[4]->value->value)) { |
|
144 | + $this->errors[] = [ |
|
145 | + 'line' => $node->getLine(), |
|
146 | + 'disallowedToken' => $node->args[4]->value->value, |
|
147 | + 'reason' => sprintf( |
|
148 | + 'Constraint name is too long on table `%s` (max. 27)', |
|
149 | + $this->tableVariableNames[$node->var->name] |
|
150 | + ), |
|
151 | + ]; |
|
152 | + } |
|
153 | + } |
|
154 | + } else if ($node->name === 'renameColumn') { |
|
155 | + $this->errors[] = [ |
|
156 | + 'line' => $node->getLine(), |
|
157 | + 'disallowedToken' => 'Deprecated method', |
|
158 | + 'reason' => sprintf( |
|
159 | + '`$%s->renameColumn()` must not be used', |
|
160 | + $node->var->name |
|
161 | + ), |
|
162 | + ]; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Find the schema |
|
167 | - */ |
|
168 | - } else if ($node instanceof Node\Expr\Assign && |
|
169 | - $node->expr instanceof Node\Expr\FuncCall && |
|
170 | - $node->var instanceof Node\Expr\Variable && |
|
171 | - $node->expr->name instanceof Node\Expr\Variable && |
|
172 | - $node->expr->name->name === 'schemaClosure') { |
|
173 | - // E.g. $schema = $schemaClosure(); |
|
174 | - $this->schemaVariableName = $node->var->name; |
|
175 | - } |
|
176 | - } |
|
165 | + /** |
|
166 | + * Find the schema |
|
167 | + */ |
|
168 | + } else if ($node instanceof Node\Expr\Assign && |
|
169 | + $node->expr instanceof Node\Expr\FuncCall && |
|
170 | + $node->var instanceof Node\Expr\Variable && |
|
171 | + $node->expr->name instanceof Node\Expr\Variable && |
|
172 | + $node->expr->name->name === 'schemaClosure') { |
|
173 | + // E.g. $schema = $schemaClosure(); |
|
174 | + $this->schemaVariableName = $node->var->name; |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - protected function checkNameLength($tableName, $hasAutoincrement = false) { |
|
179 | - if ($hasAutoincrement) { |
|
180 | - return strlen($tableName) <= 21; |
|
181 | - } |
|
182 | - return strlen($tableName) <= 27; |
|
183 | - } |
|
178 | + protected function checkNameLength($tableName, $hasAutoincrement = false) { |
|
179 | + if ($hasAutoincrement) { |
|
180 | + return strlen($tableName) <= 21; |
|
181 | + } |
|
182 | + return strlen($tableName) <= 27; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param Node\Expr\Array_ $optionsArray |
|
187 | - * @return bool Whether the column is an autoincrement column |
|
188 | - */ |
|
189 | - protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) { |
|
190 | - foreach ($optionsArray->items as $option) { |
|
191 | - if ($option->key instanceof Node\Scalar\String_) { |
|
192 | - if ($option->key->value === 'autoincrement' && |
|
193 | - $option->value instanceof Node\Expr\ConstFetch) { |
|
194 | - /** @var Node\Expr\ConstFetch $const */ |
|
195 | - $const = $option->value; |
|
185 | + /** |
|
186 | + * @param Node\Expr\Array_ $optionsArray |
|
187 | + * @return bool Whether the column is an autoincrement column |
|
188 | + */ |
|
189 | + protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) { |
|
190 | + foreach ($optionsArray->items as $option) { |
|
191 | + if ($option->key instanceof Node\Scalar\String_) { |
|
192 | + if ($option->key->value === 'autoincrement' && |
|
193 | + $option->value instanceof Node\Expr\ConstFetch) { |
|
194 | + /** @var Node\Expr\ConstFetch $const */ |
|
195 | + $const = $option->value; |
|
196 | 196 | |
197 | - if ($const->name instanceof Name && |
|
198 | - $const->name->parts === ['true']) { |
|
199 | - return true; |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
197 | + if ($const->name instanceof Name && |
|
198 | + $const->name->parts === ['true']) { |
|
199 | + return true; |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - return false; |
|
206 | - } |
|
205 | + return false; |
|
206 | + } |
|
207 | 207 | } |