diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index 1014d7cad..377759a57 100755
--- a/core/lib/Thelia/Config/Resources/config.xml
+++ b/core/lib/Thelia/Config/Resources/config.xml
@@ -40,6 +40,8 @@
+
+
diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml
index 37ddde487..720761b40 100644
--- a/core/lib/Thelia/Config/Resources/routing/install.xml
+++ b/core/lib/Thelia/Config/Resources/routing/install.xml
@@ -5,27 +5,27 @@
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
- Thelia\Controller\Install\InstallController::index
+ Thelia\Controller\Install\InstallController::indexAction
- Thelia\Controller\Install\InstallController::checkPermission
+ Thelia\Controller\Install\InstallController::checkPermissionAction
- Thelia\Controller\Install\InstallController::databaseConnection
+ Thelia\Controller\Install\InstallController::databaseConnectionAction
- Thelia\Controller\Install\InstallController::databaseSelection
+ Thelia\Controller\Install\InstallController::databaseSelectionAction
- Thelia\Controller\Install\InstallController::generalInformation
+ Thelia\Controller\Install\InstallController::generalInformationAction
- Thelia\Controller\Install\InstallController::thanks
+ Thelia\Controller\Install\InstallController::thanksAction
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/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php
index 40e6643db..a6b0d975d 100644
--- a/core/lib/Thelia/Controller/Install/InstallController.php
+++ b/core/lib/Thelia/Controller/Install/InstallController.php
@@ -22,74 +22,231 @@
/*************************************************************************************/
namespace Thelia\Controller\Install;
+use Thelia\Form\Exception\FormValidationException;
+use Thelia\Form\InstallStep3Form;
+use Thelia\Install\CheckDatabaseConnection;
use Thelia\Install\CheckPermission;
+use Thelia\Install\Exception\AlreadyInstallException;
+use Thelia\Install\Exception\InstallException;
/**
* Class InstallController
+ *
* @package Thelia\Controller\Install
- * @author Manuel Raynaud
+ * @author Manuel Raynaud
+ * @author Guillaume MOREL
*/
class InstallController extends BaseInstallController
{
- public function index()
+ public function indexAction()
{
- //$this->verifyStep(1);
+ $args = array();
+ try {
+ //$this->verifyStep(1); // @todo implement
+ $this->getSession()->set("step", 1);
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
- $this->getSession()->set("step", 1);
return $this->render("index.html");
}
- public function checkPermission()
+ /**
+ * Integration tests
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function checkPermissionAction()
{
- //$this->verifyStep(2);
+ try {
+ //$this->verifyStep(2); // @todo implement
+ $checkPermission = new CheckPermission(true, $this->getTranslator());
+ $args['isValid'] = $isValid = $checkPermission->exec();
+ $args['validationMessages'] = $checkPermission->getValidationMessages();
- //$permission = new CheckPermission();
+ $this->getSession()->set("step", 2);
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+ $args = array();
- $this->getSession()->set("step", 2);
- return $this->render("step-2.html");
+
+ return $this->render("step-2.html", $args);
}
- public function databaseConnection()
+ /**
+ * Database connexion tests
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function databaseConnectionAction()
{
- //$this->verifyStep(2);
+ $args = array();
- //$permission = new CheckPermission();
+ try {
+ //$this->verifyStep(2); // @todo implement
- $this->getSession()->set("step", 3);
- return $this->render("step-3.html");
+ if ($this->getRequest()->isMethod('POST')) {
+ // Create the form from the request
+ $step3Form = new InstallStep3Form($this->getRequest());
+
+ $message = false;
+ try {
+ // Check the form against constraints violations
+ $form = $this->validateForm($step3Form, 'POST');
+
+ // Get the form field values
+ $data = $form->getData();
+ var_dump('data', $data);
+
+ // @todo implement tests
+ try {
+ new CheckDatabaseConnection(
+ $data['host'],
+ $data['user'],
+ $data['password'],
+ $data['port'],
+ true,
+ $this->getTranslator()
+ );
+
+ $this->getSession()->set('install', array(
+ 'host' =>$data['host'],
+ 'user' => $data['user'],
+ 'password' => $data['password'],
+ 'port' => $data['port']
+ )
+ );
+ } catch (InstallException $e) {
+ $message = $this->getTranslator()->trans(
+ 'Can\'t connect with these credentials to this server',
+ array(),
+ 'install-wizard'
+ );
+ }
+
+ // $this->redirect(
+ // str_replace(
+ // '{id}',
+ // $couponEvent->getCoupon()->getId(),
+ // $creationForm->getSuccessUrl()
+ // )
+ // );
+ } catch (FormValidationException $e) {
+ // Invalid data entered
+ $message = $this->getTranslator()->trans(
+ 'Please check your input:',
+ array(),
+ 'install-wizard'
+ );
+
+ } catch (\Exception $e) {
+ // Any other error
+ $message = $this->getTranslator()->trans(
+ 'Sorry, an error occurred:',
+ array(),
+ 'install-wizard'
+ );
+ }
+
+ if ($message !== false) {
+ // Mark the form as with error
+ $step3Form->setErrorMessage($message);
+
+ // Send the form and the error to the parser
+ $this->getParserContext()
+ ->addForm($step3Form)
+ ->setGeneralError($message);
+ }
+ }
+
+ $this->getSession()->set("step", 3);
+
+ $args['edit_language_locale'] = $this->getSession()->getLang()->getLocale();
+ $args['formAction'] = 'install/step/3';
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+
+ return $this->render('step-3.html', $args);
}
- public function databaseSelection()
+ /**
+ * Database selection
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function databaseSelectionAction()
{
- //$this->verifyStep(2);
+ $args = array();
+ try {
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+
+ //$this->verifyStep(2); // @todo implement
//$permission = new CheckPermission();
$this->getSession()->set("step", 4);
+
return $this->render("step-4.html");
}
- public function generalInformation()
+ /**
+ * Set general information
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function generalInformationAction()
{
- //$this->verifyStep(2);
+ $args = array();
+ try {
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+ //$this->verifyStep(2); // @todo implement
//$permission = new CheckPermission();
$this->getSession()->set("step", 5);
+
return $this->render("step-5.html");
}
- public function thanks()
+ /**
+ * Display Thanks page
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function thanksAction()
{
- //$this->verifyStep(2);
+ $args = array();
+ try {
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+ //$this->verifyStep(2); // @todo implement
//$permission = new CheckPermission();
$this->getSession()->set("step", 6);
+
return $this->render("thanks.html");
}
+ /**
+ * Verify each steps and redirect if one step has already been passed
+ *
+ * @param int $step Step number
+ *
+ * @return bool
+ */
protected function verifyStep($step)
{
$session = $this->getSession();
@@ -107,5 +264,7 @@ class InstallController extends BaseInstallController
}
break;
}
+
+ return true;
}
}
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/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/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/install/index.html b/templates/install/index.html
index dd1d5f62b..b7843d528 100644
--- a/templates/install/index.html
+++ b/templates/install/index.html
@@ -34,7 +34,7 @@
diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl
index 4539ce32f..1497d7ea5 100644
--- a/templates/install/layout.tpl
+++ b/templates/install/layout.tpl
@@ -26,8 +26,12 @@
{* -- Main page content section ----------------------------------------- *}
+ {if $isAlreadyInstalled}
+ {intl l='Thelia is already installed'}
+ {else}
+ {block name="main-content"}Put here the content of the template{/block}
+ {/if}
- {block name="main-content"}Put here the content of the template{/block}
{* -- Footer section ---------------------------------------------------- *}
@@ -38,7 +42,6 @@
- {intl l='Édité par OpenStudio'}
- {intl l='Forum Thelia'}
- {intl l='Contributions Thelia'}
- {intl l='interface par Steaw-Webdesign'}
{module_include location='in_footer'}
diff --git a/templates/install/step-2.html b/templates/install/step-2.html
index fc24d25cb..fbd34ddb5 100644
--- a/templates/install/step-2.html
+++ b/templates/install/step-2.html
@@ -24,22 +24,21 @@
-
We will check some rights to files and directories...
+
{intl l="Checking directory permissions ..."}
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
- - Duis mollis, est non commodo luctus, nisi erat porttitor ligula.
+ {foreach from=$validationMessages item=validationMessage}
+ -
+ {$validationMessage.text nofilter}
+ {if !$validationMessage.status} - {$validationMessage.hint nofilter}{/if}
+
+ {/foreach}
diff --git a/templates/install/step-3.html b/templates/install/step-3.html
index cb4157dd7..f93b0182b 100644
--- a/templates/install/step-3.html
+++ b/templates/install/step-3.html
@@ -23,29 +23,59 @@
-
-
-
+ {form name="thelia.install.step3"}
+
-
-
+ {form_hidden_fields form=$form}
+
+ {form_field form=$form field='locale'}
+
+ {/form_field}
+
+
+
+
+
+ {/form}
diff --git a/web/install/bdd.php b/web/install/bdd.php
new file mode 100644
index 000000000..05fcfe762
--- /dev/null
+++ b/web/install/bdd.php
@@ -0,0 +1,119 @@
+. */
+/* */
+/*************************************************************************************/
+
+$step=4;
+include("header.php");
+
+if (isset($_POST['host']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['port'])){
+
+ $_SESSION['install']['host'] = $_POST['host'];
+ $_SESSION['install']['username'] = $_POST['username'];
+ $_SESSION['install']['password'] = $_POST['password'];
+ $_SESSION['install']['port'] = $_POST['port'];
+
+ $checkConnection = new \Thelia\Install\CheckDatabaseConnection($_POST['host'], $_POST['username'], $_POST['password'], $_POST['port']);
+ if(! $checkConnection->exec() || $checkConnection->getConnection()->query('show databases') === false){
+ header('location: connection.php?err=1');
+ exit;
+ }
+}
+elseif($_SESSION['install']['step'] >=3) {
+
+ $checkConnection = new \Thelia\Install\CheckDatabaseConnection($_SESSION['install']['host'], $_SESSION['install']['username'], $_SESSION['install']['password'], $_SESSION['install']['port']);
+}
+else {
+ header('location: connection.php?err=1');
+ exit;
+}
+$_SESSION['install']['step'] = 4;
+$connection = $checkConnection->getConnection();
+
+$databases = $connection->query('show databases');
+?>
+
+
+
\ No newline at end of file
diff --git a/web/install/bootstrap.php b/web/install/bootstrap.php
new file mode 100644
index 000000000..522f6483b
--- /dev/null
+++ b/web/install/bootstrap.php
@@ -0,0 +1,27 @@
+. */
+/* */
+/*************************************************************************************/
+
+include __DIR__ . "/../../core/bootstrap.php";
+
+$thelia = new \Thelia\Core\Thelia("install", false);
+$thelia->boot();
\ No newline at end of file
diff --git a/web/install/config.php b/web/install/config.php
new file mode 100644
index 000000000..9ba221cdd
--- /dev/null
+++ b/web/install/config.php
@@ -0,0 +1,110 @@
+. */
+/* */
+/*************************************************************************************/
+
+$step = 5;
+include("header.php");
+global $thelia;
+$err = isset($_GET['err']) && $_GET['err'];
+
+if (!$err && $_SESSION['install']['step'] != $step) {
+ $checkConnection = new \Thelia\Install\CheckDatabaseConnection($_SESSION['install']['host'], $_SESSION['install']['username'], $_SESSION['install']['password'], $_SESSION['install']['port']);
+ $connection = $checkConnection->getConnection();
+ $connection->exec("SET NAMES UTF8");
+ $database = new \Thelia\Install\Database($connection);
+
+ if (isset($_POST['database'])) {
+ $_SESSION['install']['database'] = $_POST['database'];
+ }
+
+ if (isset($_POST['database_create']) && $_POST['database_create'] != "") {
+ $_SESSION['install']['database'] = $_POST['database_create'];
+ $database->createDatabase($_SESSION['install']['database']);
+ }
+
+ $database->insertSql($_SESSION['install']['database']);
+
+ if(!file_exists(THELIA_ROOT . "/local/config/database.yml")) {
+ $fs = new \Symfony\Component\Filesystem\Filesystem();
+
+ $sampleConfigFile = THELIA_ROOT . "/local/config/database.yml.sample";
+ $configFile = THELIA_ROOT . "/local/config/database.yml";
+
+ $fs->copy($sampleConfigFile, $configFile, true);
+
+ $configContent = file_get_contents($configFile);
+
+ $configContent = str_replace("%DRIVER%", "mysql", $configContent);
+ $configContent = str_replace("%USERNAME%", $_SESSION['install']['username'], $configContent);
+ $configContent = str_replace("%PASSWORD%", $_SESSION['install']['password'], $configContent);
+ $configContent = str_replace(
+ "%DSN%",
+ sprintf("mysql:host=%s;dbname=%s;port=%s", $_SESSION['install']['host'], $_SESSION['install']['database'], $_SESSION['install']['port']),
+ $configContent
+ );
+
+ file_put_contents($configFile, $configContent);
+
+ // FA - no, as no further install will be possible
+ // $fs->remove($sampleConfigFile);
+
+ $fs->remove($thelia->getContainer()->getParameter("kernel.cache_dir"));
+ }
+}
+
+$_SESSION['install']['step'] = $step;
+
+?>
+
+
+
+
diff --git a/web/install/connection.php b/web/install/connection.php
new file mode 100644
index 000000000..fdbddfafd
--- /dev/null
+++ b/web/install/connection.php
@@ -0,0 +1,67 @@
+. */
+/* */
+/*************************************************************************************/
+
+$step = 3;
+include("header.php");
+if(!$_SESSION['install']['continue'] && $_SESSION['install']['step'] == 2) {
+ header(sprintf('location: %s', $_SESSION['install']['return_step']));
+}
+
+$_SESSION['install']['step'] = 3;
+?>
+
+
+
+
\ No newline at end of file
diff --git a/web/install/end.php b/web/install/end.php
new file mode 100644
index 000000000..a86c2d903
--- /dev/null
+++ b/web/install/end.php
@@ -0,0 +1,57 @@
+. */
+/* */
+/*************************************************************************************/
+$step=6;
+include "header.php";
+
+if($_SESSION['install']['step'] != $step && (empty($_POST['admin_login']) || empty($_POST['admin_password']) || ($_POST['admin_password'] != $_POST['admin_password_verif']))) {
+ header('location: config.php?err=1');
+}
+
+if($_SESSION['install']['step'] == 5) {
+ $admin = new \Thelia\Model\Admin();
+ $admin->setLogin($_POST['admin_login'])
+ ->setPassword($_POST['admin_password'])
+ ->setFirstname('admin')
+ ->setLastname('admin')
+ ->save();
+
+ $config = new \Thelia\Model\Config();
+ $config->setName('contact_email')
+ ->setValue($_POST['email_contact'])
+ ->save();
+ ;
+}
+
+$_SESSION['install']['step'] = $step;
+?>
+
+
+
+ Thank you have installed Thelia
+
+
+ Don't forget to delete the web/install directory.
+
+
+
+
\ No newline at end of file
diff --git a/web/install/fd33fd0-6fda040.ico b/web/install/fd33fd0-6fda040.ico
new file mode 100644
index 000000000..24c27fefd
Binary files /dev/null and b/web/install/fd33fd0-6fda040.ico differ
diff --git a/web/install/footer.php b/web/install/footer.php
new file mode 100644
index 000000000..29e87f2c2
--- /dev/null
+++ b/web/install/footer.php
@@ -0,0 +1,41 @@
+. */
+/* */
+/*************************************************************************************/
+?>
+
+
+
+
+
+
+
+
+