refactor update process. Now only available with command line
This commit is contained in:
84
core/lib/Thelia/Command/UpdateCommand.php
Normal file
84
core/lib/Thelia/Command/UpdateCommand.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
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 <mraynaud@openstudio.fr>
|
||||
*/
|
||||
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',
|
||||
'<info>Please wait ...</info>'
|
||||
));
|
||||
|
||||
$update = new Update();
|
||||
|
||||
try {
|
||||
$updatedVersions = $update->process();
|
||||
|
||||
$output->writeln(array(
|
||||
'',
|
||||
'<info>Your database is updated successfully !</info>',
|
||||
''
|
||||
));
|
||||
} catch(PropelException $e) {
|
||||
$errorMsg = $e->getMessage();
|
||||
|
||||
$output->writeln(array(
|
||||
'',
|
||||
sprintf('<error>Error during update process with message : %s</error>', $e->getMessage()),
|
||||
''
|
||||
));
|
||||
} catch (UpToDateException $e) {
|
||||
$output->writeln(array(
|
||||
'',
|
||||
sprintf('<error>%s</error>', $e->getMessage()),
|
||||
''
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
<command class="Thelia\Command\ReloadDatabaseCommand"/>
|
||||
<command class="Thelia\Command\GenerateResources"/>
|
||||
<command class="Thelia\Command\AdminUpdatePasswordCommand"/>
|
||||
<command class="Thelia\Command\UpdateCommand"/>
|
||||
</commands>
|
||||
|
||||
</config>
|
||||
|
||||
@@ -1122,15 +1122,6 @@
|
||||
<default key="_controller">Thelia\Controller\Admin\TranslationsController::updateAction</default>
|
||||
</route>
|
||||
|
||||
<!-- update routing -->
|
||||
<route id="update.index" path="/admin/configuration/update">
|
||||
<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}">
|
||||
|
||||
35
core/lib/Thelia/Install/Exception/UpToDateException.php
Normal file
35
core/lib/Thelia/Install/Exception/UpToDateException.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Install\Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Class UpToDateException
|
||||
* @package Thelia\Install\Exception
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class UpToDateException extends InstallException
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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 <mraynaud@openstudio.fr>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"}
|
||||
<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">
|
||||
{intl l="Your Thelia is already up-to-date"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/block}
|
||||
@@ -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"}
|
||||
<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}
|
||||
@@ -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"}
|
||||
<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}
|
||||
@@ -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"}
|
||||
<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}
|
||||
Reference in New Issue
Block a user