Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ You can find more information about this module in the following articles (in Fr
Compatibility
---

| Prestashop Version | Compatible |
|--------------------| ---------|
| 1.7.8.x | :heavy_check_mark: |
| 8.x | :heavy_check_mark: |
| Prestashop Version | Compatible |
|--------------------|---------------------------------------------------------------|
| 1.7.8.x | version 0.4.0 and under :heavy_check_mark: |
| 8.0,8.1 | version 0.4.0 and under, or with php 8.1 + :heavy_check_mark: |
| 9.0 | In progress |


Expand Down
6 changes: 6 additions & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ services:
#Console commands
hhennes.modulesmanager.manage.command:
class: Hhennes\ModulesManager\Commands\ManageModulesCommand
arguments:
- '@hhennes.modulesmanager.manager'
tags:
- { name: console.command }
hhennes.modulesmanager.upgradable.modules.list:
class: Hhennes\ModulesManager\Commands\ListUpgradableModulesCommand
arguments:
- '@PrestaShop\PrestaShop\Core\Module\ModuleRepository'
tags:
- { name: console.command }
hhennes.modulesmanager.upgrade.generate:
class: Hhennes\ModulesManager\Commands\GeneratePatchCommand
arguments:
- '@hhennes.modulesmanager.patch.generator'
tags:
- { name: console.command }
#Logger
Expand Down
20 changes: 15 additions & 5 deletions src/Commands/GeneratePatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
namespace Hhennes\ModulesManager\Commands;

use Hhennes\ModulesManager\Change;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Hhennes\ModulesManager\Patch\Generator;
use Symfony\Component\Console\Command\Command;
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
class GeneratePatchCommand extends Command
{
/**
* @param Generator $patchGenerator
* @param string|null $name
*/
public function __construct(
private readonly Generator $patchGenerator,
?string $name = null,
) {
parent::__construct($name);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -59,9 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
];
$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');
$upgradeFileName = $this->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>');
Expand Down
15 changes: 11 additions & 4 deletions src/Commands/ListUpgradableModulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@

namespace Hhennes\ModulesManager\Commands;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use PrestaShop\PrestaShop\Core\Module\ModuleRepositoryInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ListUpgradableModulesCommand extends ContainerAwareCommand
class ListUpgradableModulesCommand extends Command
{
public function __construct(
private readonly ModuleRepositoryInterface $moduleRepository,
?string $name = null,
) {
parent::__construct($name);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -62,8 +70,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
protected function getUpgradableModules(): array
{
$modulesNames = [];
$moduleRepository = $this->getContainer()->get('prestashop.core.admin.module.repository');
$installedModules = $moduleRepository->getInstalledModules();
$installedModules = $this->moduleRepository->getInstalledModules();
foreach ($installedModules as $installedModule) {
if ($installedModule->canBeUpgraded()) {
$modulesNames[] = $installedModule->get('name');
Expand Down
35 changes: 20 additions & 15 deletions src/Commands/ManageModulesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
namespace Hhennes\ModulesManager\Commands;

use Hhennes\ModulesManager\Patch\Manager;
use Module;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* This command is the main file of the module
* It should be called during the CI/CD process to run the registered upgrades
*/
class ManageModulesCommand extends ContainerAwareCommand
class ManageModulesCommand extends Command
{
/** @var string Upgrade module name */
protected string $moduleName = 'hhmodulesmanager';
Expand All @@ -41,6 +40,17 @@ class ManageModulesCommand extends ContainerAwareCommand
/** @var false|\Module */
private $module;

/**
* @param Manager $manager
* @param string|null $name
*/
public function __construct(
private readonly Manager $manager,
?string $name = null,
) {
parent::__construct($name);
}

/**
* {@inheritdoc}
*/
Expand All @@ -65,25 +75,21 @@ public function execute(InputInterface $input, OutputInterface $output): int
try {
$this->output = $output;
$this->module = \Module::getInstanceByName($this->moduleName);

/** @var Manager $manager */
$manager = $this->getContainer()->get('hhennes.modulesmanager.manager');

$output->writeln('<info>Module Upgrade command launched</info>');
$this->log('=========================');
$this->log('Command Upgrade launched');

$upgradeFiles = $manager->getUpgradeFiles();
$appliedPatches = $manager->getAppliedPatches();
$upgradeFiles = $this->manager->getUpgradeFiles();
$appliedPatches = $this->manager->getAppliedPatches();
foreach ($upgradeFiles as $upgradeFile) {
$patchName = $upgradeFile->getBasename('.yml');
if (!in_array($patchName, $appliedPatches)) {
$this->output->writeln('<comment>Applying patch "' . $patchName . '"</comment>');
$this->log('Applying patch ' . $patchName);
$manager->applyPatch($upgradeFile, $patchName);
$this->manager->applyPatch($upgradeFile, $patchName);
}
}
$this->logAndRenderResult($output, $manager);
$this->logAndRenderResult($output);
$output->writeln('<info>End of process</info>');
$this->log('End of upgrade process');
} catch (\Throwable $e) {
Expand All @@ -104,14 +110,13 @@ public function execute(InputInterface $input, OutputInterface $output): int
* Log and display the result of the run of the command
*
* @param OutputInterface $output
* @param Manager $manager
*
* @return void
*/
protected function logAndRenderResult(OutputInterface $output, Manager $manager): void
protected function logAndRenderResult(OutputInterface $output): void
{
$this->success = array_merge($this->success, $manager->getSuccess());
$this->errors = array_merge($this->errors, $manager->getErrors());
$this->success = array_merge($this->success, $this->manager->getSuccess());
$this->errors = array_merge($this->errors, $this->manager->getErrors());
if (count($this->success)) {
$this->log('=== Success Messages');
foreach ($this->success as $success) {
Expand Down
2 changes: 1 addition & 1 deletion src/Patch/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Manager
* @param UpgraderFactory $upgraderFactory
*/
public function __construct(
UpgraderFactory $upgraderFactory
UpgraderFactory $upgraderFactory,
) {
$this->upgraderFactory = $upgraderFactory;
}
Expand Down
Loading