Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhooq committed Apr 4, 2023
0 parents commit 8a070c5
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = tab
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Joomla system plugin for JEA

This plugin adds commands to the Joomla! 4 CLI (cli/joomla.php)

## Commands

- `jea:gateways:export` Run JEA gateways export jobs
- `jea:gateways:import` Run JEA gateways import jobs
67 changes: 67 additions & 0 deletions jea.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.Jea
*
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
use Joomla\Application\ApplicationEvents;
use Joomla\CMS\Console\Loader\WritableLoaderInterface;
use Joomla\Plugin\System\Jea\Console\GatewaysExportCommand;
use Joomla\Plugin\System\Jea\Console\GatewaysImportCommand;

defined('_JEXEC') or die;

/**
* Joomla! Jea plugin.
*
*/
class PlgSystemJea extends CMSPlugin implements SubscriberInterface
{

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 4.1.3
*/
public static function getSubscribedEvents(): array
{
return [
ApplicationEvents::BEFORE_EXECUTE => 'registerCommands',
];
}

public function registerCommands(): void
{
$container = Factory::getContainer();
$writableLoader = $container->get(WritableLoaderInterface::class);
assert($writableLoader instanceof WritableLoaderInterface);

$container->share(
GatewaysExportCommand::class,
function () {
return new GatewaysExportCommand();
},
true,
);

$container->share(
GatewaysImportCommand::class,
function () {
return new GatewaysImportCommand();
},
true,
);

$writableLoader->add('jea:gateways:export', GatewaysExportCommand::class);
$writableLoader->add('jea:gateways:import', GatewaysImportCommand::class);
}
}
19 changes: 19 additions & 0 deletions jea.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="system" method="upgrade">
<name>plg_system_jea</name>
<author>Sylvain Philip</author>
<creationDate>2023-03</creationDate>
<copyright>(C) 2006 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.sphilip.com</authorUrl>
<version>1.0.0</version>
<description>PLG_JEA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\Jea</namespace>
<files>
<filename plugin="jea">jea.php</filename>
<folder>language</folder>
<folder>src</folder>
</files>
<config />
</extension>
3 changes: 3 additions & 0 deletions language/en-GB/en-GB.plg_system_jea.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PLG_SYSTEM_JEA="System - JEA"
PLG_JEA_XML_DESCRIPTION="Adds specific JEA commands to the Joomla! cli console."
3 changes: 3 additions & 0 deletions language/fr-FR/fr-FR.plg_system_jea.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PLG_SYSTEM_JEA="Système - JEA"
PLG_JEA_XML_DESCRIPTION="Ce plugin ajoute des commandes spécifiques à JEA dans la console CLI Joomla!."
48 changes: 48 additions & 0 deletions src/Console/GatewaysCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Joomla\Plugin\System\Jea\Console;

use Joomla\CMS\Factory;
use Joomla\Console\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

require_once JPATH_ADMINISTRATOR . '/components/com_jea/gateways/dispatcher.php';

/**
* This command runs JEA gateways jobs
*/
abstract class GatewaysCommand extends AbstractCommand
{
protected $task = '';

/**
* Entry point for CLI script
*
* @return integer the parents result
*/
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
Factory::getApplication()->getLanguage()->load('com_jea', JPATH_ADMINISTRATOR . '/components/com_jea');
$dispatcher = \GatewaysEventDispatcher::getInstance();
$dispatcher->loadGateways();
$dispatcher->trigger($this->task);

return 0;
}

/**
* Configure the command.
*
* @return void
*
* @since 4.0.0
*/
protected function configure(): void
{
$help = "<info>%command.name%</info> Execute JEA gateways {$this->task} jobs
\nUsage: <info>php %command.full_name%</info>";
$this->setDescription('Run JEA gateways ' . $this->task . ' jobs');
$this->setHelp($help);
}
}
23 changes: 23 additions & 0 deletions src/Console/GatewaysExportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Joomla\Plugin\System\Jea\Console;

/**
* This command runs JEA gateways export jobs
*/
class GatewaysExportCommand extends GatewaysCommand
{
protected static $defaultName = 'jea:gateways:export';

/**
* Configure the command.
*
* @return void
*/
protected function configure(): void
{
$this->task = 'export';

parent::configure();
}
}
23 changes: 23 additions & 0 deletions src/Console/GatewaysImportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Joomla\Plugin\System\Jea\Console;

/**
* This command runs JEA gateways export jobs
*/
class GatewaysImportCommand extends GatewaysCommand
{
protected static $defaultName = 'jea:gateways:import';

/**
* Configure the command.
*
* @return void
*/
protected function configure(): void
{
$this->task = 'import';

parent::configure();
}
}

0 comments on commit 8a070c5

Please sign in to comment.