Commit 21838518 authored by Sebastian Castro's avatar Sebastian Castro

Improve GoGoLog

parent c1b4a723
......@@ -102,4 +102,6 @@ db.Option.updateMany({}, { $unset: { displayOption: "" } })
db.Element.updateMany( { } , { $rename: { 'website': 'data.website', 'telephone':'data.telephone', 'commitment':'data.commitment', 'description':'data.description', 'descriptionMore':'data.descriptionMore', 'openHoursMoreInfos':'data.openHoursMoreInfos', 'urls':'data.urls', 'email':'data.email' } } )
db.Element.updateMany({ 'data.openhours_more_infos': null }, { $unset: { 'data.openhours_more_infos': "" } })
db.Element.find({ 'data.openhours_more_infos': null })
\ No newline at end of file
db.Element.find({ 'data.openhours_more_infos': null })
db.GoGoLog.updateMany( { } , { $rename: { 'type': 'level' } } )
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace Biopen\CoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Gedmo\Mapping\Annotation as Gedmo;
abstract class GoGoLogType
abstract class GoGoLogLevel
{
const Debug = "debug";
const Info = "info";
......@@ -16,6 +16,11 @@ abstract class GoGoLogType
/**
* @MongoDB\Document
*
* @MongoDB\InheritanceType("SINGLE_COLLECTION")
* @MongoDB\DiscriminatorField("type")
* @MongoDB\DiscriminatorMap({"standard"="GoGoLog", "import"="GoGoLogImport"})
* @MongoDB\DefaultDiscriminatorValue("standard")
*/
class GoGoLog
{
......@@ -32,7 +37,7 @@ class GoGoLog
* @MongoDB\Field(type="string")
* @MongoDB\Index
*/
private $type;
private $level;
/**
* @var string
......@@ -42,11 +47,11 @@ class GoGoLog
private $message;
/**
* @var string
* Other informations stored into the log
*
* @MongoDB\Field(type="string")
* @MongoDB\Field(type="hash")
*/
private $subcontent;
private $data = [];
/**
* @var bool
......@@ -63,10 +68,21 @@ class GoGoLog
*/
protected $createdAt;
public function __construct($type = null, $message = null)
public function __construct($level = null, $message = null, $data = [])
{
$this->type = $type;
$this->level = $level;
$this->message = $message;
$this->data = $data;
}
public function displayMessage()
{
return $this->getMessage();
}
public function getDataProp($key)
{
return array_key_exists($key, $this->data) ? $this->data[$key] : null;
}
/**
......@@ -124,68 +140,68 @@ class GoGoLog
}
/**
* Set type
* Set hidden
*
* @param string $type
* @param bool $hidden
* @return $this
*/
public function setType($type)
public function setHidden($hidden)
{
$this->type = $type;
$this->hidden = $hidden;
return $this;
}
/**
* Get type
* Get hidden
*
* @return string $type
* @return bool $hidden
*/
public function getType()
public function getHidden()
{
return $this->type;
return $this->hidden;
}
/**
* Set hidden
* Set level
*
* @param bool $hidden
* @param string $level
* @return $this
*/
public function setHidden($hidden)
public function setLevel($level)
{
$this->hidden = $hidden;
$this->level = $level;
return $this;
}
/**
* Get hidden
* Get level
*
* @return bool $hidden
* @return string $level
*/
public function getHidden()
public function getLevel()
{
return $this->hidden;
return $this->level;
}
/**
* Set subcontent
* Set data
*
* @param string $subcontent
* @param hash $data
* @return $this
*/
public function setSubcontent($subcontent)
public function setData($data)
{
$this->subcontent = $subcontent;
$this->data = $data;
return $this;
}
/**
* Get subcontent
* Get data
*
* @return string $subcontent
* @return hash $data
*/
public function getSubcontent()
public function getData()
{
return $this->subcontent;
return $this->data;
}
}
<?php
namespace Biopen\CoreBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* Special log for Import
*
* @MongoDB\Document
*/
class GoGoLogImport extends GoGoLog
{
public function displayMessage()
{
$result = "<strong>Total: " . $this->getDataProp('elementsCount') . "</strong> ";
if ($this->getDataProp('elementsCreatedCount') > 0) $result .= " - " . $this->getDataProp('elementsCreatedCount') . " élément.s importé.s";
if ($this->getDataProp('elementsUpdatedCount') > 0) $result .= " - " . $this->getDataProp('elementsUpdatedCount') . " élement.s mis à jour";
if ($this->getDataProp('elementsNothingToDoCount') > 0) $result .= " - " . $this->getDataProp('elementsNothingToDoCount') . " élement.s laissé.s tel.s quel.s (rien à mettre à jour)";
if ($this->getDataProp('elementsNeedModerationCount') > 0) $result .= " - " . $this->getDataProp('elementsNeedModerationCount') . " élement.s incomplets (geoloc ou catégories)";
if ($this->getDataProp('elementsDeletedCount') > 0) $result .= " - " . $this->getDataProp('elementsDeletedCount') . " élement.s supprimé.s";
if ($this->getDataProp('elementsErrorsCount') > 0) $result .= " - " . $this->getDataProp('elementsErrorsCount') . " erreur.s pendant l'import";
return $result;
}
}
......@@ -8,12 +8,13 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Biopen\CoreBundle\Document\AbstractFile;
abstract class ImportState
{
const Failed = "failed";
{
const Started = "started";
const Downloading = "downloading";
const InProgress = "in_progress";
const Completed = "completed";
const Completed = "completed";
const Errors = "errors";
const Failed = "failed";
}
/**
......@@ -75,15 +76,19 @@ class Import extends AbstractFile
private $logs;
/**
*
* State of the import when processing. Type of ImportState
* When processing import, this variable is being updated in realtime, so the client can follow
* the state of the import also in realtime
* @MongoDB\Field(type="string")
*/
private $currState;
/**
* A message can be added to the state information
* @MongoDB\Field(type="string")
*/
private $currMessage;
public function __construct() {
$this->logs = new \Doctrine\Common\Collections\ArrayCollection();;
......
......@@ -15,12 +15,11 @@
{% set logs = logs is defined ? logs : form.vars.sonata_admin.admin.subject.logs %}
{% for log in logs %}
<div class="alert alert-{{ log.type }}">
<div class="alert alert-{{ log.level }}">
{% if dismissLog is defined %}
<button type="button" class="close" data-dismiss="alert" aria-label="Fermer" onclick="hideLog({{log.id}})"><span aria-hidden="true" style="font-size: 1.6rem">Ne plus afficher</span></button>
{% endif %}
<strong>{{ log.createdAt|date("d/m/Y à H:i") }}</strong> - {{ log.message|raw }}
<p>{{ log.subcontent|raw }}</p>
<strong>{{ log.createdAt|date("d/m/Y à H:i") }}</strong> - {{ log.displayMessage|raw }}
</div>
{% endfor %}
......
......@@ -22,6 +22,7 @@
case 'downloading': currClass = 'alert-info'; break;
case 'in_progress': currClass = 'alert-info'; break;
case 'failed': currClass = 'alert-danger'; break;
case 'errors': currClass = 'alert-warning'; break;
case 'completed': currClass = 'alert-success'; break;
}
$('.progress-container').removeClass("alert-info").addClass(currClass);
......
......@@ -18,8 +18,8 @@ use Biopen\GeoDirectoryBundle\Document\PostalAddress;
use Biopen\GeoDirectoryBundle\Document\ElementUrl;
use Biopen\GeoDirectoryBundle\Document\ElementImage;
use Biopen\GeoDirectoryBundle\Document\ImportState;
use Biopen\CoreBundle\Document\GoGoLog;
use Biopen\CoreBundle\Document\GoGoLogType;
use Biopen\CoreBundle\Document\GoGoLogImport;
use Biopen\CoreBundle\Document\GoGoLogLevel;
class ElementImportService
{
......@@ -225,27 +225,30 @@ class ElementImportService
$qb = $this->em->createQueryBuilder('BiopenGeoDirectoryBundle:Element');
$needModerationCount = $qb->field('source')->references($import)->field('moderationState')->notIn([ModerationState::NotNeeded])->count()->getQuery()->execute();
$result = "Import de " . $import->getSourceName() . " terminé - <strong>Total: " . $totalCount . "</strong>";
$message = "Import de " . $import->getSourceName() . " terminé";
if ($this->countElementCreated > 0) $result .= " - " . $this->countElementCreated . " élément.s importé.s";
if ($this->countElementUpdated > 0) $result .= " - " . $this->countElementUpdated . " élement.s mis à jour";
if ($this->countElementNothingToDo > 0) $result .= " - " . $this->countElementNothingToDo . " élement.s laissé.s tel.s quel.s (rien à mettre à jour)";
if ($countElemenDeleted > 0) $result .= " - " . $countElemenDeleted . " élement.s supprimé.s";
if ($needModerationCount > 0) $result .= " - " . $needModerationCount . " élement.s incomplets (geoloc ou catégories)";
if ($this->countElementErrors > 0) $result .= " - " . $this->countElementErrors . " erreur.s pendant l'import";
$logData = [
"elementsCount" => $totalCount,
"elementsCreatedCount" => $this->countElementCreated,
"elementsUpdatedCount" => $this->countElementUpdated,
"elementsNothingToDoCount" => $this->countElementNothingToDo,
"elementsNeedModerationCount" => $needModerationCount,
"elementsDeletedCount" => $countElemenDeleted,
"elementsErrorsCount" => $this->countElementErrors,
"errorMessages" => $this->errorsMessages
];
$totalErrors = $needModerationCount + $this->countElementErrors;
$logType = $totalErrors > 0 ? ($totalErrors > ($size / 4) ? 'error' : 'warning') : 'success';
$log = new GoGoLog($logType, $result);
$log->setSubcontent(implode('</br>', $this->errorsMessages));
$logLevel = $totalErrors > 0 ? ($totalErrors > ($size / 4) ? 'error' : 'warning') : 'success';
$log = new GoGoLogImport($logLevel, $message, $logData);
$import->addLog($log);
$import->setCurrState($totalErrors > ($size / 4) ? ImportState::Failed : ImportState::Completed);
$import->setCurrMessage($result . '</br></br>' . implode('</br>', $this->errorsMessages));
$import->setCurrState($totalErrors > 0 ? ($totalErrors == $size ? ImportState::Failed : ImportState::Errors) : ImportState::Completed);
$import->setCurrMessage($log->displayMessage() . '</br></br>' . implode('</br>', $this->errorsMessages));
$this->em->flush();
return $result;
return $message;
}
private function createElementFromArray($row, $import)
......
......@@ -8,7 +8,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Biopen\CoreBundle\Document\GoGoLog;
use Biopen\CoreBundle\Document\GoGoLogType;
use Biopen\CoreBundle\Document\GoGoLogLevel;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
class GoGoAbstractCommand extends ContainerAwareCommand
......@@ -54,7 +54,7 @@ class GoGoAbstractCommand extends ContainerAwareCommand
{
$this->logger->error($message);
$this->output->writeln('ERROR ' . $message);
$log = new GoGoLog(GoGoLogType::Error, 'Error running ' . $this->getName() . ' : ' . $message);
$log = new GoGoLog(GoGoLogLevel::Error, 'Error running ' . $this->getName() . ' : ' . $message);
$this->odm->persist($log);
$this->odm->flush();
}
......
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