finish update process

This commit is contained in:
Manuel Raynaud
2014-01-07 16:28:02 +01:00
parent 6a9fd30a53
commit 97a9ff26be
5 changed files with 155 additions and 5 deletions

View File

@@ -1127,6 +1127,10 @@
<default key="_controller">Thelia\Controller\Admin\UpdateController::indexAction</default>
</route>
<route id="update.process" path="/admin/configuration/update/process">
<default key="_controller">Thelia\Controller\Admin\UpdateController::updateAction</default>
</route>
<!-- The default route, to display a template -->
<route id="admin.processTemplate" path="/admin/{template}">

View File

@@ -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);
}
}

View File

@@ -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"}
<div id="wrapper" class="container">
<div class="clearfix">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/update'}">{intl l="Update Process"}</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-12">
<div class="alert alert-success">
<p>{intl l="Thelia Updated successfully"}</p>
<p>{intl l="List of versions updated successfully : "}</p>
<ul>
{foreach $updated_versions as $version}
<li>{$version}</li>
{/foreach}
</ul>
</div>
</div>
</div>
</div>
{/block}

View File

@@ -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"}
<div id="wrapper" class="container">
<div class="clearfix">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/update'}">{intl l="Update Process"}</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-12">
<div class="alert alert-info">
<p>{intl l="Your current version is <b>%current_version</b> and you will updated to <b>%latest_version</b> version." current_version={$current_version} latest_version={$latest_version}}
<a href="{url path="/admin/configuration/update/process"}">{intl l="Start updating"}</a></p>
</div>
</div>
</div>
</div>
{/block}

View File

@@ -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"}
<div id="wrapper" class="container">
<div class="clearfix">
<ul class="breadcrumb">
<li><a href="{url path='/admin/home'}">{intl l="Home"}</a></li>
<li><a href="{url path='/admin/configuration'}">{intl l="Configuration"}</a></li>
<li><a href="{url path='/admin/configuration/update'}">{intl l="Update Process"}</a></li>
</ul>
</div>
<div class="row">
<div class="col-md-12">
<div class="alert alert-error">
<p>{intl l="Thelia update failed"}</p>
<p>{intl l="error message : "} <b>{$error_message}</b></p>
<p>{intl l="Please contact your technical support or see error logs"}</p>
</div>
</div>
</div>
</div>
{/block}