finish update process
This commit is contained in:
@@ -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}">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user