Skip to content

Commit

Permalink
NGSTACK-842: inject services directly
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Jun 28, 2024
1 parent 72c299e commit aefb59d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions bundle/Command/ScheduledVisibilityUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\ContentTypeService;
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\LanguageService;
use Ibexa\Contracts\Core\Repository\Repository;
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\Configuration;
Expand Down Expand Up @@ -35,6 +38,9 @@ final class ScheduledVisibilityUpdateCommand extends Command

public function __construct(
private readonly Repository $repository,
private readonly ContentService $contentService,
private readonly ContentTypeService $contentTypeService,
private readonly LanguageService $languageService,
private readonly ScheduledVisibilityService $scheduledVisibilityService,
private readonly Configuration $configurationService,
private readonly Connection $connection,
Expand Down Expand Up @@ -159,7 +165,7 @@ private function processResults(array $results, ProgressBar $progressBar): void

/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */
$content = $this->repository->sudo(
fn () => $this->repository->getContentService()->loadContent(
fn () => $this->contentService->loadContent(
$contentId,
[$language->getLanguageCode()],
),
Expand Down Expand Up @@ -222,6 +228,9 @@ private function applySince(QueryBuilder $queryBuilder, ?int $since): void
;
}

/**
* @param int[] $contentTypeIds
*/
private function applyContentTypes(QueryBuilder $query, array $contentTypeIds): void
{
if (count($contentTypeIds) === 0) {
Expand Down Expand Up @@ -270,7 +279,7 @@ private function getContentTypeIds(): array

foreach ($allowedContentTypes as $allowedContentType) {
try {
$contentTypeIds[] = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($allowedContentType)->id;
$contentTypeIds[] = $this->contentTypeService->loadContentTypeByIdentifier($allowedContentType)->id;
} catch (NotFoundException $exception) {
$this->logger->error(
sprintf(
Expand All @@ -290,7 +299,7 @@ private function getContentTypeIds(): array
private function loadLanguage(int $id): Language
{
if (!isset($this->languageCache[$id])) {
$language = $this->repository->getContentLanguageService()->loadLanguageById($id);
$language = $this->languageService->loadLanguageById($id);
$this->languageCache[$id] = $language;
}

Expand Down
3 changes: 3 additions & 0 deletions bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ services:
Netgen\Bundle\IbexaScheduledVisibilityBundle\Command\ScheduledVisibilityUpdateCommand:
arguments:
- '@ibexa.api.repository'
- '@ibexa.api.service.content'
- '@ibexa.api.service.content_type'
- '@ibexa.api.service.language'
- '@Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\ScheduledVisibilityService'
- '@Netgen\Bundle\IbexaScheduledVisibilityBundle\Core\Configuration'
- '@ibexa.persistence.connection'
Expand Down

0 comments on commit aefb59d

Please sign in to comment.