aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php1
-rw-r--r--lib/private/AppFramework/Http/Output.php20
-rw-r--r--lib/private/Config.php10
-rw-r--r--lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php8
-rw-r--r--lib/private/Files/ObjectStore/S3ConnectionTrait.php3
-rw-r--r--lib/private/Repair.php2
-rw-r--r--lib/private/Repair/RepairMimeTypes.php94
-rw-r--r--lib/private/Session/CryptoWrapper.php28
-rw-r--r--lib/private/Session/Internal.php6
-rw-r--r--lib/private/Share/Helper.php54
-rw-r--r--lib/private/Share/Share.php14
-rw-r--r--lib/private/legacy/OC_App.php6
-rw-r--r--lib/private/legacy/OC_DB.php17
13 files changed, 131 insertions, 132 deletions
diff --git a/lib/base.php b/lib/base.php
index 0213fa9e9ef..9c914f15431 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -1006,7 +1006,6 @@ class OC {
OC_App::loadApps(['filesystem', 'logging']);
OC_App::loadApps();
}
- OC_Util::setupFS();
OC::$server->getRouter()->match(\OC::$server->getRequest()->getRawPathInfo());
return;
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
diff --git a/lib/private/AppFramework/Http/Output.php b/lib/private/AppFramework/Http/Output.php
index 45d8d9b8c66..9f26d94b8aa 100644
--- a/lib/private/AppFramework/Http/Output.php
+++ b/lib/private/AppFramework/Http/Output.php
@@ -96,17 +96,13 @@ class Output implements IOutput {
public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite = 'Lax') {
$path = $this->webRoot ? : '/';
- if (PHP_VERSION_ID < 70300) {
- setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
- } else {
- setcookie($name, $value, [
- 'expires' => $expire,
- 'path' => $path,
- 'domain' => $domain,
- 'secure' => $secure,
- 'httponly' => $httpOnly,
- 'samesite' => $sameSite
- ]);
- }
+ setcookie($name, $value, [
+ 'expires' => $expire,
+ 'path' => $path,
+ 'domain' => $domain,
+ 'secure' => $secure,
+ 'httponly' => $httpOnly,
+ 'samesite' => $sameSite
+ ]);
}
}
diff --git a/lib/private/Config.php b/lib/private/Config.php
index cbdbc5b2e64..0a868be7832 100644
--- a/lib/private/Config.php
+++ b/lib/private/Config.php
@@ -47,6 +47,8 @@ class Config {
/** @var array Associative array ($key => $value) */
protected $cache = [];
+ /** @var array */
+ protected $envCache = [];
/** @var string */
protected $configDir;
/** @var string */
@@ -88,9 +90,9 @@ class Config {
* @return mixed the value or $default
*/
public function getValue($key, $default = null) {
- $envValue = getenv(self::ENV_PREFIX . $key);
- if ($envValue !== false) {
- return $envValue;
+ $envKey = self::ENV_PREFIX . $key;
+ if (isset($this->envCache[$envKey])) {
+ return $this->envCache[$envKey];
}
if (isset($this->cache[$key])) {
@@ -222,6 +224,8 @@ class Config {
flock($filePointer, LOCK_UN);
fclose($filePointer);
}
+
+ $this->envCache = getenv();
}
/**
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php
index 2aa007dba04..f41242fdc60 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);
}
@@ -185,8 +189,6 @@ class OCIExpressionBuilder extends ExpressionBuilder {
* @inheritdoc
*/
public function iLike($x, $y, $type = null) {
- $x = $this->helper->quoteColumnName($x);
- $y = $this->helper->quoteColumnName($y);
- return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')');
+ return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y));
}
}
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/Session/CryptoWrapper.php b/lib/private/Session/CryptoWrapper.php
index f7f26bb10d2..0f791a865d8 100644
--- a/lib/private/Session/CryptoWrapper.php
+++ b/lib/private/Session/CryptoWrapper.php
@@ -88,22 +88,18 @@ class CryptoWrapper {
$webRoot = '/';
}
- if (PHP_VERSION_ID < 70300) {
- setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true);
- } else {
- setcookie(
- self::COOKIE_NAME,
- $this->passphrase,
- [
- 'expires' => 0,
- 'path' => $webRoot,
- 'domain' => '',
- 'secure' => $secureCookie,
- 'httponly' => true,
- 'samesite' => 'Lax',
- ]
- );
- }
+ setcookie(
+ self::COOKIE_NAME,
+ $this->passphrase,
+ [
+ 'expires' => 0,
+ 'path' => $webRoot,
+ 'domain' => '',
+ 'secure' => $secureCookie,
+ 'httponly' => true,
+ 'samesite' => 'Lax',
+ ]
+ );
}
}
}
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php
index f08f4da52a7..b7e1c7b7bf8 100644
--- a/lib/private/Session/Internal.php
+++ b/lib/private/Session/Internal.php
@@ -214,10 +214,6 @@ class Internal extends Session {
}
private function startSession(bool $silence = false) {
- if (PHP_VERSION_ID < 70300) {
- $this->invoke('session_start', [], $silence);
- } else {
- $this->invoke('session_start', [['cookie_samesite' => 'Lax']], $silence);
- }
+ $this->invoke('session_start', [['cookie_samesite' => 'Lax']], $silence);
}
}
diff --git a/lib/private/Share/Helper.php b/lib/private/Share/Helper.php
index 90dc3e957e9..a992330b577 100644
--- a/lib/private/Share/Helper.php
+++ b/lib/private/Share/Helper.php
@@ -31,6 +31,7 @@
namespace OC\Share;
use OC\HintException;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Share\IShare;
class Helper extends \OC\Share\Constants {
@@ -89,31 +90,30 @@ class Helper extends \OC\Share\Constants {
$changeParent = [];
$parents = [$parent];
while (!empty($parents)) {
- $parents = "'".implode("','", $parents)."'";
- // Check the owner on the first search of reshares, useful for
- // finding and deleting the reshares by a single user of a group share
- $params = [];
- if (count($ids) == 1 && isset($uidOwner)) {
- // FIXME: don't concat $parents, use Docrine's PARAM_INT_ARRAY approach
- $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' .
- '`item_target`, `file_target`, `parent` ' .
- 'FROM `*PREFIX*share` ' .
- 'WHERE `parent` IN ('.$parents.') AND `uid_owner` = ? ';
- $params[] = $uidOwner;
- } else {
- $queryString = 'SELECT `id`, `share_with`, `item_type`, `share_type`, ' .
- '`item_target`, `file_target`, `parent`, `uid_owner` ' .
- 'FROM `*PREFIX*share` WHERE `parent` IN ('.$parents.') ';
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->select(
+ 'id', 'share_with', 'item_type', 'share_type',
+ 'item_target', 'file_target', 'parent'
+ )
+ ->from('share')
+ ->where($query->expr()->in('parent', $query->createNamedParameter(
+ $parents, IQueryBuilder::PARAM_INT_ARRAY
+ )));
+
+ if (count($ids) === 1 && isset($uidOwner)) {
+ // Check the owner on the first search of reshares, useful for
+ // finding and deleting the reshares by a single user of a group share
+ $query->andWhere($query->expr()->eq('uid_owner', $uidOwner));
}
+
if ($excludeGroupChildren) {
- $queryString .= ' AND `share_type` != ?';
- $params[] = self::$shareTypeGroupUserUnique;
+ $query->andWhere($query->expr()->eq('share_type', self::$shareTypeGroupUserUnique));
}
- $query = \OC_DB::prepare($queryString);
- $result = $query->execute($params);
+
+ $result = $query->execute();
// Reset parents array, only go through loop again if items are found
$parents = [];
- while ($item = $result->fetchRow()) {
+ while ($item = $result->fetch()) {
$tmpItem = [
'id' => $item['id'],
'shareWith' => $item['share_with'],
@@ -135,20 +135,24 @@ class Helper extends \OC\Share\Constants {
$parents[] = $item['id'];
}
}
+ $result->closeCursor();
}
if ($excludeParent) {
unset($ids[0]);
}
if (!empty($changeParent)) {
- $idList = "'".implode("','", $changeParent)."'";
- $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `parent` = ? WHERE `id` IN ('.$idList.')');
- $query->execute([$newParent]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->update('share')
+ ->set('parent', $query->createNamedParameter($newParent, IQueryBuilder::PARAM_INT))
+ ->where($query->expr()->in('id', $query->createNamedParameter($changeParent, IQueryBuilder::PARAM_INT_ARRAY)));
+ $query->execute();
}
if (!empty($ids)) {
- $idList = "'".implode("','", $ids)."'";
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` IN ('.$idList.')');
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('share')
+ ->where($query->expr()->in('id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)));
$query->execute();
}
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index 0648e40f162..32801fe4c08 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -687,14 +687,20 @@ class Share extends Constants {
// Remove root from file source paths if retrieving own shared items
if (isset($uidOwner) && isset($row['path'])) {
if (isset($row['parent'])) {
- $query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?');
- $parentResult = $query->execute([$row['parent']]);
- if ($result === false) {
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->select('file_target')
+ ->from('share')
+ ->where($query->expr()->eq('id', $query->createNamedParameter($row['parent'])));
+
+ $result = $query->execute();
+ $parentRow = $result->fetch();
+ $result->closeCursor();
+
+ if ($parentRow === false) {
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where,
ILogger::ERROR);
} else {
- $parentRow = $parentResult->fetchRow();
$tmpPath = $parentRow['file_target'];
// find the right position where the row path continues from the target path
$pos = strrpos($row['path'], $parentRow['file_target']);
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 50dab74abb9..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!
*/
@@ -73,8 +74,7 @@ class OC_DB {
throw new \OC\DatabaseException($e->getMessage());
}
// differentiate between query and manipulation
- $result = new OC_DB_StatementWrapper($result, $isManipulation);
- return $result;
+ return new OC_DB_StatementWrapper($result, $isManipulation);
}
/**
@@ -85,22 +85,26 @@ class OC_DB {
* @return bool
*/
public static function isManipulation($sql) {
+ $sql = trim($sql);
$selectOccurrence = stripos($sql, 'SELECT');
- if ($selectOccurrence !== false && $selectOccurrence < 10) {
+ if ($selectOccurrence === 0) {
return false;
}
$insertOccurrence = stripos($sql, 'INSERT');
- if ($insertOccurrence !== false && $insertOccurrence < 10) {
+ if ($insertOccurrence === 0) {
return true;
}
$updateOccurrence = stripos($sql, 'UPDATE');
- if ($updateOccurrence !== false && $updateOccurrence < 10) {
+ if ($updateOccurrence === 0) {
return true;
}
$deleteOccurrence = stripos($sql, 'DELETE');
- if ($deleteOccurrence !== false && $deleteOccurrence < 10) {
+ if ($deleteOccurrence === 0) {
return true;
}
+
+ \OC::$server->getLogger()->logException(new \Exception('Can not detect if query is manipulating: ' . $sql));
+
return false;
}
@@ -112,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)) {