mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-19 16:03:14 +00:00
clean:bases command
This commit is contained in:
@@ -6,6 +6,7 @@ use Alchemy\Phrasea\Command\Maintenance\CleanNotifications;
|
|||||||
use Alchemy\Phrasea\Command\Maintenance\CleanUsers;
|
use Alchemy\Phrasea\Command\Maintenance\CleanUsers;
|
||||||
use Alchemy\Phrasea\Core\Version;
|
use Alchemy\Phrasea\Core\Version;
|
||||||
use Alchemy\Phrasea\Command\Maintenance\CleanRecords;
|
use Alchemy\Phrasea\Command\Maintenance\CleanRecords;
|
||||||
|
use Alchemy\Phrasea\Command\Maintenance\CleanBases;
|
||||||
|
|
||||||
require_once __DIR__ . '/../lib/autoload.php';
|
require_once __DIR__ . '/../lib/autoload.php';
|
||||||
|
|
||||||
@@ -32,4 +33,6 @@ $cli->command(new CleanRecords());
|
|||||||
|
|
||||||
$cli->command(new CleanUsers());
|
$cli->command(new CleanUsers());
|
||||||
|
|
||||||
|
$cli->command(new CleanBases());
|
||||||
|
|
||||||
$cli->run();
|
$cli->run();
|
||||||
|
49
lib/Alchemy/Phrasea/Command/Maintenance/CleanBases.php
Normal file
49
lib/Alchemy/Phrasea/Command/Maintenance/CleanBases.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Command\Maintenance;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Collection\Reference\CollectionReference;
|
||||||
|
use Alchemy\Phrasea\Collection\Reference\DbalCollectionReferenceRepository;
|
||||||
|
use Alchemy\Phrasea\Command\Command;
|
||||||
|
use Alchemy\Phrasea\Databox\DataboxRepository;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
class CleanBases extends Command
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('clean:bases');
|
||||||
|
|
||||||
|
$this
|
||||||
|
->setDescription('remove orphan collections ')
|
||||||
|
->addOption('orphan', null, InputOption::VALUE_NONE, 'remove collections bas that refers a non existing sbas')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
/** @var DbalCollectionReferenceRepository $dbalCollectionReferenceRepository */
|
||||||
|
$dbalCollectionReferenceRepository = $this->container['repo.collection-references'];
|
||||||
|
|
||||||
|
/** @var DataboxRepository $databoxRepository */
|
||||||
|
$databoxRepository = $this->container['repo.databoxes'];
|
||||||
|
|
||||||
|
if ($input->getOption('orphan') === true) {
|
||||||
|
/** @var CollectionReference $collectionReference */
|
||||||
|
foreach ($dbalCollectionReferenceRepository->findAll() as $collectionReference) {
|
||||||
|
if ($databoxRepository->find($collectionReference->getDataboxId()) == null) {
|
||||||
|
// if the databox of the collectionReference not found, remove the collectionReference (bas)
|
||||||
|
try {
|
||||||
|
$dbalCollectionReferenceRepository->delete($collectionReference);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$output->writeln("Can't delete bas with base_id = " . $collectionReference->getBaseId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$output->writeln("No given options!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -24,9 +24,7 @@ class CleanRecords extends Command
|
|||||||
|
|
||||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$fromBaskets = $input->getOption('from_baskets');
|
if ($input->getOption('from_baskets') === true) {
|
||||||
|
|
||||||
if ($fromBaskets === true) {
|
|
||||||
$output->writeln("<info> Remove orphans records from basket</info>");
|
$output->writeln("<info> Remove orphans records from basket</info>");
|
||||||
$this->removeOrphansFromBasket();
|
$this->removeOrphansFromBasket();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user