Skip to content
Snippets Groups Projects
Commit 88548a92 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Prise en compte des microsecondes dans les dates de début/fin inscrites dans...

Prise en compte des microsecondes dans les dates de début/fin inscrites dans la table de logs et donc dans la durée d'exécution calculée (nécessite le type TIMESTAMP sous Oracle).
parent 39468e7c
No related branches found
No related tags found
No related merge requests found
Pipeline #35813 passed
......@@ -4,6 +4,7 @@ Changelog
7.2.0
-----
- Suppression de la dépendance avec unicaen/app, et avec laminas/laminas-dependency-plugin.
- Prise en compte des microsecondes dans les dates de début/fin inscrites dans la table de logs et donc dans la durée d'exécution calculée (nécessite le type TIMESTAMP sous Oracle).
- [FIX] Le générateur SQL de la destination était utilisé aussi pour interroger la source, désormais la source a le sien propre.
7.1.0
......
......
......@@ -82,8 +82,8 @@ create table IMPORT_LOG
name varchar2(128) not null,
success int(1) not null,
log clob not null,
started_on date not null,
ended_on date not null,
started_on TIMESTAMP not null,
ended_on TIMESTAMP not null,
import_hash varchar2(64)
);
create sequence IMPORT_LOG_ID_SEQ;
......
......
......@@ -2,6 +2,7 @@
namespace UnicaenDbImport\CodeGenerator\Helper;
use DateTime;
use Exception;
use UnicaenDbImport\CodeGenerator\Helper;
use UnicaenDbImport\Domain\ImportResult;
......@@ -82,8 +83,8 @@ EOT;
$log .= PHP_EOL . 'Previous : ' . $exception->getMessage();
}
}
$startDate = $result->getStartDate()->format("Y-m-d H:i:s");
$endDate = $result->getEndDate()->format("Y-m-d H:i:s");
$startDate = $this->generateSQLForDateTimeColumnValueInsert($result->getStartDate());
$endDate = $this->generateSQLForDateTimeColumnValueInsert($result->getEndDate());
try {
$hash = $result->getHash();
......@@ -98,11 +99,13 @@ EOT;
$success,
$hasProblems,
$this->platform->quoteStringLiteral($log),
$this->platform->quoteStringLiteral($startDate),
$this->platform->quoteStringLiteral($endDate),
$startDate,
$endDate,
$this->platform->quoteStringLiteral($hash)
);
return $sql;
}
abstract protected function generateSQLForDateTimeColumnValueInsert(DateTime $datetime): string;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace UnicaenDbImport\CodeGenerator\Oracle\Helper;
use DateTime;
use UnicaenDbImport\Platforms\OraclePlatform;
/**
......@@ -26,4 +27,8 @@ class LogTableHelper extends \UnicaenDbImport\CodeGenerator\Helper\LogTableHelpe
$this->platform = new OraclePlatform();
}
protected function generateSQLForDateTimeColumnValueInsert(DateTime $datetime): string
{
return sprintf("to_timestamp('%s', 'YYYY-MM-DD HH24:MI:SS.FF')", $datetime->format("Y-m-d H:i:s.u"));
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
namespace UnicaenDbImport\CodeGenerator\PostgreSQL\Helper;
use DateTime;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
/**
......@@ -26,4 +27,8 @@ class LogTableHelper extends \UnicaenDbImport\CodeGenerator\Helper\LogTableHelpe
$this->platform = new PostgreSqlPlatform();
}
protected function generateSQLForDateTimeColumnValueInsert(DateTime $datetime): string
{
return $this->platform->quoteStringLiteral($datetime->format("Y-m-d H:i:s.u"));
}
}
\ No newline at end of file
......@@ -189,7 +189,7 @@ abstract class AbstractImportLog
*/
public function getStartedOnToString(): string
{
return $this->startedOn->format('d/m/Y H:i:s');
return $this->startedOn->format('d/m/Y H:i:s.u');
}
/**
......@@ -215,7 +215,7 @@ abstract class AbstractImportLog
*/
public function getEndedOnToString(): string
{
return $this->endedOn->format('d/m/Y H:i:s');
return $this->endedOn->format('d/m/Y H:i:s.u');
}
/**
......@@ -228,20 +228,26 @@ abstract class AbstractImportLog
return $this;
}
/**
* Retourne la durée d'exécution en secondes, d'après les dates de début et de fin.
*/
public function getDurationInSeconds(): int
{
return (int) $this->endedOn->diff($this->startedOn)->format('s');
}
/**
* Retourne la durée d'exécution au format "H min s", d'après les dates de début et de fin.
*/
public function getDurationToString(): string
{
return $this->endedOn->diff($this->startedOn)->format('%Hh %Imin %Ss');
$diff = $this->endedOn->diff($this->startedOn);
if ($diff->days === 0) {
if ($diff->h === 0) {
if ($diff->i === 0) {
return sprintf("%0.3f s", $diff->s + $diff->f);
} else {
return sprintf("%s min %0.3f s", $diff->i, $diff->s + $diff->f);
}
} else {
return sprintf("%s min %0.3f s", $diff->h*60 + $diff->i, $diff->s + $diff->f);
}
} else {
return sprintf("%s h %s min %0.3f s", $diff->days*24 + $diff->h, $diff->i, $diff->s + $diff->f);
}
}
/**
......
......
......@@ -48,10 +48,10 @@ $synchroConsultable = $this->isAllowed(SynchroPrivilege::getResourceId(SynchroPr
<?php echo $this->translate("Log"); ?>
</th>
<th>
<?php echo $this->translate("Commencé le"); ?>
<?php echo $this->translate("Début"); ?>
</th>
<th>
<?php echo $this->translate("Terminé le"); ?>
<?php echo $this->translate("Fin"); ?>
</th>
<th>
<?php echo $this->translate("Durée"); ?>
......
......
......@@ -15,9 +15,9 @@
<dd class="col-md-9"><span class="fas <?php echo $importLog->isSuccess() ? 'fa-thumbs-up text-success' : 'fa-thumbs-down text-danger' ?>"></span></dd>
<dt class="col-md-3">Problème ?</dt>
<dd class="col-md-9"><span class="<?php echo $importLog->hasProblems() ? 'text-danger' : '' ?>"><?php echo $importLog->hasProblems() ? 'Oui' : '-' ?></span></dd>
<dt class="col-md-3">Commencé le</dt>
<dt class="col-md-3">Début</dt>
<dd class="col-md-9"><?php echo $importLog->getStartedOnToString() ; ?></dd>
<dt class="col-md-3">Terminé le</dt>
<dt class="col-md-3">Fin</dt>
<dd class="col-md-9"><?php echo $importLog->getEndedOnToString() ; ?></dd>
<dt class="col-md-3">Durée</dt>
<dd class="col-md-9"><?php echo $importLog->getDurationToString() ; ?></dd>
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment