payment modules
This commit is contained in:
93
core/lib/Thelia/Command/ModuleActivateCommand.php
Executable file
93
core/lib/Thelia/Command/ModuleActivateCommand.php
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Thelia */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : info@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* This program is free software; you can redistribute it and/or modify */
|
||||||
|
/* it under the terms of the GNU General Public License as published by */
|
||||||
|
/* the Free Software Foundation; either version 3 of the License */
|
||||||
|
/* */
|
||||||
|
/* This program is distributed in the hope that it will be useful, */
|
||||||
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||||
|
/* GNU General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public License */
|
||||||
|
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
namespace Thelia\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\Filesystem\Filesystem;
|
||||||
|
use Symfony\Component\Filesystem\Exception\IOException;
|
||||||
|
|
||||||
|
use Thelia\Command\ContainerAwareCommand;
|
||||||
|
use Thelia\Model\ModuleQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* activates a module
|
||||||
|
*
|
||||||
|
* Class ModuleActivateCommand
|
||||||
|
* @package Thelia\Command
|
||||||
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ModuleActivateCommand extends BaseModuleGenerate
|
||||||
|
{
|
||||||
|
protected function configure()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->setName("module:activate")
|
||||||
|
->setDescription("Activates a module")
|
||||||
|
->addArgument(
|
||||||
|
"module" ,
|
||||||
|
InputArgument::REQUIRED,
|
||||||
|
"module to activate"
|
||||||
|
)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
{
|
||||||
|
$moduleCode = $this->formatModuleName($input->getArgument("module"));
|
||||||
|
|
||||||
|
$module = ModuleQuery::create()->findOneByCode($moduleCode);
|
||||||
|
|
||||||
|
if(null === $module) {
|
||||||
|
$output->renderBlock(array(
|
||||||
|
'',
|
||||||
|
sprintf("module %s not found", $moduleCode),
|
||||||
|
''
|
||||||
|
), "bg=red;fg=white");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$moduleReflection = new \ReflectionClass($module->getFullNamespace());
|
||||||
|
|
||||||
|
$moduleInstance = $moduleReflection->newInstance();
|
||||||
|
|
||||||
|
$moduleInstance->activate();
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$output->renderBlock(array(
|
||||||
|
'',
|
||||||
|
sprintf("Activation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()),
|
||||||
|
''
|
||||||
|
), "bg=red;fg=white");
|
||||||
|
}
|
||||||
|
|
||||||
|
$output->renderBlock(array(
|
||||||
|
'',
|
||||||
|
sprintf("Activation succeed for module %s", $moduleCode),
|
||||||
|
''
|
||||||
|
), "bg=green;fg=black");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,6 +105,7 @@
|
|||||||
<command class="Thelia\Command\ModuleGenerateCommand"/>
|
<command class="Thelia\Command\ModuleGenerateCommand"/>
|
||||||
<command class="Thelia\Command\ModuleGenerateModelCommand"/>
|
<command class="Thelia\Command\ModuleGenerateModelCommand"/>
|
||||||
<command class="Thelia\Command\ModuleGenerateSqlCommand"/>
|
<command class="Thelia\Command\ModuleGenerateSqlCommand"/>
|
||||||
|
<command class="Thelia\Command\ModuleActivateCommand"/>
|
||||||
<command class="Thelia\Command\CreateAdminUser"/>
|
<command class="Thelia\Command\CreateAdminUser"/>
|
||||||
<command class="Thelia\Command\ReloadDatabaseCommand"/>
|
<command class="Thelia\Command\ReloadDatabaseCommand"/>
|
||||||
</commands>
|
</commands>
|
||||||
|
|||||||
@@ -38,14 +38,22 @@ abstract class BaseModule extends ContainerAware
|
|||||||
const DELIVERY_MODULE_TYPE = 2;
|
const DELIVERY_MODULE_TYPE = 2;
|
||||||
const PAYMENT_MODULE_TYPE = 3;
|
const PAYMENT_MODULE_TYPE = 3;
|
||||||
|
|
||||||
|
const IS_ACTIVATED = 1;
|
||||||
|
const IS_NOT_ACTIVATED = 0;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function activate()
|
public function activate()
|
||||||
{
|
{
|
||||||
|
$moduleModel = $this->getModuleModel();
|
||||||
|
if($moduleModel->getActivate() == self::IS_NOT_ACTIVATED) {
|
||||||
|
$moduleModel->setActivate(self::IS_ACTIVATED);
|
||||||
|
$moduleModel->save();
|
||||||
|
$this->afterActivation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasContainer()
|
public function hasContainer()
|
||||||
@@ -127,7 +135,7 @@ abstract class BaseModule extends ContainerAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return ChildModule
|
* @return Module
|
||||||
* @throws \Thelia\Exception\ModuleException
|
* @throws \Thelia\Exception\ModuleException
|
||||||
*/
|
*/
|
||||||
public function getModuleModel()
|
public function getModuleModel()
|
||||||
@@ -143,6 +151,7 @@ abstract class BaseModule extends ContainerAware
|
|||||||
|
|
||||||
abstract public function getCode();
|
abstract public function getCode();
|
||||||
abstract public function install();
|
abstract public function install();
|
||||||
|
abstract public function afterActivation();
|
||||||
abstract public function destroy();
|
abstract public function destroy();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
|
|||||||
|
|
||||||
INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES
|
INSERT INTO `module` (`id`, `code`, `type`, `activate`, `position`, `full_namespace`, `created_at`, `updated_at`) VALUES
|
||||||
(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()),
|
(1, 'DebugBar', 1, 1, 1, 'DebugBar\\DebugBar', NOW(), NOW()),
|
||||||
(2, 'Colissimo', 2, 1, 1, 'Colissimo\\Colissimo', NOW(), NOW()),
|
(2, 'Colissimo', 2, 0, 1, 'Colissimo\\Colissimo', NOW(), NOW()),
|
||||||
(3, 'Cheque', 3, 1, 1, 'Cheque\\Cheque', NOW(), NOW()),
|
(3, 'Cheque', 3, 0, 1, 'Cheque\\Cheque', NOW(), NOW()),
|
||||||
(4, 'FakeCB', 3, 1, 2, 'FakeCB\\FakeCB', NOW(), NOW());
|
(4, 'FakeCB', 3, 0, 2, 'FakeCB\\FakeCB', NOW(), NOW());
|
||||||
|
|
||||||
INSERT INTO `module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES
|
INSERT INTO `module_i18n` (`id`, `locale`, `title`, `description`, `chapo`, `postscriptum`) VALUES
|
||||||
('2', 'en_US', '72h delivery', NULL, NULL, NULL),
|
('2', 'en_US', '72h delivery', NULL, NULL, NULL),
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace Cheque;
|
|||||||
|
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Thelia\Model\ModuleImageQuery;
|
||||||
use Thelia\Module\BaseModule;
|
use Thelia\Module\BaseModule;
|
||||||
use Thelia\Module\PaymentModuleInterface;
|
use Thelia\Module\PaymentModuleInterface;
|
||||||
|
|
||||||
@@ -59,6 +60,11 @@ class Cheque extends BaseModule implements PaymentModuleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterActivation()
|
||||||
{
|
{
|
||||||
/* insert the images from image folder if first module activation */
|
/* insert the images from image folder if first module activation */
|
||||||
$module = $this->getModuleModel();
|
$module = $this->getModuleModel();
|
||||||
|
|||||||
@@ -67,6 +67,11 @@ class Colissimo extends BaseModule implements DeliveryModuleInterface
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function afterActivation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
||||||
* Like install and destroy
|
* Like install and destroy
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ class DebugBar extends BaseModule
|
|||||||
* Like install and destroy
|
* Like install and destroy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public function afterActivation()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
{
|
{
|
||||||
// TODO: Implement install() method.
|
// TODO: Implement install() method.
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ class FakeCB extends BaseModule implements PaymentModuleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function install()
|
public function install()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function afterActivation()
|
||||||
{
|
{
|
||||||
/* insert the images from image folder if first module activation */
|
/* insert the images from image folder if first module activation */
|
||||||
$module = $this->getModuleModel();
|
$module = $this->getModuleModel();
|
||||||
|
|||||||
@@ -32,4 +32,11 @@ php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_na
|
|||||||
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n"
|
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n"
|
||||||
php Thelia cache:clear
|
php Thelia cache:clear
|
||||||
|
|
||||||
|
echo -e "\n\e[01;34m[INFO] Activating Delivery Module(s)\e[00m\n"
|
||||||
|
php Thelia module:activate Colissimo
|
||||||
|
|
||||||
|
echo -e "\n\e[01;34m[INFO] Activating Payment Module(s)\e[00m\n"
|
||||||
|
php Thelia module:activate Cheque
|
||||||
|
php Thelia module:activate FakeCB
|
||||||
|
|
||||||
echo -e "\n\e[00;32m[SUCCESS] Reset done\e[00m\n"
|
echo -e "\n\e[00;32m[SUCCESS] Reset done\e[00m\n"
|
||||||
Reference in New Issue
Block a user