diff options
Diffstat (limited to 'plugins/CoreConsole/Commands')
-rw-r--r-- | plugins/CoreConsole/Commands/GenerateArchiver.php | 2 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/GeneratePlugin.php | 16 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/GeneratePluginBase.php | 4 |
3 files changed, 13 insertions, 9 deletions
diff --git a/plugins/CoreConsole/Commands/GenerateArchiver.php b/plugins/CoreConsole/Commands/GenerateArchiver.php index bbbdb85dfc..29bcee7bb6 100644 --- a/plugins/CoreConsole/Commands/GenerateArchiver.php +++ b/plugins/CoreConsole/Commands/GenerateArchiver.php @@ -30,7 +30,7 @@ class GenerateArchiver extends GeneratePluginBase $this->checkAndUpdateRequiredPiwikVersion($pluginName, $output); $exampleFolder = PIWIK_INCLUDE_PATH . '/plugins/ExamplePlugin'; - $replace = array('ExamplePlugin' => ucfirst($pluginName), 'EXAMPLEPLUGIN' => strtoupper($pluginName)); + $replace = array('ExamplePlugin' => $pluginName, 'EXAMPLEPLUGIN' => strtoupper($pluginName)); $whitelistFiles = array('/Archiver.php'); $this->copyTemplateToPlugin($exampleFolder, $pluginName, $replace, $whitelistFiles); diff --git a/plugins/CoreConsole/Commands/GeneratePlugin.php b/plugins/CoreConsole/Commands/GeneratePlugin.php index c42d7a619b..bf83889305 100644 --- a/plugins/CoreConsole/Commands/GeneratePlugin.php +++ b/plugins/CoreConsole/Commands/GeneratePlugin.php @@ -12,6 +12,7 @@ namespace Piwik\Plugins\CoreConsole\Commands; use Piwik\Filesystem; use Piwik\Plugins\ExamplePlugin\ExamplePlugin; use Piwik\Version; +use Piwik\Plugin; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -28,7 +29,8 @@ class GeneratePlugin extends GeneratePluginBase ->setDescription('Generates a new plugin/theme including all needed files') ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Plugin name ([a-Z0-9_-])') ->addOption('description', null, InputOption::VALUE_REQUIRED, 'Plugin description, max 150 characters') - ->addOption('pluginversion', null, InputOption::VALUE_OPTIONAL, 'Plugin version'); + ->addOption('pluginversion', null, InputOption::VALUE_OPTIONAL, 'Plugin version') + ->addOption('overwrite', null, InputOption::VALUE_NONE, 'Generate even if plugin directory already exists.'); } protected function execute(InputInterface $input, OutputInterface $output) @@ -115,20 +117,24 @@ class GeneratePlugin extends GeneratePluginBase */ protected function getPluginName(InputInterface $input, OutputInterface $output) { + $overwrite = $input->getOption('overwrite'); + $self = $this; - $validate = function ($pluginName) use ($self) { + $validate = function ($pluginName) use ($self, $overwrite) { if (empty($pluginName)) { throw new \RuntimeException('You have to enter a plugin name'); } - if (!Filesystem::isValidFilename($pluginName)) { - throw new \RuntimeException(sprintf('The plugin name %s is not valid', $pluginName)); + if (!Plugin\Manager::getInstance()->isValidPluginName($pluginName)) { + throw new \RuntimeException(sprintf('The plugin name %s is not valid. The name must start with a letter and is only allowed to contain numbers and letters.', $pluginName)); } $pluginPath = $self->getPluginPath($pluginName); - if (file_exists($pluginPath)) { + if (file_exists($pluginPath) + && !$overwrite + ) { throw new \RuntimeException('A plugin with this name already exists'); } diff --git a/plugins/CoreConsole/Commands/GeneratePluginBase.php b/plugins/CoreConsole/Commands/GeneratePluginBase.php index c3fce493dc..9012839943 100644 --- a/plugins/CoreConsole/Commands/GeneratePluginBase.php +++ b/plugins/CoreConsole/Commands/GeneratePluginBase.php @@ -31,7 +31,7 @@ abstract class GeneratePluginBase extends ConsoleCommand private function getRelativePluginPath($pluginName) { - return '/plugins/' . ucfirst($pluginName); + return '/plugins/' . $pluginName; } private function createFolderWithinPluginIfNotExists($pluginNameOrCore, $folder) @@ -325,8 +325,6 @@ abstract class GeneratePluginBase extends ConsoleCommand $validate($pluginName); } - $pluginName = ucfirst($pluginName); - return $pluginName; } |