Skip to content
Snippets Groups Projects
Commit ec6c843c authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #31425 : script to delete orphaned pseudo records

parent 0a37ce56
Branches
Tags
5 merge requests!1267Master,!1221Master,!1220Hotline master,!1199Hotline#31425 quand on supprime une sitotheque un article ils sont encore indexes,!1193Hotline#31425 quand on supprime une sitotheque un article ils sont encore indexes
- ticket #31425 : script de suppression des pseudos notices orphelines
\ No newline at end of file
<?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
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