32include_once
'inc.php';
54@phan-var-force ?string $dolibarr_main_db_encryption
55@phan-var-force ?string $dolibarr_main_db_cryptkey
56@phan-var-force ?string $dolibarr_main_db_type
63require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
64include_once $dolibarr_main_document_root.
'/core/lib/images.lib.php';
65require_once $dolibarr_main_document_root.
'/core/class/extrafields.class.php';
66require_once $dolibarr_main_document_root.
'/core/class/html.form.class.php';
67require_once
'lib/repair.lib.php';
74$err = error_reporting();
79$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
80$langs->setDefaultLang($setuplang);
82$langs->loadLangs(array(
"admin",
"install",
"other"));
84if ($dolibarr_main_db_type ==
"mysqli") {
87if ($dolibarr_main_db_type ==
"pgsql") {
90if ($dolibarr_main_db_type ==
"mssql") {
96if (!is_object(
$conf)) {
104require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
105$user =
new User($db);
112pHeader($langs->trans(
"Repair"),
"upgrade2",
GETPOST(
'action',
'aZ09'));
117print
'<div class="div-table-responsive-no-min">';
118print
'<table cellspacing="0" cellpadding="1" class="centpercent">';
122if (preg_match(
'/(crypted|dolcrypt):/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
123 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
124 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
125 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
126 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
127 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
128 } elseif (preg_match(
'/dolcrypt:/i', $dolibarr_main_db_pass)) {
129 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
130 $dolibarr_main_db_pass =
dolDecrypt($dolibarr_main_db_pass);
132 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
137$conf->db->type = $dolibarr_main_db_type;
138$conf->db->host = $dolibarr_main_db_host;
139$conf->db->port = $dolibarr_main_db_port;
140$conf->db->name = $dolibarr_main_db_name;
141$conf->db->user = $dolibarr_main_db_user;
142$conf->db->pass = $dolibarr_main_db_pass;
145$conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
146$conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
150$form =
new Form($db);
153 print
'<tr><td class="nowrap">';
154 print $langs->trans(
"ServerConnection").
" : ".$dolibarr_main_db_host.
'</td><td class="right">'.$langs->trans(
"OK").
"</td></tr>";
155 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ServerConnection").
": ".$dolibarr_main_db_host.$langs->transnoentities(
"OK"));
158 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right">'.$langs->transnoentities(
"Error").
"</td></tr>";
159 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
164 if ($db->database_selected) {
165 print
'<tr><td class="nowrap">';
166 print $langs->trans(
"DatabaseConnection").
" : ".$dolibarr_main_db_name.
'</td><td class="right">'.$langs->trans(
"OK").
"</td></tr>";
170 print
"<tr><td>".$langs->trans(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name).
'</td><td class="right">'.$langs->trans(
"Error").
"</td></tr>";
171 dolibarr_install_syslog(
"repair: ".$langs->transnoentities(
"ErrorFailedToConnectToDatabase", $dolibarr_main_db_name));
178 $version = $db->getVersion();
179 $versionarray = $db->getVersionArray();
180 print
'<tr><td>'.$langs->trans(
"ServerVersion").
'</td>';
181 print
'<td class="right">'.$version.
'</td></tr>';
192print
'<div class="info" style="padding-top: 10px">';
193print
'Select a link "test" or "confirmed" to launch a reparation on the chosen option...';
197print
'<div class="div-table-responsive-no-min">';
198print
'<table class="liste centpercent" style="border: 1px solid #ccc">';
202print
'<th>Launch test</th>';
203print
'<th>Launch confirmed</th>';
206$warning_using_utf8mb4 =
'';
207if ($dolibarr_main_db_character_set !=
'utf8mb4') {
208 $warning_using_utf8mb4 =
'<img src="../theme/eldy/img/warning.png" class="pictofortooltip valignmiddle" title="If you switch to utf8mb4, you must also check the value for $dolibarr_main_db_character_set and $dolibarr_main_db_collation into conf/conf.php file.">';
214 'name' =>
'standard',
215 'info' =>
'Miscellaneous fixes'
220 'name' =>
'force_disable_of_modules_not_found',
221 'info' =>
'Disable modules not found'
226 'name' =>
'restore_thirdparties_logos',
227 'info' =>
'Restore logos for thirdparties'
230 'name' =>
'restore_user_pictures',
231 'info' =>
'Restore user pictures'
234 'name' =>
'rebuild_product_thumbs',
235 'info' =>
'Rebuild product thumbnails'
238 'name' =>
'repair_mailing_path',
239 'info' =>
'Repair path of mailing files',
240 'tooltip' =>
'Should be applied when using emailing module with > 99 mailings. In that case, please also set MAILING_USE_NEW_PATH_FOR_FILES.'
243 'Clean tables and data' => [
245 'name' =>
'clean_linked_elements',
246 'info' =>
'Clean linked elements'
249 'name' =>
'clean_menus',
250 'info' =>
'Clean menus'
253 'name' =>
'clean_orphelin_dir',
254 'info' =>
'Clean orphan directories'
257 'name' =>
'clean_product_stock_batch',
258 'info' =>
'Clean product stock batch'
261 'name' =>
'clean_perm_table',
262 'info' =>
'Clean permissions table'
265 'name' =>
'clean_ecm_files_table',
266 'info' =>
'Clean ECM files table'
269 'name' =>
'repair_link_dispatch_lines_supplier_order_lines',
270 'info' =>
'Repair link between dispatch lines and supplier order lines'
273 'Init empty data' => [
275 'name' =>
'set_empty_time_spent_amount',
276 'info' =>
'Init empty time spent amount'
281 'name' =>
'force_utf8_on_tables',
282 'info' =>
'Force utf8 + row=dynamic, for mysql/mariadb only'
285 'name' =>
'force_utf8mb4_on_tables',
286 'info' =>
'Force utf8mb4 + row=dynamic, for mysql/mariadb only' . $warning_using_utf8mb4
289 'name' =>
'force_collation_from_conf_on_tables',
290 'info' =>
'Force '.$conf->db->character_set.
'/'.
$conf->db->dolibarr_main_db_collation.
' + row=dynamic, for mysql/mariadb only'
295if ($db->type ==
'pgsql') {
296 $sections[
'Rebuild sequence'] = [
298 'name' =>
'rebuild_sequences',
299 'info' =>
'For postgresql only'
304$conf->use_javascript_ajax = 1;
306foreach ($sections as $section => $options) {
307 print
'<tr style="background:#f4f4f4;font-weight:bold"><td colspan="5">'.$section.
'</td></tr>';
308 foreach ($options as $opt) {
309 $option = $opt[
'name'];
310 $info = $opt[
'info'];
311 $tooltip = empty($opt[
'tooltip']) ?
'' : $opt[
'tooltip'];
312 $value =
GETPOST($option,
'alpha') ?
GETPOST($option,
'alpha') :
'undefined';
314 $url_test = $_SERVER[
'PHP_SELF'].
'?'.$option.
'=test#pleasebepatient';
315 $url_confirmed = $_SERVER[
'PHP_SELF'].
'?'.$option.
'=confirmed#pleasebepatient';
317 print
'<td>' . $option .
'</td>';
320 print $form->textwithpicto($info, $tooltip);
325 print
'<td class="center"><a href="'.$url_test.
'" title="Launch test on option '.$option.
'">test</a>'.($value ==
'test' ?
' (launched)' :
'').
'</td>';
326 print
'<td class="center"><a href="'.$url_confirmed.
'" title="Launch repair on option '.$option.
'">repair</a>'.($value ==
'confirmed' ?
' (launched)' :
'').
'</td>';
334print
'<br id="sectionresult">';
338$conf->setValues($db);
340if (defined(
'SYSLOG_FILE')) {
341 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
343$conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
348$oneoptionset = (
GETPOST(
'standard',
'alpha') ||
GETPOST(
'restore_thirdparties_logos',
'alpha') ||
GETPOST(
'clean_linked_elements',
'alpha') ||
GETPOST(
'clean_menus',
'alpha')
349 ||
GETPOST(
'clean_orphelin_dir',
'alpha') ||
GETPOST(
'clean_product_stock_batch',
'alpha') ||
GETPOST(
'set_empty_time_spent_amount',
'alpha') ||
GETPOST(
'rebuild_product_thumbs',
'alpha')
350 ||
GETPOST(
'clean_perm_table',
'alpha') ||
GETPOST(
'clean_ecm_files_table',
'alpha')
351 ||
GETPOST(
'force_disable_of_modules_not_found',
'alpha')
352 ||
GETPOST(
'force_utf8_on_tables',
'alpha') ||
GETPOST(
'force_utf8mb4_on_tables',
'alpha') ||
GETPOST(
'force_collation_from_conf_on_tables',
'alpha')
353 ||
GETPOST(
'rebuild_sequences',
'alpha') ||
GETPOST(
'recalculateinvoicetotal',
'alpha')) ||
GETPOST(
'repair_mailing_path',
'alpha');
355if ($ok && $oneoptionset) {
356 print
'<div id="pleasebepatient"></div>';
358 print $langs->trans(
"PleaseBePatient").
'<br><br>';
361 print str_repeat(
' ', 1024);
362 if (ob_get_level() > 0) {
370print
'<table cellspacing="0" cellpadding="1" class="centpercent">';
373if ($ok &&
GETPOST(
'standard',
'alpha')) {
374 $dir =
"mysql/migration/";
381 $filesindir = array();
382 $handle = opendir($dir);
383 if (is_resource($handle)) {
384 while (($file = readdir($handle)) !==
false) {
385 if (preg_match(
'/\.sql$/i', $file)) {
386 $filesindir[] = $file;
392 foreach ($filesindir as $file) {
393 if (preg_match(
'/repair/i', $file)) {
399 foreach ($filelist as $file) {
400 print
'<tr><td class="nowrap">*** ';
401 print $langs->trans(
"Script").
'</td><td class="right">'.$file.
'</td></tr>';
406 $ok =
run_sql($dir.$file, 0, 0, 1);
413if ($ok &&
GETPOST(
'standard',
'alpha')) {
414 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contratligne.class.php';
416 print
'<tr><td colspan="2"><br>*** Update denormalized_lower_planned_end_date.</td></tr>';
417 $sqltoupdatecontract =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
418 $sqltoupdatecontract .=
" SET denormalized_lower_planned_end_date = (SELECT MIN(date_fin_validite) FROM ".MAIN_DB_PREFIX.
"contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.statut = ".ContratLigne::STATUS_OPEN.
")";
419 $resqltoupdatecontract = $db->query($sqltoupdatecontract);
424 $listofmodulesextra = array(
'societe' =>
'societe',
'adherent' =>
'adherent',
'product' =>
'product',
425 'socpeople' =>
'socpeople',
'propal' =>
'propal',
'commande' =>
'commande',
426 'facture' =>
'facture',
'facturedet' =>
'facturedet',
'facture_rec' =>
'facture_rec',
'facturedet_rec' =>
'facturedet_rec',
427 'supplier_proposal' =>
'supplier_proposal',
'commande_fournisseur' =>
'commande_fournisseur',
428 'facture_fourn' =>
'facture_fourn',
'facture_fourn_rec' =>
'facture_fourn_rec',
'facture_fourn_det' =>
'facture_fourn_det',
'facture_fourn_det_rec' =>
'facture_fourn_det_rec',
429 'fichinter' =>
'fichinter',
'fichinterdet' =>
'fichinterdet',
430 'inventory' =>
'inventory',
431 'actioncomm' =>
'actioncomm',
'bom_bom' =>
'bom_bom',
'mrp_mo' =>
'mrp_mo',
432 'adherent_type' =>
'adherent_type',
'user' =>
'user',
'partnership' =>
'partnership',
'projet' =>
'projet',
'projet_task' =>
'projet_task',
'ticket' =>
'ticket',
'payment_various' =>
'payment_various');
435 print
'<tr><td colspan="2"><br>*** Check that fields into the extra table structure match the table of definition. If not, add column into table</td></tr>';
436 foreach ($listofmodulesextra as $tablename => $elementtype) {
438 $tableextra = MAIN_DB_PREFIX.$tablename.
'_extrafields';
441 $arrayoffieldsdesc = $extrafields->fetch_name_optionals_label($elementtype);
444 $arrayoffieldsfound = array();
445 $resql = $db->DDLDescTable($tableextra);
447 print
'<tr><td>Check availability of extra field for '.$tableextra;
449 while ($obj = $db->fetch_object($resql)) {
450 $fieldname = $fieldtype =
'';
451 if (preg_match(
'/mysql/', $db->type)) {
452 $fieldname = $obj->Field;
453 $fieldtype = $obj->Type;
455 $fieldname = isset($obj->Key) ? $obj->Key : $obj->attname;
456 $fieldtype = isset($obj->Type) ? $obj->Type :
'varchar';
459 if (empty($fieldname)) {
462 if (in_array($fieldname, array(
'rowid',
'tms',
'fk_object',
'import_key'))) {
465 $arrayoffieldsfound[$fieldname] = array(
'type' => $fieldtype);
467 print
' - Found '.count($arrayoffieldsfound).
' fields into table';
468 if (count($arrayoffieldsfound) > 0) {
469 print
' <span class="opacitymedium">('.implode(
', ', array_keys($arrayoffieldsfound)).
')</span>';
474 foreach ($arrayoffieldsdesc as $code => $label) {
475 if (!in_array($code, array_keys($arrayoffieldsfound))) {
476 print
'Found field '.$code.
' declared into '.MAIN_DB_PREFIX.
'extrafields table but not found into desc of table '.$tableextra.
" -> ";
477 $type = $extrafields->attributes[$elementtype][
'type'][$code];
478 $length = $extrafields->attributes[$elementtype][
'size'][$code];
484 if ($type ==
'boolean') {
487 } elseif ($type ==
'price') {
490 } elseif ($type ==
'phone') {
493 } elseif ($type ==
'mail') {
496 } elseif (($type ==
'select') || ($type ==
'sellist') || ($type ==
'radio') || ($type ==
'checkbox') || ($type ==
'chkbxlst')) {
499 } elseif ($type ==
'link') {
509 'value' => $lengthdb,
510 'attribute' => $attribute,
511 'default' => $default,
518 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
519 $result = $db->DDLAddField($tableextra, $code, $field_desc,
"");
522 print
"KO ".$db->lasterror.
"<br>\n";
527 print
' - Mode test, no column added.';
532 print
"</td><td> </td></tr>\n";
534 print
'<tr><td>Table '.$tableextra.
' is not found</td><td></td></tr>'.
"\n";
541if ($ok &&
GETPOST(
'standard',
'alpha')) {
547if ($ok &&
GETPOST(
'standard',
'alpha')) {
548 print
'<tr><td colspan="2"><br>*** Clean constant record of modules not enabled</td></tr>';
550 $sql =
"SELECT name, entity, value";
551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
552 $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'";
553 $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'";
554 $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_%'";
555 $sql .=
" OR name LIKE 'MAIN_MODULE_%_MODULEFOREXTERNAL'";
556 $sql .=
" ORDER BY name, entity";
558 $resql = $db->query($sql);
560 $num = $db->num_rows($resql);
567 $obj = $db->fetch_object($resql);
570 if (preg_match(
'/MAIN_MODULE_([^_\W]+)_(\w+)/i', $obj->name, $reg)) {
574 $sql2 =
"SELECT COUNT(*) as nb";
575 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
576 $sql2 .=
" WHERE name = 'MAIN_MODULE_".$db->sanitize($name).
"'";
577 $sql2 .=
" AND entity = ".((int) $obj->entity);
578 $resql2 = $db->query($sql2);
580 $obj2 = $db->fetch_object($resql2);
581 if ($obj2 && $obj2->nb == 0) {
583 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = '".$db->escape($obj->name).
"' AND entity = ".((int) $obj->entity);
585 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
586 $db->query($sqldelete);
588 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>';
590 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>';
604 dol_print_error($db);
610if ($ok &&
GETPOST(
'standard',
'alpha')) {
611 print
'<tr><td colspan="2"><br>*** Clean definition of boxes of modules not enabled</td></tr>';
613 $sql =
"SELECT file, entity FROM ".MAIN_DB_PREFIX.
"boxes_def";
614 $sql .=
" WHERE file like '%@%'";
616 $resql = $db->query($sql);
618 $num = $db->num_rows($resql);
625 $obj = $db->fetch_object($resql);
628 if (preg_match(
'/^(\w+)@(\w+)$/i', $obj->file, $reg)) {
632 $sql2 =
"SELECT COUNT(*) as nb";
633 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
634 $sql2 .=
" WHERE name = 'MAIN_MODULE_".strtoupper(
$module).
"'";
635 $sql2 .=
" AND entity = ".((int) $obj->entity);
636 $sql2 .=
" AND value <> 0";
637 $resql2 = $db->query($sql2);
639 $obj2 = $db->fetch_object($resql2);
640 if ($obj2 && $obj2->nb == 0) {
642 $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).
")";
643 $sqldeleteb =
"DELETE FROM ".MAIN_DB_PREFIX.
"boxes_def WHERE file = '".$db->escape($obj->file).
"' AND entity = ".((int) $obj->entity);
645 if (
GETPOST(
'standard',
'alpha') ==
'confirmed') {
646 $db->query($sqldeletea);
647 $db->query($sqldeleteb);
649 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>';
651 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>';
669if ($ok &&
GETPOST(
'restore_thirdparties_logos')) {
674 print
'<tr><td colspan="2"><br>*** Restore thirdparties logo<br>';
676 $sql =
"SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX.
"societe as s ORDER BY s.nom";
677 $resql = $db->query($sql);
679 $num = $db->num_rows($resql);
683 $obj = $db->fetch_object($resql);
691 $tmp = explode(
'.', (
string) $obj->logo);
693 if (isset($tmp[1])) {
698 $filetotest = $dolibarr_main_data_root.
'/societe/logos/'.$name.$ext;
699 $filetotestsmall = $dolibarr_main_data_root.
'/societe/logos/thumbs/'.$name.
'_small'.$ext;
701 print
'Check thirdparty '.$obj->rowid.
' name='.$obj->name.
' logo='.$obj->logo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
703 $filetarget = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/'.$name.$ext;
704 $filetargetsmall = $dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs/'.$name.
'_small'.$ext;
707 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
708 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos');
711 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
712 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
713 dol_copy($filetotest, $filetarget,
'', 0);
719 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
720 dol_mkdir($dolibarr_main_data_root.
'/societe/'.$obj->rowid.
'/logos/thumbs');
722 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
723 if (
GETPOST(
'restore_thirdparties_logos',
'alpha') ==
'confirmed') {
724 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
734 dol_print_error($db);
743if ($ok &&
GETPOST(
'restore_user_pictures',
'alpha')) {
748 print
'<tr><td colspan="2"><br>*** Restore user pictures<br>';
750 $sql =
"SELECT s.rowid, s.firstname, s.lastname, s.login, s.photo FROM ".MAIN_DB_PREFIX.
"user as s ORDER BY s.rowid";
751 $resql = $db->query($sql);
753 $num = $db->num_rows($resql);
757 $obj = $db->fetch_object($resql);
765 $tmp = explode(
'.', (
string) $obj->photo);
767 if (isset($tmp[1])) {
772 $filetotest = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/'.$name.$ext;
773 $filetotestsmall = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_small'.$ext;
774 $filetotestmini = $dolibarr_main_data_root.
'/users/'.substr(sprintf(
'%08d', $obj->rowid), -1, 1).
'/'.substr(sprintf(
'%08d', $obj->rowid), -2, 1).
'/thumbs/'.$name.
'_mini'.$ext;
776 print
'Check user '.$obj->rowid.
' lastname='.$obj->lastname.
' firstname='.$obj->firstname.
' photo='.$obj->photo.
' file '.$filetotest.
" exists=".$exists.
"<br>\n";
778 $filetarget = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/'.$name.$ext;
779 $filetargetsmall = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_small'.$ext;
780 $filetargetmini = $dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs/'.$name.
'_mini'.$ext;
784 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
785 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid);
788 print
" -> Copy file ".$filetotest.
" -> ".$filetarget.
"<br>\n";
789 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
790 dol_copy($filetotest, $filetarget,
'', 0);
796 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
797 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
800 print
" -> Copy file ".$filetotestsmall.
" -> ".$filetargetsmall.
"<br>\n";
801 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
802 dol_copy($filetotestsmall, $filetargetsmall,
'', 0);
808 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
809 dol_mkdir($dolibarr_main_data_root.
'/users/'.$obj->rowid.
'/thumbs');
812 print
" -> Copy file ".$filetotestmini.
" -> ".$filetargetmini.
"<br>\n";
813 if (
GETPOST(
'restore_user_pictures',
'alpha') ==
'confirmed') {
814 dol_copy($filetotestmini, $filetargetmini,
'', 0);
824 dol_print_error($db);
832if ($ok &&
GETPOST(
'rebuild_product_thumbs',
'alpha')) {
834 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
836 print
'<tr><td colspan="2"><br>*** Rebuild product thumbs<br>';
838 $sql =
"SELECT s.rowid, s.ref FROM ".MAIN_DB_PREFIX.
"product as s ORDER BY s.ref";
839 $resql = $db->query($sql);
841 $num = $db->num_rows($resql);
845 $obj = $db->fetch_object($resql);
847 if (!empty($obj->ref)) {
848 $files =
dol_dir_list($dolibarr_main_data_root.
'/produit/'.$obj->ref,
'files', 0);
849 foreach ($files as $file) {
852 $imgThumbSmall =
'notbuild';
853 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
855 $imgThumbSmall =
vignette($file[
'fullname'], $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
857 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbSmall.
" maxwidthsmall=".$maxwidthsmall.
" maxheightsmall=".$maxheightsmall.
"<br>\n";
858 $imgThumbMini =
'notbuild';
859 if (
GETPOST(
'rebuild_product_thumbs',
'alpha') ==
'confirmed') {
862 $imgThumbMini =
vignette($file[
'fullname'], $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
864 print
'Check product '.$obj->rowid.
", file ".$file[
'fullname'].
" -> ".$imgThumbMini.
" maxwidthmini=".$maxwidthmini.
" maxheightmini=".$maxheightmini.
"<br>\n";
873 dol_print_error($db);
880if ($ok &&
GETPOST(
'clean_linked_elements',
'alpha')) {
881 print
'<tr><td colspan="2"><br>*** Check table of linked elements and delete orphelins links</td></tr>';
883 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'commande').
"</td></tr>\n";
886 print
'<tr><td colspan="2">'.checkLinkedElements(
'propal',
'facture').
"</td></tr>\n";
889 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'facture').
"</td></tr>\n";
892 print
'<tr><td colspan="2">'.checkLinkedElements(
'commande',
'shipping').
"</td></tr>\n";
895 print
'<tr><td colspan="2">'.checkLinkedElements(
'shipping',
'delivery').
"</td></tr>\n";
898 print
'<tr><td colspan="2">'.checkLinkedElements(
'order_supplier',
'invoice_supplier').
"</td></tr>\n";
903if ($ok &&
GETPOST(
'clean_menus',
'alpha')) {
904 print
'<tr><td colspan="2"><br>*** Clean menu entries coming from disabled modules</td></tr>';
906 $sql =
"SELECT rowid, module";
907 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu as c";
908 $sql .=
" WHERE module IS NOT NULL AND module <> ''";
909 $sql .=
" ORDER BY module";
911 $resql = $db->query($sql);
913 $num = $db->num_rows($resql);
917 $obj = $db->fetch_object($resql);
919 $modulecond = $obj->module;
920 $modulecondarray = explode(
'|', $obj->module);
929 foreach ($modulecondarray as $tmpname) {
930 if ($tmpname ==
'margins') {
935 if (!empty(
$conf->$tmpname)) {
936 $result =
$conf->$tmpname->enabled;
943 if (!$moduleok && $modulecond) {
944 print
' - Module condition '.$modulecond.
' seems ko, we delete menu entry.';
945 if (
GETPOST(
'clean_menus') ==
'confirmed') {
946 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"menu WHERE module = '".$db->escape($modulecond).
"'";
947 $resql2 = $db->query($sql2);
950 dol_print_error($db);
952 print
' - <span class="warning">Cleaned</span>';
955 print
' - <span class="warning">Canceled (test mode)</span>';
958 print
' - Module condition '.$modulecond.
' is ok, we do nothing.';
977 print
'<tr><td>No menu entries of disabled menus found</td></tr>';
980 dol_print_error($db);
987if ($ok &&
GETPOST(
'clean_orphelin_dir',
'alpha')) {
988 $listmodulepart = array(
'company',
'invoice',
'invoice_supplier',
'propal',
'order',
'order_supplier',
'contract',
'tax');
989 foreach ($listmodulepart as $modulepart) {
990 $filearray = array();
991 $upload_dir = isset(
$conf->$modulepart->dir_output) ?
$conf->$modulepart->dir_output :
'';
992 if ($modulepart ==
'company') {
993 $upload_dir =
$conf->societe->dir_output;
995 if ($modulepart ==
'invoice') {
996 $upload_dir =
$conf->facture->dir_output;
998 if ($modulepart ==
'invoice_supplier') {
999 $upload_dir =
$conf->fournisseur->facture->dir_output;
1001 if ($modulepart ==
'order') {
1002 $upload_dir =
$conf->commande->dir_output;
1004 if ($modulepart ==
'order_supplier') {
1005 $upload_dir =
$conf->fournisseur->commande->dir_output;
1007 if ($modulepart ==
'contract') {
1008 $upload_dir =
$conf->contrat->dir_output;
1011 if (empty($upload_dir)) {
1015 print
'<tr><td colspan="2"><br>*** Clean orphelins files into files '.$upload_dir.
'</td></tr>';
1017 $filearray =
dol_dir_list($upload_dir,
"files", 1,
'', array(
'^SPECIMEN\.pdf$',
'^\.',
'(\.meta|_preview.*\.png)$',
'^temp$',
'^payments$',
'^CVS$',
'^thumbs$'),
'', SORT_DESC, 1, 1);
1019 $object_instance =
null;
1021 if ($modulepart ==
'company') {
1022 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1023 $object_instance =
new Societe($db);
1025 if ($modulepart ==
'invoice') {
1026 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
1027 $object_instance =
new Facture($db);
1028 } elseif ($modulepart ==
'invoice_supplier') {
1029 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
1031 } elseif ($modulepart ==
'propal') {
1032 include_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
1033 $object_instance =
new Propal($db);
1034 } elseif ($modulepart ==
'order') {
1035 include_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
1036 $object_instance =
new Commande($db);
1037 } elseif ($modulepart ==
'order_supplier') {
1038 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.class.php';
1040 } elseif ($modulepart ==
'contract') {
1041 include_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
1042 $object_instance =
new Contrat($db);
1043 } elseif ($modulepart ==
'tax') {
1044 include_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
1048 foreach ($filearray as $key => $file) {
1049 if (!is_dir($file[
'name'])
1050 && $file[
'name'] !=
'.'
1051 && $file[
'name'] !=
'..'
1052 && $file[
'name'] !=
'CVS'
1055 $relativefile = preg_replace(
'/'.preg_quote($upload_dir.
'/',
'/').
'/',
'', $file[
'fullname']);
1060 $object_instance->id = 0;
1061 $object_instance->ref =
'';
1065 if ($modulepart ==
'invoice') {
1066 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
1067 $ref = empty($reg[1]) ?
'' : $reg[1];
1069 if ($modulepart ==
'invoice_supplier') {
1070 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg);
1071 $id = empty($reg[1]) ?
'' : $reg[1];
1073 if ($modulepart ==
'propal') {
1074 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
1075 $ref = empty($reg[1]) ?
'' : $reg[1];
1077 if ($modulepart ==
'order') {
1078 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
1079 $ref = empty($reg[1]) ?
'' : $reg[1];
1081 if ($modulepart ==
'order_supplier') {
1082 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
1083 $ref = empty($reg[1]) ?
'' : $reg[1];
1085 if ($modulepart ==
'contract') {
1086 preg_match(
'/(.*)\/[^\/]+$/', $relativefile, $reg);
1087 $ref = empty($reg[1]) ?
'' : $reg[1];
1089 if ($modulepart ==
'tax') {
1090 preg_match(
'/(\d+)\/[^\/]+$/', $relativefile, $reg);
1091 $id = empty($reg[1]) ?
'' : $reg[1];
1094 if ((
$id || $ref) && $object_instance !==
null) {
1096 $result = $object_instance->fetch(
$id, $ref);
1100 print
'<tr><td colspan="2">';
1101 print
'Delete orphelins file '.$file[
'fullname'].
'<br>';
1102 if (
GETPOST(
'clean_orphelin_dir',
'alpha') ==
'confirmed') {
1107 } elseif ($result < 0) {
1108 print
'Error in '.get_class($object_instance).
'.fetch of id'.
$id.
' ref='.$ref.
', result='.$result.
'<br>';
1118if ($ok &&
GETPOST(
'clean_product_stock_batch',
'alpha')) {
1119 $methodtofix =
GETPOST(
'methodtofix',
'alpha') ?
GETPOST(
'methodtofix',
'alpha') :
'updatestock';
1121 print
'<tr><td colspan="2"><br>*** Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
1123 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
1124 $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";
1125 $sql .=
" WHERE p.rowid = ps.fk_product";
1126 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
1127 $sql .=
" HAVING (SUM(pb.qty) IS NOT NULL AND reel != SUM(pb.qty)) OR (SUM(pb.qty) IS NULL AND p.tobatch > 0)";
1129 $resql = $db->query($sql);
1131 $num = $db->num_rows($resql);
1136 $obj = $db->fetch_object($resql);
1137 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)';
1140 if ($obj->reel != $obj->reelbatch) {
1141 if (empty($obj->tobatch)) {
1143 print
' -> Delete qty '.$obj->reelbatch.
' for any lot linked to fk_product_stock='.$obj->psrowid;
1144 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"product_batch";
1145 $sql2 .=
" WHERE fk_product_stock = ".((int) $obj->psrowid);
1148 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
1149 $resql2 = $db->query($sql2);
1152 dol_print_error($db);
1156 if ($methodtofix ==
'updatebatch') {
1158 print
' -> Insert qty '.($obj->reel - $obj->reelbatch).
' with lot 000000 linked to fk_product_stock='.$obj->psrowid;
1159 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"product_batch(fk_product_stock, batch, qty)";
1160 $sql2 .=
"VALUES(".((int) $obj->psrowid).
", '000000', ".((float) ($obj->reel - $obj->reelbatch)).
")";
1163 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
1164 $resql2 = $db->query($sql2);
1173 if ($methodtofix ==
'updatestock') {
1175 print
' -> Update qty of product_stock with qty = '.($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
' for ps.rowid = '.((
int) $obj->psrowid);
1176 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"product_stock";
1177 $sql2 .=
" SET reel = ".($obj->reelbatch ? ((float) $obj->reelbatch) :
'0').
" WHERE rowid = ".((
int) $obj->psrowid);
1180 if (
GETPOST(
'clean_product_stock_batch') ==
'confirmed') {
1185 $resql2 = $db->query($sql2);
1188 $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)';
1189 $resql3 = $db->query($sql3);
1192 dol_print_error($db);
1196 dol_print_error($db);
1214 print
'<tr><td colspan="2">Nothing to do</td></tr>';
1217 dol_print_error($db);
1223if ($ok &&
GETPOST(
'clean_product_stock_negative_if_batch',
'alpha')) {
1224 print
'<tr><td colspan="2"><br>Clean table product_batch, methodtofix='.$methodtofix.
' (possible values: updatestock or updatebatch)</td></tr>';
1226 $sql =
"SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch";
1227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p, ".MAIN_DB_PREFIX.
"product_stock as ps, ".MAIN_DB_PREFIX.
"product_batch as pb";
1228 $sql .=
" WHERE p.rowid = ps.fk_product AND ps.rowid = pb.fk_product_stock";
1229 $sql .=
" AND p.tobatch > 0";
1230 $sql .=
" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel";
1231 $sql .=
" HAVING reel != SUM(pb.qty)";
1232 $resql = $db->query($sql);
1234 $num = $db->num_rows($resql);
1239 $obj = $db->fetch_object($resql);
1240 print
'<tr><td>'.$obj->rowid.
'-'.$obj->ref.
'-'.$obj->fk_entrepot.
' -> '.$obj->psrowid.
': '.$obj->reel.
' != '.$obj->reelbatch;
1249if ($ok &&
GETPOST(
'set_empty_time_spent_amount',
'alpha')) {
1250 print
'<tr><td colspan="2"><br>*** Set value of time spent without amount</td></tr>';
1252 $sql =
"SELECT COUNT(ptt.rowid) as nb, u.rowid as user_id, u.login, u.thm as user_thm";
1253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time as ptt, ".MAIN_DB_PREFIX.
"user as u";
1254 $sql .=
" WHERE ptt.fk_user = u.rowid";
1255 $sql .=
" AND ptt.thm IS NULL and u.thm > 0";
1256 $sql .=
" GROUP BY u.rowid, u.login, u.thm";
1258 $resql = $db->query($sql);
1260 $num = $db->num_rows($resql);
1265 $obj = $db->fetch_object($resql);
1266 print
'<tr><td>'.$obj->login.
'-'.$obj->user_id.
' ('.$obj->nb.
' lines to fix) -> '.$obj->user_thm;
1270 if (
GETPOST(
'set_empty_time_spent_amount') ==
'confirmed') {
1271 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time";
1272 $sql2 .=
" SET thm = ".((float) $obj->user_thm).
" WHERE thm IS NULL AND fk_user = ".((int) $obj->user_id);
1273 $resql2 = $db->query($sql2);
1276 dol_print_error($db);
1295 print
'<tr><td>No time spent with empty line on users with a hourly rate defined</td></tr>';
1298 dol_print_error($db);
1304if ($ok &&
GETPOST(
'force_disable_of_modules_not_found',
'alpha')) {
1305 print
'<tr><td colspan="2"><br>*** Force modules not found physically to be disabled (only modules adding js, css or hooks can be detected as removed physically)</td></tr>';
1307 $arraylistofkey = array(
'hooks',
'js',
'css');
1309 foreach ($arraylistofkey as $key) {
1310 $sql =
"SELECT DISTINCT name, value";
1311 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const as c";
1312 $sql .=
" WHERE name LIKE 'MAIN_MODULE_%_".strtoupper($db->escape($key)).
"'";
1313 $sql .=
" ORDER BY name";
1315 $resql = $db->query($sql);
1317 $num = $db->num_rows($resql);
1321 $obj = $db->fetch_object($resql);
1322 $constantname = $obj->name;
1330 if (preg_match(
'/MAIN_MODULE_(.*)_'.strtoupper($key).
'/i', $constantname, $reg)) {
1331 $name = strtolower($reg[1]);
1337 if ($key ==
'hooks') {
1338 $reloffile = $name.
'/class/actions_'.$name.
'.class.php';
1341 $value = $obj->value;
1342 $valuearray = (array) json_decode($value);
1343 $reloffile = $valuearray[0];
1344 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1346 if ($key ==
'css') {
1347 $value = $obj->value;
1348 $valuearray = (array) json_decode($value);
1349 if ($value && (!is_array($valuearray) || count($valuearray) == 0)) {
1350 $valuearray = array();
1351 $valuearray[0] = $value;
1353 $reloffile = preg_replace(
'/^\//',
'', $valuearray[0]);
1368 print
' - File of '.$key.
' ('.$reloffile.
') NOT found, we disable the module.';
1369 if (
GETPOST(
'force_disable_of_modules_not_found') ==
'confirmed') {
1370 $sql2 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"_".strtoupper($key).
"'";
1371 $resql2 = $db->query($sql2);
1374 dol_print_error($db);
1376 $sql3 =
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE name = 'MAIN_MODULE_".strtoupper($name).
"'";
1377 $resql3 = $db->query($sql3);
1380 dol_print_error($db);
1382 print
' - <span class="warning">Cleaned</span>';
1385 print
' - <span class="warning">Canceled (test mode)</span>';
1388 print
' - File of '.$key.
' ('.$reloffile.
') found, we do nothing.';
1408 print
'<tr><td>No active module with missing files found by searching on MAIN_MODULE_(.*)_'.strtoupper($key).
'</td></tr>';
1411 dol_print_error($db);
1418if ($ok &&
GETPOST(
'clean_perm_table',
'alpha')) {
1419 print
'<tr><td colspan="2"><br>*** Clean table user_rights from lines of external modules no more enabled</td></tr>';
1422 foreach (
$conf->modules as $key => $val) {
1423 $listofmods .= ($listofmods ?
',' :
'').
"'".$db->escape($val).
"'";
1426 $sql =
"SELECT id, libelle as label, module from ".MAIN_DB_PREFIX.
"rights_def WHERE module NOT IN (".$db->sanitize($listofmods, 1).
") AND id > 100000";
1428 $resql = $db->query($sql);
1430 $num = $db->num_rows($resql);
1434 $obj = $db->fetch_object($resql);
1436 print
'<tr><td>Found line with id '.$obj->id.
', label "'.$obj->label.
'" of module "'.$obj->module.
'" to delete';
1437 if (
GETPOST(
'clean_perm_table',
'alpha') ==
'confirmed') {
1438 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"rights_def WHERE id = ".((int) $obj->id);
1439 $resqldelete = $db->query($sqldelete);
1440 if (!$resqldelete) {
1441 dol_print_error($db);
1450 print
'<tr><td>No lines of a disabled external module (with id > 100000) found into table rights_def</td></tr>';
1453 dol_print_error($db);
1459if ($ok &&
GETPOST(
'clean_ecm_files_table',
'alpha')) {
1460 print
'<tr><td colspan="2"><br>*** Clean table ecm_files from lines of entries whose physical files does not exists anymore (emplemented for entity 1 only)</td></tr>';
1464 $sql =
"SELECT rowid, filename, filepath, entity from ".MAIN_DB_PREFIX.
"ecm_files";
1465 $sql .=
" WHERE entity = 1";
1466 $sql .=
" ORDER BY rowid ASC";
1469 $nbfiletodelete = 0;
1471 $resql = $db->query($sql);
1473 $num = $db->num_rows($resql);
1477 $obj = $db->fetch_object($resql);
1478 if ($obj->rowid > 0) {
1479 $filetocheck = DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename;
1483 if ($nbfiletodelete <= $MAXTODELETE) {
1484 print
'<tr><td>Found line with id '.$obj->rowid.
', entity '.$obj->entity.
', file "'.$filetocheck.
'" to delete';
1485 if (
GETPOST(
'clean_ecm_files_table',
'alpha') ==
'confirmed') {
1486 $sqldelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"ecm_files WHERE rowid = ".((int) $obj->rowid);
1487 $resqldelete = $db->query($sqldelete);
1488 if (!$resqldelete) {
1489 dol_print_error($db);
1502 if ($nbfiletodelete > $MAXTODELETE) {
1503 print
'<tr><td>There is more than '.$MAXTODELETE.
' invalid entries into ecm_files index table (among '.$nbfile.
' analyzed) with no valid physical files. Run the page several time to process all of them.</td></tr>';
1505 print
'<tr><td>Nb of entries processed into ecm_files index table: '.$nbfile.
', number of invalid record: '.$nbfiletodelete.
'</td></tr>';
1508 dol_print_error($db);
1513if ($ok &&
GETPOST(
'force_utf8_on_tables',
'alpha')) {
1514 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>';
1516 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1517 $force_utf8_on_tables =
GETPOST(
'force_utf8_on_tables',
'alpha');
1519 $listoftables = $db->DDLListTablesFull($db->database_name);
1522 if ($force_utf8_on_tables ==
'confirmed') {
1523 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1524 print
'<!-- '.$sql.
' -->';
1525 print
'<tr><td colspan="2">'.$sql.
'</td></tr>';
1526 $resql = $db->query($sql);
1529 $foreignkeystorestore = array();
1532 foreach ($listoftables as $table) {
1534 if (
$conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1537 if ($table[1] ==
'VIEW') {
1538 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' <span class="opacitymedium">(Skipped)</span></td></tr>';
1543 $arrayofforeignkey = array(
1544 'llx_accounting_account' =>
'fk_accounting_account_fk_pcg_version',
1545 'llx_accounting_system' =>
'fk_accounting_account_fk_pcg_version',
1546 'llx_c_type_contact' =>
'fk_societe_commerciaux_fk_c_type_contact_code',
1547 'llx_societe_commerciaux' =>
'fk_societe_commerciaux_fk_c_type_contact_code'
1550 foreach ($arrayofforeignkey as $tmptable => $foreignkeyname) {
1551 if ($table[0] == $tmptable) {
1552 print
'<tr><td colspan="2">';
1553 $sqltmp =
"ALTER TABLE ".$db->sanitize($table[0]).
" DROP FOREIGN KEY ".$db->sanitize($foreignkeyname);
1555 if ($force_utf8_on_tables ==
'confirmed') {
1556 $resqltmp = $db->query($sqltmp);
1558 print
' - <span class="opacitymedium">Disabled</span>';
1561 $foreignkeystorestore[$tmptable] = $foreignkeyname;
1566 foreach ($listoftables as $table) {
1568 if (
$conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1571 if ($table[1] ==
'VIEW') {
1572 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' <span class="opacitymedium">(Skipped)</span></td></tr>';
1576 $collation =
'utf8_unicode_ci';
1577 $defaultcollation = $db->getDefaultCollationDatabase();
1578 if (preg_match(
'/general/', $defaultcollation)) {
1579 $collation =
'utf8_general_ci';
1582 print
'<tr><td colspan="2">';
1584 $sql1 =
"ALTER TABLE ".$db->sanitize($table[0]).
" ROW_FORMAT=dynamic";
1585 $sql2 =
"ALTER TABLE ".$db->sanitize($table[0]).
" CONVERT TO CHARACTER SET utf8 COLLATE ".$db->sanitize($collation);
1586 print
'<!-- '.$sql1.
' -->';
1587 print
'<!-- '.$sql2.
' -->';
1588 if ($force_utf8_on_tables ==
'confirmed') {
1589 $resql1 = $db->query($sql1);
1591 $resql2 = $db->query($sql2);
1595 print
' - Done '.(($resql1 && $resql2) ?
'<span class="opacitymedium">(OK)</span>' :
'<span class="error" title="'.
dol_escape_htmltag($db->lasterror).
'">(KO)</span>');
1597 print
' - <span class="opacitymedium">Disabled</span>';
1601 if (ob_get_level() > 0) {
1607 foreach ($foreignkeystorestore as $tmptable => $foreignkeyname) {
1608 $stringtofindinline =
"ALTER TABLE .* ADD CONSTRAINT ".$db->sanitize($foreignkeyname);
1609 $fileforkeys = DOL_DOCUMENT_ROOT.
'/install/mysql/tables/'.$tmptable.
'.key.sql';
1612 $handle = fopen($fileforkeys,
'r');
1614 while (($line = fgets($handle)) !==
false) {
1616 if (preg_match(
'/^'.$stringtofindinline.
'/i', $line)) {
1617 $resqltmp = $db->query($line);
1618 print
'<tr><td colspan="2">';
1620 print
' - Done '.($resqltmp ?
'<span class="opacitymedium">(OK)</span>' :
'<span class="error" title="'.dol_escape_htmltag($db->lasterror).
'">(KO)</span>');
1628 if (ob_get_level() > 0) {
1634 if ($force_utf8_on_tables ==
'confirmed') {
1635 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1636 print
'<!-- '.$sql.
' -->';
1637 print
'<tr><td colspan="2">'.$sql.
'</td></tr>';
1638 $resql = $db->query($sql);
1641 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1646if ($ok &&
GETPOST(
'force_utf8mb4_on_tables',
'alpha')) {
1647 print
'<tr><td colspan="2"><br>*** Force page code and collation of tables into utf8mb4/utf8mb4_unicode_ci (for mysql/mariadb only)</td></tr>';
1649 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1650 $force_utf8mb4_on_tables =
GETPOST(
'force_utf8mb4_on_tables',
'alpha');
1653 $listoftables = $db->DDLListTablesFull($db->database_name);
1656 if ($force_utf8mb4_on_tables ==
'confirmed') {
1657 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1658 print
'<!-- '.$sql.
' -->';
1659 print
'<tr><td colspan="2">'.$sql.
'</td></tr>';
1660 $resql = $db->query($sql);
1663 $foreignkeystorestore = array();
1666 foreach ($listoftables as $table) {
1668 if (
$conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1671 if ($table[1] ==
'VIEW') {
1672 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' <span class="opacitymedium">(Skipped)</span></td></tr>';
1677 $arrayofforeignkey = array(
1678 'llx_accounting_account' =>
'fk_accounting_account_fk_pcg_version',
1679 'llx_accounting_system' =>
'fk_accounting_account_fk_pcg_version',
1680 'llx_c_type_contact' =>
'fk_societe_commerciaux_fk_c_type_contact_code',
1681 'llx_societe_commerciaux' =>
'fk_societe_commerciaux_fk_c_type_contact_code'
1684 foreach ($arrayofforeignkey as $tmptable => $foreignkeyname) {
1685 if ($table[0] == $tmptable) {
1686 print
'<tr><td colspan="2">';
1687 $sqltmp =
"ALTER TABLE ".$db->sanitize($table[0]).
" DROP FOREIGN KEY ".$db->sanitize($foreignkeyname);
1689 if ($force_utf8mb4_on_tables ==
'confirmed') {
1690 $resqltmp = $db->query($sqltmp);
1692 print
' - <span class="opacitymedium">Disabled</span>';
1695 $foreignkeystorestore[$tmptable] = $foreignkeyname;
1700 foreach ($listoftables as $table) {
1702 if (
$conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1705 if ($table[1] ==
'VIEW') {
1706 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' <span class="opacitymedium">(Skipped)</span></td></tr>';
1710 $collation =
'utf8mb4_unicode_ci';
1711 $defaultcollation = $db->getDefaultCollationDatabase();
1712 if (preg_match(
'/general/', $defaultcollation)) {
1713 $collation =
'utf8mb4_general_ci';
1716 print
'<tr><td colspan="2">';
1718 $sql1 =
"ALTER TABLE ".$db->sanitize($table[0]).
" ROW_FORMAT=dynamic";
1719 $sql2 =
"ALTER TABLE ".$db->sanitize($table[0]).
" CONVERT TO CHARACTER SET utf8mb4 COLLATE ".$db->sanitize($collation);
1720 print
'<!-- '.$sql1.
' -->';
1721 print
'<!-- '.$sql2.
' -->';
1722 if ($force_utf8mb4_on_tables ==
'confirmed') {
1723 $resql1 = $db->query($sql1);
1725 $resql2 = $db->query($sql2);
1729 print
' - Done '.(($resql1 && $resql2) ?
'<span class="opacitymedium">(OK)</span>' :
'<span class="error" title="'.
dol_escape_htmltag($db->lasterror).
'">(KO)</span>');
1731 print
' - <span class="opacitymedium">Disabled</span>';
1735 if (ob_get_level() > 0) {
1741 foreach ($foreignkeystorestore as $tmptable => $foreignkeyname) {
1742 $stringtofindinline =
"ALTER TABLE .* ADD CONSTRAINT ".$db->sanitize($foreignkeyname);
1743 $fileforkeys = DOL_DOCUMENT_ROOT.
'/install/mysql/tables/'.$tmptable.
'.key.sql';
1746 $handle = fopen($fileforkeys,
'r');
1748 while (($line = fgets($handle)) !==
false) {
1750 if (preg_match(
'/^'.$stringtofindinline.
'/i', $line)) {
1751 $resqltmp = $db->query($line);
1752 print
'<tr><td colspan="2">';
1754 print
' - Done '.($resqltmp ?
'<span class="opacitymedium">(OK)</span>' :
'<span class="error" title="'.dol_escape_htmltag($db->lasterror).
'">(KO)</span>');
1762 if (ob_get_level() > 0) {
1768 if ($force_utf8mb4_on_tables ==
'confirmed') {
1769 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1770 print
'<!-- '.$sql.
' -->';
1771 print
'<tr><td colspan="2">'.$sql.
'</td></tr>';
1772 $resql = $db->query($sql);
1775 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1779if ($ok &&
GETPOST(
'force_collation_from_conf_on_tables',
'alpha')) {
1780 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>';
1782 if ($db->type ==
"mysql" || $db->type ==
"mysqli") {
1783 $force_collation_from_conf_on_tables =
GETPOST(
'force_collation_from_conf_on_tables',
'alpha');
1785 $listoftables = $db->DDLListTablesFull($db->database_name);
1788 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1789 $sql =
'SET FOREIGN_KEY_CHECKS=0';
1790 print
'<!-- '.$sql.
' -->';
1791 $resql = $db->query($sql);
1794 foreach ($listoftables as $table) {
1796 if (
$conf->db->dolibarr_main_db_encryption != 0 && preg_match(
'/\_const$/', $table[0])) {
1799 if ($table[1] ==
'VIEW') {
1800 print
'<tr><td colspan="2">'.$table[0].
' is a '.$table[1].
' (Skipped)</td></tr>';
1804 print
'<tr><td colspan="2">';
1806 $sql1 =
"ALTER TABLE ".$table[0].
" ROW_FORMAT=dynamic";
1807 $sql2 =
"ALTER TABLE ".$table[0].
" CONVERT TO CHARACTER SET ".
$conf->db->character_set.
" COLLATE ".
$conf->db->dolibarr_main_db_collation;
1808 print
'<!-- '.$sql1.
' -->';
1809 print
'<!-- '.$sql2.
' -->';
1810 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1811 $resql1 = $db->query($sql1);
1813 $resql2 = $db->query($sql2);
1817 print
' - Done '.(($resql1 && $resql2) ?
'<span class="opacitymedium">(OK)</span>' :
'<span class="error" title="'.
dol_escape_htmltag($db->lasterror).
'">(KO)</span>');
1819 print
' - <span class="opacitymedium">Disabled</span>';
1825 if ($force_collation_from_conf_on_tables ==
'confirmed') {
1826 $sql =
'SET FOREIGN_KEY_CHECKS=1';
1827 print
'<!-- '.$sql.
' -->';
1828 $resql = $db->query($sql);
1831 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1836if ($ok &&
GETPOST(
'rebuild_sequences',
'alpha')) {
1837 print
'<tr><td colspan="2"><br>*** Force to rebuild sequences (for postgresql only)</td></tr>';
1839 if ($db->type ==
"pgsql") {
1840 $rebuild_sequence =
GETPOST(
'rebuild_sequences',
'alpha');
1842 if ($rebuild_sequence ==
'confirmed') {
1843 $sql =
"SELECT dol_util_rebuild_sequences();";
1844 print
'<!-- '.$sql.
' -->';
1845 $resql = $db->query($sql);
1848 print
'<tr><td colspan="2">Not available with database type '.$db->type.
'</td></tr>';
1853if ($ok &&
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines')) {
1877 $repair_link_dispatch_lines_supplier_order_lines =
GETPOST(
'repair_link_dispatch_lines_supplier_order_lines',
'alpha');
1880 echo
'<tr><th>Repair llx_receptiondet_batch.fk_commandefourndet</th></tr>';
1881 echo
'<tr><td>Repair in progress. This may take a while.</td></tr>';
1883 $sql_dispatch =
'SELECT * FROM '.MAIN_DB_PREFIX.
'receptiondet_batch WHERE COALESCE(fk_elementdet, 0) = 0';
1885 $resql_dispatch = $db->query($sql_dispatch);
1886 $n_processed_rows = 0;
1888 if ($resql_dispatch) {
1889 if ($db->num_rows($resql_dispatch) == 0) {
1890 echo
'<tr><td>Nothing to do.</td></tr>';
1893 while ($obj_dispatch = $db->fetch_object($resql_dispatch)) {
1894 $sql_line =
'SELECT line.rowid, line.qty FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet AS line';
1895 $sql_line .=
' WHERE line.fk_commande = '.((int) $obj_dispatch->fk_commande);
1896 $sql_line .=
' AND line.fk_product = '.((int) $obj_dispatch->fk_product);
1897 $resql_line = $db->query($sql_line);
1903 $remaining_qty = $obj_dispatch->qty;
1904 $first_iteration =
true;
1906 echo
'<tr><td>Unable to find a matching supplier order line for dispatch #'.$obj_dispatch->rowid.
'</td></tr>';
1907 $errors[] = $sql_line;
1908 $n_processed_rows++;
1911 if ($db->num_rows($resql_line) == 0) {
1914 while ($obj_line = $db->fetch_object($resql_line)) {
1915 if (!$remaining_qty) {
1918 if (!$obj_line->rowid) {
1921 $qty_for_line = min($remaining_qty, $obj_line->qty);
1922 if ($first_iteration) {
1923 $sql_attach =
'UPDATE '.MAIN_DB_PREFIX.
'receptiondet_batch';
1924 $sql_attach .=
' SET fk_elementdet = '.((int) $obj_line->rowid).
', qty = '.((float) $qty_for_line);
1925 $sql_attach .=
' WHERE rowid = '.((int) $obj_dispatch->rowid);
1926 $first_iteration =
false;
1928 $sql_attach_values = array(
1929 (
string) ((
int) $obj_dispatch->fk_element),
1930 (
string) ((
int) $obj_dispatch->fk_product),
1931 (
string) ((
int) $obj_line->rowid),
1932 (
string) ((
float) $qty_for_line),
1933 (
string) ((
int) $obj_dispatch->fk_entrepot),
1934 (
string) ((
int) $obj_dispatch->fk_user),
1935 $obj_dispatch->datec ?
"'".$db->idate($db->jdate($obj_dispatch->datec)).
"'" :
'NULL',
1936 $obj_dispatch->comment ?
"'".$db->escape($obj_dispatch->comment).
"'" :
'NULL',
1937 $obj_dispatch->
status ? (string) ((int) $obj_dispatch->
status) :
'NULL',
1938 $obj_dispatch->tms ?
"'".$db->idate($db->jdate($obj_dispatch->tms)).
"'" :
'NULL',
1939 $obj_dispatch->batch ?
"'".$db->escape($obj_dispatch->batch).
"'" :
'NULL',
1940 $obj_dispatch->eatby ?
"'".$db->escape($obj_dispatch->eatby).
"'" :
'NULL',
1941 $obj_dispatch->sellby ?
"'".$db->escape($obj_dispatch->sellby).
"'" :
'NULL'
1943 $sql_attach_values = implode(
', ', $sql_attach_values);
1945 $sql_attach =
'INSERT INTO '.MAIN_DB_PREFIX.
'receptiondet_batch';
1946 $sql_attach .=
' (fk_element, fk_product, fk_elementdet, qty, fk_entrepot, fk_user, datec, comment, status, tms, batch, eatby, sellby)';
1947 $sql_attach .=
" VALUES (".$sql_attach_values.
")";
1950 if ($repair_link_dispatch_lines_supplier_order_lines ==
'confirmed') {
1951 $resql_attach = $db->query($sql_attach);
1953 $resql_attach =
true;
1956 if ($resql_attach) {
1957 $remaining_qty -= $qty_for_line;
1959 $errors[] = $sql_attach;
1962 $first_iteration =
false;
1964 $n_processed_rows++;
1967 if (!($n_processed_rows & 0xff)) {
1968 echo
'<tr><td>Processed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1970 if (ob_get_level() > 0) {
1976 echo
'<tr><td>Unable to find any dispatch without an fk_commandefourndet.'.
"</td></tr>\n";
1977 echo $sql_dispatch.
"\n";
1979 echo
'<tr><td>Fixed '.$n_processed_rows.
' rows with '.count($errors).
' errors…'.
"</td></tr>\n";
1980 echo
'<tr><td>DONE.'.
"</td></tr>\n";
1982 if (count($errors)) {
1984 echo
'<tr><td>The transaction was rolled back due to errors: nothing was changed by the script.</td></tr>';
1990 echo
'<tr><td><h3>SQL queries with errors:</h3></tr></td>';
1991 echo
'<tr><td>'.implode(
'</td></tr><tr><td>', $errors).
'</td></tr>';
1995if ($ok &&
GETPOST(
'repair_supplier_order_duplicate_ref')) {
1996 require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.commande.class.php';
1997 include_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
2004 $sql =
"SELECT * FROM " . MAIN_DB_PREFIX .
"commande_fournisseur";
2005 $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)";
2008 $duplicateSupplierOrders = [];
2009 $resql = $db->query($sql);
2011 while ($rawSupplierOrder = $db->fetch_object($resql)) {
2013 $supplierOrder->setVarsFromFetchObj($rawSupplierOrder);
2015 $duplicateSupplierOrders[$rawSupplierOrder->ref] [] = $supplierOrder;
2022 foreach ($duplicateSupplierOrders as $ref => $supplierOrders) {
2024 foreach (array_slice($supplierOrders, 1) as $supplierOrder) {
2027 $soc->fetch((
int) $supplierOrder->fourn_id);
2029 $newRef = $supplierOrder->getNextNumRef($soc);
2031 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"commande_fournisseur cf SET cf.ref = '" . $db->escape($newRef) .
"' WHERE cf.rowid = " . (int) $supplierOrder->id;
2032 if (!$db->query($sql)) {
2048if ($ok &&
GETPOST(
'recalculateinvoicetotal') ==
'confirmed') {
2054 SUM(fd.total_ht) as total_ht
2055 FROM ".MAIN_DB_PREFIX.
"facture f
2056 LEFT JOIN ".MAIN_DB_PREFIX.
"facturedet fd
2057 ON fd.fk_facture = f.rowid
2058 WHERE f.total_ht = 0
2059 GROUP BY fd.fk_facture HAVING SUM(fd.total_ht) <> 0";
2060 $resql = $db->query($sql);
2062 $num = $db->num_rows($resql);
2063 print
"We found ".$num.
" factures qualified that will have their total recalculated because they are at zero and line items not at zero\n";
2064 dol_syslog(
"We found ".$num.
" factures qualified that will have their total recalculated because they are at zero and line items not at zero");
2069 $obj = $db->fetch_object($resql);
2072 SUM(fd.total_ht) as 'total_ht',
2073 SUM(fd.total_tva) as 'total_tva',
2074 SUM(fd.total_localtax1) as 'localtax1',
2075 SUM(fd.total_localtax2) as 'localtax2',
2076 SUM(fd.total_ttc) as 'total_ttc'
2078 ".MAIN_DB_PREFIX.
"facturedet fd
2080 fd.fk_facture = ".((int) $obj->rowid);
2081 $ressql_calculs = $db->query($sql_calculs);
2082 while ($obj_calcul = $db->fetch_object($ressql_calculs)) {
2084 $sql_paiements =
"SELECT SUM(amount) as somme from ".MAIN_DB_PREFIX.
"paiement_facture WHERE fk_facture = ".((int) $obj->rowid);
2085 $montantPaiements = $db->fetch_object($db->query($sql_paiements))->somme;
2086 $totHt = ($obj_calcul->total_ht ?
price2num($obj_calcul->total_ht,
'MT') : 0);
2087 $totTva = ($obj_calcul->total_tva ?
price2num($obj_calcul->total_tva,
'MT') : 0);
2088 $totLocal1 = ($obj_calcul->localtax1 ?
price2num($obj_calcul->localtax1,
'MT') : 0);
2089 $totLocal2 = ($obj_calcul->localtax2 ?
price2num($obj_calcul->localtax2,
'MT') : 0);
2090 $totTtc = $totHt + $totTva + $totLocal1 + $totLocal2;
2092 UPDATE ".MAIN_DB_PREFIX.
"facture
2094 total_ht = ".((float) $totHt).
",
2095 total_tva = ".((float) $totTva).
",
2096 localtax1 = ".((float) $totLocal1).
",
2097 localtax2 = ".((float) $totLocal2).
",
2098 total_ttc = ".((float) $totTtc).
",
2099 fk_statut = ".($totTtc ==
price2num($montantPaiements,
'MT') ? 2 : 1).
",
2100 paid = ".($totTtc ==
price2num($montantPaiements,
'MT') ? 1 : 0).
"
2102 rowid = ".((
int) $obj->rowid);
2103 $db->query($sql_maj);
2108 print
"Pas de factures à traiter\n";
2111 dol_print_error($db);
2112 dol_syslog(
"calculate_total_and_taxes.php: Error");
2124if ($ok &&
GETPOST(
'repair_mailing_path')) {
2126 $sav_user = is_object($user) ? clone $user : $user;
2128 require_once DOL_DOCUMENT_ROOT.
'/comm/mailing/class/mailing.class.php';
2129 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
2131 print
'<tr><td colspan="2"><br>*** Repair mailing path<br>';
2139 function migrate_mailing_filespath($mailing)
2141 global $db,
$conf, $user;
2143 $dir =
$conf->mailing->dir_output;
2144 $origin = $dir.
'/'.
get_exdir($mailing->id, 2, 0, 1, $mailing,
'mailing');
2145 $destin = $dir.
'/'.
get_exdir($mailing->id, 0, 0, 1, $mailing,
'mailing');
2151 $user =
new User($db);
2152 $user->fetch($mailing->user_creation_id);
2155 $handle = opendir($origin_osencoded);
2156 if (is_resource($handle)) {
2157 while (($file = readdir($handle)) !==
false) {
2158 if ($file !=
'.' && $file !=
'..' && is_dir($origin_osencoded.
'/'.$file)) {
2159 $thumbs = opendir($origin_osencoded.
'/'.$file);
2160 if (is_resource($thumbs)) {
2162 while (($thumb = readdir($thumbs)) !==
false) {
2163 $res =
dol_move($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb);
2164 $msg = ($res ?
' * Migration successful' :
'Migration failed') .
' for file '.$origin.
'/'.$file.
'.<br>';
2171 $res =
dol_move($origin.
'/'.$file, $destin.
'/'.$file);
2172 $msg = ($res ?
' * Migration successful' :
'Migration failed') .
' for file '.$origin.
'/'.$file.
'.<br>';
2183 $sql =
"SELECT rowid as mid from ".MAIN_DB_PREFIX.
"mailing";
2184 $resql = $db->query($sql);
2186 while ($obj = $db->fetch_object($resql)) {
2187 $mailing->fetch($obj->mid);
2188 print
"Migrating mailing id=".$mailing->id.
" ref=".$mailing->ref.
"<br>\n";
2189 migrate_mailing_filespath($mailing);
2193 dol_print_error($db);
2203if (empty($actiondone)) {
2204 print
'<div class="error">'.$langs->trans(
"ErrorWrongParameters").
'</div>';
2209 print
'<div class="center" style="padding-top: 10px"><a href="../index.php?mainmenu=home&leftmenu=home'.(GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
2210 print img_picto(
'',
'url',
'class="pictofixedwidth"');
2211 print $langs->trans(
"GoToDolibarr");
2218if ($db->connected) {
2223if (!$ok && isset($argv[1])) {
$id
Support class for third parties, contacts, members, users or resources.
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.
Class for managing the social charges.
Class to manage predefined suppliers products.
Class to manage customers orders.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage emailings module.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
if(! $sortfield) if(! $sortorder) $module
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
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_dir_list($utf8_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_is_dir($folder)
Test if filename is a directory.
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
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.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.