diff options
-rw-r--r-- | lib/Db/CoreRequestBuilder.php | 67 | ||||
-rw-r--r-- | lib/Db/IndexesRequest.php | 59 | ||||
-rw-r--r-- | lib/Db/IndexesRequestBuilder.php | 38 | ||||
-rw-r--r-- | lib/Db/TickRequest.php | 21 | ||||
-rw-r--r-- | lib/Db/TickRequestBuilder.php | 36 |
5 files changed, 144 insertions, 77 deletions
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index d1223e4..d90054c 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,6 +27,7 @@ * */ + namespace OCA\FullTextSearch\Db; @@ -35,6 +39,12 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IL10N; + +/** + * Class CoreRequestBuilder + * + * @package OCA\FullTextSearch\Db + */ class CoreRequestBuilder { const TABLE_INDEXES = 'fulltextsearch_indexes'; @@ -81,8 +91,8 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param int $id */ - protected function limitToId(IQueryBuilder &$qb, $id) { - $this->limitToDBField($qb, 'id', $id); + protected function limitToId(IQueryBuilder &$qb, int $id) { + $this->limitToDBFieldInt($qb, 'id', $id); } @@ -92,18 +102,18 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $userId */ - protected function limitToOwnerId(IQueryBuilder &$qb, $userId) { + protected function limitToOwnerId(IQueryBuilder &$qb, string $userId) { $this->limitToDBField($qb, 'owner_id', $userId); } /** - * Limit to the type + * Limit to the providerId * * @param IQueryBuilder $qb * @param string $providerId */ - protected function limitToProviderId(IQueryBuilder &$qb, $providerId) { + protected function limitToProviderId(IQueryBuilder &$qb, string $providerId) { $this->limitToDBField($qb, 'provider_id', $providerId); } @@ -114,13 +124,13 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $documentId */ - protected function limitToDocumentId(IQueryBuilder &$qb, $documentId) { + protected function limitToDocumentId(IQueryBuilder &$qb, string $documentId) { $this->limitToDBField($qb, 'document_id', $documentId); } /** - * Limit to the documentId + * Limit to the entry with at least one Error * * @param IQueryBuilder $qb */ @@ -131,7 +141,7 @@ class CoreRequestBuilder { /** - * Limit to the documentId + * Limit to the entry with no error * * @param IQueryBuilder $qb */ @@ -147,29 +157,29 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param array $documentIds */ - protected function limitToDocumentIds(IQueryBuilder &$qb, $documentIds) { - $this->limitToDBField($qb, 'document_id', $documentIds); + protected function limitToDocumentIds(IQueryBuilder &$qb, array $documentIds) { + $this->limitToDBFieldArray($qb, 'document_id', $documentIds); } /** - * Limit the request to the Source + * Limit the request to source * * @param IQueryBuilder $qb * @param string $source */ - protected function limitToSource(IQueryBuilder &$qb, $source) { + protected function limitToSource(IQueryBuilder &$qb, string $source) { $this->limitToDBField($qb, 'id', $source); } /** - * Limit the request to the Source + * Limit the request to status * * @param IQueryBuilder $qb * @param string $status */ - protected function limitToStatus(IQueryBuilder &$qb, $status) { + protected function limitToStatus(IQueryBuilder &$qb, string $status) { $this->limitToDBField($qb, 'status', $status); } @@ -177,9 +187,36 @@ class CoreRequestBuilder { /** * @param IQueryBuilder $qb * @param string $field + * @param string $value + */ + private function limitToDBField(IQueryBuilder &$qb, string $field, string $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + /** + * @param IQueryBuilder $qb + * @param string $field + * @param int $value + */ + private function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) { + $expr = $qb->expr(); + $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + $field = $pf . $field; + + $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + } + + + /** + * @param IQueryBuilder $qb + * @param string $field * @param string|integer|array $values */ - private function limitToDBField(IQueryBuilder &$qb, $field, $values) { + private function limitToDBFieldArray(IQueryBuilder &$qb, string $field, array $values) { $expr = $qb->expr(); $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; $field = $pf . $field; diff --git a/lib/Db/IndexesRequest.php b/lib/Db/IndexesRequest.php index 2eb225c..4b5b45f 100644 --- a/lib/Db/IndexesRequest.php +++ b/lib/Db/IndexesRequest.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,14 +27,20 @@ * */ + namespace OCA\FullTextSearch\Db; use OCA\FullTextSearch\Exceptions\IndexDoesNotExistException; use OCA\FullTextSearch\Model\Index; -use OCP\FullTextSearch\IFullTextSearchProvider; use OCP\FullTextSearch\Model\IIndex; + +/** + * Class IndexesRequest + * + * @package OCA\FullTextSearch\Db + */ class IndexesRequest extends IndexesRequestBuilder { @@ -41,7 +50,7 @@ class IndexesRequest extends IndexesRequestBuilder { * @return bool * @throws \Exception */ - public function create(Index $index) { + public function create(Index $index): bool { try { $qb = $this->getIndexesInsertSql(); @@ -69,7 +78,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function resetError(Index $index) { + public function resetError(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -105,7 +114,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @return Index[] */ - public function getErrorIndexes() { + public function getErrorIndexes(): array { $qb = $this->getIndexesSelectSql(); $this->limitToErr($qb); @@ -126,7 +135,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return bool */ - public function update(Index $index) { + public function update(Index $index): bool { try { $this->getIndex($index->getProviderId(), $index->getDocumentId()); @@ -159,12 +168,32 @@ class IndexesRequest extends IndexesRequestBuilder { } - public function updateStatus($providerId, $indexes, $status) { + /** + * @param string $providerId + * @param string $documentId + * @param int $status + */ + public function updateStatus(string $providerId, string $documentId, int $status) { + $qb = $this->getIndexesUpdateSql(); + $qb->set('status', $qb->createNamedParameter($status)); + + $this->limitToProviderId($qb, $providerId); + $this->limitToDocumentId($qb, $documentId); + + $qb->execute(); + } + + /** + * @param string $providerId + * @param array $indexes + * @param int $status + */ + public function updateStatuses(string $providerId, array $indexes, int $status) { $qb = $this->getIndexesUpdateSql(); $qb->set('status', $qb->createNamedParameter($status)); $this->limitToProviderId($qb, $providerId); - $this->limitToDocumentId($qb, $indexes); + $this->limitToDocumentIds($qb, $indexes); $qb->execute(); } @@ -185,7 +214,7 @@ class IndexesRequest extends IndexesRequestBuilder { /** * @param string $providerId */ - public function deleteFromProviderId($providerId) { + public function deleteFromProviderId(string $providerId) { $qb = $this->getIndexesDeleteSql(); $this->limitToProviderId($qb, $providerId); @@ -207,12 +236,12 @@ class IndexesRequest extends IndexesRequestBuilder { * return index. * * @param string $providerId - * @param string|int $documentId + * @param string $documentId * * @return Index * @throws IndexDoesNotExistException */ - public function getIndex($providerId, $documentId): Index { + public function getIndex(string $providerId, string $documentId): Index { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentId($qb, $documentId); @@ -238,7 +267,7 @@ class IndexesRequest extends IndexesRequestBuilder { * @return Index[] * @throws IndexDoesNotExistException */ - public function getIndexes($providerId, $documentIds) { + public function getIndexes(string $providerId, array $documentIds): array { $qb = $this->getIndexesSelectSql(); $this->limitToProviderId($qb, $providerId); $this->limitToDocumentIds($qb, $documentIds); @@ -263,7 +292,7 @@ class IndexesRequest extends IndexesRequestBuilder { * * @return Index[] */ - public function getQueuedIndexes($all = false) { + public function getQueuedIndexes(bool $all = false): array { $qb = $this->getIndexesSelectSql(); $this->limitToQueuedIndexes($qb); if ($all === false) { @@ -284,13 +313,13 @@ class IndexesRequest extends IndexesRequestBuilder { /** * return list of last indexes from a providerId. * - * @param IFullTextSearchProvider $provider + * @param string $providerId * * @return Index[] */ - public function getIndexesFromProvider(IFullTextSearchProvider $provider) { + public function getIndexesFromProvider(string $providerId): array { $qb = $this->getIndexesSelectSql(); - $this->limitToProviderId($qb, $provider->getId()); + $this->limitToProviderId($qb, $providerId); $indexes = []; $cursor = $qb->execute(); diff --git a/lib/Db/IndexesRequestBuilder.php b/lib/Db/IndexesRequestBuilder.php index 0eb47c2..0eb72ce 100644 --- a/lib/Db/IndexesRequestBuilder.php +++ b/lib/Db/IndexesRequestBuilder.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,30 +27,20 @@ * */ + namespace OCA\FullTextSearch\Db; use OCA\FullTextSearch\Model\Index; -use OCA\FullTextSearch\Service\ConfigService; -use OCA\FullTextSearch\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; -use OCP\IL10N; -class IndexesRequestBuilder extends CoreRequestBuilder { - - /** - * WebsitesRequestBuilder constructor. - * - * {@inheritdoc} - */ - public function __construct( - IL10N $l10n, IDBConnection $connection, ConfigService $configService, - MiscService $miscService - ) { - parent::__construct($l10n, $connection, $configService, $miscService); - } +/** + * Class IndexesRequestBuilder + * + * @package OCA\FullTextSearch\Db + */ +class IndexesRequestBuilder extends CoreRequestBuilder { /** @@ -55,7 +48,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesInsertSql() { + protected function getIndexesInsertSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_INDEXES); @@ -68,7 +61,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesUpdateSql() { + protected function getIndexesUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_INDEXES); @@ -81,7 +74,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesSelectSql() { + protected function getIndexesSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -102,7 +95,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getIndexesDeleteSql() { + protected function getIndexesDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -115,7 +108,7 @@ class IndexesRequestBuilder extends CoreRequestBuilder { * * @return Index */ - protected function parseIndexesSelectSql($data) { + protected function parseIndexesSelectSql(array $data): Index { $index = new Index($data['provider_id'], $data['document_id']); $index->setStatus($data['status']) ->setSource($data['source']) @@ -129,3 +122,4 @@ class IndexesRequestBuilder extends CoreRequestBuilder { } } + diff --git a/lib/Db/TickRequest.php b/lib/Db/TickRequest.php index 4338450..6e50678 100644 --- a/lib/Db/TickRequest.php +++ b/lib/Db/TickRequest.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,6 +27,7 @@ * */ + namespace OCA\FullTextSearch\Db; @@ -31,6 +35,11 @@ use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; use OCA\FullTextSearch\Model\Tick; +/** + * Class TickRequest + * + * @package OCA\FullTextSearch\Db + */ class TickRequest extends TickRequestBuilder { @@ -40,7 +49,7 @@ class TickRequest extends TickRequestBuilder { * @return int * @throws \Exception */ - public function create(Tick $tick) { + public function create(Tick $tick): int { try { $qb = $this->getTickInsertSql(); @@ -65,7 +74,7 @@ class TickRequest extends TickRequestBuilder { * * @return bool */ - public function update(Tick $tick) { + public function update(Tick $tick): bool { try { $this->getTickById($tick->getId()); @@ -117,7 +126,7 @@ class TickRequest extends TickRequestBuilder { * @return Tick * @throws TickDoesNotExistException */ - public function getTickById($id) { + public function getTickById(int $id): Tick { $qb = $this->getTickSelectSql(); $this->limitToId($qb, $id); @@ -134,13 +143,13 @@ class TickRequest extends TickRequestBuilder { /** - * return tick. + * return ticks. * * @param string $status * * @return Tick[] */ - public function getTickByStatus($status) { + public function getTicksByStatus(string $status): array { $ticks = []; @@ -162,7 +171,7 @@ class TickRequest extends TickRequestBuilder { * * @return Tick[] */ - public function getTickBySource($source) { + public function getTicksBySource(string $source): array { $qb = $this->getTickSelectSql(); $this->limitToSource($qb, $source); diff --git a/lib/Db/TickRequestBuilder.php b/lib/Db/TickRequestBuilder.php index cd3cf09..e19ca84 100644 --- a/lib/Db/TickRequestBuilder.php +++ b/lib/Db/TickRequestBuilder.php @@ -1,4 +1,7 @@ <?php +declare(strict_types=1); + + /** * FullTextSearch - Full text search framework for Nextcloud * @@ -24,6 +27,7 @@ * */ + namespace OCA\FullTextSearch\Db; @@ -34,19 +38,13 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use OCP\IL10N; -class TickRequestBuilder extends CoreRequestBuilder { - - /** - * TicksRequestBuilder constructor. - * - * {@inheritdoc} - */ - public function __construct( - IL10N $l10n, IDBConnection $connection, ConfigService $configService, MiscService $miscService - ) { - parent::__construct($l10n, $connection, $configService, $miscService); - } +/** + * Class TickRequestBuilder + * + * @package OCA\FullTextSearch\Db + */ +class TickRequestBuilder extends CoreRequestBuilder { /** @@ -54,7 +52,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickInsertSql() { + protected function getTickInsertSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert(self::TABLE_TICKS); @@ -67,7 +65,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickUpdateSql() { + protected function getTickUpdateSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->update(self::TABLE_TICKS); @@ -80,7 +78,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickSelectSql() { + protected function getTickSelectSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ @@ -100,7 +98,7 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return IQueryBuilder */ - protected function getTickDeleteSql() { + protected function getTickDeleteSql(): IQueryBuilder { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete(self::TABLE_INDEXES); @@ -113,12 +111,12 @@ class TickRequestBuilder extends CoreRequestBuilder { * * @return Tick */ - protected function parseTickSelectSql($data) { + protected function parseTickSelectSql(array $data): Tick { $tick = new Tick($data['source'], $data['id']); $tick->setData(json_decode($data['data'], true)) ->setTick($data['tick']) - ->setFirstTick($data['first_tick']) - ->setStatus($data['status']) + ->setFirstTick($data['first_tick']) + ->setStatus($data['status']) ->setAction($data['action']); return $tick; |