first migration to ExtendedQueryBuilder

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/730/head
Maxence Lange 2019-09-15 09:00:34 -01:00
rodzic 9920fb13fe
commit 445b52b049
5 zmienionych plików z 1407 dodań i 1431 usunięć

71
composer.lock wygenerowano
Wyświetl plik

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "f5575fb747924736058725f236d7fdae",
"content-hash": "f93a783c86bad53b0b8486db3fc61380",
"packages": [
{
"name": "daita/my-small-php-tools",
@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/daita/my-small-php-tools.git",
"reference": "bea3a148a427d446511c23b1512686fa03835754"
"reference": "ffc91a81c84ec679379b4b8a0a34434f3697c6e7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/bea3a148a427d446511c23b1512686fa03835754",
"reference": "bea3a148a427d446511c23b1512686fa03835754",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/ffc91a81c84ec679379b4b8a0a34434f3697c6e7",
"reference": "ffc91a81c84ec679379b4b8a0a34434f3697c6e7",
"shasum": ""
},
"require": {
@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
"time": "2019-08-20T20:23:09+00:00"
"time": "2019-09-15T08:55:12+00:00"
},
{
"name": "friendica/json-ld",
@ -448,26 +448,26 @@
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "4.3.1",
"version": "4.3.2",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c"
"reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c",
"reference": "bdd9f737ebc2a01c06ea7ff4308ec6697db9b53c",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e",
"reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e",
"shasum": ""
},
"require": {
"php": "^7.0",
"phpdocumentor/reflection-common": "^1.0.0",
"phpdocumentor/type-resolver": "^0.4.0",
"phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0",
"phpdocumentor/type-resolver": "~0.4 || ^1.0.0",
"webmozart/assert": "^1.0"
},
"require-dev": {
"doctrine/instantiator": "~1.0.5",
"doctrine/instantiator": "^1.0.5",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4"
},
@ -495,29 +495,29 @@
}
],
"description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
"time": "2019-04-30T17:48:53+00:00"
"time": "2019-09-12T14:27:41+00:00"
},
{
"name": "phpdocumentor/type-resolver",
"version": "0.4.0",
"version": "0.5.1",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/TypeResolver.git",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7"
"reference": "cf842904952e64e703800d094cdf34e715a8a3ae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7",
"reference": "9c977708995954784726e25d0cd1dddf4e65b0f7",
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/cf842904952e64e703800d094cdf34e715a8a3ae",
"reference": "cf842904952e64e703800d094cdf34e715a8a3ae",
"shasum": ""
},
"require": {
"php": "^5.5 || ^7.0",
"php": "^7.0",
"phpdocumentor/reflection-common": "^1.0"
},
"require-dev": {
"mockery/mockery": "^0.9.4",
"phpunit/phpunit": "^5.2||^4.8.24"
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.4"
},
"type": "library",
"extra": {
@ -527,9 +527,7 @@
},
"autoload": {
"psr-4": {
"phpDocumentor\\Reflection\\": [
"src/"
]
"phpDocumentor\\Reflection\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -542,7 +540,7 @@
"email": "me@mikevanriel.com"
}
],
"time": "2017-07-14T14:27:02+00:00"
"time": "2017-12-30T13:23:38+00:00"
},
{
"name": "phpspec/prophecy",
@ -1213,16 +1211,16 @@
},
{
"name": "sebastian/exporter",
"version": "3.1.1",
"version": "3.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "06a9a5947f47b3029d76118eb5c22802e5869687"
"reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/06a9a5947f47b3029d76118eb5c22802e5869687",
"reference": "06a9a5947f47b3029d76118eb5c22802e5869687",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e",
"reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e",
"shasum": ""
},
"require": {
@ -1276,7 +1274,7 @@
"export",
"exporter"
],
"time": "2019-08-11T12:43:14+00:00"
"time": "2019-09-14T09:02:43+00:00"
},
{
"name": "sebastian/global-state",
@ -1659,16 +1657,16 @@
},
{
"name": "webmozart/assert",
"version": "1.4.0",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/webmozart/assert.git",
"reference": "83e253c8e0be5b0257b881e1827274667c5c17a9"
"reference": "88e6d84706d09a236046d686bbea96f07b3a34f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9",
"reference": "83e253c8e0be5b0257b881e1827274667c5c17a9",
"url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4",
"reference": "88e6d84706d09a236046d686bbea96f07b3a34f4",
"shasum": ""
},
"require": {
@ -1676,8 +1674,7 @@
"symfony/polyfill-ctype": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "^4.6",
"sebastian/version": "^1.0.1"
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
},
"type": "library",
"extra": {
@ -1706,7 +1703,7 @@
"check",
"validate"
],
"time": "2018-12-25T11:19:39+00:00"
"time": "2019-08-24T08:43:50+00:00"
}
],
"aliases": [],

Wyświetl plik

@ -31,7 +31,6 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use daita\MySmallPhpTools\IQueryRow;
use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
@ -41,7 +40,6 @@ use OC\DB\SchemaWrapper;
use OCA\Social\AP;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RowNotFoundException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Follow;
@ -104,7 +102,6 @@ class CoreRequestBuilder {
protected $miscService;
/** @var Person */
protected $viewer = null;
@ -144,6 +141,14 @@ class CoreRequestBuilder {
}
/**
* @return IDBConnection
*/
public function getConnection(): IDBConnection {
return $this->dbConnection;
}
/**
* @param Person $viewer
*/
@ -291,7 +296,7 @@ class CoreRequestBuilder {
* @param string $username
*/
protected function searchInPreferredUsername(IQueryBuilder &$qb, string $username) {
$dbConn = $this->dbConnection;
$dbConn = $this->getConnection();
$this->searchInDBField(
$qb, 'preferred_username', $dbConn->escapeLikeParameter($username) . '%'
);
@ -348,7 +353,7 @@ class CoreRequestBuilder {
* @param bool $all
*/
protected function searchInHashtag(IQueryBuilder &$qb, string $hashtag, bool $all = false) {
$dbConn = $this->dbConnection;
$dbConn = $this->getConnection();
$this->searchInDBField(
$qb, 'hashtag', (($all) ? '%' : '') . $dbConn->escapeLikeParameter($hashtag) . '%'
);
@ -419,7 +424,7 @@ class CoreRequestBuilder {
* @param string $account
*/
protected function searchInAccount(IQueryBuilder &$qb, string $account) {
$dbConn = $this->dbConnection;
$dbConn = $this->getConnection();
$this->searchInDBField($qb, 'account', $dbConn->escapeLikeParameter($account) . '%');
}
@ -1206,46 +1211,6 @@ class CoreRequestBuilder {
}
/**
* @param IQueryBuilder $qb
* @param callable $method
*
* @return IQueryRow
* @throws RowNotFoundException
*/
public function getRow(IQueryBuilder $qb, callable $method): IQueryRow {
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
if ($data === false) {
throw new RowNotFoundException();
}
return $method($data);
}
/**
* @param IQueryBuilder $qb
* @param callable $method
*
* @return IQueryRow[]
*/
public function getRows(IQueryBuilder $qb, callable $method): array {
$rows = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
try {
$rows[] = $method($data);
} catch (Exception $e) {
}
}
$cursor->closeCursor();
return $rows;
}
/**
* @param Person $actor
* @param array $data

Wyświetl plik

@ -31,12 +31,12 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Exceptions\CacheItemNotFoundException;
use daita\MySmallPhpTools\Exceptions\RowNotFoundException;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Doctrine\DBAL\Query\QueryBuilder;
use OCA\Social\AP;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RowNotFoundException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
@ -62,11 +62,11 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Insert request
*
* @return IQueryBuilder
* @return SocialQueryBuilder
*/
protected function getStreamInsertSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert(self::TABLE_STREAM);
protected function getStreamInsertSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->insert(self::TABLE_STREAMS);
return $qb;
}
@ -75,11 +75,11 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Update request
*
* @return IQueryBuilder
* @return SocialQueryBuilder
*/
protected function getStreamUpdateSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->update(self::TABLE_STREAM);
protected function getStreamUpdateSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->update(self::TABLE_STREAMS);
return $qb;
}
@ -88,10 +88,10 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Select request for Shares
*
* @return IQueryBuilder
* @return SocialQueryBuilder
*/
protected function getStreamSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function getStreamSelectSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->selectDistinct('s.id')
@ -112,10 +112,10 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Select request for Shares
*
* @return IQueryBuilder
* @return SocialQueryBuilder
*/
protected function countNotesSelectSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
protected function countNotesSelectSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->selectAlias($qb->createFunction('COUNT(*)'), 'count')
->from(self::TABLE_STREAM, 's');
@ -128,11 +128,11 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* Base of the Sql Delete request
*
* @return IQueryBuilder
* @return SocialQueryBuilder
*/
protected function getStreamDeleteSql(): IQueryBuilder {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::TABLE_STREAM);
protected function getStreamDeleteSql(): SocialQueryBuilder {
$qb = $this->getQueryBuilder();
$qb->delete(self::TABLE_STREAMS);
return $qb;
}
@ -323,9 +323,8 @@ class StreamRequestBuilder extends CoreRequestBuilder {
*
* @return string
*/
protected function exprValueWithinJsonFormat(IQueryBuilder $qb, string $field, string $value
): string {
$dbConn = $this->dbConnection;
protected function exprValueWithinJsonFormat(IQueryBuilder $qb, string $field, string $value): string {
$dbConn = $this->getConnection();
$expr = $qb->expr();
return $expr->iLike(
@ -342,9 +341,8 @@ class StreamRequestBuilder extends CoreRequestBuilder {
*
* @return string
*/
protected function exprValueNotWithinJsonFormat(IQueryBuilder $qb, string $field, string $value
): string {
$dbConn = $this->dbConnection;
protected function exprValueNotWithinJsonFormat(IQueryBuilder $qb, string $field, string $value): string {
$dbConn = $this->getConnection();
$expr = $qb->expr();
$func = $qb->func();
@ -450,15 +448,15 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
* @param SocialQueryBuilder $qb
*
* @return Stream
* @throws StreamNotFoundException
*/
protected function getStreamFromRequest(IQueryBuilder $qb): Stream {
protected function getStreamFromRequest(SocialQueryBuilder $qb): Stream {
/** @var Stream $result */
try {
$result = $this->getRow($qb, [$this, 'parseStreamSelectSql']);
$result = $qb->getRow([$this, 'parseStreamSelectSql']);
} catch (RowNotFoundException $e) {
throw new StreamNotFoundException($e->getMessage());
}
@ -468,13 +466,13 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
* @param SocialQueryBuilder $qb
*
* @return Stream[]
*/
public function getStreamsFromRequest(IQueryBuilder $qb): array {
public function getStreamsFromRequest(SocialQueryBuilder $qb): array {
/** @var Stream[] $result */
$result = $this->getRows($qb, [$this, 'parseStreamSelectSql']);
$result = $qb->getRows([$this, 'parseStreamSelectSql']);
return $result;
}
@ -488,7 +486,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
protected function parseStreamSelectSql(array $data, string $as = Stream::TYPE): Stream {
public function parseStreamSelectSql(array $data, string $as = Stream::TYPE): Stream {
if ($as === Stream::TYPE) {
$as = $this->get('type', $data, Stream::TYPE);
}

Wyświetl plik

@ -1,39 +0,0 @@
<?php
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Exceptions;
use Exception;
class RowNotFoundException extends Exception {
}

2609
package-lock.json wygenerowano

Plik diff jest za duży Load Diff