Skip to content

Commit

Permalink
Add options of --if-not-exists to eccube:plugin:install
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Dec 20, 2023
1 parent cae3bf9 commit d00534b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Eccube/Command/PluginInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function configure()
$this
->addOption('path', null, InputOption::VALUE_OPTIONAL, 'path of tar or zip')
->addOption('code', null, InputOption::VALUE_OPTIONAL, 'plugin code')
->addOption('if-not-exists', null, InputOption::VALUE_NONE, 'If plugin is already installed, skip install.')
->setDescription('Install plugin from local.');
}

Expand All @@ -38,10 +39,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$path = $input->getOption('path');
$code = $input->getOption('code');
$ifNotExists = $input->getOption('if-not-exists');

// アーカイブからインストール
if ($path) {
if ($this->pluginService->install($path)) {
if ($this->pluginService->install($path, $ifNotExists)) {
$io->success('Installed.');

return 0;
Expand All @@ -50,7 +52,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// 設置済ファイルからインストール
if ($code) {
$this->pluginService->installWithCode($code);
$this->pluginService->installWithCode($code, $ifNotExists);
$this->clearCache($io);
$io->success('Installed.');

Expand Down
26 changes: 21 additions & 5 deletions src/Eccube/Service/PluginService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ public function __construct(
*
* @param string $path path to tar.gz/zip plugin file
* @param int $source
* @param bool $notExists
*
* @return boolean
*
* @throws PluginException
* @throws \Exception
*/
public function install($path, $source = 0)
public function install($path, $source = 0, $notExists = false)
{
$pluginBaseDir = null;
$tmp = null;
Expand Down Expand Up @@ -194,6 +195,11 @@ public function install($path, $source = 0)
$this->postInstall($config, $source);
} catch (PluginException $e) {
$this->deleteDirs([$tmp, $pluginBaseDir]);
if ($e->getMessage() === 'plugin already installed.' && $notExists) {

return true;
}

throw $e;
} catch (\Exception $e) {
// インストーラがどんなExceptionを上げるかわからないので
Expand All @@ -206,10 +212,11 @@ public function install($path, $source = 0)

/**
* @param $code string sプラグインコード
* @param bool $notExists
*
* @throws PluginException
*/
public function installWithCode($code)
public function installWithCode($code, $notExists = false)
{
$this->pluginContext->setCode($code);
$this->pluginContext->setInstall();
Expand All @@ -235,9 +242,18 @@ public function installWithCode($code)
}
}

$this->checkSamePlugin($config['code']);
$this->copyAssets($config['code']);
$this->postInstall($config, $config['source']);
try {
$this->checkSamePlugin($config['code']);
$this->copyAssets($config['code']);
$this->postInstall($config, $config['source']);
} catch (PluginException $e) {
if ($e->getMessage() === 'plugin already installed.' && $notExists) {

return true;
}

throw $e;
}
}

// インストール事前処理
Expand Down

0 comments on commit d00534b

Please sign in to comment.