Skip to content

Commit

Permalink
pkp/pkp-lib#9913 removed usage of Services::get and related namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
touhidurabir committed Jul 11, 2024
1 parent 0a18413 commit 6a1cc0c
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 49 deletions.
9 changes: 4 additions & 5 deletions api/v1/stats/issues/StatsIssueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace APP\API\v1\stats\issues;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\security\authorization\OjsIssueRequiredPolicy;
use APP\statistics\StatisticsHelper;
Expand Down Expand Up @@ -171,7 +170,7 @@ public function getMany(Request $illuminateRequest): StreamedResponse|JsonRespon
}

// Get a list (count number) of top issues by total (toc + galley) views
$statsService = Services::get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$statsService = app()->get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$totalMetrics = $statsService->getTotals($allowedParams);

// Get the stats for each issue
Expand Down Expand Up @@ -246,7 +245,7 @@ public function getManyTimeline(Request $illuminateRequest): StreamedResponse|Js
$allowedParams['assocTypes'] = [Application::ASSOC_TYPE_ISSUE_GALLEY];
};

$statsService = Services::get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$statsService = app()->get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */

// Identify issues which should be included in the results when a searchPhrase is passed
if (!empty($allowedParams['searchPhrase'])) {
Expand Down Expand Up @@ -297,7 +296,7 @@ public function get(Request $illuminateRequest): JsonResponse
return response()->json(['error' => $result], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$statsService = app()->get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$dateStart = array_key_exists('dateStart', $allowedParams) ? $allowedParams['dateStart'] : null;
$dateEnd = array_key_exists('dateEnd', $allowedParams) ? $allowedParams['dateEnd'] : null;
$metricsByType = $statsService->getTotalsByType($issue->getId(), $request->getContext()->getId(), $dateStart, $dateEnd);
Expand Down Expand Up @@ -354,7 +353,7 @@ public function getTimeline(Request $illuminateRequest): JsonResponse
return response()->json(['error' => $result], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$statsService = app()->get('issueStats'); /** @var \APP\services\StatsIssueService $statsService */
$data = $statsService->getTimeline($allowedParams['timelineInterval'], $allowedParams);
return response()->json($data, Response::HTTP_OK);
}
Expand Down
3 changes: 1 addition & 2 deletions classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace APP\publication;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\payment\ojs\OJSCompletedPaymentDAO;
use APP\payment\ojs\OJSPaymentManager;
Expand Down Expand Up @@ -115,7 +114,7 @@ public function validatePublish(Publication $publication, Submission $submission
// If submission fees are enabled, check that they're fulfilled
$context = Application::get()->getRequest()->getContext();
if (!$context || $context->getId() !== $submission->getData('contextId')) {
$context = Services::get('context')->get($submission->getData('contextId'));
$context = app()->get('context')->get($submission->getData('contextId'));
}
$paymentManager = Application::getPaymentManager($context);
$completedPaymentDao = DAORegistry::getDAO('OJSCompletedPaymentDAO'); /** @var OJSCompletedPaymentDAO $completedPaymentDao */
Expand Down
3 changes: 1 addition & 2 deletions classes/search/ArticleSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use APP\core\Application;
use APP\core\Request;
use APP\core\Services;
use APP\facades\Repo;
use APP\issue\IssueAction;
use PKP\db\DAORegistry;
Expand Down Expand Up @@ -71,7 +70,7 @@ public function getSparseArray($unorderedResults, $orderBy, $orderDir, $exclude)
$filter['dateStart'] = $oneMonthAgo;
$filter['dateEnd'] = $today;
}
$rawReport = Services::get('publicationStats')->getTotals($filter);
$rawReport = app()->get('publicationStats')->getTotals($filter);
foreach ($rawReport as $row) {
$unorderedResults[$row->submission_id]['metric'] = $row->metric;
}
Expand Down
3 changes: 1 addition & 2 deletions classes/submission/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace APP\submission;

use APP\article\ArticleTombstoneManager;
use APP\core\Services;
use APP\facades\Repo;
use APP\journal\JournalDAO;
use APP\section\Section;
Expand Down Expand Up @@ -120,7 +119,7 @@ public function updateStatus(Submission $submission, ?int $newStatus = null, ?Se
if ($requestContext && $requestContext->getId() === $submission->getData('contextId')) {
$context = $requestContext;
} else {
$context = Services::get('context')->get($submission->getData('contextId'));
$context = app()->get('context')->get($submission->getData('contextId'));
}
$articleTombstoneManager = new ArticleTombstoneManager();
if (!$section) {
Expand Down
3 changes: 1 addition & 2 deletions classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

namespace APP\submission;

use APP\core\Services;
use APP\facades\Repo;
use APP\publication\Publication;
use PKP\facades\Locale;
Expand Down Expand Up @@ -56,7 +55,7 @@ class Submission extends PKPSubmission
*/
public function _getContextLicenseFieldValue($locale, $field, $publication = null)
{
$context = Services::get('context')->get($this->getData('contextId'));
$context = app()->get('context')->get($this->getData('contextId'));
$fieldValue = null; // Scrutinizer
switch ($field) {
case self::PERMISSIONS_FIELD_LICENSE_URL:
Expand Down
3 changes: 1 addition & 2 deletions classes/sushi/IR.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace APP\sushi;

use APP\core\Services;
use APP\facades\Repo;
use PKP\statistics\PKPStatisticsHelper;
use PKP\sushi\CounterR5Report;
Expand Down Expand Up @@ -219,7 +218,7 @@ public function getReportItems(): array
}
// do not consider metric_type filter now, but for display

$statsService = Services::get('sushiStats');
$statsService = app()->get('sushiStats');
$metricsQB = $statsService->getQueryBuilder($params);
// consider attributes to group the metrics by
$groupBy = ['m.' . PKPStatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID];
Expand Down
3 changes: 1 addition & 2 deletions classes/sushi/PR.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace APP\sushi;

use APP\core\Services;
use PKP\statistics\PKPStatisticsHelper;
use PKP\sushi\CounterR5Report;

Expand Down Expand Up @@ -135,7 +134,7 @@ public function getReportItems(): array
$params['dateEnd'] = $this->endDate;
// do not consider metric_type filter now, but for display

$statsService = Services::get('sushiStats');
$statsService = app()->get('sushiStats');
$metricsQB = $statsService->getQueryBuilder($params);
$groupBy = [];
// consider granularity=Month to group the metrics by month
Expand Down
3 changes: 1 addition & 2 deletions classes/sushi/TR.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace APP\sushi;

use APP\core\Services;
use PKP\statistics\PKPStatisticsHelper;
use PKP\sushi\CounterR5Report;

Expand Down Expand Up @@ -178,7 +177,7 @@ public function getReportItems(): array
$params['yearsOfPublication'] = $this->yearsOfPublication;
// do not consider metric_type filter now, but for display

$statsService = Services::get('sushiStats');
$statsService = app()->get('sushiStats');
$metricsQB = $statsService->getQueryBuilder($params);
// consider attributes to group the metrics by
$groupBy = $orderBy = [];
Expand Down
3 changes: 1 addition & 2 deletions controllers/modals/publish/AssignToIssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use APP\components\forms\publication\AssignToIssueForm;
use APP\core\Application;
use APP\core\Request;
use APP\core\Services;
use APP\handler\Handler;
use APP\publication\Publication;
use APP\submission\Submission;
Expand Down Expand Up @@ -94,7 +93,7 @@ public function assign($args, $request)

$submissionContext = $request->getContext();
if (!$submissionContext || $submissionContext->getId() !== $this->submission->getData('contextId')) {
$submissionContext = Services::get('context')->get($this->submission->getData('contextId'));
$submissionContext = app()->get('context')->get($this->submission->getData('contextId'));
}

$publicationApiUrl = $request->getDispatcher()->url($request, PKPApplication::ROUTE_API, $submissionContext->getPath(), 'submissions/' . $this->submission->getId() . '/publications/' . $this->publication->getId());
Expand Down
7 changes: 3 additions & 4 deletions pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace APP\pages\article;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\handler\Handler;
use APP\issue\IssueAction;
Expand Down Expand Up @@ -493,11 +492,11 @@ public function download($args, $request)
if (!Hook::call('ArticleHandler::download', [$this->article, &$this->galley, &$this->submissionFileId])) {
$submissionFile = Repo::submissionFile()->get($this->submissionFileId);

if (!Services::get('file')->fs->has($submissionFile->getData('path'))) {
if (!app()->get('file')->fs->has($submissionFile->getData('path'))) {
$request->getDispatcher()->handle404();
}

$filename = Services::get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name'));
$filename = app()->get('file')->formatFilename($submissionFile->getData('path'), $submissionFile->getLocalizedData('name'));

// if the file is a galley file (i.e. not a dependent file e.g. CSS or images), fire an usage event.
if ($this->galley->getData('submissionFileId') == $this->submissionFileId) {
Expand All @@ -513,7 +512,7 @@ public function download($args, $request)
}
$returner = true;
Hook::call('FileManager::downloadFileFinished', [&$returner]);
Services::get('file')->download($submissionFile->getData('fileId'), $filename);
app()->get('file')->download($submissionFile->getData('fileId'), $filename);
}
} else {
header('HTTP/1.0 403 Forbidden');
Expand Down
6 changes: 1 addition & 5 deletions pages/search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace APP\pages\search;

use APP\core\Services;
use APP\facades\Repo;
use APP\handler\Handler;
use APP\search\ArticleSearch;
Expand All @@ -28,9 +27,6 @@ class SearchHandler extends Handler
/**
* @copydoc PKPHandler::authorize()
*
* @param mixed $request
* @param mixed $args
* @param mixed $roleAssignments
*/
public function authorize($request, &$args, $roleAssignments)
{
Expand Down Expand Up @@ -236,7 +232,7 @@ public function setupTemplate($request)

protected function getSearchableContexts(): array
{
$contextService = Services::get('context');
$contextService = app()->get('context');
return $contextService->getManySummary([
'isEnabled' => true,
]);
Expand Down
3 changes: 1 addition & 2 deletions pages/stats/StatsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use APP\core\Application;
use APP\core\Request;
use APP\core\Services;
use APP\facades\Repo;
use APP\template\TemplateManager;
use PKP\core\PKPApplication;
Expand Down Expand Up @@ -62,7 +61,7 @@ public function issues(array $args, Request $request): void
$dateEnd = date('Y-m-d', strtotime('yesterday'));
$count = 30;

$timeline = Services::get('issueStats')->getTimeline(PKPStatisticsHelper::STATISTICS_DIMENSION_DAY, [
$timeline = app()->get('issueStats')->getTimeline(PKPStatisticsHelper::STATISTICS_DIMENSION_DAY, [
'assocTypes' => [Application::ASSOC_TYPE_ISSUE],
'contextIds' => [$context->getId()],
'count' => $count,
Expand Down
3 changes: 1 addition & 2 deletions pages/workflow/WorkflowHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use APP\components\forms\publication\PublishForm;
use APP\core\Application;
use APP\core\Services;
use APP\decision\types\Accept;
use APP\decision\types\SkipExternalReview;
use APP\facades\Repo;
Expand Down Expand Up @@ -83,7 +82,7 @@ public function setupIndex($request)

$submissionContext = $request->getContext();
if ($submission->getData('contextId') !== $submissionContext->getId()) {
$submissionContext = Services::get('context')->get($submission->getData('contextId'));
$submissionContext = app()->get('context')->get($submission->getData('contextId'));
}

$latestPublication = $submission->getLatestPublication();
Expand Down
3 changes: 1 addition & 2 deletions plugins/generic/datacite/DatacitePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace APP\plugins\generic\datacite;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\issue\Issue;
use APP\plugins\generic\datacite\classes\DataciteSettings;
Expand Down Expand Up @@ -203,7 +202,7 @@ public function isPluginConfigured(Context $context): bool
$settingsObject = $this->getSettingsObject();

/** @var PKPSchemaService $schemaService */
$schemaService = Services::get('schema');
$schemaService = app()->get('schema');
$requiredProps = $schemaService->getRequiredProps($settingsObject::class);

foreach ($requiredProps as $requiredProp) {
Expand Down
5 changes: 2 additions & 3 deletions plugins/generic/datacite/filter/DataciteXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use APP\author\Author;
use APP\core\Application;
use APP\core\Services;
use APP\decision\Decision;
use APP\facades\Repo;
use APP\issue\Issue;
Expand Down Expand Up @@ -699,8 +698,8 @@ public function createSizesNode($doc, $issue, $article, $publication, $galley, $
// The galley represents the article.
if (isset($galleyFile)) {
$path = $galleyFile->getData('path');
$size = Services::get('file')->fs->fileSize($path);
$sizes[] = Services::get('file')->getNiceFileSize($size);
$size = app()->get('file')->fs->fileSize($path);
$sizes[] = app()->get('file')->getNiceFileSize($size);
}
break;
case isset($issue):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace APP\plugins\generic\htmlArticleGalley;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\file\PublicFileManager;
use APP\observers\events\UsageEvent;
Expand Down Expand Up @@ -165,7 +164,7 @@ protected function _getHTMLContents($request, $galley)
{
$submissionFile = $galley->getFile();
$submissionId = $submissionFile->getData('submissionId');
$contents = Services::get('file')->fs->read($submissionFile->getData('path'));
$contents = app()->get('file')->fs->read($submissionFile->getData('path'));

// Replace media file references
$embeddableFiles = Repo::submissionFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use APP\author\Author;
use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\handler\Handler;
use APP\search\ArticleSearch;
Expand Down Expand Up @@ -124,7 +123,7 @@ public function callbackTemplateArticlePageFooter($hookName, $params)
$orderedResults = [];
if ($results) {
// pkp/pkp-lib#9512: Check $results above, as an empty list of submissionIds is treated as no filter at all.
$statsReport = Services::get('publicationStats')->getTotals($filters);
$statsReport = app()->get('publicationStats')->getTotals($filters);
foreach ($statsReport as $reportRow) {
$orderedResults[] = $reportRow->{StatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID};
}
Expand Down
3 changes: 1 addition & 2 deletions plugins/reports/counter/CounterReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace APP\plugins\reports\counter;

use APP\core\Application;
use APP\core\Services;
use APP\notification\NotificationManager;
use APP\statistics\StatisticsHelper;
use APP\template\TemplateManager;
Expand Down Expand Up @@ -220,7 +219,7 @@ public function _getYears()
'contextIds' => [Application::get()->getRequest()->getContext()->getId()],
'assocTypes' => [Application::ASSOC_TYPE_SUBMISSION_FILE]
];
$metricsQB = Services::get('publicationStats')->getQueryBuilder($filters);
$metricsQB = app()->get('publicationStats')->getQueryBuilder($filters);
$metricsQB = $metricsQB->getSum([StatisticsHelper::STATISTICS_DIMENSION_YEAR]);
$metricsQB->orderBy(StatisticsHelper::STATISTICS_DIMENSION_YEAR, StatisticsHelper::STATISTICS_ORDER_ASC);
$results = $metricsQB->get()->toArray();
Expand Down
3 changes: 1 addition & 2 deletions plugins/reports/counter/classes/reports/CounterReportAR1.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace APP\plugins\reports\counter\classes\reports;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\journal\JournalDAO;
use APP\plugins\reports\counter\classes\CounterReport;
Expand Down Expand Up @@ -118,7 +117,7 @@ public function getReportItems($columns = [], $filters = [], $orderBy = [], $ran
}
}
// TODO: range
$results = Services::get('publicationStats')
$results = app()->get('publicationStats')
->getQueryBuilder($validFilters)
->getSum($defaultColumns)
->orderBy(StatisticsHelper::STATISTICS_DIMENSION_SUBMISSION_ID, StatisticsHelper::STATISTICS_ORDER_DESC)
Expand Down
3 changes: 1 addition & 2 deletions plugins/reports/counter/classes/reports/CounterReportJR1.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace APP\plugins\reports\counter\classes\reports;

use APP\core\Application;
use APP\core\Services;
use APP\journal\JournalDAO;
use APP\plugins\reports\counter\classes\CounterReport;
use APP\statistics\StatisticsHelper;
Expand Down Expand Up @@ -82,7 +81,7 @@ public function getReportItems($columns = [], $filters = [], $orderBy = [], $ran
$this->setError(new Exception(__('plugins.reports.counter.exception.filter'), COUNTER_EXCEPTION_WARNING | COUNTER_EXCEPTION_BAD_FILTERS));
}
// TODO: range
$results = Services::get('publicationStats')->getQueryBuilder($validFilters)
$results = app()->get('publicationStats')->getQueryBuilder($validFilters)
->getSum($defaultColumns)
// Ordering must be by Journal (ReportItem), and by Month (ItemPerformance) for JR1
->orderBy(StatisticsHelper::STATISTICS_DIMENSION_CONTEXT_ID, StatisticsHelper::STATISTICS_ORDER_DESC)
Expand Down

0 comments on commit 6a1cc0c

Please sign in to comment.