Skip to content

Commit

Permalink
pkp#8700 Dropped safeCount() workaround in favor of getCountForPagina…
Browse files Browse the repository at this point in the history
…tion()

(cherry picked from commit 5539710)
  • Loading branch information
jonasraoni committed May 23, 2024
1 parent 85f70f7 commit 5652fde
Show file tree
Hide file tree
Showing 24 changed files with 30 additions and 79 deletions.
2 changes: 1 addition & 1 deletion classes/announcement/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->safeCount();
->getCountForPagination();
}

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

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

/**
Expand Down
2 changes: 0 additions & 2 deletions classes/core/PKPContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Illuminate\Queue\Failed\DatabaseFailedJobProvider;
use Illuminate\Support\Facades\Facade;
use PKP\config\Config;
use PKP\db\DatabaseServiceProvider;
use PKP\i18n\LocaleServiceProvider;
use PKP\core\PKPUserProvider;
use PKP\proxy\ProxyParser;
Expand Down Expand Up @@ -144,7 +143,6 @@ public function registerConfiguredProviders()
{
// Load main settings, this should be done before registering services, e.g., it's used by Database Service
$this->loadConfiguration();
$this->register(new DatabaseServiceProvider($this));

$this->register(new \PKP\core\PKPAuthServiceProvider($this));
$this->register(new \Illuminate\Cookie\CookieServiceProvider($this));
Expand Down
47 changes: 0 additions & 47 deletions classes/db/DatabaseServiceProvider.php

This file was deleted.

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/doi/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function isAssigned(int $doiId, string $pubObjectType): bool
->getCollector()
->filterByDoiIds([$doiId])
->getQueryBuilder()
->safeCount() > 0,
->getCountForPagination() > 0,
default => false,
};
}
Expand Down
2 changes: 1 addition & 1 deletion classes/emailTemplate/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->safeCount();
->getCountForPagination();
}

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

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

/**
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->safeCount();
$total = $query->getCountForPagination();
$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->safeCount();
$total = $query->getCountForPagination();
$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 @@ -107,7 +107,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->safeCount();
->getCountForPagination();
}

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

/**
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()->safeCount();
return $metricsQB->getContextIds()->getCountForPagination();
}

/**
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)->safeCount();
return $metricsQB->getGeoData($groupBy)->getCountForPagination();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/services/PKPStatsPublicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getCount(array $args): int

Hook::call('StatsPublication::getCount::queryBuilder', [&$metricsQB, $args]);

return $metricsQB->getSubmissionIds()->safeCount();
return $metricsQB->getSubmissionIds()->getCountForPagination();
}

/**
Expand Down Expand Up @@ -197,7 +197,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->safeCount();
return $metricsQB->getCountForPagination();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/services/queryBuilders/PKPContextQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getCount()
{
return $this
->getQuery()
->safeCount();
->getCountForPagination();
}

/**
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->safeCount();
return $q->getCountForPagination();
}

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

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

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

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

/**
Expand Down Expand Up @@ -460,7 +460,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))
->safeCount();
->getCountForPagination();
}

/**
Expand All @@ -475,7 +475,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))
->safeCount();
->getCountForPagination();
}

/**
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()
->safeCount();
->getCountForPagination();
}

/**
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))
->safeCount();
->getCountForPagination();
}
}

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

/**
Expand Down Expand Up @@ -361,7 +361,7 @@ public function pubIdExists(
'sfs.setting_value' => (string) $pubId,
'sfs.submission_file_id' => (int) $excludePubObjectId,
's.context_id' => (int) $contextId
])->safeCount();
])->getCountForPagination();
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 @@ -143,7 +143,7 @@ public function getCount(Collector $query): int
{
return $query
->getQueryBuilder()
->safeCount();
->getCountForPagination();
}

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

/**
Expand Down

0 comments on commit 5652fde

Please sign in to comment.