Last active
March 3, 2023 13:42
-
-
Save patrickallaert/9013fa878c72ec4f494118efe3923ab2 to your computer and use it in GitHub Desktop.
Finds entries in `ezurl` table (Ibexa DXP) that are not in use anymore.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Command; | |
use Ibexa\Contracts\Core\Repository\PermissionResolver; | |
use Ibexa\Contracts\Core\Repository\URLService; | |
use Ibexa\Contracts\Core\Repository\UserService; | |
use Ibexa\Contracts\Core\Repository\Values\URL\Query\Criterion\MatchAll; | |
use Ibexa\Contracts\Core\Repository\Values\URL\URLQuery; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
class FindUnusedURLCommand extends Command | |
{ | |
protected static $defaultName = "app:find-unused-urls"; | |
public function __construct( | |
private readonly URLService $urlService, | |
private readonly UserService $userService, | |
private readonly PermissionResolver $permissionResolver, | |
) { | |
parent::__construct(); | |
} | |
protected function configure(): void | |
{ | |
$this->setDescription("Find unused URLs"); | |
} | |
// @phan-suppress-next-line PhanUnusedProtectedMethodParameter | |
protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | |
$this->permissionResolver->setCurrentUserReference($this->userService->loadUser(14)); | |
$query = new URLQuery(); | |
$query->filter = new MatchAll(); | |
$query->limit = \PHP_INT_MAX; | |
foreach ($this->urlService->findUrls($query) as $r) { | |
if ($this->urlService->findUsages($r)->totalCount === 0) { | |
$output->writeln("id: $r->id and url: $r->url"); | |
} | |
} | |
return Command::SUCCESS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment