Commit d792b87c authored by Sebastian Castro's avatar Sebastian Castro

Adds idsToIgnore to ImportDynamic

parent 932c8186
......@@ -34,7 +34,8 @@ class ImportDynamicAdmin extends AbstractAdmin
'multiple' => true,
'btn_add' => false,
'label' => 'Options à ajouter à chaque élément importé'), array('admin_code' => 'admin.option'))
->add('refreshFrequencyInDays', null, array('required' => false, 'label' => "Fréquence de mise à jours des données en jours (laisser vide pour ne jamais mettre à jour automatiquement"));
->add('refreshFrequencyInDays', null, array('required' => false, 'label' => "Fréquence de mise à jours des données en jours (laisser vide pour ne jamais mettre à jour automatiquement"))
->add('idsToIgnore', 'text', array('required' => false, 'attr' => ['class' => 'gogo-display-array'], 'label' => "Liste des IDs à ignorer lors de l'import (pour ignorer un élément, supprimer le et il ne sera plus jamais importé"));
}
protected function configureRoutes(RouteCollection $collection)
......
......@@ -85,11 +85,11 @@ class ElementInteractionController extends Controller
$em = $this->get('doctrine_mongodb')->getManager();
$element = $em->getRepository('BiopenGeoDirectoryBundle:Element')->find($request->get('elementId'));
$em->persist($element);
$elementActionService = $this->container->get('biopen.element_action_service');
$elementActionService->delete($element, true, $request->get('message'));
$em->persist($element);
$em->flush();
return $this->returnResponse(true, "L'élément a bien été supprimé");
......
......@@ -12,6 +12,10 @@ use Biopen\CoreBundle\Document\AbstractFile;
* @Vich\Uploadable
* Import data into GoGoCarto. the data can imported through a static file, or via API url
* The Import can be made once for all (static import) or dynamically every X days (ImportDynamic)
*
* @MongoDB\InheritanceType("SINGLE_COLLECTION")
* @MongoDB\DiscriminatorField("type")
* @MongoDB\DiscriminatorMap({"normal"="Import", "dynamic"="ImportDynamic"})
*/
class Import extends AbstractFile
{
......
......@@ -32,6 +32,14 @@ class ImportDynamic extends Import
*/
private $nextRefresh = null;
/**
* After importing some Data, if the user delete some elements, their ids will be remembered
* so next time we do not import them again
*
* @MongoDB\Field(type="collection")
*/
private $idsToIgnore = [];
public function isDynamicImport() { return true; }
public function updateNextRefreshDate()
......@@ -46,6 +54,11 @@ class ImportDynamic extends Import
}
}
public function addIdToIgnore($id)
{
$this->idsToIgnore[] = $id;
}
/**
* Set refreshFrequencyInDays
*
......@@ -111,4 +124,27 @@ class ImportDynamic extends Import
{
return $this->nextRefresh;
}
/**
* Set idsToIgnore
*
* @param collection $idsToIgnore
* @return $this
*/
public function setIdsToIgnore($idsToIgnore)
{
$this->idsToIgnore = $idsToIgnore;
return $this;
}
/**
* Get idsToIgnore
*
* @return collection $idsToIgnore
*/
public function getIdsToIgnore()
{
return $this->idsToIgnore;
}
}
{% for id in form.vars.value %}
{{ id }}{% if not loop.last %}, {% endif %}
{% endfor %}
......@@ -29,6 +29,8 @@
{% include '@BiopenAdmin/core_custom/custom-fields/api-list.html.twig' %}
{% elseif attr_class == "gogo-code-editor" %}
{% include '@BiopenAdmin/core_custom/custom-fields/ace-code-editor.html.twig' %}
{% elseif attr_class == "gogo-display-array" %}
{% include '@BiopenAdmin/core_custom/custom-fields/display-array.html.twig' %}
{% else %}
{% set attr = attr|merge({'class': attr_class ~ ' form-control'}) %}
{{ parent() }}
......
......@@ -104,6 +104,12 @@ class ElementActionService
public function delete($element, $sendMail = true, $message = null)
{
if ($element->getStatus() == ElementStatus::DynamicImport) {
$import = $element->getSource();
$import->addIdToIgnore($element->getOldId());
$this->em->persist($import);
}
$this->addContribution($element, $message, InteractType::Deleted, ElementStatus::Deleted);
$newStatus = $element->isPotentialDuplicate() ? ElementStatus::Duplicate : ElementStatus::Deleted;
$element->setStatus($newStatus);
......
......@@ -176,6 +176,7 @@ class ElementImportService
private function createElementFromArray($row, $import)
{
if (in_array($row['id'], $import->getIdsToIgnore())) return;
$this->currentRow = $row;
$new_element = new Element();
$new_element->setOldId($row['id']);
......
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