diff --git a/VERSIONS_HOTLINE/31425 b/VERSIONS_HOTLINE/31425 new file mode 100644 index 0000000000000000000000000000000000000000..a0c0372285554888f6d61c69921e313538cb5a0a --- /dev/null +++ b/VERSIONS_HOTLINE/31425 @@ -0,0 +1 @@ + - ticket #31425 : script de suppression des pseudos notices orphelines \ No newline at end of file diff --git a/scripts/delete_orphaned_pseudo_records.php b/scripts/delete_orphaned_pseudo_records.php new file mode 100644 index 0000000000000000000000000000000000000000..0c6cb74b4d0f0784c0b7c7324e5ac452bade3d1e --- /dev/null +++ b/scripts/delete_orphaned_pseudo_records.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright (c) 2012-2015, 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 + */ + + +require('console.php'); + +run_orphaned('Sites', Class_TypeDoc::SITE, 'getSite'); +run_orphaned('CMS', Class_TypeDoc::ARTICLE, 'getArticle'); + +function run_orphaned($label, $type, $parent_getter) { + $adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + + echo $label . "\n"; + + $ids = $adapter->query('select id_notice from notices where type_doc=' . $type) + ->fetchAll(); + + + if (!$ids) { + echo "No records found\n"; + return; + } + + echo count($ids) . " record(s) to verify\n"; + + $ids = array_chunk($ids, 500, true); + + $deleted = 0; + foreach($ids as $page) { + foreach($page as $data) { + if (!$record = Class_Notice::find((int)$data['id_notice'])) { + echo "Records " . $data['id_notice'] . " does not exists\n"; + continue; + } + + if (call_user_func([$record, $parent_getter])) { + echo "Records " . $data['id_notice'] . " is not an orphan\n"; + continue; + } + + $record->delete(); + echo "Records " . $data['id_notice'] . " has been deleted\n"; + $deleted++; + } + + Storm_Model_Abstract::unsetLoaders(); + Storm_Model_Loader::resetCache(); + gc_collect_cycles(); + } + + echo $deleted . " records deleted\n\n"; +} \ No newline at end of file