Skip to content

Commit

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

Reference: gh-47
  • Loading branch information
nikosdion committed Oct 18, 2023
1 parent 73cf8fb commit 733232e
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/CliCommand/SitesDisable.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:disable',
description: 'Disable a site',
hidden: false,
)]
#[ConfigAssertion(true)]
class SitesDisable 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)
->unpublish();

return Command::SUCCESS;
}

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

}
50 changes: 50 additions & 0 deletions src/CliCommand/SitesEnable.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:enable',
description: 'Enable a site',
hidden: false,
)]
#[ConfigAssertion(true)]
class SitesEnable 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)
->publish();

return Command::SUCCESS;
}

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

}

0 comments on commit 733232e

Please sign in to comment.