Skip to content

Commit

Permalink
Merge pull request #9 from nenes25/0.4.x
Browse files Browse the repository at this point in the history
Release 0.4.x
  • Loading branch information
nenes25 authored Mar 14, 2024
2 parents 6ca738a + d73e05f commit 984b70b
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '**.php'
jobs:
php-linter:
name: PHP Syntax check 7.4|8.0|8.1
name: PHP Syntax check 7.4|8.0|8.1|8.2
runs-on: ubuntu-latest
steps:
- name: PHP syntax checker 7.4
Expand All @@ -17,6 +17,8 @@ jobs:
uses: prestashop/github-action-php-lint/8.0@master
- name: PHP syntax checker 8.1
uses: prestashop/github-action-php-lint/8.1@master
- name: PHP syntax checker 8.2
uses: prestashop/github-action-php-lint/8.2@master

# Check the PHP code follow the coding standards
php-cs-fixer:
Expand Down
6 changes: 4 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
V 0.3.1 2024-02- : #5 Unable to generate an upgrade if only 1 event
: #
V 0.4.0 2024-03-14 : #1 Harmonize logs and move them to global var directory
#5 Unable to generate an upgrade if only 1 event
#6 Allow to generate file upgrade from CLI
#7 Rename GenerateModulesUpgradeListCommand
V 0.3.0 2023-11-12 : Code refactoring and improvements
Allow to add your owns converters and upgraders from custom modules
Add a hook to allow custom modules to exclude some configurations from changes
Expand Down
8 changes: 6 additions & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ services:
class: Hhennes\ModulesManager\Commands\ManageModulesCommand
tags:
- { name: console.command }
hhennes.modulesmanager.upgrade.list:
class: Hhennes\ModulesManager\Commands\GenerateModulesUpgradeListCommand
hhennes.modulesmanager.upgradable.modules.list:
class: Hhennes\ModulesManager\Commands\ListUpgradableModulesCommand
tags:
- { name: console.command }
hhennes.modulesmanager.upgrade.generate:
class: Hhennes\ModulesManager\Commands\GeneratePatchCommand
tags:
- { name: console.command }
#Logger
Expand Down
2 changes: 1 addition & 1 deletion hhmodulesmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct()
{
$this->name = 'hhmodulesmanager';
$this->tab = 'administration';
$this->version = '0.3.1';
$this->version = '0.4.0';
$this->author = 'hhennes';
$this->bootstrap = true;
parent::__construct();
Expand Down
56 changes: 56 additions & 0 deletions src/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
namespace Hhennes\ModulesManager;

use Db;
use Exception;
use ObjectModel;
use Validate;

class Change extends ObjectModel
{
Expand Down Expand Up @@ -53,6 +55,60 @@ class Change extends ObjectModel
],
];

/**
* Récupération de la liste des changements par filtres
*
* @param array $filters
*
* @return array
*/
public static function getChangesByFilters(array $filters): array
{
try {
$filters = array_filter($filters);
if (count($filters)) {
$changeQuery = (new \DbQuery())->select('id_change')
->from(self::$definition['table']);
foreach ($filters as $key => $filter) {
switch ($key) {
case 'from_date':
if (!Validate::isDate($filter)) {
throw new Exception('Invalid filter "from date"');
}
$changeQuery->where("date_add >='" . $filter . "' OR date_upd >= '" . $filter . "'");
break;
case 'to_date':
if (!Validate::isDate($filter)) {
throw new Exception('Invalid filter "to date"');
}
$changeQuery->where("date_add <='" . $filter . "' OR date_upd <= '" . $filter . "'");
break;
default:
if (false !== strpos($filter, ',')) {
$filterParts = explode(',', $filter);
$cleanAttributes = array_map(function ($item) {
return "'" . pSQL(trim($item)) . "'";
}, $filterParts);
$cond = 'IN (' . implode(',', $cleanAttributes) . ')';
} else {
$cond = "= '" . $filter . "'";
}
$changeQuery->where($key . ' ' . $cond);
break;
}
}
$results = Db::getInstance()->executeS($changeQuery);
if ($results) {
return array_column($results, 'id_change');
}
}
} catch (Exception $e) {
dump(__METHOD__ . ' ' . $e->getMessage());
}

return [];
}

/**
* Installation sql de l'entité
*
Expand Down
78 changes: 78 additions & 0 deletions src/Commands/GeneratePatchCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file docs/licenses/LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author Hervé HENNES <[email protected]>
* @copyright since 2023 Hervé HENNES
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL") v. 3.0
*/

namespace Hhennes\ModulesManager\Commands;

use Exception;
use Hhennes\ModulesManager\Change;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This command allow to generate an upgrade file (patch) from the command line
*/
class GeneratePatchCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setName('hhennes:module-manager:generate')
->setDescription('Generate a an upgrade file')
->addOption('entity', null, InputOption::VALUE_OPTIONAL)
->addOption('action', null, InputOption::VALUE_OPTIONAL)
->addOption('key', null, InputOption::VALUE_OPTIONAL)
->addOption('from_date', null, InputOption::VALUE_OPTIONAL)
->addOption('to_date', null, InputOption::VALUE_OPTIONAL);
}

/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
try {
$filters = [
'entity' => $input->getOption('entity'),
'action' => $input->getOption('action'),
'key' => $input->getOption('key'),
'from_date' => $input->getOption('from_date'),
'to_date' => $input->getOption('to_date'),
];
$changeIds = Change::getChangesByFilters($filters);
if (count($changeIds)) {
/** @var \Hhennes\ModulesManager\Patch\Generator $patchGenerator */
$patchGenerator = $this->getContainer()->get('hhennes.modulesmanager.patch.generator');
$upgradeFileName = $patchGenerator->generateChangeFile($changeIds, date('Ymd-His') . '-patch');
$output->writeln(sprintf('<info>Upgrade file %s generated with success</info>', $upgradeFileName));
} else {
$output->writeln('<info>No changes found for update, no files was generated</info>');
}
} catch (Exception $e) {
$output->writeln('<error>An error occurs when trying to generate the upgrade file</error>');
$output->writeln(sprintf('<error>Exception error %s</error>', $e->getMessage()));

return 1;
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class GenerateModulesUpgradeListCommand extends ContainerAwareCommand
class ListUpgradableModulesCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this
->setName('hhennes:module-manager:generate-modules-upgrade-list')
->setName('hhennes:module-manager:list-upgradable-modules')
->setDescription('List all the modules which can be upgraded')
->addOption('ignore', null, InputOption::VALUE_OPTIONAL);
}
Expand Down

0 comments on commit 984b70b

Please sign in to comment.