From 7d0d1a90a1810c4aeb0010209f764275d0cbac3d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 15:10:29 +0200 Subject: [PATCH 1/8] create action install file --- core/lib/Thelia/Action/Install.php | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 core/lib/Thelia/Action/Install.php diff --git a/core/lib/Thelia/Action/Install.php b/core/lib/Thelia/Action/Install.php new file mode 100644 index 000000000..4c5d31df4 --- /dev/null +++ b/core/lib/Thelia/Action/Install.php @@ -0,0 +1,61 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Action; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + + +/** + * Class Install + * @package Thelia\Action + * @author Manuel Raynaud + */ +class Install extends BaseAction implements EventSubscriberInterface { + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + array( + + ); + } +} \ No newline at end of file From 4e1cc9e810a624c3ca7651e67197f9d6df135d45 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 16:54:18 +0200 Subject: [PATCH 2/8] start refacroting install process --- .../Install.php => Install/BaseInstall.php} | 43 ++++------ core/lib/Thelia/Install/CheckPermission.php | 78 +++++++++++++++++++ .../Exception/AlreadyInstallException.php | 35 +++++++++ .../Install/Exception/InstallException.php | 32 ++++++++ 4 files changed, 159 insertions(+), 29 deletions(-) rename core/lib/Thelia/{Action/Install.php => Install/BaseInstall.php} (66%) create mode 100644 core/lib/Thelia/Install/CheckPermission.php create mode 100644 core/lib/Thelia/Install/Exception/AlreadyInstallException.php create mode 100644 core/lib/Thelia/Install/Exception/InstallException.php diff --git a/core/lib/Thelia/Action/Install.php b/core/lib/Thelia/Install/BaseInstall.php similarity index 66% rename from core/lib/Thelia/Action/Install.php rename to core/lib/Thelia/Install/BaseInstall.php index 4c5d31df4..58c510267 100644 --- a/core/lib/Thelia/Action/Install.php +++ b/core/lib/Thelia/Install/BaseInstall.php @@ -20,42 +20,27 @@ /* along with this program. If not, see . */ /* */ /*************************************************************************************/ - -namespace Thelia\Action; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - +namespace Thelia\Install; +use Thelia\Install\Exception\AlreadyInstallException; /** - * Class Install - * @package Thelia\Action + * Class BaseInstall * @author Manuel Raynaud */ -class Install extends BaseAction implements EventSubscriberInterface { - +abstract class BaseInstall +{ /** - * Returns an array of event names this subscriber wants to listen to. - * - * The array keys are event names and the value can be: - * - * * The method name to call (priority defaults to 0) - * * An array composed of the method name to call and the priority - * * An array of arrays composed of the method names to call and respective - * priorities, or 0 if unset - * - * For instance: - * - * * array('eventName' => 'methodName') - * * array('eventName' => array('methodName', $priority)) - * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) - * - * @return array The event names to listen to - * - * @api + * Verify if an installation already exists */ - public static function getSubscribedEvents() + public function __construct($verifyInstall = true) { - array( + if (file_exists(THELIA_ROOT . '/local/config/database.yml') && $verifyInstall) { + throw new AlreadyInstallException("Thelia is already installed"); + } - ); + + $this->exec(); } + + abstract public function exec(); } \ No newline at end of file diff --git a/core/lib/Thelia/Install/CheckPermission.php b/core/lib/Thelia/Install/CheckPermission.php new file mode 100644 index 000000000..db73330cf --- /dev/null +++ b/core/lib/Thelia/Install/CheckPermission.php @@ -0,0 +1,78 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install; + + +/** + * Class CheckPermission + * @package Thelia\Install + * @author Manuel Raynaud + */ +class CheckPermission extends BaseInstall +{ + const CONF = "const"; + const LOG = "log"; + const CACHE = "cache"; + + private $directories = array(); + private $validation = array(); + private $valid = true; + + public function __construct($verifyInstall = true) + { + + + $this->directories = array( + self::CONF => THELIA_ROOT . "local/config", + self::LOG => THELIA_ROOT . "log", + self::CACHE => THELIA_ROOT . "cache" + ); + + $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 + ) + ); + parent::__construct($verifyInstall); + } + + public function exec() + { + foreach ($this->directories as $key => $directory) { + if(is_writable($directory) === false) { + $this->valid = false; + $this->validation[$key]["status"] = false; + } + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/Exception/AlreadyInstallException.php b/core/lib/Thelia/Install/Exception/AlreadyInstallException.php new file mode 100644 index 000000000..1409c7cdd --- /dev/null +++ b/core/lib/Thelia/Install/Exception/AlreadyInstallException.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install\Exception; + + +/** + * Class AlreadyInstallException + * @package Thelia\Install\Exception + * @author Manuel Raynaud + */ +class AlreadyInstallException extends InstallException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Install/Exception/InstallException.php b/core/lib/Thelia/Install/Exception/InstallException.php new file mode 100644 index 000000000..6924bcfe5 --- /dev/null +++ b/core/lib/Thelia/Install/Exception/InstallException.php @@ -0,0 +1,32 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Install\Exception; + +/** + * Class InstallException + * @author Manuel Raynaud + */ +class InstallException extends \RuntimeException +{ + +} \ No newline at end of file From ac5c6b9f5aa7e553758b1785e7ff7db2c00c79eb Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 16:59:10 +0200 Subject: [PATCH 3/8] create install router --- core/lib/Thelia/Config/Resources/routing.xml | 11 ++++++ .../Config/Resources/routing/install.xml | 12 +++++++ .../Controller/Install/InstallController.php | 35 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 core/lib/Thelia/Config/Resources/routing/install.xml create mode 100644 core/lib/Thelia/Controller/Install/InstallController.php diff --git a/core/lib/Thelia/Config/Resources/routing.xml b/core/lib/Thelia/Config/Resources/routing.xml index 9c61c55a8..5200aefc1 100755 --- a/core/lib/Thelia/Config/Resources/routing.xml +++ b/core/lib/Thelia/Config/Resources/routing.xml @@ -56,6 +56,17 @@ + + + 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 new file mode 100644 index 000000000..8e0357fe0 --- /dev/null +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -0,0 +1,12 @@ + + + + + + Thelia\Controller\Front\DefaultController::noAction + index + + + diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php new file mode 100644 index 000000000..1906d25ae --- /dev/null +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Install; +use Thelia\Controller\BaseController; + + +/** + * Class InstallController + * @package Thelia\Controller\Install + * @author Manuel Raynaud + */ +class InstallController extends BaseController { + +} \ No newline at end of file From 39d17fe30dea72d5dd1ffe51a4ecccf83fa2e9eb Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 17:12:30 +0200 Subject: [PATCH 4/8] create BaseAdminController --- core/lib/Thelia/Config/Resources/routing/install.xml | 3 +-- core/lib/Thelia/Controller/Install/InstallController.php | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml index 8e0357fe0..fb5c25bcc 100644 --- a/core/lib/Thelia/Config/Resources/routing/install.xml +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -5,8 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - Thelia\Controller\Front\DefaultController::noAction - index + Thelia\Controller\Install\InstallController::index diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 1906d25ae..1d20bc9d6 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -22,14 +22,13 @@ /*************************************************************************************/ namespace Thelia\Controller\Install; -use Thelia\Controller\BaseController; - +use Thelia\Install\BaseInstall; /** * Class InstallController * @package Thelia\Controller\Install * @author Manuel Raynaud */ -class InstallController extends BaseController { +class InstallController extends BaseInstallController { } \ No newline at end of file From 347d3050f3eeff4d1af5594ca90fa12e0ad60a14 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 17:13:01 +0200 Subject: [PATCH 5/8] add missinf files --- .../Install/BaseInstallController.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/lib/Thelia/Controller/Install/BaseInstallController.php diff --git a/core/lib/Thelia/Controller/Install/BaseInstallController.php b/core/lib/Thelia/Controller/Install/BaseInstallController.php new file mode 100644 index 000000000..fb04f85e8 --- /dev/null +++ b/core/lib/Thelia/Controller/Install/BaseInstallController.php @@ -0,0 +1,60 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Install; +use Symfony\Component\HttpFoundation\Response; +use Thelia\Controller\BaseController; + + +/** + * Class BaseInstallController + * @package Thelia\Controller\Install + * @author Manuel Raynaud + */ +class BaseInstallController extends BaseController +{ + /** + * @return a ParserInterface instance parser + */ + protected function getParser() + { + $parser = $this->container->get("thelia.parser"); + + // Define the template thant shoud be used + $parser->setTemplate("install/default"); + + return $parser; + } + + public function render($templateName, $args) + { + return new Response($this->renderRaw($templateName, $args)); + } + + public function renderRaw($templateName, $args) + { + $data = $this->getParser()->render($templateName, $args); + + return $data; + } +} \ No newline at end of file From 384b0cd355a685a0b8bfab242e4631a6691a088d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 17:27:11 +0200 Subject: [PATCH 6/8] start to create install template --- .../Install/BaseInstallController.php | 6 ++--- .../Controller/Install/InstallController.php | 4 ++++ templates/install/includes/footer.inc.html | 17 +++++++++++++ templates/install/includes/header.inc.html | 24 +++++++++++++++++++ templates/install/index.html | 0 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 templates/install/includes/footer.inc.html create mode 100644 templates/install/includes/header.inc.html create mode 100644 templates/install/index.html diff --git a/core/lib/Thelia/Controller/Install/BaseInstallController.php b/core/lib/Thelia/Controller/Install/BaseInstallController.php index fb04f85e8..a5cbbd506 100644 --- a/core/lib/Thelia/Controller/Install/BaseInstallController.php +++ b/core/lib/Thelia/Controller/Install/BaseInstallController.php @@ -41,17 +41,17 @@ class BaseInstallController extends BaseController $parser = $this->container->get("thelia.parser"); // Define the template thant shoud be used - $parser->setTemplate("install/default"); + $parser->setTemplate("install"); return $parser; } - public function render($templateName, $args) + public function render($templateName, $args = array()) { return new Response($this->renderRaw($templateName, $args)); } - public function renderRaw($templateName, $args) + public function renderRaw($templateName, $args = array()) { $data = $this->getParser()->render($templateName, $args); diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 1d20bc9d6..0c7770e4b 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -31,4 +31,8 @@ use Thelia\Install\BaseInstall; */ class InstallController extends BaseInstallController { + public function index() + { + $this->render("index.html"); + } } \ No newline at end of file diff --git a/templates/install/includes/footer.inc.html b/templates/install/includes/footer.inc.html new file mode 100644 index 000000000..c20b84adc --- /dev/null +++ b/templates/install/includes/footer.inc.html @@ -0,0 +1,17 @@ + +
+ + + + \ No newline at end of file diff --git a/templates/install/includes/header.inc.html b/templates/install/includes/header.inc.html new file mode 100644 index 000000000..39d7c42da --- /dev/null +++ b/templates/install/includes/header.inc.html @@ -0,0 +1,24 @@ + + + + {intl l='Thelia Back Office'}{if ! empty($page_title)} - {$page_title}{/if} + + {images file='../../admin/default/assets/img/favicon.ico'}{/images} + + + + {stylesheets file='../../admin/default/assets/bootstrap/css/bootstrap.css' filters='cssembed'} + + {/stylesheets} + + {stylesheets file='../../admin/default/assets/bootstrap/css/bootstrap-responsive.css' filters='cssembed'} + + {/stylesheets} + + + {stylesheets file='../../admin/default/assets/css/*' filters='less,cssembed'} + + {/stylesheets} + + + diff --git a/templates/install/index.html b/templates/install/index.html new file mode 100644 index 000000000..e69de29bb From 73508028b46c8967d915bff47d9786159e29c7a5 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 17:44:22 +0200 Subject: [PATCH 7/8] create layout for install template --- templates/install/includes/footer.inc.html | 17 -------- templates/install/includes/header.inc.html | 24 ----------- templates/install/index.html | 4 ++ templates/install/layout.html | 49 ++++++++++++++++++++++ 4 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 templates/install/includes/footer.inc.html delete mode 100644 templates/install/includes/header.inc.html create mode 100644 templates/install/layout.html diff --git a/templates/install/includes/footer.inc.html b/templates/install/includes/footer.inc.html deleted file mode 100644 index c20b84adc..000000000 --- a/templates/install/includes/footer.inc.html +++ /dev/null @@ -1,17 +0,0 @@ - -
- - - - \ No newline at end of file diff --git a/templates/install/includes/header.inc.html b/templates/install/includes/header.inc.html deleted file mode 100644 index 39d7c42da..000000000 --- a/templates/install/includes/header.inc.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - {intl l='Thelia Back Office'}{if ! empty($page_title)} - {$page_title}{/if} - - {images file='../../admin/default/assets/img/favicon.ico'}{/images} - - - - {stylesheets file='../../admin/default/assets/bootstrap/css/bootstrap.css' filters='cssembed'} - - {/stylesheets} - - {stylesheets file='../../admin/default/assets/bootstrap/css/bootstrap-responsive.css' filters='cssembed'} - - {/stylesheets} - - - {stylesheets file='../../admin/default/assets/css/*' filters='less,cssembed'} - - {/stylesheets} - - - diff --git a/templates/install/index.html b/templates/install/index.html index e69de29bb..888f8b943 100644 --- a/templates/install/index.html +++ b/templates/install/index.html @@ -0,0 +1,4 @@ +{extends file="layout.html"} +{block name="content"} + Hello World ! +{/block} \ No newline at end of file diff --git a/templates/install/layout.html b/templates/install/layout.html new file mode 100644 index 000000000..0a13586ad --- /dev/null +++ b/templates/install/layout.html @@ -0,0 +1,49 @@ + + + + {block name="title"}Thelia Install{/block} + + {images file='../admin/default/assets/img/favicon.ico'}{/images} + + + + {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap.css' filters='cssembed'} + + {/stylesheets} + + {stylesheets file='../admin/default/assets/bootstrap/css/bootstrap-responsive.css' filters='cssembed'} + + {/stylesheets} + + + {stylesheets file='../admin/default/assets/css/*' filters='less,cssembed'} + + {/stylesheets} + + + +
+
+
{intl l='Version %ver' ver="{$THELIA_VERSION}"}
+
+
+
+ {block name="content"}{/block} +
+ +
+ + + + \ No newline at end of file From 50e585044f6168d9918f7c38d582391244bdacc7 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 2 Sep 2013 19:56:34 +0200 Subject: [PATCH 8/8] initialize step 2 --- .../Config/Resources/routing/install.xml | 4 +++ core/lib/Thelia/Controller/BaseController.php | 2 +- .../Controller/Install/InstallController.php | 31 +++++++++++++++++++ templates/install/index.html | 10 +++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/core/lib/Thelia/Config/Resources/routing/install.xml b/core/lib/Thelia/Config/Resources/routing/install.xml index fb5c25bcc..d53763948 100644 --- a/core/lib/Thelia/Config/Resources/routing/install.xml +++ b/core/lib/Thelia/Config/Resources/routing/install.xml @@ -8,4 +8,8 @@ Thelia\Controller\Install\InstallController::index + + Thelia\Controller\Install\InstallController::checkPermission + + diff --git a/core/lib/Thelia/Controller/BaseController.php b/core/lib/Thelia/Controller/BaseController.php index c7c9f6f14..d4c8b5854 100755 --- a/core/lib/Thelia/Controller/BaseController.php +++ b/core/lib/Thelia/Controller/BaseController.php @@ -179,7 +179,7 @@ class BaseController extends ContainerAware */ public function redirect($url) { - Redirect::exec($url); + Redirect::exec(URL::absoluteUrl($url)); } /** diff --git a/core/lib/Thelia/Controller/Install/InstallController.php b/core/lib/Thelia/Controller/Install/InstallController.php index 0c7770e4b..209eea82b 100644 --- a/core/lib/Thelia/Controller/Install/InstallController.php +++ b/core/lib/Thelia/Controller/Install/InstallController.php @@ -23,6 +23,7 @@ namespace Thelia\Controller\Install; use Thelia\Install\BaseInstall; +use Thelia\Install\CheckPermission; /** * Class InstallController @@ -33,6 +34,36 @@ class InstallController extends BaseInstallController { public function index() { + $this->verifyStep(1); + + $this->getSession()->set("step", 1); + $this->render("index.html"); } + + public function checkPermission() + { + $this->verifyStep(2); + + $permission = new CheckPermission(); + } + + 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; + } + } } \ No newline at end of file diff --git a/templates/install/index.html b/templates/install/index.html index 888f8b943..a996cc241 100644 --- a/templates/install/index.html +++ b/templates/install/index.html @@ -1,4 +1,12 @@ {extends file="layout.html"} {block name="content"} - Hello World ! +

{intl l="Thelia installation wizard"}

+
+ + {intl l="Bienvenue au sein du programme d'installation de Thelia."}
+ {intl l="Nous allons vous guider tout au long de ce processus afin d'installer l'application sur votre système."}

+ +
+ +
{/block} \ No newline at end of file