diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php | 4 | ||||
-rw-r--r-- | lib/private/Files/ObjectStore/S3ConnectionTrait.php | 3 | ||||
-rw-r--r-- | lib/private/Repair.php | 2 | ||||
-rw-r--r-- | lib/private/Repair/RepairMimeTypes.php | 94 | ||||
-rw-r--r-- | lib/private/User/Session.php | 6 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 6 | ||||
-rw-r--r-- | lib/private/legacy/OC_DB.php | 2 |
7 files changed, 57 insertions, 60 deletions
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php index 2aa007dba04..e8e436ba5bd 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php @@ -170,6 +170,10 @@ class OCIExpressionBuilder extends ExpressionBuilder { $column = $this->helper->quoteColumnName($column); return new QueryFunction('to_char(' . $column . ')'); } + if ($type === IQueryBuilder::PARAM_INT) { + $column = $this->helper->quoteColumnName($column); + return new QueryFunction('to_number(to_char(' . $column . '))'); + } return parent::castColumn($column, $type); } diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index 467ae81c8a4..c98c8a04cdf 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -76,6 +76,7 @@ trait S3ConnectionTrait { if (!isset($params['port']) || $params['port'] === '') { $params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443; } + $params['verify_bucket_exists'] = empty($params['verify_bucket_exists']) ? true : $params['verify_bucket_exists']; $this->params = $params; } @@ -130,7 +131,7 @@ trait S3ConnectionTrait { ['app' => 'objectstore']); } - if (!$this->connection->doesBucketExist($this->bucket)) { + if ($this->params['verify_bucket_exists'] && !$this->connection->doesBucketExist($this->bucket)) { $logger = \OC::$server->getLogger(); try { $logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']); diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 2b9b14b58b6..ec748355567 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -146,7 +146,7 @@ class Repair implements IOutput { public static function getRepairSteps() { return [ new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), - new RepairMimeTypes(\OC::$server->getConfig()), + new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new MoveUpdaterStepFile(\OC::$server->getConfig()), diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php index 60a7df25f63..c5157f81612 100644 --- a/lib/private/Repair/RepairMimeTypes.php +++ b/lib/private/Repair/RepairMimeTypes.php @@ -33,84 +33,74 @@ namespace OC\Repair; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; class RepairMimeTypes implements IRepairStep { - /** - * @var \OCP\IConfig - */ + /** @var IConfig */ protected $config; + /** @var IDBConnection */ + protected $connection; - /** - * @var int - */ + /** @var int */ protected $folderMimeTypeId; - /** - * @param \OCP\IConfig $config - */ - public function __construct($config) { + public function __construct(IConfig $config, + IDBConnection $connection) { $this->config = $config; + $this->connection = $connection; } public function getName() { return 'Repair mime types'; } - private static function existsStmt() { - return \OC_DB::prepare(' - SELECT count(`mimetype`) - FROM `*PREFIX*mimetypes` - WHERE `mimetype` = ? - '); - } - - private static function getIdStmt() { - return \OC_DB::prepare(' - SELECT `id` - FROM `*PREFIX*mimetypes` - WHERE `mimetype` = ? - '); - } - - private static function insertStmt() { - return \OC_DB::prepare(' - INSERT INTO `*PREFIX*mimetypes` ( `mimetype` ) - VALUES ( ? ) - '); - } - - private static function updateByNameStmt() { - return \OC_DB::prepare(' - UPDATE `*PREFIX*filecache` - SET `mimetype` = ? - WHERE `mimetype` <> ? AND `mimetype` <> ? AND `name` ILIKE ? - '); - } - private function updateMimetypes($updatedMimetypes) { + $query = $this->connection->getQueryBuilder(); + $query->select('id') + ->from('mimetypes') + ->where($query->expr()->eq('mimetype', $query->createParameter('mimetype'), IQueryBuilder::PARAM_INT)); + $insert = $this->connection->getQueryBuilder(); + $insert->insert('mimetypes') + ->setValue('mimetype', $insert->createParameter('mimetype')); + if (empty($this->folderMimeTypeId)) { - $result = \OC_DB::executeAudited(self::getIdStmt(), ['httpd/unix-directory']); - $this->folderMimeTypeId = (int)$result->fetchOne(); + $query->setParameter('mimetype', 'httpd/unix-directory'); + $result = $query->execute(); + $this->folderMimeTypeId = (int)$result->fetchColumn(); + $result->closeCursor(); } + $update = $this->connection->getQueryBuilder(); + $update->update('filecache') + ->set('mimetype', $update->createParameter('mimetype')) + ->where($update->expr()->neq('mimetype', $update->createParameter('mimetype'), IQueryBuilder::PARAM_INT)) + ->andWhere($update->expr()->neq('mimetype', $update->createParameter('folder'), IQueryBuilder::PARAM_INT)) + ->andWhere($update->expr()->iLike('name', $update->createParameter('name'))) + ->setParameter('folder', $this->folderMimeTypeId); + $count = 0; foreach ($updatedMimetypes as $extension => $mimetype) { - $result = \OC_DB::executeAudited(self::existsStmt(), [$mimetype]); - $exists = $result->fetchOne(); + // get target mimetype id + $query->setParameter('mimetype', $mimetype); + $result = $query->execute(); + $mimetypeId = (int)$result->fetchColumn(); + $result->closeCursor(); - if (!$exists) { + if (!$mimetypeId) { // insert mimetype - \OC_DB::executeAudited(self::insertStmt(), [$mimetype]); + $insert->setParameter('mimetype', $mimetype); + $insert->execute(); + $mimetypeId = $insert->getLastInsertId(); } - // get target mimetype id - $result = \OC_DB::executeAudited(self::getIdStmt(), [$mimetype]); - $mimetypeId = $result->fetchOne(); - // change mimetype for files with x extension - $count += \OC_DB::executeAudited(self::updateByNameStmt(), [$mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension]); + $update->setParameter('mimetype', $mimetypeId) + ->setParameter('name', '%' . $this->connection->escapeLikeParameter('.' . $extension)); + $count += $update->execute(); } return $count; diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 1f2eaadc12e..37d518b6123 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -814,15 +814,15 @@ class Session implements IUserSession, Emitter { */ public function tryTokenLogin(IRequest $request) { $authHeader = $request->getHeader('Authorization'); - if (strpos($authHeader, 'Bearer ') === false) { + if (strpos($authHeader, 'Bearer ') === 0) { + $token = substr($authHeader, 7); + } else { // No auth header, let's try session id try { $token = $this->session->getId(); } catch (SessionNotAvailableException $ex) { return false; } - } else { - $token = substr($authHeader, 7); } if (!$this->loginWithToken($token)) { diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index d2f8e536005..941cd25397d 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -94,7 +94,7 @@ class OC_App { * @return bool */ public static function isAppLoaded(string $app): bool { - return in_array($app, self::$loadedApps, true); + return isset(self::$loadedApps[$app]); } /** @@ -127,7 +127,7 @@ class OC_App { // prevent app.php from printing output ob_start(); foreach ($apps as $app) { - if (($types === [] or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { + if (!isset(self::$loadedApps[$app]) && ($types === [] || self::isType($app, $types))) { self::loadApp($app); } } @@ -143,7 +143,7 @@ class OC_App { * @throws Exception */ public static function loadApp(string $app) { - self::$loadedApps[] = $app; + self::$loadedApps[$app] = true; $appPath = self::getAppPath($app); if ($appPath === false) { return; diff --git a/lib/private/legacy/OC_DB.php b/lib/private/legacy/OC_DB.php index 4f2c78ed5b4..ee769a46deb 100644 --- a/lib/private/legacy/OC_DB.php +++ b/lib/private/legacy/OC_DB.php @@ -55,6 +55,7 @@ class OC_DB { * @param bool|null $isManipulation * @throws \OC\DatabaseException * @return OC_DB_StatementWrapper prepared SQL query + * @depreacted 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead * * SQL query via Doctrine prepare(), needs to be execute()'d! */ @@ -115,6 +116,7 @@ class OC_DB { * @param array $parameters * @return OC_DB_StatementWrapper * @throws \OC\DatabaseException + * @depreacted 21.0.0 Please use \OCP\IDBConnection::getQueryBuilder() instead */ public static function executeAudited($stmt, array $parameters = []) { if (is_string($stmt)) { |