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";
101print
'Option rebuild_sequences, for postgresql only (\'test\' or \'confirmed\') is '.(GETPOST(
'rebuild_sequences',
'alpha') ?
GETPOST(
'rebuild_sequences',
'alpha') :
'undefined').
'<br>'.
"\n";
104print
'<table cellspacing="0" cellpadding="1" border="0" width="100%">';
108if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
109 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
110 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
111 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
112 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
113 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
115 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
120$conf->db->type = $dolibarr_main_db_type;
121$conf->db->host = $dolibarr_main_db_host;
122$conf->db->port = $dolibarr_main_db_port;
123$conf->db->name = $dolibarr_main_db_name;
124$conf->db->user = $dolibarr_main_db_user;
125$conf->db->pass = $dolibarr_main_db_pass;
128$conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption :
'';
129$conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
131$db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
134 print
'<tr><td class="nowrap">';
135 print $langs->trans(
"ServerConnection").
" : $dolibarr_main_db_host</td><td class=\"right\">".$langs->trans(
"OK").
"</td></tr>";
136 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ServerConnection").
": ".$dolibarr_main_db_host.$langs->transnoentities(
"OK"));
139 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
"</td><td class=\"right\">".$langs->transnoentities(
"Error").
"</td></tr>";
140 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
145 if ($db->database_selected) {
146 print
'<tr><td class="nowrap">';
147 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
"</td><td class=\"right\">".$langs->trans(
"OK").
"</td></tr>";
151 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
"</td><td class=\"right\">".$langs->trans(
"Error").
"</td></tr>";
152 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
159 $version = $db->getVersion();
160 $versionarray = $db->getVersionArray();
161 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
162 print
'<td class="right">'.$version.
'</td></tr>';
167$conf->setValues($db);
169if (defined(
'SYSLOG_FILE')) {
170 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
172$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
177$oneoptionset = (
GETPOST(
'standard',
'alpha') ||
GETPOST(
'restore_thirdparties_logos',
'alpha') ||
GETPOST(
'clean_linked_elements',
'alpha') ||
GETPOST(
'clean_menus',
'alpha')
178 ||
GETPOST(
'clean_orphelin_dir',
'alpha') ||
GETPOST(
'clean_product_stock_batch',
'alpha') ||
GETPOST(
'set_empty_time_spent_amount',
'alpha') ||
GETPOST(
'rebuild_product_thumbs',
'alpha')
179 ||
GETPOST(
'clean_perm_table',
'alpha')
180 ||
GETPOST(
'force_disable_of_modules_not_found',
'alpha')
181 ||
GETPOST(
'force_utf8_on_tables',
'alpha') ||
GETPOST(
'force_utf8mb4_on_tables',
'alpha')
182 ||
GETPOST(
'rebuild_sequences',
'alpha'));
184if ($ok && $oneoptionset) {
186 print
'<tr><td colspan="2">'.$langs->trans(
"PleaseBePatient").
'<br><br></td></tr>';
192if ($ok &&
GETPOST(
'standard',
'alpha')) {
193 $dir =
"mysql/migration/";
200 $filesindir = array();
201 $handle = opendir($dir);
202 if (is_resource($handle)) {
203 while (($file = readdir($handle)) !==
false) {
204 if (preg_match(
'/\.sql$/i', $file)) {
205 $filesindir[] = $file;
211 foreach ($filesindir as $file) {
212 if (preg_match(
'/repair/i', $file)) {
218 foreach ($filelist as $file) {
219 print
'<tr><td class="nowrap">*** ';
220 print $langs->trans(
"Script").
'</td><td class="right">'.$file.
'</td></tr>';
222 $name = substr($file, 0,
dol_strlen($file) - 4);
225 $ok =
run_sql($dir.$file, 0,
'', 1);
232if ($ok &&
GETPOST(
'standard',
'alpha')) {
236 $listofmodulesextra = array(
'societe'=>
'societe',
'adherent'=>
'adherent',
'product'=>
'product',
237 'socpeople'=>
'socpeople',
'propal'=>
'propal',
'commande'=>
'commande',
238 'facture'=>
'facture',
'facturedet'=>
'facturedet',
'facture_rec'=>
'facture_rec',
'facturedet_rec'=>
'facturedet_rec',
239 'supplier_proposal'=>
'supplier_proposal',
'commande_fournisseur'=>
'commande_fournisseur',
240 'facture_fourn'=>
'facture_fourn',
'facture_fourn_rec'=>
'facture_fourn_rec',
'facture_fourn_det'=>
'facture_fourn_det',
'facture_fourn_det_rec'=>
'facture_fourn_det_rec',
241 'fichinter'=>
'fichinter',
'fichinterdet'=>
'fichinterdet',
242 'inventory'=>
'inventory',
243 'actioncomm'=>
'actioncomm',
'bom_bom'=>
'bom_bom',
'mrp_mo'=>
'mrp_mo',
244 'adherent_type'=>
'adherent_type',
'user'=>
'user',
'partnership'=>
'partnership',
'projet'=>
'projet',
'projet_task'=>
'projet_task',
'ticket'=>
'ticket');
247 print
'<tr><td colspan="2"><br>*** Check fields into extra table structure match table of definition. If not add column into table</td></tr>';
248 foreach ($listofmodulesextra as $tablename => $elementtype) {
250 $tableextra = MAIN_DB_PREFIX.$tablename.
'_extrafields';
253 $arrayoffieldsdesc = $extrafields->fetch_name_optionals_label($elementtype);
256 $arrayoffieldsfound = array();
257 $resql = $db->DDLDescTable($tableextra);
259 print
'<tr><td>Check availability of extra field for '.$tableextra;
261 while ($obj = $db->fetch_object($resql)) {
262 $fieldname = $fieldtype =
'';
263 if (preg_match(
'/mysql/', $db->type)) {
264 $fieldname = $obj->Field;
265 $fieldtype = $obj->Type;
267 $fieldname = isset($obj->Key) ? $obj->Key : $obj->attname;
268 $fieldtype = isset($obj->Type) ? $obj->Type :
'varchar';
271 if (empty($fieldname)) {
274 if (in_array($fieldname, array(
'rowid',
'tms',
'fk_object',
'import_key'))) {
277 $arrayoffieldsfound[$fieldname] = array(
'type'=>$fieldtype);
279 print
' - Found '.count($arrayoffieldsfound).
' fields into table';
280 if (count($arrayoffieldsfound) > 0) {
281 print
' <span class="opacitymedium">('.join(
', ', array_keys($arrayoffieldsfound)).
')</span>';
286 foreach ($arrayoffieldsdesc as $code => $label) {
287 if (!in_array($code, array_keys($arrayoffieldsfound))) {
288 print
'Found field '.$code.
' declared into '.MAIN_DB_PREFIX.
'extrafields table but not found into desc of table '.$tableextra.
" -> ";
289 $type = $extrafields->attributes[$elementtype][
'type'][$code]; $length = $extrafields->attributes[$elementtype][
'size'][$code]; $attribute =
''; $default =
''; $extra =
''; $null =
'null';
291 if ($type ==
'boolean') {
294 } elseif ($type ==
'price') {
297 } elseif ($type ==
'phone') {
300 } elseif ($type ==
'mail') {
303 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
306 } elseif ($type ==
'link') {
317 'attribute'=>$attribute,
325 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
326 $result = $db->DDLAddField($tableextra, $code, $field_desc,
"");
329 print
"KO ".$db->lasterror.
"<br>\n";
334 print
' - Mode test, no column added.';
339 print
"</td><td> </td></tr>\n";
341 print
'<tr><td>Table '.$tableextra.
' is not found</td><td></td></tr>'.
"\n";
348if ($ok &&
GETPOST(
'standard',
'alpha')) {
354if ($ok &&
GETPOST(
'standard',
'alpha')) {
355 print
'<tr><td colspan="2"><br>*** Clean constant record of modules not enabled</td></tr>';
357 $sql =
"SELECT name, entity, value";
358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
359 $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'";
360 $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'";
361 $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_%'";
362 $sql .=
" OR name LIKE 'MAIN_MODULE_%_MODULEFOREXTERNAL'";
363 $sql .=
" ORDER BY name, entity";
365 $resql = $db->query($sql);
367 $num = $db->num_rows($resql);
374 $obj = $db->fetch_object($resql);
377 if (preg_match(
'/MAIN_MODULE_([^_]+)_(.+)/i', $obj->name, $reg)) {
381 $sql2 =
"SELECT COUNT(*) as nb";
382 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
383 $sql2 .=
" WHERE name = 'MAIN_MODULE_".$name.
"'";
384 $sql2 .=
" AND entity = ".((int) $obj->entity);
385 $resql2 = $db->query($sql2);
387 $obj2 = $db->fetch_object($resql2);
388 if ($obj2 && $obj2->nb == 0) {
390 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = '".$db->escape($obj->name).
"' AND entity = ".((int) $obj->entity);
392 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
393 $db->query($sqldelete);
395 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>';
397 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>';
417if ($ok &&
GETPOST(
'standard',
'alpha')) {
418 print
'<tr><td colspan="2"><br>*** Clean definition of boxes of modules not enabled</td></tr>';
420 $sql =
"SELECT file, entity FROM ".MAIN_DB_PREFIX.
"boxes_def";
421 $sql .=
" WHERE file like '%@%'";
423 $resql = $db->query($sql);
425 $num = $db->num_rows($resql);
432 $obj = $db->fetch_object($resql);
435 if (preg_match(
'/^(.+)@(.+)$/i', $obj->file, $reg)) {
439 $sql2 =
"SELECT COUNT(*) as nb";
440 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
441 $sql2 .=
" WHERE name = 'MAIN_MODULE_".strtoupper($module).
"'";
442 $sql2 .=
" AND entity = ".((int) $obj->entity);
443 $sql2 .=
" AND value <> 0";
444 $resql2 = $db->query($sql2);
446 $obj2 = $db->fetch_object($resql2);
447 if ($obj2 && $obj2->nb == 0) {
449 $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).
")";
450 $sqldeleteb =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE file = '".$db->escape($obj->file).
"' AND entity = ".((int) $obj->entity);
452 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
453 $db->query($sqldeletea);
454 $db->query($sqldeleteb);
456 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>';
458 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>';
476if ($ok &&
GETPOST(
'restore_thirdparties_logos')) {
481 print
'<tr><td colspan="2"><br>*** Restore thirdparties logo<br>';
483 $sql =
"SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX.
"societe as s ORDER BY s.nom";
484 $resql = $db->query($sql);
486 $num = $db->num_rows($resql);
490 $obj = $db->fetch_object($resql);
498 $tmp = explode(
'.', $obj->logo);
500 if (isset($tmp[1])) {
505 $filetotest = $dolibarr_main_data_root.
'/societe/logos/'.$name.$ext;
506 $filetotestsmall = $dolibarr_main_data_root.
'/societe/logos/thumbs/'.$name.
'_small'.$ext;
508 print
'Check thirdparty '.$obj->rowid.
' name='.$obj->name.
' logo='.$obj->logo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
510 $filetarget = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/'.$name.$ext;
511 $filetargetsmall = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs/'.$name.
'_small'.$ext;
514 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
515 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos');
518 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
519 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
520 dol_copy($filetotest, $filetarget,
'', 0);
526 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
527 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs');
529 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
530 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
531 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
550if ($ok &&
GETPOST(
'restore_user_pictures',
'alpha')) {
555 print
'<tr><td colspan="2"><br>*** Restore user pictures<br>';
557 $sql =
"SELECT s.rowid, s.firstname, s.lastname, s.login, s.photo FROM ".MAIN_DB_PREFIX.
"user as s ORDER BY s.rowid";
558 $resql = $db->query($sql);
560 $num = $db->num_rows($resql);
564 $obj = $db->fetch_object($resql);
572 $tmp = explode(
'.', $obj->photo);
574 if (isset($tmp[1])) {
579 $filetotest = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/'.$name.$ext;
580 $filetotestsmall = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_small'.$ext;
581 $filetotestmini = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_mini'.$ext;
583 print
'Check user '.$obj->rowid.
' lastname='.$obj->lastname.
' firstname='.$obj->firstname.
' photo='.$obj->photo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
585 $filetarget = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/'.$name.$ext;
586 $filetargetsmall = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_small'.$ext;
587 $filetargetmini = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_mini'.$ext;
591 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
592 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid);
595 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
596 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
597 dol_copy($filetotest, $filetarget,
'', 0);
603 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
604 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
607 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
608 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
609 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
615 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
616 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
619 print
" -> Copy file ".$filetotestmini.
" -> ".$filetargetmini.
"<br>\n";
620 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
621 dol_copy($filetotestmini, $filetargetmini,
'', 0);
639if ($ok &&
GETPOST(
'rebuild_product_thumbs',
'alpha')) {
641 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
643 print
'<tr><td colspan="2"><br>*** Rebuild product thumbs<br>';
645 $sql =
"SELECT s.rowid, s.ref FROM ".MAIN_DB_PREFIX.
"product as s ORDER BY s.ref";
646 $resql = $db->query($sql);
648 $num = $db->num_rows($resql);
652 $obj = $db->fetch_object($resql);
654 if (!empty($obj->ref)) {
655 $files =
dol_dir_list($dolibarr_main_data_root.
'/produit/'.$obj->ref,
'files', 0);
656 foreach ($files as $file) {
659 $imgThumbSmall =
'notbuild';
660 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
662 $imgThumbSmall =
vignette($file[
'fullname'], $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
664 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbSmall.
" maxwidthsmall=".$maxwidthsmall.
" maxheightsmall=".$maxheightsmall.
"<br>\n";
665 $imgThumbMini =
'notbuild';
666 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
669 $imgThumbMini =
vignette($file[
'fullname'], $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
671 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbMini.
" maxwidthmini=".$maxwidthmini.
" maxheightmini=".$maxheightmini.
"<br>\n";
687if ($ok &&
GETPOST(
'clean_linked_elements',
'alpha')) {
688 print
'<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>';
690 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'commande').
"</td></tr>\n";
693 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'facture').
"</td></tr>\n";
696 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'facture').
"</td></tr>\n";
699 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'shipping').
"</td></tr>\n";
702 print
'<tr><td colspan="2">'.checkLinkedElements(
'shipping',
'delivery').
"</td></tr>\n";
705 print
'<tr><td colspan="2">'.checkLinkedElements(
'order_supplier',
'invoice_supplier').
"</td></tr>\n";
710if ($ok &&
GETPOST(
'clean_menus',
'alpha')) {
711 print
'<tr><td colspan="2"><br>*** Clean menu entries coming from disabled modules</td></tr>';
713 $sql =
"SELECT rowid, module";
714 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as c";
715 $sql .=
" WHERE module IS NOT NULL AND module <> ''";
716 $sql .=
" ORDER BY module";
718 $resql = $db->query($sql);
720 $num = $db->num_rows($resql);
724 $obj = $db->fetch_object($resql);
726 $modulecond = $obj->module;
727 $modulecondarray = explode(
'|', $obj->module);
736 foreach ($modulecondarray as $tmpname) {
737 if ($tmpname ==
'margins') {
742 if (!empty($conf->$tmpname)) {
743 $result = $conf->$tmpname->enabled;
750 if (!$moduleok && $modulecond) {
751 print
' - Module condition '.$modulecond.
' seems ko, we delete menu entry.';
752 if (
GETPOST(
'clean_menus') ==
'confirmed') {
753 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu WHERE module = '".$db->escape($modulecond).
"'";
754 $resql2 = $db->query($sql2);
759 print
' - <span class="warning">Cleaned</span>';
762 print
' - <span class="warning">Canceled (test mode)</span>';
765 print
' - Module condition '.$modulecond.
' is ok, we do nothing.';
784 print
'<tr><td>No menu entries of disabled menus found</td></tr>';
794if ($ok &&
GETPOST(
'clean_orphelin_dir',
'alpha')) {
795 $listmodulepart = array(
'company',
'invoice',
'invoice_supplier',
'propal',
'order',
'order_supplier',
'contract',
'tax');
796 foreach ($listmodulepart as $modulepart) {
797 $filearray = array();
798 $upload_dir = isset($conf->$modulepart->dir_output) ? $conf->$modulepart->dir_output :
'';
799 if ($modulepart ==
'company') {
800 $upload_dir = $conf->societe->dir_output;
802 if ($modulepart ==
'invoice') {
803 $upload_dir = $conf->facture->dir_output;
805 if ($modulepart ==
'invoice_supplier') {
806 $upload_dir = $conf->fournisseur->facture->dir_output;
808 if ($modulepart ==
'order') {
809 $upload_dir = $conf->commande->dir_output;
811 if ($modulepart ==
'order_supplier') {
812 $upload_dir = $conf->fournisseur->commande->dir_output;
814 if ($modulepart ==
'contract') {
815 $upload_dir = $conf->contrat->dir_output;
818 if (empty($upload_dir)) {
822 print
'<tr><td colspan="2"><br>*** Clean orphelins files into files '.$upload_dir.
'</td></tr>';
824 $filearray =
dol_dir_list($upload_dir,
"files", 1,
'', array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$'),
'', SORT_DESC, 1,
true);
827 if ($modulepart ==
'company') {
828 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
829 $object_instance =
new Societe($db);
831 if ($modulepart ==
'invoice') {
832 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
833 $object_instance =
new Facture($db);
834 } elseif ($modulepart ==
'invoice_supplier') {
835 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
837 } elseif ($modulepart ==
'propal') {
838 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
839 $object_instance =
new Propal($db);
840 } elseif ($modulepart ==
'order') {
841 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
842 $object_instance =
new Commande($db);
843 } elseif ($modulepart ==
'order_supplier') {
844 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
846 } elseif ($modulepart ==
'contract') {
847 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
848 $object_instance =
new Contrat($db);
849 } elseif ($modulepart ==
'tax') {
850 include_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
854 foreach ($filearray as $key => $file) {
855 if (!is_dir($file[
'name'])
856 && $file[
'name'] !=
'.'
857 && $file[
'name'] !=
'..'
858 && $file[
'name'] !=
'CVS'
861 $relativefile = preg_replace(
'/'.preg_quote($upload_dir.
'/',
'/').
'/',
'', $file[
'fullname']);
864 $id = 0; $ref =
''; $object_instance->id = 0; $object_instance->ref =
''; $label =
'';
867 if ($modulepart ==
'invoice') {
868 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = $reg[1];
870 if ($modulepart ==
'invoice_supplier') {
871 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg); $id = empty($reg[1]) ?
'' : $reg[1];
873 if ($modulepart ==
'propal') {
874 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = $reg[1];
876 if ($modulepart ==
'order') {
877 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = $reg[1];
879 if ($modulepart ==
'order_supplier') {
880 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = $reg[1];
882 if ($modulepart ==
'contract') {
883 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg); $ref = $reg[1];
885 if ($modulepart ==
'tax') {
886 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg); $id = $reg[1];
891 $result = $object_instance->fetch($id, $ref);
895 print
'<tr><td colspan="2">';
896 print
'Delete orphelins file '.$file[
'fullname'].
'<br>';
897 if (
GETPOST(
'clean_orphelin_dir',
'alpha') ==
'confirmed') {
902 } elseif ($result < 0) {
903 print
'Error in '.get_class($object_instance).
'.fetch of id'.$id.
' ref='.$ref.
', result='.$result.
'<br>';
912if ($ok &&
GETPOST(
'clean_product_stock_batch',
'alpha')) {
913 $methodtofix =
GETPOST(
'methodtofix',
'alpha') ?
GETPOST(
'methodtofix',
'alpha') :
'updatestock';
915 print
'<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
917 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
918 $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";
919 $sql .=
" WHERE p.rowid = ps.fk_product";
920 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
921 $sql .=
" HAVING (SUM(pb.qty) IS NOT NULL AND reel != SUM(pb.qty)) OR (SUM(pb.qty) IS NULL AND p.tobatch > 0)";
923 $resql = $db->query($sql);
925 $num = $db->num_rows($resql);
930 $obj = $db->fetch_object($resql);
931 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)';
934 if ($obj->reel != $obj->reelbatch) {
935 if (empty($obj->tobatch)) {
937 print
' -> Delete qty '.$obj->reelbatch.
' for any lot linked to fk_product_stock='.$obj->psrowid;
938 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_batch";
939 $sql2 .=
" WHERE fk_product_stock = ".((int) $obj->psrowid);
942 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
943 $resql2 = $db->query($sql2);
950 if ($methodtofix ==
'updatebatch') {
952 print
' -> Insert qty '.($obj->reel - $obj->reelbatch).
' with lot 000000 linked to fk_product_stock='.$obj->psrowid;
953 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_batch(fk_product_stock, batch, qty)";
954 $sql2 .=
"VALUES(".((int) $obj->psrowid).
", '000000', ".((float) ($obj->reel - $obj->reelbatch)).
")";
957 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
958 $resql2 = $db->query($sql2);
967 if ($methodtofix ==
'updatestock') {
969 print
' -> Update qty of product_stock with qty = '.($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
' for ps.rowid = '.((
int) $obj->psrowid);
970 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"product_stock";
971 $sql2 .=
" SET reel = ".($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
" WHERE rowid = ".((
int) $obj->psrowid);
974 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
979 $resql2 = $db->query($sql2);
982 $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)';
983 $resql3 = $db->query($sql3);
1008 print
'<tr><td colspan="2">Nothing to do</td></tr>';
1017if ($ok &&
GETPOST(
'clean_product_stock_negative_if_batch',
'alpha')) {
1018 print
'<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
1020 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
1021 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"product_stock as ps, ".MAIN_DB_PREFIX.
"product_batch as pb";
1022 $sql .=
" WHERE p.rowid = ps.fk_product AND ps.rowid = pb.fk_product_stock";
1023 $sql .=
" AND p.tobatch > 0";
1024 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
1025 $sql .=
" HAVING reel != SUM(pb.qty)";
1026 $resql = $db->query($sql);
1028 $num = $db->num_rows($resql);
1033 $obj = $db->fetch_object($resql);
1034 print
'<tr><td>'.$obj->rowid.
'-'.$obj->ref.
'-'.$obj->fk_entrepot.
' -> '.$obj->psrowid.
': '.$obj->reel.
' != '.$obj->reelbatch;
1043if ($ok &&
GETPOST(
'set_empty_time_spent_amount',
'alpha')) {
1044 print
'<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>';
1046 $sql =
"SELECT COUNT(ptt.rowid) as nb, u.rowid as user_id, u.login, u.thm as user_thm";
1047 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"user as u";
1048 $sql .=
" WHERE ptt.fk_user = u.rowid";
1049 $sql .=
" AND ptt.thm IS NULL and u.thm > 0";
1050 $sql .=
" GROUP BY u.rowid, u.login, u.thm";
1052 $resql = $db->query($sql);
1054 $num = $db->num_rows($resql);
1059 $obj = $db->fetch_object($resql);
1060 print
'<tr><td>'.$obj->login.
'-'.$obj->user_id.
' ('.$obj->nb.
' lines to fix) -> '.$obj->user_thm;
1064 if (
GETPOST(
'set_empty_time_spent_amount') ==
'confirmed') {
1065 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time";
1066 $sql2 .=
" SET thm = ".$obj->user_thm.
" WHERE thm IS NULL AND fk_user = ".((int) $obj->user_id);
1067 $resql2 = $db->query($sql2);
1089 print
'<tr><td>No time spent with empty line on users with a hourly rate defined</td></tr>';
1098if ($ok &&
GETPOST(
'force_disable_of_modules_not_found',
'alpha')) {
1099 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>';
1101 $arraylistofkey = array(
'hooks',
'js',
'css');
1103 foreach ($arraylistofkey as $key) {
1104 $sql =
"SELECT DISTINCT name, value";
1105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
1106 $sql .=
" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($key).
"'";
1107 $sql .=
" ORDER BY name";
1109 $resql = $db->query($sql);
1111 $num = $db->num_rows($resql);
1115 $obj = $db->fetch_object($resql);
1116 $constantname = $obj->name;
1124 if (preg_match(
'/MAIN_MODULE_(.*)_'.strtoupper($key).
'/i', $constantname, $reg)) {
1125 $name = strtolower($reg[1]);
1131 if ($key ==
'hooks') {
1132 $reloffile = $name.
'/class/actions_'.$name.
'.class.php';
1135 $value = $obj->value;
1136 $valuearray = (array) json_decode($value);
1137 $reloffile = $valuearray[0];
1138 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1140 if ($key ==
'css') {
1141 $value = $obj->value;
1142 $valuearray = (array) json_decode($value);
1143 if ($value && (!is_array($valuearray) || count($valuearray) == 0)) {
1144 $valuearray = array();
1145 $valuearray[0] = $value;
1147 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1162 print
' - File of '.$key.
' ('.$reloffile.
') NOT found, we disable the module.';
1163 if (
GETPOST(
'force_disable_of_modules_not_found') ==
'confirmed') {
1164 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"_".strtoupper($key).
"'";
1165 $resql2 = $db->query($sql2);
1170 $sql3 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"'";
1171 $resql3 = $db->query($sql3);
1176 print
' - <span class="warning">Cleaned</span>';
1179 print
' - <span class="warning">Canceled (test mode)</span>';
1182 print
' - File of '.$key.
' ('.$reloffile.
') found, we do nothing.';
1202 print
'<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).
'</td></tr>';
1212if ($ok &&
GETPOST(
'clean_perm_table',
'alpha')) {
1213 print
'<tr><td colspan="2"><br>*** Clean table user_rights from lines of external modules no more enabled</td></tr>';
1216 foreach ($conf->modules as $key => $val) {
1217 $listofmods .= ($listofmods ?
',' :
'').
"'".$db->escape($val).
"'";
1220 $sql =
"SELECT id, libelle as label, module from ".MAIN_DB_PREFIX.
"rights_def WHERE module NOT IN (".$db->sanitize($listofmods, 1).
") AND id > 100000";
1222 $resql = $db->query($sql);
1224 $num = $db->num_rows($resql);
1228 $obj = $db->fetch_object($resql);
1230 print
'<tr><td>Found line with id '.$obj->id.
', label "'.$obj->label.
'" of module "'.$obj->module.
'" to delete';
1231 if (
GETPOST(
'clean_perm_table',
'alpha') ==
'confirmed') {
1232 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def WHERE id = ".((int) $obj->id);
1233 $resqldelete = $db->query($sqldelete);
1234 if (!$resqldelete) {
1244 print
'<tr><td>No lines of a disabled external module (with id > 100000) found into table rights_def</td></tr>';
1254if ($ok &&
GETPOST(
'force_utf8_on_tables',
'alpha')) {
1255 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>';
1257 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1258 $force_utf8_on_tables =
GETPOST(
'force_utf8_on_tables',
'alpha');
1260 $listoftables = $db->DDLListTablesFull($db->database_name);
1263 if ($force_utf8_on_tables ==
'confirmed') {
1264 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1265 print
'<!-- '.$sql.
' -->';
1266 $resql = $db->query($sql);
1269 foreach ($listoftables as $table) {
1271 if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1274 if ($table[1] ==
'VIEW') {
1275 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1279 print
'<tr><td colspan="2">';
1281 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1282 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
1283 print
'<!-- '.$sql1.
' -->';
1284 print
'<!-- '.$sql2.
' -->';
1285 if ($force_utf8_on_tables ==
'confirmed') {
1286 $resql1 = $db->query($sql1);
1288 $resql2 = $db->query($sql2);
1292 print
' - Done ('.(($resql1 && $resql2) ?
'OK' :
'KO').
')';
1294 print
' - Disabled';
1300 if ($force_utf8_on_tables ==
'confirmed') {
1301 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1302 print
'<!-- '.$sql.
' -->';
1303 $resql = $db->query($sql);
1306 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1311if ($ok &&
GETPOST(
'force_utf8mb4_on_tables',
'alpha')) {
1312 print
'<tr><td colspan="2"><br>*** Force page code and collation of tables into utf8mb4/utf8mb4_unicode_ci (for mysql/mariadb only)</td></tr>';
1314 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1315 $force_utf8mb4_on_tables =
GETPOST(
'force_utf8mb4_on_tables',
'alpha');
1317 $listoftables = $db->DDLListTablesFull($db->database_name);
1320 if ($force_utf8mb4_on_tables ==
'confirmed') {
1321 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1322 print
'<!-- '.$sql.
' -->';
1323 $resql = $db->query($sql);
1326 foreach ($listoftables as $table) {
1328 if ($conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1331 if ($table[1] ==
'VIEW') {
1332 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1336 print
'<tr><td colspan="2">';
1338 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1339 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci";
1340 print
'<!-- '.$sql1.
' -->';
1341 print
'<!-- '.$sql2.
' -->';
1342 if ($force_utf8mb4_on_tables ==
'confirmed') {
1343 $resql1 = $db->query($sql1);
1345 $resql2 = $db->query($sql2);
1349 print
' - Done ('.(($resql1 && $resql2) ?
'OK' :
'KO').
')';
1351 print
' - Disabled';
1359 if ($force_utf8mb4_on_tables ==
'confirmed') {
1360 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1361 print
'<!-- '.$sql.
' -->';
1362 $resql = $db->query($sql);
1365 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1370if ($ok &&
GETPOST(
'rebuild_sequences',
'alpha')) {
1371 print
'<tr><td colspan="2"><br>*** Force to rebuild sequences (for postgresql only)</td></tr>';
1373 if ($db->type ==
"pgsql") {
1374 $rebuild_sequence =
GETPOST(
'rebuild_sequences',
'alpha');
1376 if ($rebuild_sequence ==
'confirmed') {
1377 $sql =
"SELECT dol_util_rebuild_sequences();";
1378 print
'<!-- '.$sql.
' -->';
1379 $resql = $db->query($sql);
1382 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1387if ($ok &&
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines')) {
1411 $repair_link_dispatch_lines_supplier_order_lines =
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines',
'alpha');
1414 echo
'<tr><th>Repair llx_commande_fournisseur_dispatch.fk_commandefourndet</th></tr>';
1415 echo
'<tr><td>Repair in progress. This may take a while.</td></tr>';
1417 $sql_dispatch =
'SELECT * FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch WHERE COALESCE(fk_commandefourndet, 0) = 0';
1419 $resql_dispatch = $db->query($sql_dispatch);
1420 $n_processed_rows = 0;
1422 if ($resql_dispatch) {
1423 if ($db->num_rows($resql_dispatch) == 0) {
1424 echo
'<tr><td>Nothing to do.</td></tr>';
1427 while ($obj_dispatch = $db->fetch_object($resql_dispatch)) {
1428 $sql_line =
'SELECT line.rowid, line.qty FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet AS line';
1429 $sql_line .=
' WHERE line.fk_commande = '.((int) $obj_dispatch->fk_commande);
1430 $sql_line .=
' AND line.fk_product = '.((int) $obj_dispatch->fk_product);
1431 $resql_line = $db->query($sql_line);
1437 $remaining_qty = $obj_dispatch->qty;
1438 $first_iteration =
true;
1440 echo
'<tr><td>Unable to find a matching supplier order line for dispatch #'.$obj_dispatch->rowid.
'</td></tr>';
1441 $errors[] = $sql_line;
1442 $n_processed_rows++;
1445 if ($db->num_rows($resql_line) == 0) {
1448 while ($obj_line = $db->fetch_object($resql_line)) {
1449 if (!$remaining_qty) {
1452 if (!$obj_line->rowid) {
1455 $qty_for_line = min($remaining_qty, $obj_line->qty);
1456 if ($first_iteration) {
1457 $sql_attach =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1458 $sql_attach .=
' SET fk_commandefourndet = '.((int) $obj_line->rowid).
', qty = '.((float) $qty_for_line);
1459 $sql_attach .=
' WHERE rowid = '.((int) $obj_dispatch->rowid);
1460 $first_iteration =
false;
1462 $sql_attach_values = array(
1463 ((
int) $obj_dispatch->fk_commande),
1464 ((
int) $obj_dispatch->fk_product),
1465 ((
int) $obj_line->rowid),
1466 ((
float) $qty_for_line),
1467 ((
int) $obj_dispatch->fk_entrepot),
1468 ((
int) $obj_dispatch->fk_user),
1469 $obj_dispatch->datec ?
"'".$db->idate($db->jdate($obj_dispatch->datec)).
"'" :
'NULL',
1470 $obj_dispatch->comment ?
"'".$db->escape($obj_dispatch->comment).
"'" :
'NULL',
1471 $obj_dispatch->status ? ((int) $obj_dispatch->status) :
'NULL',
1472 $obj_dispatch->tms ?
"'".$db->idate($db->jdate($obj_dispatch->tms)).
"'" :
'NULL',
1473 $obj_dispatch->batch ?
"'".$db->escape($obj_dispatch->batch).
"'" :
'NULL',
1474 $obj_dispatch->eatby ?
"'".$db->escape($obj_dispatch->eatby).
"'" :
'NULL',
1475 $obj_dispatch->sellby ?
"'".$db->escape($obj_dispatch->sellby).
"'" :
'NULL'
1477 $sql_attach_values = join(
', ', $sql_attach_values);
1479 $sql_attach =
'INSERT INTO '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch';
1480 $sql_attach .=
' (fk_commande, fk_product, fk_commandefourndet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)';
1481 $sql_attach .=
" VALUES (".$sql_attach_values.
")";
1484 if ($repair_link_dispatch_lines_supplier_order_lines ==
'confirmed') {
1485 $resql_attach = $db->query($sql_attach);
1487 $resql_attach =
true;
1490 if ($resql_attach) {
1491 $remaining_qty -= $qty_for_line;
1493 $errors[] = $sql_attach;
1496 $first_iteration =
false;
1498 $n_processed_rows++;
1501 if (!($n_processed_rows & 0xff)) {
1502 echo
'<tr><td>Processed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1508 echo
'<tr><td>Unable to find any dispatch without an fk_commandefourndet.'.
"</td></tr>\n";
1509 echo $sql_dispatch.
"\n";
1511 echo
'<tr><td>Fixed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1512 echo
'<tr><td>DONE.'.
"</td></tr>\n";
1514 if (count($errors)) {
1516 echo
'<tr><td>The transaction was rolled back due to errors: nothing was changed by the script.</td></tr>';
1522 echo
'<tr><td><h3>SQL queries with errors:</h3></tr></td>';
1523 echo
'<tr><td>'.join(
'</td></tr><tr><td>', $errors).
'</td></tr>';
1527if ($ok &&
GETPOST(
'repair_supplier_order_duplicate_ref')) {
1528 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.commande.class.php';
1529 include_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1536 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX .
"commande_fournisseur";
1537 $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)";
1540 $duplicateSupplierOrders = [];
1541 $resql = $db->query($sql);
1543 while ($rawSupplierOrder = $db->fetch_object($resql)) {
1545 $supplierOrder->setVarsFromFetchObj($rawSupplierOrder);
1547 $duplicateSupplierOrders[$rawSupplierOrder->ref] [] = $supplierOrder;
1554 foreach ($duplicateSupplierOrders as $ref => $supplierOrders) {
1556 foreach (array_slice($supplierOrders, 1) as $supplierOrder) {
1559 $soc->fetch($supplierOrder->fourn_id);
1561 $newRef = $supplierOrder->getNextNumRef($soc);
1563 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"commande_fournisseur cf SET cf.ref = '" . $db->escape($newRef) .
"' WHERE cf.rowid = " . (int) $supplierOrder->id;
1564 if (!$db->query($sql)) {
1581if (empty($actiondone)) {
1582 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
1586 print
'<div class="center" style="padding-top: 10px"><a href="../index.php?mainmenu=home&leftmenu=home'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
1587 print $langs->trans(
"GoToDolibarr");
1590 print
'<div class="center warning" style="padding-top: 10px">';
1591 print $langs->trans(
"SetAtLeastOneOptionAsUrlParameter");
1598if ($db->connected) {
1603if (!$ok && isset($argv[1])) {
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.