@@ -44,116 +44,116 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | abstract class Controller { |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * app name |
|
| 49 | - * @var string |
|
| 50 | - * @since 7.0.0 |
|
| 51 | - */ |
|
| 52 | - protected $appName; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * current request |
|
| 56 | - * @var \OCP\IRequest |
|
| 57 | - * @since 6.0.0 |
|
| 58 | - */ |
|
| 59 | - protected $request; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var array |
|
| 63 | - * @since 7.0.0 |
|
| 64 | - */ |
|
| 65 | - private $responders; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * constructor of the controller |
|
| 69 | - * @param string $appName the name of the app |
|
| 70 | - * @param IRequest $request an instance of the request |
|
| 71 | - * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 72 | - */ |
|
| 73 | - public function __construct($appName, |
|
| 74 | - IRequest $request) { |
|
| 75 | - $this->appName = $appName; |
|
| 76 | - $this->request = $request; |
|
| 77 | - |
|
| 78 | - // default responders |
|
| 79 | - $this->responders = array( |
|
| 80 | - 'json' => function ($data) { |
|
| 81 | - if ($data instanceof DataResponse) { |
|
| 82 | - $response = new JSONResponse( |
|
| 83 | - $data->getData(), |
|
| 84 | - $data->getStatus() |
|
| 85 | - ); |
|
| 86 | - $dataHeaders = $data->getHeaders(); |
|
| 87 | - $headers = $response->getHeaders(); |
|
| 88 | - // do not overwrite Content-Type if it already exists |
|
| 89 | - if (isset($dataHeaders['Content-Type'])) { |
|
| 90 | - unset($headers['Content-Type']); |
|
| 91 | - } |
|
| 92 | - $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 93 | - return $response; |
|
| 94 | - } |
|
| 95 | - return new JSONResponse($data); |
|
| 96 | - } |
|
| 97 | - ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Parses an HTTP accept header and returns the supported responder type |
|
| 103 | - * @param string $acceptHeader |
|
| 104 | - * @param string $default |
|
| 105 | - * @return string the responder type |
|
| 106 | - * @since 7.0.0 |
|
| 107 | - * @since 9.1.0 Added default parameter |
|
| 108 | - */ |
|
| 109 | - public function getResponderByHTTPHeader($acceptHeader, $default='json') { |
|
| 110 | - $headers = explode(',', $acceptHeader); |
|
| 111 | - |
|
| 112 | - // return the first matching responder |
|
| 113 | - foreach ($headers as $header) { |
|
| 114 | - $header = strtolower(trim($header)); |
|
| 115 | - |
|
| 116 | - $responder = str_replace('application/', '', $header); |
|
| 117 | - |
|
| 118 | - if (array_key_exists($responder, $this->responders)) { |
|
| 119 | - return $responder; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // no matching header return default |
|
| 124 | - return $default; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Registers a formatter for a type |
|
| 130 | - * @param string $format |
|
| 131 | - * @param \Closure $responder |
|
| 132 | - * @since 7.0.0 |
|
| 133 | - */ |
|
| 134 | - protected function registerResponder($format, \Closure $responder) { |
|
| 135 | - $this->responders[$format] = $responder; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Serializes and formats a response |
|
| 141 | - * @param mixed $response the value that was returned from a controller and |
|
| 142 | - * is not a Response instance |
|
| 143 | - * @param string $format the format for which a formatter has been registered |
|
| 144 | - * @throws \DomainException if format does not match a registered formatter |
|
| 145 | - * @return Response |
|
| 146 | - * @since 7.0.0 |
|
| 147 | - */ |
|
| 148 | - public function buildResponse($response, $format='json') { |
|
| 149 | - if(array_key_exists($format, $this->responders)) { |
|
| 150 | - |
|
| 151 | - $responder = $this->responders[$format]; |
|
| 152 | - |
|
| 153 | - return $responder($response); |
|
| 154 | - |
|
| 155 | - } |
|
| 156 | - throw new \DomainException('No responder registered for format '. |
|
| 157 | - $format . '!'); |
|
| 158 | - } |
|
| 47 | + /** |
|
| 48 | + * app name |
|
| 49 | + * @var string |
|
| 50 | + * @since 7.0.0 |
|
| 51 | + */ |
|
| 52 | + protected $appName; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * current request |
|
| 56 | + * @var \OCP\IRequest |
|
| 57 | + * @since 6.0.0 |
|
| 58 | + */ |
|
| 59 | + protected $request; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var array |
|
| 63 | + * @since 7.0.0 |
|
| 64 | + */ |
|
| 65 | + private $responders; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * constructor of the controller |
|
| 69 | + * @param string $appName the name of the app |
|
| 70 | + * @param IRequest $request an instance of the request |
|
| 71 | + * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 72 | + */ |
|
| 73 | + public function __construct($appName, |
|
| 74 | + IRequest $request) { |
|
| 75 | + $this->appName = $appName; |
|
| 76 | + $this->request = $request; |
|
| 77 | + |
|
| 78 | + // default responders |
|
| 79 | + $this->responders = array( |
|
| 80 | + 'json' => function ($data) { |
|
| 81 | + if ($data instanceof DataResponse) { |
|
| 82 | + $response = new JSONResponse( |
|
| 83 | + $data->getData(), |
|
| 84 | + $data->getStatus() |
|
| 85 | + ); |
|
| 86 | + $dataHeaders = $data->getHeaders(); |
|
| 87 | + $headers = $response->getHeaders(); |
|
| 88 | + // do not overwrite Content-Type if it already exists |
|
| 89 | + if (isset($dataHeaders['Content-Type'])) { |
|
| 90 | + unset($headers['Content-Type']); |
|
| 91 | + } |
|
| 92 | + $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 93 | + return $response; |
|
| 94 | + } |
|
| 95 | + return new JSONResponse($data); |
|
| 96 | + } |
|
| 97 | + ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Parses an HTTP accept header and returns the supported responder type |
|
| 103 | + * @param string $acceptHeader |
|
| 104 | + * @param string $default |
|
| 105 | + * @return string the responder type |
|
| 106 | + * @since 7.0.0 |
|
| 107 | + * @since 9.1.0 Added default parameter |
|
| 108 | + */ |
|
| 109 | + public function getResponderByHTTPHeader($acceptHeader, $default='json') { |
|
| 110 | + $headers = explode(',', $acceptHeader); |
|
| 111 | + |
|
| 112 | + // return the first matching responder |
|
| 113 | + foreach ($headers as $header) { |
|
| 114 | + $header = strtolower(trim($header)); |
|
| 115 | + |
|
| 116 | + $responder = str_replace('application/', '', $header); |
|
| 117 | + |
|
| 118 | + if (array_key_exists($responder, $this->responders)) { |
|
| 119 | + return $responder; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // no matching header return default |
|
| 124 | + return $default; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Registers a formatter for a type |
|
| 130 | + * @param string $format |
|
| 131 | + * @param \Closure $responder |
|
| 132 | + * @since 7.0.0 |
|
| 133 | + */ |
|
| 134 | + protected function registerResponder($format, \Closure $responder) { |
|
| 135 | + $this->responders[$format] = $responder; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Serializes and formats a response |
|
| 141 | + * @param mixed $response the value that was returned from a controller and |
|
| 142 | + * is not a Response instance |
|
| 143 | + * @param string $format the format for which a formatter has been registered |
|
| 144 | + * @throws \DomainException if format does not match a registered formatter |
|
| 145 | + * @return Response |
|
| 146 | + * @since 7.0.0 |
|
| 147 | + */ |
|
| 148 | + public function buildResponse($response, $format='json') { |
|
| 149 | + if(array_key_exists($format, $this->responders)) { |
|
| 150 | + |
|
| 151 | + $responder = $this->responders[$format]; |
|
| 152 | + |
|
| 153 | + return $responder($response); |
|
| 154 | + |
|
| 155 | + } |
|
| 156 | + throw new \DomainException('No responder registered for format '. |
|
| 157 | + $format . '!'); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | // default responders |
| 79 | 79 | $this->responders = array( |
| 80 | - 'json' => function ($data) { |
|
| 80 | + 'json' => function($data) { |
|
| 81 | 81 | if ($data instanceof DataResponse) { |
| 82 | 82 | $response = new JSONResponse( |
| 83 | 83 | $data->getData(), |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @since 7.0.0 |
| 107 | 107 | * @since 9.1.0 Added default parameter |
| 108 | 108 | */ |
| 109 | - public function getResponderByHTTPHeader($acceptHeader, $default='json') { |
|
| 109 | + public function getResponderByHTTPHeader($acceptHeader, $default = 'json') { |
|
| 110 | 110 | $headers = explode(',', $acceptHeader); |
| 111 | 111 | |
| 112 | 112 | // return the first matching responder |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | * @return Response |
| 146 | 146 | * @since 7.0.0 |
| 147 | 147 | */ |
| 148 | - public function buildResponse($response, $format='json') { |
|
| 149 | - if(array_key_exists($format, $this->responders)) { |
|
| 148 | + public function buildResponse($response, $format = 'json') { |
|
| 149 | + if (array_key_exists($format, $this->responders)) { |
|
| 150 | 150 | |
| 151 | 151 | $responder = $this->responders[$format]; |
| 152 | 152 | |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | } |
| 156 | 156 | throw new \DomainException('No responder registered for format '. |
| 157 | - $format . '!'); |
|
| 157 | + $format.'!'); |
|
| 158 | 158 | } |
| 159 | 159 | } |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | // Backends |
| 40 | 40 | $authBackend = new OCA\DAV\Connector\PublicAuth( |
| 41 | - \OC::$server->getRequest(), |
|
| 42 | - \OC::$server->getShareManager(), |
|
| 43 | - \OC::$server->getSession() |
|
| 41 | + \OC::$server->getRequest(), |
|
| 42 | + \OC::$server->getShareManager(), |
|
| 43 | + \OC::$server->getSession() |
|
| 44 | 44 | ); |
| 45 | 45 | $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); |
| 46 | 46 | |
| 47 | 47 | $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( |
| 48 | - \OC::$server->getConfig(), |
|
| 49 | - \OC::$server->getLogger(), |
|
| 50 | - \OC::$server->getDatabaseConnection(), |
|
| 51 | - \OC::$server->getUserSession(), |
|
| 52 | - \OC::$server->getMountManager(), |
|
| 53 | - \OC::$server->getTagManager(), |
|
| 54 | - \OC::$server->getRequest(), |
|
| 55 | - \OC::$server->getPreviewManager() |
|
| 48 | + \OC::$server->getConfig(), |
|
| 49 | + \OC::$server->getLogger(), |
|
| 50 | + \OC::$server->getDatabaseConnection(), |
|
| 51 | + \OC::$server->getUserSession(), |
|
| 52 | + \OC::$server->getMountManager(), |
|
| 53 | + \OC::$server->getTagManager(), |
|
| 54 | + \OC::$server->getRequest(), |
|
| 55 | + \OC::$server->getPreviewManager() |
|
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | 58 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
@@ -61,43 +61,43 @@ discard block |
||
| 61 | 61 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
| 62 | 62 | |
| 63 | 63 | $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
| 64 | - $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
| 65 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 66 | - $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
| 67 | - if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
| 68 | - // this is what is thrown when trying to access a non-existing share |
|
| 69 | - throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $share = $authBackend->getShare(); |
|
| 73 | - $owner = $share->getShareOwner(); |
|
| 74 | - $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
| 75 | - $fileId = $share->getNodeId(); |
|
| 76 | - |
|
| 77 | - // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
| 78 | - $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 79 | - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
| 80 | - return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); |
|
| 81 | - }); |
|
| 82 | - |
|
| 83 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
| 84 | - |
|
| 85 | - OC_Util::tearDownFS(); |
|
| 86 | - OC_Util::setupFS($owner); |
|
| 87 | - $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
| 88 | - $path = $ownerView->getPath($fileId); |
|
| 89 | - $fileInfo = $ownerView->getFileInfo($path); |
|
| 90 | - $linkCheckPlugin->setFileInfo($fileInfo); |
|
| 91 | - |
|
| 92 | - // If not readble (files_drop) enable the filesdrop plugin |
|
| 93 | - if (!$isReadable) { |
|
| 94 | - $filesDropPlugin->enable(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
| 98 | - $filesDropPlugin->setView($view); |
|
| 99 | - |
|
| 100 | - return $view; |
|
| 64 | + $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
|
| 65 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 66 | + $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
|
| 67 | + if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
|
| 68 | + // this is what is thrown when trying to access a non-existing share |
|
| 69 | + throw new \Sabre\DAV\Exception\NotAuthenticated(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $share = $authBackend->getShare(); |
|
| 73 | + $owner = $share->getShareOwner(); |
|
| 74 | + $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
|
| 75 | + $fileId = $share->getNodeId(); |
|
| 76 | + |
|
| 77 | + // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
|
| 78 | + $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 79 | + \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
| 80 | + return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); |
|
| 81 | + }); |
|
| 82 | + |
|
| 83 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
|
| 84 | + |
|
| 85 | + OC_Util::tearDownFS(); |
|
| 86 | + OC_Util::setupFS($owner); |
|
| 87 | + $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
| 88 | + $path = $ownerView->getPath($fileId); |
|
| 89 | + $fileInfo = $ownerView->getFileInfo($path); |
|
| 90 | + $linkCheckPlugin->setFileInfo($fileInfo); |
|
| 91 | + |
|
| 92 | + // If not readble (files_drop) enable the filesdrop plugin |
|
| 93 | + if (!$isReadable) { |
|
| 94 | + $filesDropPlugin->enable(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
|
| 98 | + $filesDropPlugin->setView($view); |
|
| 99 | + |
|
| 100 | + return $view; |
|
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | 103 | $server->addPlugin($linkCheckPlugin); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); |
| 61 | 61 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
| 62 | 62 | |
| 63 | -$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
|
| 63 | +$server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function(\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
|
| 64 | 64 | $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
| 65 | 65 | $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
| 66 | 66 | $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider(); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
| 78 | 78 | $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 79 | - \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
|
| 79 | + \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function($mountPoint, $storage) use ($share) { |
|
| 80 | 80 | return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); |
| 81 | 81 | }); |
| 82 | 82 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | OC_Util::tearDownFS(); |
| 86 | 86 | OC_Util::setupFS($owner); |
| 87 | - $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
|
| 87 | + $ownerView = new \OC\Files\View('/'.$owner.'/files'); |
|
| 88 | 88 | $path = $ownerView->getPath($fileId); |
| 89 | 89 | $fileInfo = $ownerView->getFileInfo($path); |
| 90 | 90 | $linkCheckPlugin->setFileInfo($fileInfo); |
@@ -191,9 +191,9 @@ discard block |
||
| 191 | 191 | $params = []; |
| 192 | 192 | foreach ($this->getParameters() as $placeholder => $value) { |
| 193 | 193 | if (is_array($value)) { |
| 194 | - $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; |
|
| 194 | + $params[] = $placeholder.' => (\''.implode('\', \'', $value).'\')'; |
|
| 195 | 195 | } else { |
| 196 | - $params[] = $placeholder . ' => \'' . $value . '\''; |
|
| 196 | + $params[] = $placeholder.' => \''.$value.'\''; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | if (empty($params)) { |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | public function selectAlias($select, $alias) { |
| 411 | 411 | |
| 412 | 412 | $this->queryBuilder->addSelect( |
| 413 | - $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) |
|
| 413 | + $this->helper->quoteColumnName($select).' AS '.$this->helper->quoteColumnName($alias) |
|
| 414 | 414 | ); |
| 415 | 415 | |
| 416 | 416 | return $this; |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | public function selectDistinct($select) { |
| 433 | 433 | |
| 434 | 434 | $this->queryBuilder->addSelect( |
| 435 | - 'DISTINCT ' . $this->helper->quoteColumnName($select) |
|
| 435 | + 'DISTINCT '.$this->helper->quoteColumnName($select) |
|
| 436 | 436 | ); |
| 437 | 437 | |
| 438 | 438 | return $this; |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | * @return IParameter |
| 1110 | 1110 | */ |
| 1111 | 1111 | public function createParameter($name) { |
| 1112 | - return new Parameter(':' . $name); |
|
| 1112 | + return new Parameter(':'.$name); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | return $table; |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | - return '*PREFIX*' . $table; |
|
| 1179 | + return '*PREFIX*'.$table; |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | /** |
@@ -1191,7 +1191,7 @@ discard block |
||
| 1191 | 1191 | $tableAlias .= '.'; |
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | - return $this->helper->quoteColumnName($tableAlias . $column); |
|
| 1194 | + return $this->helper->quoteColumnName($tableAlias.$column); |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | /** |
@@ -47,1173 +47,1173 @@ |
||
| 47 | 47 | |
| 48 | 48 | class QueryBuilder implements IQueryBuilder { |
| 49 | 49 | |
| 50 | - /** @var \OCP\IDBConnection */ |
|
| 51 | - private $connection; |
|
| 52 | - |
|
| 53 | - /** @var SystemConfig */ |
|
| 54 | - private $systemConfig; |
|
| 55 | - |
|
| 56 | - /** @var ILogger */ |
|
| 57 | - private $logger; |
|
| 58 | - |
|
| 59 | - /** @var \Doctrine\DBAL\Query\QueryBuilder */ |
|
| 60 | - private $queryBuilder; |
|
| 61 | - |
|
| 62 | - /** @var QuoteHelper */ |
|
| 63 | - private $helper; |
|
| 64 | - |
|
| 65 | - /** @var bool */ |
|
| 66 | - private $automaticTablePrefix = true; |
|
| 67 | - |
|
| 68 | - /** @var string */ |
|
| 69 | - protected $lastInsertedTable; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Initializes a new QueryBuilder. |
|
| 73 | - * |
|
| 74 | - * @param IDBConnection $connection |
|
| 75 | - * @param SystemConfig $systemConfig |
|
| 76 | - * @param ILogger $logger |
|
| 77 | - */ |
|
| 78 | - public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) { |
|
| 79 | - $this->connection = $connection; |
|
| 80 | - $this->systemConfig = $systemConfig; |
|
| 81 | - $this->logger = $logger; |
|
| 82 | - $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection); |
|
| 83 | - $this->helper = new QuoteHelper(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Enable/disable automatic prefixing of table names with the oc_ prefix |
|
| 88 | - * |
|
| 89 | - * @param bool $enabled If set to true table names will be prefixed with the |
|
| 90 | - * owncloud database prefix automatically. |
|
| 91 | - * @since 8.2.0 |
|
| 92 | - */ |
|
| 93 | - public function automaticTablePrefix($enabled) { |
|
| 94 | - $this->automaticTablePrefix = (bool) $enabled; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets an ExpressionBuilder used for object-oriented construction of query expressions. |
|
| 99 | - * This producer method is intended for convenient inline usage. Example: |
|
| 100 | - * |
|
| 101 | - * <code> |
|
| 102 | - * $qb = $conn->getQueryBuilder() |
|
| 103 | - * ->select('u') |
|
| 104 | - * ->from('users', 'u') |
|
| 105 | - * ->where($qb->expr()->eq('u.id', 1)); |
|
| 106 | - * </code> |
|
| 107 | - * |
|
| 108 | - * For more complex expression construction, consider storing the expression |
|
| 109 | - * builder object in a local variable. |
|
| 110 | - * |
|
| 111 | - * @return \OCP\DB\QueryBuilder\IExpressionBuilder |
|
| 112 | - */ |
|
| 113 | - public function expr() { |
|
| 114 | - if ($this->connection instanceof OracleConnection) { |
|
| 115 | - return new OCIExpressionBuilder($this->connection, $this); |
|
| 116 | - } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { |
|
| 117 | - return new PgSqlExpressionBuilder($this->connection, $this); |
|
| 118 | - } else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
| 119 | - return new MySqlExpressionBuilder($this->connection, $this); |
|
| 120 | - } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 121 | - return new SqliteExpressionBuilder($this->connection, $this); |
|
| 122 | - } else { |
|
| 123 | - return new ExpressionBuilder($this->connection, $this); |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Gets an FunctionBuilder used for object-oriented construction of query functions. |
|
| 129 | - * This producer method is intended for convenient inline usage. Example: |
|
| 130 | - * |
|
| 131 | - * <code> |
|
| 132 | - * $qb = $conn->getQueryBuilder() |
|
| 133 | - * ->select('u') |
|
| 134 | - * ->from('users', 'u') |
|
| 135 | - * ->where($qb->fun()->md5('u.id')); |
|
| 136 | - * </code> |
|
| 137 | - * |
|
| 138 | - * For more complex function construction, consider storing the function |
|
| 139 | - * builder object in a local variable. |
|
| 140 | - * |
|
| 141 | - * @return \OCP\DB\QueryBuilder\IFunctionBuilder |
|
| 142 | - */ |
|
| 143 | - public function func() { |
|
| 144 | - if ($this->connection instanceof OracleConnection) { |
|
| 145 | - return new OCIFunctionBuilder($this->helper); |
|
| 146 | - } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 147 | - return new SqliteFunctionBuilder($this->helper); |
|
| 148 | - } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { |
|
| 149 | - return new PgSqlFunctionBuilder($this->helper); |
|
| 150 | - } else { |
|
| 151 | - return new FunctionBuilder($this->helper); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Gets the type of the currently built query. |
|
| 157 | - * |
|
| 158 | - * @return integer |
|
| 159 | - */ |
|
| 160 | - public function getType() { |
|
| 161 | - return $this->queryBuilder->getType(); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Gets the associated DBAL Connection for this query builder. |
|
| 166 | - * |
|
| 167 | - * @return \OCP\IDBConnection |
|
| 168 | - */ |
|
| 169 | - public function getConnection() { |
|
| 170 | - return $this->connection; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Gets the state of this query builder instance. |
|
| 175 | - * |
|
| 176 | - * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. |
|
| 177 | - */ |
|
| 178 | - public function getState() { |
|
| 179 | - return $this->queryBuilder->getState(); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Executes this query using the bound parameters and their types. |
|
| 184 | - * |
|
| 185 | - * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} |
|
| 186 | - * for insert, update and delete statements. |
|
| 187 | - * |
|
| 188 | - * @return \Doctrine\DBAL\Driver\Statement|int |
|
| 189 | - */ |
|
| 190 | - public function execute() { |
|
| 191 | - if ($this->systemConfig->getValue('log_query', false)) { |
|
| 192 | - $params = []; |
|
| 193 | - foreach ($this->getParameters() as $placeholder => $value) { |
|
| 194 | - if (is_array($value)) { |
|
| 195 | - $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; |
|
| 196 | - } else { |
|
| 197 | - $params[] = $placeholder . ' => \'' . $value . '\''; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - if (empty($params)) { |
|
| 201 | - $this->logger->debug('DB QueryBuilder: \'{query}\'', [ |
|
| 202 | - 'query' => $this->getSQL(), |
|
| 203 | - 'app' => 'core', |
|
| 204 | - ]); |
|
| 205 | - } else { |
|
| 206 | - $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ |
|
| 207 | - 'query' => $this->getSQL(), |
|
| 208 | - 'params' => implode(', ', $params), |
|
| 209 | - 'app' => 'core', |
|
| 210 | - ]); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - return $this->queryBuilder->execute(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Gets the complete SQL string formed by the current specifications of this QueryBuilder. |
|
| 219 | - * |
|
| 220 | - * <code> |
|
| 221 | - * $qb = $conn->getQueryBuilder() |
|
| 222 | - * ->select('u') |
|
| 223 | - * ->from('User', 'u') |
|
| 224 | - * echo $qb->getSQL(); // SELECT u FROM User u |
|
| 225 | - * </code> |
|
| 226 | - * |
|
| 227 | - * @return string The SQL query string. |
|
| 228 | - */ |
|
| 229 | - public function getSQL() { |
|
| 230 | - return $this->queryBuilder->getSQL(); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Sets a query parameter for the query being constructed. |
|
| 235 | - * |
|
| 236 | - * <code> |
|
| 237 | - * $qb = $conn->getQueryBuilder() |
|
| 238 | - * ->select('u') |
|
| 239 | - * ->from('users', 'u') |
|
| 240 | - * ->where('u.id = :user_id') |
|
| 241 | - * ->setParameter(':user_id', 1); |
|
| 242 | - * </code> |
|
| 243 | - * |
|
| 244 | - * @param string|integer $key The parameter position or name. |
|
| 245 | - * @param mixed $value The parameter value. |
|
| 246 | - * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants. |
|
| 247 | - * |
|
| 248 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 249 | - */ |
|
| 250 | - public function setParameter($key, $value, $type = null) { |
|
| 251 | - $this->queryBuilder->setParameter($key, $value, $type); |
|
| 252 | - |
|
| 253 | - return $this; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Sets a collection of query parameters for the query being constructed. |
|
| 258 | - * |
|
| 259 | - * <code> |
|
| 260 | - * $qb = $conn->getQueryBuilder() |
|
| 261 | - * ->select('u') |
|
| 262 | - * ->from('users', 'u') |
|
| 263 | - * ->where('u.id = :user_id1 OR u.id = :user_id2') |
|
| 264 | - * ->setParameters(array( |
|
| 265 | - * ':user_id1' => 1, |
|
| 266 | - * ':user_id2' => 2 |
|
| 267 | - * )); |
|
| 268 | - * </code> |
|
| 269 | - * |
|
| 270 | - * @param array $params The query parameters to set. |
|
| 271 | - * @param array $types The query parameters types to set. |
|
| 272 | - * |
|
| 273 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 274 | - */ |
|
| 275 | - public function setParameters(array $params, array $types = array()) { |
|
| 276 | - $this->queryBuilder->setParameters($params, $types); |
|
| 277 | - |
|
| 278 | - return $this; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Gets all defined query parameters for the query being constructed indexed by parameter index or name. |
|
| 283 | - * |
|
| 284 | - * @return array The currently defined query parameters indexed by parameter index or name. |
|
| 285 | - */ |
|
| 286 | - public function getParameters() { |
|
| 287 | - return $this->queryBuilder->getParameters(); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Gets a (previously set) query parameter of the query being constructed. |
|
| 292 | - * |
|
| 293 | - * @param mixed $key The key (index or name) of the bound parameter. |
|
| 294 | - * |
|
| 295 | - * @return mixed The value of the bound parameter. |
|
| 296 | - */ |
|
| 297 | - public function getParameter($key) { |
|
| 298 | - return $this->queryBuilder->getParameter($key); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. |
|
| 303 | - * |
|
| 304 | - * @return array The currently defined query parameter types indexed by parameter index or name. |
|
| 305 | - */ |
|
| 306 | - public function getParameterTypes() { |
|
| 307 | - return $this->queryBuilder->getParameterTypes(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Gets a (previously set) query parameter type of the query being constructed. |
|
| 312 | - * |
|
| 313 | - * @param mixed $key The key (index or name) of the bound parameter type. |
|
| 314 | - * |
|
| 315 | - * @return mixed The value of the bound parameter type. |
|
| 316 | - */ |
|
| 317 | - public function getParameterType($key) { |
|
| 318 | - return $this->queryBuilder->getParameterType($key); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Sets the position of the first result to retrieve (the "offset"). |
|
| 323 | - * |
|
| 324 | - * @param integer $firstResult The first result to return. |
|
| 325 | - * |
|
| 326 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 327 | - */ |
|
| 328 | - public function setFirstResult($firstResult) { |
|
| 329 | - $this->queryBuilder->setFirstResult($firstResult); |
|
| 330 | - |
|
| 331 | - return $this; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Gets the position of the first result the query object was set to retrieve (the "offset"). |
|
| 336 | - * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder. |
|
| 337 | - * |
|
| 338 | - * @return integer The position of the first result. |
|
| 339 | - */ |
|
| 340 | - public function getFirstResult() { |
|
| 341 | - return $this->queryBuilder->getFirstResult(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * Sets the maximum number of results to retrieve (the "limit"). |
|
| 346 | - * |
|
| 347 | - * NOTE: Setting max results to "0" will cause mixed behaviour. While most |
|
| 348 | - * of the databases will just return an empty result set, Oracle will return |
|
| 349 | - * all entries. |
|
| 350 | - * |
|
| 351 | - * @param integer $maxResults The maximum number of results to retrieve. |
|
| 352 | - * |
|
| 353 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 354 | - */ |
|
| 355 | - public function setMaxResults($maxResults) { |
|
| 356 | - $this->queryBuilder->setMaxResults($maxResults); |
|
| 357 | - |
|
| 358 | - return $this; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Gets the maximum number of results the query object was set to retrieve (the "limit"). |
|
| 363 | - * Returns NULL if {@link setMaxResults} was not applied to this query builder. |
|
| 364 | - * |
|
| 365 | - * @return integer The maximum number of results. |
|
| 366 | - */ |
|
| 367 | - public function getMaxResults() { |
|
| 368 | - return $this->queryBuilder->getMaxResults(); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Specifies an item that is to be returned in the query result. |
|
| 373 | - * Replaces any previously specified selections, if any. |
|
| 374 | - * |
|
| 375 | - * <code> |
|
| 376 | - * $qb = $conn->getQueryBuilder() |
|
| 377 | - * ->select('u.id', 'p.id') |
|
| 378 | - * ->from('users', 'u') |
|
| 379 | - * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
| 380 | - * </code> |
|
| 381 | - * |
|
| 382 | - * @param mixed ...$selects The selection expressions. |
|
| 383 | - * |
|
| 384 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 385 | - */ |
|
| 386 | - public function select(...$selects) { |
|
| 387 | - if (count($selects) === 1 && is_array($selects[0])) { |
|
| 388 | - $selects = $selects[0]; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $this->queryBuilder->select( |
|
| 392 | - $this->helper->quoteColumnNames($selects) |
|
| 393 | - ); |
|
| 394 | - |
|
| 395 | - return $this; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Specifies an item that is to be returned with a different name in the query result. |
|
| 400 | - * |
|
| 401 | - * <code> |
|
| 402 | - * $qb = $conn->getQueryBuilder() |
|
| 403 | - * ->selectAlias('u.id', 'user_id') |
|
| 404 | - * ->from('users', 'u') |
|
| 405 | - * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
| 406 | - * </code> |
|
| 407 | - * |
|
| 408 | - * @param mixed $select The selection expressions. |
|
| 409 | - * @param string $alias The column alias used in the constructed query. |
|
| 410 | - * |
|
| 411 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 412 | - */ |
|
| 413 | - public function selectAlias($select, $alias) { |
|
| 414 | - |
|
| 415 | - $this->queryBuilder->addSelect( |
|
| 416 | - $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) |
|
| 417 | - ); |
|
| 418 | - |
|
| 419 | - return $this; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Specifies an item that is to be returned uniquely in the query result. |
|
| 424 | - * |
|
| 425 | - * <code> |
|
| 426 | - * $qb = $conn->getQueryBuilder() |
|
| 427 | - * ->selectDistinct('type') |
|
| 428 | - * ->from('users'); |
|
| 429 | - * </code> |
|
| 430 | - * |
|
| 431 | - * @param mixed $select The selection expressions. |
|
| 432 | - * |
|
| 433 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 434 | - */ |
|
| 435 | - public function selectDistinct($select) { |
|
| 436 | - |
|
| 437 | - $this->queryBuilder->addSelect( |
|
| 438 | - 'DISTINCT ' . $this->helper->quoteColumnName($select) |
|
| 439 | - ); |
|
| 440 | - |
|
| 441 | - return $this; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Adds an item that is to be returned in the query result. |
|
| 446 | - * |
|
| 447 | - * <code> |
|
| 448 | - * $qb = $conn->getQueryBuilder() |
|
| 449 | - * ->select('u.id') |
|
| 450 | - * ->addSelect('p.id') |
|
| 451 | - * ->from('users', 'u') |
|
| 452 | - * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id'); |
|
| 453 | - * </code> |
|
| 454 | - * |
|
| 455 | - * @param mixed ...$selects The selection expression. |
|
| 456 | - * |
|
| 457 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 458 | - */ |
|
| 459 | - public function addSelect(...$selects) { |
|
| 460 | - if (count($selects) === 1 && is_array($selects[0])) { |
|
| 461 | - $selects = $selects[0]; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - $this->queryBuilder->addSelect( |
|
| 465 | - $this->helper->quoteColumnNames($selects) |
|
| 466 | - ); |
|
| 467 | - |
|
| 468 | - return $this; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Turns the query being built into a bulk delete query that ranges over |
|
| 473 | - * a certain table. |
|
| 474 | - * |
|
| 475 | - * <code> |
|
| 476 | - * $qb = $conn->getQueryBuilder() |
|
| 477 | - * ->delete('users', 'u') |
|
| 478 | - * ->where('u.id = :user_id'); |
|
| 479 | - * ->setParameter(':user_id', 1); |
|
| 480 | - * </code> |
|
| 481 | - * |
|
| 482 | - * @param string $delete The table whose rows are subject to the deletion. |
|
| 483 | - * @param string $alias The table alias used in the constructed query. |
|
| 484 | - * |
|
| 485 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 486 | - */ |
|
| 487 | - public function delete($delete = null, $alias = null) { |
|
| 488 | - $this->queryBuilder->delete( |
|
| 489 | - $this->getTableName($delete), |
|
| 490 | - $alias |
|
| 491 | - ); |
|
| 492 | - |
|
| 493 | - return $this; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Turns the query being built into a bulk update query that ranges over |
|
| 498 | - * a certain table |
|
| 499 | - * |
|
| 500 | - * <code> |
|
| 501 | - * $qb = $conn->getQueryBuilder() |
|
| 502 | - * ->update('users', 'u') |
|
| 503 | - * ->set('u.password', md5('password')) |
|
| 504 | - * ->where('u.id = ?'); |
|
| 505 | - * </code> |
|
| 506 | - * |
|
| 507 | - * @param string $update The table whose rows are subject to the update. |
|
| 508 | - * @param string $alias The table alias used in the constructed query. |
|
| 509 | - * |
|
| 510 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 511 | - */ |
|
| 512 | - public function update($update = null, $alias = null) { |
|
| 513 | - $this->queryBuilder->update( |
|
| 514 | - $this->getTableName($update), |
|
| 515 | - $alias |
|
| 516 | - ); |
|
| 517 | - |
|
| 518 | - return $this; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Turns the query being built into an insert query that inserts into |
|
| 523 | - * a certain table |
|
| 524 | - * |
|
| 525 | - * <code> |
|
| 526 | - * $qb = $conn->getQueryBuilder() |
|
| 527 | - * ->insert('users') |
|
| 528 | - * ->values( |
|
| 529 | - * array( |
|
| 530 | - * 'name' => '?', |
|
| 531 | - * 'password' => '?' |
|
| 532 | - * ) |
|
| 533 | - * ); |
|
| 534 | - * </code> |
|
| 535 | - * |
|
| 536 | - * @param string $insert The table into which the rows should be inserted. |
|
| 537 | - * |
|
| 538 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 539 | - */ |
|
| 540 | - public function insert($insert = null) { |
|
| 541 | - $this->queryBuilder->insert( |
|
| 542 | - $this->getTableName($insert) |
|
| 543 | - ); |
|
| 544 | - |
|
| 545 | - $this->lastInsertedTable = $insert; |
|
| 546 | - |
|
| 547 | - return $this; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - /** |
|
| 551 | - * Creates and adds a query root corresponding to the table identified by the |
|
| 552 | - * given alias, forming a cartesian product with any existing query roots. |
|
| 553 | - * |
|
| 554 | - * <code> |
|
| 555 | - * $qb = $conn->getQueryBuilder() |
|
| 556 | - * ->select('u.id') |
|
| 557 | - * ->from('users', 'u') |
|
| 558 | - * </code> |
|
| 559 | - * |
|
| 560 | - * @param string $from The table. |
|
| 561 | - * @param string|null $alias The alias of the table. |
|
| 562 | - * |
|
| 563 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 564 | - */ |
|
| 565 | - public function from($from, $alias = null) { |
|
| 566 | - $this->queryBuilder->from( |
|
| 567 | - $this->getTableName($from), |
|
| 568 | - $this->quoteAlias($alias) |
|
| 569 | - ); |
|
| 570 | - |
|
| 571 | - return $this; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Creates and adds a join to the query. |
|
| 576 | - * |
|
| 577 | - * <code> |
|
| 578 | - * $qb = $conn->getQueryBuilder() |
|
| 579 | - * ->select('u.name') |
|
| 580 | - * ->from('users', 'u') |
|
| 581 | - * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 582 | - * </code> |
|
| 583 | - * |
|
| 584 | - * @param string $fromAlias The alias that points to a from clause. |
|
| 585 | - * @param string $join The table name to join. |
|
| 586 | - * @param string $alias The alias of the join table. |
|
| 587 | - * @param string $condition The condition for the join. |
|
| 588 | - * |
|
| 589 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 590 | - */ |
|
| 591 | - public function join($fromAlias, $join, $alias, $condition = null) { |
|
| 592 | - $this->queryBuilder->join( |
|
| 593 | - $this->quoteAlias($fromAlias), |
|
| 594 | - $this->getTableName($join), |
|
| 595 | - $this->quoteAlias($alias), |
|
| 596 | - $condition |
|
| 597 | - ); |
|
| 598 | - |
|
| 599 | - return $this; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Creates and adds a join to the query. |
|
| 604 | - * |
|
| 605 | - * <code> |
|
| 606 | - * $qb = $conn->getQueryBuilder() |
|
| 607 | - * ->select('u.name') |
|
| 608 | - * ->from('users', 'u') |
|
| 609 | - * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 610 | - * </code> |
|
| 611 | - * |
|
| 612 | - * @param string $fromAlias The alias that points to a from clause. |
|
| 613 | - * @param string $join The table name to join. |
|
| 614 | - * @param string $alias The alias of the join table. |
|
| 615 | - * @param string $condition The condition for the join. |
|
| 616 | - * |
|
| 617 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 618 | - */ |
|
| 619 | - public function innerJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 620 | - $this->queryBuilder->innerJoin( |
|
| 621 | - $this->quoteAlias($fromAlias), |
|
| 622 | - $this->getTableName($join), |
|
| 623 | - $this->quoteAlias($alias), |
|
| 624 | - $condition |
|
| 625 | - ); |
|
| 626 | - |
|
| 627 | - return $this; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Creates and adds a left join to the query. |
|
| 632 | - * |
|
| 633 | - * <code> |
|
| 634 | - * $qb = $conn->getQueryBuilder() |
|
| 635 | - * ->select('u.name') |
|
| 636 | - * ->from('users', 'u') |
|
| 637 | - * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 638 | - * </code> |
|
| 639 | - * |
|
| 640 | - * @param string $fromAlias The alias that points to a from clause. |
|
| 641 | - * @param string $join The table name to join. |
|
| 642 | - * @param string $alias The alias of the join table. |
|
| 643 | - * @param string $condition The condition for the join. |
|
| 644 | - * |
|
| 645 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 646 | - */ |
|
| 647 | - public function leftJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 648 | - $this->queryBuilder->leftJoin( |
|
| 649 | - $this->quoteAlias($fromAlias), |
|
| 650 | - $this->getTableName($join), |
|
| 651 | - $this->quoteAlias($alias), |
|
| 652 | - $condition |
|
| 653 | - ); |
|
| 654 | - |
|
| 655 | - return $this; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Creates and adds a right join to the query. |
|
| 660 | - * |
|
| 661 | - * <code> |
|
| 662 | - * $qb = $conn->getQueryBuilder() |
|
| 663 | - * ->select('u.name') |
|
| 664 | - * ->from('users', 'u') |
|
| 665 | - * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 666 | - * </code> |
|
| 667 | - * |
|
| 668 | - * @param string $fromAlias The alias that points to a from clause. |
|
| 669 | - * @param string $join The table name to join. |
|
| 670 | - * @param string $alias The alias of the join table. |
|
| 671 | - * @param string $condition The condition for the join. |
|
| 672 | - * |
|
| 673 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 674 | - */ |
|
| 675 | - public function rightJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 676 | - $this->queryBuilder->rightJoin( |
|
| 677 | - $this->quoteAlias($fromAlias), |
|
| 678 | - $this->getTableName($join), |
|
| 679 | - $this->quoteAlias($alias), |
|
| 680 | - $condition |
|
| 681 | - ); |
|
| 682 | - |
|
| 683 | - return $this; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * Sets a new value for a column in a bulk update query. |
|
| 688 | - * |
|
| 689 | - * <code> |
|
| 690 | - * $qb = $conn->getQueryBuilder() |
|
| 691 | - * ->update('users', 'u') |
|
| 692 | - * ->set('u.password', md5('password')) |
|
| 693 | - * ->where('u.id = ?'); |
|
| 694 | - * </code> |
|
| 695 | - * |
|
| 696 | - * @param string $key The column to set. |
|
| 697 | - * @param string $value The value, expression, placeholder, etc. |
|
| 698 | - * |
|
| 699 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 700 | - */ |
|
| 701 | - public function set($key, $value) { |
|
| 702 | - $this->queryBuilder->set( |
|
| 703 | - $this->helper->quoteColumnName($key), |
|
| 704 | - $this->helper->quoteColumnName($value) |
|
| 705 | - ); |
|
| 706 | - |
|
| 707 | - return $this; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * Specifies one or more restrictions to the query result. |
|
| 712 | - * Replaces any previously specified restrictions, if any. |
|
| 713 | - * |
|
| 714 | - * <code> |
|
| 715 | - * $qb = $conn->getQueryBuilder() |
|
| 716 | - * ->select('u.name') |
|
| 717 | - * ->from('users', 'u') |
|
| 718 | - * ->where('u.id = ?'); |
|
| 719 | - * |
|
| 720 | - * // You can optionally programatically build and/or expressions |
|
| 721 | - * $qb = $conn->getQueryBuilder(); |
|
| 722 | - * |
|
| 723 | - * $or = $qb->expr()->orx(); |
|
| 724 | - * $or->add($qb->expr()->eq('u.id', 1)); |
|
| 725 | - * $or->add($qb->expr()->eq('u.id', 2)); |
|
| 726 | - * |
|
| 727 | - * $qb->update('users', 'u') |
|
| 728 | - * ->set('u.password', md5('password')) |
|
| 729 | - * ->where($or); |
|
| 730 | - * </code> |
|
| 731 | - * |
|
| 732 | - * @param mixed ...$predicates The restriction predicates. |
|
| 733 | - * |
|
| 734 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 735 | - */ |
|
| 736 | - public function where(...$predicates) { |
|
| 737 | - call_user_func_array( |
|
| 738 | - [$this->queryBuilder, 'where'], |
|
| 739 | - $predicates |
|
| 740 | - ); |
|
| 741 | - |
|
| 742 | - return $this; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * Adds one or more restrictions to the query results, forming a logical |
|
| 747 | - * conjunction with any previously specified restrictions. |
|
| 748 | - * |
|
| 749 | - * <code> |
|
| 750 | - * $qb = $conn->getQueryBuilder() |
|
| 751 | - * ->select('u') |
|
| 752 | - * ->from('users', 'u') |
|
| 753 | - * ->where('u.username LIKE ?') |
|
| 754 | - * ->andWhere('u.is_active = 1'); |
|
| 755 | - * </code> |
|
| 756 | - * |
|
| 757 | - * @param mixed ...$where The query restrictions. |
|
| 758 | - * |
|
| 759 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 760 | - * |
|
| 761 | - * @see where() |
|
| 762 | - */ |
|
| 763 | - public function andWhere(...$where) { |
|
| 764 | - call_user_func_array( |
|
| 765 | - [$this->queryBuilder, 'andWhere'], |
|
| 766 | - $where |
|
| 767 | - ); |
|
| 768 | - |
|
| 769 | - return $this; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Adds one or more restrictions to the query results, forming a logical |
|
| 774 | - * disjunction with any previously specified restrictions. |
|
| 775 | - * |
|
| 776 | - * <code> |
|
| 777 | - * $qb = $conn->getQueryBuilder() |
|
| 778 | - * ->select('u.name') |
|
| 779 | - * ->from('users', 'u') |
|
| 780 | - * ->where('u.id = 1') |
|
| 781 | - * ->orWhere('u.id = 2'); |
|
| 782 | - * </code> |
|
| 783 | - * |
|
| 784 | - * @param mixed ...$where The WHERE statement. |
|
| 785 | - * |
|
| 786 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 787 | - * |
|
| 788 | - * @see where() |
|
| 789 | - */ |
|
| 790 | - public function orWhere(...$where) { |
|
| 791 | - call_user_func_array( |
|
| 792 | - [$this->queryBuilder, 'orWhere'], |
|
| 793 | - $where |
|
| 794 | - ); |
|
| 795 | - |
|
| 796 | - return $this; |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Specifies a grouping over the results of the query. |
|
| 801 | - * Replaces any previously specified groupings, if any. |
|
| 802 | - * |
|
| 803 | - * <code> |
|
| 804 | - * $qb = $conn->getQueryBuilder() |
|
| 805 | - * ->select('u.name') |
|
| 806 | - * ->from('users', 'u') |
|
| 807 | - * ->groupBy('u.id'); |
|
| 808 | - * </code> |
|
| 809 | - * |
|
| 810 | - * @param mixed ...$groupBys The grouping expression. |
|
| 811 | - * |
|
| 812 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 813 | - */ |
|
| 814 | - public function groupBy(...$groupBys) { |
|
| 815 | - if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
| 816 | - $groupBys = $groupBys[0]; |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - call_user_func_array( |
|
| 820 | - [$this->queryBuilder, 'groupBy'], |
|
| 821 | - $this->helper->quoteColumnNames($groupBys) |
|
| 822 | - ); |
|
| 823 | - |
|
| 824 | - return $this; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Adds a grouping expression to the query. |
|
| 829 | - * |
|
| 830 | - * <code> |
|
| 831 | - * $qb = $conn->getQueryBuilder() |
|
| 832 | - * ->select('u.name') |
|
| 833 | - * ->from('users', 'u') |
|
| 834 | - * ->groupBy('u.lastLogin'); |
|
| 835 | - * ->addGroupBy('u.createdAt') |
|
| 836 | - * </code> |
|
| 837 | - * |
|
| 838 | - * @param mixed ...$groupBy The grouping expression. |
|
| 839 | - * |
|
| 840 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 841 | - */ |
|
| 842 | - public function addGroupBy(...$groupBys) { |
|
| 843 | - if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
| 844 | - $$groupBys = $groupBys[0]; |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - call_user_func_array( |
|
| 848 | - [$this->queryBuilder, 'addGroupBy'], |
|
| 849 | - $this->helper->quoteColumnNames($groupBys) |
|
| 850 | - ); |
|
| 851 | - |
|
| 852 | - return $this; |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * Sets a value for a column in an insert query. |
|
| 857 | - * |
|
| 858 | - * <code> |
|
| 859 | - * $qb = $conn->getQueryBuilder() |
|
| 860 | - * ->insert('users') |
|
| 861 | - * ->values( |
|
| 862 | - * array( |
|
| 863 | - * 'name' => '?' |
|
| 864 | - * ) |
|
| 865 | - * ) |
|
| 866 | - * ->setValue('password', '?'); |
|
| 867 | - * </code> |
|
| 868 | - * |
|
| 869 | - * @param string $column The column into which the value should be inserted. |
|
| 870 | - * @param string $value The value that should be inserted into the column. |
|
| 871 | - * |
|
| 872 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 873 | - */ |
|
| 874 | - public function setValue($column, $value) { |
|
| 875 | - $this->queryBuilder->setValue( |
|
| 876 | - $this->helper->quoteColumnName($column), |
|
| 877 | - $value |
|
| 878 | - ); |
|
| 879 | - |
|
| 880 | - return $this; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Specifies values for an insert query indexed by column names. |
|
| 885 | - * Replaces any previous values, if any. |
|
| 886 | - * |
|
| 887 | - * <code> |
|
| 888 | - * $qb = $conn->getQueryBuilder() |
|
| 889 | - * ->insert('users') |
|
| 890 | - * ->values( |
|
| 891 | - * array( |
|
| 892 | - * 'name' => '?', |
|
| 893 | - * 'password' => '?' |
|
| 894 | - * ) |
|
| 895 | - * ); |
|
| 896 | - * </code> |
|
| 897 | - * |
|
| 898 | - * @param array $values The values to specify for the insert query indexed by column names. |
|
| 899 | - * |
|
| 900 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 901 | - */ |
|
| 902 | - public function values(array $values) { |
|
| 903 | - $quotedValues = []; |
|
| 904 | - foreach ($values as $key => $value) { |
|
| 905 | - $quotedValues[$this->helper->quoteColumnName($key)] = $value; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - $this->queryBuilder->values($quotedValues); |
|
| 909 | - |
|
| 910 | - return $this; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * Specifies a restriction over the groups of the query. |
|
| 915 | - * Replaces any previous having restrictions, if any. |
|
| 916 | - * |
|
| 917 | - * @param mixed ...$having The restriction over the groups. |
|
| 918 | - * |
|
| 919 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 920 | - */ |
|
| 921 | - public function having(...$having) { |
|
| 922 | - call_user_func_array( |
|
| 923 | - [$this->queryBuilder, 'having'], |
|
| 924 | - $having |
|
| 925 | - ); |
|
| 926 | - |
|
| 927 | - return $this; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Adds a restriction over the groups of the query, forming a logical |
|
| 932 | - * conjunction with any existing having restrictions. |
|
| 933 | - * |
|
| 934 | - * @param mixed ...$having The restriction to append. |
|
| 935 | - * |
|
| 936 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 937 | - */ |
|
| 938 | - public function andHaving(...$having) { |
|
| 939 | - call_user_func_array( |
|
| 940 | - [$this->queryBuilder, 'andHaving'], |
|
| 941 | - $having |
|
| 942 | - ); |
|
| 943 | - |
|
| 944 | - return $this; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * Adds a restriction over the groups of the query, forming a logical |
|
| 949 | - * disjunction with any existing having restrictions. |
|
| 950 | - * |
|
| 951 | - * @param mixed ...$having The restriction to add. |
|
| 952 | - * |
|
| 953 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 954 | - */ |
|
| 955 | - public function orHaving(...$having) { |
|
| 956 | - call_user_func_array( |
|
| 957 | - [$this->queryBuilder, 'orHaving'], |
|
| 958 | - $having |
|
| 959 | - ); |
|
| 960 | - |
|
| 961 | - return $this; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * Specifies an ordering for the query results. |
|
| 966 | - * Replaces any previously specified orderings, if any. |
|
| 967 | - * |
|
| 968 | - * @param string $sort The ordering expression. |
|
| 969 | - * @param string $order The ordering direction. |
|
| 970 | - * |
|
| 971 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 972 | - */ |
|
| 973 | - public function orderBy($sort, $order = null) { |
|
| 974 | - $this->queryBuilder->orderBy( |
|
| 975 | - $this->helper->quoteColumnName($sort), |
|
| 976 | - $order |
|
| 977 | - ); |
|
| 978 | - |
|
| 979 | - return $this; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * Adds an ordering to the query results. |
|
| 984 | - * |
|
| 985 | - * @param string $sort The ordering expression. |
|
| 986 | - * @param string $order The ordering direction. |
|
| 987 | - * |
|
| 988 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 989 | - */ |
|
| 990 | - public function addOrderBy($sort, $order = null) { |
|
| 991 | - $this->queryBuilder->addOrderBy( |
|
| 992 | - $this->helper->quoteColumnName($sort), |
|
| 993 | - $order |
|
| 994 | - ); |
|
| 995 | - |
|
| 996 | - return $this; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * Gets a query part by its name. |
|
| 1001 | - * |
|
| 1002 | - * @param string $queryPartName |
|
| 1003 | - * |
|
| 1004 | - * @return mixed |
|
| 1005 | - */ |
|
| 1006 | - public function getQueryPart($queryPartName) { |
|
| 1007 | - return $this->queryBuilder->getQueryPart($queryPartName); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - /** |
|
| 1011 | - * Gets all query parts. |
|
| 1012 | - * |
|
| 1013 | - * @return array |
|
| 1014 | - */ |
|
| 1015 | - public function getQueryParts() { |
|
| 1016 | - return $this->queryBuilder->getQueryParts(); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * Resets SQL parts. |
|
| 1021 | - * |
|
| 1022 | - * @param array|null $queryPartNames |
|
| 1023 | - * |
|
| 1024 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 1025 | - */ |
|
| 1026 | - public function resetQueryParts($queryPartNames = null) { |
|
| 1027 | - $this->queryBuilder->resetQueryParts($queryPartNames); |
|
| 1028 | - |
|
| 1029 | - return $this; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Resets a single SQL part. |
|
| 1034 | - * |
|
| 1035 | - * @param string $queryPartName |
|
| 1036 | - * |
|
| 1037 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 1038 | - */ |
|
| 1039 | - public function resetQueryPart($queryPartName) { |
|
| 1040 | - $this->queryBuilder->resetQueryPart($queryPartName); |
|
| 1041 | - |
|
| 1042 | - return $this; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * Creates a new named parameter and bind the value $value to it. |
|
| 1047 | - * |
|
| 1048 | - * This method provides a shortcut for PDOStatement::bindValue |
|
| 1049 | - * when using prepared statements. |
|
| 1050 | - * |
|
| 1051 | - * The parameter $value specifies the value that you want to bind. If |
|
| 1052 | - * $placeholder is not provided bindValue() will automatically create a |
|
| 1053 | - * placeholder for you. An automatic placeholder will be of the name |
|
| 1054 | - * ':dcValue1', ':dcValue2' etc. |
|
| 1055 | - * |
|
| 1056 | - * For more information see {@link http://php.net/pdostatement-bindparam} |
|
| 1057 | - * |
|
| 1058 | - * Example: |
|
| 1059 | - * <code> |
|
| 1060 | - * $value = 2; |
|
| 1061 | - * $q->eq( 'id', $q->bindValue( $value ) ); |
|
| 1062 | - * $stmt = $q->executeQuery(); // executed with 'id = 2' |
|
| 1063 | - * </code> |
|
| 1064 | - * |
|
| 1065 | - * @license New BSD License |
|
| 1066 | - * @link http://www.zetacomponents.org |
|
| 1067 | - * |
|
| 1068 | - * @param mixed $value |
|
| 1069 | - * @param mixed $type |
|
| 1070 | - * @param string $placeHolder The name to bind with. The string must start with a colon ':'. |
|
| 1071 | - * |
|
| 1072 | - * @return IParameter the placeholder name used. |
|
| 1073 | - */ |
|
| 1074 | - public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { |
|
| 1075 | - return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder)); |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * Creates a new positional parameter and bind the given value to it. |
|
| 1080 | - * |
|
| 1081 | - * Attention: If you are using positional parameters with the query builder you have |
|
| 1082 | - * to be very careful to bind all parameters in the order they appear in the SQL |
|
| 1083 | - * statement , otherwise they get bound in the wrong order which can lead to serious |
|
| 1084 | - * bugs in your code. |
|
| 1085 | - * |
|
| 1086 | - * Example: |
|
| 1087 | - * <code> |
|
| 1088 | - * $qb = $conn->getQueryBuilder(); |
|
| 1089 | - * $qb->select('u.*') |
|
| 1090 | - * ->from('users', 'u') |
|
| 1091 | - * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR)) |
|
| 1092 | - * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR)) |
|
| 1093 | - * </code> |
|
| 1094 | - * |
|
| 1095 | - * @param mixed $value |
|
| 1096 | - * @param integer $type |
|
| 1097 | - * |
|
| 1098 | - * @return IParameter |
|
| 1099 | - */ |
|
| 1100 | - public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { |
|
| 1101 | - return new Parameter($this->queryBuilder->createPositionalParameter($value, $type)); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - /** |
|
| 1105 | - * Creates a new parameter |
|
| 1106 | - * |
|
| 1107 | - * Example: |
|
| 1108 | - * <code> |
|
| 1109 | - * $qb = $conn->getQueryBuilder(); |
|
| 1110 | - * $qb->select('u.*') |
|
| 1111 | - * ->from('users', 'u') |
|
| 1112 | - * ->where('u.username = ' . $qb->createParameter('name')) |
|
| 1113 | - * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR)) |
|
| 1114 | - * </code> |
|
| 1115 | - * |
|
| 1116 | - * @param string $name |
|
| 1117 | - * |
|
| 1118 | - * @return IParameter |
|
| 1119 | - */ |
|
| 1120 | - public function createParameter($name) { |
|
| 1121 | - return new Parameter(':' . $name); |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - /** |
|
| 1125 | - * Creates a new function |
|
| 1126 | - * |
|
| 1127 | - * Attention: Column names inside the call have to be quoted before hand |
|
| 1128 | - * |
|
| 1129 | - * Example: |
|
| 1130 | - * <code> |
|
| 1131 | - * $qb = $conn->getQueryBuilder(); |
|
| 1132 | - * $qb->select($qb->createFunction('COUNT(*)')) |
|
| 1133 | - * ->from('users', 'u') |
|
| 1134 | - * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u |
|
| 1135 | - * </code> |
|
| 1136 | - * <code> |
|
| 1137 | - * $qb = $conn->getQueryBuilder(); |
|
| 1138 | - * $qb->select($qb->createFunction('COUNT(`column`)')) |
|
| 1139 | - * ->from('users', 'u') |
|
| 1140 | - * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u |
|
| 1141 | - * </code> |
|
| 1142 | - * |
|
| 1143 | - * @param string $call |
|
| 1144 | - * |
|
| 1145 | - * @return IQueryFunction |
|
| 1146 | - */ |
|
| 1147 | - public function createFunction($call) { |
|
| 1148 | - return new QueryFunction($call); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - /** |
|
| 1152 | - * Used to get the id of the last inserted element |
|
| 1153 | - * @return int |
|
| 1154 | - * @throws \BadMethodCallException When being called before an insert query has been run. |
|
| 1155 | - */ |
|
| 1156 | - public function getLastInsertId() { |
|
| 1157 | - if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) { |
|
| 1158 | - // lastInsertId() needs the prefix but no quotes |
|
| 1159 | - $table = $this->prefixTableName($this->lastInsertedTable); |
|
| 1160 | - return (int) $this->connection->lastInsertId($table); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.'); |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - /** |
|
| 1167 | - * Returns the table name quoted and with database prefix as needed by the implementation |
|
| 1168 | - * |
|
| 1169 | - * @param string $table |
|
| 1170 | - * @return string |
|
| 1171 | - */ |
|
| 1172 | - public function getTableName($table) { |
|
| 1173 | - $table = $this->prefixTableName($table); |
|
| 1174 | - return $this->helper->quoteColumnName($table); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - /** |
|
| 1178 | - * Returns the table name with database prefix as needed by the implementation |
|
| 1179 | - * |
|
| 1180 | - * @param string $table |
|
| 1181 | - * @return string |
|
| 1182 | - */ |
|
| 1183 | - protected function prefixTableName($table) { |
|
| 1184 | - if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) { |
|
| 1185 | - return $table; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - return '*PREFIX*' . $table; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - /** |
|
| 1192 | - * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
| 1193 | - * |
|
| 1194 | - * @param string $column |
|
| 1195 | - * @param string $tableAlias |
|
| 1196 | - * @return string |
|
| 1197 | - */ |
|
| 1198 | - public function getColumnName($column, $tableAlias = '') { |
|
| 1199 | - if ($tableAlias !== '') { |
|
| 1200 | - $tableAlias .= '.'; |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - return $this->helper->quoteColumnName($tableAlias . $column); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
| 1208 | - * |
|
| 1209 | - * @param string $alias |
|
| 1210 | - * @return string |
|
| 1211 | - */ |
|
| 1212 | - public function quoteAlias($alias) { |
|
| 1213 | - if ($alias === '' || $alias === null) { |
|
| 1214 | - return $alias; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return $this->helper->quoteColumnName($alias); |
|
| 1218 | - } |
|
| 50 | + /** @var \OCP\IDBConnection */ |
|
| 51 | + private $connection; |
|
| 52 | + |
|
| 53 | + /** @var SystemConfig */ |
|
| 54 | + private $systemConfig; |
|
| 55 | + |
|
| 56 | + /** @var ILogger */ |
|
| 57 | + private $logger; |
|
| 58 | + |
|
| 59 | + /** @var \Doctrine\DBAL\Query\QueryBuilder */ |
|
| 60 | + private $queryBuilder; |
|
| 61 | + |
|
| 62 | + /** @var QuoteHelper */ |
|
| 63 | + private $helper; |
|
| 64 | + |
|
| 65 | + /** @var bool */ |
|
| 66 | + private $automaticTablePrefix = true; |
|
| 67 | + |
|
| 68 | + /** @var string */ |
|
| 69 | + protected $lastInsertedTable; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Initializes a new QueryBuilder. |
|
| 73 | + * |
|
| 74 | + * @param IDBConnection $connection |
|
| 75 | + * @param SystemConfig $systemConfig |
|
| 76 | + * @param ILogger $logger |
|
| 77 | + */ |
|
| 78 | + public function __construct(IDBConnection $connection, SystemConfig $systemConfig, ILogger $logger) { |
|
| 79 | + $this->connection = $connection; |
|
| 80 | + $this->systemConfig = $systemConfig; |
|
| 81 | + $this->logger = $logger; |
|
| 82 | + $this->queryBuilder = new \Doctrine\DBAL\Query\QueryBuilder($this->connection); |
|
| 83 | + $this->helper = new QuoteHelper(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Enable/disable automatic prefixing of table names with the oc_ prefix |
|
| 88 | + * |
|
| 89 | + * @param bool $enabled If set to true table names will be prefixed with the |
|
| 90 | + * owncloud database prefix automatically. |
|
| 91 | + * @since 8.2.0 |
|
| 92 | + */ |
|
| 93 | + public function automaticTablePrefix($enabled) { |
|
| 94 | + $this->automaticTablePrefix = (bool) $enabled; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets an ExpressionBuilder used for object-oriented construction of query expressions. |
|
| 99 | + * This producer method is intended for convenient inline usage. Example: |
|
| 100 | + * |
|
| 101 | + * <code> |
|
| 102 | + * $qb = $conn->getQueryBuilder() |
|
| 103 | + * ->select('u') |
|
| 104 | + * ->from('users', 'u') |
|
| 105 | + * ->where($qb->expr()->eq('u.id', 1)); |
|
| 106 | + * </code> |
|
| 107 | + * |
|
| 108 | + * For more complex expression construction, consider storing the expression |
|
| 109 | + * builder object in a local variable. |
|
| 110 | + * |
|
| 111 | + * @return \OCP\DB\QueryBuilder\IExpressionBuilder |
|
| 112 | + */ |
|
| 113 | + public function expr() { |
|
| 114 | + if ($this->connection instanceof OracleConnection) { |
|
| 115 | + return new OCIExpressionBuilder($this->connection, $this); |
|
| 116 | + } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { |
|
| 117 | + return new PgSqlExpressionBuilder($this->connection, $this); |
|
| 118 | + } else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
| 119 | + return new MySqlExpressionBuilder($this->connection, $this); |
|
| 120 | + } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 121 | + return new SqliteExpressionBuilder($this->connection, $this); |
|
| 122 | + } else { |
|
| 123 | + return new ExpressionBuilder($this->connection, $this); |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Gets an FunctionBuilder used for object-oriented construction of query functions. |
|
| 129 | + * This producer method is intended for convenient inline usage. Example: |
|
| 130 | + * |
|
| 131 | + * <code> |
|
| 132 | + * $qb = $conn->getQueryBuilder() |
|
| 133 | + * ->select('u') |
|
| 134 | + * ->from('users', 'u') |
|
| 135 | + * ->where($qb->fun()->md5('u.id')); |
|
| 136 | + * </code> |
|
| 137 | + * |
|
| 138 | + * For more complex function construction, consider storing the function |
|
| 139 | + * builder object in a local variable. |
|
| 140 | + * |
|
| 141 | + * @return \OCP\DB\QueryBuilder\IFunctionBuilder |
|
| 142 | + */ |
|
| 143 | + public function func() { |
|
| 144 | + if ($this->connection instanceof OracleConnection) { |
|
| 145 | + return new OCIFunctionBuilder($this->helper); |
|
| 146 | + } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { |
|
| 147 | + return new SqliteFunctionBuilder($this->helper); |
|
| 148 | + } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { |
|
| 149 | + return new PgSqlFunctionBuilder($this->helper); |
|
| 150 | + } else { |
|
| 151 | + return new FunctionBuilder($this->helper); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Gets the type of the currently built query. |
|
| 157 | + * |
|
| 158 | + * @return integer |
|
| 159 | + */ |
|
| 160 | + public function getType() { |
|
| 161 | + return $this->queryBuilder->getType(); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Gets the associated DBAL Connection for this query builder. |
|
| 166 | + * |
|
| 167 | + * @return \OCP\IDBConnection |
|
| 168 | + */ |
|
| 169 | + public function getConnection() { |
|
| 170 | + return $this->connection; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Gets the state of this query builder instance. |
|
| 175 | + * |
|
| 176 | + * @return integer Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. |
|
| 177 | + */ |
|
| 178 | + public function getState() { |
|
| 179 | + return $this->queryBuilder->getState(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Executes this query using the bound parameters and their types. |
|
| 184 | + * |
|
| 185 | + * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} |
|
| 186 | + * for insert, update and delete statements. |
|
| 187 | + * |
|
| 188 | + * @return \Doctrine\DBAL\Driver\Statement|int |
|
| 189 | + */ |
|
| 190 | + public function execute() { |
|
| 191 | + if ($this->systemConfig->getValue('log_query', false)) { |
|
| 192 | + $params = []; |
|
| 193 | + foreach ($this->getParameters() as $placeholder => $value) { |
|
| 194 | + if (is_array($value)) { |
|
| 195 | + $params[] = $placeholder . ' => (\'' . implode('\', \'', $value) . '\')'; |
|
| 196 | + } else { |
|
| 197 | + $params[] = $placeholder . ' => \'' . $value . '\''; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + if (empty($params)) { |
|
| 201 | + $this->logger->debug('DB QueryBuilder: \'{query}\'', [ |
|
| 202 | + 'query' => $this->getSQL(), |
|
| 203 | + 'app' => 'core', |
|
| 204 | + ]); |
|
| 205 | + } else { |
|
| 206 | + $this->logger->debug('DB QueryBuilder: \'{query}\' with parameters: {params}', [ |
|
| 207 | + 'query' => $this->getSQL(), |
|
| 208 | + 'params' => implode(', ', $params), |
|
| 209 | + 'app' => 'core', |
|
| 210 | + ]); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + return $this->queryBuilder->execute(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Gets the complete SQL string formed by the current specifications of this QueryBuilder. |
|
| 219 | + * |
|
| 220 | + * <code> |
|
| 221 | + * $qb = $conn->getQueryBuilder() |
|
| 222 | + * ->select('u') |
|
| 223 | + * ->from('User', 'u') |
|
| 224 | + * echo $qb->getSQL(); // SELECT u FROM User u |
|
| 225 | + * </code> |
|
| 226 | + * |
|
| 227 | + * @return string The SQL query string. |
|
| 228 | + */ |
|
| 229 | + public function getSQL() { |
|
| 230 | + return $this->queryBuilder->getSQL(); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Sets a query parameter for the query being constructed. |
|
| 235 | + * |
|
| 236 | + * <code> |
|
| 237 | + * $qb = $conn->getQueryBuilder() |
|
| 238 | + * ->select('u') |
|
| 239 | + * ->from('users', 'u') |
|
| 240 | + * ->where('u.id = :user_id') |
|
| 241 | + * ->setParameter(':user_id', 1); |
|
| 242 | + * </code> |
|
| 243 | + * |
|
| 244 | + * @param string|integer $key The parameter position or name. |
|
| 245 | + * @param mixed $value The parameter value. |
|
| 246 | + * @param string|null|int $type One of the IQueryBuilder::PARAM_* constants. |
|
| 247 | + * |
|
| 248 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 249 | + */ |
|
| 250 | + public function setParameter($key, $value, $type = null) { |
|
| 251 | + $this->queryBuilder->setParameter($key, $value, $type); |
|
| 252 | + |
|
| 253 | + return $this; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Sets a collection of query parameters for the query being constructed. |
|
| 258 | + * |
|
| 259 | + * <code> |
|
| 260 | + * $qb = $conn->getQueryBuilder() |
|
| 261 | + * ->select('u') |
|
| 262 | + * ->from('users', 'u') |
|
| 263 | + * ->where('u.id = :user_id1 OR u.id = :user_id2') |
|
| 264 | + * ->setParameters(array( |
|
| 265 | + * ':user_id1' => 1, |
|
| 266 | + * ':user_id2' => 2 |
|
| 267 | + * )); |
|
| 268 | + * </code> |
|
| 269 | + * |
|
| 270 | + * @param array $params The query parameters to set. |
|
| 271 | + * @param array $types The query parameters types to set. |
|
| 272 | + * |
|
| 273 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 274 | + */ |
|
| 275 | + public function setParameters(array $params, array $types = array()) { |
|
| 276 | + $this->queryBuilder->setParameters($params, $types); |
|
| 277 | + |
|
| 278 | + return $this; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Gets all defined query parameters for the query being constructed indexed by parameter index or name. |
|
| 283 | + * |
|
| 284 | + * @return array The currently defined query parameters indexed by parameter index or name. |
|
| 285 | + */ |
|
| 286 | + public function getParameters() { |
|
| 287 | + return $this->queryBuilder->getParameters(); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Gets a (previously set) query parameter of the query being constructed. |
|
| 292 | + * |
|
| 293 | + * @param mixed $key The key (index or name) of the bound parameter. |
|
| 294 | + * |
|
| 295 | + * @return mixed The value of the bound parameter. |
|
| 296 | + */ |
|
| 297 | + public function getParameter($key) { |
|
| 298 | + return $this->queryBuilder->getParameter($key); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. |
|
| 303 | + * |
|
| 304 | + * @return array The currently defined query parameter types indexed by parameter index or name. |
|
| 305 | + */ |
|
| 306 | + public function getParameterTypes() { |
|
| 307 | + return $this->queryBuilder->getParameterTypes(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Gets a (previously set) query parameter type of the query being constructed. |
|
| 312 | + * |
|
| 313 | + * @param mixed $key The key (index or name) of the bound parameter type. |
|
| 314 | + * |
|
| 315 | + * @return mixed The value of the bound parameter type. |
|
| 316 | + */ |
|
| 317 | + public function getParameterType($key) { |
|
| 318 | + return $this->queryBuilder->getParameterType($key); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Sets the position of the first result to retrieve (the "offset"). |
|
| 323 | + * |
|
| 324 | + * @param integer $firstResult The first result to return. |
|
| 325 | + * |
|
| 326 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 327 | + */ |
|
| 328 | + public function setFirstResult($firstResult) { |
|
| 329 | + $this->queryBuilder->setFirstResult($firstResult); |
|
| 330 | + |
|
| 331 | + return $this; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Gets the position of the first result the query object was set to retrieve (the "offset"). |
|
| 336 | + * Returns NULL if {@link setFirstResult} was not applied to this QueryBuilder. |
|
| 337 | + * |
|
| 338 | + * @return integer The position of the first result. |
|
| 339 | + */ |
|
| 340 | + public function getFirstResult() { |
|
| 341 | + return $this->queryBuilder->getFirstResult(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * Sets the maximum number of results to retrieve (the "limit"). |
|
| 346 | + * |
|
| 347 | + * NOTE: Setting max results to "0" will cause mixed behaviour. While most |
|
| 348 | + * of the databases will just return an empty result set, Oracle will return |
|
| 349 | + * all entries. |
|
| 350 | + * |
|
| 351 | + * @param integer $maxResults The maximum number of results to retrieve. |
|
| 352 | + * |
|
| 353 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 354 | + */ |
|
| 355 | + public function setMaxResults($maxResults) { |
|
| 356 | + $this->queryBuilder->setMaxResults($maxResults); |
|
| 357 | + |
|
| 358 | + return $this; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Gets the maximum number of results the query object was set to retrieve (the "limit"). |
|
| 363 | + * Returns NULL if {@link setMaxResults} was not applied to this query builder. |
|
| 364 | + * |
|
| 365 | + * @return integer The maximum number of results. |
|
| 366 | + */ |
|
| 367 | + public function getMaxResults() { |
|
| 368 | + return $this->queryBuilder->getMaxResults(); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Specifies an item that is to be returned in the query result. |
|
| 373 | + * Replaces any previously specified selections, if any. |
|
| 374 | + * |
|
| 375 | + * <code> |
|
| 376 | + * $qb = $conn->getQueryBuilder() |
|
| 377 | + * ->select('u.id', 'p.id') |
|
| 378 | + * ->from('users', 'u') |
|
| 379 | + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
| 380 | + * </code> |
|
| 381 | + * |
|
| 382 | + * @param mixed ...$selects The selection expressions. |
|
| 383 | + * |
|
| 384 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 385 | + */ |
|
| 386 | + public function select(...$selects) { |
|
| 387 | + if (count($selects) === 1 && is_array($selects[0])) { |
|
| 388 | + $selects = $selects[0]; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $this->queryBuilder->select( |
|
| 392 | + $this->helper->quoteColumnNames($selects) |
|
| 393 | + ); |
|
| 394 | + |
|
| 395 | + return $this; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Specifies an item that is to be returned with a different name in the query result. |
|
| 400 | + * |
|
| 401 | + * <code> |
|
| 402 | + * $qb = $conn->getQueryBuilder() |
|
| 403 | + * ->selectAlias('u.id', 'user_id') |
|
| 404 | + * ->from('users', 'u') |
|
| 405 | + * ->leftJoin('u', 'phonenumbers', 'p', 'u.id = p.user_id'); |
|
| 406 | + * </code> |
|
| 407 | + * |
|
| 408 | + * @param mixed $select The selection expressions. |
|
| 409 | + * @param string $alias The column alias used in the constructed query. |
|
| 410 | + * |
|
| 411 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 412 | + */ |
|
| 413 | + public function selectAlias($select, $alias) { |
|
| 414 | + |
|
| 415 | + $this->queryBuilder->addSelect( |
|
| 416 | + $this->helper->quoteColumnName($select) . ' AS ' . $this->helper->quoteColumnName($alias) |
|
| 417 | + ); |
|
| 418 | + |
|
| 419 | + return $this; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Specifies an item that is to be returned uniquely in the query result. |
|
| 424 | + * |
|
| 425 | + * <code> |
|
| 426 | + * $qb = $conn->getQueryBuilder() |
|
| 427 | + * ->selectDistinct('type') |
|
| 428 | + * ->from('users'); |
|
| 429 | + * </code> |
|
| 430 | + * |
|
| 431 | + * @param mixed $select The selection expressions. |
|
| 432 | + * |
|
| 433 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 434 | + */ |
|
| 435 | + public function selectDistinct($select) { |
|
| 436 | + |
|
| 437 | + $this->queryBuilder->addSelect( |
|
| 438 | + 'DISTINCT ' . $this->helper->quoteColumnName($select) |
|
| 439 | + ); |
|
| 440 | + |
|
| 441 | + return $this; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Adds an item that is to be returned in the query result. |
|
| 446 | + * |
|
| 447 | + * <code> |
|
| 448 | + * $qb = $conn->getQueryBuilder() |
|
| 449 | + * ->select('u.id') |
|
| 450 | + * ->addSelect('p.id') |
|
| 451 | + * ->from('users', 'u') |
|
| 452 | + * ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id'); |
|
| 453 | + * </code> |
|
| 454 | + * |
|
| 455 | + * @param mixed ...$selects The selection expression. |
|
| 456 | + * |
|
| 457 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 458 | + */ |
|
| 459 | + public function addSelect(...$selects) { |
|
| 460 | + if (count($selects) === 1 && is_array($selects[0])) { |
|
| 461 | + $selects = $selects[0]; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + $this->queryBuilder->addSelect( |
|
| 465 | + $this->helper->quoteColumnNames($selects) |
|
| 466 | + ); |
|
| 467 | + |
|
| 468 | + return $this; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Turns the query being built into a bulk delete query that ranges over |
|
| 473 | + * a certain table. |
|
| 474 | + * |
|
| 475 | + * <code> |
|
| 476 | + * $qb = $conn->getQueryBuilder() |
|
| 477 | + * ->delete('users', 'u') |
|
| 478 | + * ->where('u.id = :user_id'); |
|
| 479 | + * ->setParameter(':user_id', 1); |
|
| 480 | + * </code> |
|
| 481 | + * |
|
| 482 | + * @param string $delete The table whose rows are subject to the deletion. |
|
| 483 | + * @param string $alias The table alias used in the constructed query. |
|
| 484 | + * |
|
| 485 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 486 | + */ |
|
| 487 | + public function delete($delete = null, $alias = null) { |
|
| 488 | + $this->queryBuilder->delete( |
|
| 489 | + $this->getTableName($delete), |
|
| 490 | + $alias |
|
| 491 | + ); |
|
| 492 | + |
|
| 493 | + return $this; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Turns the query being built into a bulk update query that ranges over |
|
| 498 | + * a certain table |
|
| 499 | + * |
|
| 500 | + * <code> |
|
| 501 | + * $qb = $conn->getQueryBuilder() |
|
| 502 | + * ->update('users', 'u') |
|
| 503 | + * ->set('u.password', md5('password')) |
|
| 504 | + * ->where('u.id = ?'); |
|
| 505 | + * </code> |
|
| 506 | + * |
|
| 507 | + * @param string $update The table whose rows are subject to the update. |
|
| 508 | + * @param string $alias The table alias used in the constructed query. |
|
| 509 | + * |
|
| 510 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 511 | + */ |
|
| 512 | + public function update($update = null, $alias = null) { |
|
| 513 | + $this->queryBuilder->update( |
|
| 514 | + $this->getTableName($update), |
|
| 515 | + $alias |
|
| 516 | + ); |
|
| 517 | + |
|
| 518 | + return $this; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Turns the query being built into an insert query that inserts into |
|
| 523 | + * a certain table |
|
| 524 | + * |
|
| 525 | + * <code> |
|
| 526 | + * $qb = $conn->getQueryBuilder() |
|
| 527 | + * ->insert('users') |
|
| 528 | + * ->values( |
|
| 529 | + * array( |
|
| 530 | + * 'name' => '?', |
|
| 531 | + * 'password' => '?' |
|
| 532 | + * ) |
|
| 533 | + * ); |
|
| 534 | + * </code> |
|
| 535 | + * |
|
| 536 | + * @param string $insert The table into which the rows should be inserted. |
|
| 537 | + * |
|
| 538 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 539 | + */ |
|
| 540 | + public function insert($insert = null) { |
|
| 541 | + $this->queryBuilder->insert( |
|
| 542 | + $this->getTableName($insert) |
|
| 543 | + ); |
|
| 544 | + |
|
| 545 | + $this->lastInsertedTable = $insert; |
|
| 546 | + |
|
| 547 | + return $this; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + /** |
|
| 551 | + * Creates and adds a query root corresponding to the table identified by the |
|
| 552 | + * given alias, forming a cartesian product with any existing query roots. |
|
| 553 | + * |
|
| 554 | + * <code> |
|
| 555 | + * $qb = $conn->getQueryBuilder() |
|
| 556 | + * ->select('u.id') |
|
| 557 | + * ->from('users', 'u') |
|
| 558 | + * </code> |
|
| 559 | + * |
|
| 560 | + * @param string $from The table. |
|
| 561 | + * @param string|null $alias The alias of the table. |
|
| 562 | + * |
|
| 563 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 564 | + */ |
|
| 565 | + public function from($from, $alias = null) { |
|
| 566 | + $this->queryBuilder->from( |
|
| 567 | + $this->getTableName($from), |
|
| 568 | + $this->quoteAlias($alias) |
|
| 569 | + ); |
|
| 570 | + |
|
| 571 | + return $this; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Creates and adds a join to the query. |
|
| 576 | + * |
|
| 577 | + * <code> |
|
| 578 | + * $qb = $conn->getQueryBuilder() |
|
| 579 | + * ->select('u.name') |
|
| 580 | + * ->from('users', 'u') |
|
| 581 | + * ->join('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 582 | + * </code> |
|
| 583 | + * |
|
| 584 | + * @param string $fromAlias The alias that points to a from clause. |
|
| 585 | + * @param string $join The table name to join. |
|
| 586 | + * @param string $alias The alias of the join table. |
|
| 587 | + * @param string $condition The condition for the join. |
|
| 588 | + * |
|
| 589 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 590 | + */ |
|
| 591 | + public function join($fromAlias, $join, $alias, $condition = null) { |
|
| 592 | + $this->queryBuilder->join( |
|
| 593 | + $this->quoteAlias($fromAlias), |
|
| 594 | + $this->getTableName($join), |
|
| 595 | + $this->quoteAlias($alias), |
|
| 596 | + $condition |
|
| 597 | + ); |
|
| 598 | + |
|
| 599 | + return $this; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Creates and adds a join to the query. |
|
| 604 | + * |
|
| 605 | + * <code> |
|
| 606 | + * $qb = $conn->getQueryBuilder() |
|
| 607 | + * ->select('u.name') |
|
| 608 | + * ->from('users', 'u') |
|
| 609 | + * ->innerJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 610 | + * </code> |
|
| 611 | + * |
|
| 612 | + * @param string $fromAlias The alias that points to a from clause. |
|
| 613 | + * @param string $join The table name to join. |
|
| 614 | + * @param string $alias The alias of the join table. |
|
| 615 | + * @param string $condition The condition for the join. |
|
| 616 | + * |
|
| 617 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 618 | + */ |
|
| 619 | + public function innerJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 620 | + $this->queryBuilder->innerJoin( |
|
| 621 | + $this->quoteAlias($fromAlias), |
|
| 622 | + $this->getTableName($join), |
|
| 623 | + $this->quoteAlias($alias), |
|
| 624 | + $condition |
|
| 625 | + ); |
|
| 626 | + |
|
| 627 | + return $this; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Creates and adds a left join to the query. |
|
| 632 | + * |
|
| 633 | + * <code> |
|
| 634 | + * $qb = $conn->getQueryBuilder() |
|
| 635 | + * ->select('u.name') |
|
| 636 | + * ->from('users', 'u') |
|
| 637 | + * ->leftJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 638 | + * </code> |
|
| 639 | + * |
|
| 640 | + * @param string $fromAlias The alias that points to a from clause. |
|
| 641 | + * @param string $join The table name to join. |
|
| 642 | + * @param string $alias The alias of the join table. |
|
| 643 | + * @param string $condition The condition for the join. |
|
| 644 | + * |
|
| 645 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 646 | + */ |
|
| 647 | + public function leftJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 648 | + $this->queryBuilder->leftJoin( |
|
| 649 | + $this->quoteAlias($fromAlias), |
|
| 650 | + $this->getTableName($join), |
|
| 651 | + $this->quoteAlias($alias), |
|
| 652 | + $condition |
|
| 653 | + ); |
|
| 654 | + |
|
| 655 | + return $this; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Creates and adds a right join to the query. |
|
| 660 | + * |
|
| 661 | + * <code> |
|
| 662 | + * $qb = $conn->getQueryBuilder() |
|
| 663 | + * ->select('u.name') |
|
| 664 | + * ->from('users', 'u') |
|
| 665 | + * ->rightJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1'); |
|
| 666 | + * </code> |
|
| 667 | + * |
|
| 668 | + * @param string $fromAlias The alias that points to a from clause. |
|
| 669 | + * @param string $join The table name to join. |
|
| 670 | + * @param string $alias The alias of the join table. |
|
| 671 | + * @param string $condition The condition for the join. |
|
| 672 | + * |
|
| 673 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 674 | + */ |
|
| 675 | + public function rightJoin($fromAlias, $join, $alias, $condition = null) { |
|
| 676 | + $this->queryBuilder->rightJoin( |
|
| 677 | + $this->quoteAlias($fromAlias), |
|
| 678 | + $this->getTableName($join), |
|
| 679 | + $this->quoteAlias($alias), |
|
| 680 | + $condition |
|
| 681 | + ); |
|
| 682 | + |
|
| 683 | + return $this; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Sets a new value for a column in a bulk update query. |
|
| 688 | + * |
|
| 689 | + * <code> |
|
| 690 | + * $qb = $conn->getQueryBuilder() |
|
| 691 | + * ->update('users', 'u') |
|
| 692 | + * ->set('u.password', md5('password')) |
|
| 693 | + * ->where('u.id = ?'); |
|
| 694 | + * </code> |
|
| 695 | + * |
|
| 696 | + * @param string $key The column to set. |
|
| 697 | + * @param string $value The value, expression, placeholder, etc. |
|
| 698 | + * |
|
| 699 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 700 | + */ |
|
| 701 | + public function set($key, $value) { |
|
| 702 | + $this->queryBuilder->set( |
|
| 703 | + $this->helper->quoteColumnName($key), |
|
| 704 | + $this->helper->quoteColumnName($value) |
|
| 705 | + ); |
|
| 706 | + |
|
| 707 | + return $this; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * Specifies one or more restrictions to the query result. |
|
| 712 | + * Replaces any previously specified restrictions, if any. |
|
| 713 | + * |
|
| 714 | + * <code> |
|
| 715 | + * $qb = $conn->getQueryBuilder() |
|
| 716 | + * ->select('u.name') |
|
| 717 | + * ->from('users', 'u') |
|
| 718 | + * ->where('u.id = ?'); |
|
| 719 | + * |
|
| 720 | + * // You can optionally programatically build and/or expressions |
|
| 721 | + * $qb = $conn->getQueryBuilder(); |
|
| 722 | + * |
|
| 723 | + * $or = $qb->expr()->orx(); |
|
| 724 | + * $or->add($qb->expr()->eq('u.id', 1)); |
|
| 725 | + * $or->add($qb->expr()->eq('u.id', 2)); |
|
| 726 | + * |
|
| 727 | + * $qb->update('users', 'u') |
|
| 728 | + * ->set('u.password', md5('password')) |
|
| 729 | + * ->where($or); |
|
| 730 | + * </code> |
|
| 731 | + * |
|
| 732 | + * @param mixed ...$predicates The restriction predicates. |
|
| 733 | + * |
|
| 734 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 735 | + */ |
|
| 736 | + public function where(...$predicates) { |
|
| 737 | + call_user_func_array( |
|
| 738 | + [$this->queryBuilder, 'where'], |
|
| 739 | + $predicates |
|
| 740 | + ); |
|
| 741 | + |
|
| 742 | + return $this; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * Adds one or more restrictions to the query results, forming a logical |
|
| 747 | + * conjunction with any previously specified restrictions. |
|
| 748 | + * |
|
| 749 | + * <code> |
|
| 750 | + * $qb = $conn->getQueryBuilder() |
|
| 751 | + * ->select('u') |
|
| 752 | + * ->from('users', 'u') |
|
| 753 | + * ->where('u.username LIKE ?') |
|
| 754 | + * ->andWhere('u.is_active = 1'); |
|
| 755 | + * </code> |
|
| 756 | + * |
|
| 757 | + * @param mixed ...$where The query restrictions. |
|
| 758 | + * |
|
| 759 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 760 | + * |
|
| 761 | + * @see where() |
|
| 762 | + */ |
|
| 763 | + public function andWhere(...$where) { |
|
| 764 | + call_user_func_array( |
|
| 765 | + [$this->queryBuilder, 'andWhere'], |
|
| 766 | + $where |
|
| 767 | + ); |
|
| 768 | + |
|
| 769 | + return $this; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Adds one or more restrictions to the query results, forming a logical |
|
| 774 | + * disjunction with any previously specified restrictions. |
|
| 775 | + * |
|
| 776 | + * <code> |
|
| 777 | + * $qb = $conn->getQueryBuilder() |
|
| 778 | + * ->select('u.name') |
|
| 779 | + * ->from('users', 'u') |
|
| 780 | + * ->where('u.id = 1') |
|
| 781 | + * ->orWhere('u.id = 2'); |
|
| 782 | + * </code> |
|
| 783 | + * |
|
| 784 | + * @param mixed ...$where The WHERE statement. |
|
| 785 | + * |
|
| 786 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 787 | + * |
|
| 788 | + * @see where() |
|
| 789 | + */ |
|
| 790 | + public function orWhere(...$where) { |
|
| 791 | + call_user_func_array( |
|
| 792 | + [$this->queryBuilder, 'orWhere'], |
|
| 793 | + $where |
|
| 794 | + ); |
|
| 795 | + |
|
| 796 | + return $this; |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Specifies a grouping over the results of the query. |
|
| 801 | + * Replaces any previously specified groupings, if any. |
|
| 802 | + * |
|
| 803 | + * <code> |
|
| 804 | + * $qb = $conn->getQueryBuilder() |
|
| 805 | + * ->select('u.name') |
|
| 806 | + * ->from('users', 'u') |
|
| 807 | + * ->groupBy('u.id'); |
|
| 808 | + * </code> |
|
| 809 | + * |
|
| 810 | + * @param mixed ...$groupBys The grouping expression. |
|
| 811 | + * |
|
| 812 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 813 | + */ |
|
| 814 | + public function groupBy(...$groupBys) { |
|
| 815 | + if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
| 816 | + $groupBys = $groupBys[0]; |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + call_user_func_array( |
|
| 820 | + [$this->queryBuilder, 'groupBy'], |
|
| 821 | + $this->helper->quoteColumnNames($groupBys) |
|
| 822 | + ); |
|
| 823 | + |
|
| 824 | + return $this; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Adds a grouping expression to the query. |
|
| 829 | + * |
|
| 830 | + * <code> |
|
| 831 | + * $qb = $conn->getQueryBuilder() |
|
| 832 | + * ->select('u.name') |
|
| 833 | + * ->from('users', 'u') |
|
| 834 | + * ->groupBy('u.lastLogin'); |
|
| 835 | + * ->addGroupBy('u.createdAt') |
|
| 836 | + * </code> |
|
| 837 | + * |
|
| 838 | + * @param mixed ...$groupBy The grouping expression. |
|
| 839 | + * |
|
| 840 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 841 | + */ |
|
| 842 | + public function addGroupBy(...$groupBys) { |
|
| 843 | + if (count($groupBys) === 1 && is_array($groupBys[0])) { |
|
| 844 | + $$groupBys = $groupBys[0]; |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + call_user_func_array( |
|
| 848 | + [$this->queryBuilder, 'addGroupBy'], |
|
| 849 | + $this->helper->quoteColumnNames($groupBys) |
|
| 850 | + ); |
|
| 851 | + |
|
| 852 | + return $this; |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * Sets a value for a column in an insert query. |
|
| 857 | + * |
|
| 858 | + * <code> |
|
| 859 | + * $qb = $conn->getQueryBuilder() |
|
| 860 | + * ->insert('users') |
|
| 861 | + * ->values( |
|
| 862 | + * array( |
|
| 863 | + * 'name' => '?' |
|
| 864 | + * ) |
|
| 865 | + * ) |
|
| 866 | + * ->setValue('password', '?'); |
|
| 867 | + * </code> |
|
| 868 | + * |
|
| 869 | + * @param string $column The column into which the value should be inserted. |
|
| 870 | + * @param string $value The value that should be inserted into the column. |
|
| 871 | + * |
|
| 872 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 873 | + */ |
|
| 874 | + public function setValue($column, $value) { |
|
| 875 | + $this->queryBuilder->setValue( |
|
| 876 | + $this->helper->quoteColumnName($column), |
|
| 877 | + $value |
|
| 878 | + ); |
|
| 879 | + |
|
| 880 | + return $this; |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Specifies values for an insert query indexed by column names. |
|
| 885 | + * Replaces any previous values, if any. |
|
| 886 | + * |
|
| 887 | + * <code> |
|
| 888 | + * $qb = $conn->getQueryBuilder() |
|
| 889 | + * ->insert('users') |
|
| 890 | + * ->values( |
|
| 891 | + * array( |
|
| 892 | + * 'name' => '?', |
|
| 893 | + * 'password' => '?' |
|
| 894 | + * ) |
|
| 895 | + * ); |
|
| 896 | + * </code> |
|
| 897 | + * |
|
| 898 | + * @param array $values The values to specify for the insert query indexed by column names. |
|
| 899 | + * |
|
| 900 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 901 | + */ |
|
| 902 | + public function values(array $values) { |
|
| 903 | + $quotedValues = []; |
|
| 904 | + foreach ($values as $key => $value) { |
|
| 905 | + $quotedValues[$this->helper->quoteColumnName($key)] = $value; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + $this->queryBuilder->values($quotedValues); |
|
| 909 | + |
|
| 910 | + return $this; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * Specifies a restriction over the groups of the query. |
|
| 915 | + * Replaces any previous having restrictions, if any. |
|
| 916 | + * |
|
| 917 | + * @param mixed ...$having The restriction over the groups. |
|
| 918 | + * |
|
| 919 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 920 | + */ |
|
| 921 | + public function having(...$having) { |
|
| 922 | + call_user_func_array( |
|
| 923 | + [$this->queryBuilder, 'having'], |
|
| 924 | + $having |
|
| 925 | + ); |
|
| 926 | + |
|
| 927 | + return $this; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Adds a restriction over the groups of the query, forming a logical |
|
| 932 | + * conjunction with any existing having restrictions. |
|
| 933 | + * |
|
| 934 | + * @param mixed ...$having The restriction to append. |
|
| 935 | + * |
|
| 936 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 937 | + */ |
|
| 938 | + public function andHaving(...$having) { |
|
| 939 | + call_user_func_array( |
|
| 940 | + [$this->queryBuilder, 'andHaving'], |
|
| 941 | + $having |
|
| 942 | + ); |
|
| 943 | + |
|
| 944 | + return $this; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * Adds a restriction over the groups of the query, forming a logical |
|
| 949 | + * disjunction with any existing having restrictions. |
|
| 950 | + * |
|
| 951 | + * @param mixed ...$having The restriction to add. |
|
| 952 | + * |
|
| 953 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 954 | + */ |
|
| 955 | + public function orHaving(...$having) { |
|
| 956 | + call_user_func_array( |
|
| 957 | + [$this->queryBuilder, 'orHaving'], |
|
| 958 | + $having |
|
| 959 | + ); |
|
| 960 | + |
|
| 961 | + return $this; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * Specifies an ordering for the query results. |
|
| 966 | + * Replaces any previously specified orderings, if any. |
|
| 967 | + * |
|
| 968 | + * @param string $sort The ordering expression. |
|
| 969 | + * @param string $order The ordering direction. |
|
| 970 | + * |
|
| 971 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 972 | + */ |
|
| 973 | + public function orderBy($sort, $order = null) { |
|
| 974 | + $this->queryBuilder->orderBy( |
|
| 975 | + $this->helper->quoteColumnName($sort), |
|
| 976 | + $order |
|
| 977 | + ); |
|
| 978 | + |
|
| 979 | + return $this; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * Adds an ordering to the query results. |
|
| 984 | + * |
|
| 985 | + * @param string $sort The ordering expression. |
|
| 986 | + * @param string $order The ordering direction. |
|
| 987 | + * |
|
| 988 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 989 | + */ |
|
| 990 | + public function addOrderBy($sort, $order = null) { |
|
| 991 | + $this->queryBuilder->addOrderBy( |
|
| 992 | + $this->helper->quoteColumnName($sort), |
|
| 993 | + $order |
|
| 994 | + ); |
|
| 995 | + |
|
| 996 | + return $this; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * Gets a query part by its name. |
|
| 1001 | + * |
|
| 1002 | + * @param string $queryPartName |
|
| 1003 | + * |
|
| 1004 | + * @return mixed |
|
| 1005 | + */ |
|
| 1006 | + public function getQueryPart($queryPartName) { |
|
| 1007 | + return $this->queryBuilder->getQueryPart($queryPartName); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + /** |
|
| 1011 | + * Gets all query parts. |
|
| 1012 | + * |
|
| 1013 | + * @return array |
|
| 1014 | + */ |
|
| 1015 | + public function getQueryParts() { |
|
| 1016 | + return $this->queryBuilder->getQueryParts(); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * Resets SQL parts. |
|
| 1021 | + * |
|
| 1022 | + * @param array|null $queryPartNames |
|
| 1023 | + * |
|
| 1024 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 1025 | + */ |
|
| 1026 | + public function resetQueryParts($queryPartNames = null) { |
|
| 1027 | + $this->queryBuilder->resetQueryParts($queryPartNames); |
|
| 1028 | + |
|
| 1029 | + return $this; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + /** |
|
| 1033 | + * Resets a single SQL part. |
|
| 1034 | + * |
|
| 1035 | + * @param string $queryPartName |
|
| 1036 | + * |
|
| 1037 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder This QueryBuilder instance. |
|
| 1038 | + */ |
|
| 1039 | + public function resetQueryPart($queryPartName) { |
|
| 1040 | + $this->queryBuilder->resetQueryPart($queryPartName); |
|
| 1041 | + |
|
| 1042 | + return $this; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * Creates a new named parameter and bind the value $value to it. |
|
| 1047 | + * |
|
| 1048 | + * This method provides a shortcut for PDOStatement::bindValue |
|
| 1049 | + * when using prepared statements. |
|
| 1050 | + * |
|
| 1051 | + * The parameter $value specifies the value that you want to bind. If |
|
| 1052 | + * $placeholder is not provided bindValue() will automatically create a |
|
| 1053 | + * placeholder for you. An automatic placeholder will be of the name |
|
| 1054 | + * ':dcValue1', ':dcValue2' etc. |
|
| 1055 | + * |
|
| 1056 | + * For more information see {@link http://php.net/pdostatement-bindparam} |
|
| 1057 | + * |
|
| 1058 | + * Example: |
|
| 1059 | + * <code> |
|
| 1060 | + * $value = 2; |
|
| 1061 | + * $q->eq( 'id', $q->bindValue( $value ) ); |
|
| 1062 | + * $stmt = $q->executeQuery(); // executed with 'id = 2' |
|
| 1063 | + * </code> |
|
| 1064 | + * |
|
| 1065 | + * @license New BSD License |
|
| 1066 | + * @link http://www.zetacomponents.org |
|
| 1067 | + * |
|
| 1068 | + * @param mixed $value |
|
| 1069 | + * @param mixed $type |
|
| 1070 | + * @param string $placeHolder The name to bind with. The string must start with a colon ':'. |
|
| 1071 | + * |
|
| 1072 | + * @return IParameter the placeholder name used. |
|
| 1073 | + */ |
|
| 1074 | + public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { |
|
| 1075 | + return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder)); |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * Creates a new positional parameter and bind the given value to it. |
|
| 1080 | + * |
|
| 1081 | + * Attention: If you are using positional parameters with the query builder you have |
|
| 1082 | + * to be very careful to bind all parameters in the order they appear in the SQL |
|
| 1083 | + * statement , otherwise they get bound in the wrong order which can lead to serious |
|
| 1084 | + * bugs in your code. |
|
| 1085 | + * |
|
| 1086 | + * Example: |
|
| 1087 | + * <code> |
|
| 1088 | + * $qb = $conn->getQueryBuilder(); |
|
| 1089 | + * $qb->select('u.*') |
|
| 1090 | + * ->from('users', 'u') |
|
| 1091 | + * ->where('u.username = ' . $qb->createPositionalParameter('Foo', IQueryBuilder::PARAM_STR)) |
|
| 1092 | + * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', IQueryBuilder::PARAM_STR)) |
|
| 1093 | + * </code> |
|
| 1094 | + * |
|
| 1095 | + * @param mixed $value |
|
| 1096 | + * @param integer $type |
|
| 1097 | + * |
|
| 1098 | + * @return IParameter |
|
| 1099 | + */ |
|
| 1100 | + public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { |
|
| 1101 | + return new Parameter($this->queryBuilder->createPositionalParameter($value, $type)); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + /** |
|
| 1105 | + * Creates a new parameter |
|
| 1106 | + * |
|
| 1107 | + * Example: |
|
| 1108 | + * <code> |
|
| 1109 | + * $qb = $conn->getQueryBuilder(); |
|
| 1110 | + * $qb->select('u.*') |
|
| 1111 | + * ->from('users', 'u') |
|
| 1112 | + * ->where('u.username = ' . $qb->createParameter('name')) |
|
| 1113 | + * ->setParameter('name', 'Bar', IQueryBuilder::PARAM_STR)) |
|
| 1114 | + * </code> |
|
| 1115 | + * |
|
| 1116 | + * @param string $name |
|
| 1117 | + * |
|
| 1118 | + * @return IParameter |
|
| 1119 | + */ |
|
| 1120 | + public function createParameter($name) { |
|
| 1121 | + return new Parameter(':' . $name); |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + /** |
|
| 1125 | + * Creates a new function |
|
| 1126 | + * |
|
| 1127 | + * Attention: Column names inside the call have to be quoted before hand |
|
| 1128 | + * |
|
| 1129 | + * Example: |
|
| 1130 | + * <code> |
|
| 1131 | + * $qb = $conn->getQueryBuilder(); |
|
| 1132 | + * $qb->select($qb->createFunction('COUNT(*)')) |
|
| 1133 | + * ->from('users', 'u') |
|
| 1134 | + * echo $qb->getSQL(); // SELECT COUNT(*) FROM `users` u |
|
| 1135 | + * </code> |
|
| 1136 | + * <code> |
|
| 1137 | + * $qb = $conn->getQueryBuilder(); |
|
| 1138 | + * $qb->select($qb->createFunction('COUNT(`column`)')) |
|
| 1139 | + * ->from('users', 'u') |
|
| 1140 | + * echo $qb->getSQL(); // SELECT COUNT(`column`) FROM `users` u |
|
| 1141 | + * </code> |
|
| 1142 | + * |
|
| 1143 | + * @param string $call |
|
| 1144 | + * |
|
| 1145 | + * @return IQueryFunction |
|
| 1146 | + */ |
|
| 1147 | + public function createFunction($call) { |
|
| 1148 | + return new QueryFunction($call); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + /** |
|
| 1152 | + * Used to get the id of the last inserted element |
|
| 1153 | + * @return int |
|
| 1154 | + * @throws \BadMethodCallException When being called before an insert query has been run. |
|
| 1155 | + */ |
|
| 1156 | + public function getLastInsertId() { |
|
| 1157 | + if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) { |
|
| 1158 | + // lastInsertId() needs the prefix but no quotes |
|
| 1159 | + $table = $this->prefixTableName($this->lastInsertedTable); |
|
| 1160 | + return (int) $this->connection->lastInsertId($table); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.'); |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + /** |
|
| 1167 | + * Returns the table name quoted and with database prefix as needed by the implementation |
|
| 1168 | + * |
|
| 1169 | + * @param string $table |
|
| 1170 | + * @return string |
|
| 1171 | + */ |
|
| 1172 | + public function getTableName($table) { |
|
| 1173 | + $table = $this->prefixTableName($table); |
|
| 1174 | + return $this->helper->quoteColumnName($table); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + /** |
|
| 1178 | + * Returns the table name with database prefix as needed by the implementation |
|
| 1179 | + * |
|
| 1180 | + * @param string $table |
|
| 1181 | + * @return string |
|
| 1182 | + */ |
|
| 1183 | + protected function prefixTableName($table) { |
|
| 1184 | + if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) { |
|
| 1185 | + return $table; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + return '*PREFIX*' . $table; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + /** |
|
| 1192 | + * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
| 1193 | + * |
|
| 1194 | + * @param string $column |
|
| 1195 | + * @param string $tableAlias |
|
| 1196 | + * @return string |
|
| 1197 | + */ |
|
| 1198 | + public function getColumnName($column, $tableAlias = '') { |
|
| 1199 | + if ($tableAlias !== '') { |
|
| 1200 | + $tableAlias .= '.'; |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + return $this->helper->quoteColumnName($tableAlias . $column); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * Returns the column name quoted and with table alias prefix as needed by the implementation |
|
| 1208 | + * |
|
| 1209 | + * @param string $alias |
|
| 1210 | + * @return string |
|
| 1211 | + */ |
|
| 1212 | + public function quoteAlias($alias) { |
|
| 1213 | + if ($alias === '' || $alias === null) { |
|
| 1214 | + return $alias; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return $this->helper->quoteColumnName($alias); |
|
| 1218 | + } |
|
| 1219 | 1219 | } |
@@ -27,55 +27,55 @@ |
||
| 27 | 27 | use OCP\DB\QueryBuilder\IQueryFunction; |
| 28 | 28 | |
| 29 | 29 | class QuoteHelper { |
| 30 | - /** |
|
| 31 | - * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
| 32 | - * @return array|string |
|
| 33 | - */ |
|
| 34 | - public function quoteColumnNames($strings) { |
|
| 35 | - if (!is_array($strings)) { |
|
| 36 | - return $this->quoteColumnName($strings); |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * @param array|string|ILiteral|IParameter|IQueryFunction $strings string, Literal or Parameter |
|
| 32 | + * @return array|string |
|
| 33 | + */ |
|
| 34 | + public function quoteColumnNames($strings) { |
|
| 35 | + if (!is_array($strings)) { |
|
| 36 | + return $this->quoteColumnName($strings); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - $return = []; |
|
| 40 | - foreach ($strings as $string) { |
|
| 41 | - $return[] = $this->quoteColumnName($string); |
|
| 42 | - } |
|
| 39 | + $return = []; |
|
| 40 | + foreach ($strings as $string) { |
|
| 41 | + $return[] = $this->quoteColumnName($string); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $return; |
|
| 45 | - } |
|
| 44 | + return $return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function quoteColumnName($string) { |
|
| 52 | - if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
| 53 | - return (string) $string; |
|
| 54 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string|ILiteral|IParameter|IQueryFunction $string string, Literal or Parameter |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function quoteColumnName($string) { |
|
| 52 | + if ($string instanceof IParameter || $string instanceof ILiteral || $string instanceof IQueryFunction) { |
|
| 53 | + return (string) $string; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - if ($string === null || $string === 'null' || $string === '*') { |
|
| 57 | - return $string; |
|
| 58 | - } |
|
| 56 | + if ($string === null || $string === 'null' || $string === '*') { |
|
| 57 | + return $string; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - if (!is_string($string)) { |
|
| 61 | - throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
| 62 | - } |
|
| 60 | + if (!is_string($string)) { |
|
| 61 | + throw new \InvalidArgumentException('Only strings, Literals and Parameters are allowed'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $string = str_replace(' AS ', ' as ', $string); |
|
| 65 | - if (substr_count($string, ' as ')) { |
|
| 66 | - return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2))); |
|
| 67 | - } |
|
| 64 | + $string = str_replace(' AS ', ' as ', $string); |
|
| 65 | + if (substr_count($string, ' as ')) { |
|
| 66 | + return implode(' as ', array_map([$this, 'quoteColumnName'], explode(' as ', $string, 2))); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - if (substr_count($string, '.')) { |
|
| 70 | - list($alias, $columnName) = explode('.', $string, 2); |
|
| 69 | + if (substr_count($string, '.')) { |
|
| 70 | + list($alias, $columnName) = explode('.', $string, 2); |
|
| 71 | 71 | |
| 72 | - if ($columnName === '*') { |
|
| 73 | - return '`' . $alias . '`.*'; |
|
| 74 | - } |
|
| 72 | + if ($columnName === '*') { |
|
| 73 | + return '`' . $alias . '`.*'; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return '`' . $alias . '`.`' . $columnName . '`'; |
|
| 77 | - } |
|
| 76 | + return '`' . $alias . '`.`' . $columnName . '`'; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return '`' . $string . '`'; |
|
| 80 | - } |
|
| 79 | + return '`' . $string . '`'; |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -70,12 +70,12 @@ |
||
| 70 | 70 | list($alias, $columnName) = explode('.', $string, 2); |
| 71 | 71 | |
| 72 | 72 | if ($columnName === '*') { |
| 73 | - return '`' . $alias . '`.*'; |
|
| 73 | + return '`'.$alias.'`.*'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return '`' . $alias . '`.`' . $columnName . '`'; |
|
| 76 | + return '`'.$alias.'`.`'.$columnName.'`'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return '`' . $string . '`'; |
|
| 79 | + return '`'.$string.'`'; |
|
| 80 | 80 | } |
| 81 | 81 | } |
@@ -45,337 +45,337 @@ |
||
| 45 | 45 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
| 46 | 46 | |
| 47 | 47 | class Router implements IRouter { |
| 48 | - /** @var RouteCollection[] */ |
|
| 49 | - protected $collections = []; |
|
| 50 | - /** @var null|RouteCollection */ |
|
| 51 | - protected $collection = null; |
|
| 52 | - /** @var null|string */ |
|
| 53 | - protected $collectionName = null; |
|
| 54 | - /** @var null|RouteCollection */ |
|
| 55 | - protected $root = null; |
|
| 56 | - /** @var null|UrlGenerator */ |
|
| 57 | - protected $generator = null; |
|
| 58 | - /** @var string[] */ |
|
| 59 | - protected $routingFiles; |
|
| 60 | - /** @var bool */ |
|
| 61 | - protected $loaded = false; |
|
| 62 | - /** @var array */ |
|
| 63 | - protected $loadedApps = []; |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - protected $logger; |
|
| 66 | - /** @var RequestContext */ |
|
| 67 | - protected $context; |
|
| 48 | + /** @var RouteCollection[] */ |
|
| 49 | + protected $collections = []; |
|
| 50 | + /** @var null|RouteCollection */ |
|
| 51 | + protected $collection = null; |
|
| 52 | + /** @var null|string */ |
|
| 53 | + protected $collectionName = null; |
|
| 54 | + /** @var null|RouteCollection */ |
|
| 55 | + protected $root = null; |
|
| 56 | + /** @var null|UrlGenerator */ |
|
| 57 | + protected $generator = null; |
|
| 58 | + /** @var string[] */ |
|
| 59 | + protected $routingFiles; |
|
| 60 | + /** @var bool */ |
|
| 61 | + protected $loaded = false; |
|
| 62 | + /** @var array */ |
|
| 63 | + protected $loadedApps = []; |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + protected $logger; |
|
| 66 | + /** @var RequestContext */ |
|
| 67 | + protected $context; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param ILogger $logger |
|
| 71 | - */ |
|
| 72 | - public function __construct(ILogger $logger) { |
|
| 73 | - $this->logger = $logger; |
|
| 74 | - $baseUrl = \OC::$WEBROOT; |
|
| 75 | - if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
| 76 | - $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); |
|
| 77 | - } |
|
| 78 | - if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) { |
|
| 79 | - $method = $_SERVER['REQUEST_METHOD']; |
|
| 80 | - } else { |
|
| 81 | - $method = 'GET'; |
|
| 82 | - } |
|
| 83 | - $request = \OC::$server->getRequest(); |
|
| 84 | - $host = $request->getServerHost(); |
|
| 85 | - $schema = $request->getServerProtocol(); |
|
| 86 | - $this->context = new RequestContext($baseUrl, $method, $host, $schema); |
|
| 87 | - // TODO cache |
|
| 88 | - $this->root = $this->getCollection('root'); |
|
| 89 | - } |
|
| 69 | + /** |
|
| 70 | + * @param ILogger $logger |
|
| 71 | + */ |
|
| 72 | + public function __construct(ILogger $logger) { |
|
| 73 | + $this->logger = $logger; |
|
| 74 | + $baseUrl = \OC::$WEBROOT; |
|
| 75 | + if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
| 76 | + $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); |
|
| 77 | + } |
|
| 78 | + if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) { |
|
| 79 | + $method = $_SERVER['REQUEST_METHOD']; |
|
| 80 | + } else { |
|
| 81 | + $method = 'GET'; |
|
| 82 | + } |
|
| 83 | + $request = \OC::$server->getRequest(); |
|
| 84 | + $host = $request->getServerHost(); |
|
| 85 | + $schema = $request->getServerProtocol(); |
|
| 86 | + $this->context = new RequestContext($baseUrl, $method, $host, $schema); |
|
| 87 | + // TODO cache |
|
| 88 | + $this->root = $this->getCollection('root'); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get the files to load the routes from |
|
| 93 | - * |
|
| 94 | - * @return string[] |
|
| 95 | - */ |
|
| 96 | - public function getRoutingFiles() { |
|
| 97 | - if (!isset($this->routingFiles)) { |
|
| 98 | - $this->routingFiles = []; |
|
| 99 | - foreach (\OC_APP::getEnabledApps() as $app) { |
|
| 100 | - $appPath = \OC_App::getAppPath($app); |
|
| 101 | - if($appPath !== false) { |
|
| 102 | - $file = $appPath . '/appinfo/routes.php'; |
|
| 103 | - if (file_exists($file)) { |
|
| 104 | - $this->routingFiles[$app] = $file; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - return $this->routingFiles; |
|
| 110 | - } |
|
| 91 | + /** |
|
| 92 | + * Get the files to load the routes from |
|
| 93 | + * |
|
| 94 | + * @return string[] |
|
| 95 | + */ |
|
| 96 | + public function getRoutingFiles() { |
|
| 97 | + if (!isset($this->routingFiles)) { |
|
| 98 | + $this->routingFiles = []; |
|
| 99 | + foreach (\OC_APP::getEnabledApps() as $app) { |
|
| 100 | + $appPath = \OC_App::getAppPath($app); |
|
| 101 | + if($appPath !== false) { |
|
| 102 | + $file = $appPath . '/appinfo/routes.php'; |
|
| 103 | + if (file_exists($file)) { |
|
| 104 | + $this->routingFiles[$app] = $file; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + return $this->routingFiles; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Loads the routes |
|
| 114 | - * |
|
| 115 | - * @param null|string $app |
|
| 116 | - */ |
|
| 117 | - public function loadRoutes($app = null) { |
|
| 118 | - if(is_string($app)) { |
|
| 119 | - $app = \OC_App::cleanAppId($app); |
|
| 120 | - } |
|
| 112 | + /** |
|
| 113 | + * Loads the routes |
|
| 114 | + * |
|
| 115 | + * @param null|string $app |
|
| 116 | + */ |
|
| 117 | + public function loadRoutes($app = null) { |
|
| 118 | + if(is_string($app)) { |
|
| 119 | + $app = \OC_App::cleanAppId($app); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - $requestedApp = $app; |
|
| 123 | - if ($this->loaded) { |
|
| 124 | - return; |
|
| 125 | - } |
|
| 126 | - if (is_null($app)) { |
|
| 127 | - $this->loaded = true; |
|
| 128 | - $routingFiles = $this->getRoutingFiles(); |
|
| 129 | - } else { |
|
| 130 | - if (isset($this->loadedApps[$app])) { |
|
| 131 | - return; |
|
| 132 | - } |
|
| 133 | - $file = \OC_App::getAppPath($app) . '/appinfo/routes.php'; |
|
| 134 | - if ($file !== false && file_exists($file)) { |
|
| 135 | - $routingFiles = [$app => $file]; |
|
| 136 | - } else { |
|
| 137 | - $routingFiles = []; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); |
|
| 141 | - foreach ($routingFiles as $app => $file) { |
|
| 142 | - if (!isset($this->loadedApps[$app])) { |
|
| 143 | - if (!\OC_App::isAppLoaded($app)) { |
|
| 144 | - // app MUST be loaded before app routes |
|
| 145 | - // try again next time loadRoutes() is called |
|
| 146 | - $this->loaded = false; |
|
| 147 | - continue; |
|
| 148 | - } |
|
| 149 | - $this->loadedApps[$app] = true; |
|
| 150 | - $this->useCollection($app); |
|
| 151 | - $this->requireRouteFile($file, $app); |
|
| 152 | - $collection = $this->getCollection($app); |
|
| 153 | - $collection->addPrefix('/apps/' . $app); |
|
| 154 | - $this->root->addCollection($collection); |
|
| 122 | + $requestedApp = $app; |
|
| 123 | + if ($this->loaded) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 126 | + if (is_null($app)) { |
|
| 127 | + $this->loaded = true; |
|
| 128 | + $routingFiles = $this->getRoutingFiles(); |
|
| 129 | + } else { |
|
| 130 | + if (isset($this->loadedApps[$app])) { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 133 | + $file = \OC_App::getAppPath($app) . '/appinfo/routes.php'; |
|
| 134 | + if ($file !== false && file_exists($file)) { |
|
| 135 | + $routingFiles = [$app => $file]; |
|
| 136 | + } else { |
|
| 137 | + $routingFiles = []; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); |
|
| 141 | + foreach ($routingFiles as $app => $file) { |
|
| 142 | + if (!isset($this->loadedApps[$app])) { |
|
| 143 | + if (!\OC_App::isAppLoaded($app)) { |
|
| 144 | + // app MUST be loaded before app routes |
|
| 145 | + // try again next time loadRoutes() is called |
|
| 146 | + $this->loaded = false; |
|
| 147 | + continue; |
|
| 148 | + } |
|
| 149 | + $this->loadedApps[$app] = true; |
|
| 150 | + $this->useCollection($app); |
|
| 151 | + $this->requireRouteFile($file, $app); |
|
| 152 | + $collection = $this->getCollection($app); |
|
| 153 | + $collection->addPrefix('/apps/' . $app); |
|
| 154 | + $this->root->addCollection($collection); |
|
| 155 | 155 | |
| 156 | - // Also add the OCS collection |
|
| 157 | - $collection = $this->getCollection($app.'.ocs'); |
|
| 158 | - $collection->addPrefix('/ocsapp'); |
|
| 159 | - $this->root->addCollection($collection); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - if (!isset($this->loadedApps['core'])) { |
|
| 163 | - $this->loadedApps['core'] = true; |
|
| 164 | - $this->useCollection('root'); |
|
| 165 | - require_once __DIR__ . '/../../../settings/routes.php'; |
|
| 166 | - require_once __DIR__ . '/../../../core/routes.php'; |
|
| 156 | + // Also add the OCS collection |
|
| 157 | + $collection = $this->getCollection($app.'.ocs'); |
|
| 158 | + $collection->addPrefix('/ocsapp'); |
|
| 159 | + $this->root->addCollection($collection); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + if (!isset($this->loadedApps['core'])) { |
|
| 163 | + $this->loadedApps['core'] = true; |
|
| 164 | + $this->useCollection('root'); |
|
| 165 | + require_once __DIR__ . '/../../../settings/routes.php'; |
|
| 166 | + require_once __DIR__ . '/../../../core/routes.php'; |
|
| 167 | 167 | |
| 168 | - // Also add the OCS collection |
|
| 169 | - $collection = $this->getCollection('root.ocs'); |
|
| 170 | - $collection->addPrefix('/ocsapp'); |
|
| 171 | - $this->root->addCollection($collection); |
|
| 172 | - } |
|
| 173 | - if ($this->loaded) { |
|
| 174 | - $collection = $this->getCollection('ocs'); |
|
| 175 | - $collection->addPrefix('/ocs'); |
|
| 176 | - $this->root->addCollection($collection); |
|
| 177 | - } |
|
| 178 | - \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); |
|
| 179 | - } |
|
| 168 | + // Also add the OCS collection |
|
| 169 | + $collection = $this->getCollection('root.ocs'); |
|
| 170 | + $collection->addPrefix('/ocsapp'); |
|
| 171 | + $this->root->addCollection($collection); |
|
| 172 | + } |
|
| 173 | + if ($this->loaded) { |
|
| 174 | + $collection = $this->getCollection('ocs'); |
|
| 175 | + $collection->addPrefix('/ocs'); |
|
| 176 | + $this->root->addCollection($collection); |
|
| 177 | + } |
|
| 178 | + \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * @return string |
|
| 183 | - * @deprecated |
|
| 184 | - */ |
|
| 185 | - public function getCacheKey() { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 181 | + /** |
|
| 182 | + * @return string |
|
| 183 | + * @deprecated |
|
| 184 | + */ |
|
| 185 | + public function getCacheKey() { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @param string $name |
|
| 191 | - * @return \Symfony\Component\Routing\RouteCollection |
|
| 192 | - */ |
|
| 193 | - protected function getCollection($name) { |
|
| 194 | - if (!isset($this->collections[$name])) { |
|
| 195 | - $this->collections[$name] = new RouteCollection(); |
|
| 196 | - } |
|
| 197 | - return $this->collections[$name]; |
|
| 198 | - } |
|
| 189 | + /** |
|
| 190 | + * @param string $name |
|
| 191 | + * @return \Symfony\Component\Routing\RouteCollection |
|
| 192 | + */ |
|
| 193 | + protected function getCollection($name) { |
|
| 194 | + if (!isset($this->collections[$name])) { |
|
| 195 | + $this->collections[$name] = new RouteCollection(); |
|
| 196 | + } |
|
| 197 | + return $this->collections[$name]; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * Sets the collection to use for adding routes |
|
| 202 | - * |
|
| 203 | - * @param string $name Name of the collection to use. |
|
| 204 | - * @return void |
|
| 205 | - */ |
|
| 206 | - public function useCollection($name) { |
|
| 207 | - $this->collection = $this->getCollection($name); |
|
| 208 | - $this->collectionName = $name; |
|
| 209 | - } |
|
| 200 | + /** |
|
| 201 | + * Sets the collection to use for adding routes |
|
| 202 | + * |
|
| 203 | + * @param string $name Name of the collection to use. |
|
| 204 | + * @return void |
|
| 205 | + */ |
|
| 206 | + public function useCollection($name) { |
|
| 207 | + $this->collection = $this->getCollection($name); |
|
| 208 | + $this->collectionName = $name; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * returns the current collection name in use for adding routes |
|
| 213 | - * |
|
| 214 | - * @return string the collection name |
|
| 215 | - */ |
|
| 216 | - public function getCurrentCollection() { |
|
| 217 | - return $this->collectionName; |
|
| 218 | - } |
|
| 211 | + /** |
|
| 212 | + * returns the current collection name in use for adding routes |
|
| 213 | + * |
|
| 214 | + * @return string the collection name |
|
| 215 | + */ |
|
| 216 | + public function getCurrentCollection() { |
|
| 217 | + return $this->collectionName; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Create a \OC\Route\Route. |
|
| 223 | - * |
|
| 224 | - * @param string $name Name of the route to create. |
|
| 225 | - * @param string $pattern The pattern to match |
|
| 226 | - * @param array $defaults An array of default parameter values |
|
| 227 | - * @param array $requirements An array of requirements for parameters (regexes) |
|
| 228 | - * @return \OC\Route\Route |
|
| 229 | - */ |
|
| 230 | - public function create($name, |
|
| 231 | - $pattern, |
|
| 232 | - array $defaults = [], |
|
| 233 | - array $requirements = []) { |
|
| 234 | - $route = new Route($pattern, $defaults, $requirements); |
|
| 235 | - $this->collection->add($name, $route); |
|
| 236 | - return $route; |
|
| 237 | - } |
|
| 221 | + /** |
|
| 222 | + * Create a \OC\Route\Route. |
|
| 223 | + * |
|
| 224 | + * @param string $name Name of the route to create. |
|
| 225 | + * @param string $pattern The pattern to match |
|
| 226 | + * @param array $defaults An array of default parameter values |
|
| 227 | + * @param array $requirements An array of requirements for parameters (regexes) |
|
| 228 | + * @return \OC\Route\Route |
|
| 229 | + */ |
|
| 230 | + public function create($name, |
|
| 231 | + $pattern, |
|
| 232 | + array $defaults = [], |
|
| 233 | + array $requirements = []) { |
|
| 234 | + $route = new Route($pattern, $defaults, $requirements); |
|
| 235 | + $this->collection->add($name, $route); |
|
| 236 | + return $route; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Find the route matching $url |
|
| 241 | - * |
|
| 242 | - * @param string $url The url to find |
|
| 243 | - * @throws \Exception |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function match($url) { |
|
| 247 | - if (substr($url, 0, 6) === '/apps/') { |
|
| 248 | - // empty string / 'apps' / $app / rest of the route |
|
| 249 | - list(, , $app,) = explode('/', $url, 4); |
|
| 239 | + /** |
|
| 240 | + * Find the route matching $url |
|
| 241 | + * |
|
| 242 | + * @param string $url The url to find |
|
| 243 | + * @throws \Exception |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function match($url) { |
|
| 247 | + if (substr($url, 0, 6) === '/apps/') { |
|
| 248 | + // empty string / 'apps' / $app / rest of the route |
|
| 249 | + list(, , $app,) = explode('/', $url, 4); |
|
| 250 | 250 | |
| 251 | - $app = \OC_App::cleanAppId($app); |
|
| 252 | - \OC::$REQUESTEDAPP = $app; |
|
| 253 | - $this->loadRoutes($app); |
|
| 254 | - } else if (substr($url, 0, 13) === '/ocsapp/apps/') { |
|
| 255 | - // empty string / 'ocsapp' / 'apps' / $app / rest of the route |
|
| 256 | - list(, , , $app,) = explode('/', $url, 5); |
|
| 251 | + $app = \OC_App::cleanAppId($app); |
|
| 252 | + \OC::$REQUESTEDAPP = $app; |
|
| 253 | + $this->loadRoutes($app); |
|
| 254 | + } else if (substr($url, 0, 13) === '/ocsapp/apps/') { |
|
| 255 | + // empty string / 'ocsapp' / 'apps' / $app / rest of the route |
|
| 256 | + list(, , , $app,) = explode('/', $url, 5); |
|
| 257 | 257 | |
| 258 | - $app = \OC_App::cleanAppId($app); |
|
| 259 | - \OC::$REQUESTEDAPP = $app; |
|
| 260 | - $this->loadRoutes($app); |
|
| 261 | - } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') { |
|
| 262 | - \OC::$REQUESTEDAPP = $url; |
|
| 263 | - if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) { |
|
| 264 | - \OC_App::loadApps(); |
|
| 265 | - } |
|
| 266 | - $this->loadRoutes('core'); |
|
| 267 | - } else { |
|
| 268 | - $this->loadRoutes(); |
|
| 269 | - } |
|
| 258 | + $app = \OC_App::cleanAppId($app); |
|
| 259 | + \OC::$REQUESTEDAPP = $app; |
|
| 260 | + $this->loadRoutes($app); |
|
| 261 | + } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') { |
|
| 262 | + \OC::$REQUESTEDAPP = $url; |
|
| 263 | + if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) { |
|
| 264 | + \OC_App::loadApps(); |
|
| 265 | + } |
|
| 266 | + $this->loadRoutes('core'); |
|
| 267 | + } else { |
|
| 268 | + $this->loadRoutes(); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - $matcher = new UrlMatcher($this->root, $this->context); |
|
| 272 | - try { |
|
| 273 | - $parameters = $matcher->match($url); |
|
| 274 | - } catch (ResourceNotFoundException $e) { |
|
| 275 | - if (substr($url, -1) !== '/') { |
|
| 276 | - // We allow links to apps/files? for backwards compatibility reasons |
|
| 277 | - // However, since Symfony does not allow empty route names, the route |
|
| 278 | - // we need to match is '/', so we need to append the '/' here. |
|
| 279 | - try { |
|
| 280 | - $parameters = $matcher->match($url . '/'); |
|
| 281 | - } catch (ResourceNotFoundException $newException) { |
|
| 282 | - // If we still didn't match a route, we throw the original exception |
|
| 283 | - throw $e; |
|
| 284 | - } |
|
| 285 | - } else { |
|
| 286 | - throw $e; |
|
| 287 | - } |
|
| 288 | - } |
|
| 271 | + $matcher = new UrlMatcher($this->root, $this->context); |
|
| 272 | + try { |
|
| 273 | + $parameters = $matcher->match($url); |
|
| 274 | + } catch (ResourceNotFoundException $e) { |
|
| 275 | + if (substr($url, -1) !== '/') { |
|
| 276 | + // We allow links to apps/files? for backwards compatibility reasons |
|
| 277 | + // However, since Symfony does not allow empty route names, the route |
|
| 278 | + // we need to match is '/', so we need to append the '/' here. |
|
| 279 | + try { |
|
| 280 | + $parameters = $matcher->match($url . '/'); |
|
| 281 | + } catch (ResourceNotFoundException $newException) { |
|
| 282 | + // If we still didn't match a route, we throw the original exception |
|
| 283 | + throw $e; |
|
| 284 | + } |
|
| 285 | + } else { |
|
| 286 | + throw $e; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - \OC::$server->getEventLogger()->start('run_route', 'Run route'); |
|
| 291 | - if (isset($parameters['action'])) { |
|
| 292 | - $action = $parameters['action']; |
|
| 293 | - if (!is_callable($action)) { |
|
| 294 | - throw new \Exception('not a callable action'); |
|
| 295 | - } |
|
| 296 | - unset($parameters['action']); |
|
| 297 | - call_user_func($action, $parameters); |
|
| 298 | - } elseif (isset($parameters['file'])) { |
|
| 299 | - include $parameters['file']; |
|
| 300 | - } else { |
|
| 301 | - throw new \Exception('no action available'); |
|
| 302 | - } |
|
| 303 | - \OC::$server->getEventLogger()->end('run_route'); |
|
| 304 | - } |
|
| 290 | + \OC::$server->getEventLogger()->start('run_route', 'Run route'); |
|
| 291 | + if (isset($parameters['action'])) { |
|
| 292 | + $action = $parameters['action']; |
|
| 293 | + if (!is_callable($action)) { |
|
| 294 | + throw new \Exception('not a callable action'); |
|
| 295 | + } |
|
| 296 | + unset($parameters['action']); |
|
| 297 | + call_user_func($action, $parameters); |
|
| 298 | + } elseif (isset($parameters['file'])) { |
|
| 299 | + include $parameters['file']; |
|
| 300 | + } else { |
|
| 301 | + throw new \Exception('no action available'); |
|
| 302 | + } |
|
| 303 | + \OC::$server->getEventLogger()->end('run_route'); |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Get the url generator |
|
| 308 | - * |
|
| 309 | - * @return \Symfony\Component\Routing\Generator\UrlGenerator |
|
| 310 | - * |
|
| 311 | - */ |
|
| 312 | - public function getGenerator() { |
|
| 313 | - if (null !== $this->generator) { |
|
| 314 | - return $this->generator; |
|
| 315 | - } |
|
| 306 | + /** |
|
| 307 | + * Get the url generator |
|
| 308 | + * |
|
| 309 | + * @return \Symfony\Component\Routing\Generator\UrlGenerator |
|
| 310 | + * |
|
| 311 | + */ |
|
| 312 | + public function getGenerator() { |
|
| 313 | + if (null !== $this->generator) { |
|
| 314 | + return $this->generator; |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - return $this->generator = new UrlGenerator($this->root, $this->context); |
|
| 318 | - } |
|
| 317 | + return $this->generator = new UrlGenerator($this->root, $this->context); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Generate url based on $name and $parameters |
|
| 322 | - * |
|
| 323 | - * @param string $name Name of the route to use. |
|
| 324 | - * @param array $parameters Parameters for the route |
|
| 325 | - * @param bool $absolute |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 328 | - public function generate($name, |
|
| 329 | - $parameters = [], |
|
| 330 | - $absolute = false) { |
|
| 331 | - $this->loadRoutes(); |
|
| 332 | - try { |
|
| 333 | - $referenceType = UrlGenerator::ABSOLUTE_URL; |
|
| 334 | - if ($absolute === false) { |
|
| 335 | - $referenceType = UrlGenerator::ABSOLUTE_PATH; |
|
| 336 | - } |
|
| 337 | - return $this->getGenerator()->generate($name, $parameters, $referenceType); |
|
| 338 | - } catch (RouteNotFoundException $e) { |
|
| 339 | - $this->logger->logException($e); |
|
| 340 | - return ''; |
|
| 341 | - } |
|
| 342 | - } |
|
| 320 | + /** |
|
| 321 | + * Generate url based on $name and $parameters |
|
| 322 | + * |
|
| 323 | + * @param string $name Name of the route to use. |
|
| 324 | + * @param array $parameters Parameters for the route |
|
| 325 | + * @param bool $absolute |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | + public function generate($name, |
|
| 329 | + $parameters = [], |
|
| 330 | + $absolute = false) { |
|
| 331 | + $this->loadRoutes(); |
|
| 332 | + try { |
|
| 333 | + $referenceType = UrlGenerator::ABSOLUTE_URL; |
|
| 334 | + if ($absolute === false) { |
|
| 335 | + $referenceType = UrlGenerator::ABSOLUTE_PATH; |
|
| 336 | + } |
|
| 337 | + return $this->getGenerator()->generate($name, $parameters, $referenceType); |
|
| 338 | + } catch (RouteNotFoundException $e) { |
|
| 339 | + $this->logger->logException($e); |
|
| 340 | + return ''; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * To isolate the variable scope used inside the $file it is required in it's own method |
|
| 346 | - * |
|
| 347 | - * @param string $file the route file location to include |
|
| 348 | - * @param string $appName |
|
| 349 | - */ |
|
| 350 | - private function requireRouteFile($file, $appName) { |
|
| 351 | - $this->setupRoutes(include_once $file, $appName); |
|
| 352 | - } |
|
| 344 | + /** |
|
| 345 | + * To isolate the variable scope used inside the $file it is required in it's own method |
|
| 346 | + * |
|
| 347 | + * @param string $file the route file location to include |
|
| 348 | + * @param string $appName |
|
| 349 | + */ |
|
| 350 | + private function requireRouteFile($file, $appName) { |
|
| 351 | + $this->setupRoutes(include_once $file, $appName); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * If a routes.php file returns an array, try to set up the application and |
|
| 357 | - * register the routes for the app. The application class will be chosen by |
|
| 358 | - * camelcasing the appname, e.g.: my_app will be turned into |
|
| 359 | - * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default |
|
| 360 | - * App will be intialized. This makes it optional to ship an |
|
| 361 | - * appinfo/application.php by using the built in query resolver |
|
| 362 | - * |
|
| 363 | - * @param array $routes the application routes |
|
| 364 | - * @param string $appName the name of the app. |
|
| 365 | - */ |
|
| 366 | - private function setupRoutes($routes, $appName) { |
|
| 367 | - if (is_array($routes)) { |
|
| 368 | - $appNameSpace = App::buildAppNamespace($appName); |
|
| 355 | + /** |
|
| 356 | + * If a routes.php file returns an array, try to set up the application and |
|
| 357 | + * register the routes for the app. The application class will be chosen by |
|
| 358 | + * camelcasing the appname, e.g.: my_app will be turned into |
|
| 359 | + * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default |
|
| 360 | + * App will be intialized. This makes it optional to ship an |
|
| 361 | + * appinfo/application.php by using the built in query resolver |
|
| 362 | + * |
|
| 363 | + * @param array $routes the application routes |
|
| 364 | + * @param string $appName the name of the app. |
|
| 365 | + */ |
|
| 366 | + private function setupRoutes($routes, $appName) { |
|
| 367 | + if (is_array($routes)) { |
|
| 368 | + $appNameSpace = App::buildAppNamespace($appName); |
|
| 369 | 369 | |
| 370 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 370 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 371 | 371 | |
| 372 | - if (class_exists($applicationClassName)) { |
|
| 373 | - $application = new $applicationClassName(); |
|
| 374 | - } else { |
|
| 375 | - $application = new App($appName); |
|
| 376 | - } |
|
| 372 | + if (class_exists($applicationClassName)) { |
|
| 373 | + $application = new $applicationClassName(); |
|
| 374 | + } else { |
|
| 375 | + $application = new App($appName); |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - $application->registerRoutes($this, $routes); |
|
| 379 | - } |
|
| 380 | - } |
|
| 378 | + $application->registerRoutes($this, $routes); |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | 381 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | public function __construct(ILogger $logger) { |
| 73 | 73 | $this->logger = $logger; |
| 74 | 74 | $baseUrl = \OC::$WEBROOT; |
| 75 | - if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
| 75 | + if (!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
| 76 | 76 | $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); |
| 77 | 77 | } |
| 78 | 78 | if (!\OC::$CLI && isset($_SERVER['REQUEST_METHOD'])) { |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | $this->routingFiles = []; |
| 99 | 99 | foreach (\OC_APP::getEnabledApps() as $app) { |
| 100 | 100 | $appPath = \OC_App::getAppPath($app); |
| 101 | - if($appPath !== false) { |
|
| 102 | - $file = $appPath . '/appinfo/routes.php'; |
|
| 101 | + if ($appPath !== false) { |
|
| 102 | + $file = $appPath.'/appinfo/routes.php'; |
|
| 103 | 103 | if (file_exists($file)) { |
| 104 | 104 | $this->routingFiles[$app] = $file; |
| 105 | 105 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param null|string $app |
| 116 | 116 | */ |
| 117 | 117 | public function loadRoutes($app = null) { |
| 118 | - if(is_string($app)) { |
|
| 118 | + if (is_string($app)) { |
|
| 119 | 119 | $app = \OC_App::cleanAppId($app); |
| 120 | 120 | } |
| 121 | 121 | |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | if (isset($this->loadedApps[$app])) { |
| 131 | 131 | return; |
| 132 | 132 | } |
| 133 | - $file = \OC_App::getAppPath($app) . '/appinfo/routes.php'; |
|
| 133 | + $file = \OC_App::getAppPath($app).'/appinfo/routes.php'; |
|
| 134 | 134 | if ($file !== false && file_exists($file)) { |
| 135 | 135 | $routingFiles = [$app => $file]; |
| 136 | 136 | } else { |
| 137 | 137 | $routingFiles = []; |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | - \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); |
|
| 140 | + \OC::$server->getEventLogger()->start('loadroutes'.$requestedApp, 'Loading Routes'); |
|
| 141 | 141 | foreach ($routingFiles as $app => $file) { |
| 142 | 142 | if (!isset($this->loadedApps[$app])) { |
| 143 | 143 | if (!\OC_App::isAppLoaded($app)) { |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $this->useCollection($app); |
| 151 | 151 | $this->requireRouteFile($file, $app); |
| 152 | 152 | $collection = $this->getCollection($app); |
| 153 | - $collection->addPrefix('/apps/' . $app); |
|
| 153 | + $collection->addPrefix('/apps/'.$app); |
|
| 154 | 154 | $this->root->addCollection($collection); |
| 155 | 155 | |
| 156 | 156 | // Also add the OCS collection |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | if (!isset($this->loadedApps['core'])) { |
| 163 | 163 | $this->loadedApps['core'] = true; |
| 164 | 164 | $this->useCollection('root'); |
| 165 | - require_once __DIR__ . '/../../../settings/routes.php'; |
|
| 166 | - require_once __DIR__ . '/../../../core/routes.php'; |
|
| 165 | + require_once __DIR__.'/../../../settings/routes.php'; |
|
| 166 | + require_once __DIR__.'/../../../core/routes.php'; |
|
| 167 | 167 | |
| 168 | 168 | // Also add the OCS collection |
| 169 | 169 | $collection = $this->getCollection('root.ocs'); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $collection->addPrefix('/ocs'); |
| 176 | 176 | $this->root->addCollection($collection); |
| 177 | 177 | } |
| 178 | - \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); |
|
| 178 | + \OC::$server->getEventLogger()->end('loadroutes'.$requestedApp); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -246,14 +246,14 @@ discard block |
||
| 246 | 246 | public function match($url) { |
| 247 | 247 | if (substr($url, 0, 6) === '/apps/') { |
| 248 | 248 | // empty string / 'apps' / $app / rest of the route |
| 249 | - list(, , $app,) = explode('/', $url, 4); |
|
| 249 | + list(,, $app,) = explode('/', $url, 4); |
|
| 250 | 250 | |
| 251 | 251 | $app = \OC_App::cleanAppId($app); |
| 252 | 252 | \OC::$REQUESTEDAPP = $app; |
| 253 | 253 | $this->loadRoutes($app); |
| 254 | 254 | } else if (substr($url, 0, 13) === '/ocsapp/apps/') { |
| 255 | 255 | // empty string / 'ocsapp' / 'apps' / $app / rest of the route |
| 256 | - list(, , , $app,) = explode('/', $url, 5); |
|
| 256 | + list(,,, $app,) = explode('/', $url, 5); |
|
| 257 | 257 | |
| 258 | 258 | $app = \OC_App::cleanAppId($app); |
| 259 | 259 | \OC::$REQUESTEDAPP = $app; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | // However, since Symfony does not allow empty route names, the route |
| 278 | 278 | // we need to match is '/', so we need to append the '/' here. |
| 279 | 279 | try { |
| 280 | - $parameters = $matcher->match($url . '/'); |
|
| 280 | + $parameters = $matcher->match($url.'/'); |
|
| 281 | 281 | } catch (ResourceNotFoundException $newException) { |
| 282 | 282 | // If we still didn't match a route, we throw the original exception |
| 283 | 283 | throw $e; |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | if (is_array($routes)) { |
| 368 | 368 | $appNameSpace = App::buildAppNamespace($appName); |
| 369 | 369 | |
| 370 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
| 370 | + $applicationClassName = $appNameSpace.'\\AppInfo\\Application'; |
|
| 371 | 371 | |
| 372 | 372 | if (class_exists($applicationClassName)) { |
| 373 | 373 | $application = new $applicationClassName(); |
@@ -34,156 +34,156 @@ |
||
| 34 | 34 | |
| 35 | 35 | class RemoteController extends OCSController { |
| 36 | 36 | |
| 37 | - /** @var Manager */ |
|
| 38 | - private $externalManager; |
|
| 39 | - |
|
| 40 | - /** @var ILogger */ |
|
| 41 | - private $logger; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @NoAdminRequired |
|
| 45 | - * |
|
| 46 | - * Remote constructor. |
|
| 47 | - * |
|
| 48 | - * @param string $appName |
|
| 49 | - * @param IRequest $request |
|
| 50 | - * @param Manager $externalManager |
|
| 51 | - */ |
|
| 52 | - public function __construct($appName, |
|
| 53 | - IRequest $request, |
|
| 54 | - Manager $externalManager, |
|
| 55 | - ILogger $logger) { |
|
| 56 | - parent::__construct($appName, $request); |
|
| 57 | - |
|
| 58 | - $this->externalManager = $externalManager; |
|
| 59 | - $this->logger = $logger; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @NoAdminRequired |
|
| 64 | - * |
|
| 65 | - * Get list of pending remote shares |
|
| 66 | - * |
|
| 67 | - * @return DataResponse |
|
| 68 | - */ |
|
| 69 | - public function getOpenShares() { |
|
| 70 | - return new DataResponse($this->externalManager->getOpenShares()); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @NoAdminRequired |
|
| 75 | - * |
|
| 76 | - * Accept a remote share |
|
| 77 | - * |
|
| 78 | - * @param int $id |
|
| 79 | - * @return DataResponse |
|
| 80 | - * @throws OCSNotFoundException |
|
| 81 | - */ |
|
| 82 | - public function acceptShare($id) { |
|
| 83 | - if ($this->externalManager->acceptShare($id)) { |
|
| 84 | - return new DataResponse(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $this->logger->error('Could not accept federated share with id: ' . $id, |
|
| 88 | - ['app' => 'files_sharing']); |
|
| 89 | - |
|
| 90 | - throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @NoAdminRequired |
|
| 95 | - * |
|
| 96 | - * Decline a remote share |
|
| 97 | - * |
|
| 98 | - * @param int $id |
|
| 99 | - * @return DataResponse |
|
| 100 | - * @throws OCSNotFoundException |
|
| 101 | - */ |
|
| 102 | - public function declineShare($id) { |
|
| 103 | - if ($this->externalManager->declineShare($id)) { |
|
| 104 | - return new DataResponse(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // Make sure the user has no notification for something that does not exist anymore. |
|
| 108 | - $this->externalManager->processNotification($id); |
|
| 109 | - |
|
| 110 | - throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param array $share Share with info from the share_external table |
|
| 115 | - * @return array enriched share info with data from the filecache |
|
| 116 | - */ |
|
| 117 | - private static function extendShareInfo($share) { |
|
| 118 | - $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
| 119 | - $info = $view->getFileInfo($share['mountpoint']); |
|
| 120 | - |
|
| 121 | - $share['mimetype'] = $info->getMimetype(); |
|
| 122 | - $share['mtime'] = $info->getMTime(); |
|
| 123 | - $share['permissions'] = $info->getPermissions(); |
|
| 124 | - $share['type'] = $info->getType(); |
|
| 125 | - $share['file_id'] = $info->getId(); |
|
| 126 | - |
|
| 127 | - return $share; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @NoAdminRequired |
|
| 132 | - * |
|
| 133 | - * List accepted remote shares |
|
| 134 | - * |
|
| 135 | - * @return DataResponse |
|
| 136 | - */ |
|
| 137 | - public function getShares() { |
|
| 138 | - $shares = $this->externalManager->getAcceptedShares(); |
|
| 139 | - $shares = array_map('self::extendShareInfo', $shares); |
|
| 140 | - |
|
| 141 | - return new DataResponse($shares); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @NoAdminRequired |
|
| 146 | - * |
|
| 147 | - * Get info of a remote share |
|
| 148 | - * |
|
| 149 | - * @param int $id |
|
| 150 | - * @return DataResponse |
|
| 151 | - * @throws OCSNotFoundException |
|
| 152 | - */ |
|
| 153 | - public function getShare($id) { |
|
| 154 | - $shareInfo = $this->externalManager->getShare($id); |
|
| 155 | - |
|
| 156 | - if ($shareInfo === false) { |
|
| 157 | - throw new OCSNotFoundException('share does not exist'); |
|
| 158 | - } else { |
|
| 159 | - $shareInfo = self::extendShareInfo($shareInfo); |
|
| 160 | - return new DataResponse($shareInfo); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @NoAdminRequired |
|
| 166 | - * |
|
| 167 | - * Unshare a remote share |
|
| 168 | - * |
|
| 169 | - * @param int $id |
|
| 170 | - * @return DataResponse |
|
| 171 | - * @throws OCSNotFoundException |
|
| 172 | - * @throws OCSForbiddenException |
|
| 173 | - */ |
|
| 174 | - public function unshare($id) { |
|
| 175 | - $shareInfo = $this->externalManager->getShare($id); |
|
| 176 | - |
|
| 177 | - if ($shareInfo === false) { |
|
| 178 | - throw new OCSNotFoundException('Share does not exist'); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
| 182 | - |
|
| 183 | - if ($this->externalManager->removeShare($mountPoint) === true) { |
|
| 184 | - return new DataResponse(); |
|
| 185 | - } else { |
|
| 186 | - throw new OCSForbiddenException('Could not unshare'); |
|
| 187 | - } |
|
| 188 | - } |
|
| 37 | + /** @var Manager */ |
|
| 38 | + private $externalManager; |
|
| 39 | + |
|
| 40 | + /** @var ILogger */ |
|
| 41 | + private $logger; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @NoAdminRequired |
|
| 45 | + * |
|
| 46 | + * Remote constructor. |
|
| 47 | + * |
|
| 48 | + * @param string $appName |
|
| 49 | + * @param IRequest $request |
|
| 50 | + * @param Manager $externalManager |
|
| 51 | + */ |
|
| 52 | + public function __construct($appName, |
|
| 53 | + IRequest $request, |
|
| 54 | + Manager $externalManager, |
|
| 55 | + ILogger $logger) { |
|
| 56 | + parent::__construct($appName, $request); |
|
| 57 | + |
|
| 58 | + $this->externalManager = $externalManager; |
|
| 59 | + $this->logger = $logger; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @NoAdminRequired |
|
| 64 | + * |
|
| 65 | + * Get list of pending remote shares |
|
| 66 | + * |
|
| 67 | + * @return DataResponse |
|
| 68 | + */ |
|
| 69 | + public function getOpenShares() { |
|
| 70 | + return new DataResponse($this->externalManager->getOpenShares()); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @NoAdminRequired |
|
| 75 | + * |
|
| 76 | + * Accept a remote share |
|
| 77 | + * |
|
| 78 | + * @param int $id |
|
| 79 | + * @return DataResponse |
|
| 80 | + * @throws OCSNotFoundException |
|
| 81 | + */ |
|
| 82 | + public function acceptShare($id) { |
|
| 83 | + if ($this->externalManager->acceptShare($id)) { |
|
| 84 | + return new DataResponse(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $this->logger->error('Could not accept federated share with id: ' . $id, |
|
| 88 | + ['app' => 'files_sharing']); |
|
| 89 | + |
|
| 90 | + throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @NoAdminRequired |
|
| 95 | + * |
|
| 96 | + * Decline a remote share |
|
| 97 | + * |
|
| 98 | + * @param int $id |
|
| 99 | + * @return DataResponse |
|
| 100 | + * @throws OCSNotFoundException |
|
| 101 | + */ |
|
| 102 | + public function declineShare($id) { |
|
| 103 | + if ($this->externalManager->declineShare($id)) { |
|
| 104 | + return new DataResponse(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // Make sure the user has no notification for something that does not exist anymore. |
|
| 108 | + $this->externalManager->processNotification($id); |
|
| 109 | + |
|
| 110 | + throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param array $share Share with info from the share_external table |
|
| 115 | + * @return array enriched share info with data from the filecache |
|
| 116 | + */ |
|
| 117 | + private static function extendShareInfo($share) { |
|
| 118 | + $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
| 119 | + $info = $view->getFileInfo($share['mountpoint']); |
|
| 120 | + |
|
| 121 | + $share['mimetype'] = $info->getMimetype(); |
|
| 122 | + $share['mtime'] = $info->getMTime(); |
|
| 123 | + $share['permissions'] = $info->getPermissions(); |
|
| 124 | + $share['type'] = $info->getType(); |
|
| 125 | + $share['file_id'] = $info->getId(); |
|
| 126 | + |
|
| 127 | + return $share; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @NoAdminRequired |
|
| 132 | + * |
|
| 133 | + * List accepted remote shares |
|
| 134 | + * |
|
| 135 | + * @return DataResponse |
|
| 136 | + */ |
|
| 137 | + public function getShares() { |
|
| 138 | + $shares = $this->externalManager->getAcceptedShares(); |
|
| 139 | + $shares = array_map('self::extendShareInfo', $shares); |
|
| 140 | + |
|
| 141 | + return new DataResponse($shares); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @NoAdminRequired |
|
| 146 | + * |
|
| 147 | + * Get info of a remote share |
|
| 148 | + * |
|
| 149 | + * @param int $id |
|
| 150 | + * @return DataResponse |
|
| 151 | + * @throws OCSNotFoundException |
|
| 152 | + */ |
|
| 153 | + public function getShare($id) { |
|
| 154 | + $shareInfo = $this->externalManager->getShare($id); |
|
| 155 | + |
|
| 156 | + if ($shareInfo === false) { |
|
| 157 | + throw new OCSNotFoundException('share does not exist'); |
|
| 158 | + } else { |
|
| 159 | + $shareInfo = self::extendShareInfo($shareInfo); |
|
| 160 | + return new DataResponse($shareInfo); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @NoAdminRequired |
|
| 166 | + * |
|
| 167 | + * Unshare a remote share |
|
| 168 | + * |
|
| 169 | + * @param int $id |
|
| 170 | + * @return DataResponse |
|
| 171 | + * @throws OCSNotFoundException |
|
| 172 | + * @throws OCSForbiddenException |
|
| 173 | + */ |
|
| 174 | + public function unshare($id) { |
|
| 175 | + $shareInfo = $this->externalManager->getShare($id); |
|
| 176 | + |
|
| 177 | + if ($shareInfo === false) { |
|
| 178 | + throw new OCSNotFoundException('Share does not exist'); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
| 182 | + |
|
| 183 | + if ($this->externalManager->removeShare($mountPoint) === true) { |
|
| 184 | + return new DataResponse(); |
|
| 185 | + } else { |
|
| 186 | + throw new OCSForbiddenException('Could not unshare'); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | 189 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | return new DataResponse(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $this->logger->error('Could not accept federated share with id: ' . $id, |
|
| 87 | + $this->logger->error('Could not accept federated share with id: '.$id, |
|
| 88 | 88 | ['app' => 'files_sharing']); |
| 89 | 89 | |
| 90 | 90 | throw new OCSNotFoundException('wrong share ID, share doesn\'t exist.'); |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @return array enriched share info with data from the filecache |
| 116 | 116 | */ |
| 117 | 117 | private static function extendShareInfo($share) { |
| 118 | - $view = new \OC\Files\View('/' . \OC_User::getUser() . '/files/'); |
|
| 118 | + $view = new \OC\Files\View('/'.\OC_User::getUser().'/files/'); |
|
| 119 | 119 | $info = $view->getFileInfo($share['mountpoint']); |
| 120 | 120 | |
| 121 | 121 | $share['mimetype'] = $info->getMimetype(); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | throw new OCSNotFoundException('Share does not exist'); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - $mountPoint = '/' . \OC_User::getUser() . '/files' . $shareInfo['mountpoint']; |
|
| 181 | + $mountPoint = '/'.\OC_User::getUser().'/files'.$shareInfo['mountpoint']; |
|
| 182 | 182 | |
| 183 | 183 | if ($this->externalManager->removeShare($mountPoint) === true) { |
| 184 | 184 | return new DataResponse(); |
@@ -25,18 +25,18 @@ |
||
| 25 | 25 | use OCA\Testing\AlternativeHomeUserBackend; |
| 26 | 26 | |
| 27 | 27 | class Application extends App { |
| 28 | - public function __construct (array $urlParams = array()) { |
|
| 29 | - $appName = 'testing'; |
|
| 30 | - parent::__construct($appName, $urlParams); |
|
| 28 | + public function __construct (array $urlParams = array()) { |
|
| 29 | + $appName = 'testing'; |
|
| 30 | + parent::__construct($appName, $urlParams); |
|
| 31 | 31 | |
| 32 | - $c = $this->getContainer(); |
|
| 33 | - $config = $c->getServer()->getConfig(); |
|
| 34 | - if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') { |
|
| 35 | - $userManager = $c->getServer()->getUserManager(); |
|
| 32 | + $c = $this->getContainer(); |
|
| 33 | + $config = $c->getServer()->getConfig(); |
|
| 34 | + if ($config->getAppValue($appName, 'enable_alt_user_backend', 'no') === 'yes') { |
|
| 35 | + $userManager = $c->getServer()->getUserManager(); |
|
| 36 | 36 | |
| 37 | - // replace all user backends with this one |
|
| 38 | - $userManager->clearBackends(); |
|
| 39 | - $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class)); |
|
| 40 | - } |
|
| 41 | - } |
|
| 37 | + // replace all user backends with this one |
|
| 38 | + $userManager->clearBackends(); |
|
| 39 | + $userManager->registerBackend($c->query(AlternativeHomeUserBackend::class)); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | use OCA\Testing\AlternativeHomeUserBackend; |
| 26 | 26 | |
| 27 | 27 | class Application extends App { |
| 28 | - public function __construct (array $urlParams = array()) { |
|
| 28 | + public function __construct(array $urlParams = array()) { |
|
| 29 | 29 | $appName = 'testing'; |
| 30 | 30 | parent::__construct($appName, $urlParams); |
| 31 | 31 | |
@@ -29,39 +29,39 @@ |
||
| 29 | 29 | |
| 30 | 30 | class ConfigController extends OCSController { |
| 31 | 31 | |
| 32 | - /** @var IConfig */ |
|
| 33 | - private $config; |
|
| 32 | + /** @var IConfig */ |
|
| 33 | + private $config; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $appName |
|
| 37 | - * @param IRequest $request |
|
| 38 | - * @param IConfig $config |
|
| 39 | - */ |
|
| 40 | - public function __construct($appName, |
|
| 41 | - IRequest $request, |
|
| 42 | - IConfig $config) { |
|
| 43 | - parent::__construct($appName, $request); |
|
| 44 | - $this->config = $config; |
|
| 45 | - } |
|
| 35 | + /** |
|
| 36 | + * @param string $appName |
|
| 37 | + * @param IRequest $request |
|
| 38 | + * @param IConfig $config |
|
| 39 | + */ |
|
| 40 | + public function __construct($appName, |
|
| 41 | + IRequest $request, |
|
| 42 | + IConfig $config) { |
|
| 43 | + parent::__construct($appName, $request); |
|
| 44 | + $this->config = $config; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param string $appid |
|
| 49 | - * @param string $configkey |
|
| 50 | - * @param string $value |
|
| 51 | - * @return DataResponse |
|
| 52 | - */ |
|
| 53 | - public function setAppValue($appid, $configkey, $value) { |
|
| 54 | - $this->config->setAppValue($appid, $configkey, $value); |
|
| 55 | - return new DataResponse(); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * @param string $appid |
|
| 49 | + * @param string $configkey |
|
| 50 | + * @param string $value |
|
| 51 | + * @return DataResponse |
|
| 52 | + */ |
|
| 53 | + public function setAppValue($appid, $configkey, $value) { |
|
| 54 | + $this->config->setAppValue($appid, $configkey, $value); |
|
| 55 | + return new DataResponse(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param string $appid |
|
| 60 | - * @param string $configkey |
|
| 61 | - * @return DataResponse |
|
| 62 | - */ |
|
| 63 | - public function deleteAppValue($appid, $configkey) { |
|
| 64 | - $this->config->deleteAppValue($appid, $configkey); |
|
| 65 | - return new DataResponse(); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * @param string $appid |
|
| 60 | + * @param string $configkey |
|
| 61 | + * @return DataResponse |
|
| 62 | + */ |
|
| 63 | + public function deleteAppValue($appid, $configkey) { |
|
| 64 | + $this->config->deleteAppValue($appid, $configkey); |
|
| 65 | + return new DataResponse(); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -39,208 +39,208 @@ |
||
| 39 | 39 | |
| 40 | 40 | class LockingController extends OCSController { |
| 41 | 41 | |
| 42 | - /** @var ILockingProvider */ |
|
| 43 | - protected $lockingProvider; |
|
| 44 | - |
|
| 45 | - /** @var FakeDBLockingProvider */ |
|
| 46 | - protected $fakeDBLockingProvider; |
|
| 47 | - |
|
| 48 | - /** @var IDBConnection */ |
|
| 49 | - protected $connection; |
|
| 50 | - |
|
| 51 | - /** @var IConfig */ |
|
| 52 | - protected $config; |
|
| 53 | - |
|
| 54 | - /** @var IRootFolder */ |
|
| 55 | - protected $rootFolder; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $appName |
|
| 59 | - * @param IRequest $request |
|
| 60 | - * @param ILockingProvider $lockingProvider |
|
| 61 | - * @param FakeDBLockingProvider $fakeDBLockingProvider |
|
| 62 | - * @param IDBConnection $connection |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param IRootFolder $rootFolder |
|
| 65 | - */ |
|
| 66 | - public function __construct($appName, |
|
| 67 | - IRequest $request, |
|
| 68 | - ILockingProvider $lockingProvider, |
|
| 69 | - FakeDBLockingProvider $fakeDBLockingProvider, |
|
| 70 | - IDBConnection $connection, |
|
| 71 | - IConfig $config, |
|
| 72 | - IRootFolder $rootFolder) { |
|
| 73 | - parent::__construct($appName, $request); |
|
| 74 | - |
|
| 75 | - $this->lockingProvider = $lockingProvider; |
|
| 76 | - $this->fakeDBLockingProvider = $fakeDBLockingProvider; |
|
| 77 | - $this->connection = $connection; |
|
| 78 | - $this->config = $config; |
|
| 79 | - $this->rootFolder = $rootFolder; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @return ILockingProvider |
|
| 84 | - * @throws \RuntimeException |
|
| 85 | - */ |
|
| 86 | - protected function getLockingProvider() { |
|
| 87 | - if ($this->lockingProvider instanceof DBLockingProvider) { |
|
| 88 | - return $this->fakeDBLockingProvider; |
|
| 89 | - } |
|
| 90 | - throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param string $user |
|
| 95 | - * @param string $path |
|
| 96 | - * @return string |
|
| 97 | - * @throws NotFoundException |
|
| 98 | - */ |
|
| 99 | - protected function getPath($user, $path) { |
|
| 100 | - $node = $this->rootFolder->getUserFolder($user)->get($path); |
|
| 101 | - return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return DataResponse |
|
| 106 | - * @throws OCSException |
|
| 107 | - */ |
|
| 108 | - public function isLockingEnabled() { |
|
| 109 | - try { |
|
| 110 | - $this->getLockingProvider(); |
|
| 111 | - return new DataResponse(); |
|
| 112 | - } catch (\RuntimeException $e) { |
|
| 113 | - throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param int $type |
|
| 119 | - * @param string $user |
|
| 120 | - * @param string $path |
|
| 121 | - * @return DataResponse |
|
| 122 | - * @throws OCSException |
|
| 123 | - */ |
|
| 124 | - public function acquireLock($type, $user, $path) { |
|
| 125 | - try { |
|
| 126 | - $path = $this->getPath($user, $path); |
|
| 127 | - } catch (NoUserException $e) { |
|
| 128 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 129 | - } catch (NotFoundException $e) { |
|
| 130 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $lockingProvider = $this->getLockingProvider(); |
|
| 134 | - |
|
| 135 | - try { |
|
| 136 | - $lockingProvider->acquireLock($path, $type); |
|
| 137 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 138 | - return new DataResponse(); |
|
| 139 | - } catch (LockedException $e) { |
|
| 140 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param int $type |
|
| 146 | - * @param string $user |
|
| 147 | - * @param string $path |
|
| 148 | - * @return DataResponse |
|
| 149 | - * @throws OCSException |
|
| 150 | - */ |
|
| 151 | - public function changeLock($type, $user, $path) { |
|
| 152 | - try { |
|
| 153 | - $path = $this->getPath($user, $path); |
|
| 154 | - } catch (NoUserException $e) { |
|
| 155 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 156 | - } catch (NotFoundException $e) { |
|
| 157 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $lockingProvider = $this->getLockingProvider(); |
|
| 161 | - |
|
| 162 | - try { |
|
| 163 | - $lockingProvider->changeLock($path, $type); |
|
| 164 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 165 | - return new DataResponse(); |
|
| 166 | - } catch (LockedException $e) { |
|
| 167 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param int $type |
|
| 173 | - * @param string $user |
|
| 174 | - * @param string $path |
|
| 175 | - * @return DataResponse |
|
| 176 | - * @throws OCSException |
|
| 177 | - */ |
|
| 178 | - public function releaseLock($type, $user, $path) { |
|
| 179 | - try { |
|
| 180 | - $path = $this->getPath($user, $path); |
|
| 181 | - } catch (NoUserException $e) { |
|
| 182 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 183 | - } catch (NotFoundException $e) { |
|
| 184 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $lockingProvider = $this->getLockingProvider(); |
|
| 188 | - |
|
| 189 | - try { |
|
| 190 | - $lockingProvider->releaseLock($path, $type); |
|
| 191 | - $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
| 192 | - return new DataResponse(); |
|
| 193 | - } catch (LockedException $e) { |
|
| 194 | - throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @param int $type |
|
| 200 | - * @param string $user |
|
| 201 | - * @param string $path |
|
| 202 | - * @return DataResponse |
|
| 203 | - * @throws OCSException |
|
| 204 | - */ |
|
| 205 | - public function isLocked($type, $user, $path) { |
|
| 206 | - try { |
|
| 207 | - $path = $this->getPath($user, $path); |
|
| 208 | - } catch (NoUserException $e) { |
|
| 209 | - throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 210 | - } catch (NotFoundException $e) { |
|
| 211 | - throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $lockingProvider = $this->getLockingProvider(); |
|
| 215 | - |
|
| 216 | - if ($lockingProvider->isLocked($path, $type)) { |
|
| 217 | - return new DataResponse(); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - throw new OCSException('', Http::STATUS_LOCKED); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @param int $type |
|
| 225 | - * @return DataResponse |
|
| 226 | - */ |
|
| 227 | - public function releaseAll($type = null) { |
|
| 228 | - $lockingProvider = $this->getLockingProvider(); |
|
| 229 | - |
|
| 230 | - foreach ($this->config->getAppKeys('testing') as $lock) { |
|
| 231 | - if (strpos($lock, 'locking_') === 0) { |
|
| 232 | - $path = substr($lock, strlen('locking_')); |
|
| 233 | - |
|
| 234 | - if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
| 235 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 236 | - } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
| 237 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 238 | - } else { |
|
| 239 | - $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return new DataResponse(); |
|
| 245 | - } |
|
| 42 | + /** @var ILockingProvider */ |
|
| 43 | + protected $lockingProvider; |
|
| 44 | + |
|
| 45 | + /** @var FakeDBLockingProvider */ |
|
| 46 | + protected $fakeDBLockingProvider; |
|
| 47 | + |
|
| 48 | + /** @var IDBConnection */ |
|
| 49 | + protected $connection; |
|
| 50 | + |
|
| 51 | + /** @var IConfig */ |
|
| 52 | + protected $config; |
|
| 53 | + |
|
| 54 | + /** @var IRootFolder */ |
|
| 55 | + protected $rootFolder; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $appName |
|
| 59 | + * @param IRequest $request |
|
| 60 | + * @param ILockingProvider $lockingProvider |
|
| 61 | + * @param FakeDBLockingProvider $fakeDBLockingProvider |
|
| 62 | + * @param IDBConnection $connection |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param IRootFolder $rootFolder |
|
| 65 | + */ |
|
| 66 | + public function __construct($appName, |
|
| 67 | + IRequest $request, |
|
| 68 | + ILockingProvider $lockingProvider, |
|
| 69 | + FakeDBLockingProvider $fakeDBLockingProvider, |
|
| 70 | + IDBConnection $connection, |
|
| 71 | + IConfig $config, |
|
| 72 | + IRootFolder $rootFolder) { |
|
| 73 | + parent::__construct($appName, $request); |
|
| 74 | + |
|
| 75 | + $this->lockingProvider = $lockingProvider; |
|
| 76 | + $this->fakeDBLockingProvider = $fakeDBLockingProvider; |
|
| 77 | + $this->connection = $connection; |
|
| 78 | + $this->config = $config; |
|
| 79 | + $this->rootFolder = $rootFolder; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @return ILockingProvider |
|
| 84 | + * @throws \RuntimeException |
|
| 85 | + */ |
|
| 86 | + protected function getLockingProvider() { |
|
| 87 | + if ($this->lockingProvider instanceof DBLockingProvider) { |
|
| 88 | + return $this->fakeDBLockingProvider; |
|
| 89 | + } |
|
| 90 | + throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param string $user |
|
| 95 | + * @param string $path |
|
| 96 | + * @return string |
|
| 97 | + * @throws NotFoundException |
|
| 98 | + */ |
|
| 99 | + protected function getPath($user, $path) { |
|
| 100 | + $node = $this->rootFolder->getUserFolder($user)->get($path); |
|
| 101 | + return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return DataResponse |
|
| 106 | + * @throws OCSException |
|
| 107 | + */ |
|
| 108 | + public function isLockingEnabled() { |
|
| 109 | + try { |
|
| 110 | + $this->getLockingProvider(); |
|
| 111 | + return new DataResponse(); |
|
| 112 | + } catch (\RuntimeException $e) { |
|
| 113 | + throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param int $type |
|
| 119 | + * @param string $user |
|
| 120 | + * @param string $path |
|
| 121 | + * @return DataResponse |
|
| 122 | + * @throws OCSException |
|
| 123 | + */ |
|
| 124 | + public function acquireLock($type, $user, $path) { |
|
| 125 | + try { |
|
| 126 | + $path = $this->getPath($user, $path); |
|
| 127 | + } catch (NoUserException $e) { |
|
| 128 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 129 | + } catch (NotFoundException $e) { |
|
| 130 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $lockingProvider = $this->getLockingProvider(); |
|
| 134 | + |
|
| 135 | + try { |
|
| 136 | + $lockingProvider->acquireLock($path, $type); |
|
| 137 | + $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 138 | + return new DataResponse(); |
|
| 139 | + } catch (LockedException $e) { |
|
| 140 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param int $type |
|
| 146 | + * @param string $user |
|
| 147 | + * @param string $path |
|
| 148 | + * @return DataResponse |
|
| 149 | + * @throws OCSException |
|
| 150 | + */ |
|
| 151 | + public function changeLock($type, $user, $path) { |
|
| 152 | + try { |
|
| 153 | + $path = $this->getPath($user, $path); |
|
| 154 | + } catch (NoUserException $e) { |
|
| 155 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 156 | + } catch (NotFoundException $e) { |
|
| 157 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $lockingProvider = $this->getLockingProvider(); |
|
| 161 | + |
|
| 162 | + try { |
|
| 163 | + $lockingProvider->changeLock($path, $type); |
|
| 164 | + $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 165 | + return new DataResponse(); |
|
| 166 | + } catch (LockedException $e) { |
|
| 167 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param int $type |
|
| 173 | + * @param string $user |
|
| 174 | + * @param string $path |
|
| 175 | + * @return DataResponse |
|
| 176 | + * @throws OCSException |
|
| 177 | + */ |
|
| 178 | + public function releaseLock($type, $user, $path) { |
|
| 179 | + try { |
|
| 180 | + $path = $this->getPath($user, $path); |
|
| 181 | + } catch (NoUserException $e) { |
|
| 182 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 183 | + } catch (NotFoundException $e) { |
|
| 184 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $lockingProvider = $this->getLockingProvider(); |
|
| 188 | + |
|
| 189 | + try { |
|
| 190 | + $lockingProvider->releaseLock($path, $type); |
|
| 191 | + $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
| 192 | + return new DataResponse(); |
|
| 193 | + } catch (LockedException $e) { |
|
| 194 | + throw new OCSException('', Http::STATUS_LOCKED, $e); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param int $type |
|
| 200 | + * @param string $user |
|
| 201 | + * @param string $path |
|
| 202 | + * @return DataResponse |
|
| 203 | + * @throws OCSException |
|
| 204 | + */ |
|
| 205 | + public function isLocked($type, $user, $path) { |
|
| 206 | + try { |
|
| 207 | + $path = $this->getPath($user, $path); |
|
| 208 | + } catch (NoUserException $e) { |
|
| 209 | + throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e); |
|
| 210 | + } catch (NotFoundException $e) { |
|
| 211 | + throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $lockingProvider = $this->getLockingProvider(); |
|
| 215 | + |
|
| 216 | + if ($lockingProvider->isLocked($path, $type)) { |
|
| 217 | + return new DataResponse(); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + throw new OCSException('', Http::STATUS_LOCKED); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param int $type |
|
| 225 | + * @return DataResponse |
|
| 226 | + */ |
|
| 227 | + public function releaseAll($type = null) { |
|
| 228 | + $lockingProvider = $this->getLockingProvider(); |
|
| 229 | + |
|
| 230 | + foreach ($this->config->getAppKeys('testing') as $lock) { |
|
| 231 | + if (strpos($lock, 'locking_') === 0) { |
|
| 232 | + $path = substr($lock, strlen('locking_')); |
|
| 233 | + |
|
| 234 | + if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
| 235 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 236 | + } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
| 237 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 238 | + } else { |
|
| 239 | + $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return new DataResponse(); |
|
| 245 | + } |
|
| 246 | 246 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected function getPath($user, $path) { |
| 100 | 100 | $node = $this->rootFolder->getUserFolder($user)->get($path); |
| 101 | - return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/')); |
|
| 101 | + return 'files/'.md5($node->getStorage()->getId().'::'.trim($node->getInternalPath(), '/')); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | try { |
| 136 | 136 | $lockingProvider->acquireLock($path, $type); |
| 137 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 137 | + $this->config->setAppValue('testing', 'locking_'.$path, $type); |
|
| 138 | 138 | return new DataResponse(); |
| 139 | 139 | } catch (LockedException $e) { |
| 140 | 140 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | try { |
| 163 | 163 | $lockingProvider->changeLock($path, $type); |
| 164 | - $this->config->setAppValue('testing', 'locking_' . $path, $type); |
|
| 164 | + $this->config->setAppValue('testing', 'locking_'.$path, $type); |
|
| 165 | 165 | return new DataResponse(); |
| 166 | 166 | } catch (LockedException $e) { |
| 167 | 167 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | try { |
| 190 | 190 | $lockingProvider->releaseLock($path, $type); |
| 191 | - $this->config->deleteAppValue('testing', 'locking_' . $path); |
|
| 191 | + $this->config->deleteAppValue('testing', 'locking_'.$path); |
|
| 192 | 192 | return new DataResponse(); |
| 193 | 193 | } catch (LockedException $e) { |
| 194 | 194 | throw new OCSException('', Http::STATUS_LOCKED, $e); |
@@ -231,9 +231,9 @@ discard block |
||
| 231 | 231 | if (strpos($lock, 'locking_') === 0) { |
| 232 | 232 | $path = substr($lock, strlen('locking_')); |
| 233 | 233 | |
| 234 | - if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
| 234 | + if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) { |
|
| 235 | 235 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
| 236 | - } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
| 236 | + } else if ($type === ILockingProvider::LOCK_SHARED && (int) $this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) { |
|
| 237 | 237 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |
| 238 | 238 | } else { |
| 239 | 239 | $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock)); |