Skip to content

Commit

Permalink
#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 Mar 23, 2023
1 parent 01a32bb commit 29935df
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 38 deletions.
4 changes: 2 additions & 2 deletions api/v1/_email/PKPEmailHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function process(ServerRequestInterface $slimRequest, APIResponse $respon
$countRunning = Capsule::table('jobs')
->where('queue', $args['queueId'])
->whereNotNull('reserved_at')
->count();
->safeCount();
$countPending = $this->countPending($args['queueId']);

// Don't run another job if one is already running.
Expand Down Expand Up @@ -230,6 +230,6 @@ function() {
protected function countPending(string $queueId) : int {
return Capsule::table('jobs')
->where('queue', $queueId)
->count();
->safeCount();
}
}
3 changes: 2 additions & 1 deletion classes/db/DAOResultFactory.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import('lib.pkp.classes.core.ItemIterator');
import('lib.pkp.classes.db.DAOResultIterator');

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Enumerable;

class DAOResultFactory extends ItemIterator {
Expand All @@ -37,7 +38,7 @@ class DAOResultFactory extends ItemIterator {
var $records;

/**
* @var string|null Fetch SQL
* @var string|Builder|null Fetch SQL
*/
var $sql;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private function _migrateSubmissionFiles() {
// be unique.
$count = Capsule::table('review_round_files')
->where('file_id', '=', $row->file_id)
->count();
->safeCount();
if ($count > 1) {
Capsule::table('review_round_files')
->where('file_id', '=', $row->file_id)
Expand Down
5 changes: 3 additions & 2 deletions classes/services/PKPUserService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,9 @@ public function getAccessibleStageRoles($userId, $contextId, &$submission, $stag
* @param array $args See self::getMany()
*/
public function count($args = []) {
$qb = $this->getQueryBuilder($args);
return $qb->getQuery()->get()->count();
return $this->getQueryBuilder($args)
->getQuery()
->safeCount();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ public function searchPhrase($phrase) {
public function getCount() {
return $this
->getQuery()
->select('a.announcement_id')
->get()
->count();
->safeCount();
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public function searchPhrase($phrase) {
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 @@ -177,7 +177,7 @@ public function getCount() {
$compiledQuery = $this->getCompiledQuery();
return Capsule::table(Capsule::raw('(' . $compiledQuery[0] . ') as email_template_count'))
->setBindings($compiledQuery[1])
->count();
->safeCount();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public function offsetBy($offset) {
public function getCount() {
return $this
->getQuery()
->select('p.publication_id')
->get()
->count();
->safeCount();
}

/**
Expand Down Expand Up @@ -186,6 +184,6 @@ public function isDuplicateUrlPath($urlPath, $submissionId, $contextId) {
->where('url_path', '=' , $urlPath)
->where('p.submission_id', '!=', $submissionId)
->where('s.context_id', '=', $contextId)
->count();
->safeCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function countSubmissionsReceived() {
$q->where('s.date_submitted', '<=', $this->dateEnd);
}

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

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

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

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

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

/**
Expand Down Expand Up @@ -433,7 +433,7 @@ public function countImported() {
->when($this->dateEnd, function (Builder $q) {
$q->where('s.date_submitted', '<=', $this->dateEnd);
})
->count();
->safeCount();
}

/**
Expand All @@ -451,7 +451,7 @@ public function countInProgress() {
->when($this->dateEnd, function (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 @@ -157,9 +157,7 @@ public function includeDependentFiles($includeDependentFiles) {
public function getCount() {
return $this
->getQuery()
->select('sf.submission_file_id')
->get()
->count();
->safeCount();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ public function offsetBy($offset) {
public function getCount() {
return $this
->getQuery()
->select('s.submission_id')
->get()
->count();
->safeCount();
}

/**
Expand Down
9 changes: 3 additions & 6 deletions classes/services/queryBuilders/PKPUserQueryBuilder.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,9 @@ public function offsetBy($offset) {
* @copydoc PKP\Services\QueryBuilders\Interfaces\EntityQueryBuilderInterface::getCount()
*/
public function getCount() {
$q = $this->getQuery();
// Reset the orderBy
$q->orders = [];
return $q->select('u.user_id')
->get()
->count();
return $this
->getQuery()
->safeCount();
}

/**
Expand Down

0 comments on commit 29935df

Please sign in to comment.