28include_once
'inc.php';
29if (file_exists($conffile)) {
30 include_once $conffile;
32require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
33include_once $dolibarr_main_document_root.
'/core/lib/images.lib.php';
34require_once $dolibarr_main_document_root.
'/core/class/extrafields.class.php';
35require_once
'lib/repair.lib.php';
43$err = error_reporting();
48$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
49$langs->setDefaultLang($setuplang);
51$langs->loadLangs(array(
"admin",
"install",
"other"));
53if ($dolibarr_main_db_type ==
"mysqli") {
56if ($dolibarr_main_db_type ==
"pgsql") {
59if ($dolibarr_main_db_type ==
"mssql") {
65if (!is_object($conf)) {
79print
'<h3>'.$langs->trans(
"Repair").
'</h3>';
81print
'Option standard (\'test\' or \'confirmed\') is '.(GETPOST(
'standard',
'alpha') ?
GETPOST(
'standard',
'alpha') :
'undefined').
'<br>'.
"\n";
83print
'Option force_disable_of_modules_not_found (\'test\' or \'confirmed\') is '.(GETPOST(
'force_disable_of_modules_not_found',
'alpha') ?
GETPOST(
'force_disable_of_modules_not_found',
'alpha') :
'undefined').
'<br>'.
"\n";
85print
'Option restore_thirdparties_logos (\'test\' or \'confirmed\') is '.(GETPOST(
'restore_thirdparties_logos',
'alpha') ?
GETPOST(
'restore_thirdparties_logos',
'alpha') :
'undefined').
'<br>'.
"\n";
86print
'Option restore_user_pictures (\'test\' or \'confirmed\') is '.(GETPOST(
'restore_user_pictures',
'alpha') ?
GETPOST(
'restore_user_pictures',
'alpha') :
'undefined').
'<br>'.
"\n";
87print
'Option rebuild_product_thumbs (\'test\' or \'confirmed\') is '.(GETPOST(
'rebuild_product_thumbs',
'alpha') ?
GETPOST(
'rebuild_product_thumbs',
'alpha') :
'undefined').
'<br>'.
"\n";
89print
'Option clean_linked_elements (\'test\' or \'confirmed\') is '.(GETPOST(
'clean_linked_elements',
'alpha') ?
GETPOST(
'clean_linked_elements',
'alpha') :
'undefined').
'<br>'.
"\n";
90print
'Option clean_menus (\'test\' or \'confirmed\') is '.(GETPOST(
'clean_menus',
'alpha') ?
GETPOST(
'clean_menus',
'alpha') :
'undefined').
'<br>'.
"\n";
91print
'Option clean_orphelin_dir (\'test\' or \'confirmed\') is '.(GETPOST(
'clean_orphelin_dir',
'alpha') ?
GETPOST(
'clean_orphelin_dir',
'alpha') :
'undefined').
'<br>'.
"\n";
92print
'Option clean_product_stock_batch (\'test\' or \'confirmed\') is '.(GETPOST(
'clean_product_stock_batch',
'alpha') ?
GETPOST(
'clean_product_stock_batch',
'alpha') :
'undefined').
'<br>'.
"\n";
93print
'Option clean_perm_table (\'test\' or \'confirmed\') is '.(GETPOST(
'clean_perm_table',
'alpha') ?
GETPOST(
'clean_perm_table',
'alpha') :
'undefined').
'<br>'.
"\n";
94print
'Option repair_link_dispatch_lines_supplier_order_lines, (\'test\' or \'confirmed\') is '.(GETPOST(
'repair_link_dispatch_lines_supplier_order_lines',
'alpha') ?
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines',
'alpha') :
'undefined').
'<br>'.
"\n";
96print
'Option set_empty_time_spent_amount (\'test\' or \'confirmed\') is '.(GETPOST(
'set_empty_time_spent_amount',
'alpha') ?
GETPOST(
'set_empty_time_spent_amount',
'alpha') :
'undefined').
'<br>'.
"\n";
98print
'Option force_utf8_on_tables (force utf8 + row=dynamic), for mysql/mariadb only (\'test\' or \'confirmed\') is '.(GETPOST(
'force_utf8_on_tables',
'alpha') ?
GETPOST(
'force_utf8_on_tables',
'alpha') :
'undefined').
'<br>'.
"\n";
99print
"Option force_utf8mb4_on_tables (force utf8mb4 + row=dynamic, EXPERIMENTAL!), for mysql/mariadb only ('test' or 'confirmed') is ".(GETPOST(
'force_utf8mb4_on_tables',
'alpha') ?
GETPOST(
'force_utf8mb4_on_tables',
'alpha') :
'undefined').
"<br>\n";
100print
"Option force_collation_from_conf_on_tables (force ".$conf->db->character_set.
"/".$conf->db->dolibarr_main_db_collation.
" + row=dynamic), for mysql/mariadb only ('test' or 'confirmed') is ".(
GETPOST(
'force_collation_from_conf_on_tables',
'alpha') ?
GETPOST(
'force_collation_from_conf_on_tables',
'alpha') :
'undefined').
"<br>\n";
102print
'Option rebuild_sequences, for postgresql only (\'test\' or \'confirmed\') is '.(GETPOST(
'rebuild_sequences',
'alpha') ?
GETPOST(
'rebuild_sequences',
'alpha') :
'undefined').
'<br>'.
"\n";
105print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
109if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
110 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
111 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
112 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
113 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
114 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
116 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
121$conf->db->type = $dolibarr_main_db_type;
122$conf->db->host = $dolibarr_main_db_host;
123$conf->db->port = $dolibarr_main_db_port;
124$conf->db->name = $dolibarr_main_db_name;
125$conf->db->user = $dolibarr_main_db_user;
126$conf->db->pass = $dolibarr_main_db_pass;
129$conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption :
'';
130$conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
132$db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
135 print
'<tr><td class="nowrap">';
136 print $langs->trans(
"ServerConnection").
" : $dolibarr_main_db_host</td><td class=\"right\">".$langs->trans(
"OK").
"</td></tr>";
137 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ServerConnection").
": ".$dolibarr_main_db_host.$langs->transnoentities(
"OK"));
140 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
"</td><td class=\"right\">".$langs->transnoentities(
"Error").
"</td></tr>";
141 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
146 if ($db->database_selected) {
147 print
'<tr><td class="nowrap">';
148 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
"</td><td class=\"right\">".$langs->trans(
"OK").
"</td></tr>";
152 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
"</td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>";
153 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
160 $version = $db->getVersion();
161 $versionarray = $db->getVersionArray();
162 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
163 print
'<td class="right">'.$version.
'</td></tr>';
168$conf->setValues($db);
170if (defined(
'SYSLOG_FILE')) {
171 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
173$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
178$oneoptionset = (
GETPOST(
'standard',
'alpha') ||
GETPOST(
'restore_thirdparties_logos',
'alpha') ||
GETPOST(
'clean_linked_elements',
'alpha') ||
GETPOST(
'clean_menus',
'alpha')
179 ||
GETPOST(
'clean_orphelin_dir',
'alpha') ||
GETPOST(
'clean_product_stock_batch',
'alpha') ||
GETPOST(
'set_empty_time_spent_amount',
'alpha') ||
GETPOST(
'rebuild_product_thumbs',
'alpha')
180 ||
GETPOST(
'clean_perm_table',
'alpha')
181 ||
GETPOST(
'force_disable_of_modules_not_found',
'alpha')
182 ||
GETPOST(
'force_utf8_on_tables',
'alpha') ||
GETPOST(
'force_utf8mb4_on_tables',
'alpha') ||
GETPOST(
'force_collation_from_conf_on_tables',
'alpha')
183 ||
GETPOST(
'rebuild_sequences',
'alpha'));
185if ($ok && $oneoptionset) {
187 print
'<tr><td colspan="2">'.$langs->trans(
"PleaseBePatient").
'<br><br></td></tr>';
193if ($ok &&
GETPOST(
'standard',
'alpha')) {
194 $dir =
"mysql/migration/";
201 $filesindir = array();
202 $handle = opendir($dir);
203 if (is_resource($handle)) {
204 while (($file = readdir($handle)) !==
false) {
205 if (preg_match(
'/\.sql$/i', $file)) {
206 $filesindir[] = $file;
212 foreach ($filesindir as $file) {
213 if (preg_match(
'/repair/i', $file)) {
219 foreach ($filelist as $file) {
220 print
'<tr><td class="nowrap">*** ';
221 print $langs->trans(
"Script").
'</td><td class="right">'.$file.
'</td></tr>';
223 $name = substr($file, 0,
dol_strlen($file) - 4);
226 $ok =
run_sql($dir.$file, 0,
'', 1);
233if ($ok &&
GETPOST(
'standard',
'alpha')) {
237 $listofmodulesextra = array(
'societe'=>
'societe',
'adherent'=>
'adherent',
'product'=>
'product',
238 'socpeople'=>
'socpeople',
'propal'=>
'propal',
'commande'=>
'commande',
239 'facture'=>
'facture',
'facturedet'=>
'facturedet',
'facture_rec'=>
'facture_rec',
'facturedet_rec'=>
'facturedet_rec',
240 'supplier_proposal'=>
'supplier_proposal',
'commande_fournisseur'=>
'commande_fournisseur',
241 'facture_fourn'=>
'facture_fourn',
'facture_fourn_rec'=>
'facture_fourn_rec',
'facture_fourn_det'=>
'facture_fourn_det',
'facture_fourn_det_rec'=>
'facture_fourn_det_rec',
242 'fichinter'=>
'fichinter',
'fichinterdet'=>
'fichinterdet',
243 'inventory'=>
'inventory',
244 'actioncomm'=>
'actioncomm',
'bom_bom'=>
'bom_bom',
'mrp_mo'=>
'mrp_mo',
245 'adherent_type'=>
'adherent_type',
'user'=>
'user',
'partnership'=>
'partnership',
'projet'=>
'projet',
'projet_task'=>
'projet_task',
'ticket'=>
'ticket');
248 print
'<tr><td colspan="2"><br>*** Check fields into extra table structure match table of definition. If not add column into table</td></tr>';
249 foreach ($listofmodulesextra as $tablename => $elementtype) {
251 $tableextra = MAIN_DB_PREFIX.$tablename.
'_extrafields';
254 $arrayoffieldsdesc = $extrafields->fetch_name_optionals_label($elementtype);
257 $arrayoffieldsfound = array();
258 $resql = $db->DDLDescTable($tableextra);
260 print
'<tr><td>Check availability of extra field for '.$tableextra;
262 while ($obj = $db->fetch_object($resql)) {
263 $fieldname = $fieldtype =
'';
264 if (preg_match(
'/mysql/', $db->type)) {
265 $fieldname = $obj->Field;
266 $fieldtype = $obj->Type;
268 $fieldname = isset($obj->Key) ? $obj->Key : $obj->attname;
269 $fieldtype = isset($obj->Type) ? $obj->Type :
'varchar';
272 if (empty($fieldname)) {
275 if (in_array($fieldname, array(
'rowid',
'tms',
'fk_object',
'import_key'))) {
278 $arrayoffieldsfound[$fieldname] = array(
'type'=>$fieldtype);
280 print
' - Found '.count($arrayoffieldsfound).
' fields into table';
281 if (count($arrayoffieldsfound) > 0) {
282 print
' <span class="opacitymedium">('.join(
', ', array_keys($arrayoffieldsfound)).
')</span>';
287 foreach ($arrayoffieldsdesc as $code => $label) {
288 if (!in_array($code, array_keys($arrayoffieldsfound))) {
289 print
'Found field '.$code.
' declared into '.MAIN_DB_PREFIX.
'extrafields table but not found into desc of table '.$tableextra.
" -> ";
290 $type = $extrafields->attributes[$elementtype][
'type'][$code];
291 $length = $extrafields->attributes[$elementtype][
'size'][$code];
297 if ($type ==
'boolean') {
300 } elseif ($type ==
'price') {
303 } elseif ($type ==
'phone') {
306 } elseif ($type ==
'mail') {
309 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
312 } elseif ($type ==
'link') {
323 'attribute'=>$attribute,
331 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
332 $result = $db->DDLAddField($tableextra, $code, $field_desc,
"");
335 print
"KO ".$db->lasterror.
"<br>\n";
340 print
' - Mode test, no column added.';
345 print
"</td><td> </td></tr>\n";
347 print
'<tr><td>Table '.$tableextra.
' is not found</td><td></td></tr>'.
"\n";
354if ($ok &&
GETPOST(
'standard',
'alpha')) {
360if ($ok &&
GETPOST(
'standard',
'alpha')) {
361 print
'<tr><td colspan="2"><br>*** Clean constant record of modules not enabled</td></tr>';
363 $sql =
"SELECT name, entity, value";
364 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
365 $sql .=
" WHERE name LIKE 'MAIN_MODULE_%_TPL' OR name LIKE 'MAIN_MODULE_%_CSS' OR name LIKE 'MAIN_MODULE_%_JS' OR name LIKE 'MAIN_MODULE_%_HOOKS'";
366 $sql .=
" OR name LIKE 'MAIN_MODULE_%_TRIGGERS' OR name LIKE 'MAIN_MODULE_%_THEME' OR name LIKE 'MAIN_MODULE_%_SUBSTITUTIONS' OR name LIKE 'MAIN_MODULE_%_MODELS'";
367 $sql .=
" OR name LIKE 'MAIN_MODULE_%_MENUS' OR name LIKE 'MAIN_MODULE_%_LOGIN' OR name LIKE 'MAIN_MODULE_%_BARCODE' OR name LIKE 'MAIN_MODULE_%_TABS_%'";
368 $sql .=
" OR name LIKE 'MAIN_MODULE_%_MODULEFOREXTERNAL'";
369 $sql .=
" ORDER BY name, entity";
371 $resql = $db->query($sql);
373 $num = $db->num_rows($resql);
380 $obj = $db->fetch_object($resql);
383 if (preg_match(
'/MAIN_MODULE_([^_]+)_(.+)/i', $obj->name, $reg)) {
387 $sql2 =
"SELECT COUNT(*) as nb";
388 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
389 $sql2 .=
" WHERE name = 'MAIN_MODULE_".$name.
"'";
390 $sql2 .=
" AND entity = ".((int) $obj->entity);
391 $resql2 = $db->query($sql2);
393 $obj2 = $db->fetch_object($resql2);
394 if ($obj2 && $obj2->nb == 0) {
396 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = '".$db->escape($obj->name).
"' AND entity = ".((int) $obj->entity);
398 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
399 $db->query($sqldelete);
401 print
'<tr><td>Widget '.$obj->name.
' set in entity '.$obj->entity.
' with value '.$obj->value.
' -> Module '.$name.
' not enabled in entity '.((int) $obj->entity).
', we delete record</td></tr>';
403 print
'<tr><td>Widget '.$obj->name.
' set in entity '.$obj->entity.
' with value '.$obj->value.
' -> Module '.$name.
' not enabled in entity '.((int) $obj->entity).
', we should delete record (not done, mode test)</td></tr>';
423if ($ok &&
GETPOST(
'standard',
'alpha')) {
424 print
'<tr><td colspan="2"><br>*** Clean definition of boxes of modules not enabled</td></tr>';
426 $sql =
"SELECT file, entity FROM ".MAIN_DB_PREFIX.
"boxes_def";
427 $sql .=
" WHERE file like '%@%'";
429 $resql = $db->query($sql);
431 $num = $db->num_rows($resql);
438 $obj = $db->fetch_object($resql);
441 if (preg_match(
'/^(.+)@(.+)$/i', $obj->file, $reg)) {
445 $sql2 =
"SELECT COUNT(*) as nb";
446 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
447 $sql2 .=
" WHERE name = 'MAIN_MODULE_".strtoupper($module).
"'";
448 $sql2 .=
" AND entity = ".((int) $obj->entity);
449 $sql2 .=
" AND value <> 0";
450 $resql2 = $db->query($sql2);
452 $obj2 = $db->fetch_object($resql2);
453 if ($obj2 && $obj2->nb == 0) {
455 $sqldeletea =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes WHERE entity = ".((int) $obj->entity).
" AND box_id IN (SELECT rowid FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE file = '".$db->escape($obj->file).
"' AND entity = ".((int) $obj->entity).
")";
456 $sqldeleteb =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE file = '".$db->escape($obj->file).
"' AND entity = ".((int) $obj->entity);
458 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
459 $db->query($sqldeletea);
460 $db->query($sqldeleteb);
462 print
'<tr><td>Constant '.$obj->file.
' set in boxes_def for entity '.$obj->entity.
' but MAIN_MODULE_'.strtoupper($module).
' not defined in entity '.((int) $obj->entity).
', we delete record</td></tr>';
464 print
'<tr><td>Constant '.$obj->file.
' set in boxes_def for entity '.$obj->entity.
' but MAIN_MODULE_'.strtoupper($module).
' not defined in entity '.((int) $obj->entity).
', we should delete record (not done, mode test)</td></tr>';
482if ($ok &&
GETPOST(
'restore_thirdparties_logos')) {
487 print
'<tr><td colspan="2"><br>*** Restore thirdparties logo<br>';
489 $sql =
"SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX.
"societe as s ORDER BY s.nom";
490 $resql = $db->query($sql);
492 $num = $db->num_rows($resql);
496 $obj = $db->fetch_object($resql);
504 $tmp = explode(
'.', $obj->logo);
506 if (isset($tmp[1])) {
511 $filetotest = $dolibarr_main_data_root.
'/societe/logos/'.$name.$ext;
512 $filetotestsmall = $dolibarr_main_data_root.
'/societe/logos/thumbs/'.$name.
'_small'.$ext;
514 print
'Check thirdparty '.$obj->rowid.
' name='.$obj->name.
' logo='.$obj->logo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
516 $filetarget = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/'.$name.$ext;
517 $filetargetsmall = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs/'.$name.
'_small'.$ext;
520 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
521 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos');
524 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
525 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
526 dol_copy($filetotest, $filetarget,
'', 0);
532 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
533 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs');
535 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
536 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
537 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
556if ($ok &&
GETPOST(
'restore_user_pictures',
'alpha')) {
561 print
'<tr><td colspan="2"><br>*** Restore user pictures<br>';
563 $sql =
"SELECT s.rowid, s.firstname, s.lastname, s.login, s.photo FROM ".MAIN_DB_PREFIX.
"user as s ORDER BY s.rowid";
564 $resql = $db->query($sql);
566 $num = $db->num_rows($resql);
570 $obj = $db->fetch_object($resql);
578 $tmp = explode(
'.', $obj->photo);
580 if (isset($tmp[1])) {
585 $filetotest = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/'.$name.$ext;
586 $filetotestsmall = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_small'.$ext;
587 $filetotestmini = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_mini'.$ext;
589 print
'Check user '.$obj->rowid.
' lastname='.$obj->lastname.
' firstname='.$obj->firstname.
' photo='.$obj->photo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
591 $filetarget = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/'.$name.$ext;
592 $filetargetsmall = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_small'.$ext;
593 $filetargetmini = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_mini'.$ext;
597 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
598 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid);
601 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
602 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
603 dol_copy($filetotest, $filetarget,
'', 0);
609 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
610 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
613 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
614 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
615 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
621 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
622 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
625 print
" -> Copy file ".$filetotestmini.
" -> ".$filetargetmini.
"<br>\n";
626 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
627 dol_copy($filetotestmini, $filetargetmini,
'', 0);
645if ($ok &&
GETPOST(
'rebuild_product_thumbs',
'alpha')) {
647 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
649 print
'<tr><td colspan="2"><br>*** Rebuild product thumbs<br>';
651 $sql =
"SELECT s.rowid, s.ref FROM ".MAIN_DB_PREFIX.
"product as s ORDER BY s.ref";
652 $resql = $db->query($sql);
654 $num = $db->num_rows($resql);
658 $obj = $db->fetch_object($resql);
660 if (!empty($obj->ref)) {
661 $files =
dol_dir_list($dolibarr_main_data_root.
'/produit/'.$obj->ref,
'files', 0);
662 foreach ($files as $file) {
665 $imgThumbSmall =
'notbuild';
666 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
668 $imgThumbSmall =
vignette($file[
'fullname'], $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
670 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbSmall.
" maxwidthsmall=".$maxwidthsmall.
" maxheightsmall=".$maxheightsmall.
"<br>\n";
671 $imgThumbMini =
'notbuild';
672 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
675 $imgThumbMini =
vignette($file[
'fullname'], $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
677 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbMini.
" maxwidthmini=".$maxwidthmini.
" maxheightmini=".$maxheightmini.
"<br>\n";
693if ($ok &&
GETPOST(
'clean_linked_elements',
'alpha')) {
694 print
'<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>';
696 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'commande').
"</td></tr>\n";
699 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'facture').
"</td></tr>\n";
702 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'facture').
"</td></tr>\n";
705 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'shipping').
"</td></tr>\n";
708 print
'<tr><td colspan="2">'.checkLinkedElements(
'shipping',
'delivery').
"</td></tr>\n";
711 print
'<tr><td colspan="2">'.checkLinkedElements(
'order_supplier',
'invoice_supplier').
"</td></tr>\n";
716if ($ok &&
GETPOST(
'clean_menus',
'alpha')) {
717 print
'<tr><td colspan="2"><br>*** Clean menu entries coming from disabled modules</td></tr>';
719 $sql =
"SELECT rowid, module";
720 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as c";
721 $sql .=
" WHERE module IS NOT NULL AND module <> ''";
722 $sql .=
" ORDER BY module";
724 $resql = $db->query($sql);
726 $num = $db->num_rows($resql);
730 $obj = $db->fetch_object($resql);
732 $modulecond = $obj->module;
733 $modulecondarray = explode(
'|', $obj->module);
742 foreach ($modulecondarray as $tmpname) {
743 if ($tmpname ==
'margins') {
748 if (!empty($conf->$tmpname)) {
749 $result = $conf->$tmpname->enabled;
756 if (!$moduleok && $modulecond) {
757 print
' - Module condition '.$modulecond.
' seems ko, we delete menu entry.';
758 if (
GETPOST(
'clean_menus') ==
'confirmed') {
759 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu WHERE module = '".$db->escape($modulecond).
"'";
760 $resql2 = $db->query($sql2);
765 print
' - <span class="warning">Cleaned</span>';
768 print
' - <span class="warning">Canceled (test mode)</span>';
771 print
' - Module condition '.$modulecond.
' is ok, we do nothing.';
790 print
'<tr><td>No menu entries of disabled menus found</td></tr>';
800if ($ok &&
GETPOST(
'clean_orphelin_dir',
'alpha')) {
801 $listmodulepart = array(
'company',
'invoice',
'invoice_supplier',
'propal',
'order',
'order_supplier',
'contract',
'tax');
802 foreach ($listmodulepart as $modulepart) {
803 $filearray = array();
804 $upload_dir = isset($conf->$modulepart->dir_output) ? $conf->$modulepart->dir_output :
'';
805 if ($modulepart ==
'company') {
806 $upload_dir = $conf->societe->dir_output;
808 if ($modulepart ==
'invoice') {
809 $upload_dir = $conf->facture->dir_output;
811 if ($modulepart ==
'invoice_supplier') {
812 $upload_dir = $conf->fournisseur->facture->dir_output;
814 if ($modulepart ==
'order') {
815 $upload_dir = $conf->commande->dir_output;
817 if ($modulepart ==
'order_supplier') {
818 $upload_dir = $conf->fournisseur->commande->dir_output;
820 if ($modulepart ==
'contract') {
821 $upload_dir = $conf->contrat->dir_output;
824 if (empty($upload_dir)) {
828 print
'<tr><td colspan="2"><br>*** Clean orphelins files into files '.$upload_dir.
'</td></tr>';
830 $filearray =
dol_dir_list($upload_dir,
"files", 1,
'', array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$'),
'', SORT_DESC, 1,
true);
833 if ($modulepart ==
'company') {
834 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
835 $object_instance =
new Societe($db);
837 if ($modulepart ==
'invoice') {
838 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
839 $object_instance =
new Facture($db);
840 } elseif ($modulepart ==
'invoice_supplier') {
841 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
843 } elseif ($modulepart ==
'propal') {
844 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
845 $object_instance =
new Propal($db);
846 } elseif ($modulepart ==
'order') {
847 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
848 $object_instance =
new Commande($db);
849 } elseif ($modulepart ==
'order_supplier') {
850 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
852 } elseif ($modulepart ==
'contract') {
853 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
854 $object_instance =
new Contrat($db);
855 } elseif ($modulepart ==
'tax') {
856 include_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
860 foreach ($filearray as $key => $file) {
861 if (!is_dir($file[
'name'])
862 && $file[
'name'] !=
'.'
863 && $file[
'name'] !=
'..'
864 && $file[
'name'] !=
'CVS'
867 $relativefile = preg_replace(
'/'.preg_quote($upload_dir.
'/',
'/').
'/',
'', $file[
'fullname']);
872 $object_instance->id = 0;
873 $object_instance->ref =
'';
877 if ($modulepart ==
'invoice') {
878 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
881 if ($modulepart ==
'invoice_supplier') {
882 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg);
883 $id = empty($reg[1]) ?
'' : $reg[1];
885 if ($modulepart ==
'propal') {
886 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
889 if ($modulepart ==
'order') {
890 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
893 if ($modulepart ==
'order_supplier') {
894 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
897 if ($modulepart ==
'contract') {
898 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
901 if ($modulepart ==
'tax') {
902 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg);
908 $result = $object_instance->fetch($id, $ref);
912 print
'<tr><td colspan="2">';
913 print
'Delete orphelins file '.$file[
'fullname'].
'<br>';
914 if (
GETPOST(
'clean_orphelin_dir',
'alpha') ==
'confirmed') {
919 } elseif ($result < 0) {
920 print
'Error in '.get_class($object_instance).
'.fetch of id'.$id.
' ref='.$ref.
', result='.$result.
'<br>';
929if ($ok &&
GETPOST(
'clean_product_stock_batch',
'alpha')) {
930 $methodtofix =
GETPOST(
'methodtofix',
'alpha') ?
GETPOST(
'methodtofix',
'alpha') :
'updatestock';
932 print
'<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
934 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"product_stock as ps LEFT JOIN ".MAIN_DB_PREFIX.
"product_batch as pb ON ps.rowid = pb.fk_product_stock";
936 $sql .=
" WHERE p.rowid = ps.fk_product";
937 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
938 $sql .=
" HAVING (SUM(pb.qty) IS NOT NULL AND reel != SUM(pb.qty)) OR (SUM(pb.qty) IS NULL AND p.tobatch > 0)";
940 $resql = $db->query($sql);
942 $num = $db->num_rows($resql);
947 $obj = $db->fetch_object($resql);
948 print
'<tr><td>Product '.$obj->rowid.
'-'.$obj->ref.
' in warehouse id='.$obj->fk_entrepot.
' (product_stock.id='.$obj->psrowid.
'): '.$obj->reel.
' (Stock product_stock.reel) != '.($obj->reelbatch ? $obj->reelbatch :
'0').
' (Stock batch sum product_batch)';
951 if ($obj->reel != $obj->reelbatch) {
952 if (empty($obj->tobatch)) {
954 print
' -> Delete qty '.$obj->reelbatch.
' for any lot linked to fk_product_stock='.$obj->psrowid;
955 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_batch";
956 $sql2 .=
" WHERE fk_product_stock = ".((int) $obj->psrowid);
959 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
960 $resql2 = $db->query($sql2);
967 if ($methodtofix ==
'updatebatch') {
969 print
' -> Insert qty '.($obj->reel - $obj->reelbatch).
' with lot 000000 linked to fk_product_stock='.$obj->psrowid;
970 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_batch(fk_product_stock, batch, qty)";
971 $sql2 .=
"VALUES(".((int) $obj->psrowid).
", '000000', ".((float) ($obj->reel - $obj->reelbatch)).
")";
974 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
975 $resql2 = $db->query($sql2);
984 if ($methodtofix ==
'updatestock') {
986 print
' -> Update qty of product_stock with qty = '.($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
' for ps.rowid = '.((
int) $obj->psrowid);
987 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"product_stock";
988 $sql2 .=
" SET reel = ".($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
" WHERE rowid = ".((
int) $obj->psrowid);
991 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
996 $resql2 = $db->query($sql2);
999 $sql3 =
'UPDATE '.MAIN_DB_PREFIX.
'product p SET p.stock= (SELECT SUM(ps.reel) FROM '.MAIN_DB_PREFIX.
'product_stock ps WHERE ps.fk_product = p.rowid)';
1000 $resql3 = $db->query($sql3);
1025 print
'<tr><td colspan="2">Nothing to do</td></tr>';
1034if ($ok &&
GETPOST(
'clean_product_stock_negative_if_batch',
'alpha')) {
1035 print
'<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
1037 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
1038 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"product_stock as ps, ".MAIN_DB_PREFIX.
"product_batch as pb";
1039 $sql .=
" WHERE p.rowid = ps.fk_product AND ps.rowid = pb.fk_product_stock";
1040 $sql .=
" AND p.tobatch > 0";
1041 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
1042 $sql .=
" HAVING reel != SUM(pb.qty)";
1043 $resql = $db->query($sql);
1045 $num = $db->num_rows($resql);
1050 $obj = $db->fetch_object($resql);
1051 print
'<tr><td>'.$obj->rowid.
'-'.$obj->ref.
'-'.$obj->fk_entrepot.
' -> '.$obj->psrowid.
': '.$obj->reel.
' != '.$obj->reelbatch;
1060if ($ok &&
GETPOST(
'set_empty_time_spent_amount',
'alpha')) {
1061 print
'<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>';
1063 $sql =
"SELECT COUNT(ptt.rowid) as nb, u.rowid as user_id, u.login, u.thm as user_thm";
1064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"user as u";
1065 $sql .=
" WHERE ptt.fk_user = u.rowid";
1066 $sql .=
" AND ptt.thm IS NULL and u.thm > 0";
1067 $sql .=
" GROUP BY u.rowid, u.login, u.thm";
1069 $resql = $db->query($sql);
1071 $num = $db->num_rows($resql);
1076 $obj = $db->fetch_object($resql);
1077 print
'<tr><td>'.$obj->login.
'-'.$obj->user_id.
' ('.$obj->nb.
' lines to fix) -> '.$obj->user_thm;
1081 if (
GETPOST(
'set_empty_time_spent_amount') ==
'confirmed') {
1082 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time";
1083 $sql2 .=
" SET thm = ".$obj->user_thm.
" WHERE thm IS NULL AND fk_user = ".((int) $obj->user_id);
1084 $resql2 = $db->query($sql2);
1106 print
'<tr><td>No time spent with empty line on users with a hourly rate defined</td></tr>';
1115if ($ok &&
GETPOST(
'force_disable_of_modules_not_found',
'alpha')) {
1116 print
'<tr><td colspan="2"><br>*** Force modules not found physicaly to be disabled (only modules adding js, css or hooks can be detected as removed physicaly)</td></tr>';
1118 $arraylistofkey = array(
'hooks',
'js',
'css');
1120 foreach ($arraylistofkey as $key) {
1121 $sql =
"SELECT DISTINCT name, value";
1122 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
1123 $sql .=
" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key).
"'";
1124 $sql .=
" ORDER BY name";
1126 $resql = $db->query($sql);
1128 $num = $db->num_rows($resql);
1132 $obj = $db->fetch_object($resql);
1133 $constantname = $obj->name;
1141 if (preg_match(
'/MAIN_MODULE_(.*)_'.strtoupper($key).
'/i', $constantname, $reg)) {
1142 $name = strtolower($reg[1]);
1148 if ($key ==
'hooks') {
1149 $reloffile = $name.
'/class/actions_'.$name.
'.class.php';
1152 $value = $obj->value;
1153 $valuearray = (array) json_decode($value);
1154 $reloffile = $valuearray[0];
1155 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1157 if ($key ==
'css') {
1158 $value = $obj->value;
1159 $valuearray = (array) json_decode($value);
1160 if ($value && (!is_array($valuearray) || count($valuearray) == 0)) {
1161 $valuearray = array();
1162 $valuearray[0] = $value;
1164 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1179 print
' - File of '.$key.
' ('.$reloffile.
') NOT found, we disable the module.';
1180 if (
GETPOST(
'force_disable_of_modules_not_found') ==
'confirmed') {
1181 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"_".strtoupper($key).
"'";
1182 $resql2 = $db->query($sql2);
1187 $sql3 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"'";
1188 $resql3 = $db->query($sql3);
1193 print
' - <span class="warning">Cleaned</span>';
1196 print
' - <span class="warning">Canceled (test mode)</span>';
1199 print
' - File of '.$key.
' ('.$reloffile.
') found, we do nothing.';
1219 print
'<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).
'</td></tr>';
1229if ($ok &&
GETPOST(
'clean_perm_table',
'alpha')) {
1230 print
'<tr><td colspan="2"><br>*** Clean table user_rights from lines of external modules no more enabled</td></tr>';
1233 foreach ($conf->modules as $key => $val) {
1234 $listofmods .= ($listofmods ?
',' :
'').
"'".$db->escape($val).
"'";
1237 $sql =
"SELECT id, libelle as label, module from ".MAIN_DB_PREFIX.
"rights_def WHERE module NOT IN (".$db->sanitize($listofmods, 1).
") AND id > 100000";
1239 $resql = $db->query($sql);
1241 $num = $db->num_rows($resql);
1245 $obj = $db->fetch_object($resql);
1247 print
'<tr><td>Found line with id '.$obj->id.
', label "'.$obj->label.
'" of module "'.$obj->module.
'" to delete';
1248 if (
GETPOST(
'clean_perm_table',
'alpha') ==
'confirmed') {
1249 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def WHERE id = ".((int) $obj->id);
1250 $resqldelete = $db->query($sqldelete);
1251 if (!$resqldelete) {
1261 print
'<tr><td>No lines of a disabled external module (with id > 100000) found into table rights_def</td></tr>';
1271if ($ok &&
GETPOST(
'force_utf8_on_tables',
'alpha')) {
1272 print
'<tr><td colspan="2"><br>*** Force page code and collation of tables into utf8/utf8_unicode_ci and row_format=dynamic (for mysql/mariadb only)</td></tr>';
1274 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1275 $force_utf8_on_tables =
GETPOST(
'force_utf8_on_tables',
'alpha');
1277 $listoftables = $db->DDLListTablesFull($db->database_name);
1280 if ($force_utf8_on_tables ==
'confirmed') {
1281 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1282 print
'<!-- '.$sql.
' -->';
1283 $resql = $db->query($sql);
1286 foreach ($listoftables as $table) {
1288 if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1291 if ($table[1] ==
'VIEW') {
1292 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1296 print
'<tr><td colspan="2">';
1298 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1299 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
1300 print
'<!-- '.$sql1.
' -->';
1301 print
'<!-- '.$sql2.
' -->';
1302 if ($force_utf8_on_tables ==
'confirmed') {
1303 $resql1 = $db->query($sql1);
1305 $resql2 = $db->query($sql2);
1309 print
' - Done ('.(($resql1 && $resql2) ?
'OK' :
'KO').
')';
1311 print
' - Disabled';
1317 if ($force_utf8_on_tables ==
'confirmed') {
1318 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1319 print
'<!-- '.$sql.
' -->';
1320 $resql = $db->query($sql);
1323 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1328if ($ok &&
GETPOST(
'force_utf8mb4_on_tables',
'alpha')) {
1329 print
'<tr><td colspan="2"><br>*** Force page code and collation of tables into utf8mb4/utf8mb4_unicode_ci (for mysql/mariadb only)</td></tr>';
1331 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1332 $force_utf8mb4_on_tables =
GETPOST(
'force_utf8mb4_on_tables',
'alpha');
1334 $listoftables = $db->DDLListTablesFull($db->database_name);
1337 if ($force_utf8mb4_on_tables ==
'confirmed') {
1338 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1339 print
'<!-- '.$sql.
' -->';
1340 $resql = $db->query($sql);
1343 foreach ($listoftables as $table) {
1345 if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1348 if ($table[1] ==
'VIEW') {
1349 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1353 print
'<tr><td colspan="2">';
1355 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1356 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
1357 print
'<!-- '.$sql1.
' -->';
1358 print
'<!-- '.$sql2.
' -->';
1359 if ($force_utf8mb4_on_tables ==
'confirmed') {
1360 $resql1 = $db->query($sql1);
1362 $resql2 = $db->query($sql2);
1366 print
' - Done ('.(($resql1 && $resql2) ?
'OK' :
'KO').
')';
1368 print
' - Disabled';
1376 if ($force_utf8mb4_on_tables ==
'confirmed') {
1377 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1378 print
'<!-- '.$sql.
' -->';
1379 $resql = $db->query($sql);
1382 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1386if ($ok &&
GETPOST(
'force_collation_from_conf_on_tables',
'alpha')) {
1387 print
'<tr><td colspan="2"><br>*** Force page code and collation of tables into '.$conf->db->character_set.
'/'.$conf->db->dolibarr_main_db_collation.
' and row_format=dynamic (for mysql/mariadb only)</td></tr>';
1389 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1390 $force_collation_from_conf_on_tables =
GETPOST(
'force_collation_from_conf_on_tables',
'alpha');
1392 $listoftables = $db->DDLListTablesFull($db->database_name);
1395 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1396 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1397 print
'<!-- '.$sql.
' -->';
1398 $resql = $db->query($sql);
1401 foreach ($listoftables as $table) {
1403 if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1406 if ($table[1] ==
'VIEW') {
1407 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1411 print
'<tr><td colspan="2">';
1413 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1414 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET ".$conf->db->character_set.
" COLLATE ".$conf->db->dolibarr_main_db_collation;
1415 print
'<!-- '.$sql1.
' -->';
1416 print
'<!-- '.$sql2.
' -->';
1417 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1418 $resql1 = $db->query($sql1);
1420 $resql2 = $db->query($sql2);
1424 print
' - Done ('.(($resql1 && $resql2) ?
'OK' :
'KO').
')';
1426 print
' - Disabled';
1432 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1433 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1434 print
'<!-- '.$sql.
' -->';
1435 $resql = $db->query($sql);
1438 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1443if ($ok &&
GETPOST(
'rebuild_sequences',
'alpha')) {
1444 print
'<tr><td colspan="2"><br>*** Force to rebuild sequences (for postgresql only)</td></tr>';
1446 if ($db->type ==
"pgsql") {
1447 $rebuild_sequence =
GETPOST(
'rebuild_sequences',
'alpha');
1449 if ($rebuild_sequence ==
'confirmed') {
1450 $sql =
"SELECT dol_util_rebuild_sequences();";
1451 print
'<!-- '.$sql.
' -->';
1452 $resql = $db->query($sql);
1455 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1460if ($ok &&
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines')) {
1484 $repair_link_dispatch_lines_supplier_order_lines =
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines',
'alpha');
1487 echo
'<tr><th>Repair llx_commande_fournisseur_dispatch.fk_commandefourndet</th></tr>';
1488 echo
'<tr><td>Repair in progress. This may take a while.</td></tr>';
1490 $sql_dispatch =
'SELECT * FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0';
1492 $resql_dispatch = $db->query($sql_dispatch);
1493 $n_processed_rows = 0;
1495 if ($resql_dispatch) {
1496 if ($db->num_rows($resql_dispatch) == 0) {
1497 echo
'<tr><td>Nothing to do.</td></tr>';
1500 while ($obj_dispatch = $db->fetch_object($resql_dispatch)) {
1501 $sql_line =
'SELECT line.rowid, line.qty FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet AS line';
1502 $sql_line .=
' WHERE line.fk_commande = '.((int) $obj_dispatch->fk_commande);
1503 $sql_line .=
' AND line.fk_product = '.((int) $obj_dispatch->fk_product);
1504 $resql_line = $db->query($sql_line);
1510 $remaining_qty = $obj_dispatch->qty;
1511 $first_iteration =
true;
1513 echo
'<tr><td>Unable to find a matching supplier order line for dispatch #'.$obj_dispatch->rowid.
'</td></tr>';
1514 $errors[] = $sql_line;
1515 $n_processed_rows++;
1518 if ($db->num_rows($resql_line) == 0) {
1521 while ($obj_line = $db->fetch_object($resql_line)) {
1522 if (!$remaining_qty) {
1525 if (!$obj_line->rowid) {
1528 $qty_for_line = min($remaining_qty, $obj_line->qty);
1529 if ($first_iteration) {
1530 $sql_attach =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1531 $sql_attach .=
' SET fk_commandefourndet = '.((int) $obj_line->rowid).
', qty = '.((float) $qty_for_line);
1532 $sql_attach .=
' WHERE rowid = '.((int) $obj_dispatch->rowid);
1533 $first_iteration =
false;
1535 $sql_attach_values = array(
1536 ((
int) $obj_dispatch->fk_commande),
1537 ((
int) $obj_dispatch->fk_product),
1538 ((
int) $obj_line->rowid),
1539 ((
float) $qty_for_line),
1540 ((
int) $obj_dispatch->fk_entrepot),
1541 ((
int) $obj_dispatch->fk_user),
1542 $obj_dispatch->datec ?
"'".$db->idate($db->jdate($obj_dispatch->datec)).
"'" :
'NULL',
1543 $obj_dispatch->comment ?
"'".$db->escape($obj_dispatch->comment).
"'" :
'NULL',
1544 $obj_dispatch->
status ? ((int) $obj_dispatch->
status) :
'NULL',
1545 $obj_dispatch->tms ?
"'".$db->idate($db->jdate($obj_dispatch->tms)).
"'" :
'NULL',
1546 $obj_dispatch->batch ?
"'".$db->escape($obj_dispatch->batch).
"'" :
'NULL',
1547 $obj_dispatch->eatby ?
"'".$db->escape($obj_dispatch->eatby).
"'" :
'NULL',
1548 $obj_dispatch->sellby ?
"'".$db->escape($obj_dispatch->sellby).
"'" :
'NULL'
1550 $sql_attach_values = join(
', ', $sql_attach_values);
1552 $sql_attach =
'INSERT INTO '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1553 $sql_attach .=
' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)';
1554 $sql_attach .=
" VALUES (".$sql_attach_values.
")";
1557 if ($repair_link_dispatch_lines_supplier_order_lines ==
'confirmed') {
1558 $resql_attach = $db->query($sql_attach);
1560 $resql_attach =
true;
1563 if ($resql_attach) {
1564 $remaining_qty -= $qty_for_line;
1566 $errors[] = $sql_attach;
1569 $first_iteration =
false;
1571 $n_processed_rows++;
1574 if (!($n_processed_rows & 0xff)) {
1575 echo
'<tr><td>Processed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1581 echo
'<tr><td>Unable to find any dispatch without an fk_commandefourndet.'.
"</td></tr>\n";
1582 echo $sql_dispatch.
"\n";
1584 echo
'<tr><td>Fixed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1585 echo
'<tr><td>DONE.'.
"</td></tr>\n";
1587 if (count($errors)) {
1589 echo
'<tr><td>The transaction was rolled back due to errors: nothing was changed by the script.</td></tr>';
1595 echo
'<tr><td><h3>SQL queries with errors:</h3></tr></td>';
1596 echo
'<tr><td>'.join(
'</td></tr><tr><td>', $errors).
'</td></tr>';
1600if ($ok &&
GETPOST(
'repair_supplier_order_duplicate_ref')) {
1601 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.commande.class.php';
1602 include_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1609 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX .
"commande_fournisseur";
1610 $sql .=
" WHERE ref IN (SELECT cf.ref FROM " . MAIN_DB_PREFIX .
"commande_fournisseur cf GROUP BY cf.ref, cf.entity HAVING COUNT(cf.rowid) > 1)";
1613 $duplicateSupplierOrders = [];
1614 $resql = $db->query($sql);
1616 while ($rawSupplierOrder = $db->fetch_object($resql)) {
1618 $supplierOrder->setVarsFromFetchObj($rawSupplierOrder);
1620 $duplicateSupplierOrders[$rawSupplierOrder->ref] [] = $supplierOrder;
1627 foreach ($duplicateSupplierOrders as $ref => $supplierOrders) {
1629 foreach (array_slice($supplierOrders, 1) as $supplierOrder) {
1632 $soc->fetch($supplierOrder->fourn_id);
1634 $newRef = $supplierOrder->getNextNumRef($soc);
1636 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"commande_fournisseur cf SET cf.ref = '" . $db->escape($newRef) .
"' WHERE cf.rowid = " . (int) $supplierOrder->id;
1637 if (!$db->query($sql)) {
1654if (empty($actiondone)) {
1655 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
1659 print
'<div class="center" style="padding-top: 10px"><a href="../index.php?mainmenu=home&leftmenu=home'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
1660 print $langs->trans(
"GoToDolibarr");
1663 print
'<div class="center warning" style="padding-top: 10px">';
1664 print $langs->trans(
"SetAtLeastOneOptionAsUrlParameter");
1671if ($db->connected) {
1676if (!$ok && isset($argv[1])) {
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
Classe permettant la gestion des paiements des charges La tva collectee n'est calculee que sur les fa...
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage contracts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_is_file($pathoffile)
Return if path is a file.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
clean_data_ecm_directories()
Clean data into ecm_directories table.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.