Commit 302d0546 authored by Baudouin Feildel's avatar Baudouin Feildel
Browse files

Add error & warning in ImportLogger

parent 0cbecd3e
......@@ -78,4 +78,36 @@ interface IImportLogger
* @return int
*/
public function getUpdatedGroupsCount(): int;
/**
* Get the number of reported errors
* @return int
*/
public function getErrorsCount(): int;
/**
* Get the number of reported warnings
* @return int
*/
public function getWarningsCount(): int;
/**
* Get the reported errors
* Each element of the array contains the following elements:
* - line_number an integer
* - line an array
* - message a string
* @return array
*/
public function getErrors(): array;
/**
* Get the reported warnings
* Each element of the array contains the following elements:
* - line_number an integer
* - line an array
* - message a string
* @return array
*/
public function getWarnings(): array;
}
\ No newline at end of file
......@@ -19,6 +19,10 @@ class ImportLogger implements IImportLogger
private $updatedGroups = [];
private $errors = [];
private $warnings = [];
private $logger;
public function __construct(LoggerInterface $logger) {
......@@ -137,6 +141,22 @@ class ImportLogger implements IImportLogger
}
}
public function reportError(int $line_number, array $line, string $message) {
$this->errors[] = [
'line_number' => $line_number,
'line' => $line,
'message' => $message,
];
}
public function reportWarning(int $line_number, array $line, string $message) {
$this->warnings[] = [
'line_number' => $line_number,
'line' => $line,
'message' => $message,
];
}
/**
* Get the list of created users during the import
* @return User[]
......@@ -224,4 +244,20 @@ class ImportLogger implements IImportLogger
public function getUpdatedGroupsCount(): int {
return count($this->updatedGroups);
}
public function getErrorsCount(): int {
return count($this->errors);
}
public function getWarningsCount(): int {
return count($this->warnings);
}
public function getErrors(): array {
return $this->errors;
}
public function getWarnings(): array {
return $this->warnings;
}
}
\ No newline at end of file
......@@ -17,6 +17,8 @@
<h2>Vue d'ensemble</h2>
<ul>
<li>Nombre d'erreurs : {{ importLogger.errorsCount }}</li>
<li>Nombre d'avertissements : {{ importLogger.warningsCount }}</li>
<li>Nombre d'utilisateurs créés&nbsp;: {{ importLogger.createdUsersCount }}</li>
<li>Nombre d'utilisateurs mis à jour&nbsp;: {{ importLogger.updatedUsersCount }}</li>
<li>Nombre de groupes créés&nbsp;: {{ importLogger.createdGroupsCount }}</li>
......@@ -25,6 +27,24 @@
<h2>Détails</h2>
<h3>Erreurs</h3>
<ul>
{% for e in importLogger.errors %}
<li>Ligne {{ e.line_number }}&nbsp;: {{ e.message }}</li>
{% else %}
<li><i>Aucune erreur</i></li>
{% endfor %}
</ul>
<h3>Avertissements</h3>
<ul>
{% for w in importLogger.warnings %}
<li>Ligne {{ w.line_number }}&nbsp;: {{ w.message }}</li>
{% else %}
<li><i>Aucun avertissement</i></li>
{% endfor %}
</ul>
<h3>Utilisateurs</h3>
<h4>Créés</h4>
<ul>
......
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