fix tests, edit reset_install.sh, manage payment modules, change debugbar namespace to theliadebugbar

This commit is contained in:
Etienne Roudeix
2013-09-18 19:51:01 +02:00
parent 16d0985718
commit 891ebcd491
16 changed files with 203 additions and 65 deletions

View File

@@ -62,26 +62,34 @@ class CacheClear extends ContainerAwareCommand
$this->clearCache($cacheDir, $output); $this->clearCache($cacheDir, $output);
if (!$input->getOption("without-assets")) { if (!$input->getOption("without-assets")) {
$this->clearCache(THELIA_WEB_DIR . "/assets", $output); $this->clearCache(THELIA_WEB_DIR . "assets", $output);
} }
} }
protected function clearCache($dir, OutputInterface $output) protected function clearCache($dir, OutputInterface $output)
{ {
if (!is_writable($dir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $dir));
}
$output->writeln(sprintf("Clearing cache in <info>%s</info> directory", $dir)); $output->writeln(sprintf("Clearing cache in <info>%s</info> directory", $dir));
try {
$directoryBrowser = new \DirectoryIterator($dir);
} catch(\UnexpectedValueException $e) {
// throws same exception code for does not exist and permission denied ...
if(!file_exists($dir)) {
$output->writeln(sprintf("<info>%s cache dir already clear</info>", $dir));
return;
}
throw $e;
}
$fs = new Filesystem(); $fs = new Filesystem();
try { try {
$fs->remove($dir); $fs->remove($dir);
$output->writeln(sprintf("<info>%s cache dir cleared successfully</info>", $dir)); $output->writeln(sprintf("<info>%s cache dir cleared successfully</info>", $dir));
} catch (IOException $e) { } catch (IOException $e) {
$output->writeln(sprintf("error during clearing cache : %s", $e->getMessage())); $output->writeln(sprintf("Error during clearing cache : %s", $e->getMessage()));
} }
} }
} }

View File

@@ -63,31 +63,28 @@ class ModuleActivateCommand extends BaseModuleGenerate
$module = ModuleQuery::create()->findOneByCode($moduleCode); $module = ModuleQuery::create()->findOneByCode($moduleCode);
if(null === $module) { if(null === $module) {
$output->renderBlock(array( throw new \RuntimeException(sprintf("module %s not found", $moduleCode));
'',
sprintf("module %s not found", $moduleCode),
''
), "bg=red;fg=white");
} }
try { try {
new \TheliaDebugBar\TheliaDebugBar();
$moduleReflection = new \ReflectionClass($module->getFullNamespace()); $moduleReflection = new \ReflectionClass($module->getFullNamespace());
$moduleInstance = $moduleReflection->newInstance(); $moduleInstance = $moduleReflection->newInstance();
$moduleInstance->activate(); $moduleInstance->activate();
} catch(\Exception $e) { } catch(\Exception $e) {
$output->renderBlock(array( throw new \RuntimeException(sprintf("Activation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()));
'',
sprintf("Activation fail with Exception : [%d] %s", $e->getCode(), $e->getMessage()),
''
), "bg=red;fg=white");
} }
$output->renderBlock(array( //impossible to change output class in CommandTester...
'', if (method_exists($output, "renderBlock")) {
sprintf("Activation succeed for module %s", $moduleCode), $output->renderBlock(array(
'' '',
), "bg=green;fg=black"); sprintf("Activation succeed for module %s", $moduleCode),
''
), "bg=green;fg=black");
}
} }
} }

View File

@@ -32,6 +32,7 @@ use Thelia\Core\Template\Element\LoopResultRow;
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Core\Template\Loop\Argument\Argument; use Thelia\Core\Template\Loop\Argument\Argument;
use Thelia\Exception\TaxEngineException;
use Thelia\Model\CategoryQuery; use Thelia\Model\CategoryQuery;
use Thelia\Model\CountryQuery; use Thelia\Model\CountryQuery;
use Thelia\Model\CurrencyQuery; use Thelia\Model\CurrencyQuery;
@@ -603,9 +604,13 @@ class Product extends BaseI18nLoop
$price = $product->getRealLowestPrice(); $price = $product->getRealLowestPrice();
$taxedPrice = $product->getTaxedPrice( try {
CountryQuery::create()->findOneById(64) // @TODO : make it magic $taxedPrice = $product->getTaxedPrice(
); CountryQuery::create()->findOneById(64) // @TODO : make it magic
);
} catch(TaxEngineException $e) {
$taxedPrice = null;
}
// Find previous and next product, in the default category. // Find previous and next product, in the default category.
$default_category_id = $product->getDefaultCategoryId(); $default_category_id = $product->getDefaultCategoryId();

View File

@@ -151,13 +151,21 @@ class ProductSaleElements extends BaseLoop
$loopResultRow = new LoopResultRow($loopResult, $PSEValue, $this->versionable, $this->timestampable, $this->countable); $loopResultRow = new LoopResultRow($loopResult, $PSEValue, $this->versionable, $this->timestampable, $this->countable);
$price = $PSEValue->getPrice(); $price = $PSEValue->getPrice();
$taxedPrice = $PSEValue->getTaxedPrice( try {
CountryQuery::create()->findOneById(64) // @TODO : make it magic $taxedPrice = $PSEValue->getTaxedPrice(
); CountryQuery::create()->findOneById(64) // @TODO : make it magic
);
} catch(TaxEngineException $e) {
$taxedPrice = null;
}
$promoPrice = $PSEValue->getPromoPrice(); $promoPrice = $PSEValue->getPromoPrice();
$taxedPromoPrice = $PSEValue->getTaxedPromoPrice( try {
CountryQuery::create()->findOneById(64) // @TODO : make it magic $taxedPromoPrice = $PSEValue->getTaxedPromoPrice(
); CountryQuery::create()->findOneById(64) // @TODO : make it magic
);
} catch(TaxEngineException $e) {
$taxedPromoPrice = null;
}
$loopResultRow->set("ID", $PSEValue->getId()) $loopResultRow->set("ID", $PSEValue->getId())
->set("QUANTITY", $PSEValue->getQuantity()) ->set("QUANTITY", $PSEValue->getQuantity())

View File

@@ -52,7 +52,13 @@ abstract class BaseModule extends ContainerAware
if($moduleModel->getActivate() == self::IS_NOT_ACTIVATED) { if($moduleModel->getActivate() == self::IS_NOT_ACTIVATED) {
$moduleModel->setActivate(self::IS_ACTIVATED); $moduleModel->setActivate(self::IS_ACTIVATED);
$moduleModel->save(); $moduleModel->save();
$this->afterActivation(); try {
$this->afterActivation();
} catch(\Exception $e) {
$moduleModel->setActivate(self::IS_NOT_ACTIVATED);
$moduleModel->save();
throw $e;
}
} }
} }
@@ -106,20 +112,20 @@ abstract class BaseModule extends ContainerAware
$increment = 0; $increment = 0;
while(file_exists($imageDirectory . '/' . $imageFileName)) { while(file_exists($imageDirectory . '/' . $imageFileName)) {
$imageFileName = sprintf("module/%s-%d-%d-%s", $module->getCode(), $image->getId(), $increment, $fileName); $imageFileName = sprintf("%s-%d-%d-%s", $module->getCode(), $image->getId(), $increment, $fileName);
$increment++; $increment++;
} }
$imagePath = sprintf('%s/%s', $imageDirectory, $imageFileName); $imagePath = sprintf('%s/%s', $imageDirectory, $imageFileName);
if (! is_dir($imageDirectory)) { if (! is_dir($imageDirectory)) {
if(! mkdir($imageDirectory, 0777, true)) { if(! @mkdir($imageDirectory, 0777, true)) {
$con->rollBack(); $con->rollBack();
throw new ModuleException(sprintf("Cannot create directory : %s", $imageDirectory), ModuleException::CODE_NOT_FOUND); throw new ModuleException(sprintf("Cannot create directory : %s", $imageDirectory), ModuleException::CODE_NOT_FOUND);
} }
} }
if(! copy($filePath, $imagePath)) { if(! @copy($filePath, $imagePath)) {
$con->rollBack(); $con->rollBack();
throw new ModuleException(sprintf("Cannot copy file : %s to : %s", $filePath, $imagePath), ModuleException::CODE_NOT_FOUND); throw new ModuleException(sprintf("Cannot copy file : %s to : %s", $filePath, $imagePath), ModuleException::CODE_NOT_FOUND);
} }

View File

@@ -0,0 +1,109 @@
<?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\Tests\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Thelia\Command\ModuleActivateCommand;
use Thelia\Core\Application;
use Thelia\Model\ModuleQuery;
use Thelia\Module\BaseModule;
/**
* Class ModuleActivateCommandTest
*
* @package Thelia\Tests\Command
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*/
class ModuleActivateCommandTest extends \PHPUnit_Framework_TestCase
{
public function testModuleActivateCommand()
{
$module = ModuleQuery::create()->findOne();
if(null !== $module) {
$application = new Application($this->getKernel());
$module->setActivate(BaseModule::IS_NOT_ACTIVATED);
$module->save();
$moduleActivate = new ModuleActivateCommand();
$moduleActivate->setContainer($this->getContainer());
$application->add($moduleActivate);
$command = $application->find("module:activate");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"module" => $module->getCode(),
));
$this->assertEquals(BaseModule::IS_ACTIVATED, ModuleQuery::create()->findPk($module->getId())->getActivate());
}
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
*/
public function testModuleActivateCommandUnknownModule()
{
$module = ModuleQuery::create()->findOne();
$testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
if(null !== $module && null == $testedModule) {
$application = new Application($this->getKernel());
$module->setActivate(BaseModule::IS_NOT_ACTIVATED);
$module->save();
$moduleActivate = new ModuleActivateCommand();
$moduleActivate->setContainer($this->getContainer());
$application->add($moduleActivate);
$command = $application->find("module:activate");
$commandTester = new CommandTester($command);
$commandTester->execute(array(
"command" => $command->getName(),
"module" => "letshopethismoduledoesnotexists",
));
$out = true;
}
}
public function getKernel()
{
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
return $kernel;
}
public function getContainer()
{
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
return $container;
}
}

View File

@@ -31,7 +31,7 @@ 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, 'TheliaDebugBar', 1, 1, 1, 'TheliaDebugBar\\TheliaDebugBar', NOW(), NOW()),
(2, 'Colissimo', 2, 0, 1, 'Colissimo\\Colissimo', NOW(), NOW()), (2, 'Colissimo', 2, 0, 1, 'Colissimo\\Colissimo', NOW(), NOW()),
(3, 'Cheque', 3, 0, 1, 'Cheque\\Cheque', NOW(), NOW()), (3, 'Cheque', 3, 0, 1, 'Cheque\\Cheque', NOW(), NOW()),
(4, 'FakeCB', 3, 0, 2, 'FakeCB\\FakeCB', NOW(), NOW()); (4, 'FakeCB', 3, 0, 2, 'FakeCB\\FakeCB', NOW(), NOW());

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="DebugBar\Model">
<!--
See propel documentation on http://propelorm.org for all information about schema file
-->
<external-schema filename="/home/manu/dev/www/thelia/local/config/schema.xml" referenceOnly="true" />
</database>

View File

@@ -32,13 +32,13 @@
<services> <services>
<service id="debugBar" class="DebugBar\DebugBar"/> <service id="debugBar" class="DebugBar\DebugBar"/>
<service id="smarty.debugbar" class="DebugBar\Smarty\Plugin\DebugBar"> <service id="smarty.debugbar" class="TheliaDebugBar\Smarty\Plugin\DebugBar">
<argument type="service" id="debugBar"/> <argument type="service" id="debugBar"/>
<argument >%kernel.debug%</argument> <argument >%kernel.debug%</argument>
<tag name="thelia.parser.register_plugin"/> <tag name="thelia.parser.register_plugin"/>
</service> </service>
<service id="debugBar.listener" class="DebugBar\Listeners\DebugBarListeners"> <service id="debugBar.listener" class="TheliaDebugBar\Listeners\DebugBarListeners">
<argument type="service" id="service_container"/> <argument type="service" id="service_container"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<database defaultIdMethod="native" name="thelia" namespace="TheliaDebugBar\Model">
<!--
See propel documentation on http://propelorm.org for all information about schema file
-->
</database>

View File

@@ -21,14 +21,17 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace DebugBar\DataCollector; namespace TheliaDebugBar\DataCollector;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use Propel\Runtime\Propel; use Propel\Runtime\Propel;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
/** /**
* Class PropelCollector * Class PropelCollector
* @package DebugBar\DataCollector * @package TheliaDebugBar\DataCollector
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class PropelCollector extends DataCollector implements Renderable, LoggerInterface class PropelCollector extends DataCollector implements Renderable, LoggerInterface

View File

@@ -21,11 +21,12 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace DebugBar\Listeners; namespace TheliaDebugBar\Listeners;
use DebugBar\DataCollector\MemoryCollector; use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector; use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DataCollector\PhpInfoCollector; use DebugBar\DataCollector\PhpInfoCollector;
use DebugBar\DataCollector\PropelCollector; use TheliaDebugBar\DataCollector\PropelCollector;
use DebugBar\DataCollector\TimeDataCollector; use DebugBar\DataCollector\TimeDataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
@@ -35,7 +36,7 @@ use Thelia\Core\Event\TheliaEvents;
/** /**
* Class DebugBarListeners * Class DebugBarListeners
* @package DebugBar\Listeners * @package TheliaDebugBar\Listeners
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class DebugBarListeners extends BaseAction implements EventSubscriberInterface { class DebugBarListeners extends BaseAction implements EventSubscriberInterface {

View File

@@ -21,7 +21,7 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace DebugBar\Smarty\Plugin; namespace TheliaDebugBar\Smarty\Plugin;
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\an; use Thelia\Core\Template\Smarty\an;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;

View File

@@ -21,11 +21,11 @@
/* */ /* */
/*************************************************************************************/ /*************************************************************************************/
namespace DebugBar; namespace TheliaDebugBar;
use Thelia\Module\BaseModule; use Thelia\Module\BaseModule;
class DebugBar extends BaseModule class TheliaDebugBar extends BaseModule
{ {
/** /**
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
@@ -49,6 +49,6 @@ class DebugBar extends BaseModule
public function getCode() public function getCode()
{ {
return 'DebugBar'; return 'TheliaDebugBar';
} }
} }

View File

@@ -2,41 +2,43 @@
# @author Guillaume MOREL # @author Guillaume MOREL
# v0.2 # v0.2
echo -e "\033[47m\033[1;31m\n[WARN] This script will reset this Thelia2 install\n\033[0m" echo -e "\033[47m\033[1;31m\n[WARNING] This script will reset this Thelia2 install\nPress ENTER to continue or ^C to cancel\033[0m"
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n" read test
echo -e "\n\033[01;34m[INFO] Clearing caches\033[00m\n"
php Thelia cache:clear php Thelia cache:clear
echo -e "\n\e[01;34m[INFO] Downloading vendors\e[00m\n" echo -e "\n\033[01;34m[INFO] Downloading vendors\033[00m\n"
composer install --prefer-dist --optimize-autoloader composer install --prefer-dist --optimize-autoloader
cd local/config/ cd local/config/
echo -e "\n\e[01;34m[INFO] Building Models file\e[00m\n" echo -e "\n\033[01;34m[INFO] Building Models file\033[00m\n"
../../bin/propel build -v --output-dir=../../core/lib/ ../../bin/propel build -v --output-dir=../../core/lib/
echo -e "\n\e[01;34m[INFO] Building SQL CREATE file\e[00m\n" echo -e "\n\033[01;34m[INFO] Building SQL CREATE file\033[00m\n"
../../bin/propel sql:build -v --output-dir=../../install/ ../../bin/propel sql:build -v --output-dir=../../install/
echo -e "\n\e[01;34m[INFO] Reloading Thelia2 database\e[00m\n" echo -e "\n\033[01;34m[INFO] Reloading Thelia2 database\033[00m\n"
cd ../.. cd ../..
rm install/sqldb.map rm install/sqldb.map
php Thelia thelia:dev:reloadDB php Thelia thelia:dev:reloadDB
echo -e "\n\e[01;34m[INFO] Installing fixtures\e[00m\n" echo -e "\n\033[01;34m[INFO] Installing fixtures\033[00m\n"
php install/faker.php php install/faker.php
echo -e "\n\e[01;34m[INFO] Adding admin\e[00m\n" echo -e "\n\033[01;34m[INFO] Adding admin\033[00m\n"
php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2 php Thelia thelia:create-admin --login_name thelia2 --password thelia2 --last_name thelia2 --first_name thelia2
echo -e "\n\e[01;34m[INFO] Clearing caches\e[00m\n" echo -e "\n\033[01;34m[INFO] Clearing caches\033[00m\n"
php Thelia cache:clear php Thelia cache:clear
echo -e "\n\e[01;34m[INFO] Activating Delivery Module(s)\e[00m\n" echo -e "\n\033[01;34m[INFO] Activating Delivery Module(s)\033[00m\n"
php Thelia module:activate Colissimo php Thelia module:activate Colissimo
echo -e "\n\e[01;34m[INFO] Activating Payment Module(s)\e[00m\n" echo -e "\n\033[01;34m[INFO] Activating Payment Module(s)\033[00m\n"
php Thelia module:activate Cheque php Thelia module:activate Cheque
php Thelia module:activate FakeCB php Thelia module:activate FakeCB
echo -e "\n\e[00;32m[SUCCESS] Reset done\e[00m\n" echo -e "\n\033[00;32m[SUCCESS] Reset done\033[00m\n"