@@ -33,98 +33,98 @@ |
||
33 | 33 | * @since 8.0.0 |
34 | 34 | */ |
35 | 35 | class Template extends \OC_Template { |
36 | - /** |
|
37 | - * Make OC_Helper::imagePath available as a simple function |
|
38 | - * |
|
39 | - * @see \OCP\IURLGenerator::imagePath |
|
40 | - * |
|
41 | - * @param string $app |
|
42 | - * @param string $image |
|
43 | - * @return string to the image |
|
44 | - * @since 8.0.0 |
|
45 | - * @suppress PhanDeprecatedFunction |
|
46 | - */ |
|
47 | - public static function image_path($app, $image) { |
|
48 | - return \image_path($app, $image); |
|
49 | - } |
|
36 | + /** |
|
37 | + * Make OC_Helper::imagePath available as a simple function |
|
38 | + * |
|
39 | + * @see \OCP\IURLGenerator::imagePath |
|
40 | + * |
|
41 | + * @param string $app |
|
42 | + * @param string $image |
|
43 | + * @return string to the image |
|
44 | + * @since 8.0.0 |
|
45 | + * @suppress PhanDeprecatedFunction |
|
46 | + */ |
|
47 | + public static function image_path($app, $image) { |
|
48 | + return \image_path($app, $image); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Make OC_Helper::mimetypeIcon available as a simple function |
|
54 | - * |
|
55 | - * @param string $mimetype |
|
56 | - * @return string to the image of this file type. |
|
57 | - * @since 8.0.0 |
|
58 | - * @suppress PhanDeprecatedFunction |
|
59 | - */ |
|
60 | - public static function mimetype_icon($mimetype) { |
|
61 | - return \mimetype_icon($mimetype); |
|
62 | - } |
|
52 | + /** |
|
53 | + * Make OC_Helper::mimetypeIcon available as a simple function |
|
54 | + * |
|
55 | + * @param string $mimetype |
|
56 | + * @return string to the image of this file type. |
|
57 | + * @since 8.0.0 |
|
58 | + * @suppress PhanDeprecatedFunction |
|
59 | + */ |
|
60 | + public static function mimetype_icon($mimetype) { |
|
61 | + return \mimetype_icon($mimetype); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Make preview_icon available as a simple function |
|
66 | - * |
|
67 | - * @param string $path path to file |
|
68 | - * @return string to the preview of the image |
|
69 | - * @since 8.0.0 |
|
70 | - * @suppress PhanDeprecatedFunction |
|
71 | - */ |
|
72 | - public static function preview_icon($path) { |
|
73 | - return \preview_icon($path); |
|
74 | - } |
|
64 | + /** |
|
65 | + * Make preview_icon available as a simple function |
|
66 | + * |
|
67 | + * @param string $path path to file |
|
68 | + * @return string to the preview of the image |
|
69 | + * @since 8.0.0 |
|
70 | + * @suppress PhanDeprecatedFunction |
|
71 | + */ |
|
72 | + public static function preview_icon($path) { |
|
73 | + return \preview_icon($path); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Make publicpreview_icon available as a simple function |
|
78 | - * Returns the path to the preview of the image. |
|
79 | - * |
|
80 | - * @param string $path of file |
|
81 | - * @param string $token |
|
82 | - * @return string link to the preview |
|
83 | - * @since 8.0.0 |
|
84 | - * @suppress PhanDeprecatedFunction |
|
85 | - */ |
|
86 | - public static function publicPreview_icon($path, $token) { |
|
87 | - return \publicPreview_icon($path, $token); |
|
88 | - } |
|
76 | + /** |
|
77 | + * Make publicpreview_icon available as a simple function |
|
78 | + * Returns the path to the preview of the image. |
|
79 | + * |
|
80 | + * @param string $path of file |
|
81 | + * @param string $token |
|
82 | + * @return string link to the preview |
|
83 | + * @since 8.0.0 |
|
84 | + * @suppress PhanDeprecatedFunction |
|
85 | + */ |
|
86 | + public static function publicPreview_icon($path, $token) { |
|
87 | + return \publicPreview_icon($path, $token); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Make OC_Helper::humanFileSize available as a simple function |
|
92 | - * Example: 2048 to 2 kB. |
|
93 | - * |
|
94 | - * @param int $bytes in bytes |
|
95 | - * @return string size as string |
|
96 | - * @since 8.0.0 |
|
97 | - * @suppress PhanDeprecatedFunction |
|
98 | - */ |
|
99 | - public static function human_file_size($bytes) { |
|
100 | - return \human_file_size($bytes); |
|
101 | - } |
|
90 | + /** |
|
91 | + * Make OC_Helper::humanFileSize available as a simple function |
|
92 | + * Example: 2048 to 2 kB. |
|
93 | + * |
|
94 | + * @param int $bytes in bytes |
|
95 | + * @return string size as string |
|
96 | + * @since 8.0.0 |
|
97 | + * @suppress PhanDeprecatedFunction |
|
98 | + */ |
|
99 | + public static function human_file_size($bytes) { |
|
100 | + return \human_file_size($bytes); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Return the relative date in relation to today. Returns something like "last hour" or "two month ago" |
|
105 | - * |
|
106 | - * @param int $timestamp unix timestamp |
|
107 | - * @param boolean $dateOnly |
|
108 | - * @return string human readable interpretation of the timestamp |
|
109 | - * @since 8.0.0 |
|
110 | - * @suppress PhanDeprecatedFunction |
|
111 | - * @suppress PhanTypeMismatchArgument |
|
112 | - */ |
|
113 | - public static function relative_modified_date($timestamp, $dateOnly = false) { |
|
114 | - return \relative_modified_date($timestamp, null, $dateOnly); |
|
115 | - } |
|
103 | + /** |
|
104 | + * Return the relative date in relation to today. Returns something like "last hour" or "two month ago" |
|
105 | + * |
|
106 | + * @param int $timestamp unix timestamp |
|
107 | + * @param boolean $dateOnly |
|
108 | + * @return string human readable interpretation of the timestamp |
|
109 | + * @since 8.0.0 |
|
110 | + * @suppress PhanDeprecatedFunction |
|
111 | + * @suppress PhanTypeMismatchArgument |
|
112 | + */ |
|
113 | + public static function relative_modified_date($timestamp, $dateOnly = false) { |
|
114 | + return \relative_modified_date($timestamp, null, $dateOnly); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Generate html code for an options block. |
|
119 | - * |
|
120 | - * @param array $options the options |
|
121 | - * @param mixed $selected which one is selected? |
|
122 | - * @param array $params the parameters |
|
123 | - * @return string html options |
|
124 | - * @since 8.0.0 |
|
125 | - * @suppress PhanDeprecatedFunction |
|
126 | - */ |
|
127 | - public static function html_select_options($options, $selected, $params=[]) { |
|
128 | - return \html_select_options($options, $selected, $params); |
|
129 | - } |
|
117 | + /** |
|
118 | + * Generate html code for an options block. |
|
119 | + * |
|
120 | + * @param array $options the options |
|
121 | + * @param mixed $selected which one is selected? |
|
122 | + * @param array $params the parameters |
|
123 | + * @return string html options |
|
124 | + * @since 8.0.0 |
|
125 | + * @suppress PhanDeprecatedFunction |
|
126 | + */ |
|
127 | + public static function html_select_options($options, $selected, $params=[]) { |
|
128 | + return \html_select_options($options, $selected, $params); |
|
129 | + } |
|
130 | 130 | } |
@@ -48,17 +48,17 @@ |
||
48 | 48 | */ |
49 | 49 | interface ITagManager { |
50 | 50 | |
51 | - /** |
|
52 | - * Create a new \OCP\ITags instance and load tags from db for the current user. |
|
53 | - * |
|
54 | - * @see \OCP\ITags |
|
55 | - * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
56 | - * @param array $defaultTags An array of default tags to be used if none are stored. |
|
57 | - * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
58 | - * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
59 | - * logged in user |
|
60 | - * @return \OCP\ITags |
|
61 | - * @since 6.0.0 - parameter $includeShared and $userId were added in 8.0.0 |
|
62 | - */ |
|
63 | - public function load($type, $defaultTags = [], $includeShared = false, $userId = null); |
|
51 | + /** |
|
52 | + * Create a new \OCP\ITags instance and load tags from db for the current user. |
|
53 | + * |
|
54 | + * @see \OCP\ITags |
|
55 | + * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
56 | + * @param array $defaultTags An array of default tags to be used if none are stored. |
|
57 | + * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
58 | + * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
59 | + * logged in user |
|
60 | + * @return \OCP\ITags |
|
61 | + * @since 6.0.0 - parameter $includeShared and $userId were added in 8.0.0 |
|
62 | + */ |
|
63 | + public function load($type, $defaultTags = [], $includeShared = false, $userId = null); |
|
64 | 64 | } |
@@ -35,71 +35,71 @@ |
||
35 | 35 | * @since 6.0.0 |
36 | 36 | */ |
37 | 37 | interface IURLGenerator { |
38 | - /** |
|
39 | - * Returns the URL for a route |
|
40 | - * @param string $routeName the name of the route |
|
41 | - * @param array $arguments an array with arguments which will be filled into the url |
|
42 | - * @return string the url |
|
43 | - * @since 6.0.0 |
|
44 | - */ |
|
45 | - public function linkToRoute(string $routeName, array $arguments = []): string; |
|
38 | + /** |
|
39 | + * Returns the URL for a route |
|
40 | + * @param string $routeName the name of the route |
|
41 | + * @param array $arguments an array with arguments which will be filled into the url |
|
42 | + * @return string the url |
|
43 | + * @since 6.0.0 |
|
44 | + */ |
|
45 | + public function linkToRoute(string $routeName, array $arguments = []): string; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the absolute URL for a route |
|
49 | - * @param string $routeName the name of the route |
|
50 | - * @param array $arguments an array with arguments which will be filled into the url |
|
51 | - * @return string the absolute url |
|
52 | - * @since 8.0.0 |
|
53 | - */ |
|
54 | - public function linkToRouteAbsolute(string $routeName, array $arguments = []): string; |
|
47 | + /** |
|
48 | + * Returns the absolute URL for a route |
|
49 | + * @param string $routeName the name of the route |
|
50 | + * @param array $arguments an array with arguments which will be filled into the url |
|
51 | + * @return string the absolute url |
|
52 | + * @since 8.0.0 |
|
53 | + */ |
|
54 | + public function linkToRouteAbsolute(string $routeName, array $arguments = []): string; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $routeName |
|
58 | - * @param array $arguments |
|
59 | - * @return string |
|
60 | - * @since 15.0.0 |
|
61 | - */ |
|
62 | - public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string; |
|
56 | + /** |
|
57 | + * @param string $routeName |
|
58 | + * @param array $arguments |
|
59 | + * @return string |
|
60 | + * @since 15.0.0 |
|
61 | + */ |
|
62 | + public function linkToOCSRouteAbsolute(string $routeName, array $arguments = []): string; |
|
63 | 63 | |
64 | - /** |
|
65 | - * Returns an URL for an image or file |
|
66 | - * @param string $appName the name of the app |
|
67 | - * @param string $file the name of the file |
|
68 | - * @param array $args array with param=>value, will be appended to the returned url |
|
69 | - * The value of $args will be urlencoded |
|
70 | - * @return string the url |
|
71 | - * @since 6.0.0 |
|
72 | - */ |
|
73 | - public function linkTo(string $appName, string $file, array $args = []): string; |
|
64 | + /** |
|
65 | + * Returns an URL for an image or file |
|
66 | + * @param string $appName the name of the app |
|
67 | + * @param string $file the name of the file |
|
68 | + * @param array $args array with param=>value, will be appended to the returned url |
|
69 | + * The value of $args will be urlencoded |
|
70 | + * @return string the url |
|
71 | + * @since 6.0.0 |
|
72 | + */ |
|
73 | + public function linkTo(string $appName, string $file, array $args = []): string; |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the link to an image, like linkTo but only with prepending img/ |
|
77 | - * @param string $appName the name of the app |
|
78 | - * @param string $file the name of the file |
|
79 | - * @return string the url |
|
80 | - * @since 6.0.0 |
|
81 | - */ |
|
82 | - public function imagePath(string $appName, string $file): string; |
|
75 | + /** |
|
76 | + * Returns the link to an image, like linkTo but only with prepending img/ |
|
77 | + * @param string $appName the name of the app |
|
78 | + * @param string $file the name of the file |
|
79 | + * @return string the url |
|
80 | + * @since 6.0.0 |
|
81 | + */ |
|
82 | + public function imagePath(string $appName, string $file): string; |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * Makes an URL absolute |
|
87 | - * @param string $url the url in the ownCloud host |
|
88 | - * @return string the absolute version of the url |
|
89 | - * @since 6.0.0 |
|
90 | - */ |
|
91 | - public function getAbsoluteURL(string $url): string; |
|
85 | + /** |
|
86 | + * Makes an URL absolute |
|
87 | + * @param string $url the url in the ownCloud host |
|
88 | + * @return string the absolute version of the url |
|
89 | + * @since 6.0.0 |
|
90 | + */ |
|
91 | + public function getAbsoluteURL(string $url): string; |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param string $key |
|
95 | - * @return string url to the online documentation |
|
96 | - * @since 8.0.0 |
|
97 | - */ |
|
98 | - public function linkToDocs(string $key): string; |
|
93 | + /** |
|
94 | + * @param string $key |
|
95 | + * @return string url to the online documentation |
|
96 | + * @since 8.0.0 |
|
97 | + */ |
|
98 | + public function linkToDocs(string $key): string; |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return string base url of the current request |
|
102 | - * @since 13.0.0 |
|
103 | - */ |
|
104 | - public function getBaseUrl(): string; |
|
100 | + /** |
|
101 | + * @return string base url of the current request |
|
102 | + * @since 13.0.0 |
|
103 | + */ |
|
104 | + public function getBaseUrl(): string; |
|
105 | 105 | } |
@@ -56,473 +56,473 @@ |
||
56 | 56 | * @since 4.0.0 |
57 | 57 | */ |
58 | 58 | class Util { |
59 | - /** |
|
60 | - * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
61 | - */ |
|
62 | - const DEBUG=0; |
|
63 | - /** |
|
64 | - * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
65 | - */ |
|
66 | - const INFO=1; |
|
67 | - /** |
|
68 | - * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
69 | - */ |
|
70 | - const WARN=2; |
|
71 | - /** |
|
72 | - * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
73 | - */ |
|
74 | - const ERROR=3; |
|
75 | - /** |
|
76 | - * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
77 | - */ |
|
78 | - const FATAL=4; |
|
79 | - |
|
80 | - /** \OCP\Share\IManager */ |
|
81 | - private static $shareManager; |
|
82 | - |
|
83 | - /** |
|
84 | - * get the current installed version of Nextcloud |
|
85 | - * @return array |
|
86 | - * @since 4.0.0 |
|
87 | - */ |
|
88 | - public static function getVersion() { |
|
89 | - return \OC_Util::getVersion(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @since 17.0.0 |
|
94 | - */ |
|
95 | - public static function hasExtendedSupport(): bool { |
|
96 | - try { |
|
97 | - /** @var \OCP\Support\Subscription\IRegistry */ |
|
98 | - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
99 | - return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
100 | - } catch (AppFramework\QueryException $e) {} |
|
101 | - return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Set current update channel |
|
106 | - * @param string $channel |
|
107 | - * @since 8.1.0 |
|
108 | - */ |
|
109 | - public static function setChannel($channel) { |
|
110 | - \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get current update channel |
|
115 | - * @return string |
|
116 | - * @since 8.1.0 |
|
117 | - */ |
|
118 | - public static function getChannel() { |
|
119 | - return \OC_Util::getChannel(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * write a message in the log |
|
124 | - * @param string $app |
|
125 | - * @param string $message |
|
126 | - * @param int $level |
|
127 | - * @since 4.0.0 |
|
128 | - * @deprecated 13.0.0 use log of \OCP\ILogger |
|
129 | - */ |
|
130 | - public static function writeLog( $app, $message, $level ) { |
|
131 | - $context = ['app' => $app]; |
|
132 | - \OC::$server->getLogger()->log($level, $message, $context); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * check if sharing is disabled for the current user |
|
137 | - * |
|
138 | - * @return boolean |
|
139 | - * @since 7.0.0 |
|
140 | - * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
141 | - */ |
|
142 | - public static function isSharingDisabledForUser() { |
|
143 | - if (self::$shareManager === null) { |
|
144 | - self::$shareManager = \OC::$server->getShareManager(); |
|
145 | - } |
|
146 | - |
|
147 | - $user = \OC::$server->getUserSession()->getUser(); |
|
148 | - if ($user !== null) { |
|
149 | - $user = $user->getUID(); |
|
150 | - } |
|
151 | - |
|
152 | - return self::$shareManager->sharingDisabledForUser($user); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * get l10n object |
|
157 | - * @param string $application |
|
158 | - * @param string|null $language |
|
159 | - * @return \OCP\IL10N |
|
160 | - * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
161 | - */ |
|
162 | - public static function getL10N($application, $language = null) { |
|
163 | - return \OC::$server->getL10N($application, $language); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * add a css file |
|
168 | - * @param string $application |
|
169 | - * @param string $file |
|
170 | - * @since 4.0.0 |
|
171 | - */ |
|
172 | - public static function addStyle( $application, $file = null ) { |
|
173 | - \OC_Util::addStyle( $application, $file ); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * add a javascript file |
|
178 | - * @param string $application |
|
179 | - * @param string $file |
|
180 | - * @since 4.0.0 |
|
181 | - */ |
|
182 | - public static function addScript( $application, $file = null ) { |
|
183 | - \OC_Util::addScript( $application, $file ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Add a translation JS file |
|
188 | - * @param string $application application id |
|
189 | - * @param string $languageCode language code, defaults to the current locale |
|
190 | - * @since 8.0.0 |
|
191 | - */ |
|
192 | - public static function addTranslations($application, $languageCode = null) { |
|
193 | - \OC_Util::addTranslations($application, $languageCode); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Add a custom element to the header |
|
198 | - * If $text is null then the element will be written as empty element. |
|
199 | - * So use "" to get a closing tag. |
|
200 | - * @param string $tag tag name of the element |
|
201 | - * @param array $attributes array of attributes for the element |
|
202 | - * @param string $text the text content for the element |
|
203 | - * @since 4.0.0 |
|
204 | - */ |
|
205 | - public static function addHeader($tag, $attributes, $text=null) { |
|
206 | - \OC_Util::addHeader($tag, $attributes, $text); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Creates an absolute url to the given app and file. |
|
211 | - * @param string $app app |
|
212 | - * @param string $file file |
|
213 | - * @param array $args array with param=>value, will be appended to the returned url |
|
214 | - * The value of $args will be urlencoded |
|
215 | - * @return string the url |
|
216 | - * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
217 | - */ |
|
218 | - public static function linkToAbsolute( $app, $file, $args = [] ) { |
|
219 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
220 | - return $urlGenerator->getAbsoluteURL( |
|
221 | - $urlGenerator->linkTo($app, $file, $args) |
|
222 | - ); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Creates an absolute url for remote use. |
|
227 | - * @param string $service id |
|
228 | - * @return string the url |
|
229 | - * @since 4.0.0 |
|
230 | - */ |
|
231 | - public static function linkToRemote( $service ) { |
|
232 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
233 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
234 | - return $urlGenerator->getAbsoluteURL( |
|
235 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Creates an absolute url for public use |
|
241 | - * @param string $service id |
|
242 | - * @return string the url |
|
243 | - * @since 4.5.0 |
|
244 | - * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
245 | - */ |
|
246 | - public static function linkToPublic($service) { |
|
247 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
248 | - if ($service === 'files') { |
|
249 | - return $urlGenerator->getAbsoluteURL('/s'); |
|
250 | - } |
|
251 | - return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Returns the server host name without an eventual port number |
|
256 | - * @return string the server hostname |
|
257 | - * @since 5.0.0 |
|
258 | - */ |
|
259 | - public static function getServerHostName() { |
|
260 | - $host_name = \OC::$server->getRequest()->getServerHost(); |
|
261 | - // strip away port number (if existing) |
|
262 | - $colon_pos = strpos($host_name, ':'); |
|
263 | - if ($colon_pos != false) { |
|
264 | - $host_name = substr($host_name, 0, $colon_pos); |
|
265 | - } |
|
266 | - return $host_name; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Returns the default email address |
|
271 | - * @param string $user_part the user part of the address |
|
272 | - * @return string the default email address |
|
273 | - * |
|
274 | - * Assembles a default email address (using the server hostname |
|
275 | - * and the given user part, and returns it |
|
276 | - * Example: when given lostpassword-noreply as $user_part param, |
|
277 | - * and is currently accessed via http(s)://example.com/, |
|
278 | - * it would return '[email protected]' |
|
279 | - * |
|
280 | - * If the configuration value 'mail_from_address' is set in |
|
281 | - * config.php, this value will override the $user_part that |
|
282 | - * is passed to this function |
|
283 | - * @since 5.0.0 |
|
284 | - */ |
|
285 | - public static function getDefaultEmailAddress($user_part) { |
|
286 | - $config = \OC::$server->getConfig(); |
|
287 | - $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
288 | - $host_name = self::getServerHostName(); |
|
289 | - $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
290 | - $defaultEmailAddress = $user_part.'@'.$host_name; |
|
291 | - |
|
292 | - $mailer = \OC::$server->getMailer(); |
|
293 | - if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
294 | - return $defaultEmailAddress; |
|
295 | - } |
|
296 | - |
|
297 | - // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
298 | - return $user_part.'@localhost.localdomain'; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Make a human file size (2048 to 2 kB) |
|
303 | - * @param int $bytes file size in bytes |
|
304 | - * @return string a human readable file size |
|
305 | - * @since 4.0.0 |
|
306 | - */ |
|
307 | - public static function humanFileSize($bytes) { |
|
308 | - return \OC_Helper::humanFileSize($bytes); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Make a computer file size (2 kB to 2048) |
|
313 | - * @param string $str file size in a fancy format |
|
314 | - * @return float a file size in bytes |
|
315 | - * |
|
316 | - * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
317 | - * @since 4.0.0 |
|
318 | - */ |
|
319 | - public static function computerFileSize($str) { |
|
320 | - return \OC_Helper::computerFileSize($str); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * connects a function to a hook |
|
325 | - * |
|
326 | - * @param string $signalClass class name of emitter |
|
327 | - * @param string $signalName name of signal |
|
328 | - * @param string|object $slotClass class name of slot |
|
329 | - * @param string $slotName name of slot |
|
330 | - * @return bool |
|
331 | - * |
|
332 | - * This function makes it very easy to connect to use hooks. |
|
333 | - * |
|
334 | - * TODO: write example |
|
335 | - * @since 4.0.0 |
|
336 | - */ |
|
337 | - static public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
338 | - return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Emits a signal. To get data from the slot use references! |
|
343 | - * @param string $signalclass class name of emitter |
|
344 | - * @param string $signalname name of signal |
|
345 | - * @param array $params default: array() array with additional data |
|
346 | - * @return bool true if slots exists or false if not |
|
347 | - * |
|
348 | - * TODO: write example |
|
349 | - * @since 4.0.0 |
|
350 | - */ |
|
351 | - static public function emitHook($signalclass, $signalname, $params = []) { |
|
352 | - return \OC_Hook::emit($signalclass, $signalname, $params); |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
357 | - * multiple OC_Template elements which invoke `callRegister`. If the value |
|
358 | - * would not be cached these unit-tests would fail. |
|
359 | - * @var string |
|
360 | - */ |
|
361 | - private static $token = ''; |
|
362 | - |
|
363 | - /** |
|
364 | - * Register an get/post call. This is important to prevent CSRF attacks |
|
365 | - * @since 4.5.0 |
|
366 | - */ |
|
367 | - public static function callRegister() { |
|
368 | - if(self::$token === '') { |
|
369 | - self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
370 | - } |
|
371 | - return self::$token; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Used to sanitize HTML |
|
376 | - * |
|
377 | - * This function is used to sanitize HTML and should be applied on any |
|
378 | - * string or array of strings before displaying it on a web page. |
|
379 | - * |
|
380 | - * @param string|array $value |
|
381 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
382 | - * @since 4.5.0 |
|
383 | - */ |
|
384 | - public static function sanitizeHTML($value) { |
|
385 | - return \OC_Util::sanitizeHTML($value); |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Public function to encode url parameters |
|
390 | - * |
|
391 | - * This function is used to encode path to file before output. |
|
392 | - * Encoding is done according to RFC 3986 with one exception: |
|
393 | - * Character '/' is preserved as is. |
|
394 | - * |
|
395 | - * @param string $component part of URI to encode |
|
396 | - * @return string |
|
397 | - * @since 6.0.0 |
|
398 | - */ |
|
399 | - public static function encodePath($component) { |
|
400 | - return \OC_Util::encodePath($component); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
405 | - * |
|
406 | - * @param array $input The array to work on |
|
407 | - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
408 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
409 | - * @return array |
|
410 | - * @since 4.5.0 |
|
411 | - */ |
|
412 | - public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
413 | - return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * performs a search in a nested array |
|
418 | - * |
|
419 | - * @param array $haystack the array to be searched |
|
420 | - * @param string $needle the search string |
|
421 | - * @param mixed $index optional, only search this key name |
|
422 | - * @return mixed the key of the matching field, otherwise false |
|
423 | - * @since 4.5.0 |
|
424 | - * @deprecated 15.0.0 |
|
425 | - */ |
|
426 | - public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
427 | - return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * calculates the maximum upload size respecting system settings, free space and user quota |
|
432 | - * |
|
433 | - * @param string $dir the current folder where the user currently operates |
|
434 | - * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
435 | - * @return int number of bytes representing |
|
436 | - * @since 5.0.0 |
|
437 | - */ |
|
438 | - public static function maxUploadFilesize($dir, $free = null) { |
|
439 | - return \OC_Helper::maxUploadFilesize($dir, $free); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Calculate free space left within user quota |
|
444 | - * @param string $dir the current folder where the user currently operates |
|
445 | - * @return int number of bytes representing |
|
446 | - * @since 7.0.0 |
|
447 | - */ |
|
448 | - public static function freeSpace($dir) { |
|
449 | - return \OC_Helper::freeSpace($dir); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Calculate PHP upload limit |
|
454 | - * |
|
455 | - * @return int number of bytes representing |
|
456 | - * @since 7.0.0 |
|
457 | - */ |
|
458 | - public static function uploadLimit() { |
|
459 | - return \OC_Helper::uploadLimit(); |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Returns whether the given file name is valid |
|
464 | - * @param string $file file name to check |
|
465 | - * @return bool true if the file name is valid, false otherwise |
|
466 | - * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
467 | - * @since 7.0.0 |
|
468 | - * @suppress PhanDeprecatedFunction |
|
469 | - */ |
|
470 | - public static function isValidFileName($file) { |
|
471 | - return \OC_Util::isValidFileName($file); |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Compare two strings to provide a natural sort |
|
476 | - * @param string $a first string to compare |
|
477 | - * @param string $b second string to compare |
|
478 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
479 | - * or 0 if the strings are identical |
|
480 | - * @since 7.0.0 |
|
481 | - */ |
|
482 | - public static function naturalSortCompare($a, $b) { |
|
483 | - return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * check if a password is required for each public link |
|
488 | - * @return boolean |
|
489 | - * @since 7.0.0 |
|
490 | - */ |
|
491 | - public static function isPublicLinkPasswordRequired() { |
|
492 | - return \OC_Util::isPublicLinkPasswordRequired(); |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * check if share API enforces a default expire date |
|
497 | - * @return boolean |
|
498 | - * @since 8.0.0 |
|
499 | - */ |
|
500 | - public static function isDefaultExpireDateEnforced() { |
|
501 | - return \OC_Util::isDefaultExpireDateEnforced(); |
|
502 | - } |
|
503 | - |
|
504 | - protected static $needUpgradeCache = null; |
|
505 | - |
|
506 | - /** |
|
507 | - * Checks whether the current version needs upgrade. |
|
508 | - * |
|
509 | - * @return bool true if upgrade is needed, false otherwise |
|
510 | - * @since 7.0.0 |
|
511 | - */ |
|
512 | - public static function needUpgrade() { |
|
513 | - if (!isset(self::$needUpgradeCache)) { |
|
514 | - self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
515 | - } |
|
516 | - return self::$needUpgradeCache; |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * is this Internet explorer ? |
|
521 | - * |
|
522 | - * @return boolean |
|
523 | - * @since 14.0.0 |
|
524 | - */ |
|
525 | - public static function isIe() { |
|
526 | - return \OC_Util::isIe(); |
|
527 | - } |
|
59 | + /** |
|
60 | + * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
61 | + */ |
|
62 | + const DEBUG=0; |
|
63 | + /** |
|
64 | + * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
65 | + */ |
|
66 | + const INFO=1; |
|
67 | + /** |
|
68 | + * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
69 | + */ |
|
70 | + const WARN=2; |
|
71 | + /** |
|
72 | + * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
73 | + */ |
|
74 | + const ERROR=3; |
|
75 | + /** |
|
76 | + * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
77 | + */ |
|
78 | + const FATAL=4; |
|
79 | + |
|
80 | + /** \OCP\Share\IManager */ |
|
81 | + private static $shareManager; |
|
82 | + |
|
83 | + /** |
|
84 | + * get the current installed version of Nextcloud |
|
85 | + * @return array |
|
86 | + * @since 4.0.0 |
|
87 | + */ |
|
88 | + public static function getVersion() { |
|
89 | + return \OC_Util::getVersion(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @since 17.0.0 |
|
94 | + */ |
|
95 | + public static function hasExtendedSupport(): bool { |
|
96 | + try { |
|
97 | + /** @var \OCP\Support\Subscription\IRegistry */ |
|
98 | + $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
99 | + return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
100 | + } catch (AppFramework\QueryException $e) {} |
|
101 | + return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Set current update channel |
|
106 | + * @param string $channel |
|
107 | + * @since 8.1.0 |
|
108 | + */ |
|
109 | + public static function setChannel($channel) { |
|
110 | + \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get current update channel |
|
115 | + * @return string |
|
116 | + * @since 8.1.0 |
|
117 | + */ |
|
118 | + public static function getChannel() { |
|
119 | + return \OC_Util::getChannel(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * write a message in the log |
|
124 | + * @param string $app |
|
125 | + * @param string $message |
|
126 | + * @param int $level |
|
127 | + * @since 4.0.0 |
|
128 | + * @deprecated 13.0.0 use log of \OCP\ILogger |
|
129 | + */ |
|
130 | + public static function writeLog( $app, $message, $level ) { |
|
131 | + $context = ['app' => $app]; |
|
132 | + \OC::$server->getLogger()->log($level, $message, $context); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * check if sharing is disabled for the current user |
|
137 | + * |
|
138 | + * @return boolean |
|
139 | + * @since 7.0.0 |
|
140 | + * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
141 | + */ |
|
142 | + public static function isSharingDisabledForUser() { |
|
143 | + if (self::$shareManager === null) { |
|
144 | + self::$shareManager = \OC::$server->getShareManager(); |
|
145 | + } |
|
146 | + |
|
147 | + $user = \OC::$server->getUserSession()->getUser(); |
|
148 | + if ($user !== null) { |
|
149 | + $user = $user->getUID(); |
|
150 | + } |
|
151 | + |
|
152 | + return self::$shareManager->sharingDisabledForUser($user); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * get l10n object |
|
157 | + * @param string $application |
|
158 | + * @param string|null $language |
|
159 | + * @return \OCP\IL10N |
|
160 | + * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
161 | + */ |
|
162 | + public static function getL10N($application, $language = null) { |
|
163 | + return \OC::$server->getL10N($application, $language); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * add a css file |
|
168 | + * @param string $application |
|
169 | + * @param string $file |
|
170 | + * @since 4.0.0 |
|
171 | + */ |
|
172 | + public static function addStyle( $application, $file = null ) { |
|
173 | + \OC_Util::addStyle( $application, $file ); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * add a javascript file |
|
178 | + * @param string $application |
|
179 | + * @param string $file |
|
180 | + * @since 4.0.0 |
|
181 | + */ |
|
182 | + public static function addScript( $application, $file = null ) { |
|
183 | + \OC_Util::addScript( $application, $file ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Add a translation JS file |
|
188 | + * @param string $application application id |
|
189 | + * @param string $languageCode language code, defaults to the current locale |
|
190 | + * @since 8.0.0 |
|
191 | + */ |
|
192 | + public static function addTranslations($application, $languageCode = null) { |
|
193 | + \OC_Util::addTranslations($application, $languageCode); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Add a custom element to the header |
|
198 | + * If $text is null then the element will be written as empty element. |
|
199 | + * So use "" to get a closing tag. |
|
200 | + * @param string $tag tag name of the element |
|
201 | + * @param array $attributes array of attributes for the element |
|
202 | + * @param string $text the text content for the element |
|
203 | + * @since 4.0.0 |
|
204 | + */ |
|
205 | + public static function addHeader($tag, $attributes, $text=null) { |
|
206 | + \OC_Util::addHeader($tag, $attributes, $text); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Creates an absolute url to the given app and file. |
|
211 | + * @param string $app app |
|
212 | + * @param string $file file |
|
213 | + * @param array $args array with param=>value, will be appended to the returned url |
|
214 | + * The value of $args will be urlencoded |
|
215 | + * @return string the url |
|
216 | + * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
217 | + */ |
|
218 | + public static function linkToAbsolute( $app, $file, $args = [] ) { |
|
219 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
220 | + return $urlGenerator->getAbsoluteURL( |
|
221 | + $urlGenerator->linkTo($app, $file, $args) |
|
222 | + ); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Creates an absolute url for remote use. |
|
227 | + * @param string $service id |
|
228 | + * @return string the url |
|
229 | + * @since 4.0.0 |
|
230 | + */ |
|
231 | + public static function linkToRemote( $service ) { |
|
232 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
233 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
234 | + return $urlGenerator->getAbsoluteURL( |
|
235 | + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Creates an absolute url for public use |
|
241 | + * @param string $service id |
|
242 | + * @return string the url |
|
243 | + * @since 4.5.0 |
|
244 | + * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
245 | + */ |
|
246 | + public static function linkToPublic($service) { |
|
247 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
248 | + if ($service === 'files') { |
|
249 | + return $urlGenerator->getAbsoluteURL('/s'); |
|
250 | + } |
|
251 | + return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Returns the server host name without an eventual port number |
|
256 | + * @return string the server hostname |
|
257 | + * @since 5.0.0 |
|
258 | + */ |
|
259 | + public static function getServerHostName() { |
|
260 | + $host_name = \OC::$server->getRequest()->getServerHost(); |
|
261 | + // strip away port number (if existing) |
|
262 | + $colon_pos = strpos($host_name, ':'); |
|
263 | + if ($colon_pos != false) { |
|
264 | + $host_name = substr($host_name, 0, $colon_pos); |
|
265 | + } |
|
266 | + return $host_name; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Returns the default email address |
|
271 | + * @param string $user_part the user part of the address |
|
272 | + * @return string the default email address |
|
273 | + * |
|
274 | + * Assembles a default email address (using the server hostname |
|
275 | + * and the given user part, and returns it |
|
276 | + * Example: when given lostpassword-noreply as $user_part param, |
|
277 | + * and is currently accessed via http(s)://example.com/, |
|
278 | + * it would return '[email protected]' |
|
279 | + * |
|
280 | + * If the configuration value 'mail_from_address' is set in |
|
281 | + * config.php, this value will override the $user_part that |
|
282 | + * is passed to this function |
|
283 | + * @since 5.0.0 |
|
284 | + */ |
|
285 | + public static function getDefaultEmailAddress($user_part) { |
|
286 | + $config = \OC::$server->getConfig(); |
|
287 | + $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
288 | + $host_name = self::getServerHostName(); |
|
289 | + $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
290 | + $defaultEmailAddress = $user_part.'@'.$host_name; |
|
291 | + |
|
292 | + $mailer = \OC::$server->getMailer(); |
|
293 | + if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
294 | + return $defaultEmailAddress; |
|
295 | + } |
|
296 | + |
|
297 | + // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
298 | + return $user_part.'@localhost.localdomain'; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Make a human file size (2048 to 2 kB) |
|
303 | + * @param int $bytes file size in bytes |
|
304 | + * @return string a human readable file size |
|
305 | + * @since 4.0.0 |
|
306 | + */ |
|
307 | + public static function humanFileSize($bytes) { |
|
308 | + return \OC_Helper::humanFileSize($bytes); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Make a computer file size (2 kB to 2048) |
|
313 | + * @param string $str file size in a fancy format |
|
314 | + * @return float a file size in bytes |
|
315 | + * |
|
316 | + * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
317 | + * @since 4.0.0 |
|
318 | + */ |
|
319 | + public static function computerFileSize($str) { |
|
320 | + return \OC_Helper::computerFileSize($str); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * connects a function to a hook |
|
325 | + * |
|
326 | + * @param string $signalClass class name of emitter |
|
327 | + * @param string $signalName name of signal |
|
328 | + * @param string|object $slotClass class name of slot |
|
329 | + * @param string $slotName name of slot |
|
330 | + * @return bool |
|
331 | + * |
|
332 | + * This function makes it very easy to connect to use hooks. |
|
333 | + * |
|
334 | + * TODO: write example |
|
335 | + * @since 4.0.0 |
|
336 | + */ |
|
337 | + static public function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
338 | + return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Emits a signal. To get data from the slot use references! |
|
343 | + * @param string $signalclass class name of emitter |
|
344 | + * @param string $signalname name of signal |
|
345 | + * @param array $params default: array() array with additional data |
|
346 | + * @return bool true if slots exists or false if not |
|
347 | + * |
|
348 | + * TODO: write example |
|
349 | + * @since 4.0.0 |
|
350 | + */ |
|
351 | + static public function emitHook($signalclass, $signalname, $params = []) { |
|
352 | + return \OC_Hook::emit($signalclass, $signalname, $params); |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
357 | + * multiple OC_Template elements which invoke `callRegister`. If the value |
|
358 | + * would not be cached these unit-tests would fail. |
|
359 | + * @var string |
|
360 | + */ |
|
361 | + private static $token = ''; |
|
362 | + |
|
363 | + /** |
|
364 | + * Register an get/post call. This is important to prevent CSRF attacks |
|
365 | + * @since 4.5.0 |
|
366 | + */ |
|
367 | + public static function callRegister() { |
|
368 | + if(self::$token === '') { |
|
369 | + self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
370 | + } |
|
371 | + return self::$token; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Used to sanitize HTML |
|
376 | + * |
|
377 | + * This function is used to sanitize HTML and should be applied on any |
|
378 | + * string or array of strings before displaying it on a web page. |
|
379 | + * |
|
380 | + * @param string|array $value |
|
381 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
382 | + * @since 4.5.0 |
|
383 | + */ |
|
384 | + public static function sanitizeHTML($value) { |
|
385 | + return \OC_Util::sanitizeHTML($value); |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Public function to encode url parameters |
|
390 | + * |
|
391 | + * This function is used to encode path to file before output. |
|
392 | + * Encoding is done according to RFC 3986 with one exception: |
|
393 | + * Character '/' is preserved as is. |
|
394 | + * |
|
395 | + * @param string $component part of URI to encode |
|
396 | + * @return string |
|
397 | + * @since 6.0.0 |
|
398 | + */ |
|
399 | + public static function encodePath($component) { |
|
400 | + return \OC_Util::encodePath($component); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
405 | + * |
|
406 | + * @param array $input The array to work on |
|
407 | + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
408 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
409 | + * @return array |
|
410 | + * @since 4.5.0 |
|
411 | + */ |
|
412 | + public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
413 | + return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * performs a search in a nested array |
|
418 | + * |
|
419 | + * @param array $haystack the array to be searched |
|
420 | + * @param string $needle the search string |
|
421 | + * @param mixed $index optional, only search this key name |
|
422 | + * @return mixed the key of the matching field, otherwise false |
|
423 | + * @since 4.5.0 |
|
424 | + * @deprecated 15.0.0 |
|
425 | + */ |
|
426 | + public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
427 | + return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * calculates the maximum upload size respecting system settings, free space and user quota |
|
432 | + * |
|
433 | + * @param string $dir the current folder where the user currently operates |
|
434 | + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
435 | + * @return int number of bytes representing |
|
436 | + * @since 5.0.0 |
|
437 | + */ |
|
438 | + public static function maxUploadFilesize($dir, $free = null) { |
|
439 | + return \OC_Helper::maxUploadFilesize($dir, $free); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Calculate free space left within user quota |
|
444 | + * @param string $dir the current folder where the user currently operates |
|
445 | + * @return int number of bytes representing |
|
446 | + * @since 7.0.0 |
|
447 | + */ |
|
448 | + public static function freeSpace($dir) { |
|
449 | + return \OC_Helper::freeSpace($dir); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Calculate PHP upload limit |
|
454 | + * |
|
455 | + * @return int number of bytes representing |
|
456 | + * @since 7.0.0 |
|
457 | + */ |
|
458 | + public static function uploadLimit() { |
|
459 | + return \OC_Helper::uploadLimit(); |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Returns whether the given file name is valid |
|
464 | + * @param string $file file name to check |
|
465 | + * @return bool true if the file name is valid, false otherwise |
|
466 | + * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
467 | + * @since 7.0.0 |
|
468 | + * @suppress PhanDeprecatedFunction |
|
469 | + */ |
|
470 | + public static function isValidFileName($file) { |
|
471 | + return \OC_Util::isValidFileName($file); |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Compare two strings to provide a natural sort |
|
476 | + * @param string $a first string to compare |
|
477 | + * @param string $b second string to compare |
|
478 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
479 | + * or 0 if the strings are identical |
|
480 | + * @since 7.0.0 |
|
481 | + */ |
|
482 | + public static function naturalSortCompare($a, $b) { |
|
483 | + return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * check if a password is required for each public link |
|
488 | + * @return boolean |
|
489 | + * @since 7.0.0 |
|
490 | + */ |
|
491 | + public static function isPublicLinkPasswordRequired() { |
|
492 | + return \OC_Util::isPublicLinkPasswordRequired(); |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * check if share API enforces a default expire date |
|
497 | + * @return boolean |
|
498 | + * @since 8.0.0 |
|
499 | + */ |
|
500 | + public static function isDefaultExpireDateEnforced() { |
|
501 | + return \OC_Util::isDefaultExpireDateEnforced(); |
|
502 | + } |
|
503 | + |
|
504 | + protected static $needUpgradeCache = null; |
|
505 | + |
|
506 | + /** |
|
507 | + * Checks whether the current version needs upgrade. |
|
508 | + * |
|
509 | + * @return bool true if upgrade is needed, false otherwise |
|
510 | + * @since 7.0.0 |
|
511 | + */ |
|
512 | + public static function needUpgrade() { |
|
513 | + if (!isset(self::$needUpgradeCache)) { |
|
514 | + self::$needUpgradeCache=\OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
515 | + } |
|
516 | + return self::$needUpgradeCache; |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * is this Internet explorer ? |
|
521 | + * |
|
522 | + * @return boolean |
|
523 | + * @since 14.0.0 |
|
524 | + */ |
|
525 | + public static function isIe() { |
|
526 | + return \OC_Util::isIe(); |
|
527 | + } |
|
528 | 528 | } |
@@ -53,132 +53,132 @@ |
||
53 | 53 | */ |
54 | 54 | interface IManager { |
55 | 55 | |
56 | - /** |
|
57 | - * This function is used to search and find contacts within the users address books. |
|
58 | - * In case $pattern is empty all contacts will be returned. |
|
59 | - * |
|
60 | - * Example: |
|
61 | - * Following function shows how to search for contacts for the name and the email address. |
|
62 | - * |
|
63 | - * public static function getMatchingRecipient($term) { |
|
64 | - * $cm = \OC::$server->getContactsManager(); |
|
65 | - * // The API is not active -> nothing to do |
|
66 | - * if (!$cm->isEnabled()) { |
|
67 | - * return array(); |
|
68 | - * } |
|
69 | - * |
|
70 | - * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
71 | - * $receivers = array(); |
|
72 | - * foreach ($result as $r) { |
|
73 | - * $id = $r['id']; |
|
74 | - * $fn = $r['FN']; |
|
75 | - * $email = $r['EMAIL']; |
|
76 | - * if (!is_array($email)) { |
|
77 | - * $email = array($email); |
|
78 | - * } |
|
79 | - * |
|
80 | - * // loop through all email addresses of this contact |
|
81 | - * foreach ($email as $e) { |
|
82 | - * $displayName = $fn . " <$e>"; |
|
83 | - * $receivers[] = array( |
|
84 | - * 'id' => $id, |
|
85 | - * 'label' => $displayName, |
|
86 | - * 'value' => $displayName); |
|
87 | - * } |
|
88 | - * } |
|
89 | - * |
|
90 | - * return $receivers; |
|
91 | - * } |
|
92 | - * |
|
93 | - * |
|
94 | - * @param string $pattern which should match within the $searchProperties |
|
95 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
96 | - * @param array $options = array() to define the search behavior |
|
97 | - * - 'escape_like_param' - If set to false wildcards _ and % are not escaped |
|
98 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
99 | - * @since 6.0.0 |
|
100 | - */ |
|
101 | - public function search($pattern, $searchProperties = [], $options = []); |
|
56 | + /** |
|
57 | + * This function is used to search and find contacts within the users address books. |
|
58 | + * In case $pattern is empty all contacts will be returned. |
|
59 | + * |
|
60 | + * Example: |
|
61 | + * Following function shows how to search for contacts for the name and the email address. |
|
62 | + * |
|
63 | + * public static function getMatchingRecipient($term) { |
|
64 | + * $cm = \OC::$server->getContactsManager(); |
|
65 | + * // The API is not active -> nothing to do |
|
66 | + * if (!$cm->isEnabled()) { |
|
67 | + * return array(); |
|
68 | + * } |
|
69 | + * |
|
70 | + * $result = $cm->search($term, array('FN', 'EMAIL')); |
|
71 | + * $receivers = array(); |
|
72 | + * foreach ($result as $r) { |
|
73 | + * $id = $r['id']; |
|
74 | + * $fn = $r['FN']; |
|
75 | + * $email = $r['EMAIL']; |
|
76 | + * if (!is_array($email)) { |
|
77 | + * $email = array($email); |
|
78 | + * } |
|
79 | + * |
|
80 | + * // loop through all email addresses of this contact |
|
81 | + * foreach ($email as $e) { |
|
82 | + * $displayName = $fn . " <$e>"; |
|
83 | + * $receivers[] = array( |
|
84 | + * 'id' => $id, |
|
85 | + * 'label' => $displayName, |
|
86 | + * 'value' => $displayName); |
|
87 | + * } |
|
88 | + * } |
|
89 | + * |
|
90 | + * return $receivers; |
|
91 | + * } |
|
92 | + * |
|
93 | + * |
|
94 | + * @param string $pattern which should match within the $searchProperties |
|
95 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
96 | + * @param array $options = array() to define the search behavior |
|
97 | + * - 'escape_like_param' - If set to false wildcards _ and % are not escaped |
|
98 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
99 | + * @since 6.0.0 |
|
100 | + */ |
|
101 | + public function search($pattern, $searchProperties = [], $options = []); |
|
102 | 102 | |
103 | - /** |
|
104 | - * This function can be used to delete the contact identified by the given id |
|
105 | - * |
|
106 | - * @param object $id the unique identifier to a contact |
|
107 | - * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
108 | - * @return bool successful or not |
|
109 | - * @since 6.0.0 |
|
110 | - */ |
|
111 | - public function delete($id, $address_book_key); |
|
103 | + /** |
|
104 | + * This function can be used to delete the contact identified by the given id |
|
105 | + * |
|
106 | + * @param object $id the unique identifier to a contact |
|
107 | + * @param string $address_book_key identifier of the address book in which the contact shall be deleted |
|
108 | + * @return bool successful or not |
|
109 | + * @since 6.0.0 |
|
110 | + */ |
|
111 | + public function delete($id, $address_book_key); |
|
112 | 112 | |
113 | - /** |
|
114 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
115 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
116 | - * |
|
117 | - * @param array $properties this array if key-value-pairs defines a contact |
|
118 | - * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
119 | - * @return array an array representing the contact just created or updated |
|
120 | - * @since 6.0.0 |
|
121 | - */ |
|
122 | - public function createOrUpdate($properties, $address_book_key); |
|
113 | + /** |
|
114 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
115 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
116 | + * |
|
117 | + * @param array $properties this array if key-value-pairs defines a contact |
|
118 | + * @param string $address_book_key identifier of the address book in which the contact shall be created or updated |
|
119 | + * @return array an array representing the contact just created or updated |
|
120 | + * @since 6.0.0 |
|
121 | + */ |
|
122 | + public function createOrUpdate($properties, $address_book_key); |
|
123 | 123 | |
124 | - /** |
|
125 | - * Check if contacts are available (e.g. contacts app enabled) |
|
126 | - * |
|
127 | - * @return bool true if enabled, false if not |
|
128 | - * @since 6.0.0 |
|
129 | - */ |
|
130 | - public function isEnabled(); |
|
124 | + /** |
|
125 | + * Check if contacts are available (e.g. contacts app enabled) |
|
126 | + * |
|
127 | + * @return bool true if enabled, false if not |
|
128 | + * @since 6.0.0 |
|
129 | + */ |
|
130 | + public function isEnabled(); |
|
131 | 131 | |
132 | - /** |
|
133 | - * Registers an address book |
|
134 | - * |
|
135 | - * @param \OCP\IAddressBook $address_book |
|
136 | - * @return void |
|
137 | - * @since 6.0.0 |
|
138 | - */ |
|
139 | - public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
132 | + /** |
|
133 | + * Registers an address book |
|
134 | + * |
|
135 | + * @param \OCP\IAddressBook $address_book |
|
136 | + * @return void |
|
137 | + * @since 6.0.0 |
|
138 | + */ |
|
139 | + public function registerAddressBook(\OCP\IAddressBook $address_book); |
|
140 | 140 | |
141 | - /** |
|
142 | - * Unregisters an address book |
|
143 | - * |
|
144 | - * @param \OCP\IAddressBook $address_book |
|
145 | - * @return void |
|
146 | - * @since 6.0.0 |
|
147 | - */ |
|
148 | - public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
141 | + /** |
|
142 | + * Unregisters an address book |
|
143 | + * |
|
144 | + * @param \OCP\IAddressBook $address_book |
|
145 | + * @return void |
|
146 | + * @since 6.0.0 |
|
147 | + */ |
|
148 | + public function unregisterAddressBook(\OCP\IAddressBook $address_book); |
|
149 | 149 | |
150 | - /** |
|
151 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
152 | - * address books are actually requested |
|
153 | - * |
|
154 | - * @param \Closure $callable |
|
155 | - * @return void |
|
156 | - * @since 6.0.0 |
|
157 | - */ |
|
158 | - public function register(\Closure $callable); |
|
150 | + /** |
|
151 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
152 | + * address books are actually requested |
|
153 | + * |
|
154 | + * @param \Closure $callable |
|
155 | + * @return void |
|
156 | + * @since 6.0.0 |
|
157 | + */ |
|
158 | + public function register(\Closure $callable); |
|
159 | 159 | |
160 | - /** |
|
161 | - * Return a list of the user's addressbooks display names |
|
162 | - * |
|
163 | - * @return array |
|
164 | - * @since 6.0.0 |
|
165 | - * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
166 | - */ |
|
167 | - public function getAddressBooks(); |
|
160 | + /** |
|
161 | + * Return a list of the user's addressbooks display names |
|
162 | + * |
|
163 | + * @return array |
|
164 | + * @since 6.0.0 |
|
165 | + * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
166 | + */ |
|
167 | + public function getAddressBooks(); |
|
168 | 168 | |
169 | - /** |
|
170 | - * Return a list of the user's addressbooks |
|
171 | - * |
|
172 | - * @return IAddressBook[] |
|
173 | - * @since 16.0.0 |
|
174 | - */ |
|
175 | - public function getUserAddressBooks(); |
|
169 | + /** |
|
170 | + * Return a list of the user's addressbooks |
|
171 | + * |
|
172 | + * @return IAddressBook[] |
|
173 | + * @since 16.0.0 |
|
174 | + */ |
|
175 | + public function getUserAddressBooks(); |
|
176 | 176 | |
177 | - /** |
|
178 | - * removes all registered address book instances |
|
179 | - * |
|
180 | - * @return void |
|
181 | - * @since 6.0.0 |
|
182 | - */ |
|
183 | - public function clear(); |
|
177 | + /** |
|
178 | + * removes all registered address book instances |
|
179 | + * |
|
180 | + * @return void |
|
181 | + * @since 6.0.0 |
|
182 | + */ |
|
183 | + public function clear(); |
|
184 | 184 | } |
@@ -48,256 +48,256 @@ |
||
48 | 48 | */ |
49 | 49 | interface IDBConnection { |
50 | 50 | |
51 | - const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES'; |
|
52 | - const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES'; |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets the QueryBuilder for the connection. |
|
56 | - * |
|
57 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
58 | - * @since 8.2.0 |
|
59 | - */ |
|
60 | - public function getQueryBuilder(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Used to abstract the ownCloud database access away |
|
64 | - * @param string $sql the sql query with ? placeholder for params |
|
65 | - * @param int $limit the maximum number of rows |
|
66 | - * @param int $offset from which row we want to start |
|
67 | - * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
68 | - * @since 6.0.0 |
|
69 | - */ |
|
70 | - public function prepare($sql, $limit=null, $offset=null); |
|
71 | - |
|
72 | - /** |
|
73 | - * Executes an, optionally parameterized, SQL query. |
|
74 | - * |
|
75 | - * If the query is parameterized, a prepared statement is used. |
|
76 | - * If an SQLLogger is configured, the execution is logged. |
|
77 | - * |
|
78 | - * @param string $query The SQL query to execute. |
|
79 | - * @param string[] $params The parameters to bind to the query, if any. |
|
80 | - * @param array $types The types the previous parameters are in. |
|
81 | - * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
82 | - * @since 8.0.0 |
|
83 | - */ |
|
84 | - public function executeQuery($query, array $params = [], $types = []); |
|
85 | - |
|
86 | - /** |
|
87 | - * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
88 | - * and returns the number of affected rows. |
|
89 | - * |
|
90 | - * This method supports PDO binding types as well as DBAL mapping types. |
|
91 | - * |
|
92 | - * @param string $query The SQL query. |
|
93 | - * @param array $params The query parameters. |
|
94 | - * @param array $types The parameter types. |
|
95 | - * @return integer The number of affected rows. |
|
96 | - * @since 8.0.0 |
|
97 | - */ |
|
98 | - public function executeUpdate($query, array $params = [], array $types = []); |
|
99 | - |
|
100 | - /** |
|
101 | - * Used to get the id of the just inserted element |
|
102 | - * @param string $table the name of the table where we inserted the item |
|
103 | - * @return int the id of the inserted element |
|
104 | - * @since 6.0.0 |
|
105 | - */ |
|
106 | - public function lastInsertId($table = null); |
|
107 | - |
|
108 | - /** |
|
109 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
110 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
111 | - * catch the exception and return 0. |
|
112 | - * |
|
113 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
114 | - * @param array $input data that should be inserted into the table (column name => value) |
|
115 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
116 | - * If this is null or an empty array, all keys of $input will be compared |
|
117 | - * Please note: text fields (clob) must not be used in the compare array |
|
118 | - * @return int number of inserted rows |
|
119 | - * @throws \Doctrine\DBAL\DBALException |
|
120 | - * @since 6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0 |
|
121 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
122 | - */ |
|
123 | - public function insertIfNotExist($table, $input, array $compare = null); |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * |
|
128 | - * Insert a row if the row does not exist. Eventual conflicts during insert will be ignored. |
|
129 | - * |
|
130 | - * Implementation is not fully finished and should not be used! |
|
131 | - * |
|
132 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
133 | - * @param array $values data that should be inserted into the table (column name => value) |
|
134 | - * @return int number of inserted rows |
|
135 | - * @since 16.0.0 |
|
136 | - */ |
|
137 | - public function insertIgnoreConflict(string $table,array $values) : int; |
|
138 | - |
|
139 | - /** |
|
140 | - * Insert or update a row value |
|
141 | - * |
|
142 | - * @param string $table |
|
143 | - * @param array $keys (column name => value) |
|
144 | - * @param array $values (column name => value) |
|
145 | - * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
146 | - * @return int number of new rows |
|
147 | - * @throws \Doctrine\DBAL\DBALException |
|
148 | - * @throws PreconditionNotMetException |
|
149 | - * @since 9.0.0 |
|
150 | - */ |
|
151 | - public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []); |
|
152 | - |
|
153 | - /** |
|
154 | - * Create an exclusive read+write lock on a table |
|
155 | - * |
|
156 | - * Important Note: Due to the nature how locks work on different DBs, it is |
|
157 | - * only possible to lock one table at a time. You should also NOT start a |
|
158 | - * transaction while holding a lock. |
|
159 | - * |
|
160 | - * @param string $tableName |
|
161 | - * @since 9.1.0 |
|
162 | - */ |
|
163 | - public function lockTable($tableName); |
|
164 | - |
|
165 | - /** |
|
166 | - * Release a previous acquired lock again |
|
167 | - * |
|
168 | - * @since 9.1.0 |
|
169 | - */ |
|
170 | - public function unlockTable(); |
|
171 | - |
|
172 | - /** |
|
173 | - * Start a transaction |
|
174 | - * @since 6.0.0 |
|
175 | - */ |
|
176 | - public function beginTransaction(); |
|
177 | - |
|
178 | - /** |
|
179 | - * Check if a transaction is active |
|
180 | - * |
|
181 | - * @return bool |
|
182 | - * @since 8.2.0 |
|
183 | - */ |
|
184 | - public function inTransaction(); |
|
185 | - |
|
186 | - /** |
|
187 | - * Commit the database changes done during a transaction that is in progress |
|
188 | - * @since 6.0.0 |
|
189 | - */ |
|
190 | - public function commit(); |
|
191 | - |
|
192 | - /** |
|
193 | - * Rollback the database changes done during a transaction that is in progress |
|
194 | - * @since 6.0.0 |
|
195 | - */ |
|
196 | - public function rollBack(); |
|
197 | - |
|
198 | - /** |
|
199 | - * Gets the error code and message as a string for logging |
|
200 | - * @return string |
|
201 | - * @since 6.0.0 |
|
202 | - */ |
|
203 | - public function getError(); |
|
204 | - |
|
205 | - /** |
|
206 | - * Fetch the SQLSTATE associated with the last database operation. |
|
207 | - * |
|
208 | - * @return integer The last error code. |
|
209 | - * @since 8.0.0 |
|
210 | - */ |
|
211 | - public function errorCode(); |
|
212 | - |
|
213 | - /** |
|
214 | - * Fetch extended error information associated with the last database operation. |
|
215 | - * |
|
216 | - * @return array The last error information. |
|
217 | - * @since 8.0.0 |
|
218 | - */ |
|
219 | - public function errorInfo(); |
|
220 | - |
|
221 | - /** |
|
222 | - * Establishes the connection with the database. |
|
223 | - * |
|
224 | - * @return bool |
|
225 | - * @since 8.0.0 |
|
226 | - */ |
|
227 | - public function connect(); |
|
228 | - |
|
229 | - /** |
|
230 | - * Close the database connection |
|
231 | - * @since 8.0.0 |
|
232 | - */ |
|
233 | - public function close(); |
|
234 | - |
|
235 | - /** |
|
236 | - * Quotes a given input parameter. |
|
237 | - * |
|
238 | - * @param mixed $input Parameter to be quoted. |
|
239 | - * @param int $type Type of the parameter. |
|
240 | - * @return string The quoted parameter. |
|
241 | - * @since 8.0.0 |
|
242 | - */ |
|
243 | - public function quote($input, $type = IQueryBuilder::PARAM_STR); |
|
244 | - |
|
245 | - /** |
|
246 | - * Gets the DatabasePlatform instance that provides all the metadata about |
|
247 | - * the platform this driver connects to. |
|
248 | - * |
|
249 | - * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform. |
|
250 | - * @since 8.0.0 |
|
251 | - */ |
|
252 | - public function getDatabasePlatform(); |
|
253 | - |
|
254 | - /** |
|
255 | - * Drop a table from the database if it exists |
|
256 | - * |
|
257 | - * @param string $table table name without the prefix |
|
258 | - * @since 8.0.0 |
|
259 | - */ |
|
260 | - public function dropTable($table); |
|
261 | - |
|
262 | - /** |
|
263 | - * Check if a table exists |
|
264 | - * |
|
265 | - * @param string $table table name without the prefix |
|
266 | - * @return bool |
|
267 | - * @since 8.0.0 |
|
268 | - */ |
|
269 | - public function tableExists($table); |
|
270 | - |
|
271 | - /** |
|
272 | - * Escape a parameter to be used in a LIKE query |
|
273 | - * |
|
274 | - * @param string $param |
|
275 | - * @return string |
|
276 | - * @since 9.0.0 |
|
277 | - */ |
|
278 | - public function escapeLikeParameter($param); |
|
279 | - |
|
280 | - /** |
|
281 | - * Check whether or not the current database support 4byte wide unicode |
|
282 | - * |
|
283 | - * @return bool |
|
284 | - * @since 11.0.0 |
|
285 | - */ |
|
286 | - public function supports4ByteText(); |
|
287 | - |
|
288 | - /** |
|
289 | - * Create the schema of the connected database |
|
290 | - * |
|
291 | - * @return Schema |
|
292 | - * @since 13.0.0 |
|
293 | - */ |
|
294 | - public function createSchema(); |
|
295 | - |
|
296 | - /** |
|
297 | - * Migrate the database to the given schema |
|
298 | - * |
|
299 | - * @param Schema $toSchema |
|
300 | - * @since 13.0.0 |
|
301 | - */ |
|
302 | - public function migrateToSchema(Schema $toSchema); |
|
51 | + const ADD_MISSING_INDEXES_EVENT = self::class . '::ADD_MISSING_INDEXES'; |
|
52 | + const CHECK_MISSING_INDEXES_EVENT = self::class . '::CHECK_MISSING_INDEXES'; |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets the QueryBuilder for the connection. |
|
56 | + * |
|
57 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
58 | + * @since 8.2.0 |
|
59 | + */ |
|
60 | + public function getQueryBuilder(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Used to abstract the ownCloud database access away |
|
64 | + * @param string $sql the sql query with ? placeholder for params |
|
65 | + * @param int $limit the maximum number of rows |
|
66 | + * @param int $offset from which row we want to start |
|
67 | + * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
68 | + * @since 6.0.0 |
|
69 | + */ |
|
70 | + public function prepare($sql, $limit=null, $offset=null); |
|
71 | + |
|
72 | + /** |
|
73 | + * Executes an, optionally parameterized, SQL query. |
|
74 | + * |
|
75 | + * If the query is parameterized, a prepared statement is used. |
|
76 | + * If an SQLLogger is configured, the execution is logged. |
|
77 | + * |
|
78 | + * @param string $query The SQL query to execute. |
|
79 | + * @param string[] $params The parameters to bind to the query, if any. |
|
80 | + * @param array $types The types the previous parameters are in. |
|
81 | + * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
82 | + * @since 8.0.0 |
|
83 | + */ |
|
84 | + public function executeQuery($query, array $params = [], $types = []); |
|
85 | + |
|
86 | + /** |
|
87 | + * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
88 | + * and returns the number of affected rows. |
|
89 | + * |
|
90 | + * This method supports PDO binding types as well as DBAL mapping types. |
|
91 | + * |
|
92 | + * @param string $query The SQL query. |
|
93 | + * @param array $params The query parameters. |
|
94 | + * @param array $types The parameter types. |
|
95 | + * @return integer The number of affected rows. |
|
96 | + * @since 8.0.0 |
|
97 | + */ |
|
98 | + public function executeUpdate($query, array $params = [], array $types = []); |
|
99 | + |
|
100 | + /** |
|
101 | + * Used to get the id of the just inserted element |
|
102 | + * @param string $table the name of the table where we inserted the item |
|
103 | + * @return int the id of the inserted element |
|
104 | + * @since 6.0.0 |
|
105 | + */ |
|
106 | + public function lastInsertId($table = null); |
|
107 | + |
|
108 | + /** |
|
109 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
110 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
111 | + * catch the exception and return 0. |
|
112 | + * |
|
113 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
114 | + * @param array $input data that should be inserted into the table (column name => value) |
|
115 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
116 | + * If this is null or an empty array, all keys of $input will be compared |
|
117 | + * Please note: text fields (clob) must not be used in the compare array |
|
118 | + * @return int number of inserted rows |
|
119 | + * @throws \Doctrine\DBAL\DBALException |
|
120 | + * @since 6.0.0 - parameter $compare was added in 8.1.0, return type changed from boolean in 8.1.0 |
|
121 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
122 | + */ |
|
123 | + public function insertIfNotExist($table, $input, array $compare = null); |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * |
|
128 | + * Insert a row if the row does not exist. Eventual conflicts during insert will be ignored. |
|
129 | + * |
|
130 | + * Implementation is not fully finished and should not be used! |
|
131 | + * |
|
132 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
133 | + * @param array $values data that should be inserted into the table (column name => value) |
|
134 | + * @return int number of inserted rows |
|
135 | + * @since 16.0.0 |
|
136 | + */ |
|
137 | + public function insertIgnoreConflict(string $table,array $values) : int; |
|
138 | + |
|
139 | + /** |
|
140 | + * Insert or update a row value |
|
141 | + * |
|
142 | + * @param string $table |
|
143 | + * @param array $keys (column name => value) |
|
144 | + * @param array $values (column name => value) |
|
145 | + * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
146 | + * @return int number of new rows |
|
147 | + * @throws \Doctrine\DBAL\DBALException |
|
148 | + * @throws PreconditionNotMetException |
|
149 | + * @since 9.0.0 |
|
150 | + */ |
|
151 | + public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []); |
|
152 | + |
|
153 | + /** |
|
154 | + * Create an exclusive read+write lock on a table |
|
155 | + * |
|
156 | + * Important Note: Due to the nature how locks work on different DBs, it is |
|
157 | + * only possible to lock one table at a time. You should also NOT start a |
|
158 | + * transaction while holding a lock. |
|
159 | + * |
|
160 | + * @param string $tableName |
|
161 | + * @since 9.1.0 |
|
162 | + */ |
|
163 | + public function lockTable($tableName); |
|
164 | + |
|
165 | + /** |
|
166 | + * Release a previous acquired lock again |
|
167 | + * |
|
168 | + * @since 9.1.0 |
|
169 | + */ |
|
170 | + public function unlockTable(); |
|
171 | + |
|
172 | + /** |
|
173 | + * Start a transaction |
|
174 | + * @since 6.0.0 |
|
175 | + */ |
|
176 | + public function beginTransaction(); |
|
177 | + |
|
178 | + /** |
|
179 | + * Check if a transaction is active |
|
180 | + * |
|
181 | + * @return bool |
|
182 | + * @since 8.2.0 |
|
183 | + */ |
|
184 | + public function inTransaction(); |
|
185 | + |
|
186 | + /** |
|
187 | + * Commit the database changes done during a transaction that is in progress |
|
188 | + * @since 6.0.0 |
|
189 | + */ |
|
190 | + public function commit(); |
|
191 | + |
|
192 | + /** |
|
193 | + * Rollback the database changes done during a transaction that is in progress |
|
194 | + * @since 6.0.0 |
|
195 | + */ |
|
196 | + public function rollBack(); |
|
197 | + |
|
198 | + /** |
|
199 | + * Gets the error code and message as a string for logging |
|
200 | + * @return string |
|
201 | + * @since 6.0.0 |
|
202 | + */ |
|
203 | + public function getError(); |
|
204 | + |
|
205 | + /** |
|
206 | + * Fetch the SQLSTATE associated with the last database operation. |
|
207 | + * |
|
208 | + * @return integer The last error code. |
|
209 | + * @since 8.0.0 |
|
210 | + */ |
|
211 | + public function errorCode(); |
|
212 | + |
|
213 | + /** |
|
214 | + * Fetch extended error information associated with the last database operation. |
|
215 | + * |
|
216 | + * @return array The last error information. |
|
217 | + * @since 8.0.0 |
|
218 | + */ |
|
219 | + public function errorInfo(); |
|
220 | + |
|
221 | + /** |
|
222 | + * Establishes the connection with the database. |
|
223 | + * |
|
224 | + * @return bool |
|
225 | + * @since 8.0.0 |
|
226 | + */ |
|
227 | + public function connect(); |
|
228 | + |
|
229 | + /** |
|
230 | + * Close the database connection |
|
231 | + * @since 8.0.0 |
|
232 | + */ |
|
233 | + public function close(); |
|
234 | + |
|
235 | + /** |
|
236 | + * Quotes a given input parameter. |
|
237 | + * |
|
238 | + * @param mixed $input Parameter to be quoted. |
|
239 | + * @param int $type Type of the parameter. |
|
240 | + * @return string The quoted parameter. |
|
241 | + * @since 8.0.0 |
|
242 | + */ |
|
243 | + public function quote($input, $type = IQueryBuilder::PARAM_STR); |
|
244 | + |
|
245 | + /** |
|
246 | + * Gets the DatabasePlatform instance that provides all the metadata about |
|
247 | + * the platform this driver connects to. |
|
248 | + * |
|
249 | + * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform. |
|
250 | + * @since 8.0.0 |
|
251 | + */ |
|
252 | + public function getDatabasePlatform(); |
|
253 | + |
|
254 | + /** |
|
255 | + * Drop a table from the database if it exists |
|
256 | + * |
|
257 | + * @param string $table table name without the prefix |
|
258 | + * @since 8.0.0 |
|
259 | + */ |
|
260 | + public function dropTable($table); |
|
261 | + |
|
262 | + /** |
|
263 | + * Check if a table exists |
|
264 | + * |
|
265 | + * @param string $table table name without the prefix |
|
266 | + * @return bool |
|
267 | + * @since 8.0.0 |
|
268 | + */ |
|
269 | + public function tableExists($table); |
|
270 | + |
|
271 | + /** |
|
272 | + * Escape a parameter to be used in a LIKE query |
|
273 | + * |
|
274 | + * @param string $param |
|
275 | + * @return string |
|
276 | + * @since 9.0.0 |
|
277 | + */ |
|
278 | + public function escapeLikeParameter($param); |
|
279 | + |
|
280 | + /** |
|
281 | + * Check whether or not the current database support 4byte wide unicode |
|
282 | + * |
|
283 | + * @return bool |
|
284 | + * @since 11.0.0 |
|
285 | + */ |
|
286 | + public function supports4ByteText(); |
|
287 | + |
|
288 | + /** |
|
289 | + * Create the schema of the connected database |
|
290 | + * |
|
291 | + * @return Schema |
|
292 | + * @since 13.0.0 |
|
293 | + */ |
|
294 | + public function createSchema(); |
|
295 | + |
|
296 | + /** |
|
297 | + * Migrate the database to the given schema |
|
298 | + * |
|
299 | + * @param Schema $toSchema |
|
300 | + * @since 13.0.0 |
|
301 | + */ |
|
302 | + public function migrateToSchema(Schema $toSchema); |
|
303 | 303 | } |
@@ -39,219 +39,219 @@ |
||
39 | 39 | * Takes care of creating and configuring Doctrine connections. |
40 | 40 | */ |
41 | 41 | class ConnectionFactory { |
42 | - /** @var string default database name */ |
|
43 | - const DEFAULT_DBNAME = 'owncloud'; |
|
42 | + /** @var string default database name */ |
|
43 | + const DEFAULT_DBNAME = 'owncloud'; |
|
44 | 44 | |
45 | - /** @var string default database table prefix */ |
|
46 | - const DEFAULT_DBTABLEPREFIX = 'oc_'; |
|
45 | + /** @var string default database table prefix */ |
|
46 | + const DEFAULT_DBTABLEPREFIX = 'oc_'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - * |
|
51 | - * Array mapping DBMS type to default connection parameters passed to |
|
52 | - * \Doctrine\DBAL\DriverManager::getConnection(). |
|
53 | - */ |
|
54 | - protected $defaultConnectionParams = [ |
|
55 | - 'mysql' => [ |
|
56 | - 'adapter' => AdapterMySQL::class, |
|
57 | - 'charset' => 'UTF8', |
|
58 | - 'driver' => 'pdo_mysql', |
|
59 | - 'wrapperClass' => Connection::class, |
|
60 | - ], |
|
61 | - 'oci' => [ |
|
62 | - 'adapter' => AdapterOCI8::class, |
|
63 | - 'charset' => 'AL32UTF8', |
|
64 | - 'driver' => 'oci8', |
|
65 | - 'wrapperClass' => OracleConnection::class, |
|
66 | - ], |
|
67 | - 'pgsql' => [ |
|
68 | - 'adapter' => AdapterPgSql::class, |
|
69 | - 'driver' => 'pdo_pgsql', |
|
70 | - 'wrapperClass' => Connection::class, |
|
71 | - ], |
|
72 | - 'sqlite3' => [ |
|
73 | - 'adapter' => AdapterSqlite::class, |
|
74 | - 'driver' => 'pdo_sqlite', |
|
75 | - 'wrapperClass' => Connection::class, |
|
76 | - ], |
|
77 | - ]; |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + * |
|
51 | + * Array mapping DBMS type to default connection parameters passed to |
|
52 | + * \Doctrine\DBAL\DriverManager::getConnection(). |
|
53 | + */ |
|
54 | + protected $defaultConnectionParams = [ |
|
55 | + 'mysql' => [ |
|
56 | + 'adapter' => AdapterMySQL::class, |
|
57 | + 'charset' => 'UTF8', |
|
58 | + 'driver' => 'pdo_mysql', |
|
59 | + 'wrapperClass' => Connection::class, |
|
60 | + ], |
|
61 | + 'oci' => [ |
|
62 | + 'adapter' => AdapterOCI8::class, |
|
63 | + 'charset' => 'AL32UTF8', |
|
64 | + 'driver' => 'oci8', |
|
65 | + 'wrapperClass' => OracleConnection::class, |
|
66 | + ], |
|
67 | + 'pgsql' => [ |
|
68 | + 'adapter' => AdapterPgSql::class, |
|
69 | + 'driver' => 'pdo_pgsql', |
|
70 | + 'wrapperClass' => Connection::class, |
|
71 | + ], |
|
72 | + 'sqlite3' => [ |
|
73 | + 'adapter' => AdapterSqlite::class, |
|
74 | + 'driver' => 'pdo_sqlite', |
|
75 | + 'wrapperClass' => Connection::class, |
|
76 | + ], |
|
77 | + ]; |
|
78 | 78 | |
79 | - /** @var SystemConfig */ |
|
80 | - private $config; |
|
79 | + /** @var SystemConfig */ |
|
80 | + private $config; |
|
81 | 81 | |
82 | - /** |
|
83 | - * ConnectionFactory constructor. |
|
84 | - * |
|
85 | - * @param SystemConfig $systemConfig |
|
86 | - */ |
|
87 | - public function __construct(SystemConfig $systemConfig) { |
|
88 | - $this->config = $systemConfig; |
|
89 | - if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
90 | - $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4'; |
|
91 | - } |
|
92 | - } |
|
82 | + /** |
|
83 | + * ConnectionFactory constructor. |
|
84 | + * |
|
85 | + * @param SystemConfig $systemConfig |
|
86 | + */ |
|
87 | + public function __construct(SystemConfig $systemConfig) { |
|
88 | + $this->config = $systemConfig; |
|
89 | + if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
90 | + $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4'; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @brief Get default connection parameters for a given DBMS. |
|
96 | - * @param string $type DBMS type |
|
97 | - * @throws \InvalidArgumentException If $type is invalid |
|
98 | - * @return array Default connection parameters. |
|
99 | - */ |
|
100 | - public function getDefaultConnectionParams($type) { |
|
101 | - $normalizedType = $this->normalizeType($type); |
|
102 | - if (!isset($this->defaultConnectionParams[$normalizedType])) { |
|
103 | - throw new \InvalidArgumentException("Unsupported type: $type"); |
|
104 | - } |
|
105 | - $result = $this->defaultConnectionParams[$normalizedType]; |
|
106 | - // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL |
|
107 | - // driver is missing. In this case, we won't be able to connect anyway. |
|
108 | - if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { |
|
109 | - $result['driverOptions'] = [ |
|
110 | - \PDO::MYSQL_ATTR_FOUND_ROWS => true, |
|
111 | - ]; |
|
112 | - } |
|
113 | - return $result; |
|
114 | - } |
|
94 | + /** |
|
95 | + * @brief Get default connection parameters for a given DBMS. |
|
96 | + * @param string $type DBMS type |
|
97 | + * @throws \InvalidArgumentException If $type is invalid |
|
98 | + * @return array Default connection parameters. |
|
99 | + */ |
|
100 | + public function getDefaultConnectionParams($type) { |
|
101 | + $normalizedType = $this->normalizeType($type); |
|
102 | + if (!isset($this->defaultConnectionParams[$normalizedType])) { |
|
103 | + throw new \InvalidArgumentException("Unsupported type: $type"); |
|
104 | + } |
|
105 | + $result = $this->defaultConnectionParams[$normalizedType]; |
|
106 | + // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL |
|
107 | + // driver is missing. In this case, we won't be able to connect anyway. |
|
108 | + if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { |
|
109 | + $result['driverOptions'] = [ |
|
110 | + \PDO::MYSQL_ATTR_FOUND_ROWS => true, |
|
111 | + ]; |
|
112 | + } |
|
113 | + return $result; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * @brief Get default connection parameters for a given DBMS. |
|
118 | - * @param string $type DBMS type |
|
119 | - * @param array $additionalConnectionParams Additional connection parameters |
|
120 | - * @return \OC\DB\Connection |
|
121 | - */ |
|
122 | - public function getConnection($type, $additionalConnectionParams) { |
|
123 | - $normalizedType = $this->normalizeType($type); |
|
124 | - $eventManager = new EventManager(); |
|
125 | - $eventManager->addEventSubscriber(new SetTransactionIsolationLevel()); |
|
126 | - switch ($normalizedType) { |
|
127 | - case 'mysql': |
|
128 | - $eventManager->addEventSubscriber( |
|
129 | - new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); |
|
130 | - break; |
|
131 | - case 'oci': |
|
132 | - $eventManager->addEventSubscriber(new OracleSessionInit); |
|
133 | - // the driverOptions are unused in dbal and need to be mapped to the parameters |
|
134 | - if (isset($additionalConnectionParams['driverOptions'])) { |
|
135 | - $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); |
|
136 | - } |
|
137 | - $host = $additionalConnectionParams['host']; |
|
138 | - $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null; |
|
139 | - $dbName = $additionalConnectionParams['dbname']; |
|
116 | + /** |
|
117 | + * @brief Get default connection parameters for a given DBMS. |
|
118 | + * @param string $type DBMS type |
|
119 | + * @param array $additionalConnectionParams Additional connection parameters |
|
120 | + * @return \OC\DB\Connection |
|
121 | + */ |
|
122 | + public function getConnection($type, $additionalConnectionParams) { |
|
123 | + $normalizedType = $this->normalizeType($type); |
|
124 | + $eventManager = new EventManager(); |
|
125 | + $eventManager->addEventSubscriber(new SetTransactionIsolationLevel()); |
|
126 | + switch ($normalizedType) { |
|
127 | + case 'mysql': |
|
128 | + $eventManager->addEventSubscriber( |
|
129 | + new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); |
|
130 | + break; |
|
131 | + case 'oci': |
|
132 | + $eventManager->addEventSubscriber(new OracleSessionInit); |
|
133 | + // the driverOptions are unused in dbal and need to be mapped to the parameters |
|
134 | + if (isset($additionalConnectionParams['driverOptions'])) { |
|
135 | + $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']); |
|
136 | + } |
|
137 | + $host = $additionalConnectionParams['host']; |
|
138 | + $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null; |
|
139 | + $dbName = $additionalConnectionParams['dbname']; |
|
140 | 140 | |
141 | - // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string |
|
142 | - if ($host === '') { |
|
143 | - $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name |
|
144 | - } else { |
|
145 | - $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; |
|
146 | - } |
|
147 | - unset($additionalConnectionParams['host']); |
|
148 | - break; |
|
141 | + // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string |
|
142 | + if ($host === '') { |
|
143 | + $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name |
|
144 | + } else { |
|
145 | + $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; |
|
146 | + } |
|
147 | + unset($additionalConnectionParams['host']); |
|
148 | + break; |
|
149 | 149 | |
150 | - case 'sqlite3': |
|
151 | - $journalMode = $additionalConnectionParams['sqlite.journal_mode']; |
|
152 | - $additionalConnectionParams['platform'] = new OCSqlitePlatform(); |
|
153 | - $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode)); |
|
154 | - break; |
|
155 | - } |
|
156 | - /** @var Connection $connection */ |
|
157 | - $connection = DriverManager::getConnection( |
|
158 | - array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), |
|
159 | - new Configuration(), |
|
160 | - $eventManager |
|
161 | - ); |
|
162 | - return $connection; |
|
163 | - } |
|
150 | + case 'sqlite3': |
|
151 | + $journalMode = $additionalConnectionParams['sqlite.journal_mode']; |
|
152 | + $additionalConnectionParams['platform'] = new OCSqlitePlatform(); |
|
153 | + $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode)); |
|
154 | + break; |
|
155 | + } |
|
156 | + /** @var Connection $connection */ |
|
157 | + $connection = DriverManager::getConnection( |
|
158 | + array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams), |
|
159 | + new Configuration(), |
|
160 | + $eventManager |
|
161 | + ); |
|
162 | + return $connection; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @brief Normalize DBMS type |
|
167 | - * @param string $type DBMS type |
|
168 | - * @return string Normalized DBMS type |
|
169 | - */ |
|
170 | - public function normalizeType($type) { |
|
171 | - return $type === 'sqlite' ? 'sqlite3' : $type; |
|
172 | - } |
|
165 | + /** |
|
166 | + * @brief Normalize DBMS type |
|
167 | + * @param string $type DBMS type |
|
168 | + * @return string Normalized DBMS type |
|
169 | + */ |
|
170 | + public function normalizeType($type) { |
|
171 | + return $type === 'sqlite' ? 'sqlite3' : $type; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Checks whether the specified DBMS type is valid. |
|
176 | - * |
|
177 | - * @param string $type |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function isValidType($type) { |
|
181 | - $normalizedType = $this->normalizeType($type); |
|
182 | - return isset($this->defaultConnectionParams[$normalizedType]); |
|
183 | - } |
|
174 | + /** |
|
175 | + * Checks whether the specified DBMS type is valid. |
|
176 | + * |
|
177 | + * @param string $type |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function isValidType($type) { |
|
181 | + $normalizedType = $this->normalizeType($type); |
|
182 | + return isset($this->defaultConnectionParams[$normalizedType]); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Create the connection parameters for the config |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function createConnectionParams() { |
|
191 | - $type = $this->config->getValue('dbtype', 'sqlite'); |
|
185 | + /** |
|
186 | + * Create the connection parameters for the config |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function createConnectionParams() { |
|
191 | + $type = $this->config->getValue('dbtype', 'sqlite'); |
|
192 | 192 | |
193 | - $connectionParams = [ |
|
194 | - 'user' => $this->config->getValue('dbuser', ''), |
|
195 | - 'password' => $this->config->getValue('dbpassword', ''), |
|
196 | - ]; |
|
197 | - $name = $this->config->getValue('dbname', self::DEFAULT_DBNAME); |
|
193 | + $connectionParams = [ |
|
194 | + 'user' => $this->config->getValue('dbuser', ''), |
|
195 | + 'password' => $this->config->getValue('dbpassword', ''), |
|
196 | + ]; |
|
197 | + $name = $this->config->getValue('dbname', self::DEFAULT_DBNAME); |
|
198 | 198 | |
199 | - if ($this->normalizeType($type) === 'sqlite3') { |
|
200 | - $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
201 | - $connectionParams['path'] = $dataDir . '/' . $name . '.db'; |
|
202 | - } else { |
|
203 | - $host = $this->config->getValue('dbhost', ''); |
|
204 | - $connectionParams = array_merge($connectionParams, $this->splitHostFromPortAndSocket($host)); |
|
205 | - $connectionParams['dbname'] = $name; |
|
206 | - } |
|
199 | + if ($this->normalizeType($type) === 'sqlite3') { |
|
200 | + $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
201 | + $connectionParams['path'] = $dataDir . '/' . $name . '.db'; |
|
202 | + } else { |
|
203 | + $host = $this->config->getValue('dbhost', ''); |
|
204 | + $connectionParams = array_merge($connectionParams, $this->splitHostFromPortAndSocket($host)); |
|
205 | + $connectionParams['dbname'] = $name; |
|
206 | + } |
|
207 | 207 | |
208 | - $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', self::DEFAULT_DBTABLEPREFIX); |
|
209 | - $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); |
|
208 | + $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', self::DEFAULT_DBTABLEPREFIX); |
|
209 | + $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); |
|
210 | 210 | |
211 | - //additional driver options, eg. for mysql ssl |
|
212 | - $driverOptions = $this->config->getValue('dbdriveroptions', null); |
|
213 | - if ($driverOptions) { |
|
214 | - $connectionParams['driverOptions'] = $driverOptions; |
|
215 | - } |
|
211 | + //additional driver options, eg. for mysql ssl |
|
212 | + $driverOptions = $this->config->getValue('dbdriveroptions', null); |
|
213 | + if ($driverOptions) { |
|
214 | + $connectionParams['driverOptions'] = $driverOptions; |
|
215 | + } |
|
216 | 216 | |
217 | - // set default table creation options |
|
218 | - $connectionParams['defaultTableOptions'] = [ |
|
219 | - 'collate' => 'utf8_bin', |
|
220 | - 'tablePrefix' => $connectionParams['tablePrefix'] |
|
221 | - ]; |
|
217 | + // set default table creation options |
|
218 | + $connectionParams['defaultTableOptions'] = [ |
|
219 | + 'collate' => 'utf8_bin', |
|
220 | + 'tablePrefix' => $connectionParams['tablePrefix'] |
|
221 | + ]; |
|
222 | 222 | |
223 | - if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
224 | - $connectionParams['defaultTableOptions'] = [ |
|
225 | - 'collate' => 'utf8mb4_bin', |
|
226 | - 'charset' => 'utf8mb4', |
|
227 | - 'row_format' => 'compressed', |
|
228 | - 'tablePrefix' => $connectionParams['tablePrefix'] |
|
229 | - ]; |
|
230 | - } |
|
223 | + if ($this->config->getValue('mysql.utf8mb4', false)) { |
|
224 | + $connectionParams['defaultTableOptions'] = [ |
|
225 | + 'collate' => 'utf8mb4_bin', |
|
226 | + 'charset' => 'utf8mb4', |
|
227 | + 'row_format' => 'compressed', |
|
228 | + 'tablePrefix' => $connectionParams['tablePrefix'] |
|
229 | + ]; |
|
230 | + } |
|
231 | 231 | |
232 | - return $connectionParams; |
|
233 | - } |
|
232 | + return $connectionParams; |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * @param string $host |
|
237 | - * @return array |
|
238 | - */ |
|
239 | - protected function splitHostFromPortAndSocket($host): array { |
|
240 | - $params = [ |
|
241 | - 'host' => $host, |
|
242 | - ]; |
|
235 | + /** |
|
236 | + * @param string $host |
|
237 | + * @return array |
|
238 | + */ |
|
239 | + protected function splitHostFromPortAndSocket($host): array { |
|
240 | + $params = [ |
|
241 | + 'host' => $host, |
|
242 | + ]; |
|
243 | 243 | |
244 | - $matches = []; |
|
245 | - if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { |
|
246 | - // Host variable carries a port or socket. |
|
247 | - $params['host'] = $matches[1]; |
|
248 | - if (is_numeric($matches[2])) { |
|
249 | - $params['port'] = (int) $matches[2]; |
|
250 | - } else { |
|
251 | - $params['unix_socket'] = $matches[2]; |
|
252 | - } |
|
253 | - } |
|
244 | + $matches = []; |
|
245 | + if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { |
|
246 | + // Host variable carries a port or socket. |
|
247 | + $params['host'] = $matches[1]; |
|
248 | + if (is_numeric($matches[2])) { |
|
249 | + $params['port'] = (int) $matches[2]; |
|
250 | + } else { |
|
251 | + $params['unix_socket'] = $matches[2]; |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - return $params; |
|
256 | - } |
|
255 | + return $params; |
|
256 | + } |
|
257 | 257 | } |
@@ -48,410 +48,410 @@ |
||
48 | 48 | use OCP\PreConditionNotMetException; |
49 | 49 | |
50 | 50 | class Connection extends ReconnectWrapper implements IDBConnection { |
51 | - /** |
|
52 | - * @var string $tablePrefix |
|
53 | - */ |
|
54 | - protected $tablePrefix; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var \OC\DB\Adapter $adapter |
|
58 | - */ |
|
59 | - protected $adapter; |
|
60 | - |
|
61 | - protected $lockedTable = null; |
|
62 | - |
|
63 | - public function connect() { |
|
64 | - try { |
|
65 | - return parent::connect(); |
|
66 | - } catch (DBALException $e) { |
|
67 | - // throw a new exception to prevent leaking info from the stacktrace |
|
68 | - throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Returns a QueryBuilder for the connection. |
|
74 | - * |
|
75 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
76 | - */ |
|
77 | - public function getQueryBuilder() { |
|
78 | - return new QueryBuilder( |
|
79 | - $this, |
|
80 | - \OC::$server->getSystemConfig(), |
|
81 | - \OC::$server->getLogger() |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Gets the QueryBuilder for the connection. |
|
87 | - * |
|
88 | - * @return \Doctrine\DBAL\Query\QueryBuilder |
|
89 | - * @deprecated please use $this->getQueryBuilder() instead |
|
90 | - */ |
|
91 | - public function createQueryBuilder() { |
|
92 | - $backtrace = $this->getCallerBacktrace(); |
|
93 | - \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
94 | - return parent::createQueryBuilder(); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Gets the ExpressionBuilder for the connection. |
|
99 | - * |
|
100 | - * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
101 | - * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
102 | - */ |
|
103 | - public function getExpressionBuilder() { |
|
104 | - $backtrace = $this->getCallerBacktrace(); |
|
105 | - \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
106 | - return parent::getExpressionBuilder(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - protected function getCallerBacktrace() { |
|
115 | - $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
116 | - |
|
117 | - // 0 is the method where we use `getCallerBacktrace` |
|
118 | - // 1 is the target method which uses the method we want to log |
|
119 | - if (isset($traces[1])) { |
|
120 | - return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
121 | - } |
|
122 | - |
|
123 | - return ''; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public function getPrefix() { |
|
130 | - return $this->tablePrefix; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initializes a new instance of the Connection class. |
|
135 | - * |
|
136 | - * @param array $params The connection parameters. |
|
137 | - * @param \Doctrine\DBAL\Driver $driver |
|
138 | - * @param \Doctrine\DBAL\Configuration $config |
|
139 | - * @param \Doctrine\Common\EventManager $eventManager |
|
140 | - * @throws \Exception |
|
141 | - */ |
|
142 | - public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
143 | - EventManager $eventManager = null) |
|
144 | - { |
|
145 | - if (!isset($params['adapter'])) { |
|
146 | - throw new \Exception('adapter not set'); |
|
147 | - } |
|
148 | - if (!isset($params['tablePrefix'])) { |
|
149 | - throw new \Exception('tablePrefix not set'); |
|
150 | - } |
|
151 | - parent::__construct($params, $driver, $config, $eventManager); |
|
152 | - $this->adapter = new $params['adapter']($this); |
|
153 | - $this->tablePrefix = $params['tablePrefix']; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Prepares an SQL statement. |
|
158 | - * |
|
159 | - * @param string $statement The SQL statement to prepare. |
|
160 | - * @param int $limit |
|
161 | - * @param int $offset |
|
162 | - * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
163 | - */ |
|
164 | - public function prepare( $statement, $limit=null, $offset=null ) { |
|
165 | - if ($limit === -1) { |
|
166 | - $limit = null; |
|
167 | - } |
|
168 | - if (!is_null($limit)) { |
|
169 | - $platform = $this->getDatabasePlatform(); |
|
170 | - $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
171 | - } |
|
172 | - $statement = $this->replaceTablePrefix($statement); |
|
173 | - $statement = $this->adapter->fixupStatement($statement); |
|
174 | - |
|
175 | - return parent::prepare($statement); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Executes an, optionally parametrized, SQL query. |
|
180 | - * |
|
181 | - * If the query is parametrized, a prepared statement is used. |
|
182 | - * If an SQLLogger is configured, the execution is logged. |
|
183 | - * |
|
184 | - * @param string $query The SQL query to execute. |
|
185 | - * @param array $params The parameters to bind to the query, if any. |
|
186 | - * @param array $types The types the previous parameters are in. |
|
187 | - * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
188 | - * |
|
189 | - * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
190 | - * |
|
191 | - * @throws \Doctrine\DBAL\DBALException |
|
192 | - */ |
|
193 | - public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) |
|
194 | - { |
|
195 | - $query = $this->replaceTablePrefix($query); |
|
196 | - $query = $this->adapter->fixupStatement($query); |
|
197 | - return parent::executeQuery($query, $params, $types, $qcp); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
202 | - * and returns the number of affected rows. |
|
203 | - * |
|
204 | - * This method supports PDO binding types as well as DBAL mapping types. |
|
205 | - * |
|
206 | - * @param string $query The SQL query. |
|
207 | - * @param array $params The query parameters. |
|
208 | - * @param array $types The parameter types. |
|
209 | - * |
|
210 | - * @return integer The number of affected rows. |
|
211 | - * |
|
212 | - * @throws \Doctrine\DBAL\DBALException |
|
213 | - */ |
|
214 | - public function executeUpdate($query, array $params = [], array $types = []) |
|
215 | - { |
|
216 | - $query = $this->replaceTablePrefix($query); |
|
217 | - $query = $this->adapter->fixupStatement($query); |
|
218 | - return parent::executeUpdate($query, $params, $types); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
223 | - * depending on the underlying driver. |
|
224 | - * |
|
225 | - * Note: This method may not return a meaningful or consistent result across different drivers, |
|
226 | - * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
227 | - * columns or sequences. |
|
228 | - * |
|
229 | - * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
230 | - * @return string A string representation of the last inserted ID. |
|
231 | - */ |
|
232 | - public function lastInsertId($seqName = null) { |
|
233 | - if ($seqName) { |
|
234 | - $seqName = $this->replaceTablePrefix($seqName); |
|
235 | - } |
|
236 | - return $this->adapter->lastInsertId($seqName); |
|
237 | - } |
|
238 | - |
|
239 | - // internal use |
|
240 | - public function realLastInsertId($seqName = null) { |
|
241 | - return parent::lastInsertId($seqName); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
246 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
247 | - * catch the exception and return 0. |
|
248 | - * |
|
249 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
250 | - * @param array $input data that should be inserted into the table (column name => value) |
|
251 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
252 | - * If this is null or an empty array, all keys of $input will be compared |
|
253 | - * Please note: text fields (clob) must not be used in the compare array |
|
254 | - * @return int number of inserted rows |
|
255 | - * @throws \Doctrine\DBAL\DBALException |
|
256 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
257 | - */ |
|
258 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
259 | - return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
260 | - } |
|
261 | - |
|
262 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
263 | - return $this->adapter->insertIgnoreConflict($table, $values); |
|
264 | - } |
|
265 | - |
|
266 | - private function getType($value) { |
|
267 | - if (is_bool($value)) { |
|
268 | - return IQueryBuilder::PARAM_BOOL; |
|
269 | - } else if (is_int($value)) { |
|
270 | - return IQueryBuilder::PARAM_INT; |
|
271 | - } else { |
|
272 | - return IQueryBuilder::PARAM_STR; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Insert or update a row value |
|
278 | - * |
|
279 | - * @param string $table |
|
280 | - * @param array $keys (column name => value) |
|
281 | - * @param array $values (column name => value) |
|
282 | - * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
283 | - * @return int number of new rows |
|
284 | - * @throws \Doctrine\DBAL\DBALException |
|
285 | - * @throws PreConditionNotMetException |
|
286 | - * @suppress SqlInjectionChecker |
|
287 | - */ |
|
288 | - public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
289 | - try { |
|
290 | - $insertQb = $this->getQueryBuilder(); |
|
291 | - $insertQb->insert($table) |
|
292 | - ->values( |
|
293 | - array_map(function($value) use ($insertQb) { |
|
294 | - return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
295 | - }, array_merge($keys, $values)) |
|
296 | - ); |
|
297 | - return $insertQb->execute(); |
|
298 | - } catch (ConstraintViolationException $e) { |
|
299 | - // value already exists, try update |
|
300 | - $updateQb = $this->getQueryBuilder(); |
|
301 | - $updateQb->update($table); |
|
302 | - foreach ($values as $name => $value) { |
|
303 | - $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
304 | - } |
|
305 | - $where = $updateQb->expr()->andX(); |
|
306 | - $whereValues = array_merge($keys, $updatePreconditionValues); |
|
307 | - foreach ($whereValues as $name => $value) { |
|
308 | - $where->add($updateQb->expr()->eq( |
|
309 | - $name, |
|
310 | - $updateQb->createNamedParameter($value, $this->getType($value)), |
|
311 | - $this->getType($value) |
|
312 | - )); |
|
313 | - } |
|
314 | - $updateQb->where($where); |
|
315 | - $affected = $updateQb->execute(); |
|
316 | - |
|
317 | - if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
318 | - throw new PreConditionNotMetException(); |
|
319 | - } |
|
320 | - |
|
321 | - return 0; |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Create an exclusive read+write lock on a table |
|
327 | - * |
|
328 | - * @param string $tableName |
|
329 | - * @throws \BadMethodCallException When trying to acquire a second lock |
|
330 | - * @since 9.1.0 |
|
331 | - */ |
|
332 | - public function lockTable($tableName) { |
|
333 | - if ($this->lockedTable !== null) { |
|
334 | - throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
335 | - } |
|
336 | - |
|
337 | - $tableName = $this->tablePrefix . $tableName; |
|
338 | - $this->lockedTable = $tableName; |
|
339 | - $this->adapter->lockTable($tableName); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Release a previous acquired lock again |
|
344 | - * |
|
345 | - * @since 9.1.0 |
|
346 | - */ |
|
347 | - public function unlockTable() { |
|
348 | - $this->adapter->unlockTable(); |
|
349 | - $this->lockedTable = null; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * returns the error code and message as a string for logging |
|
354 | - * works with DoctrineException |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function getError() { |
|
358 | - $msg = $this->errorCode() . ': '; |
|
359 | - $errorInfo = $this->errorInfo(); |
|
360 | - if (is_array($errorInfo)) { |
|
361 | - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
362 | - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
363 | - $msg .= 'Driver Message = '.$errorInfo[2]; |
|
364 | - } |
|
365 | - return $msg; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Drop a table from the database if it exists |
|
370 | - * |
|
371 | - * @param string $table table name without the prefix |
|
372 | - */ |
|
373 | - public function dropTable($table) { |
|
374 | - $table = $this->tablePrefix . trim($table); |
|
375 | - $schema = $this->getSchemaManager(); |
|
376 | - if($schema->tablesExist([$table])) { |
|
377 | - $schema->dropTable($table); |
|
378 | - } |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Check if a table exists |
|
383 | - * |
|
384 | - * @param string $table table name without the prefix |
|
385 | - * @return bool |
|
386 | - */ |
|
387 | - public function tableExists($table){ |
|
388 | - $table = $this->tablePrefix . trim($table); |
|
389 | - $schema = $this->getSchemaManager(); |
|
390 | - return $schema->tablesExist([$table]); |
|
391 | - } |
|
392 | - |
|
393 | - // internal use |
|
394 | - /** |
|
395 | - * @param string $statement |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - protected function replaceTablePrefix($statement) { |
|
399 | - return str_replace( '*PREFIX*', $this->tablePrefix, $statement ); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Check if a transaction is active |
|
404 | - * |
|
405 | - * @return bool |
|
406 | - * @since 8.2.0 |
|
407 | - */ |
|
408 | - public function inTransaction() { |
|
409 | - return $this->getTransactionNestingLevel() > 0; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Escape a parameter to be used in a LIKE query |
|
414 | - * |
|
415 | - * @param string $param |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function escapeLikeParameter($param) { |
|
419 | - return addcslashes($param, '\\_%'); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Check whether or not the current database support 4byte wide unicode |
|
424 | - * |
|
425 | - * @return bool |
|
426 | - * @since 11.0.0 |
|
427 | - */ |
|
428 | - public function supports4ByteText() { |
|
429 | - if (!$this->getDatabasePlatform() instanceof MySqlPlatform) { |
|
430 | - return true; |
|
431 | - } |
|
432 | - return $this->getParams()['charset'] === 'utf8mb4'; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Create the schema of the connected database |
|
438 | - * |
|
439 | - * @return Schema |
|
440 | - */ |
|
441 | - public function createSchema() { |
|
442 | - $schemaManager = new MDB2SchemaManager($this); |
|
443 | - $migrator = $schemaManager->getMigrator(); |
|
444 | - return $migrator->createSchema(); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Migrate the database to the given schema |
|
449 | - * |
|
450 | - * @param Schema $toSchema |
|
451 | - */ |
|
452 | - public function migrateToSchema(Schema $toSchema) { |
|
453 | - $schemaManager = new MDB2SchemaManager($this); |
|
454 | - $migrator = $schemaManager->getMigrator(); |
|
455 | - $migrator->migrate($toSchema); |
|
456 | - } |
|
51 | + /** |
|
52 | + * @var string $tablePrefix |
|
53 | + */ |
|
54 | + protected $tablePrefix; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var \OC\DB\Adapter $adapter |
|
58 | + */ |
|
59 | + protected $adapter; |
|
60 | + |
|
61 | + protected $lockedTable = null; |
|
62 | + |
|
63 | + public function connect() { |
|
64 | + try { |
|
65 | + return parent::connect(); |
|
66 | + } catch (DBALException $e) { |
|
67 | + // throw a new exception to prevent leaking info from the stacktrace |
|
68 | + throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Returns a QueryBuilder for the connection. |
|
74 | + * |
|
75 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
76 | + */ |
|
77 | + public function getQueryBuilder() { |
|
78 | + return new QueryBuilder( |
|
79 | + $this, |
|
80 | + \OC::$server->getSystemConfig(), |
|
81 | + \OC::$server->getLogger() |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Gets the QueryBuilder for the connection. |
|
87 | + * |
|
88 | + * @return \Doctrine\DBAL\Query\QueryBuilder |
|
89 | + * @deprecated please use $this->getQueryBuilder() instead |
|
90 | + */ |
|
91 | + public function createQueryBuilder() { |
|
92 | + $backtrace = $this->getCallerBacktrace(); |
|
93 | + \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
94 | + return parent::createQueryBuilder(); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Gets the ExpressionBuilder for the connection. |
|
99 | + * |
|
100 | + * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
101 | + * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
102 | + */ |
|
103 | + public function getExpressionBuilder() { |
|
104 | + $backtrace = $this->getCallerBacktrace(); |
|
105 | + \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
106 | + return parent::getExpressionBuilder(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + protected function getCallerBacktrace() { |
|
115 | + $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
116 | + |
|
117 | + // 0 is the method where we use `getCallerBacktrace` |
|
118 | + // 1 is the target method which uses the method we want to log |
|
119 | + if (isset($traces[1])) { |
|
120 | + return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
121 | + } |
|
122 | + |
|
123 | + return ''; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public function getPrefix() { |
|
130 | + return $this->tablePrefix; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initializes a new instance of the Connection class. |
|
135 | + * |
|
136 | + * @param array $params The connection parameters. |
|
137 | + * @param \Doctrine\DBAL\Driver $driver |
|
138 | + * @param \Doctrine\DBAL\Configuration $config |
|
139 | + * @param \Doctrine\Common\EventManager $eventManager |
|
140 | + * @throws \Exception |
|
141 | + */ |
|
142 | + public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
143 | + EventManager $eventManager = null) |
|
144 | + { |
|
145 | + if (!isset($params['adapter'])) { |
|
146 | + throw new \Exception('adapter not set'); |
|
147 | + } |
|
148 | + if (!isset($params['tablePrefix'])) { |
|
149 | + throw new \Exception('tablePrefix not set'); |
|
150 | + } |
|
151 | + parent::__construct($params, $driver, $config, $eventManager); |
|
152 | + $this->adapter = new $params['adapter']($this); |
|
153 | + $this->tablePrefix = $params['tablePrefix']; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Prepares an SQL statement. |
|
158 | + * |
|
159 | + * @param string $statement The SQL statement to prepare. |
|
160 | + * @param int $limit |
|
161 | + * @param int $offset |
|
162 | + * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
163 | + */ |
|
164 | + public function prepare( $statement, $limit=null, $offset=null ) { |
|
165 | + if ($limit === -1) { |
|
166 | + $limit = null; |
|
167 | + } |
|
168 | + if (!is_null($limit)) { |
|
169 | + $platform = $this->getDatabasePlatform(); |
|
170 | + $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
171 | + } |
|
172 | + $statement = $this->replaceTablePrefix($statement); |
|
173 | + $statement = $this->adapter->fixupStatement($statement); |
|
174 | + |
|
175 | + return parent::prepare($statement); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Executes an, optionally parametrized, SQL query. |
|
180 | + * |
|
181 | + * If the query is parametrized, a prepared statement is used. |
|
182 | + * If an SQLLogger is configured, the execution is logged. |
|
183 | + * |
|
184 | + * @param string $query The SQL query to execute. |
|
185 | + * @param array $params The parameters to bind to the query, if any. |
|
186 | + * @param array $types The types the previous parameters are in. |
|
187 | + * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
188 | + * |
|
189 | + * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
190 | + * |
|
191 | + * @throws \Doctrine\DBAL\DBALException |
|
192 | + */ |
|
193 | + public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) |
|
194 | + { |
|
195 | + $query = $this->replaceTablePrefix($query); |
|
196 | + $query = $this->adapter->fixupStatement($query); |
|
197 | + return parent::executeQuery($query, $params, $types, $qcp); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
202 | + * and returns the number of affected rows. |
|
203 | + * |
|
204 | + * This method supports PDO binding types as well as DBAL mapping types. |
|
205 | + * |
|
206 | + * @param string $query The SQL query. |
|
207 | + * @param array $params The query parameters. |
|
208 | + * @param array $types The parameter types. |
|
209 | + * |
|
210 | + * @return integer The number of affected rows. |
|
211 | + * |
|
212 | + * @throws \Doctrine\DBAL\DBALException |
|
213 | + */ |
|
214 | + public function executeUpdate($query, array $params = [], array $types = []) |
|
215 | + { |
|
216 | + $query = $this->replaceTablePrefix($query); |
|
217 | + $query = $this->adapter->fixupStatement($query); |
|
218 | + return parent::executeUpdate($query, $params, $types); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
223 | + * depending on the underlying driver. |
|
224 | + * |
|
225 | + * Note: This method may not return a meaningful or consistent result across different drivers, |
|
226 | + * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
227 | + * columns or sequences. |
|
228 | + * |
|
229 | + * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
230 | + * @return string A string representation of the last inserted ID. |
|
231 | + */ |
|
232 | + public function lastInsertId($seqName = null) { |
|
233 | + if ($seqName) { |
|
234 | + $seqName = $this->replaceTablePrefix($seqName); |
|
235 | + } |
|
236 | + return $this->adapter->lastInsertId($seqName); |
|
237 | + } |
|
238 | + |
|
239 | + // internal use |
|
240 | + public function realLastInsertId($seqName = null) { |
|
241 | + return parent::lastInsertId($seqName); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
246 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
247 | + * catch the exception and return 0. |
|
248 | + * |
|
249 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
250 | + * @param array $input data that should be inserted into the table (column name => value) |
|
251 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
252 | + * If this is null or an empty array, all keys of $input will be compared |
|
253 | + * Please note: text fields (clob) must not be used in the compare array |
|
254 | + * @return int number of inserted rows |
|
255 | + * @throws \Doctrine\DBAL\DBALException |
|
256 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
257 | + */ |
|
258 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
259 | + return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
260 | + } |
|
261 | + |
|
262 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
263 | + return $this->adapter->insertIgnoreConflict($table, $values); |
|
264 | + } |
|
265 | + |
|
266 | + private function getType($value) { |
|
267 | + if (is_bool($value)) { |
|
268 | + return IQueryBuilder::PARAM_BOOL; |
|
269 | + } else if (is_int($value)) { |
|
270 | + return IQueryBuilder::PARAM_INT; |
|
271 | + } else { |
|
272 | + return IQueryBuilder::PARAM_STR; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Insert or update a row value |
|
278 | + * |
|
279 | + * @param string $table |
|
280 | + * @param array $keys (column name => value) |
|
281 | + * @param array $values (column name => value) |
|
282 | + * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
283 | + * @return int number of new rows |
|
284 | + * @throws \Doctrine\DBAL\DBALException |
|
285 | + * @throws PreConditionNotMetException |
|
286 | + * @suppress SqlInjectionChecker |
|
287 | + */ |
|
288 | + public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
289 | + try { |
|
290 | + $insertQb = $this->getQueryBuilder(); |
|
291 | + $insertQb->insert($table) |
|
292 | + ->values( |
|
293 | + array_map(function($value) use ($insertQb) { |
|
294 | + return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
295 | + }, array_merge($keys, $values)) |
|
296 | + ); |
|
297 | + return $insertQb->execute(); |
|
298 | + } catch (ConstraintViolationException $e) { |
|
299 | + // value already exists, try update |
|
300 | + $updateQb = $this->getQueryBuilder(); |
|
301 | + $updateQb->update($table); |
|
302 | + foreach ($values as $name => $value) { |
|
303 | + $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
304 | + } |
|
305 | + $where = $updateQb->expr()->andX(); |
|
306 | + $whereValues = array_merge($keys, $updatePreconditionValues); |
|
307 | + foreach ($whereValues as $name => $value) { |
|
308 | + $where->add($updateQb->expr()->eq( |
|
309 | + $name, |
|
310 | + $updateQb->createNamedParameter($value, $this->getType($value)), |
|
311 | + $this->getType($value) |
|
312 | + )); |
|
313 | + } |
|
314 | + $updateQb->where($where); |
|
315 | + $affected = $updateQb->execute(); |
|
316 | + |
|
317 | + if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
318 | + throw new PreConditionNotMetException(); |
|
319 | + } |
|
320 | + |
|
321 | + return 0; |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Create an exclusive read+write lock on a table |
|
327 | + * |
|
328 | + * @param string $tableName |
|
329 | + * @throws \BadMethodCallException When trying to acquire a second lock |
|
330 | + * @since 9.1.0 |
|
331 | + */ |
|
332 | + public function lockTable($tableName) { |
|
333 | + if ($this->lockedTable !== null) { |
|
334 | + throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
335 | + } |
|
336 | + |
|
337 | + $tableName = $this->tablePrefix . $tableName; |
|
338 | + $this->lockedTable = $tableName; |
|
339 | + $this->adapter->lockTable($tableName); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Release a previous acquired lock again |
|
344 | + * |
|
345 | + * @since 9.1.0 |
|
346 | + */ |
|
347 | + public function unlockTable() { |
|
348 | + $this->adapter->unlockTable(); |
|
349 | + $this->lockedTable = null; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * returns the error code and message as a string for logging |
|
354 | + * works with DoctrineException |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function getError() { |
|
358 | + $msg = $this->errorCode() . ': '; |
|
359 | + $errorInfo = $this->errorInfo(); |
|
360 | + if (is_array($errorInfo)) { |
|
361 | + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
362 | + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
363 | + $msg .= 'Driver Message = '.$errorInfo[2]; |
|
364 | + } |
|
365 | + return $msg; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Drop a table from the database if it exists |
|
370 | + * |
|
371 | + * @param string $table table name without the prefix |
|
372 | + */ |
|
373 | + public function dropTable($table) { |
|
374 | + $table = $this->tablePrefix . trim($table); |
|
375 | + $schema = $this->getSchemaManager(); |
|
376 | + if($schema->tablesExist([$table])) { |
|
377 | + $schema->dropTable($table); |
|
378 | + } |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Check if a table exists |
|
383 | + * |
|
384 | + * @param string $table table name without the prefix |
|
385 | + * @return bool |
|
386 | + */ |
|
387 | + public function tableExists($table){ |
|
388 | + $table = $this->tablePrefix . trim($table); |
|
389 | + $schema = $this->getSchemaManager(); |
|
390 | + return $schema->tablesExist([$table]); |
|
391 | + } |
|
392 | + |
|
393 | + // internal use |
|
394 | + /** |
|
395 | + * @param string $statement |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + protected function replaceTablePrefix($statement) { |
|
399 | + return str_replace( '*PREFIX*', $this->tablePrefix, $statement ); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Check if a transaction is active |
|
404 | + * |
|
405 | + * @return bool |
|
406 | + * @since 8.2.0 |
|
407 | + */ |
|
408 | + public function inTransaction() { |
|
409 | + return $this->getTransactionNestingLevel() > 0; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Escape a parameter to be used in a LIKE query |
|
414 | + * |
|
415 | + * @param string $param |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function escapeLikeParameter($param) { |
|
419 | + return addcslashes($param, '\\_%'); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Check whether or not the current database support 4byte wide unicode |
|
424 | + * |
|
425 | + * @return bool |
|
426 | + * @since 11.0.0 |
|
427 | + */ |
|
428 | + public function supports4ByteText() { |
|
429 | + if (!$this->getDatabasePlatform() instanceof MySqlPlatform) { |
|
430 | + return true; |
|
431 | + } |
|
432 | + return $this->getParams()['charset'] === 'utf8mb4'; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Create the schema of the connected database |
|
438 | + * |
|
439 | + * @return Schema |
|
440 | + */ |
|
441 | + public function createSchema() { |
|
442 | + $schemaManager = new MDB2SchemaManager($this); |
|
443 | + $migrator = $schemaManager->getMigrator(); |
|
444 | + return $migrator->createSchema(); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Migrate the database to the given schema |
|
449 | + * |
|
450 | + * @param Schema $toSchema |
|
451 | + */ |
|
452 | + public function migrateToSchema(Schema $toSchema) { |
|
453 | + $schemaManager = new MDB2SchemaManager($this); |
|
454 | + $migrator = $schemaManager->getMigrator(); |
|
455 | + $migrator->migrate($toSchema); |
|
456 | + } |
|
457 | 457 | } |
@@ -27,80 +27,80 @@ |
||
27 | 27 | namespace OC\DB; |
28 | 28 | |
29 | 29 | class OracleConnection extends Connection { |
30 | - /** |
|
31 | - * Quote the keys of the array |
|
32 | - */ |
|
33 | - private function quoteKeys(array $data) { |
|
34 | - $return = []; |
|
35 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
36 | - foreach($data as $key => $value) { |
|
37 | - if ($key[0] !== $c) { |
|
38 | - $return[$this->quoteIdentifier($key)] = $value; |
|
39 | - } else { |
|
40 | - $return[$key] = $value; |
|
41 | - } |
|
42 | - } |
|
43 | - return $return; |
|
44 | - } |
|
30 | + /** |
|
31 | + * Quote the keys of the array |
|
32 | + */ |
|
33 | + private function quoteKeys(array $data) { |
|
34 | + $return = []; |
|
35 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
36 | + foreach($data as $key => $value) { |
|
37 | + if ($key[0] !== $c) { |
|
38 | + $return[$this->quoteIdentifier($key)] = $value; |
|
39 | + } else { |
|
40 | + $return[$key] = $value; |
|
41 | + } |
|
42 | + } |
|
43 | + return $return; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - */ |
|
49 | - public function insert($tableName, array $data, array $types = []) { |
|
50 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
51 | - $tableName = $this->quoteIdentifier($tableName); |
|
52 | - } |
|
53 | - $data = $this->quoteKeys($data); |
|
54 | - return parent::insert($tableName, $data, $types); |
|
55 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + */ |
|
49 | + public function insert($tableName, array $data, array $types = []) { |
|
50 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
51 | + $tableName = $this->quoteIdentifier($tableName); |
|
52 | + } |
|
53 | + $data = $this->quoteKeys($data); |
|
54 | + return parent::insert($tableName, $data, $types); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - */ |
|
60 | - public function update($tableName, array $data, array $identifier, array $types = []) { |
|
61 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
62 | - $tableName = $this->quoteIdentifier($tableName); |
|
63 | - } |
|
64 | - $data = $this->quoteKeys($data); |
|
65 | - $identifier = $this->quoteKeys($identifier); |
|
66 | - return parent::update($tableName, $data, $identifier, $types); |
|
67 | - } |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + */ |
|
60 | + public function update($tableName, array $data, array $identifier, array $types = []) { |
|
61 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
62 | + $tableName = $this->quoteIdentifier($tableName); |
|
63 | + } |
|
64 | + $data = $this->quoteKeys($data); |
|
65 | + $identifier = $this->quoteKeys($identifier); |
|
66 | + return parent::update($tableName, $data, $identifier, $types); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - */ |
|
72 | - public function delete($tableExpression, array $identifier, array $types = []) { |
|
73 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
74 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
75 | - } |
|
76 | - $identifier = $this->quoteKeys($identifier); |
|
77 | - return parent::delete($tableExpression, $identifier); |
|
78 | - } |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + */ |
|
72 | + public function delete($tableExpression, array $identifier, array $types = []) { |
|
73 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
74 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
75 | + } |
|
76 | + $identifier = $this->quoteKeys($identifier); |
|
77 | + return parent::delete($tableExpression, $identifier); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Drop a table from the database if it exists |
|
82 | - * |
|
83 | - * @param string $table table name without the prefix |
|
84 | - */ |
|
85 | - public function dropTable($table) { |
|
86 | - $table = $this->tablePrefix . trim($table); |
|
87 | - $table = $this->quoteIdentifier($table); |
|
88 | - $schema = $this->getSchemaManager(); |
|
89 | - if($schema->tablesExist([$table])) { |
|
90 | - $schema->dropTable($table); |
|
91 | - } |
|
92 | - } |
|
80 | + /** |
|
81 | + * Drop a table from the database if it exists |
|
82 | + * |
|
83 | + * @param string $table table name without the prefix |
|
84 | + */ |
|
85 | + public function dropTable($table) { |
|
86 | + $table = $this->tablePrefix . trim($table); |
|
87 | + $table = $this->quoteIdentifier($table); |
|
88 | + $schema = $this->getSchemaManager(); |
|
89 | + if($schema->tablesExist([$table])) { |
|
90 | + $schema->dropTable($table); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Check if a table exists |
|
96 | - * |
|
97 | - * @param string $table table name without the prefix |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function tableExists($table){ |
|
101 | - $table = $this->tablePrefix . trim($table); |
|
102 | - $table = $this->quoteIdentifier($table); |
|
103 | - $schema = $this->getSchemaManager(); |
|
104 | - return $schema->tablesExist([$table]); |
|
105 | - } |
|
94 | + /** |
|
95 | + * Check if a table exists |
|
96 | + * |
|
97 | + * @param string $table table name without the prefix |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function tableExists($table){ |
|
101 | + $table = $this->tablePrefix . trim($table); |
|
102 | + $table = $this->quoteIdentifier($table); |
|
103 | + $schema = $this->getSchemaManager(); |
|
104 | + return $schema->tablesExist([$table]); |
|
105 | + } |
|
106 | 106 | } |