Skip to content

Commit 733232e

Browse files
committed
CLI commands to manage sites
Implement `sites:enable` and `sites:disable` Reference: gh-47
1 parent 73cf8fb commit 733232e

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

src/CliCommand/SitesDisable.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* @package panopticon
4+
* @copyright Copyright (c)2023-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
5+
* @license https://www.gnu.org/licenses/agpl-3.0.txt GNU Affero General Public License, version 3 or later
6+
*/
7+
8+
namespace Akeeba\Panopticon\CliCommand;
9+
10+
defined('AKEEBA') || die;
11+
12+
use Akeeba\Panopticon\CliCommand\Attribute\ConfigAssertion;
13+
use Akeeba\Panopticon\Factory;
14+
use Akeeba\Panopticon\Model\Sites;
15+
use Symfony\Component\Console\Attribute\AsCommand;
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
#[AsCommand(
22+
name: 'sites:disable',
23+
description: 'Disable a site',
24+
hidden: false,
25+
)]
26+
#[ConfigAssertion(true)]
27+
class SitesDisable extends AbstractCommand
28+
{
29+
protected function execute(InputInterface $input, OutputInterface $output): int
30+
{
31+
$container = Factory::getContainer();
32+
/** @var Sites $model */
33+
$model = $container->mvcFactory->makeTempModel('Sites');
34+
35+
$id = intval($input->getArgument('id'));
36+
37+
$model
38+
->findOrFail($id)
39+
->unpublish();
40+
41+
return Command::SUCCESS;
42+
}
43+
44+
protected function configure(): void
45+
{
46+
$this
47+
->addArgument('id', InputArgument::REQUIRED, 'The numeric site ID to disable');
48+
}
49+
50+
}

src/CliCommand/SitesEnable.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* @package panopticon
4+
* @copyright Copyright (c)2023-2023 Nicholas K. Dionysopoulos / Akeeba Ltd
5+
* @license https://www.gnu.org/licenses/agpl-3.0.txt GNU Affero General Public License, version 3 or later
6+
*/
7+
8+
namespace Akeeba\Panopticon\CliCommand;
9+
10+
defined('AKEEBA') || die;
11+
12+
use Akeeba\Panopticon\CliCommand\Attribute\ConfigAssertion;
13+
use Akeeba\Panopticon\Factory;
14+
use Akeeba\Panopticon\Model\Sites;
15+
use Symfony\Component\Console\Attribute\AsCommand;
16+
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
21+
#[AsCommand(
22+
name: 'sites:enable',
23+
description: 'Enable a site',
24+
hidden: false,
25+
)]
26+
#[ConfigAssertion(true)]
27+
class SitesEnable extends AbstractCommand
28+
{
29+
protected function execute(InputInterface $input, OutputInterface $output): int
30+
{
31+
$container = Factory::getContainer();
32+
/** @var Sites $model */
33+
$model = $container->mvcFactory->makeTempModel('Sites');
34+
35+
$id = intval($input->getArgument('id'));
36+
37+
$model
38+
->findOrFail($id)
39+
->publish();
40+
41+
return Command::SUCCESS;
42+
}
43+
44+
protected function configure(): void
45+
{
46+
$this
47+
->addArgument('id', InputArgument::REQUIRED, 'The numeric site ID to enable');
48+
}
49+
50+
}

0 commit comments

Comments
 (0)