@@ -30,33 +30,33 @@ |
||
30 | 30 | */ |
31 | 31 | interface IObjectStore { |
32 | 32 | |
33 | - /** |
|
34 | - * @return string the container or bucket name where objects are stored |
|
35 | - * @since 7.0.0 |
|
36 | - */ |
|
37 | - public function getStorageId(); |
|
33 | + /** |
|
34 | + * @return string the container or bucket name where objects are stored |
|
35 | + * @since 7.0.0 |
|
36 | + */ |
|
37 | + public function getStorageId(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $urn the unified resource name used to identify the object |
|
41 | - * @return resource stream with the read data |
|
42 | - * @throws \Exception when something goes wrong, message will be logged |
|
43 | - * @since 7.0.0 |
|
44 | - */ |
|
45 | - public function readObject($urn); |
|
39 | + /** |
|
40 | + * @param string $urn the unified resource name used to identify the object |
|
41 | + * @return resource stream with the read data |
|
42 | + * @throws \Exception when something goes wrong, message will be logged |
|
43 | + * @since 7.0.0 |
|
44 | + */ |
|
45 | + public function readObject($urn); |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $urn the unified resource name used to identify the object |
|
49 | - * @param resource $stream stream with the data to write |
|
50 | - * @throws \Exception when something goes wrong, message will be logged |
|
51 | - * @since 7.0.0 |
|
52 | - */ |
|
53 | - public function writeObject($urn, $stream); |
|
47 | + /** |
|
48 | + * @param string $urn the unified resource name used to identify the object |
|
49 | + * @param resource $stream stream with the data to write |
|
50 | + * @throws \Exception when something goes wrong, message will be logged |
|
51 | + * @since 7.0.0 |
|
52 | + */ |
|
53 | + public function writeObject($urn, $stream); |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param string $urn the unified resource name used to identify the object |
|
57 | - * @return void |
|
58 | - * @throws \Exception when something goes wrong, message will be logged |
|
59 | - * @since 7.0.0 |
|
60 | - */ |
|
61 | - public function deleteObject($urn); |
|
55 | + /** |
|
56 | + * @param string $urn the unified resource name used to identify the object |
|
57 | + * @return void |
|
58 | + * @throws \Exception when something goes wrong, message will be logged |
|
59 | + * @since 7.0.0 |
|
60 | + */ |
|
61 | + public function deleteObject($urn); |
|
62 | 62 | } |
@@ -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 | } |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param array $headers additional key value based headers |
47 | 47 | * @since 8.1.0 |
48 | 48 | */ |
49 | - public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | - $headers=[]) { |
|
49 | + public function __construct($data = '', $statusCode = Http::STATUS_OK, |
|
50 | + $headers = []) { |
|
51 | 51 | $this->data = $data; |
52 | 52 | $this->setStatus($statusCode); |
53 | 53 | $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return DataDisplayResponse Reference to this object |
71 | 71 | * @since 8.1.0 |
72 | 72 | */ |
73 | - public function setData($data){ |
|
73 | + public function setData($data) { |
|
74 | 74 | $this->data = $data; |
75 | 75 | |
76 | 76 | return $this; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @return string the data |
83 | 83 | * @since 8.1.0 |
84 | 84 | */ |
85 | - public function getData(){ |
|
85 | + public function getData() { |
|
86 | 86 | return $this->data; |
87 | 87 | } |
88 | 88 |
@@ -33,57 +33,57 @@ |
||
33 | 33 | */ |
34 | 34 | class DataDisplayResponse extends Response { |
35 | 35 | |
36 | - /** |
|
37 | - * response data |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $data; |
|
36 | + /** |
|
37 | + * response data |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $data; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @param string $data the data to display |
|
45 | - * @param int $statusCode the Http status code, defaults to 200 |
|
46 | - * @param array $headers additional key value based headers |
|
47 | - * @since 8.1.0 |
|
48 | - */ |
|
49 | - public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | - $headers=[]) { |
|
51 | - $this->data = $data; |
|
52 | - $this->setStatus($statusCode); |
|
53 | - $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
54 | - $this->addHeader('Content-Disposition', 'inline; filename=""'); |
|
55 | - } |
|
43 | + /** |
|
44 | + * @param string $data the data to display |
|
45 | + * @param int $statusCode the Http status code, defaults to 200 |
|
46 | + * @param array $headers additional key value based headers |
|
47 | + * @since 8.1.0 |
|
48 | + */ |
|
49 | + public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
50 | + $headers=[]) { |
|
51 | + $this->data = $data; |
|
52 | + $this->setStatus($statusCode); |
|
53 | + $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
54 | + $this->addHeader('Content-Disposition', 'inline; filename=""'); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Outputs data. No processing is done. |
|
59 | - * @return string |
|
60 | - * @since 8.1.0 |
|
61 | - */ |
|
62 | - public function render() { |
|
63 | - return $this->data; |
|
64 | - } |
|
57 | + /** |
|
58 | + * Outputs data. No processing is done. |
|
59 | + * @return string |
|
60 | + * @since 8.1.0 |
|
61 | + */ |
|
62 | + public function render() { |
|
63 | + return $this->data; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * Sets values in the data |
|
69 | - * @param string $data the data to display |
|
70 | - * @return DataDisplayResponse Reference to this object |
|
71 | - * @since 8.1.0 |
|
72 | - */ |
|
73 | - public function setData($data){ |
|
74 | - $this->data = $data; |
|
67 | + /** |
|
68 | + * Sets values in the data |
|
69 | + * @param string $data the data to display |
|
70 | + * @return DataDisplayResponse Reference to this object |
|
71 | + * @since 8.1.0 |
|
72 | + */ |
|
73 | + public function setData($data){ |
|
74 | + $this->data = $data; |
|
75 | 75 | |
76 | - return $this; |
|
77 | - } |
|
76 | + return $this; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Used to get the set parameters |
|
82 | - * @return string the data |
|
83 | - * @since 8.1.0 |
|
84 | - */ |
|
85 | - public function getData(){ |
|
86 | - return $this->data; |
|
87 | - } |
|
80 | + /** |
|
81 | + * Used to get the set parameters |
|
82 | + * @return string the data |
|
83 | + * @since 8.1.0 |
|
84 | + */ |
|
85 | + public function getData(){ |
|
86 | + return $this->data; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | } |
@@ -52,119 +52,119 @@ |
||
52 | 52 | */ |
53 | 53 | interface IManager { |
54 | 54 | |
55 | - /** |
|
56 | - * This function is used to search and find contacts within the users address books. |
|
57 | - * In case $pattern is empty all contacts will be returned. |
|
58 | - * |
|
59 | - * Example: |
|
60 | - * Following function shows how to search for contacts for the name and the email address. |
|
61 | - * |
|
62 | - * public static function getMatchingRecipient($term) { |
|
63 | - * $cm = \OC::$server->getContactsManager(); |
|
64 | - * // The API is not active -> nothing to do |
|
65 | - * if (!$cm->isEnabled()) { |
|
66 | - * return array(); |
|
67 | - * } |
|
68 | - * |
|
69 | - * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
70 | - * $receivers = array(); |
|
71 | - * foreach ($result as $r) { |
|
72 | - * $id = $r['id']; |
|
73 | - * $fn = $r['FN']; |
|
74 | - * $email = $r['EMAIL']; |
|
75 | - * if (!is_array($email)) { |
|
76 | - * $email = array($email); |
|
77 | - * } |
|
78 | - * |
|
79 | - * // loop through all email addresses of this contact |
|
80 | - * foreach ($email as $e) { |
|
81 | - * $displayName = $fn . " <$e>"; |
|
82 | - * $receivers[] = array( |
|
83 | - * 'id' => $id, |
|
84 | - * 'label' => $displayName, |
|
85 | - * 'value' => $displayName); |
|
86 | - * } |
|
87 | - * } |
|
88 | - * |
|
89 | - * return $receivers; |
|
90 | - * } |
|
91 | - * |
|
92 | - * |
|
93 | - * @param string $pattern which should match within the $searchProperties |
|
94 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
95 | - * @param array $options - for future use. One should always have options! |
|
96 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
97 | - * @since 6.0.0 |
|
98 | - */ |
|
99 | - public function search($pattern, $searchProperties = array(), $options = array()); |
|
55 | + /** |
|
56 | + * This function is used to search and find contacts within the users address books. |
|
57 | + * In case $pattern is empty all contacts will be returned. |
|
58 | + * |
|
59 | + * Example: |
|
60 | + * Following function shows how to search for contacts for the name and the email address. |
|
61 | + * |
|
62 | + * public static function getMatchingRecipient($term) { |
|
63 | + * $cm = \OC::$server->getContactsManager(); |
|
64 | + * // The API is not active -> nothing to do |
|
65 | + * if (!$cm->isEnabled()) { |
|
66 | + * return array(); |
|
67 | + * } |
|
68 | + * |
|
69 | + * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
70 | + * $receivers = array(); |
|
71 | + * foreach ($result as $r) { |
|
72 | + * $id = $r['id']; |
|
73 | + * $fn = $r['FN']; |
|
74 | + * $email = $r['EMAIL']; |
|
75 | + * if (!is_array($email)) { |
|
76 | + * $email = array($email); |
|
77 | + * } |
|
78 | + * |
|
79 | + * // loop through all email addresses of this contact |
|
80 | + * foreach ($email as $e) { |
|
81 | + * $displayName = $fn . " <$e>"; |
|
82 | + * $receivers[] = array( |
|
83 | + * 'id' => $id, |
|
84 | + * 'label' => $displayName, |
|
85 | + * 'value' => $displayName); |
|
86 | + * } |
|
87 | + * } |
|
88 | + * |
|
89 | + * return $receivers; |
|
90 | + * } |
|
91 | + * |
|
92 | + * |
|
93 | + * @param string $pattern which should match within the $searchProperties |
|
94 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
95 | + * @param array $options - for future use. One should always have options! |
|
96 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
97 | + * @since 6.0.0 |
|
98 | + */ |
|
99 | + public function search($pattern, $searchProperties = array(), $options = array()); |
|
100 | 100 | |
101 | - /** |
|
102 | - * This function can be used to delete the contact identified by the given id |
|
103 | - * |
|
104 | - * @param object $id the unique identifier to a contact |
|
105 | - * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
106 | - * @return bool successful or not |
|
107 | - * @since 6.0.0 |
|
108 | - */ |
|
109 | - public function delete($id, $address_book_key); |
|
101 | + /** |
|
102 | + * This function can be used to delete the contact identified by the given id |
|
103 | + * |
|
104 | + * @param object $id the unique identifier to a contact |
|
105 | + * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
106 | + * @return bool successful or not |
|
107 | + * @since 6.0.0 |
|
108 | + */ |
|
109 | + public function delete($id, $address_book_key); |
|
110 | 110 | |
111 | - /** |
|
112 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
113 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
114 | - * |
|
115 | - * @param array $properties this array if key-value-pairs defines a contact |
|
116 | - * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
117 | - * @return array an array representing the contact just created or updated |
|
118 | - * @since 6.0.0 |
|
119 | - */ |
|
120 | - public function createOrUpdate($properties, $address_book_key); |
|
111 | + /** |
|
112 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
113 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
114 | + * |
|
115 | + * @param array $properties this array if key-value-pairs defines a contact |
|
116 | + * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
117 | + * @return array an array representing the contact just created or updated |
|
118 | + * @since 6.0.0 |
|
119 | + */ |
|
120 | + public function createOrUpdate($properties, $address_book_key); |
|
121 | 121 | |
122 | - /** |
|
123 | - * Check if contacts are available (e.g. contacts app enabled) |
|
124 | - * |
|
125 | - * @return bool true if enabled, false if not |
|
126 | - * @since 6.0.0 |
|
127 | - */ |
|
128 | - public function isEnabled(); |
|
122 | + /** |
|
123 | + * Check if contacts are available (e.g. contacts app enabled) |
|
124 | + * |
|
125 | + * @return bool true if enabled, false if not |
|
126 | + * @since 6.0.0 |
|
127 | + */ |
|
128 | + public function isEnabled(); |
|
129 | 129 | |
130 | - /** |
|
131 | - * Registers an address book |
|
132 | - * |
|
133 | - * @param \OCP\IAddressBook $address_book |
|
134 | - * @return void |
|
135 | - * @since 6.0.0 |
|
136 | - */ |
|
137 | - public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
130 | + /** |
|
131 | + * Registers an address book |
|
132 | + * |
|
133 | + * @param \OCP\IAddressBook $address_book |
|
134 | + * @return void |
|
135 | + * @since 6.0.0 |
|
136 | + */ |
|
137 | + public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
138 | 138 | |
139 | - /** |
|
140 | - * Unregisters an address book |
|
141 | - * |
|
142 | - * @param \OCP\IAddressBook $address_book |
|
143 | - * @return void |
|
144 | - * @since 6.0.0 |
|
145 | - */ |
|
146 | - public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
139 | + /** |
|
140 | + * Unregisters an address book |
|
141 | + * |
|
142 | + * @param \OCP\IAddressBook $address_book |
|
143 | + * @return void |
|
144 | + * @since 6.0.0 |
|
145 | + */ |
|
146 | + public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
147 | 147 | |
148 | - /** |
|
149 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
150 | - * address books are actually requested |
|
151 | - * |
|
152 | - * @param \Closure $callable |
|
153 | - * @return void |
|
154 | - * @since 6.0.0 |
|
155 | - */ |
|
156 | - public function register(\Closure $callable); |
|
148 | + /** |
|
149 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
150 | + * address books are actually requested |
|
151 | + * |
|
152 | + * @param \Closure $callable |
|
153 | + * @return void |
|
154 | + * @since 6.0.0 |
|
155 | + */ |
|
156 | + public function register(\Closure $callable); |
|
157 | 157 | |
158 | - /** |
|
159 | - * @return array |
|
160 | - * @since 6.0.0 |
|
161 | - */ |
|
162 | - public function getAddressBooks(); |
|
158 | + /** |
|
159 | + * @return array |
|
160 | + * @since 6.0.0 |
|
161 | + */ |
|
162 | + public function getAddressBooks(); |
|
163 | 163 | |
164 | - /** |
|
165 | - * removes all registered address book instances |
|
166 | - * @return void |
|
167 | - * @since 6.0.0 |
|
168 | - */ |
|
169 | - public function clear(); |
|
164 | + /** |
|
165 | + * removes all registered address book instances |
|
166 | + * @return void |
|
167 | + * @since 6.0.0 |
|
168 | + */ |
|
169 | + public function clear(); |
|
170 | 170 | } |
@@ -32,68 +32,68 @@ |
||
32 | 32 | * @package OC\Security |
33 | 33 | */ |
34 | 34 | class TrustedDomainHelper { |
35 | - /** @var IConfig */ |
|
36 | - private $config; |
|
35 | + /** @var IConfig */ |
|
36 | + private $config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param IConfig $config |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config) { |
|
42 | - $this->config = $config; |
|
43 | - } |
|
38 | + /** |
|
39 | + * @param IConfig $config |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config) { |
|
42 | + $this->config = $config; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Strips a potential port from a domain (in format domain:port) |
|
47 | - * @param string $host |
|
48 | - * @return string $host without appended port |
|
49 | - */ |
|
50 | - private function getDomainWithoutPort($host) { |
|
51 | - $pos = strrpos($host, ':'); |
|
52 | - if ($pos !== false) { |
|
53 | - $port = substr($host, $pos + 1); |
|
54 | - if (is_numeric($port)) { |
|
55 | - $host = substr($host, 0, $pos); |
|
56 | - } |
|
57 | - } |
|
58 | - return $host; |
|
59 | - } |
|
45 | + /** |
|
46 | + * Strips a potential port from a domain (in format domain:port) |
|
47 | + * @param string $host |
|
48 | + * @return string $host without appended port |
|
49 | + */ |
|
50 | + private function getDomainWithoutPort($host) { |
|
51 | + $pos = strrpos($host, ':'); |
|
52 | + if ($pos !== false) { |
|
53 | + $port = substr($host, $pos + 1); |
|
54 | + if (is_numeric($port)) { |
|
55 | + $host = substr($host, 0, $pos); |
|
56 | + } |
|
57 | + } |
|
58 | + return $host; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Checks whether a domain is considered as trusted from the list |
|
63 | - * of trusted domains. If no trusted domains have been configured, returns |
|
64 | - * true. |
|
65 | - * This is used to prevent Host Header Poisoning. |
|
66 | - * @param string $domainWithPort |
|
67 | - * @return bool true if the given domain is trusted or if no trusted domains |
|
68 | - * have been configured |
|
69 | - */ |
|
70 | - public function isTrustedDomain($domainWithPort) { |
|
71 | - $domain = $this->getDomainWithoutPort($domainWithPort); |
|
61 | + /** |
|
62 | + * Checks whether a domain is considered as trusted from the list |
|
63 | + * of trusted domains. If no trusted domains have been configured, returns |
|
64 | + * true. |
|
65 | + * This is used to prevent Host Header Poisoning. |
|
66 | + * @param string $domainWithPort |
|
67 | + * @return bool true if the given domain is trusted or if no trusted domains |
|
68 | + * have been configured |
|
69 | + */ |
|
70 | + public function isTrustedDomain($domainWithPort) { |
|
71 | + $domain = $this->getDomainWithoutPort($domainWithPort); |
|
72 | 72 | |
73 | - // Read trusted domains from config |
|
74 | - $trustedList = $this->config->getSystemValue('trusted_domains', []); |
|
75 | - if (!is_array($trustedList)) { |
|
76 | - return false; |
|
77 | - } |
|
73 | + // Read trusted domains from config |
|
74 | + $trustedList = $this->config->getSystemValue('trusted_domains', []); |
|
75 | + if (!is_array($trustedList)) { |
|
76 | + return false; |
|
77 | + } |
|
78 | 78 | |
79 | - // Always allow access from localhost |
|
80 | - if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) { |
|
81 | - return true; |
|
82 | - } |
|
83 | - // Reject misformed domains in any case |
|
84 | - if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
85 | - return false; |
|
86 | - } |
|
87 | - // Match, allowing for * wildcards |
|
88 | - foreach ($trustedList as $trusted) { |
|
89 | - if (gettype($trusted) !== 'string') { |
|
90 | - break; |
|
91 | - } |
|
92 | - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
93 | - if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
|
94 | - return true; |
|
95 | - } |
|
96 | - } |
|
97 | - return false; |
|
98 | - } |
|
79 | + // Always allow access from localhost |
|
80 | + if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) { |
|
81 | + return true; |
|
82 | + } |
|
83 | + // Reject misformed domains in any case |
|
84 | + if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
85 | + return false; |
|
86 | + } |
|
87 | + // Match, allowing for * wildcards |
|
88 | + foreach ($trustedList as $trusted) { |
|
89 | + if (gettype($trusted) !== 'string') { |
|
90 | + break; |
|
91 | + } |
|
92 | + $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
93 | + if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
|
94 | + return true; |
|
95 | + } |
|
96 | + } |
|
97 | + return false; |
|
98 | + } |
|
99 | 99 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | // Reject misformed domains in any case |
84 | - if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
84 | + if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | // Match, allowing for * wildcards |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | if (gettype($trusted) !== 'string') { |
90 | 90 | break; |
91 | 91 | } |
92 | - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/'; |
|
92 | + $regex = '/^'.implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))).'$/'; |
|
93 | 93 | if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
94 | 94 | return true; |
95 | 95 | } |
@@ -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 | } |