Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit f79b9479 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

fix features stuff

parent 567aced1
......@@ -50,7 +50,7 @@ class Language
private $relationType;
/**
* @ORM\OneToMany(targetEntity="Feature", mappedBy="language", cascade={"remove"})
* @ORM\OneToMany(targetEntity="Feature", mappedBy="language")
*/
private $features;
......
......@@ -37,7 +37,7 @@ class Word implements JsonSerializable
private $cleanValue;
/**
* @ORM\ManyToMany(targetEntity="Feature" , cascade={"remove"}, orphanRemoval=true)
* @ORM\ManyToMany(targetEntity="Feature", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $features;
......
......@@ -24,21 +24,22 @@ class FeatureManager
$this->em = $em;
}
public function findOrCreate(Language $language, $label, $value, &$features)
public function findOrCreate(Language $language, $label, $value, &$featuresToFlush)
{
if (!isset($features[$label][$value])) {
if (!array_key_exists($label, $featuresToFlush) || !array_key_exists($value, $featuresToFlush[$label])) {
if (!$feature = $this->em->getRepository(Feature::class)->findOneBy(['value' => $value, 'label' => $label, 'language' => $language])) {
$feature = new Feature();
$feature->setLanguage($language);
$feature->setValue($value);
$feature->setLabel($label);
$feature->setValue($value);
$this->em->persist($feature);
$features[$label][$value] = $feature;
$featuresToFlush[$label][$value] = $feature;
}
return $feature;
}
return $features[$label][$value];
return $featuresToFlush[$label][$value];
}
}
......@@ -136,7 +136,7 @@ class ImportManager
$lengths = $specs["lengths"];
$pathLexiconDir = $specs["directory"];
$roots = [];
$features = [];
$featuresToFlush = [];
$letters = [];
$wordStarts = [];
$flushCpt = 0;
......@@ -175,7 +175,7 @@ class ImportManager
$features = [];
foreach ($labelsNValues as $labelNValue) {
$featureStringTab = explode("=", $labelNValue);
$features[] = $this->fm->findOrCreate($language, $featureStringTab[0], $featureStringTab[1]);
$features[] = $this->fm->findOrCreate($language, $featureStringTab[0], $featureStringTab[1], $featuresToFlush);
}
$this->wm->create($language, $root, $features, $wordValue, $cleanWordValue);
......@@ -206,8 +206,8 @@ class ImportManager
$flushCpt = 1;
$roots = null;
$roots = [];
$features = null;
$features = [];
$featuresToFlush = null;
$featuresToFlush = [];
$languageId = $specs["language_id"];
$language = $this->em->getRepository(Language::class)->find($languageId);
$percent = round($cpt / $total * 100, 2);
......
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