seeddms-code/utils/Commands/PackageextensionCommand.php
2025-11-13 18:57:22 +01:00

80 lines
2.9 KiB
PHP

<?php
namespace Seeddms\Console\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Seeddms\Seeddms\Settings;
use Seeddms\Seeddms\Translator;
use SeedDMS_Core_File;
use SeedDMS_View_Common;
use SeedDMS_Extension_Mgr;
use Log_file;
class PackageextensionCommand extends Command
{
protected $settings;
protected $logger;
protected $translator;
protected $extmgr;
public function __construct(Settings $settings, Log_file $logger, Translator $translator, SeedDMS_Extension_Mgr $extmgr)
{
$this->settings = $settings;
$this->logger = $logger;
$this->translator = $translator;
$this->extmgr = $extmgr;
parent::__construct();
}
protected function configure()
{
$this->setName('ext:package')
->setDescription('Package extension as a zip file')
->setHelp('Creates a zip file of an extension, which can be uploaded into SeedDMS. If --output-dir is given, the zip file will be placed into this directory otherwise it will be saved in the current directory. The name of the zip file will be <extname>-<version>.zip. If such a file already exists, it will be deleted and recreated.')
->addOption('name', '', InputOption::VALUE_REQUIRED, 'Name of extension.', null)
->addOption('output-dir', '', InputOption::VALUE_REQUIRED, 'Name of directory where the zip file is saved.', null)
;
}
protected function execute(InputInterface $input, OutputInterface $output) : int
{
$settings = $this->settings;
$logger = $this->logger;
$translator = $this->translator;
$extmgr = $this->extmgr;
$output->writeln("<comment>Using configuration from '".$settings->_configFilePath."'.</comment>", OutputInterface::VERBOSITY_VERBOSE);
$extconf = $extmgr->getExtensionConfiguration();
$extname = $input->getOption('name');
if (!isset($extconf[$extname])) {
$output->writeln(sprintf("<error>No such extension '%s'</error>", $extname));
return Command::FAILURE;
}
$outputdir = $input->getOption('output-dir');
if(!$outputdir)
$outputdir = '.';
/* If the $outputdir is not passed to createArchive(), the cache
* dir of SeedDMS will be used, which requires to run this script
* with sufficient access rights on that directory.
*/
$filename = $extmgr->createArchive($extname, $extmgr->getExtensionConfiguration()[$extname]['version'], $outputdir);
$output->writeln(sprintf("Extension saved as '%s'", $filename));
return Command::SUCCESS;
}
}
// vim: ts=4 sw=4 expandtab