diff --git a/library/Class/CodifThesaurus.php b/library/Class/CodifThesaurus.php index 4365bfc61b618ed05b60d8ffe0ae96448af6cdaf..11188fedaf492ab40ea1a665a7856a19c89d96a9 100644 --- a/library/Class/CodifThesaurus.php +++ b/library/Class/CodifThesaurus.php @@ -208,19 +208,8 @@ class Class_CodifThesaurusLoader extends Storm_Model_Loader { $thesauri = array_filter(Class_CodifThesaurus::getIndices('root', true), $filter); - foreach(Class_CodifThesaurus::findCustomFieldsRoot()->getChildren() as $item) { - if(!$meta = Class_CustomField_Meta::find($item->getIdOrigine())) { - $item->deleteMeAndMyChildren(); - continue; - } - - if(!Class_CustomField::findFirstBy(['meta_id' => $meta->getId()])) { - $meta->delete(); - continue; - } - + foreach(Class_CodifThesaurus::findCustomFieldsRoot()->getChildren() as $item) $thesauri[] = $item; - } return $thesauri; } diff --git a/library/Class/CustomField.php b/library/Class/CustomField.php index 6773bb6b12fe0bfadf39e2208a6180901aa0b38d..212f10d246b47ec2c23ef595cb59594ec4651e81 100644 --- a/library/Class/CustomField.php +++ b/library/Class/CustomField.php @@ -189,10 +189,4 @@ class Class_CustomField extends Storm_Model_Abstract { public function getThesaurusIdOrigine() { return $this->getMeta()->getId(); } - - - public function afterDelete() { - if($meta = $this->getMeta()) - $meta->delete(); - } } \ No newline at end of file diff --git a/library/Class/Migration/CleanCustomfieldsFacets.php b/library/Class/Migration/CleanCustomfieldsFacets.php new file mode 100644 index 0000000000000000000000000000000000000000..a72be8405f8687be4f724fd7658eeaaf27a3cd6b --- /dev/null +++ b/library/Class/Migration/CleanCustomfieldsFacets.php @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Migration_CleanCustomFieldsFacets { + use Trait_MemoryCleaner; + + protected $_patrons_group; + + public function run() { + if(!$custom_fields_thesaurus = Class_CodifThesaurus::findCustomFieldsRoot()->getChildren()) + return $this; + + foreach($custom_fields_thesaurus as $thesaurus) + if(Class_CustomField_Meta::find($thesaurus->getIdOrigine())) + $thesaurus->deleteMeAndMyChildren(); + } +} \ No newline at end of file