Skip to content

Commit

Permalink
pkp#8700 Updated code to make use of the new safeCount() macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed May 23, 2024
1 parent 9a325ef commit cf3d30d
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 43 deletions.
3 changes: 1 addition & 2 deletions classes/announcement/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->get('a.' . $this->primaryKeyColumn)
->count();
->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/author/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/category/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function newDataObject(): Category
*/
public function getCount(Collector $query): int
{
return $query->getQueryBuilder()->count();
return $query->getQueryBuilder()->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/decision/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions classes/doi/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->select('d.' . $this->primaryKeyColumn)
->get()
->count();
->safeCount();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/doi/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand Down
3 changes: 1 addition & 2 deletions classes/emailTemplate/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->get()
->count();
->safeCount();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions classes/galley/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->select('g.' . $this->primaryKeyColumn)
->get()
->count();
->safeCount();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions classes/institution/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->select('i.' . $this->primaryKeyColumn)
->count();
->safeCount();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/oai/PKPOAIDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 1 addition & 1 deletion classes/publication/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions classes/section/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->select($this->primaryKeyColumn)
->count();
->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/services/PKPStatsContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/services/PKPStatsGeoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/services/PKPStatsPublicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand Down
4 changes: 1 addition & 3 deletions classes/services/queryBuilders/PKPContextQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ public function getCount()
{
return $this
->getQuery()
->select('c.' . $this->dbIdColumn)
->get()
->count();
->safeCount();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getContextIds(): Builder
{
return $this->_getObject()
->select([PKPStatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID])
->distinct();
->groupBy(PKPStatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions classes/services/queryBuilders/PKPStatsEditorialQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function countSubmissionsReceived()
$q->where('s.date_submitted', '<=', $this->dateEnd);
}

return $q->count();
return $q->safeCount();
}

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ public function countByStatus($status)
{
return $this->_getObject()
->whereIn('s.status', (array) $status)
->count();
->safeCount();
}

/**
Expand All @@ -199,7 +199,7 @@ public function countActiveByStages($stages)
return $this->_getObject()
->where('s.status', '=', PKPSubmission::STATUS_QUEUED)
->whereIn('s.stage_id', $stages)
->count();
->safeCount();
}

/**
Expand Down Expand Up @@ -234,7 +234,7 @@ public function countPublished()
}
}

return $q->count();
return $q->safeCount();
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/submission/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/submission/reviewRound/ReviewRoundDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions classes/submissionFile/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/user/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/userGroup/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->count();
->safeCount();
}

/**
Expand Down

0 comments on commit cf3d30d

Please sign in to comment.