From cf3d30d886dbc61668d6f05e6963add297d76731 Mon Sep 17 00:00:00 2001 From: Jonas Raoni Soares da Silva Date: Thu, 6 Apr 2023 17:22:07 +0300 Subject: [PATCH] #8700 Updated code to make use of the new safeCount() macro --- classes/announcement/DAO.php | 3 +-- classes/author/DAO.php | 2 +- classes/category/DAO.php | 2 +- classes/decision/DAO.php | 2 +- classes/doi/DAO.php | 4 +--- classes/doi/Repository.php | 4 ++-- classes/emailTemplate/DAO.php | 3 +-- classes/galley/DAO.php | 4 +--- classes/institution/DAO.php | 3 +-- classes/oai/PKPOAIDAO.php | 4 ++-- classes/publication/DAO.php | 2 +- classes/section/DAO.php | 3 +-- classes/services/PKPStatsContextService.php | 2 +- classes/services/PKPStatsGeoService.php | 2 +- classes/services/PKPStatsPublicationService.php | 4 ++-- .../queryBuilders/PKPContextQueryBuilder.php | 4 +--- .../queryBuilders/PKPStatsContextQueryBuilder.php | 2 +- .../queryBuilders/PKPStatsEditorialQueryBuilder.php | 12 ++++++------ .../PKPStatsPublicationQueryBuilder.php | 2 +- classes/submission/DAO.php | 2 +- classes/submission/reviewRound/ReviewRoundDAO.php | 2 +- classes/submissionFile/DAO.php | 4 ++-- classes/user/DAO.php | 2 +- classes/userGroup/DAO.php | 2 +- 24 files changed, 33 insertions(+), 43 deletions(-) diff --git a/classes/announcement/DAO.php b/classes/announcement/DAO.php index 81d17c68314..b942b03ae50 100644 --- a/classes/announcement/DAO.php +++ b/classes/announcement/DAO.php @@ -82,8 +82,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->get('a.' . $this->primaryKeyColumn) - ->count(); + ->safeCount(); } /** diff --git a/classes/author/DAO.php b/classes/author/DAO.php index f0e7d45791e..067fd44b37f 100644 --- a/classes/author/DAO.php +++ b/classes/author/DAO.php @@ -112,7 +112,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** diff --git a/classes/category/DAO.php b/classes/category/DAO.php index c8e7195092f..465f2d00435 100644 --- a/classes/category/DAO.php +++ b/classes/category/DAO.php @@ -70,7 +70,7 @@ public function newDataObject(): Category */ public function getCount(Collector $query): int { - return $query->getQueryBuilder()->count(); + return $query->getQueryBuilder()->safeCount(); } /** diff --git a/classes/decision/DAO.php b/classes/decision/DAO.php index 9bf129310a8..d9227b575a1 100644 --- a/classes/decision/DAO.php +++ b/classes/decision/DAO.php @@ -76,7 +76,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** diff --git a/classes/doi/DAO.php b/classes/doi/DAO.php index c37a8fca746..e476a60bb66 100644 --- a/classes/doi/DAO.php +++ b/classes/doi/DAO.php @@ -78,9 +78,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->select('d.' . $this->primaryKeyColumn) - ->get() - ->count(); + ->safeCount(); } /** diff --git a/classes/doi/Repository.php b/classes/doi/Repository.php index d1cde5dd357..a1b824e42b7 100644 --- a/classes/doi/Repository.php +++ b/classes/doi/Repository.php @@ -322,8 +322,8 @@ public function isAssigned(int $doiId, string $pubObjectType): bool Repo::doi()::TYPE_PUBLICATION => Repo::publication() ->getCollector() ->filterByDoiIds([$doiId]) - ->getIds() - ->count(), + ->getQueryBuilder() + ->safeCount() > 0, default => false, }; } diff --git a/classes/emailTemplate/DAO.php b/classes/emailTemplate/DAO.php index bb84bed3251..3eaa6afe74a 100644 --- a/classes/emailTemplate/DAO.php +++ b/classes/emailTemplate/DAO.php @@ -145,8 +145,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->get() - ->count(); + ->safeCount(); } /** diff --git a/classes/galley/DAO.php b/classes/galley/DAO.php index 89aea17979c..251399d99d8 100644 --- a/classes/galley/DAO.php +++ b/classes/galley/DAO.php @@ -91,9 +91,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->select('g.' . $this->primaryKeyColumn) - ->get() - ->count(); + ->safeCount(); } /** diff --git a/classes/institution/DAO.php b/classes/institution/DAO.php index 58ff88defb7..7277fd7e226 100644 --- a/classes/institution/DAO.php +++ b/classes/institution/DAO.php @@ -79,8 +79,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->select('i.' . $this->primaryKeyColumn) - ->count(); + ->safeCount(); } /** diff --git a/classes/oai/PKPOAIDAO.php b/classes/oai/PKPOAIDAO.php index b72fa6e9f92..1c5e0f4633b 100755 --- a/classes/oai/PKPOAIDAO.php +++ b/classes/oai/PKPOAIDAO.php @@ -145,7 +145,7 @@ public function getRecord($dataObjectId, $setIds = []) public function getRecords($setIds, $from, $until, $set, $offset, $limit, &$total) { $query = $this->_getRecordsRecordSetQuery($setIds, $from, $until, $set); - $total = $query->count(); + $total = $query->safeCount(); $results = $query->offset($offset)->limit($limit)->get(); $records = []; @@ -173,7 +173,7 @@ public function getRecords($setIds, $from, $until, $set, $offset, $limit, &$tota public function getIdentifiers($setIds, $from, $until, $set, $offset, $limit, &$total) { $query = $this->_getRecordsRecordSetQuery($setIds, $from, $until, $set); - $total = $query->count(); + $total = $query->safeCount(); $results = $query->offset($offset)->limit($limit)->get(); $records = []; diff --git a/classes/publication/DAO.php b/classes/publication/DAO.php index b9530a8d05a..c7dddef953a 100644 --- a/classes/publication/DAO.php +++ b/classes/publication/DAO.php @@ -112,7 +112,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** diff --git a/classes/section/DAO.php b/classes/section/DAO.php index 1f85b5c8587..90dde458344 100644 --- a/classes/section/DAO.php +++ b/classes/section/DAO.php @@ -53,8 +53,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->select($this->primaryKeyColumn) - ->count(); + ->safeCount(); } /** diff --git a/classes/services/PKPStatsContextService.php b/classes/services/PKPStatsContextService.php index 87759455a32..d2e9b883c28 100644 --- a/classes/services/PKPStatsContextService.php +++ b/classes/services/PKPStatsContextService.php @@ -33,7 +33,7 @@ public function getCount(array $args): int unset($args['count']); unset($args['offset']); $metricsQB = $this->getQueryBuilder($args); - return $metricsQB->getContextIds()->get()->count(); + return $metricsQB->getContextIds()->safeCount(); } /** diff --git a/classes/services/PKPStatsGeoService.php b/classes/services/PKPStatsGeoService.php index 9606637da13..3439470b1d6 100644 --- a/classes/services/PKPStatsGeoService.php +++ b/classes/services/PKPStatsGeoService.php @@ -48,7 +48,7 @@ public function getCount(array $args, string $scale): int $groupBy = [StatisticsHelper::STATISTICS_DIMENSION_COUNTRY]; } - return $metricsQB->getGeoData($groupBy)->get()->count(); + return $metricsQB->getGeoData($groupBy)->safeCount(); } /** diff --git a/classes/services/PKPStatsPublicationService.php b/classes/services/PKPStatsPublicationService.php index c653e443111..09db5078487 100644 --- a/classes/services/PKPStatsPublicationService.php +++ b/classes/services/PKPStatsPublicationService.php @@ -87,7 +87,7 @@ public function getCount(array $args): int Hook::call('StatsPublication::getCount::queryBuilder', [&$metricsQB, $args]); - return $metricsQB->getSubmissionIds()->get()->count(); + return $metricsQB->getSubmissionIds()->safeCount(); } /** @@ -189,7 +189,7 @@ public function getFilesCount(array $args): int $groupBy = [PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID, PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_FILE_ID]; $metricsQB = $metricsQB->getSum($groupBy); - return $metricsQB->get()->count(); + return $metricsQB->safeCount(); } /** diff --git a/classes/services/queryBuilders/PKPContextQueryBuilder.php b/classes/services/queryBuilders/PKPContextQueryBuilder.php index 979e8933bc8..c9b661827b1 100644 --- a/classes/services/queryBuilders/PKPContextQueryBuilder.php +++ b/classes/services/queryBuilders/PKPContextQueryBuilder.php @@ -93,9 +93,7 @@ public function getCount() { return $this ->getQuery() - ->select('c.' . $this->dbIdColumn) - ->get() - ->count(); + ->safeCount(); } /** diff --git a/classes/services/queryBuilders/PKPStatsContextQueryBuilder.php b/classes/services/queryBuilders/PKPStatsContextQueryBuilder.php index e94aad82ad8..1340f9e105a 100644 --- a/classes/services/queryBuilders/PKPStatsContextQueryBuilder.php +++ b/classes/services/queryBuilders/PKPStatsContextQueryBuilder.php @@ -31,7 +31,7 @@ public function getContextIds(): Builder { return $this->_getObject() ->select([PKPStatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID]) - ->distinct(); + ->groupBy(PKPStatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID); } /** diff --git a/classes/services/queryBuilders/PKPStatsEditorialQueryBuilder.php b/classes/services/queryBuilders/PKPStatsEditorialQueryBuilder.php index 92019c84e83..f80da28779f 100644 --- a/classes/services/queryBuilders/PKPStatsEditorialQueryBuilder.php +++ b/classes/services/queryBuilders/PKPStatsEditorialQueryBuilder.php @@ -110,7 +110,7 @@ public function countSubmissionsReceived() $q->where('s.date_submitted', '<=', $this->dateEnd); } - return $q->count(); + return $q->safeCount(); } /** @@ -184,7 +184,7 @@ public function countByStatus($status) { return $this->_getObject() ->whereIn('s.status', (array) $status) - ->count(); + ->safeCount(); } /** @@ -199,7 +199,7 @@ public function countActiveByStages($stages) return $this->_getObject() ->where('s.status', '=', PKPSubmission::STATUS_QUEUED) ->whereIn('s.stage_id', $stages) - ->count(); + ->safeCount(); } /** @@ -234,7 +234,7 @@ public function countPublished() } } - return $q->count(); + return $q->safeCount(); } /** @@ -458,7 +458,7 @@ public function countImported() ->where(DB::raw('CAST(s.date_submitted AS DATE)'), '>', DB::raw('pi.date_published')) ->when($this->dateStart, fn (Builder $q) => $q->where('s.date_submitted', '>=', $this->dateStart)) ->when($this->dateEnd, fn (Builder $q) => $q->where('s.date_submitted', '<=', $this->dateEnd)) - ->count(); + ->safeCount(); } /** @@ -473,7 +473,7 @@ public function countInProgress() ->where('s.submission_progress', '<>', '') ->when($this->dateStart, fn (Builder $q) => $q->where('s.date_submitted', '>=', $this->dateStart)) ->when($this->dateEnd, fn (Builder $q) => $q->where('s.date_submitted', '<=', $this->dateEnd)) - ->count(); + ->safeCount(); } /** diff --git a/classes/services/queryBuilders/PKPStatsPublicationQueryBuilder.php b/classes/services/queryBuilders/PKPStatsPublicationQueryBuilder.php index f7201fb2874..14a8be0bf89 100644 --- a/classes/services/queryBuilders/PKPStatsPublicationQueryBuilder.php +++ b/classes/services/queryBuilders/PKPStatsPublicationQueryBuilder.php @@ -111,7 +111,7 @@ public function getSubmissionIds(): Builder { return $this->_getObject() ->select(['metrics_submission.' . PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID]) - ->distinct(); + ->groupBy(PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID); } /** diff --git a/classes/submission/DAO.php b/classes/submission/DAO.php index a68d8b29f06..fb7967c631a 100644 --- a/classes/submission/DAO.php +++ b/classes/submission/DAO.php @@ -91,7 +91,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** diff --git a/classes/submission/reviewRound/ReviewRoundDAO.php b/classes/submission/reviewRound/ReviewRoundDAO.php index 206ac1d7b96..a67d30b3288 100644 --- a/classes/submission/reviewRound/ReviewRoundDAO.php +++ b/classes/submission/reviewRound/ReviewRoundDAO.php @@ -389,7 +389,7 @@ public function getReviewRoundCountBySubmissionId(int $submissionId, ?int $stage return DB::table('review_rounds') ->where('submission_id', $submissionId) ->when(!is_null($stageId), fn ($query) => $query->where('stage_id', $stageId)) - ->count(); + ->safeCount(); } } diff --git a/classes/submissionFile/DAO.php b/classes/submissionFile/DAO.php index 99ea72abf70..b2d250e22d9 100644 --- a/classes/submissionFile/DAO.php +++ b/classes/submissionFile/DAO.php @@ -122,7 +122,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** @@ -359,7 +359,7 @@ public function pubIdExists( 'sfs.setting_value' => (string) $pubId, 'sfs.submission_file_id' => (int) $excludePubObjectId, 's.context_id' => (int) $contextId - ])->count(); + ])->safeCount(); return (bool) $result > 0; } diff --git a/classes/user/DAO.php b/classes/user/DAO.php index 247c0d45cd9..b9fbc7659e8 100644 --- a/classes/user/DAO.php +++ b/classes/user/DAO.php @@ -138,7 +138,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /** diff --git a/classes/userGroup/DAO.php b/classes/userGroup/DAO.php index 15869322c22..84deadb198b 100644 --- a/classes/userGroup/DAO.php +++ b/classes/userGroup/DAO.php @@ -78,7 +78,7 @@ public function getCount(Collector $query): int { return $query ->getQueryBuilder() - ->count(); + ->safeCount(); } /**