summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Repair.php2
-rw-r--r--lib/private/Repair/RepairMimeTypes.php94
-rw-r--r--lib/private/legacy/OC_App.php6
-rw-r--r--lib/private/legacy/OC_DB.php17
4 files changed, 57 insertions, 62 deletions
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/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)) {