Skip to content

Commit 00294e3

Browse files
committed
[ticket/11998] Turn develop/extensions.php into console commands.
PHPBB3-11998
1 parent 73ea5da commit 00294e3

7 files changed

Lines changed: 249 additions & 129 deletions

File tree

phpBB/config/console.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
services:
2+
console.command.extension.disable:
3+
class: phpbb\console\command\extension\disable
4+
arguments:
5+
- @ext.manager
6+
tags:
7+
- { name: console.command }
8+
9+
console.command.extension.enable:
10+
class: phpbb\console\command\extension\enable
11+
arguments:
12+
- @ext.manager
13+
tags:
14+
- { name: console.command }
15+
16+
console.command.extension.purge:
17+
class: phpbb\console\command\extension\purge
18+
arguments:
19+
- @ext.manager
20+
tags:
21+
- { name: console.command }
22+
23+
console.command.extension.show:
24+
class: phpbb\console\command\extension\show
25+
arguments:
26+
- @ext.manager
27+
tags:
28+
- { name: console.command }
29+
230
console.command.fixup.recalculate_email_hash:
331
class: phpbb\console\command\fixup\recalculate_email_hash
432
arguments:

phpBB/develop/extensions.php

Lines changed: 0 additions & 129 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB3
5+
* @copyright (c) 2013 phpBB Group
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
namespace phpbb\console\command\extension;
10+
11+
abstract class command extends \phpbb\console\command\command
12+
{
13+
/** @var \phpbb\extension\manager */
14+
protected $manager;
15+
16+
function __construct(\phpbb\extension\manager $manager)
17+
{
18+
$this->manager = $manager;
19+
20+
parent::__construct();
21+
}
22+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB3
5+
* @copyright (c) 2013 phpBB Group
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
namespace phpbb\console\command\extension;
10+
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class disable extends command
16+
{
17+
protected function configure()
18+
{
19+
$this
20+
->setName('extension:disable')
21+
->setDescription('Disables the specified extension.')
22+
->addArgument(
23+
'extension-name',
24+
InputArgument::REQUIRED,
25+
'Name of the extension'
26+
)
27+
;
28+
}
29+
30+
protected function execute(InputInterface $input, OutputInterface $output)
31+
{
32+
$name = $input->getArgument('extension-name');
33+
$this->manager->disable($name);
34+
$this->manager->load_extensions();
35+
36+
if ($this->manager->enabled($name))
37+
{
38+
$output->writeln("<error>Could not disable extension $name</error>");
39+
return 1;
40+
}
41+
else
42+
{
43+
$output->writeln("<info>Successfully disabled extension $name</info>");
44+
return 0;
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB3
5+
* @copyright (c) 2013 phpBB Group
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
namespace phpbb\console\command\extension;
10+
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class enable extends command
16+
{
17+
protected function configure()
18+
{
19+
$this
20+
->setName('extension:enable')
21+
->setDescription('Enables the specified extension.')
22+
->addArgument(
23+
'extension-name',
24+
InputArgument::REQUIRED,
25+
'Name of the extension'
26+
)
27+
;
28+
}
29+
30+
protected function execute(InputInterface $input, OutputInterface $output)
31+
{
32+
$name = $input->getArgument('extension-name');
33+
$this->manager->enable($name);
34+
$this->manager->load_extensions();
35+
36+
if ($this->manager->enabled($name))
37+
{
38+
$output->writeln("<info>Successfully enabled extension $name</info>");
39+
return 0;
40+
}
41+
else
42+
{
43+
$output->writeln("<error>Could not enable extension $name</error>");
44+
return 1;
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB3
5+
* @copyright (c) 2013 phpBB Group
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
namespace phpbb\console\command\extension;
10+
11+
use Symfony\Component\Console\Input\InputArgument;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class purge extends command
16+
{
17+
protected function configure()
18+
{
19+
$this
20+
->setName('extension:purge')
21+
->setDescription('Purges the specified extension.')
22+
->addArgument(
23+
'extension-name',
24+
InputArgument::REQUIRED,
25+
'Name of the extension'
26+
)
27+
;
28+
}
29+
30+
protected function execute(InputInterface $input, OutputInterface $output)
31+
{
32+
$name = $input->getArgument('extension-name');
33+
$this->manager->purge($name);
34+
$this->manager->load_extensions();
35+
36+
if ($this->manager->enabled($name))
37+
{
38+
$output->writeln("<error>Could not purge extension $name</error>");
39+
return 1;
40+
}
41+
else
42+
{
43+
$output->writeln("<info>Successfully purge extension $name</info>");
44+
return 0;
45+
}
46+
}
47+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
*
4+
* @package phpBB3
5+
* @copyright (c) 2013 phpBB Group
6+
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7+
*
8+
*/
9+
namespace phpbb\console\command\extension;
10+
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class show extends command
15+
{
16+
protected function configure()
17+
{
18+
$this
19+
->setName('extension:show')
20+
->setDescription('Lists all extensions in the database and on the filesystem.')
21+
;
22+
}
23+
24+
protected function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$this->manager->load_extensions();
27+
$all = array_keys($this->manager->all_available());
28+
29+
if (empty($all))
30+
{
31+
$output->writeln('<comment>No extensions were found.</comment>');
32+
return 3;
33+
}
34+
35+
$enabled = array_keys($this->manager->all_enabled());
36+
$this->print_extension_list($output, 'Enabled', $enabled);
37+
38+
$output->writeln('');
39+
40+
$disabled = array_keys($this->manager->all_disabled());
41+
$this->print_extension_list($output, 'Disabled', $disabled);
42+
43+
$output->writeln('');
44+
45+
$purged = array_diff($all, $enabled, $disabled);
46+
$this->print_extension_list($output, 'Available', $purged);
47+
}
48+
49+
protected function print_extension_list(OutputInterface $output, $type, array $extensions)
50+
{
51+
$output->writeln("<info>$type:</info>");
52+
53+
foreach ($extensions as $extension)
54+
{
55+
$output->writeln(" - $extension");
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)