Commit f3001e10 authored by dj3c1t's avatar dj3c1t

/import/previous_version via cli or http

parent b92fb8d9
......@@ -9,15 +9,41 @@ use Symfony\Component\HttpFoundation\Response;
class ImportController extends Controller {
public function previousVersionAction(Request $request) {
$message = "";
$importPreviousVersion = $this->get('sourceml.import_previous_version');
if(php_sapi_name() !== 'cli') {
return $this->render(
'Dj3c1tSourceMLBundle:Import:index.html.twig'
);
}
try {
$importPreviousVersion->init();
$importPreviousVersion->import();
$importPreviousVersion->log("import done");
}
catch(\Exception $e) {
$importPreviousVersion->log(" ERROR ".$e->getMessage());
}
return new Response();
}
public function doImportAction(Request $request) {
$importPreviousVersion = $this->get('sourceml.import_previous_version');
try {
$this->get('sourceml.import_previous_version')->import();
$message = "[".date("Y-m-d H:i:s")."] import done";
$importPreviousVersion->init();
$importPreviousVersion->import();
$importPreviousVersion->log("import done");
$this->get('session')->getFlashBag()->add('success', "L'upgrade s'est terminé avec succès");
}
catch(\Exception $e) {
$message = "[".date("Y-m-d H:i:s")."] import ERROR ".$e->getMessage();
$importPreviousVersion->log(" ERROR ".$e->getMessage());
$this->get('session')->getFlashBag()->add('error', "L'upgrade s'est terminé avec des erreurs");
}
return new Response($message."\n");
return $this->render(
'Dj3c1tSourceMLBundle:Import:logs.html.twig',
array(
"logs" => $importPreviousVersion->getLogs(),
)
);
}
}
......@@ -6,6 +6,10 @@ sourceml_import_previous_version:
path: /import/previous_version
defaults: { _controller: Dj3c1tSourceMLBundle:Import:previousVersion }
sourceml_do_import_previous_version:
path: /doimport/previous_version
defaults: { _controller: Dj3c1tSourceMLBundle:Import:doImport }
# -------------------------------------------------------------------
# Status
......
{% extends '::base.html.twig' %}
{% block header %}
<h1>Upgrade</h1>
{% endblock %}
{% block main %}
{{ parent() }}
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<h3>Upgrade d'une version 1 de SourceML vers une version 2</h3>
<a href="{{ path('sourceml_do_import_previous_version') }}" class="btn btn-primary">Lancer l'upgrade</a>
</div>
</div>
{% endblock %}
{% extends '::base.html.twig' %}
{% block header %}
<h1>Upgrade</h1>
{% endblock %}
{% block main %}
{{ parent() }}
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<h3>Upgrade d'une version 1 de SourceML vers une version 2</h3>
<p>Terminé</p>
{{ dump(logs) }}
</div>
</div>
{% endblock %}
{% extends '::base.html.twig' %}
{% block header %}
<h1>Upgrade</h1>
{% endblock %}
{% block main %}
{{ parent() }}
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<h3>Upgrade d'une version 1 de SourceML vers une version 2</h3>
{{ dump(logs) }}
<a href="{{ app.request.baseUrl }}" class="btn btn-primary">Aller sur le site</a>
</div>
</div>
{% endblock %}
......@@ -16,10 +16,10 @@ class ImportPreviousVersion {
protected $mw_env;
protected $mw_data;
protected $mw_sgbd;
protected $logs;
public function __construct(Container $container) {
$this->container = $container;
$this->init();
}
// ----------------------------------------------------------------------
......@@ -229,11 +229,27 @@ class ImportPreviousVersion {
//
public function log($content) {
echo "[".date("Y-m-d H:i:s")."] ".$content."\n";
$entry = $this->formatLog($content);
$this->logs[] = $entry;
if(php_sapi_name() == 'cli') {
$this->printLog($content);
}
}
public function printLog($content) {
echo $this->formatLog($content)."\n";
}
public function error($content) {
throw new \Exception("[".date("Y-m-d H:i:s")."] ERROR ".$content."\n");
throw new \Exception($this->formatLog(" ERROR ".$content));
}
public function formatLog($content) {
return "[".date("Y-m-d H:i:s")."] ".$content;
}
public function getLogs() {
return $this->logs;
}
public function notifyNewPassword(User $user, $password) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment