From b6bc6994fc007254bd8a9b64456a24471244303e Mon Sep 17 00:00:00 2001
From: gmorel
Date: Mon, 16 Sep 2013 10:53:15 +0200
Subject: [PATCH 1/9] WIP : Install wizard
---
.../Controller/Install/InstallController.php | 3 ++-
core/lib/Thelia/Install/CheckPermission.php | 25 ++++++++++---------
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php
index 40e6643db..75594868a 100644
--- a/core/lib/Thelia/Controller/Install/InstallController.php
+++ b/core/lib/Thelia/Controller/Install/InstallController.php
@@ -42,9 +42,10 @@ class InstallController extends BaseInstallController
public function checkPermission()
{
+ var_dump('step2');
//$this->verifyStep(2);
- //$permission = new CheckPermission();
+ $permission = new CheckPermission();
$this->getSession()->set("step", 2);
return $this->render("step-2.html");
diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php
index db73330cf..e57185c36 100644
--- a/core/lib/Thelia/Install/CheckPermission.php
+++ b/core/lib/Thelia/Install/CheckPermission.php
@@ -31,9 +31,10 @@ namespace Thelia\Install;
*/
class CheckPermission extends BaseInstall
{
- const CONF = "const";
- const LOG = "log";
- const CACHE = "cache";
+
+ const DIR_CONF = 'local/config';
+ const DIR_LOG = 'log';
+ const DIR_CACHE = 'cache';
private $directories = array();
private $validation = array();
@@ -44,22 +45,22 @@ class CheckPermission extends BaseInstall
$this->directories = array(
- self::CONF => THELIA_ROOT . "local/config",
- self::LOG => THELIA_ROOT . "log",
- self::CACHE => THELIA_ROOT . "cache"
+ self::DIR_CONF => THELIA_ROOT . 'local/config',
+ self::DIR_LOG => THELIA_ROOT . 'DIR_LOG',
+ self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE'
);
$this->validation = array(
- self::CONF => array(
- "text" => sprintf("config directory(%s)...", $this->directories[self::CONF]),
+ self::DIR_CONF => array(
+ "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]),
"status" => true
),
- self::LOG => array(
- "text" => sprintf("cache directory(%s)...", $this->directories[self::LOG]),
+ self::DIR_LOG => array(
+ "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]),
"status" => true
),
- self::CACHE => array(
- "text" => sprintf("log directory(%s)...", $this->directories[self::CACHE]),
+ self::DIR_CACHE => array(
+ "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]),
"status" => true
)
);
From b151325e572c9c23a1940e9565462c2abe29ee6f Mon Sep 17 00:00:00 2001
From: gmorel
Date: Mon, 16 Sep 2013 15:07:41 +0200
Subject: [PATCH 2/9] WIP : Install wizard : step 2 file permission
---
.../Controller/Install/InstallController.php | 70 ++++++-
core/lib/Thelia/Install/BaseInstall.php | 15 +-
core/lib/Thelia/Install/CheckPermission.php | 183 ++++++++++++++----
templates/install/layout.tpl | 1 -
templates/install/step-2.html | 15 +-
5 files changed, 232 insertions(+), 52 deletions(-)
diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php
index 75594868a..648ae843e 100644
--- a/core/lib/Thelia/Controller/Install/InstallController.php
+++ b/core/lib/Thelia/Controller/Install/InstallController.php
@@ -26,12 +26,14 @@ use Thelia\Install\CheckPermission;
/**
* 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);
@@ -40,57 +42,109 @@ class InstallController extends BaseInstallController
return $this->render("index.html");
}
- public function checkPermission()
+ /**
+ * Integration tests
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function checkPermissionAction()
{
+ $args = array();
var_dump('step2');
//$this->verifyStep(2);
- $permission = new CheckPermission();
+ $checkPermission = new CheckPermission(true, $this->getTranslator());
+ $args['isValid'] = $isValid = $checkPermission->exec();
+ $args['validationMessages'] = $checkPermission->getValidationMessages();
$this->getSession()->set("step", 2);
- return $this->render("step-2.html");
+
+ return $this->render("step-2.html", $args);
}
+ /**
+ * Database connexion tests
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
public function databaseConnection()
{
+ var_dump('step 3 bis');
+ }
+
+ /**
+ * Database connexion tests
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function databaseConnectionAction()
+ {
+ var_dump('step 3');
+ exit();
//$this->verifyStep(2);
//$permission = new CheckPermission();
$this->getSession()->set("step", 3);
+
return $this->render("step-3.html");
}
- public function databaseSelection()
+ /**
+ * Database selection
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function databaseSelectionAction()
{
//$this->verifyStep(2);
//$permission = new CheckPermission();
$this->getSession()->set("step", 4);
+
return $this->render("step-4.html");
}
- public function generalInformation()
+ /**
+ * Set general informations
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function generalInformationAction()
{
//$this->verifyStep(2);
//$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);
//$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();
diff --git a/core/lib/Thelia/Install/BaseInstall.php b/core/lib/Thelia/Install/BaseInstall.php
index 11b8d0999..86928236a 100644
--- a/core/lib/Thelia/Install/BaseInstall.php
+++ b/core/lib/Thelia/Install/BaseInstall.php
@@ -25,15 +25,28 @@ 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
*/
public function __construct($verifyInstall = true)
{
+
+ // Check if install wizard is launched via CLI
+ if (php_sapi_name() == 'cli') {
+ $this->isConsoleMode = true;
+ } else {
+ $this->isConsoleMode = false;
+ }
/* TODO : activate this part
if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) {
throw new AlreadyInstallException("Thelia is already installed");
diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php
index e57185c36..d924bac35 100644
--- a/core/lib/Thelia/Install/CheckPermission.php
+++ b/core/lib/Thelia/Install/CheckPermission.php
@@ -23,57 +23,172 @@
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 DIR_CONF = 'local/config';
- const DIR_LOG = 'log';
- const DIR_CACHE = 'cache';
+ const DIR_CONF = 'local/config';
+ const DIR_LOG = 'log';
+ const DIR_CACHE = 'cache';
- private $directories = array();
- private $validation = array();
- private $valid = true;
+ /** @var array Directory needed to be writable */
+ protected $directoriesToBeWritable = array(
+ self::DIR_CONF,
+ self::DIR_LOG,
+ self::DIR_CACHE,
+ );
- public function __construct($verifyInstall = true)
+ 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::DIR_CONF => THELIA_ROOT . 'local/config',
- self::DIR_LOG => THELIA_ROOT . 'DIR_LOG',
- self::DIR_CACHE => THELIA_ROOT . 'DIR_CACHE'
- );
-
- $this->validation = array(
- self::DIR_CONF => array(
- "text" => sprintf("config directory(%s)...", $this->directories[self::DIR_CONF]),
- "status" => true
- ),
- self::DIR_LOG => array(
- "text" => sprintf("DIR_CACHE directory(%s)...", $this->directories[self::DIR_LOG]),
- "status" => true
- ),
- self::DIR_CACHE => array(
- "text" => sprintf("DIR_LOG directory(%s)...", $this->directories[self::DIR_CACHE]),
- "status" => true
- )
- );
+ foreach ($this->directoriesToBeWritable as $directory) {
+ $this->validationMessages[$directory] = array(
+ 'text' => '',
+ 'hint' => '',
+ '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;
+ foreach ($this->directoriesToBeWritable as $directory) {
+ $fullDirectory = THELIA_ROOT . $directory;
+ $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, true);
+ if (is_writable($fullDirectory) === false) {
+ if (!$this->makeDirectoryWritable($fullDirectory)) {
+ $this->isValid = false;
+ $this->validationMessages[$directory]['status'] = false;
+ $this->validationMessages[$directory]['text'] = $this->getI18nText($fullDirectory, false);
+ $this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory);
+ }
}
}
+
+ 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 getI18nText($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 getI18nHint($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;
+ }
+}
diff --git a/templates/install/layout.tpl b/templates/install/layout.tpl
index 4539ce32f..6b38292e2 100644
--- a/templates/install/layout.tpl
+++ b/templates/install/layout.tpl
@@ -38,7 +38,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..a05267c7c 100644
--- a/templates/install/step-2.html
+++ b/templates/install/step-2.html
@@ -24,15 +24,14 @@
-
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}
From bca2b58e416c9fb1d01aa55f9165d7f3151657bb Mon Sep 17 00:00:00 2001
From: gmorel
Date: Mon, 16 Sep 2013 15:07:58 +0200
Subject: [PATCH 3/9] Merge master
---
local/modules/Colissimo/Colissimo.php | 0
local/modules/Colissimo/Config/config.xml | 0
local/modules/Colissimo/Config/plugin.xml | 0
local/modules/Colissimo/Config/schema.xml | 0
local/modules/DebugBar/Config/config.xml | 0
local/modules/DebugBar/Config/plugin.xml | 0
local/modules/DebugBar/Config/schema.xml | 0
local/modules/DebugBar/DataCollector/PropelCollector.php | 0
local/modules/DebugBar/DebugBar.php | 0
local/modules/DebugBar/Listeners/DebugBarListeners.php | 0
local/modules/DebugBar/Smarty/Plugin/DebugBar.php | 0
11 files changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 local/modules/Colissimo/Colissimo.php
mode change 100644 => 100755 local/modules/Colissimo/Config/config.xml
mode change 100644 => 100755 local/modules/Colissimo/Config/plugin.xml
mode change 100644 => 100755 local/modules/Colissimo/Config/schema.xml
mode change 100644 => 100755 local/modules/DebugBar/Config/config.xml
mode change 100644 => 100755 local/modules/DebugBar/Config/plugin.xml
mode change 100644 => 100755 local/modules/DebugBar/Config/schema.xml
mode change 100644 => 100755 local/modules/DebugBar/DataCollector/PropelCollector.php
mode change 100644 => 100755 local/modules/DebugBar/DebugBar.php
mode change 100644 => 100755 local/modules/DebugBar/Listeners/DebugBarListeners.php
mode change 100644 => 100755 local/modules/DebugBar/Smarty/Plugin/DebugBar.php
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
From cfc52c4e7fade57c5d5f5f157eab6a3c84de5cc9 Mon Sep 17 00:00:00 2001
From: gmorel
Date: Mon, 16 Sep 2013 18:15:09 +0200
Subject: [PATCH 4/9] Working : install wizard : type inference
---
core/lib/Thelia/Controller/BaseController.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php
index 19e62a400..d5c54e991 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;
@@ -89,7 +90,7 @@ class BaseController extends ContainerAware
*
* return the Translator
*
- * @return mixed \Thelia\Core\Translation\Translator
+ * @return Translator
*/
public function getTranslator()
{
From 63472b9f80e1be15a736bd38a1bc921f7ec515f4 Mon Sep 17 00:00:00 2001
From: gmorel
Date: Mon, 16 Sep 2013 19:00:28 +0200
Subject: [PATCH 5/9] WIP : install wizard : step 1, 2, 3
---
core/lib/Thelia/Config/Resources/config.xml | 2 +
.../Config/Resources/routing/install.xml | 12 +-
.../Controller/Install/InstallController.php | 162 +++++++++++---
core/lib/Thelia/Form/InstallStep3Form.php | 111 ++++++++++
core/lib/Thelia/Install/BaseInstall.php | 5 +-
.../Install/CheckDatabaseConnection.php | 100 +++++++++
core/lib/Thelia/Install/CheckPermission.php | 202 +++++++++++++++++-
templates/install/index.html | 2 +-
templates/install/layout.tpl | 6 +-
templates/install/step-2.html | 4 +-
templates/install/step-3.html | 74 +++++--
11 files changed, 612 insertions(+), 68 deletions(-)
create mode 100755 core/lib/Thelia/Form/InstallStep3Form.php
create mode 100644 core/lib/Thelia/Install/CheckDatabaseConnection.php
diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml
index 691cf2198..b90ca3e45 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/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php
index 648ae843e..a6b0d975d 100644
--- a/core/lib/Thelia/Controller/Install/InstallController.php
+++ b/core/lib/Thelia/Controller/Install/InstallController.php
@@ -22,7 +22,12 @@
/*************************************************************************************/
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
@@ -35,9 +40,14 @@ class InstallController extends BaseInstallController
{
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");
}
@@ -49,29 +59,22 @@ class InstallController extends BaseInstallController
*/
public function checkPermissionAction()
{
+ try {
+ //$this->verifyStep(2); // @todo implement
+ $checkPermission = new CheckPermission(true, $this->getTranslator());
+ $args['isValid'] = $isValid = $checkPermission->exec();
+ $args['validationMessages'] = $checkPermission->getValidationMessages();
+
+ $this->getSession()->set("step", 2);
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
$args = array();
- var_dump('step2');
- //$this->verifyStep(2);
- $checkPermission = new CheckPermission(true, $this->getTranslator());
- $args['isValid'] = $isValid = $checkPermission->exec();
- $args['validationMessages'] = $checkPermission->getValidationMessages();
-
- $this->getSession()->set("step", 2);
return $this->render("step-2.html", $args);
}
- /**
- * Database connexion tests
- *
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function databaseConnection()
- {
- var_dump('step 3 bis');
- }
-
/**
* Database connexion tests
*
@@ -79,15 +82,95 @@ class InstallController extends BaseInstallController
*/
public function databaseConnectionAction()
{
- var_dump('step 3');
- exit();
- //$this->verifyStep(2);
+ $args = array();
- //$permission = new CheckPermission();
+ try {
+ //$this->verifyStep(2); // @todo implement
- $this->getSession()->set("step", 3);
+ if ($this->getRequest()->isMethod('POST')) {
+ // Create the form from the request
+ $step3Form = new InstallStep3Form($this->getRequest());
- return $this->render("step-3.html");
+ $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);
}
/**
@@ -97,7 +180,14 @@ class InstallController extends BaseInstallController
*/
public function databaseSelectionAction()
{
- //$this->verifyStep(2);
+ $args = array();
+ try {
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+
+ //$this->verifyStep(2); // @todo implement
//$permission = new CheckPermission();
@@ -107,13 +197,19 @@ class InstallController extends BaseInstallController
}
/**
- * Set general informations
+ * 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();
@@ -129,7 +225,13 @@ class InstallController extends BaseInstallController
*/
public function thanksAction()
{
- //$this->verifyStep(2);
+ $args = array();
+ try {
+
+ } catch (AlreadyInstallException $e) {
+ $args['isAlreadyInstalled'] = true;
+ }
+ //$this->verifyStep(2); // @todo implement
//$permission = new CheckPermission();
@@ -162,5 +264,7 @@ class InstallController extends BaseInstallController
}
break;
}
+
+ return 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 86928236a..aa41140dd 100644
--- a/core/lib/Thelia/Install/BaseInstall.php
+++ b/core/lib/Thelia/Install/BaseInstall.php
@@ -37,6 +37,8 @@ abstract class BaseInstall
* Constructor
*
* @param bool $verifyInstall Verify if an installation already exists
+ *
+ * @throws Exception\AlreadyInstallException
*/
public function __construct($verifyInstall = true)
{
@@ -47,10 +49,9 @@ abstract class BaseInstall
} else {
$this->isConsoleMode = false;
}
- /* TODO : activate this part
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..50c117d22
--- /dev/null
+++ b/core/lib/Thelia/Install/CheckDatabaseConnection.php
@@ -0,0 +1,100 @@
+. */
+/* */
+/*************************************************************************************/
+
+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;
+
+ /**
+ * 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()
+ {
+ $link = mysql_connect($this->host . ':' . $this->port, $this->user, $this->password);
+ if (!$link) {
+ throw new InstallException('Can\'t connect to the given credentials');
+ }
+ mysql_close($link);
+ }
+
+}
diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php
index d924bac35..d07b8ed83 100644
--- a/core/lib/Thelia/Install/CheckPermission.php
+++ b/core/lib/Thelia/Install/CheckPermission.php
@@ -52,6 +52,13 @@ class CheckPermission extends BaseInstall
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 */
@@ -71,6 +78,12 @@ class CheckPermission extends BaseInstall
{
$this->translator = $translator;
+ $this->validationMessages['php_version'] = array(
+ 'text' => $this->getI18nPhpVersionText('5.4', phpversion(), true),
+ 'hint' => $this->getI18nPhpVersionHint(),
+ 'status' => true
+ );
+
foreach ($this->directoriesToBeWritable as $directory) {
$this->validationMessages[$directory] = array(
'text' => '',
@@ -78,6 +91,14 @@ class CheckPermission extends BaseInstall
'status' => true
);
}
+ foreach ($this->minServerConfigurationNecessary as $key => $value) {
+ $this->validationMessages[$key] = array(
+ 'text' => '',
+ 'hint' => $this->getI18nConfigHint(),
+ 'status' => true
+ );
+ }
+
parent::__construct($verifyInstall);
}
@@ -88,19 +109,35 @@ class CheckPermission extends BaseInstall
*/
public function exec()
{
+ 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->getI18nText($fullDirectory, true);
+ $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->getI18nText($fullDirectory, false);
- $this->validationMessages[$directory]['hint'] = $this->getI18nHint($fullDirectory);
+ $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;
}
@@ -144,7 +181,7 @@ class CheckPermission extends BaseInstall
*
* @return string
*/
- protected function getI18nText($directory, $isValid)
+ protected function getI18nDirectoryText($directory, $isValid)
{
if ($this->translator !== null) {
if ($isValid) {
@@ -174,7 +211,7 @@ class CheckPermission extends BaseInstall
*
* @return string
*/
- protected function getI18nHint($directory)
+ protected function getI18nDirectoryHint($directory)
{
if ($this->translator !== null) {
$sentence = 'chmod 777 %directory% on your server with admin rights could help';
@@ -191,4 +228,159 @@ class CheckPermission extends BaseInstall
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/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 6b38292e2..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 ---------------------------------------------------- *}
diff --git a/templates/install/step-2.html b/templates/install/step-2.html
index a05267c7c..fbd34ddb5 100644
--- a/templates/install/step-2.html
+++ b/templates/install/step-2.html
@@ -37,8 +37,8 @@
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}
From eeb9a0f9ebf659a6d2455b047ae86c17c4f48546 Mon Sep 17 00:00:00 2001
From: Manuel Raynaud
Date: Mon, 16 Sep 2013 20:42:18 +0200
Subject: [PATCH 6/9] use sqlite database for install process
---
core/lib/Thelia/Core/Thelia.php | 39 ++++++++++++++++++++------------
install/thelia.sqlite | Bin 0 -> 262144 bytes
2 files changed, 24 insertions(+), 15 deletions(-)
create mode 100644 install/thelia.sqlite
diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php
index eb560a484..b446af221 100755
--- a/core/lib/Thelia/Core/Thelia.php
+++ b/core/lib/Thelia/Core/Thelia.php
@@ -69,23 +69,32 @@ class Thelia extends Kernel
protected function initPropel()
{
- if (file_exists(THELIA_ROOT . '/local/config/database.yml') === false) {
- return ;
+ if (defined('THELIA_INSTALL_MODE') === true) {
+ $serviceContainer = Propel::getServiceContainer();
+ $serviceContainer->setAdapterClass('thelia', 'sqlite');
+ $manager = new ConnectionManagerSingle();
+ $manager->setConfiguration(array(
+ "classname" => "\Propel\Runtime\Connection\PropelPDO",
+ "dsn" => "sqlite:".THELIA_ROOT . "/install/thelia.sqlite"
+ ));
+ $serviceContainer->setConnectionManager('thelia', $manager);
+ } else {
+ $definePropel = new DefinePropel(new DatabaseConfiguration(),
+ Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
+ $serviceContainer = Propel::getServiceContainer();
+ $serviceContainer->setAdapterClass('thelia', 'mysql');
+ $manager = new ConnectionManagerSingle();
+ $manager->setConfiguration($definePropel->getConfig());
+ $serviceContainer->setConnectionManager('thelia', $manager);
+ $con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
+ $con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
+ if ($this->isDebug()) {
+ $serviceContainer->setLogger('defaultLogger', \Thelia\Log\Tlog::getInstance());
+ $con->useDebug(true);
+ }
}
- $definePropel = new DefinePropel(new DatabaseConfiguration(),
- Yaml::parse(THELIA_ROOT . '/local/config/database.yml'));
- $serviceContainer = Propel::getServiceContainer();
- $serviceContainer->setAdapterClass('thelia', 'mysql');
- $manager = new ConnectionManagerSingle();
- $manager->setConfiguration($definePropel->getConfig());
- $serviceContainer->setConnectionManager('thelia', $manager);
- $con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
- $con->setAttribute(ConnectionWrapper::PROPEL_ATTR_CACHE_PREPARES, true);
- if ($this->isDebug()) {
- $serviceContainer->setLogger('defaultLogger', \Thelia\Log\Tlog::getInstance());
- $con->useDebug(true);
- }
+
}
/**
diff --git a/install/thelia.sqlite b/install/thelia.sqlite
new file mode 100644
index 0000000000000000000000000000000000000000..65d4cb6a9fb8af1ef1ccd4edbb66f4072e3e8d00
GIT binary patch
literal 262144
zcmeI*&u=4F9RTpL_eXw+DE*;
zVeaw2gQ@+`f=~bU>2H4im!Hi%{?GnrkAHtzhiSEM%U%Kd3)!$BkjH7k3)_wbtFYI};aEOO>cpjlyc_hpSOI
z(KK6_4U?nQ3|Gq4=-sFime;Fcd2@Aj@wlPgZPeRw_(7?%^j@h_xK|ACN6V$n)oQp9
zcWRp(3m5u#>bqyXzkRPb8s$M{Wvx`%3V#%Bg@smgaWv{l-JlNR<|==veB3i_iN2~yFP3W!s<$SD_PEy
z-|EFle6yCk)w{Z~7Hw2ZYY#>(!@cHHEwjZZA6}oz-MW?e<%`D@?Rw`?`nfSdkkb@RViPJF|N8-gv8}Db-HiVm{urry+yZ?&XbXdBgPdrvRbV5d9m*E`Mrmvw56#_2yDe%Ts6d&L{ixw5}_>)KTA&YjHB
zYokrx?QFLmjh+@~#p@I6oNt`9R?_Zz*|
zUb=D5S2uR*d)<6kjecBBqLM@hqi)09QDyN#_Ga$YS2J73b3VDV`|-!a7-;%1q^6c_s7Y;GDxK(d@(sC)r<2{QS)wPTbw$1WNjYqa?z{PTcrO
zVX(g!cee}qMX=e==Aorh-4Mw};Q}J!-koy`MhrE2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs
z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ
zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U
zAV7cs0RjXF5V+z3U&~&*ooNhvy|~lZ&rWBq-O9A%Lf|{u7lLoRmzT97sEH-&b$zO^E7TciCgZ~JAeFbz183DZTD)+
zmCGXMlDxAAe+~}*o}3&62oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7
z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N
z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkL{
zY6*NjI}^M-Kb4sdg3XQl-}?SP3jh4WuRkhg=QBzD%QG`GK@e?LK0o^1T$=ac)k
Date: Tue, 17 Sep 2013 12:17:48 +0200
Subject: [PATCH 7/9] icreate install wizard
---
.../Install/CheckDatabaseConnection.php | 30 +-
web/install/bdd.php | 113 +
web/install/bootstrap.php | 27 +
web/install/connection.php | 67 +
web/install/fd33fd0-6fda040.ico | Bin 0 -> 3447 bytes
web/install/footer.php | 42 +
web/install/header.php | 59 +
web/install/index.php | 39 +
web/install/permission.php | 56 +
web/install/script.js | 1999 +++++
web/install/styles.css | 7534 +++++++++++++++++
11 files changed, 9962 insertions(+), 4 deletions(-)
create mode 100644 web/install/bdd.php
create mode 100644 web/install/bootstrap.php
create mode 100644 web/install/connection.php
create mode 100644 web/install/fd33fd0-6fda040.ico
create mode 100644 web/install/footer.php
create mode 100644 web/install/header.php
create mode 100644 web/install/index.php
create mode 100644 web/install/permission.php
create mode 100644 web/install/script.js
create mode 100644 web/install/styles.css
diff --git a/core/lib/Thelia/Install/CheckDatabaseConnection.php b/core/lib/Thelia/Install/CheckDatabaseConnection.php
index 50c117d22..a2a18853e 100644
--- a/core/lib/Thelia/Install/CheckDatabaseConnection.php
+++ b/core/lib/Thelia/Install/CheckDatabaseConnection.php
@@ -62,6 +62,11 @@ class CheckDatabaseConnection extends BaseInstall
/** @var int Database port information */
protected $port = null;
+ /**
+ * @var \PDO instance
+ */
+ protected $connection = null;
+
/**
* Constructor
*
@@ -90,11 +95,28 @@ class CheckDatabaseConnection extends BaseInstall
*/
public function exec()
{
- $link = mysql_connect($this->host . ':' . $this->port, $this->user, $this->password);
- if (!$link) {
- throw new InstallException('Can\'t connect to the given credentials');
+
+ $dsn = "mysql:host=%s";
+
+ try {
+ $this->connection = new \PDO(
+ sprintf($dsn, $this->host),
+ $this->user,
+ $this->password
+ );
+ } catch (\PDOException $e) {
+
+ $this->validationMessages = 'Wrong connection information';
+
+ $this->isValid = false;
}
- mysql_close($link);
+
+ return $this->isValid;
+ }
+
+ public function getConnection()
+ {
+ return $this->connection;
}
}
diff --git a/web/install/bdd.php b/web/install/bdd.php
new file mode 100644
index 000000000..059a25eb8
--- /dev/null
+++ b/web/install/bdd.php
@@ -0,0 +1,113 @@
+. */
+/* */
+/*************************************************************************************/
+
+$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/connection.php b/web/install/connection.php
new file mode 100644
index 000000000..2d68c5cac
--- /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/fd33fd0-6fda040.ico b/web/install/fd33fd0-6fda040.ico
new file mode 100644
index 0000000000000000000000000000000000000000..24c27fefda083bbb0c2e15292e4bfdb6ce1dfbd4
GIT binary patch
literal 3447
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
Z*dOOSw(A)Zay0+|002ovPDHLkV1k~6kmmpZ
literal 0
HcmV?d00001
diff --git a/web/install/footer.php b/web/install/footer.php
new file mode 100644
index 000000000..2dbe991d4
--- /dev/null
+++ b/web/install/footer.php
@@ -0,0 +1,42 @@
+. */
+/* */
+/*************************************************************************************/
+?>
+
+
+
+
+
+
+
+
+
+