From 97a9ff26bec439995df1c2f3790aa0605cdcb35d Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 7 Jan 2014 16:28:02 +0100 Subject: [PATCH] finish update process --- .../Thelia/Config/Resources/routing/admin.xml | 4 ++ .../Controller/Admin/UpdateController.php | 67 +++++++++++++++++-- .../backOffice/default/update-success.html | 32 +++++++++ templates/backOffice/default/update.html | 28 ++++++++ .../backOffice/default/updated-fail.html | 29 ++++++++ 5 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 templates/backOffice/default/update-success.html create mode 100644 templates/backOffice/default/update.html create mode 100644 templates/backOffice/default/updated-fail.html diff --git a/core/lib/Thelia/Config/Resources/routing/admin.xml b/core/lib/Thelia/Config/Resources/routing/admin.xml index f2b1c6f35..17543c905 100755 --- a/core/lib/Thelia/Config/Resources/routing/admin.xml +++ b/core/lib/Thelia/Config/Resources/routing/admin.xml @@ -1127,6 +1127,10 @@ Thelia\Controller\Admin\UpdateController::indexAction + + Thelia\Controller\Admin\UpdateController::updateAction + + diff --git a/core/lib/Thelia/Controller/Admin/UpdateController.php b/core/lib/Thelia/Controller/Admin/UpdateController.php index e1f408d1f..7bb58a2eb 100644 --- a/core/lib/Thelia/Controller/Admin/UpdateController.php +++ b/core/lib/Thelia/Controller/Admin/UpdateController.php @@ -22,11 +22,15 @@ /*************************************************************************************/ namespace Thelia\Controller\Admin; +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\Model\ConfigQuery; +use Thelia\Model\Map\ProductTableMap; /** @@ -46,7 +50,7 @@ class UpdateController extends BaseAdminController protected function isLatestVersion($version) { - $lastEntry = array_pop(self::$version); + $lastEntry = end(self::$version); return $lastEntry == $version; } @@ -54,8 +58,8 @@ class UpdateController extends BaseAdminController public function indexAction() { // Check current user authorization - if (null !== $this->checkAuth(AdminResources::UPDATE, array(), AccessManager::VIEW)) { - throw new NotFoundHttpException(); + if (null !== $response = $this->checkAuth(AdminResources::UPDATE, array(), AccessManager::VIEW)) { + return $response; } $currentVersion = ConfigQuery::read('thelia_version'); @@ -63,9 +67,62 @@ class UpdateController extends BaseAdminController if(true === $this->isLatestVersion($currentVersion)) { return $this->render('update-notneeded'); } else { - return $this->render('update-index', array( - 'current_version' => $currentVersion + return $this->render('update', array( + 'current_version' => $currentVersion, + 'latest_version' => end(self::$version) )); } } + + public function updateAction() + { + // Check current user authorization + if (null !== $response = $this->checkAuth(AdminResources::UPDATE, array(), AccessManager::UPDATE)) { + return $response; + } + + $success = true; + $updatedVersions = array(); + + $currentVersion = ConfigQuery::read('thelia_version'); + + if(true === $this->isLatestVersion($currentVersion)) { + return $this->render('update-notneeded'); + } + + $index = array_search($currentVersion, self::$version); + $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME); + $con->beginTransaction(); + $database = new Database($con->getWrappedConnection()); + try { + for ($i = ++$index; $i < count(self::$version); $i++) { + $this->updateToVersion(self::$version[$i], $database); + $updatedVersions[] = self::$version[$i]; + } + $con->commit(); + } catch(PropelException $e) { + $con->rollBack(); + $success = false; + $errorMsg = $e->getMessage(); + } + + if ($success) { + return $this->render('update-success', array( + "updated_versions" => $updatedVersions + )); + } else { + return $this->render('update-fail', array( + "error_message" => $errorMsg + )); + } + } + + protected function updateToVersion($version, Database $database) + { + if (file_exists(THELIA_ROOT . '/install/update/'.$version.'.sql')) { + $database->insertSql(null, array(THELIA_ROOT . '/install/update/'.$version.'.sql')); + } + + ConfigQuery::write('thelia_version', $version); + } } \ No newline at end of file diff --git a/templates/backOffice/default/update-success.html b/templates/backOffice/default/update-success.html new file mode 100644 index 000000000..b904a5e81 --- /dev/null +++ b/templates/backOffice/default/update-success.html @@ -0,0 +1,32 @@ +{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 new file mode 100644 index 000000000..99595112c --- /dev/null +++ b/templates/backOffice/default/update.html @@ -0,0 +1,28 @@ +{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 new file mode 100644 index 000000000..330fabb43 --- /dev/null +++ b/templates/backOffice/default/updated-fail.html @@ -0,0 +1,29 @@ +{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