Browse Source

[FEATURE] Add console command to create patch

tags/v1.8.2.4
Adam Bukowski 4 years ago
parent
commit
97e5ecc045
2 changed files with 61 additions and 0 deletions
  1. +1
    -0
      console.php
  2. +60
    -0
      console/Develop/CreatePatchCommand.php

+ 1
- 0
console.php View File

@@ -39,5 +39,6 @@ $application->add(new \Epesi\Console\Backup\BackupFilesCommand());
$application->add(new \Epesi\Console\Backup\BackupAllCommand());
$application->add(new \Epesi\Console\Backup\ListBackupsCommand());
$application->add(new \Epesi\Console\Develop\CreateModuleCommand());
$application->add(new \Epesi\Console\Develop\CreatePatchCommand());
$application->add(new \Epesi\Console\ShellCommand());
$application->run($input);

+ 60
- 0
console/Develop/CreatePatchCommand.php View File

@@ -0,0 +1,60 @@
<?php

namespace Epesi\Console\Develop;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class CreatePatchCommand extends Command
{
protected function configure()
{
$this
->setName('dev:module:patch')
->setDescription('Create EPESI module files')
->addArgument(
'module',
InputArgument::REQUIRED,
'Module name or location'
)
->addArgument(
'patch title',
InputArgument::REQUIRED,
'Patch Title'
)
->addOption('core', 'c', InputOption::VALUE_NONE, 'Create patch without date in filename')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$st = new SymfonyStyle($input, $output);

$module_name = $input->getArgument('module');
$patch_title = $input->getArgument('patch title');
$core = $input->getOption('core');

$module_name = str_replace('_', '/', $module_name);
$parts = explode('/', $module_name);
if ($parts[0] != 'modules') {
array_unshift($parts, 'modules');
}
$parts[] = 'patches';
$path = implode('/', $parts);
if (!file_exists($path)) {
mkdir($path);
}
$filename = ($core ? '' : date('Ymd_')) . preg_replace('/[^0-9a-z_]/', '_', strtolower($patch_title)) . '.php';
$filepath = "$path/$filename";
if (file_exists($filepath)) {
$st->error("Patch already exists: $filepath");
} else {
file_put_contents($filepath, "<?php\n\ndefined(\"_VALID_ACCESS\") || die('Direct access forbidden');\n\n");
$st->success("Patch created: $filepath");
}
}
}

Loading…
Cancel
Save