diff --git a/.gitignore b/.gitignore index 3063f9a02..8cf78452c 100755 --- a/.gitignore +++ b/.gitignore @@ -19,10 +19,9 @@ local/media/documents/* local/media/images/* web/assets/* web/cache/* -web/.htaccess phpdoc*.log php-cs xhprof/ phpunit.phar .DS_Store -phpmyadmin \ No newline at end of file +phpmyadmin diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index e8ea3a9d5..41e49d7d7 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -40,6 +40,8 @@ +
+ @@ -53,6 +55,9 @@ + + + @@ -203,6 +208,7 @@ + diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index a8ad18abf..efeea61e8 100755 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -56,17 +56,6 @@ - - - install.xml - - %kernel.cache_dir% - %kernel.debug% - - - - - front.xml diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml deleted file mode 100644 index 37ddde487..000000000 --- a/core/lib/Thelia/Config/Resources/routing/install.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - Thelia\Controller\Install\InstallController::index - - - - Thelia\Controller\Install\InstallController::checkPermission - - - - Thelia\Controller\Install\InstallController::databaseConnection - - - - Thelia\Controller\Install\InstallController::databaseSelection - - - - Thelia\Controller\Install\InstallController::generalInformation - - - - Thelia\Controller\Install\InstallController::thanks - - - diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index 1c7140211..8ba0cb038 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -31,6 +31,7 @@ use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Router; use Thelia\Core\Security\SecurityContext; +use Thelia\Core\Translation\Translator; use Thelia\Tools\URL; use Thelia\Tools\Redirect; use Thelia\Core\Template\ParserContext; @@ -97,7 +98,7 @@ class BaseController extends ContainerAware * * return the Translator * - * @return mixed \Thelia\Core\Translation\Translator + * @return Translator */ public function getTranslator() { diff --git a/core/lib/Thelia/Controller/Front/BaseFrontController.php b/core/lib/Thelia/Controller/Front/BaseFrontController.php index 6540f28a4..69ea8553d 100755 --- a/core/lib/Thelia/Controller/Front/BaseFrontController.php +++ b/core/lib/Thelia/Controller/Front/BaseFrontController.php @@ -60,7 +60,8 @@ class BaseFrontController extends BaseController protected function checkCartNotEmpty() { - if($this->getSession()->getCart()->countCartItems() == 0) { + $cart = $this->getSession()->getCart(); + if($cart===null || $cart->countCartItems() == 0) { $this->redirectToRoute("cart.view"); } } diff --git a/core/lib/Thelia/Controller/Front/OrderController.php b/core/lib/Thelia/Controller/Front/OrderController.php index 1bac39b14..f34715894 100755 --- a/core/lib/Thelia/Controller/Front/OrderController.php +++ b/core/lib/Thelia/Controller/Front/OrderController.php @@ -29,7 +29,8 @@ use Thelia\Core\Event\TheliaEvents; use Symfony\Component\HttpFoundation\Request; use Thelia\Form\OrderDelivery; use Thelia\Log\Tlog; -use Thelia\Model\Base\AddressQuery; +use Thelia\Model\AddressQuery; +use Thelia\Model\AreaDeliveryModuleQuery; use Thelia\Model\Order; /** @@ -53,9 +54,6 @@ class OrderController extends BaseFrontController $orderDelivery = new OrderDelivery($this->getRequest()); - $x = $this->getRequest(); - $y = $_POST; - try { $form = $this->validateForm($orderDelivery, "post"); @@ -69,7 +67,12 @@ class OrderController extends BaseFrontController } /* check that the delivery module fetch the delivery address area */ - + if(AreaDeliveryModuleQuery::create() + ->filterByAreaId($deliveryAddress->getCountry()->getAreaId()) + ->filterByDeliveryModuleId() + ->count() == 0) { + throw new \Exception("PUKE"); + } $orderEvent = $this->getOrderEvent(); diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php deleted file mode 100644 index 40e6643db..000000000 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ /dev/null @@ -1,111 +0,0 @@ -. */ -/* */ -/*************************************************************************************/ - -namespace Thelia\Controller\Install; -use Thelia\Install\CheckPermission; - -/** - * Class InstallController - * @package Thelia\Controller\Install - * @author Manuel Raynaud - */ -class InstallController extends BaseInstallController -{ - public function index() - { - //$this->verifyStep(1); - - $this->getSession()->set("step", 1); - - return $this->render("index.html"); - } - - public function checkPermission() - { - //$this->verifyStep(2); - - //$permission = new CheckPermission(); - - $this->getSession()->set("step", 2); - return $this->render("step-2.html"); - } - - public function databaseConnection() - { - //$this->verifyStep(2); - - //$permission = new CheckPermission(); - - $this->getSession()->set("step", 3); - return $this->render("step-3.html"); - } - - public function databaseSelection() - { - //$this->verifyStep(2); - - //$permission = new CheckPermission(); - - $this->getSession()->set("step", 4); - return $this->render("step-4.html"); - } - - public function generalInformation() - { - //$this->verifyStep(2); - - //$permission = new CheckPermission(); - - $this->getSession()->set("step", 5); - return $this->render("step-5.html"); - } - - public function thanks() - { - //$this->verifyStep(2); - - //$permission = new CheckPermission(); - - $this->getSession()->set("step", 6); - return $this->render("thanks.html"); - } - - protected function verifyStep($step) - { - $session = $this->getSession(); - - if ($session->has("step")) { - $sessionStep = $session->get("step"); - } else { - return true; - } - - switch ($step) { - case "1" : - if ($sessionStep > 1) { - $this->redirect("/install/step/2"); - } - break; - } - } -} diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php index 24d2c29ee..71b9c3f81 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Security.php @@ -23,18 +23,22 @@ namespace Thelia\Core\Template\Smarty\Plugins; +use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; use Thelia\Core\Security\SecurityContext; use Thelia\Core\Security\Exception\AuthenticationException; +use Thelia\Exception\OrderException; class Security extends AbstractSmartyPlugin { + protected $request; private $securityContext; - public function __construct(SecurityContext $securityContext) + public function __construct(Request $request, SecurityContext $securityContext) { $this->securityContext = $securityContext; + $this->request = $request; } /** @@ -43,32 +47,43 @@ class Security extends AbstractSmartyPlugin * @param array $params * @param unknown $smarty * @return string no text is returned. + * @throws \Thelia\Core\Security\Exception\AuthenticationException */ public function checkAuthFunction($params, &$smarty) { - $roles = $this->_explode($this->getParam($params, 'roles')); - $permissions = $this->_explode($this->getParam($params, 'permissions')); + $roles = $this->_explode($this->getParam($params, 'roles')); + $permissions = $this->_explode($this->getParam($params, 'permissions')); - if (! $this->securityContext->isGranted($roles, $permissions)) { + if (! $this->securityContext->isGranted($roles, $permissions)) { - $ex = new AuthenticationException( - sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.", - implode(',', $roles), implode(',', $permissions), $context - ) - ); + $ex = new AuthenticationException( + sprintf("User not granted for roles '%s', permissions '%s' in context '%s'.", + implode(',', $roles), implode(',', $permissions), $context + ) + ); - $loginTpl = $this->getParam($params, 'login_tpl'); + $loginTpl = $this->getParam($params, 'login_tpl'); - if (null != $loginTpl) { - $ex->setLoginTemplate($loginTpl); - } + if (null != $loginTpl) { + $ex->setLoginTemplate($loginTpl); + } - throw $ex; - } + throw $ex; + } - return ''; + return ''; } + public function checkCartNotEmptyFunction($params, &$smarty) + { + $cart = $this->request->getSession()->getCart(); + if($cart===null || $cart->countCartItems() == 0) { + throw new OrderException('Cart must not be empty', OrderException::CART_EMPTY); + } + + return ""; + } + /** * Define the various smarty plugins handled by this class * @@ -77,7 +92,8 @@ class Security extends AbstractSmartyPlugin public function getPluginDescriptors() { return array( - new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction') + new SmartyPluginDescriptor('function', 'check_auth', $this, 'checkAuthFunction'), + new SmartyPluginDescriptor('function', 'check_cart_not_empty', $this, 'checkCartNotEmptyFunction'), ); } } diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index eb560a484..dbfe48e17 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -86,6 +86,8 @@ class Thelia extends Kernel $serviceContainer->setLogger('defaultLogger', \Thelia\Log\Tlog::getInstance()); $con->useDebug(true); } + + } /** diff --git a/core/lib/Thelia/Controller/Install/BaseInstallController.php b/core/lib/Thelia/Exception/OrderException.php old mode 100644 new mode 100755 similarity index 68% rename from core/lib/Thelia/Controller/Install/BaseInstallController.php rename to core/lib/Thelia/Exception/OrderException.php index bac7a4f19..d276f8b59 --- a/core/lib/Thelia/Controller/Install/BaseInstallController.php +++ b/core/lib/Thelia/Exception/OrderException.php @@ -21,39 +21,19 @@ /* */ /*************************************************************************************/ -namespace Thelia\Controller\Install; -use Symfony\Component\HttpFoundation\Response; -use Thelia\Controller\BaseController; +namespace Thelia\Exception; -/** - * Class BaseInstallController - * @package Thelia\Controller\Install - * @author Manuel Raynaud - */ -class BaseInstallController extends BaseController +class OrderException extends \RuntimeException { - /** - * @return a ParserInterface instance parser - */ - protected function getParser() + const UNKNOWN_EXCEPTION = 0; + + const CART_EMPTY = 100; + + public function __construct($message, $code = null, $previous = null) { - $parser = $this->container->get("thelia.parser"); - - // Define the template that shoud be used - $parser->setTemplate("install"); - - return $parser; - } - - public function render($templateName, $args = array()) - { - return new Response($this->renderRaw($templateName, $args)); - } - - public function renderRaw($templateName, $args = array()) - { - $data = $this->getParser()->render($templateName, $args); - - return $data; + if ($code === null) { + $code = self::UNKNOWN_EXCEPTION; + } + parent::__construct($message, $code, $previous); } } diff --git a/core/lib/Thelia/Form/InstallStep3Form.php b/core/lib/Thelia/Form/InstallStep3Form.php new file mode 100755 index 000000000..9388f14db --- /dev/null +++ b/core/lib/Thelia/Form/InstallStep3Form.php @@ -0,0 +1,111 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\GreaterThan; +use Symfony\Component\Validator\Constraints\NotBlank; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/29/13 + * Time: 3:45 PM + * + * Allow to build a form Install Step 3 Database connection + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class InstallStep3Form extends BaseForm +{ + /** + * Build Coupon form + * + * @return void + */ + protected function buildForm() + { + $this->formBuilder + ->add( + 'host', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'user', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'password', + 'text', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ) + ->add( + 'port', + 'text', + array( + 'constraints' => array( + new NotBlank(), + new GreaterThan( + array( + 'value' => 0 + ) + ) + ) + ) + ) + ->add( + 'locale', + 'hidden', + array( + 'constraints' => array( + new NotBlank() + ) + ) + ); + } + + /** + * Get form name + * + * @return string + */ + public function getName() + { + return 'thelia_install_step3'; + } +} diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php index 11b8d0999..aa41140dd 100644 --- a/core/lib/Thelia/Install/BaseInstall.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -25,19 +25,33 @@ use Thelia\Install\Exception\AlreadyInstallException; /** * Class BaseInstall + * * @author Manuel Raynaud */ abstract class BaseInstall { + /** @var bool If Installation wizard is launched by CLI */ + protected $isConsoleMode = true; + /** - * Verify if an installation already exists + * Constructor + * + * @param bool $verifyInstall Verify if an installation already exists + * + * @throws Exception\AlreadyInstallException */ public function __construct($verifyInstall = true) { - /* TODO : activate this part + + // Check if install wizard is launched via CLI + if (php_sapi_name() == 'cli') { + $this->isConsoleMode = true; + } else { + $this->isConsoleMode = false; + } if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { throw new AlreadyInstallException("Thelia is already installed"); - }*/ + } $this->exec(); diff --git a/core/lib/Thelia/Install/CheckDatabaseConnection.php b/core/lib/Thelia/Install/CheckDatabaseConnection.php new file mode 100644 index 000000000..c9c2060f5 --- /dev/null +++ b/core/lib/Thelia/Install/CheckDatabaseConnection.php @@ -0,0 +1,122 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install; + +use PDO; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Core\Translation\Translator; +use Thelia\Install\Exception\InstallException; + + +/** + * Class CheckDatabaseConnection + * + * Take care of integration tests (database connection) + * + * @package Thelia\Install + * @author Manuel Raynaud + * @author Guillaume MOREL + */ +class CheckDatabaseConnection extends BaseInstall +{ + protected $validationMessages = array(); + + /** @var bool If permissions are OK */ + protected $isValid = true; + + /** @var TranslatorInterface Translator Service */ + protected $translator = null; + + /** @var string Database host information */ + protected $host = null; + + /** @var string Database user information */ + protected $user = null; + + /** @var string Database password information */ + protected $password = null; + + /** @var int Database port information */ + protected $port = null; + + /** + * @var \PDO instance + */ + protected $connection = null; + + /** + * Constructor + * + * @param string $host Database host information + * @param string $user Database user information + * @param string $password Database password information + * @param int $port Database port information + * @param bool $verifyInstall If verify install + * @param Translator $translator Translator Service + * necessary for install wizard + */ + public function __construct($host, $user, $password, $port, $verifyInstall = true, Translator $translator = null) + { + $this->host = $host; + $this->user = $user; + $this->password = $password; + $this->port = $port; + + parent::__construct($verifyInstall); + } + + /** + * Perform database connection check + * + * @return bool + */ + public function exec() + { + + $dsn = "mysql:host=%s;port=%s"; + + try { + $this->connection = new \PDO( + sprintf($dsn, $this->host, $this->port), + $this->user, + $this->password + ); + } catch (\PDOException $e) { + + $this->validationMessages = 'Wrong connection information'; + + $this->isValid = false; + } + + return $this->isValid; + } + + public function getConnection() + { + return $this->connection; + } + +} diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php index db73330cf..d07b8ed83 100644 --- a/core/lib/Thelia/Install/CheckPermission.php +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -23,56 +23,364 @@ namespace Thelia\Install; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use Symfony\Component\Translation\TranslatorInterface; +use Thelia\Core\Translation\Translator; + /** * Class CheckPermission + * + * Take care of integration tests (files permissions) + * * @package Thelia\Install - * @author Manuel Raynaud + * @author Manuel Raynaud + * @author Guillaume MOREL */ class CheckPermission extends BaseInstall { - const CONF = "const"; - const LOG = "log"; - const CACHE = "cache"; - private $directories = array(); - private $validation = array(); - private $valid = true; + const DIR_CONF = 'local/config'; + const DIR_LOG = 'log'; + const DIR_CACHE = 'cache'; - public function __construct($verifyInstall = true) + /** @var array Directory needed to be writable */ + protected $directoriesToBeWritable = array( + self::DIR_CONF, + self::DIR_LOG, + self::DIR_CACHE, + ); + + /** @var array Minimum server configuration necessary */ + protected $minServerConfigurationNecessary = array( + 'memory_limit' => 134217728, + 'post_max_size' => 20971520, + 'upload_max_filesize' => 2097152 + ); + + protected $validationMessages = array(); + + /** @var bool If permissions are OK */ + protected $isValid = true; + + /** @var TranslatorInterface Translator Service */ + protected $translator = null; + + /** + * Constructor + * + * @param bool $verifyInstall If verify install + * @param Translator $translator Translator Service + * necessary for install wizard + */ + public function __construct($verifyInstall = true, Translator $translator = null) { + $this->translator = $translator; - - $this->directories = array( - self::CONF => THELIA_ROOT . "local/config", - self::LOG => THELIA_ROOT . "log", - self::CACHE => THELIA_ROOT . "cache" + $this->validationMessages['php_version'] = array( + 'text' => $this->getI18nPhpVersionText('5.4', phpversion(), true), + 'hint' => $this->getI18nPhpVersionHint(), + 'status' => true ); - $this->validation = array( - self::CONF => array( - "text" => sprintf("config directory(%s)...", $this->directories[self::CONF]), - "status" => true - ), - self::LOG => array( - "text" => sprintf("cache directory(%s)...", $this->directories[self::LOG]), - "status" => true - ), - self::CACHE => array( - "text" => sprintf("log directory(%s)...", $this->directories[self::CACHE]), - "status" => true - ) - ); + foreach ($this->directoriesToBeWritable as $directory) { + $this->validationMessages[$directory] = array( + 'text' => '', + 'hint' => '', + 'status' => true + ); + } + foreach ($this->minServerConfigurationNecessary as $key => $value) { + $this->validationMessages[$key] = array( + 'text' => '', + 'hint' => $this->getI18nConfigHint(), + 'status' => true + ); + } + parent::__construct($verifyInstall); } + /** + * Perform file permission check + * + * @return bool + */ public function exec() { - foreach ($this->directories as $key => $directory) { - if(is_writable($directory) === false) { - $this->valid = false; - $this->validation[$key]["status"] = false; + if (version_compare(phpversion(), '5.4', '<')) { + $this->validationMessages['php_version'] = $this->getI18nPhpVersionText('5.4', phpversion(), false); + } + + foreach ($this->directoriesToBeWritable as $directory) { + $fullDirectory = THELIA_ROOT . $directory; + $this->validationMessages[$directory]['text'] = $this->getI18nDirectoryText($fullDirectory, true); + if (is_writable($fullDirectory) === false) { + if (!$this->makeDirectoryWritable($fullDirectory)) { + $this->isValid = false; + $this->validationMessages[$directory]['status'] = false; + $this->validationMessages[$directory]['text'] = $this->getI18nDirectoryText($fullDirectory, false); + $this->validationMessages[$directory]['hint'] = $this->getI18nDirectoryHint($fullDirectory); + } } } + + foreach ($this->minServerConfigurationNecessary as $key => $value) { + $this->validationMessages[$key]['text'] = $this->getI18nConfigText($key, $this->formatBytes($value), ini_get($key), true); + if (!$this->verifyServerMemoryValues($key, $value)) { + $this->isValid = false; + $this->validationMessages[$key]['status'] = false; + $this->validationMessages[$key]['text'] = $this->getI18nConfigText($key, $this->formatBytes($value), ini_get($key), false);; + } + } + + + + + return $this->isValid; } -} \ No newline at end of file + + /** + * Get validation messages + * + * @return array + */ + public function getValidationMessages() + { + return $this->validationMessages; + } + + /** + * Make a directory writable (recursively) + * + * @param string $directory path to directory + * + * @return bool + */ + protected function makeDirectoryWritable($directory) + { + chmod($directory, 0777); + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory) + ); + foreach ($iterator as $item) { + chmod($item, 0777); + } + + return (is_writable(THELIA_ROOT . $directory) === true); + } + + + + /** + * Get Translated text about the directory state + * + * @param string $directory Directory being checked + * @param bool $isValid If directory permission is valid + * + * @return string + */ + protected function getI18nDirectoryText($directory, $isValid) + { + if ($this->translator !== null) { + if ($isValid) { + $sentence = 'Your directory %directory% is writable'; + } else { + $sentence = 'Your directory %directory% is not writable'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('Your directory %s needs to be writable', $directory); + } + + return $translatedText; + } + + /** + * Get Translated hint about the directory state + * + * @param string $directory Directory being checked + * + * @return string + */ + protected function getI18nDirectoryHint($directory) + { + if ($this->translator !== null) { + $sentence = 'chmod 777 %directory% on your server with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array( + '%directory%' => $directory + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('chmod 777 %s on your server with admin rights could help', $directory); + } + + return $translatedText; + } + + + /** + * Get Translated text about the directory state + * Not usable with CLI + * + * @param string $key .ini file key + * @param string $expectedValue Expected server value + * @param string $currentValue Actual server value + * @param bool $isValid If server configuration is valid + * + * @return string + */ + protected function getI18nConfigText($key, $expectedValue, $currentValue, $isValid) + { + if ($isValid) { + $sentence = 'Your %key% server configuration (currently %currentValue%) is well enough to run Thelia2 (%expectedValue% needed)'; + } else { + $sentence = 'Your %key% server configuration (currently %currentValue%) is not sufficient enough in order to run Thelia2 (%expectedValue% needed)'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%key%' => $key, + '%expectedValue%' => $expectedValue, + '%currentValue%' => $currentValue, + ), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Get Translated hint about the config requirement issue + * + * @return string + */ + protected function getI18nConfigHint() + { + $sentence = 'Modifying this value on your server php.ini file with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array(), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Get Translated hint about the PHP version requirement issue + * + * @param string $expectedValue + * @param string $currentValue + * @param bool $isValid + * + * @return string + */ + protected function getI18nPhpVersionText($expectedValue, $currentValue, $isValid) + { + if ($this->translator !== null) { + if ($isValid) { + $sentence = 'Your PHP version %currentValue% is well enough to run Thelia2 (%expectedValue% needed)'; + } else { + $sentence = 'Your PHP version %currentValue% is not sufficient enough to run Thelia2 (%expectedValue% needed)'; + } + + $translatedText = $this->translator->trans( + $sentence, + array( + '%expectedValue%' => $expectedValue, + '%currentValue%' => $currentValue, + ), + 'install-wizard' + ); + } else { + $translatedText = sprintf('Thelia needs at least PHP %s (%s currently)', $expectedValue, $currentValue); + } + + return $translatedText; + } + + /** + * Get Translated hint about the config requirement issue + * + * @return string + */ + protected function getI18nPhpVersionHint() + { + $sentence = 'Upgrading your version of PHP with admin rights could help'; + $translatedText = $this->translator->trans( + $sentence, + array(), + 'install-wizard' + ); + + return $translatedText; + } + + /** + * Check if a server memory value is met or not + * + * @param string $key .ini file key + * @param int $necessaryValueInBytes Expected value in bytes + * + * @return bool + */ + protected function verifyServerMemoryValues($key, $necessaryValueInBytes) + { + $serverValueInBytes = $this->returnBytes(ini_get($key)); + + return ($serverValueInBytes >= $necessaryValueInBytes); + } + + /** + * Return bytes from memory .ini value + * + * @param string $val .ini value + * + * @return int + */ + protected function returnBytes($val) + { + $val = trim($val); + $last = strtolower($val[strlen($val)-1]); + switch($last) { + // The 'G' modifier is available since PHP 5.1.0 + case 'g': + $val *= 1024; + case 'm': + $val *= 1024; + case 'k': + $val *= 1024; + } + + return $val; + } + + /** + * Convert bytes to readable string + * + * @param int $bytes bytes + * @param int $precision conversion precision + * + * @return string + */ + protected function formatBytes($bytes, $precision = 2) + { + $base = log($bytes) / log(1024); + $suffixes = array('', 'k', 'M', 'G', 'T'); + + return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)]; + } +} diff --git a/core/lib/Thelia/Install/Database.php b/core/lib/Thelia/Install/Database.php index 34ca97dae..648a6431a 100644 --- a/core/lib/Thelia/Install/Database.php +++ b/core/lib/Thelia/Install/Database.php @@ -93,7 +93,7 @@ class Database */ public function createDatabase($dbName) { - $this->connection->query( + $this->connection->exec( sprintf( "CREATE DATABASE IF NOT EXISTS %s CHARACTER SET utf8", $dbName diff --git a/core/lib/Thelia/Model/Admin.php b/core/lib/Thelia/Model/Admin.php index 67f6a5928..2712eb95c 100755 --- a/core/lib/Thelia/Model/Admin.php +++ b/core/lib/Thelia/Model/Admin.php @@ -34,8 +34,6 @@ class Admin extends BaseAdmin implements UserInterface public function setPassword($password) { - \Thelia\Log\Tlog::getInstance()->debug($password); - if ($this->isNew() && ($password === null || trim($password) == "")) { throw new \InvalidArgumentException("customer password is mandatory on creation"); } diff --git a/install/thelia.sql b/install/thelia.sql index 3d003091f..dd3247d57 100755 --- a/install/thelia.sql +++ b/install/thelia.sql @@ -893,6 +893,7 @@ CREATE TABLE `area_delivery_module` `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), + UNIQUE INDEX `delivery_module_id_area_id_UNIQUE` (`area_id`, `delivery_module_id`), INDEX `idx_area_delivery_module_area_id` (`area_id`), INDEX `idx_area_delivery_module_delivery_module_id` (`delivery_module_id`), CONSTRAINT `fk_area_delivery_module_area_id` diff --git a/local/config/schema.xml b/local/config/schema.xml index 688fc1fa4..9b52fff61 100755 --- a/local/config/schema.xml +++ b/local/config/schema.xml @@ -695,6 +695,10 @@ + + + + diff --git a/local/modules/Colissimo/Colissimo.php b/local/modules/Colissimo/Colissimo.php old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/plugin.xml b/local/modules/Colissimo/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/Colissimo/Config/schema.xml b/local/modules/Colissimo/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/config.xml b/local/modules/DebugBar/Config/config.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/plugin.xml b/local/modules/DebugBar/Config/plugin.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Config/schema.xml b/local/modules/DebugBar/Config/schema.xml old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DataCollector/PropelCollector.php b/local/modules/DebugBar/DataCollector/PropelCollector.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/DebugBar.php b/local/modules/DebugBar/DebugBar.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Listeners/DebugBarListeners.php b/local/modules/DebugBar/Listeners/DebugBarListeners.php old mode 100644 new mode 100755 diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php old mode 100644 new mode 100755 diff --git a/templates/default/account.html b/templates/default/account.html index 94bd58501..cffd5d754 100644 --- a/templates/default/account.html +++ b/templates/default/account.html @@ -1,6 +1,9 @@ -{check_auth context="front" roles="CUSTOMER" login_tpl="login"} {extends file="layout.tpl"} +{block name="no-return-functions"} + {check_auth context="front" roles="CUSTOMER" login_tpl="login"} +{/block} + {block name="breadcrumb"}