Skip to content

Commit

Permalink
CLI commands to manage sites
Browse files Browse the repository at this point in the history
Implement `sites:delete`

Reference: gh-47
  • Loading branch information
nikosdion committed Oct 18, 2023
1 parent 6ef17d4 commit 28a3b23
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/CliCommand/SitesDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @package panopticon
* @copyright Copyright (c)2023-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license https://www.gnu.org/licenses/agpl-3.0.txt GNU Affero General Public License, version 3 or later
*/

namespace Akeeba\Panopticon\CliCommand;

defined('AKEEBA') || die;

use Akeeba\Panopticon\CliCommand\Attribute\ConfigAssertion;
use Akeeba\Panopticon\Factory;
use Akeeba\Panopticon\Model\Sites;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'sites:delete',
description: 'Delete a site',
hidden: false,
)]
#[ConfigAssertion(true)]
class SitesDelete extends AbstractCommand
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$container = Factory::getContainer();
/** @var Sites $model */
$model = $container->mvcFactory->makeTempModel('Sites');

$id = intval($input->getArgument('id'));

$model
->findOrFail($id)
->delete();

return Command::SUCCESS;
}

protected function configure(): void
{
$this
->addArgument('id', InputArgument::REQUIRED, 'The numeric site ID to delete');
}

}
14 changes: 14 additions & 0 deletions src/Model/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,20 @@ protected function isSiteSpecificTaskScheduled(string $type): bool
);
}

protected function onBeforeDelete($id)
{
if (empty($id))
{
return;
}

// Remove all tasks attached to this site
/** @var Tasks $taskModel */
$taskModel = $this->getContainer()->mvcFactory->makeTempModel('Tasks');
$taskModel->setState('site_id', $id);
$taskModel->get(true)->delete();
}

private function applyUserGroupsToQuery(Query $query): void
{
if (defined('AKEEBA_CLI'))
Expand Down

0 comments on commit 28a3b23

Please sign in to comment.