Use the querybuilder for the queries

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2019-04-16 11:44:23 +02:00 committed by Roeland Jago Douma
parent e0a825658d
commit 6286923022
No known key found for this signature in database
GPG key ID: F941078878347C0C

View file

@ -26,6 +26,7 @@ namespace OC\Repair;
use Doctrine\DBAL\Driver\Statement;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
@ -98,27 +99,35 @@ class RemoveLinkShares implements IRepairStep {
* @return int
*/
private function getTotal(): int {
$sql = 'SELECT COUNT(*) AS `total`
FROM `*PREFIX*share`
WHERE `id` IN (
SELECT `s1`.`id`
FROM (
SELECT *
FROM `*PREFIX*share`
WHERE `parent` IS NOT NULL
AND `share_type` = 3
) AS s1
JOIN `*PREFIX*share` AS s2
ON `s1`.`parent` = `s2`.`id`
WHERE (`s2`.`share_type` = 1 OR `s2`.`share_type` = 2)
AND `s1`.`item_source` = `s2`.`item_source`
)';
$cursor = $this->connection->executeQuery($sql);
$data = $cursor->fetchAll();
$total = (int)$data[0]['total'];
$cursor->closeCursor();
$subSubQuery = $this->connection->getQueryBuilder();
$subSubQuery->select('*')
->from('share')
->where($subSubQuery->expr()->isNotNull('parent'))
->andWhere($subSubQuery->expr()->eq('share_type', $subSubQuery->expr()->literal(3, IQueryBuilder::PARAM_INT)));
return $total;
$subQuery = $this->connection->getQueryBuilder();
$subQuery->select('s1.id')
->from($subQuery->createFunction('(' . $subSubQuery->getSQL() . ')'), 's1')
->join(
's1', 'share', 's2',
$subQuery->expr()->eq('s1.parent', 's2.id')
)
->where($subQuery->expr()->orX(
$subQuery->expr()->eq('s2.share_type', $subQuery->expr()->literal(1, IQueryBuilder::PARAM_INT)),
$subQuery->expr()->eq('s2.share_type', $subQuery->expr()->literal(2, IQueryBuilder::PARAM_INT))
))
->andWhere($subQuery->expr()->eq('s1.item_source', 's2.item_source'));
$query = $this->connection->getQueryBuilder();
$query->select($query->func()->count('*', 'total'))
->from('share')
->where($query->expr()->in('id', $query->createFunction('(' . $subQuery->getSQL() . ')')));
$result = $query->execute();
$data = $result->fetch();
$result->closeCursor();
return (int) $data['total'];
}
/**
@ -127,19 +136,25 @@ class RemoveLinkShares implements IRepairStep {
* @return \Doctrine\DBAL\Driver\Statement
*/
private function getShares(): Statement {
$sql = 'SELECT `s1`.`id`, `s1`.`uid_owner`, `s1`.`uid_initiator`
FROM (
SELECT *
FROM `*PREFIX*share`
WHERE `parent` IS NOT NULL
AND `share_type` = 3
) AS s1
JOIN `*PREFIX*share` AS s2
ON `s1`.`parent` = `s2`.`id`
WHERE (`s2`.`share_type` = 1 OR `s2`.`share_type` = 2)
AND `s1`.`item_source` = `s2`.`item_source`';
$cursor = $this->connection->executeQuery($sql);
return $cursor;
$subQuery = $this->connection->getQueryBuilder();
$subQuery->select('*')
->from('share')
->where($subQuery->expr()->isNotNull('parent'))
->andWhere($subQuery->expr()->eq('share_type', $subQuery->expr()->literal(3, IQueryBuilder::PARAM_INT)));
$query = $this->connection->getQueryBuilder();
$query->select('s1.id', 's1.uid_owner', 's1.uid_initiator')
->from($query->createFunction('(' . $subQuery->getSQL() . ')'), 's1')
->join(
's1', 'share', 's2',
$query->expr()->eq('s1.parent', 's2.id')
)
->where($query->expr()->orX(
$query->expr()->eq('s2.share_type', $query->expr()->literal(1, IQueryBuilder::PARAM_INT)),
$query->expr()->eq('s2.share_type', $query->expr()->literal(2, IQueryBuilder::PARAM_INT))
))
->andWhere($query->expr()->eq('s1.item_source', 's2.item_source'));
return $query->execute();
}
/**