Skip to content

Commit

Permalink
pkp#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 Aug 1, 2024
1 parent c632e47 commit 475b8be
Show file tree
Hide file tree
Showing 79 changed files with 168 additions and 248 deletions.
3 changes: 1 addition & 2 deletions api/v1/_library/PKPLibraryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace PKP\API\v1\_library;

use APP\core\Application;
use APP\core\Services;
use APP\file\LibraryFileManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -142,7 +141,7 @@ protected function fileToResponse(LibraryFile $file, LibraryFileManager $library
'filename' => $file->getServerFileName(),
'name' => $file->getName(null),
'mimetype' => $file->getFileType(),
'documentType' => Services::get('file')->getDocumentType($file->getFileType()),
'documentType' => app()->get('file')->getDocumentType($file->getFileType()),
'submissionId' => $file->getSubmissionId() ?? 0,
'type' => $file->getType(),
'typeName' => __($libraryFileManager->getTitleKeyFromType($file->getType())),
Expand Down
3 changes: 1 addition & 2 deletions api/v1/_payments/PKPBackendPaymentsSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace PKP\API\v1\_payments;

use APP\core\Services;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand Down Expand Up @@ -94,7 +93,7 @@ public function edit(Request $illuminateRequest): JsonResponse
$request = $this->getRequest();
$context = $request->getContext();
$params = $illuminateRequest->input();
$contextService = Services::get('context');
$contextService = app()->get('context');

// Process query params to format incoming data as needed
foreach ($illuminateRequest->input() as $param => $val) {
Expand Down
21 changes: 10 additions & 11 deletions api/v1/contexts/PKPContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace PKP\API\v1\contexts;

use APP\core\Application;
use APP\core\Services;
use APP\plugins\IDoiRegistrationAgency;
use APP\services\ContextService;
use APP\template\TemplateManager;
Expand Down Expand Up @@ -181,7 +180,7 @@ public function getMany(Request $illuminateRequest): JsonResponse
}
}

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$items = [];
$contextsIterator = $contextService->getMany($allowedParams);
$propertyArgs = [
Expand All @@ -208,7 +207,7 @@ public function get(Request $illuminateRequest): JsonResponse
$request = $this->getRequest();
$user = $request->getUser();

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get((int) $illuminateRequest->route('contextId'));

if (!$context) {
Expand Down Expand Up @@ -254,7 +253,7 @@ public function getTheme(Request $illuminateRequest): JsonResponse
$request = $this->getRequest();
$user = $request->getUser();

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get((int) $illuminateRequest->route('contextId'));

if (!$context) {
Expand Down Expand Up @@ -339,7 +338,7 @@ public function add(Request $illuminateRequest): JsonResponse
}
}

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$errors = $contextService->validate(EntityWriteInterface::VALIDATE_ACTION_ADD, $params, $allowedLocales, $primaryLocale);

if (!empty($errors)) {
Expand Down Expand Up @@ -382,7 +381,7 @@ public function edit(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get($contextId);

if (!$context) {
Expand Down Expand Up @@ -445,7 +444,7 @@ public function editTheme(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get($contextId);

if (!$context) {
Expand Down Expand Up @@ -549,7 +548,7 @@ public function editDoiRegistrationAgencyPlugin(Request $illuminateRequest): Jso
], Response::HTTP_FORBIDDEN);
}

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get($contextId);

if (!$context) {
Expand All @@ -565,7 +564,7 @@ public function editDoiRegistrationAgencyPlugin(Request $illuminateRequest): Jso
], Response::HTTP_FORBIDDEN);
}

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

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_CONTEXT, $illuminateRequest->input());
$contextFullProps = array_flip($schemaService->getFullProps(PKPSchemaService::SCHEMA_CONTEXT));
Expand Down Expand Up @@ -683,7 +682,7 @@ public function delete(Request $illuminateRequest): JsonResponse

$contextId = (int) $illuminateRequest->route('contextId');

$contextService = Services::get('context'); /** @var PKPContextService $contextService */
$contextService = app()->get('context'); /** @var PKPContextService $contextService */
$context = $contextService->get($contextId);

if (!$context) {
Expand Down Expand Up @@ -712,7 +711,7 @@ public function delete(Request $illuminateRequest): JsonResponse
*/
protected function updateRegistrationAgencyPluginSettings(int $contextId, Plugin $plugin, string $schemaName, array $props): void
{
$schemaService = Services::get('schema'); /** @var PKPSchemaService $schemaService */
$schemaService = app()->get('schema'); /** @var PKPSchemaService $schemaService */
$sanitizedProps = $schemaService->sanitize($schemaName, $props);

foreach ($sanitizedProps as $fieldName => $value) {
Expand Down
7 changes: 3 additions & 4 deletions api/v1/site/PKPSiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
namespace PKP\API\v1\site;

use APP\core\Application;
use APP\core\Services;
use APP\template\TemplateManager;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -101,7 +100,7 @@ public function get(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();

$siteProps = Services::get('site')
$siteProps = app()->get('site')
->getFullProperties($request->getSite(), [
'request' => $request,
]);
Expand Down Expand Up @@ -149,7 +148,7 @@ public function edit(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$site = $request->getSite();
$siteService = Services::get('site');
$siteService = app()->get('site');

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_SITE, $illuminateRequest->input());

Expand All @@ -175,7 +174,7 @@ public function editTheme(Request $illuminateRequest): JsonResponse
{
$request = $this->getRequest();
$site = $request->getSite();
$siteService = Services::get('site');
$siteService = app()->get('site');

$params = $illuminateRequest->input();

Expand Down
23 changes: 11 additions & 12 deletions api/v1/stats/contexts/PKPStatsContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace PKP\API\v1\stats\contexts;

use APP\core\Services;
use APP\services\ContextService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -157,7 +156,7 @@ public function getMany(Request $illuminateRequest): StreamedResponse|JsonRespon
}

// Get a list of contexts with their total views matching the params
$statsService = Services::get('contextStats'); /** @var PKPStatsContextService $statsService */
$statsService = app()->get('contextStats'); /** @var PKPStatsContextService $statsService */
$totalMetrics = $statsService->getTotals($allowedParams);

// Get the stats for each context
Expand Down Expand Up @@ -223,7 +222,7 @@ public function getManyTimeline(Request $illuminateRequest): StreamedResponse|Js
], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('contextStats'); /** @var PKPStatsContextService $statsService */
$statsService = app()->get('contextStats'); /** @var PKPStatsContextService $statsService */

// Identify contexts which should be included in the results when a searchPhrase is passed
if (!empty($allowedParams['searchPhrase'])) {
Expand Down Expand Up @@ -261,7 +260,7 @@ public function get(Request $illuminateRequest): StreamedResponse|JsonResponse
$responseCSV = str_contains($illuminateRequest->headers->get('Accept'), 'text/csv') ? true : false;

$request = $this->getRequest();
$contextService = Services::get('context'); /** @var ContextService $contextService */
$contextService = app()->get('context'); /** @var ContextService $contextService */

$context = $contextService->get((int) $illuminateRequest->route('contextId', null));
if (!$context) {
Expand Down Expand Up @@ -293,7 +292,7 @@ public function get(Request $illuminateRequest): StreamedResponse|JsonResponse
$dateStart = array_key_exists('dateStart', $allowedParams) ? $allowedParams['dateStart'] : null;
$dateEnd = array_key_exists('dateEnd', $allowedParams) ? $allowedParams['dateEnd'] : null;

$statsService = Services::get('contextStats');
$statsService = app()->get('contextStats');
$contextViews = $statsService->getTotal($context->getId(), $dateStart, $dateEnd);

// Get basic context details for display
Expand Down Expand Up @@ -324,7 +323,7 @@ public function getTimeline(Request $illuminateRequest): StreamedResponse|JsonRe
$responseCSV = str_contains($illuminateRequest->headers->get('Accept'), 'text/csv') ? true : false;

$request = $this->getRequest();
$contextService = Services::get('context'); /** @var ContextService $contextService */
$contextService = app()->get('context'); /** @var ContextService $contextService */

$context = $contextService->get((int) $illuminateRequest->route('contextId'));
if (!$context) {
Expand Down Expand Up @@ -368,11 +367,11 @@ public function getTimeline(Request $illuminateRequest): StreamedResponse|JsonRe
], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('contextStats'); /** @var PKPStatsContextService $statsService */
$statsService = app()->get('contextStats'); /** @var PKPStatsContextService $statsService */
$data = $statsService->getTimeline($allowedParams['timelineInterval'], $allowedParams);

if ($responseCSV) {
$csvColumnNames = Services::get('contextStats')->getTimelineReportColumnNames();
$csvColumnNames = app()->get('contextStats')->getTimelineReportColumnNames();
return response()->withFile($data, $csvColumnNames, count($data));
}

Expand Down Expand Up @@ -432,7 +431,7 @@ protected function _processAllowedParams(array $requestParams, array $allowedPar
*/
protected function _processSearchPhrase(string $searchPhrase, array $contextIds = []): array
{
$searchPhraseContextIds = Services::get('context')->getIds(['searchPhrase' => $searchPhrase]);
$searchPhraseContextIds = app()->get('context')->getIds(['searchPhrase' => $searchPhrase]);
if (!empty($contextIds)) {
return array_intersect($contextIds, $searchPhraseContextIds->toArray());
}
Expand All @@ -457,7 +456,7 @@ protected function _getContextReportColumnNames(): array
protected function getItemForCSV(int $contextId, int $contextViews): array
{
// Get context title for display
$contexts = Services::get('context')->getManySummary([]);
$contexts = app()->get('context')->getManySummary([]);
// @todo: Avoid retrieving all contexts just to grab one item
$context = array_filter($contexts, function ($context) use ($contextId) {
return $context->id == $contextId;
Expand All @@ -480,8 +479,8 @@ protected function getItemForJSON(Request $illuminateRequest, int $contextId, in
'request' => $this->getRequest(),
'apiRequest' => $illuminateRequest,
];
$context = Services::get('context')->get($contextId);
$contextProps = Services::get('context')->getSummaryProperties($context, $propertyArgs);
$context = app()->get('context')->get($contextId);
$contextProps = app()->get('context')->getSummaryProperties($context, $propertyArgs);
return [
'total' => $contextViews,
'context' => $contextProps,
Expand Down
5 changes: 2 additions & 3 deletions api/v1/stats/editorial/PKPStatsEditorialController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace PKP\API\v1\stats\editorial;

use APP\core\Services;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand Down Expand Up @@ -145,7 +144,7 @@ function ($item) {
$item['name'] = __($item['name']);
return $item;
},
Services::get('editorialStats')->getOverview($params)
app()->get('editorialStats')->getOverview($params)
),
Response::HTTP_OK
);
Expand Down Expand Up @@ -188,7 +187,7 @@ public function getAverages(Request $illuminateRequest): JsonResponse

$params['contextIds'] = [$request->getContext()->getId()];

$statsEditorialService = Services::get('editorialStats'); /** @var \PKP\services\PKPStatsEditorialService $statsEditorialService */
$statsEditorialService = app()->get('editorialStats'); /** @var \PKP\services\PKPStatsEditorialService $statsEditorialService */

return response()->json($statsEditorialService->getAverages($params), Response::HTTP_OK);
}
Expand Down
17 changes: 8 additions & 9 deletions api/v1/stats/publications/PKPStatsPublicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace PKP\API\v1\stats\publications;

use APP\core\Application;
use APP\core\Services;
use APP\facades\Repo;
use APP\statistics\StatisticsHelper;
use APP\submission\Submission;
Expand Down Expand Up @@ -210,7 +209,7 @@ public function getMany(Request $illuminateRequest): StreamedResponse|JsonRespon
], $e->getCode());
}

$statsService = Services::get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$statsService = app()->get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */

// Get a list of top submissions by total views
$totalMetrics = $statsService->getTotals($allowedParams);
Expand Down Expand Up @@ -263,7 +262,7 @@ public function getManyTimeline(Request $illuminateRequest): StreamedResponse|Js

Hook::call('API::stats::publications::timeline::params', [&$allowedParams, $illuminateRequest]);

$statsService = Services::get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$statsService = app()->get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */

// Check/validate, filter and sanitize the request params
try {
Expand Down Expand Up @@ -320,7 +319,7 @@ public function get(Request $illuminateRequest): JsonResponse
return response()->json(['error' => $result], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$statsService = app()->get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */

// get abstract, pdf, html and other views for the submission
$dateStart = array_key_exists('dateStart', $allowedParams) ? $allowedParams['dateStart'] : null;
Expand Down Expand Up @@ -383,7 +382,7 @@ public function getTimeline(Request $illuminateRequest): JsonResponse
], Response::HTTP_BAD_REQUEST);
}

$statsService = Services::get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$statsService = app()->get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$data = $statsService->getTimeline($allowedParams['timelineInterval'], $allowedParams);

return response()->json($data, Response::HTTP_OK);
Expand Down Expand Up @@ -426,7 +425,7 @@ public function getManyFiles(Request $illuminateRequest): StreamedResponse|JsonR
return response()->json(['error' => $e->getMessage()], $e->getCode());
}

$statsService = Services::get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$statsService = app()->get('publicationStats'); /** @var \PKP\services\PKPStatsPublicationService $statsService */
$filesMetrics = $statsService->getFilesTotals($allowedParams);

$items = $submissionTitles = [];
Expand Down Expand Up @@ -500,7 +499,7 @@ public function getManyCountries(Request $illuminateRequest): StreamedResponse|J
return response()->json(['error' => $e->getMessage()], $e->getCode());
}

$statsService = Services::get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
$statsService = app()->get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
// Get a list of top countries by total views
$totals = $statsService->getTotals($allowedParams, StatisticsHelper::STATISTICS_DIMENSION_COUNTRY);

Expand Down Expand Up @@ -571,7 +570,7 @@ public function getManyRegions(Request $illuminateRequest): StreamedResponse|Jso
return response()->json(['error' => $e->getMessage()], $e->getCode());
}

$statsService = Services::get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
$statsService = app()->get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
// Get a list of top regions by total views
$totals = $statsService->getTotals($allowedParams, StatisticsHelper::STATISTICS_DIMENSION_REGION);

Expand Down Expand Up @@ -649,7 +648,7 @@ public function getManyCities(Request $illuminateRequest): StreamedResponse|Json
return response()->json(['error' => $e->getMessage()], $e->getCode());
}

$statsService = Services::get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
$statsService = app()->get('geoStats'); /** @var \PKP\services\PKPStatsGeoService $statsService */
// Get a list of top cities by total views
$totals = $statsService->getTotals($allowedParams, StatisticsHelper::STATISTICS_DIMENSION_CITY);

Expand Down
Loading

0 comments on commit 475b8be

Please sign in to comment.