diff --git a/core/lib/Thelia/Command/UpdateCommand.php b/core/lib/Thelia/Command/UpdateCommand.php new file mode 100644 index 000000000..745a1b219 --- /dev/null +++ b/core/lib/Thelia/Command/UpdateCommand.php @@ -0,0 +1,84 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Command; +use Propel\Runtime\Exception\PropelException; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Thelia\Install\Exception\UpToDateException; +use Thelia\Install\Update; +use Thelia\Model\ConfigQuery; + + +/** + * Class UpdateCommand + * @package Thelia\Command + * @author Manuel Raynaud + */ +class UpdateCommand extends ContainerAwareCommand +{ + + protected function configure() + { + $this + ->setName('thelia:update') + ->setDescription('update your database. Before that you have to update all your files') + + ; + } + + public function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln(array( + '', + 'Welcome to the update database process', + 'Please wait ...' + )); + + $update = new Update(); + + try { + $updatedVersions = $update->process(); + + $output->writeln(array( + '', + 'Your database is updated successfully !', + '' + )); + } catch(PropelException $e) { + $errorMsg = $e->getMessage(); + + $output->writeln(array( + '', + sprintf('Error during update process with message : %s', $e->getMessage()), + '' + )); + } catch (UpToDateException $e) { + $output->writeln(array( + '', + sprintf('%s', $e->getMessage()), + '' + )); + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Config/Resources/command.xml b/core/lib/Thelia/Config/Resources/command.xml index 308a1c50c..e9b90d8b9 100644 --- a/core/lib/Thelia/Config/Resources/command.xml +++ b/core/lib/Thelia/Config/Resources/command.xml @@ -16,6 +16,7 @@ + diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index 17543c905..c0e54528a 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1122,15 +1122,6 @@ Thelia\Controller\Admin\TranslationsController::updateAction - - - Thelia\Controller\Admin\UpdateController::indexAction - - - - Thelia\Controller\Admin\UpdateController::updateAction - - diff --git a/core/lib/Thelia/Install/Exception/UpToDateException.php b/core/lib/Thelia/Install/Exception/UpToDateException.php new file mode 100644 index 000000000..45db7eb5a --- /dev/null +++ b/core/lib/Thelia/Install/Exception/UpToDateException.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Install\Exception; + + +/** + * Class UpToDateException + * @package Thelia\Install\Exception + * @author Manuel Raynaud + */ +class UpToDateException extends InstallException +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Controller/Admin/UpdateController.php b/core/lib/Thelia/Install/Update.php similarity index 81% rename from core/lib/Thelia/Controller/Admin/UpdateController.php rename to core/lib/Thelia/Install/Update.php index c22ed779a..373e46fa7 100644 --- a/core/lib/Thelia/Controller/Admin/UpdateController.php +++ b/core/lib/Thelia/Install/Update.php @@ -21,28 +21,21 @@ /* */ /*************************************************************************************/ -namespace Thelia\Controller\Admin; - +namespace Thelia\Install; use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Propel; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Thelia\Controller\Admin\BaseAdminController; -use Thelia\Core\Security\AccessManager; -use Thelia\Core\Security\Resource\AdminResources; -use Thelia\Install\Database; +use Thelia\Install\Exception\UpToDateException; use Thelia\Log\Tlog; use Thelia\Model\ConfigQuery; -use Thelia\Model\Map\ProductTableMap; /** - * Class UpdateController - * @package Thelia\Controller\Update + * Class Update + * @package Thelia\Install * @author Manuel Raynaud */ -class UpdateController extends BaseAdminController +class Update { - protected static $version = array( '0' => '2.0.0-beta1', '1' => '2.0.0-beta2', @@ -55,7 +48,7 @@ class UpdateController extends BaseAdminController return $lastEntry == $version; } - +/* public function indexAction() { // Check current user authorization @@ -73,14 +66,10 @@ class UpdateController extends BaseAdminController 'latest_version' => end(self::$version) )); } - } + }*/ - public function updateAction() + public function process() { - // Check current user authorization - if (null !== $response = $this->checkAuth(AdminResources::UPDATE, array(), AccessManager::UPDATE)) { - return $response; - } $logger = Tlog::getInstance(); $logger->setLevel(Tlog::DEBUG); @@ -92,7 +81,7 @@ class UpdateController extends BaseAdminController $logger->debug("start update process"); if(true === $this->isLatestVersion($currentVersion)) { $logger->debug("You already have the latest version. No update available"); - return $this->render('update-notneeded'); + throw new UpToDateException('You already have the latest version. No update available'); } $index = array_search($currentVersion, self::$version); @@ -109,21 +98,13 @@ class UpdateController extends BaseAdminController $logger->debug('update successfully'); } catch(PropelException $e) { $con->rollBack(); - $success = false; - $errorMsg = $e->getMessage(); $logger->error(sprintf('error during update process with message : %s', $e->getMessage())); + throw $e; } $logger->debug('end of update processing'); - if ($success) { - return $this->render('update-success', array( - "updated_versions" => $updatedVersions - )); - } else { - return $this->render('update-fail', array( - "error_message" => $errorMsg - )); - } + + return $updatedVersions; } protected function updateToVersion($version, Database $database,Tlog $logger) @@ -136,4 +117,4 @@ class UpdateController extends BaseAdminController ConfigQuery::write('thelia_version', $version); } -} \ No newline at end of file +} \ No newline at end of file diff --git a/templates/backOffice/default/update-notneeded.html b/templates/backOffice/default/update-notneeded.html deleted file mode 100644 index 643b24f9a..000000000 --- a/templates/backOffice/default/update-notneeded.html +++ /dev/null @@ -1,26 +0,0 @@ -{extends file="admin-layout.tpl"} - -{block name="page-title"}{intl l='Update'}{/block} - -{block name="check-resource"}admin.configuration.update{/block} -{block name="check-access"}view{/block} - -{block name="main-content"} -
- -
-
-
- {intl l="Your Thelia is already up-to-date"} -
-
-
-
- -{/block} \ No newline at end of file diff --git a/templates/backOffice/default/update-success.html b/templates/backOffice/default/update-success.html deleted file mode 100644 index b904a5e81..000000000 --- a/templates/backOffice/default/update-success.html +++ /dev/null @@ -1,32 +0,0 @@ -{extends file="admin-layout.tpl"} - -{block name="page-title"}{intl l='Update'}{/block} - -{block name="check-resource"}admin.configuration.update{/block} -{block name="check-access"}update{/block} - -{block name="main-content"} -
- -
-
-
-

{intl l="Thelia Updated successfully"}

-

{intl l="List of versions updated successfully : "}

-
    - {foreach $updated_versions as $version} -
  • {$version}
  • - {/foreach} -
-
-
-
-
- -{/block} \ No newline at end of file diff --git a/templates/backOffice/default/update.html b/templates/backOffice/default/update.html deleted file mode 100644 index 99595112c..000000000 --- a/templates/backOffice/default/update.html +++ /dev/null @@ -1,28 +0,0 @@ -{extends file="admin-layout.tpl"} - -{block name="page-title"}{intl l='Update'}{/block} - -{block name="check-resource"}admin.configuration.update{/block} -{block name="check-access"}view{/block} - -{block name="main-content"} -
- -
-
-
-

{intl l="Your current version is %current_version and you will updated to %latest_version version." current_version={$current_version} latest_version={$latest_version}} - {intl l="Start updating"}

- -
-
-
-
- -{/block} \ No newline at end of file diff --git a/templates/backOffice/default/updated-fail.html b/templates/backOffice/default/updated-fail.html deleted file mode 100644 index 330fabb43..000000000 --- a/templates/backOffice/default/updated-fail.html +++ /dev/null @@ -1,29 +0,0 @@ -{extends file="admin-layout.tpl"} - -{block name="page-title"}{intl l='Update'}{/block} - -{block name="check-resource"}admin.configuration.update{/block} -{block name="check-access"}update{/block} - -{block name="main-content"} -
- -
-
-
-

{intl l="Thelia update failed"}

-

{intl l="error message : "} {$error_message}

- -

{intl l="Please contact your technical support or see error logs"}

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