mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix clean unvalid entries into ecm file table
This commit is contained in:
parent
132b4f95fe
commit
9c7686e571
|
|
@ -111,6 +111,7 @@ print 'Option clean_menus is '.(GETPOST('clean_menus', 'alpha') ? GETPOST('clean
|
|||
print 'Option clean_orphelin_dir is '.(GETPOST('clean_orphelin_dir', 'alpha') ? GETPOST('clean_orphelin_dir', 'alpha') : 'undefined').'<br>'."\n";
|
||||
print 'Option clean_product_stock_batch is '.(GETPOST('clean_product_stock_batch', 'alpha') ? GETPOST('clean_product_stock_batch', 'alpha') : 'undefined').'<br>'."\n";
|
||||
print 'Option clean_perm_table is '.(GETPOST('clean_perm_table', 'alpha') ? GETPOST('clean_perm_table', 'alpha') : 'undefined').'<br>'."\n";
|
||||
print 'Option clean_ecm_files_table is '.(GETPOST('clean_ecm_files_table', 'alpha') ? GETPOST('clean_ecm_files_table', 'alpha') : 'undefined').'<br>'."\n";
|
||||
print 'Option repair_link_dispatch_lines_supplier_order_lines, is '.(GETPOST('repair_link_dispatch_lines_supplier_order_lines', 'alpha') ? GETPOST('repair_link_dispatch_lines_supplier_order_lines', 'alpha') : 'undefined').'<br>'."\n";
|
||||
// Init data
|
||||
print 'Option set_empty_time_spent_amount is '.(GETPOST('set_empty_time_spent_amount', 'alpha') ? GETPOST('set_empty_time_spent_amount', 'alpha') : 'undefined').'<br>'."\n";
|
||||
|
|
@ -205,7 +206,7 @@ $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
|
|||
$oneoptionset = 0;
|
||||
$oneoptionset = (GETPOST('standard', 'alpha') || GETPOST('restore_thirdparties_logos', 'alpha') || GETPOST('clean_linked_elements', 'alpha') || GETPOST('clean_menus', 'alpha')
|
||||
|| GETPOST('clean_orphelin_dir', 'alpha') || GETPOST('clean_product_stock_batch', 'alpha') || GETPOST('set_empty_time_spent_amount', 'alpha') || GETPOST('rebuild_product_thumbs', 'alpha')
|
||||
|| GETPOST('clean_perm_table', 'alpha')
|
||||
|| GETPOST('clean_perm_table', 'alpha') || GETPOST('clean_ecm_files_table', 'alpha')
|
||||
|| GETPOST('force_disable_of_modules_not_found', 'alpha')
|
||||
|| GETPOST('force_utf8_on_tables', 'alpha') || GETPOST('force_utf8mb4_on_tables', 'alpha') || GETPOST('force_collation_from_conf_on_tables', 'alpha')
|
||||
|| GETPOST('rebuild_sequences', 'alpha') || GETPOST('recalculateinvoicetotal', 'alpha'));
|
||||
|
|
@ -1294,6 +1295,55 @@ if ($ok && GETPOST('clean_perm_table', 'alpha')) {
|
|||
}
|
||||
|
||||
|
||||
// clean_old_module_entries: Clean data into const when files of module were removed without being
|
||||
if ($ok && GETPOST('clean_ecm_files_table', 'alpha')) {
|
||||
print '<tr><td colspan="2"><br>*** Clean table ecm_files from lines of entries whose physical files does not exists anymore (emplemented for entity 1 only)</td></tr>';
|
||||
|
||||
$MAXTODELETE = 100;
|
||||
|
||||
$sql = "SELECT rowid, filename, filepath, entity from ".MAIN_DB_PREFIX."ecm_files";
|
||||
$sql .= " WHERE entity = 1";
|
||||
$sql .= " ORDER BY rowid ASC";
|
||||
|
||||
$nbfile = 0;
|
||||
$nbfiletodelete = 0;
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
if ($num) {
|
||||
$i = 0;
|
||||
while ($i < $num && $nbfiletodelete < $MAXTODELETE) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj->rowid > 0) {
|
||||
$filetocheck = DOL_DATA_ROOT.'/'.$obj->filepath.'/'.$obj->filename;
|
||||
$nbfile++;
|
||||
if (!dol_is_file($filetocheck)) {
|
||||
$nbfiletodelete++;
|
||||
print '<tr><td>Found line with id '.$obj->rowid.', entity '.$obj->entity.', file "'.$filetocheck.'" to delete';
|
||||
if (GETPOST('clean_ecm_files_table', 'alpha') == 'confirmed') {
|
||||
$sqldelete = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files WHERE rowid = ".((int) $obj->rowid);
|
||||
$resqldelete = $db->query($sqldelete);
|
||||
if (!$resqldelete) {
|
||||
dol_print_error($db);
|
||||
}
|
||||
print ' - deleted';
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
if ($nbfiletodelete > $MAXTODELETE) {
|
||||
print '<tr><td>There is more than '.$MAXTODELETE.' invalid entries into ecm_files index table (among '.$nbfile.' analyzed) with no valid physical files. Run the page several time to process all of them.</td></tr>';
|
||||
} else {
|
||||
print '<tr><td>Nb of entries processed into ecm_files index table: '.$nbfile.', number of invalid record: '.$nbfiletodelete.'</td></tr>';
|
||||
}
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
|
||||
// force utf8 on tables
|
||||
if ($ok && GETPOST('force_utf8_on_tables', 'alpha')) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user