41 include_once
'inc.php';
42 if (!file_exists($conffile)) {
43 print
'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
45 require_once $conffile;
46 require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
47 require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
48 require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
49 require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
50 require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
51 require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
52 require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
53 require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
64 $err = error_reporting();
66 if (!empty($conf->global->MAIN_OVERRIDE_TIME_LIMIT)) {
67 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
71 error_reporting($err);
73 $setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
74 $langs->setDefaultLang($setuplang);
75 $versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
76 $versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
77 $enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
79 $langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
81 if ($dolibarr_main_db_type ==
'mysqli') {
84 if ($dolibarr_main_db_type ==
'pgsql') {
87 if ($dolibarr_main_db_type ==
'mssql') {
92 dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
93 if (!is_object($conf)) {
103 if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
104 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
105 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
107 $sapi_type = php_sapi_name();
108 $script_file = basename(__FILE__);
110 if (substr($sapi_type, 0, 3) ==
'cli') {
111 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
116 pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
119 if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
120 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
121 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
123 print
'<table border="0" width="100%">';
126 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
127 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
128 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
129 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
130 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
131 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
133 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
138 $conf->db->type = $dolibarr_main_db_type;
139 $conf->db->host = $dolibarr_main_db_host;
140 $conf->db->port = $dolibarr_main_db_port;
141 $conf->db->name = $dolibarr_main_db_name;
142 $conf->db->user = $dolibarr_main_db_user;
143 $conf->db->pass = $dolibarr_main_db_pass;
145 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
147 if (!$db->connected) {
148 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
149 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
154 if ($db->database_selected) {
161 if (empty($dolibarr_main_db_encryption)) {
162 $dolibarr_main_db_encryption = 0;
164 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
165 if (empty($dolibarr_main_db_cryptkey)) {
166 $dolibarr_main_db_cryptkey =
'';
168 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
171 $conf->setValues($db);
174 $listofentities = array(1);
177 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
179 $hookmanager->initHooks(array(
'upgrade2'));
181 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
182 $object =
new stdClass();
184 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters, $object, $action);
185 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
187 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
198 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
200 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
224 foreach ($listofentities as $entity) {
226 $conf->setEntityValues($db, $entity);
228 if (defined(
'SYSLOG_FILE')) {
229 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
231 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
234 if (count($listofentities) > 1) {
235 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
240 $dolibarrlastupgradeversionarray = preg_split(
'/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL :
''));
246 $versiontoarray = explode(
'.', $versionto);
247 $versionranarray = explode(
'.', DOL_VERSION);
250 $afterversionarray = explode(
'.',
'2.0.0');
251 $beforeversionarray = explode(
'.',
'2.7.9');
312 $afterversionarray = explode(
'.',
'2.7.9');
313 $beforeversionarray = explode(
'.',
'2.8.9');
338 $afterversionarray = explode(
'.',
'2.8.9');
339 $beforeversionarray = explode(
'.',
'2.9.9');
351 $afterversionarray = explode(
'.',
'2.9.9');
352 $beforeversionarray = explode(
'.',
'3.0.9');
358 $afterversionarray = explode(
'.',
'3.0.9');
359 $beforeversionarray = explode(
'.',
'3.1.9');
367 $afterversionarray = explode(
'.',
'3.1.9');
368 $beforeversionarray = explode(
'.',
'3.2.9');
378 $afterversionarray = explode(
'.',
'3.2.9');
379 $beforeversionarray = explode(
'.',
'3.3.9');
388 $afterversionarray = explode(
'.',
'3.6.9');
389 $beforeversionarray = explode(
'.',
'3.7.9');
395 $afterversionarray = explode(
'.',
'3.7.9');
396 $beforeversionarray = explode(
'.',
'3.8.9');
402 $afterversionarray = explode(
'.',
'3.9.9');
403 $beforeversionarray = explode(
'.',
'4.0.9');
409 $afterversionarray = explode(
'.',
'4.0.9');
410 $beforeversionarray = explode(
'.',
'5.0.9');
420 $afterversionarray = explode(
'.',
'5.0.9');
421 $beforeversionarray = explode(
'.',
'6.0.9');
424 global $multicompany_transverse_mode;
427 if (empty($multicompany_transverse_mode)) {
438 $afterversionarray = explode(
'.',
'6.0.9');
439 $beforeversionarray = explode(
'.',
'7.0.9');
448 $afterversionarray = explode(
'.',
'7.0.9');
449 $beforeversionarray = explode(
'.',
'8.0.9');
455 $afterversionarray = explode(
'.',
'8.0.9');
456 $beforeversionarray = explode(
'.',
'9.0.9');
462 $afterversionarray = explode(
'.',
'10.0.9');
463 $beforeversionarray = explode(
'.',
'11.0.9');
472 $afterversionarray = explode(
'.',
'13.0.9');
473 $beforeversionarray = explode(
'.',
'14.0.9');
480 $afterversionarray = explode(
'.',
'15.0.9');
481 $beforeversionarray = explode(
'.',
'16.0.9');
488 $afterversionarray = explode(
'.',
'16.0.9');
489 $beforeversionarray = explode(
'.',
'17.0.9');
495 $afterversionarray = explode(
'.',
'170.9');
496 $beforeversionarray = explode(
'.',
'18.0.9');
506 $listofmodule = array(
507 'MAIN_MODULE_ACCOUNTING'=>
'newboxdefonly',
508 'MAIN_MODULE_AGENDA'=>
'newboxdefonly',
509 'MAIN_MODULE_BOM'=>
'menuonly',
510 'MAIN_MODULE_BANQUE'=>
'menuonly',
511 'MAIN_MODULE_BARCODE'=>
'newboxdefonly',
512 'MAIN_MODULE_CRON'=>
'newboxdefonly',
513 'MAIN_MODULE_COMMANDE'=>
'newboxdefonly',
514 'MAIN_MODULE_BLOCKEDLOG'=>
'noboxes',
515 'MAIN_MODULE_DEPLACEMENT'=>
'newboxdefonly',
516 'MAIN_MODULE_DON'=>
'newboxdefonly',
517 'MAIN_MODULE_ECM'=>
'newboxdefonly',
518 'MAIN_MODULE_EXTERNALSITE'=>
'newboxdefonly',
519 'MAIN_MODULE_EXPENSEREPORT'=>
'newboxdefonly',
520 'MAIN_MODULE_FACTURE'=>
'newboxdefonly',
521 'MAIN_MODULE_FOURNISSEUR'=>
'newboxdefonly',
522 'MAIN_MODULE_HOLIDAY'=>
'newboxdefonly',
523 'MAIN_MODULE_MARGIN'=>
'menuonly',
524 'MAIN_MODULE_MRP'=>
'menuonly',
525 'MAIN_MODULE_OPENSURVEY'=>
'newboxdefonly',
526 'MAIN_MODULE_PAYBOX'=>
'newboxdefonly',
527 'MAIN_MODULE_PRINTING'=>
'newboxdefonly',
528 'MAIN_MODULE_PRODUIT'=>
'newboxdefonly',
529 'MAIN_MODULE_RECRUITMENT'=>
'menuonly',
530 'MAIN_MODULE_RESOURCE'=>
'noboxes',
531 'MAIN_MODULE_SALARIES'=>
'newboxdefonly',
532 'MAIN_MODULE_SERVICE'=>
'newboxdefonly',
533 'MAIN_MODULE_SYSLOG'=>
'newboxdefonly',
534 'MAIN_MODULE_SOCIETE'=>
'newboxdefonly',
535 'MAIN_MODULE_STRIPE'=>
'menuonly',
536 'MAIN_MODULE_TICKET'=>
'newboxdefonly',
537 'MAIN_MODULE_TAKEPOS'=>
'newboxdefonly',
538 'MAIN_MODULE_USER'=>
'newboxdefonly',
539 'MAIN_MODULE_VARIANTS'=>
'newboxdefonly',
540 'MAIN_MODULE_WEBSITE'=>
'newboxdefonly',
556 if (!$error && $enablemodules) {
558 $listofmodules = array();
559 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
560 $tmplistofmodules = explode(
',', $enablemodules);
561 foreach ($tmplistofmodules as $value) {
562 $listofmodules[$value] =
'forceactivate';
566 if ($resultreloadmodules < 0) {
574 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
575 $object =
new stdClass();
577 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters, $object, $action);
578 if ($hookmanager->resNbOfHooks > 0) {
580 print
'<tr><td colspan="4">';
581 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
582 print $hookmanager->error;
583 print
"<!-- (".$reshook.
") -->";
586 print
'<tr class="trforrunsql"><td colspan="4">';
587 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
588 print
"<!-- (".$reshook.
") -->";
593 if (!empty($conf->modules_parts[
'hooks'])) {
594 print
'<tr class="trforrunsql"><td colspan="4">';
595 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
606 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
621 foreach ($listofentities as $entity) {
623 $conf->setEntityValues($db, $entity);
625 if (defined(
'SYSLOG_FILE')) {
626 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
628 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
632 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
633 $destroot = DOL_DATA_ROOT.
'/medias';
646 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
647 $object =
new stdClass();
649 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters, $object, $action);
650 if ($hookmanager->resNbOfHooks > 0) {
652 print
'<tr><td colspan="4">';
653 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
654 print $hookmanager->error;
655 print
"<!-- (".$reshook.
") -->";
658 print
'<tr class="trforrunsql"><td colspan="4">';
659 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
660 print
"<!-- (".$reshook.
") -->";
665 if (!empty($conf->modules_parts[
'hooks'])) {
666 print
'<tr class="trforrunsql"><td colspan="4">';
667 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
677 print
'<table width="100%">';
678 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
679 print
'<td class="right">';
683 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
687 print
'<script type="text/javascript">
688 jQuery(document).ready(function() {
689 function init_trrunsql()
691 console.log("toggle .trforrunsql");
692 jQuery(".trforrunsql").toggle();
695 jQuery(".trforrunsqlshowhide").click(function() {
700 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
703 print
'</td></tr>'.
"\n";
709 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
714 if ($error && isset($argv[1])) {
720 pFooter($error ? 2 : 0, $setuplang);
722 if ($db->connected) {
743 print
'<tr><td colspan="4">';
746 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
748 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
749 $obj = $db->fetch_object($result);
751 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
752 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
753 $sql .=
" WHERE p.fk_facture > 0";
755 $resql = $db->query($sql);
761 $num = $db->num_rows(
$resql);
764 $obj = $db->fetch_object(
$resql);
765 $row[$i][0] = $obj->rowid;
766 $row[$i][1] = $obj->fk_facture;
767 $row[$i][2] = $obj->amount;
775 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
779 for ($i = 0; $i < $num; $i++) {
780 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
781 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((
float) $row[$i][2]).
")";
783 $res += $db->query($sql);
785 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
787 $res += $db->query($sql);
789 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
793 if ($res == (2 * count($row))) {
795 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
798 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
801 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
804 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
822 print
'<tr><td colspan="4">';
825 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
827 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
828 $obj = $db->fetch_object($result);
831 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
832 $sql .=
" bu2.url_id as socid";
833 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
834 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
835 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
836 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
837 $sql .=
" AND b.rappro = 1";
838 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
840 $resql = $db->query($sql);
846 $num = $db->num_rows(
$resql);
849 $obj = $db->fetch_object(
$resql);
850 if ($obj->pamount == $obj->bamount && $obj->socid) {
851 $row[$j][
'paymentid'] = $obj->rowid;
852 $row[$j][
'pamount'] = $obj->pamount;
853 $row[$j][
'fk_bank'] = $obj->fk_bank;
854 $row[$j][
'bamount'] = $obj->bamount;
855 $row[$j][
'socid'] = $obj->socid;
856 $row[$j][
'datec'] = $obj->datec;
866 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
871 for ($i = 0; $i < $num; $i++) {
872 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
873 print
'* '.$row[$i][
'datec'].
' paymentid='.$row[$i][
'paymentid'].
' pamount='.$row[$i][
'pamount'].
' fk_bank='.$row[$i][
'fk_bank'].
' bamount='.$row[$i][
'bamount'].
' socid='.$row[$i][
'socid'].
'<br>';
877 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
878 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
879 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((
float) $row[$i][
'pamount']);
880 $sql .=
" AND pf.fk_facture IS NULL";
881 $sql .=
" ORDER BY f.fk_statut";
883 $resql = $db->query($sql);
885 $num = $db->num_rows(
$resql);
888 $obj = $db->fetch_object(
$resql);
889 $facid = $obj->rowid;
891 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
892 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((
float) $row[$i][
'pamount']).
")";
894 $res += $db->query($sql);
896 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
904 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
906 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
911 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
914 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
932 print
'<tr><td colspan="4">';
935 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
937 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
938 $obj = $db->fetch_object($result);
941 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
942 $sql .=
" bu2.url_id as socid";
943 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
944 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
945 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
946 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
947 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
949 $resql = $db->query($sql);
955 $num = $db->num_rows(
$resql);
958 $obj = $db->fetch_object(
$resql);
959 if ($obj->pamount == $obj->bamount && $obj->socid) {
960 $row[$j][
'paymentid'] = $obj->rowid;
961 $row[$j][
'pamount'] = $obj->pamount;
962 $row[$j][
'fk_bank'] = $obj->fk_bank;
963 $row[$j][
'bamount'] = $obj->bamount;
964 $row[$j][
'socid'] = $obj->socid;
965 $row[$j][
'datec'] = $obj->datec;
978 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
982 for ($i = 0; $i < $num; $i++) {
983 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
984 print
'* '.$row[$i][
'datec'].
' paymentid='.$row[$i][
'paymentid'].
' pamount='.$row[$i][
'pamount'].
' fk_bank='.$row[$i][
'fk_bank'].
' '.$row[$i][
'bamount'].
' socid='.$row[$i][
'socid'].
'<br>';
988 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
989 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
990 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((
float) $row[$i][
'pamount']);
991 $sql .=
" AND pf.fk_facture IS NULL";
992 $sql .=
" ORDER BY f.fk_statut";
994 $resql = $db->query($sql);
996 $num = $db->num_rows(
$resql);
999 $obj = $db->fetch_object(
$resql);
1000 $facid = $obj->rowid;
1002 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1003 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((
float) $row[$i][
'pamount']).
")";
1005 $res += $db->query($sql);
1007 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1016 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1018 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1023 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1029 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1039 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1056 print
'<tr><td colspan="4">';
1061 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1063 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1064 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1065 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1066 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1067 $sql .=
" ON c.fk_product = p.rowid";
1068 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1069 $sql .=
" ON c.rowid=cd.fk_contrat";
1070 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1071 $resql = $db->query($sql);
1077 $num = $db->num_rows(
$resql);
1080 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1084 $obj = $db->fetch_object(
$resql);
1086 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1087 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1088 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1089 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1090 $sql .=
" VALUES (";
1091 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1093 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1094 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1097 $sql .= ((
float) $obj->tva_tx).
", 1, ";
1098 $sql .= ((
float) $obj->price).
", ".((
float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1102 if ($db->query($sql)) {
1103 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1115 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1118 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1121 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1124 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1141 print
'<tr><td colspan="4">';
1146 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1148 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1149 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1150 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1151 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1152 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1153 $sql .=
" AND bu.fk_bank IS NULL";
1154 $resql = $db->query($sql);
1160 $num = $db->num_rows(
$resql);
1163 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1167 $obj = $db->fetch_object(
$resql);
1169 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1170 $sql .=
"fk_bank, url_id, url, label, type";
1172 $sql .=
" VALUES (";
1173 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1179 if (!$db->query($sql)) {
1190 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1193 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1196 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1215 print
'<tr><td colspan="4">';
1218 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1220 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1222 $resql = $db->query($sql);
1226 if ($db->affected_rows(
$resql) > 0) {
1227 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1229 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1232 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1234 $resql = $db->query($sql);
1238 if ($db->affected_rows(
$resql) > 0) {
1239 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1241 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1257 print
'<tr><td colspan="4">';
1262 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1264 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1265 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1266 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1267 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1268 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1269 $resql = $db->query($sql);
1275 $num = $db->num_rows(
$resql);
1278 $nbcontratsmodifie = 0;
1282 $obj = $db->fetch_object(
$resql);
1283 if ($obj->date_contrat > $obj->datemin) {
1284 $datemin = $db->jdate($obj->datemin);
1286 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1287 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1288 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1289 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1290 $resql2 = $db->query($sql);
1295 $nbcontratsmodifie++;
1302 if ($nbcontratsmodifie) {
1303 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1305 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1325 print
'<tr><td colspan="4">';
1328 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1330 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1332 $resql = $db->query($sql);
1336 if ($db->affected_rows(
$resql) > 0) {
1337 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1339 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1355 print
'<tr><td colspan="4">';
1358 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1360 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1361 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1363 $resql = $db->query($sql);
1367 if ($db->affected_rows(
$resql) > 0) {
1370 $num = $db->num_rows(
$resql);
1373 $nbcontratsmodifie = 0;
1377 $obj = $db->fetch_object(
$resql);
1379 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1380 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1381 $sql .=
" SET statut = 1";
1382 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1383 $resql2 = $db->query($sql);
1388 $nbcontratsmodifie++;
1395 if ($nbcontratsmodifie) {
1396 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1398 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1402 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1420 print
'<tr><td colspan="4">';
1422 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1425 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1426 $obj = $db->fetch_object($result);
1431 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1432 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1433 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1436 $select_resql = $db->query($select_sql);
1437 if ($select_resql) {
1438 $select_num = $db->num_rows($select_resql);
1442 while (($i < $select_num) && (!$error)) {
1443 $select_obj = $db->fetch_object($select_resql);
1446 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1447 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1448 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1449 $check_resql = $db->query($check_sql);
1451 $check_num = $db->num_rows($check_resql);
1452 if ($check_num == 0) {
1456 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1457 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1460 print
'<tr class="oddeven">';
1461 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1463 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1464 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1465 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1466 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1467 $insert_resql = $db->query($insert_sql);
1469 if ($insert_resql) {
1471 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1473 print
'<td><span class="error">Error on insert</span></td>';
1489 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1493 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1496 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1500 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1517 $tmpmysoc->setMysoc($conf);
1521 print
'<tr><td colspan="4">';
1524 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1527 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1528 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1529 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1530 $sql .=
" WHERE fd.fk_facture = f.rowid";
1531 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1535 $resql = $db->query($sql);
1537 $num = $db->num_rows(
$resql);
1541 $obj = $db->fetch_object(
$resql);
1543 $rowid = $obj->rowid;
1545 $pu = $obj->subprice;
1546 $vatrate = $obj->vatrate;
1547 $remise_percent = $obj->remise_percent;
1548 $remise_percent_global = $obj->remise_percent_global;
1549 $total_ttc_f = $obj->total_ttc_f;
1550 $info_bits = $obj->info_bits;
1554 $facligne->fetch($rowid);
1556 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1557 $total_ht = $result[0];
1558 $total_tva = $result[1];
1559 $total_ttc = $result[2];
1561 $facligne->total_ht = $total_ht;
1562 $facligne->total_tva = $total_tva;
1563 $facligne->total_ttc = $total_ttc;
1565 dolibarr_install_syslog(
"upgrade2: line ".$rowid.
": facid=".$obj->facid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1567 $facligne->update_total();
1571 if (!$total_ttc_f) {
1573 $facture->id = $obj->facid;
1575 if ($facture->fetch($facture->id) >= 0) {
1576 if ($facture->update_price() > 0) {
1579 print
"Error id=".$facture->id;
1592 print $langs->trans(
"AlreadyDone");
1598 print
"Error #1 ".$db->error();
1620 $tmpmysoc->setMysoc($conf);
1624 print
'<tr><td colspan="4">';
1627 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1630 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1631 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1632 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1633 $sql .=
" WHERE pd.fk_propal = p.rowid";
1634 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1637 $resql = $db->query($sql);
1639 $num = $db->num_rows(
$resql);
1643 $obj = $db->fetch_object(
$resql);
1645 $rowid = $obj->rowid;
1647 $pu = $obj->subprice;
1648 $vatrate = $obj->vatrate;
1649 $remise_percent = $obj->remise_percent;
1650 $remise_percent_global = $obj->remise_percent_global;
1651 $info_bits = $obj->info_bits;
1655 $propalligne->fetch($rowid);
1657 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1658 $total_ht = $result[0];
1659 $total_tva = $result[1];
1660 $total_ttc = $result[2];
1662 $propalligne->total_ht = $total_ht;
1663 $propalligne->total_tva = $total_tva;
1664 $propalligne->total_ttc = $total_ttc;
1666 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": propalid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1668 $propalligne->update_total();
1693 print $langs->trans(
"AlreadyDone");
1700 print
"Error #1 ".$db->error();
1723 $tmpmysoc->setMysoc($conf);
1724 if (empty($tmpmysoc->country_id)) {
1725 $tmpmysoc->country_id = 0;
1728 print
'<tr><td colspan="4">';
1731 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1734 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1735 $sql .=
" c.rowid as contratid";
1736 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1737 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1738 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1741 $resql = $db->query($sql);
1743 $num = $db->num_rows(
$resql);
1747 $obj = $db->fetch_object(
$resql);
1749 $rowid = $obj->rowid;
1751 $pu = $obj->subprice;
1752 $vatrate = $obj->vatrate;
1753 $remise_percent = $obj->remise_percent;
1754 $info_bits = $obj->info_bits;
1759 $contratligne->fetch($rowid);
1761 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1762 $total_ht = $result[0];
1763 $total_tva = $result[1];
1764 $total_ttc = $result[2];
1766 $contratligne->total_ht = $total_ht;
1767 $contratligne->total_tva = $total_tva;
1768 $contratligne->total_ttc = $total_ttc;
1770 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": contratdetid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" -> ".$total_ht.
", ".$total_tva.
" , ".$total_ttc);
1772 $contratligne->update_total();
1777 print $langs->trans(
"AlreadyDone");
1784 print
"Error #1 ".$db->error();
1807 $tmpmysoc->setMysoc($conf);
1809 print
'<tr><td colspan="4">';
1812 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1815 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1816 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1817 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1818 $sql .=
" WHERE cd.fk_commande = c.rowid";
1819 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1822 $resql = $db->query($sql);
1824 $num = $db->num_rows(
$resql);
1828 $obj = $db->fetch_object(
$resql);
1830 $rowid = $obj->rowid;
1832 $pu = $obj->subprice;
1833 $vatrate = $obj->vatrate;
1834 $remise_percent = $obj->remise_percent;
1835 $remise_percent_global = $obj->remise_percent_global;
1836 $info_bits = $obj->info_bits;
1840 $commandeligne->fetch($rowid);
1842 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1843 $total_ht = $result[0];
1844 $total_tva = $result[1];
1845 $total_ttc = $result[2];
1847 $commandeligne->total_ht = $total_ht;
1848 $commandeligne->total_tva = $total_tva;
1849 $commandeligne->total_ttc = $total_ttc;
1851 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
" : commandeid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1853 $commandeligne->update_total();
1877 print $langs->trans(
"AlreadyDone");
1894 print
"Error #1 ".$db->error();
1917 $tmpmysoc->setMysoc($conf);
1919 print
'<tr><td colspan="4">';
1922 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1925 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1926 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1927 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1928 $sql .=
" WHERE cd.fk_commande = c.rowid";
1929 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1932 $resql = $db->query($sql);
1934 $num = $db->num_rows(
$resql);
1938 $obj = $db->fetch_object(
$resql);
1940 $rowid = $obj->rowid;
1942 $pu = $obj->subprice;
1943 $vatrate = $obj->vatrate;
1944 $remise_percent = $obj->remise_percent;
1945 $remise_percent_global = $obj->remise_percent_global;
1946 $info_bits = $obj->info_bits;
1950 $commandeligne->fetch($rowid);
1952 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpsoc);
1953 $total_ht = $result[0];
1954 $total_tva = $result[1];
1955 $total_ttc = $result[2];
1957 $commandeligne->total_ht = $total_ht;
1958 $commandeligne->total_tva = $total_tva;
1959 $commandeligne->total_ttc = $total_ttc;
1961 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": commandeid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1963 $commandeligne->update_total();
1987 print $langs->trans(
"AlreadyDone");
2004 print
"Error #1 ".$db->error();
2030 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2032 if (count($modellist) == 0) {
2034 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2035 $resql = $db->query($sql);
2043 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2045 if (count($modellist) == 0) {
2047 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2048 $resql = $db->query($sql);
2056 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2057 $modellist = ModelePDFExpedition::liste_modeles($db);
2058 if (count($modellist) == 0) {
2060 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2061 $resql = $db->query($sql);
2084 print
'<tr><td colspan="4">';
2087 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2089 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2090 $obj = $db->fetch_object($result);
2096 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2097 $resql = $db->query($sql);
2100 $num = $db->num_rows(
$resql);
2104 $obj = $db->fetch_object(
$resql);
2106 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2107 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2108 $resql2 = $db->query($sql);
2121 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2122 print $langs->trans(
'FieldRenamed').
"<br>\n";
2132 print $langs->trans(
'AlreadyDone').
"<br>\n";
2149 print
'<tr><td colspan="4">';
2152 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2154 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2155 $obj = $db->fetch_object($result);
2161 $sql =
"SELECT l.rowid, l.fk_commande,";
2162 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2163 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2164 $sql .=
" WHERE c.rowid = l.fk_commande";
2165 $resql = $db->query($sql);
2168 $num = $db->num_rows(
$resql);
2172 $obj = $db->fetch_object(
$resql);
2174 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2175 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2176 $resql2 = $db->query($sql);
2179 $delivery_date = $db->jdate($obj->delivery_date);
2181 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2182 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2183 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2184 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2185 $resql3 = $db->query($sqlu);
2201 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2202 print $langs->trans(
'FieldRenamed').
"<br>\n";
2212 print $langs->trans(
'AlreadyDone').
"<br>\n";
2229 print
'<tr><td colspan="4">';
2232 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2236 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2237 $obj = $db->fetch_object($result);
2243 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2244 $sql .=
", ld.fk_livraison";
2245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2246 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2247 $resql = $db->query($sql);
2250 $num = $db->num_rows(
$resql);
2254 $obj = $db->fetch_object(
$resql);
2256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2257 $sql .=
" fk_product = ".((int) $obj->fk_product);
2258 $sql .=
",description = '".$db->escape($obj->description).
"'";
2259 $sql .=
",subprice = ".price2num($obj->subprice);
2260 $sql .=
",total_ht = ".price2num($obj->total_ht);
2261 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2262 $resql2 = $db->query($sql);
2265 $sql =
"SELECT total_ht";
2266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2267 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2268 $resql3 = $db->query($sql);
2271 $obju = $db->fetch_object($resql3);
2272 $total_ht = $obju->total_ht + $obj->total_ht;
2274 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2275 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2276 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2277 $resql4 = $db->query($sqlu);
2297 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2298 print $langs->trans(
'FieldRenamed').
"<br>\n";
2308 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2309 $obj = $db->fetch_object($result);
2311 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2314 print $langs->trans(
'AlreadyDone').
"<br>\n";
2331 print
'<tr><td colspan="4">';
2334 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2340 $sql =
"SELECT SUM(reel) as total, fk_product";
2341 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2342 $sql .=
" GROUP BY fk_product";
2343 $resql = $db->query($sql);
2346 $num = $db->num_rows(
$resql);
2350 $obj = $db->fetch_object(
$resql);
2352 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2353 $sql .=
" stock = ".price2num($obj->total,
'MS');
2354 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2356 $resql2 = $db->query($sql);
2393 print
'<tr><td colspan="4">';
2396 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2400 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2403 $sql =
"SELECT m.rowid, mc.action";
2404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2405 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2406 $sql .=
" AND m.enabled = '1'";
2407 $resql = $db->query($sql);
2410 $num = $db->num_rows(
$resql);
2413 $obj = $db->fetch_object(
$resql);
2415 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2416 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2417 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2418 $sql .=
" AND enabled = '1'";
2420 $resql2 = $db->query($sql);
2441 print $langs->trans(
'AlreadyDone').
"<br>\n";
2460 print
'<tr><td colspan="4">';
2463 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2467 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2470 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2471 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2472 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2473 $sql .=
" WHERE c.rowid = ce.fk_commande";
2474 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2476 $resql = $db->query($sql);
2479 $num = $db->num_rows(
$resql);
2483 $obj = $db->fetch_object(
$resql);
2485 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2486 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2487 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2489 $resql2 = $db->query($sql);
2498 print $langs->trans(
'AlreadyDone').
"<br>\n";
2511 print $langs->trans(
'AlreadyDone').
"<br>\n";
2530 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2532 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2536 print
'<tr><td colspan="4">';
2539 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2545 $table1 =
'facturedet'; $field1 =
'fk_remise_except';
2546 $table2 =
'societe_remise_except'; $field2 =
'fk_facture_line';
2550 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2551 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2552 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2553 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2554 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2557 $resql = $db->query($sql);
2560 $num = $db->num_rows(
$resql);
2564 $obj = $db->fetch_object(
$resql);
2566 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2567 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2568 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2569 $sql .=
" WHERE rowid = ".((int) $obj->field);
2571 $resql2 = $db->query($sql);
2580 print $langs->trans(
'AlreadyDone').
"<br>\n";
2596 print
'<tr><td colspan="4">';
2599 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2602 $table2 =
'facturedet'; $field2 =
'fk_remise_except';
2603 $table1 =
'societe_remise_except'; $field1 =
'fk_facture_line';
2607 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2608 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2609 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2610 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2611 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2614 $resql = $db->query($sql);
2617 $num = $db->num_rows(
$resql);
2621 $obj = $db->fetch_object(
$resql);
2623 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2624 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2625 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2626 $sql .=
" WHERE rowid = ".((int) $obj->field);
2628 $resql2 = $db->query($sql);
2637 print $langs->trans(
'AlreadyDone').
"<br>\n";
2665 print
'<tr><td colspan="4">';
2668 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2670 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2671 $obj = $db->fetch_object($result);
2677 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2678 $resql = $db->query($sql);
2681 $num = $db->num_rows(
$resql);
2685 $obj = $db->fetch_object(
$resql);
2687 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2688 $sql2 .=
"datecreate";
2689 $sql2 .=
", statut";
2690 $sql2 .=
", element_id";
2691 $sql2 .=
", fk_c_type_contact";
2692 $sql2 .=
", fk_socpeople";
2693 $sql2 .=
") VALUES (";
2694 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2696 $sql2 .=
", ".$obj->rowid;
2698 $sql2 .=
", ".$obj->fk_user_resp;
2701 if ($obj->fk_user_resp > 0) {
2702 $resql2 = $db->query($sql2);
2715 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2716 if ($db->query($sqlDrop)) {
2729 print $langs->trans(
'AlreadyDone').
"<br>\n";
2746 print
'<tr><td colspan="4">';
2749 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2751 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2756 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2757 $resql = $db->query($sql);
2760 $num = $db->num_rows(
$resql);
2764 $obj = $db->fetch_object(
$resql);
2766 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2767 $sql2 .=
"datecreate";
2768 $sql2 .=
", statut";
2769 $sql2 .=
", element_id";
2770 $sql2 .=
", fk_c_type_contact";
2771 $sql2 .=
", fk_socpeople";
2772 $sql2 .=
") VALUES (";
2773 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2775 $sql2 .=
", ".$obj->fk_project_task;
2777 $sql2 .=
", ".$obj->fk_user;
2780 $resql2 = $db->query($sql2);
2792 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2793 if ($db->query($sqlDrop)) {
2806 print $langs->trans(
'AlreadyDone').
"<br>\n";
2826 print
'<tr><td colspan="4">';
2829 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2833 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2838 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2839 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2841 $resql = $db->query($sqlSelect);
2844 $num = $db->num_rows(
$resql);
2848 $obj = $db->fetch_object(
$resql);
2850 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2851 $sqlInsert .=
"fk_source";
2852 $sqlInsert .=
", sourcetype";
2853 $sqlInsert .=
", fk_target";
2854 $sqlInsert .=
", targettype";
2855 $sqlInsert .=
") VALUES (";
2856 $sqlInsert .= $obj->$fk_source;
2857 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2858 $sqlInsert .=
", ".$obj->$fk_target;
2859 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2862 $result = $db->query($sqlInsert);
2871 print $langs->trans(
'AlreadyDone').
"<br>\n";
2875 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2876 if ($db->query($sqlDrop)) {
2889 print $langs->trans(
'AlreadyDone').
"<br>\n";
2907 print
'<tr><td colspan="4">';
2910 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2916 $sql =
"SELECT rowid, fk_task, task_duration";
2917 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet_task_time";
2918 $resql = $db->query($sql);
2921 $num = $db->num_rows(
$resql);
2924 $totaltime = array();
2928 $obj = $db->fetch_object(
$resql);
2930 if ($obj->task_duration > 0) {
2933 list($hour, $min) = explode(
'.', $obj->task_duration);
2934 $hour = $hour * 60 * 60;
2935 $min = ($min / 100) * 60 * 60;
2936 $newtime = $hour + $min;
2938 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task_time SET";
2939 $sql2 .=
" task_duration = ".((int) $newtime);
2940 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2942 $resql2 = $db->query($sql2);
2949 if (!empty($totaltime[$obj->fk_task])) {
2950 $totaltime[$obj->fk_task] += $newtime;
2952 $totaltime[$obj->fk_task] = $newtime;
2955 if (!empty($totaltime[$obj->fk_task])) {
2956 $totaltime[$obj->fk_task] += $obj->task_duration;
2958 $totaltime[$obj->fk_task] = $obj->task_duration;
2967 foreach ($totaltime as $taskid => $total_duration) {
2968 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2969 $sql .=
" duration_effective = ".((int) $total_duration);
2970 $sql .=
" WHERE rowid = ".((int) $taskid);
2972 $resql = $db->query($sql);
2979 print $langs->trans(
'AlreadyDone').
"<br>\n";
2985 print $langs->trans(
'AlreadyDone').
"<br>\n";
3010 print
'<tr><td colspan="4">';
3013 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3017 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3018 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3019 $obj1 = $db->fetch_object($result1);
3020 $obj2 = $db->fetch_object($result2);
3021 if (!$obj1 && !$obj2) {
3026 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3027 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3029 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3030 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3031 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3032 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3033 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3034 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3035 $sqlSelect .=
" AND el.targettype = 'shipping'";
3037 $resql = $db->query($sqlSelect);
3040 $num = $db->num_rows(
$resql);
3044 $obj = $db->fetch_object(
$resql);
3046 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3047 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3048 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3049 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3051 $result = $db->query($sqlUpdate);
3060 print $langs->trans(
'AlreadyDone').
"<br>\n";
3078 print $langs->trans(
'AlreadyDone').
"<br>\n";
3094 print
'<tr><td colspan="4">';
3097 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3101 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3102 $obj = $db->fetch_object($result);
3108 $sqlSelect =
"SELECT rowid, fk_expedition";
3109 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3110 $sqlSelect .=
" WHERE fk_expedition is not null";
3112 $resql = $db->query($sqlSelect);
3115 $num = $db->num_rows(
$resql);
3119 $obj = $db->fetch_object(
$resql);
3121 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3122 $sqlInsert .=
"fk_source";
3123 $sqlInsert .=
", sourcetype";
3124 $sqlInsert .=
", fk_target";
3125 $sqlInsert .=
", targettype";
3126 $sqlInsert .=
") VALUES (";
3127 $sqlInsert .= $obj->fk_expedition;
3128 $sqlInsert .=
", 'shipping'";
3129 $sqlInsert .=
", ".$obj->rowid;
3130 $sqlInsert .=
", 'delivery'";
3133 $result = $db->query($sqlInsert);
3135 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3136 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3138 $result = $db->query($sqlUpdate);
3151 print $langs->trans(
'AlreadyDone').
"<br>\n";
3155 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3156 $db->query($sqlDelete);
3161 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3162 $db->query($sqlDrop);
3172 print $langs->trans(
'AlreadyDone').
"<br>\n";
3189 print
'<tr><td colspan="4">';
3192 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3200 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3201 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3202 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3203 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3204 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3205 $sqlSelect .=
" AND el.targettype = 'delivery'";
3206 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3207 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3209 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3210 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3212 $resql = $db->query($sqlSelect);
3215 $num = $db->num_rows(
$resql);
3219 $obj = $db->fetch_object(
$resql);
3221 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3222 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3223 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3224 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3226 $result = $db->query($sqlUpdate);
3235 print $langs->trans(
'AlreadyDone').
"<br>\n";
3262 print
'<tr><td colspan="4">';
3265 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3268 'propal' =>
'propalrowid',
3269 'order' =>
'fk_commande',
3270 'invoice' =>
'fk_facture',
3271 'contract' =>
'fk_contract',
3272 'order_supplier' =>
'fk_supplier_order',
3273 'invoice_supplier' =>
'fk_supplier_invoice'
3276 foreach ($elements as $type => $field) {
3277 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3278 $obj = $db->fetch_object($result);
3284 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3285 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3286 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3287 $sql .=
" AND fk_element IS NULL";
3288 $sql .=
" AND elementtype IS NULL";
3290 $resql = $db->query($sql);
3304 print $langs->trans(
'AlreadyDone').
"<br>\n";
3321 print
'<tr><td colspan="4">';
3324 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3327 'old_id' => array(5, 8, 9, 10, 11),
3328 'new_id' => array(50, 51, 52, 53, 54),
3329 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3330 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3334 foreach ($elements[
'old_id'] as $key => $old_id) {
3339 $sqlSelect =
"SELECT id";
3340 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3341 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3342 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3344 $resql = $db->query($sqlSelect);
3346 $num = $db->num_rows(
$resql);
3352 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3353 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3354 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3355 $sqla .=
" AND fk_paiement IN (SELECT id FROM ".MAIN_DB_PREFIX.
"c_paiement WHERE id = ".((int) $old_id).
" AND code = '".$db->escape($elements[
'code'][$key]).
"')";
3356 $resqla = $db->query($sqla);
3358 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3359 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3360 $sql .=
" WHERE id = ".((int) $old_id);
3361 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3362 $resql = $db->query($sql);
3365 foreach ($elements[
'tables'] as $table) {
3366 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3367 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3368 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3370 $resql = $db->query($sql);
3393 print $langs->trans(
'AlreadyDone').
"<br>\n";
3411 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3413 $obj = $db->fetch_object($result);
3417 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3418 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3420 $resql = $db->query($sql);
3422 $num = $db->num_rows(
$resql);
3423 while ($obj = $db->fetch_object(
$resql)) {
3424 if (!isset($filles[$obj->fk_categorie_fille])) {
3425 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3426 $filles[$obj->fk_categorie_fille] = 1;
3427 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere'=>$obj->fk_categorie_mere,
'fille'=>$obj->fk_categorie_fille);
3435 if (count($couples) > 0 && $num > count($couples)) {
3441 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3443 $resqld = $db->query($sql);
3446 foreach ($couples as $key => $val) {
3447 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3448 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3450 $resqli = $db->query($sql);
3458 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3459 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3462 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3463 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3468 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3469 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3486 print
'<tr><td colspan="4">';
3489 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3493 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3498 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3499 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3501 $resql = $db->query($sqlSelect);
3504 $num = $db->num_rows(
$resql);
3508 $obj = $db->fetch_object(
$resql);
3510 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3511 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3512 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3514 $result = $db->query($sqlUpdate);
3523 print $langs->trans(
'AlreadyDone').
"<br>\n";
3536 print $langs->trans(
'AlreadyDone').
"<br>\n";
3552 print
'<tr><td colspan="4">';
3555 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3563 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3564 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3565 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action";
3566 $sqlSelect .=
" WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX.
"actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')";
3567 $sqlSelect .=
" ORDER BY a.id";
3570 $resql = $db->query($sqlSelect);
3573 $num = $db->num_rows(
$resql);
3577 $obj = $db->fetch_object(
$resql);
3579 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3580 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3582 $result = $db->query($sqlUpdate);
3591 print $langs->trans(
'AlreadyDone').
"<br>\n";
3618 print
'<tr><td colspan="4">';
3621 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3629 $sqlSelect =
"SELECT a.id, a.fk_contact";
3630 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3631 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople' AND ar.fk_element = a.fk_contact";
3632 $sqlSelect .=
" WHERE fk_contact > 0 AND fk_contact NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX.
"actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople')";
3633 $sqlSelect .=
" ORDER BY a.id";
3636 $resql = $db->query($sqlSelect);
3639 $num = $db->num_rows(
$resql);
3643 $obj = $db->fetch_object(
$resql);
3645 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3646 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3648 $result = $db->query($sqlUpdate);
3657 print $langs->trans(
'AlreadyDone').
"<br>\n";
3687 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3689 print
'<tr><td colspan="4">';
3692 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3700 $sqlSelect =
"SELECT DISTINCT entity";
3701 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3705 $resql = $db->query($sqlSelect);
3708 $num = $db->num_rows(
$resql);
3712 $obj = $db->fetch_object(
$resql);
3714 print
'Process entity '.$obj->entity;
3716 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3717 $resqlSearch = $db->query($sqlSearch);
3719 $objSearch = $db->fetch_object($resqlSearch);
3721 if ($objSearch && $objSearch->nb == 0) {
3722 print
' - Record for entity must be reset...';
3724 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3725 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3726 $resqlUpdate = $db->query($sqlUpdate);
3727 if (!$resqlUpdate) {
3732 $object =
new stdClass();
3734 $object->element =
'module';
3735 $object->ref =
'systemevent';
3736 $object->entity = $obj->entity;
3740 $b->setObjectData($object,
'MODULE_SET', 0);
3742 $res = $b->create($user);
3748 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3757 print $langs->trans(
'NothingToDo').
"<br>\n";
3784 print
'<tr><td colspan="4">';
3787 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3795 $sqlSelect =
"SELECT sr.rowid, s.entity";
3796 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3797 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3801 $resql = $db->query($sqlSelect);
3804 $num = $db->num_rows(
$resql);
3808 $obj = $db->fetch_object(
$resql);
3810 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3811 $sqlUpdate .=
" entity = ".$obj->entity;
3812 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3814 $result = $db->query($sqlUpdate);
3824 print $langs->trans(
'AlreadyDone').
"<br>\n";
3850 print
'<tr><td colspan="4">';
3853 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3861 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3862 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3865 $resql = $db->query($sqlSelect);
3868 $num = $db->num_rows(
$resql);
3872 $obj = $db->fetch_object(
$resql);
3874 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3875 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3877 $sqlSelect2 =
"SELECT f.entity";
3878 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3879 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3880 } elseif (!empty($obj->fk_facture_line)) {
3881 $sqlSelect2 =
"SELECT f.entity";
3882 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3883 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3884 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3886 $sqlSelect2 =
"SELECT s.entity";
3887 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3888 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3891 $resql2 = $db->query($sqlSelect2);
3893 if ($db->num_rows($resql2) > 0) {
3894 $obj2 = $db->fetch_object($resql2);
3896 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3897 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3898 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3900 $result = $db->query($sqlUpdate);
3915 print $langs->trans(
'AlreadyDone').
"<br>\n";
3942 print
'<tr><td colspan="4">';
3944 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3952 $sqlSelect =
"SELECT u.rowid, u.entity";
3953 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3954 $sqlSelect .=
" WHERE u.entity > 1";
3957 $resql = $db->query($sqlSelect);
3960 $num = $db->num_rows(
$resql);
3964 $obj = $db->fetch_object(
$resql);
3966 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3967 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3968 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3970 $result = $db->query($sqlUpdate);
3980 print $langs->trans(
'AlreadyDone').
"<br>\n";
4007 print
'<tr><td colspan="4">';
4009 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4017 $sqlSelect =
"SELECT u.rowid, u.entity";
4018 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4019 $sqlSelect .=
" WHERE u.entity > 1";
4022 $resql = $db->query($sqlSelect);
4025 $num = $db->num_rows(
$resql);
4029 $obj = $db->fetch_object(
$resql);
4031 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4032 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4033 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4035 $result = $db->query($sqlUpdate);
4045 print $langs->trans(
'AlreadyDone').
"<br>\n";
4076 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4077 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4078 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4098 $filetodeletearray = array(
4099 '/core/triggers/interface_demo.class.php',
4100 '/core/menus/barre_left/default.php',
4101 '/core/menus/barre_top/default.php',
4102 '/core/modules/modComptabiliteExpert.class.php',
4103 '/core/modules/modCommercial.class.php',
4104 '/core/modules/modProduit.class.php',
4105 '/core/modules/modSkype.class.php',
4106 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4107 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4108 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4109 '/core/triggers/interface_modCommande_Ecotax.class.php',
4110 '/core/triggers/interface_modCommande_fraisport.class.php',
4111 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4112 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4113 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4114 '/core/menus/smartphone/iphone.lib.php',
4115 '/core/menus/smartphone/iphone_backoffice.php',
4116 '/core/menus/smartphone/iphone_frontoffice.php',
4117 '/core/menus/standard/auguria_backoffice.php',
4118 '/core/menus/standard/auguria_frontoffice.php',
4119 '/core/menus/standard/eldy_backoffice.php',
4120 '/core/menus/standard/eldy_frontoffice.php',
4121 '/core/modules/mailings/contacts2.modules.php',
4122 '/core/modules/mailings/contacts3.modules.php',
4123 '/core/modules/mailings/contacts4.modules.php',
4124 '/core/modules/mailings/framboise.modules.php',
4125 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4126 '/core/modules/mailings/peche.modules.php',
4127 '/core/modules/mailings/poire.modules.php',
4128 '/core/modules/mailings/kiwi.modules.php',
4129 '/core/modules/facture/pdf_crabe.modules.php',
4130 '/core/modules/facture/pdf_oursin.modules.php',
4131 '/core/modules/export/export_excel.modules.php',
4132 '/core/modules/export/export_excel2007new.modules.php',
4133 '/core/boxes/box_members.php',
4135 '/api/class/api_generic.class.php',
4136 '/asterisk/cidlookup.php',
4137 '/categories/class/api_category.class.php',
4138 '/categories/class/api_deprecated_category.class.php',
4139 '/compta/facture/class/api_invoice.class.php',
4140 '/commande/class/api_commande.class.php',
4141 '/user/class/api_user.class.php',
4142 '/product/class/api_product.class.php',
4143 '/societe/class/api_contact.class.php',
4144 '/societe/class/api_thirdparty.class.php',
4145 '/support/online.php',
4146 '/takepos/class/actions_takepos.class.php',
4148 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4149 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4150 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4151 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4152 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4153 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4156 foreach ($filetodeletearray as $filetodelete) {
4158 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4159 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true,
false);
4161 $langs->load(
"errors");
4162 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4163 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4188 $filetodeletearray = array(
4189 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4190 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4194 if (!empty($_SERVER[
"WINDIR"])) {
4195 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4198 foreach ($filetodeletearray as $filetodelete) {
4200 if (file_exists($filetodelete)) {
4204 $langs->load(
"errors");
4205 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4206 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4228 if (count($listofmodule) == 0) {
4232 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".join(
',', array_keys($listofmodule)));
4234 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4235 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4241 if ($moduletoreload ==
'MAIN_MODULE_AGENDA') {
4243 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modAgenda.class.php';
4246 $mod->remove(
'noboxes');
4247 $mod->init($reloadmode);
4249 } elseif ($moduletoreload ==
'MAIN_MODULE_API') {
4251 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modApi.class.php';
4255 $mod->init($reloadmode);
4257 } elseif ($moduletoreload ==
'MAIN_MODULE_BARCODE') {
4259 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modBarcode.class.php';
4262 $mod->remove(
'noboxes');
4263 $mod->init($reloadmode);
4265 } elseif ($moduletoreload ==
'MAIN_MODULE_BLOCKEDLOG') {
4267 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modBlockedLog.class.php';
4271 $mod->delete_menus();
4272 $mod->insert_menus();
4274 } elseif ($moduletoreload ==
'MAIN_MODULE_CRON') {
4276 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modCron.class.php';
4279 $mod->remove(
'noboxes');
4280 $mod->init($reloadmode);
4282 } elseif ($moduletoreload ==
'MAIN_MODULE_EXTERNALSITE') {
4284 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modExternalSite.class.php';
4287 $mod->remove(
'noboxes');
4288 $mod->init($reloadmode);
4290 } elseif ($moduletoreload ==
'MAIN_MODULE_SOCIETE') {
4292 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modSociete.class.php';
4295 $mod->remove(
'noboxes');
4296 $mod->init($reloadmode);
4298 } elseif ($moduletoreload ==
'MAIN_MODULE_PRODUIT') {
4300 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modProduct.class.php';
4304 $mod->init($reloadmode);
4306 } elseif ($moduletoreload ==
'MAIN_MODULE_SERVICE') {
4308 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modService.class.php';
4312 $mod->init($reloadmode);
4314 } elseif ($moduletoreload ==
'MAIN_MODULE_COMMANDE') {
4316 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modCommande.class.php';
4320 $mod->init($reloadmode);
4322 } elseif ($moduletoreload ==
'MAIN_MODULE_FACTURE') {
4324 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modFacture.class.php';
4328 $mod->init($reloadmode);
4330 } elseif ($moduletoreload ==
'MAIN_MODULE_FOURNISSEUR') {
4332 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modFournisseur.class.php';
4336 $mod->init($reloadmode);
4338 } elseif ($moduletoreload ==
'MAIN_MODULE_HOLIDAY') {
4340 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modHoliday.class.php';
4343 $mod->remove(
'noboxes');
4344 $mod->init($reloadmode);
4346 } elseif ($moduletoreload ==
'MAIN_MODULE_DEPLACEMENT') {
4348 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modDeplacement.class.php';
4352 $mod->init($reloadmode);
4354 } elseif ($moduletoreload ==
'MAIN_MODULE_EXPENSEREPORT') {
4356 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modExpenseReport.class.php';
4360 $mod->init($reloadmode);
4362 } elseif ($moduletoreload ==
'MAIN_MODULE_DON') {
4364 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modDon.class.php';
4368 $mod->init($reloadmode);
4370 } elseif ($moduletoreload ==
'MAIN_MODULE_ECM') {
4372 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modECM.class.php';
4375 $mod->remove(
'noboxes');
4376 $mod->init($reloadmode);
4378 } elseif ($moduletoreload ==
'MAIN_MODULE_KNOWLEDGEMANAGEMENT') {
4380 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modKnowledgeManagement.class.php';
4383 $mod->remove(
'noboxes');
4384 $mod->init($reloadmode);
4386 } elseif ($moduletoreload ==
'MAIN_MODULE_EVENTORGANIZATION') {
4388 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modEventOrganization.class.php';
4391 $mod->remove(
'noboxes');
4392 $mod->init($reloadmode);
4394 } elseif ($moduletoreload ==
'MAIN_MODULE_PAYBOX') {
4396 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modPaybox.class.php';
4398 $mod =
new modPaybox($db);
4399 $mod->remove(
'noboxes');
4400 $mod->init($reloadmode);
4402 } elseif ($moduletoreload ==
'MAIN_MODULE_SUPPLIERPROPOSAL') {
4404 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modSupplierProposal.class.php';
4407 $mod->remove(
'noboxes');
4408 $mod->init($reloadmode);
4410 } elseif ($moduletoreload ==
'MAIN_MODULE_OPENSURVEY') {
4412 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modOpenSurvey.class.php';
4415 $mod->remove(
'noboxes');
4416 $mod->init($reloadmode);
4418 } elseif ($moduletoreload ==
'MAIN_MODULE_PRODUCTBATCH') {
4420 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modProductBatch.class.php';
4423 $mod->remove(
'noboxes');
4424 $mod->init($reloadmode);
4426 } elseif ($moduletoreload ==
'MAIN_MODULE_TAKEPOS') {
4428 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/modTakePos.class.php';
4431 $mod->remove(
'noboxes');
4432 $mod->init($reloadmode);
4436 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4437 if (!empty($reg[1])) {
4438 if (strtoupper($moduletoreload) == $moduletoreload) {
4439 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4442 $moduletoreloadshort = $reg[1];
4445 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode);
4446 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4448 $classname =
'mod'.$moduletoreloadshort;
4449 $mod =
new $classname($db);
4452 $mod->delete_menus();
4453 $mod->init($reloadmode);
4455 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4457 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4459 $classname =
'mod'.$moduletoreloadshort;
4460 $mod =
new $classname($db);
4461 $mod->init($reloadmode);
4463 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4464 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4470 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4475 if (!empty($mod) && is_object($mod)) {
4476 print
'<tr class="trforrunsql"><td colspan="4">';
4477 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4478 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4479 print
"<!-- (".$reloadmode.
") -->";
4504 $listofmenuhandler = array();
4505 if ($conf->global->MAIN_MENU_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE ==
'auguria_menu'
4506 || $conf->global->MAIN_MENUFRONT_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE ==
'auguria_menu') {
4507 $listofmenuhandler[
'auguria'] = 1;
4510 foreach ($listofmenuhandler as $key => $val) {
4511 print
'<tr class="trforrunsql"><td colspan="4">';
4515 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4518 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4519 $file =
'init_menu_'.$key.
'.sql';
4520 if (file_exists($dir.$file)) {
4521 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4537 global $conf, $db, $langs, $user;
4539 print
'<tr><td colspan="4">';
4541 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4543 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4544 $fuser =
new User($db);
4546 if (!is_object($user)) {
4550 $sql =
"SELECT rowid as uid from ".MAIN_DB_PREFIX.
"user";
4551 $resql = $db->query($sql);
4553 while ($obj = $db->fetch_object(
$resql)) {
4554 $fuser->fetch($obj->uid);
4556 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4558 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4560 $dir = $conf->user->multidir_output[$entity];
4565 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4566 $destin = $dir.
'/'.$fuser->id;
4574 $handle = opendir($origin_osencoded);
4575 if (is_resource($handle)) {
4576 while (($file = readdir($handle)) !==
false) {
4577 if ($file ==
'.' || $file ==
'..') {
4582 $thumbs = opendir($origin_osencoded.
'/'.$file);
4583 if (is_resource($thumbs)) {
4585 while (($thumb = readdir($thumbs)) !==
false) {
4587 if ($thumb ==
'.' || $thumb ==
'..') {
4593 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4603 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4624 global $conf, $db, $langs, $user;
4626 print
'<tr><td colspan="4">';
4628 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4630 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4631 $fuser =
new User($db);
4633 if (!is_object($user)) {
4637 $sql =
"SELECT rowid as uid from ".MAIN_DB_PREFIX.
"user";
4638 $resql = $db->query($sql);
4640 while ($obj = $db->fetch_object(
$resql)) {
4641 $fuser->fetch($obj->uid);
4643 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4645 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4647 $dir = DOL_DATA_ROOT.
'/users';
4652 $origin = $dir.
'/'.$fuser->id;
4653 $destin = $dir.
'/'.$fuser->id.
'/photos';
4661 $handle = opendir($origin_osencoded);
4662 if (is_resource($handle)) {
4663 while (($file = readdir($handle)) !==
false) {
4664 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4667 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4672 $thumbs = opendir($origin_osencoded.
'/'.$file);
4673 if (is_resource($thumbs)) {
4675 while (($thumb = readdir($thumbs)) !==
false) {
4677 if ($thumb ==
'.' || $thumb ==
'..') {
4683 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4692 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4729 print
'<tr><td colspan="4">';
4730 $sql =
'SELECT rowid, socialnetworks';
4731 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4732 $sql .=
" skype IS NOT NULL OR skype <> ''";
4733 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4734 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4735 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4736 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4737 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4738 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4739 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4740 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4742 $resql = $db->query($sql);
4744 while ($obj = $db->fetch_object(
$resql)) {
4745 $arraysocialnetworks = array();
4746 if (!empty($obj->skype)) {
4747 $arraysocialnetworks[
'skype'] = $obj->skype;
4749 if (!empty($obj->twitter)) {
4750 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4752 if (!empty($obj->facebook)) {
4753 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4755 if (!empty($obj->linkedin)) {
4756 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4758 if (!empty($obj->instagram)) {
4759 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4761 if (!empty($obj->snapchat)) {
4762 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4764 if (!empty($obj->googleplus)) {
4765 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4767 if (!empty($obj->youtube)) {
4768 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4770 if (!empty($obj->whatsapp)) {
4771 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4773 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4774 $obj->socialnetworks =
'[]';
4776 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4777 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4778 $sqlupd .=
', skype=null';
4779 $sqlupd .=
', twitter=null';
4780 $sqlupd .=
', facebook=null';
4781 $sqlupd .=
', linkedin=null';
4782 $sqlupd .=
', instagram=null';
4783 $sqlupd .=
', snapchat=null';
4784 $sqlupd .=
', googleplus=null';
4785 $sqlupd .=
', youtube=null';
4786 $sqlupd .=
', whatsapp=null';
4787 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4789 $resqlupd = $db->query($sqlupd);
4804 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4818 print
'<tr><td colspan="4">';
4821 print
'<tr><td colspan="4">';
4822 $sql =
'SELECT rowid, socialnetworks';
4823 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4824 $sql .=
" skype IS NOT NULL OR skype <> ''";
4825 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4826 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4827 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4828 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4829 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4830 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4831 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4832 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4834 $resql = $db->query($sql);
4836 while ($obj = $db->fetch_object(
$resql)) {
4837 $arraysocialnetworks = array();
4838 if (!empty($obj->skype)) {
4839 $arraysocialnetworks[
'skype'] = $obj->skype;
4841 if (!empty($obj->twitter)) {
4842 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4844 if (!empty($obj->facebook)) {
4845 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4847 if (!empty($obj->linkedin)) {
4848 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4850 if (!empty($obj->instagram)) {
4851 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4853 if (!empty($obj->snapchat)) {
4854 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4856 if (!empty($obj->googleplus)) {
4857 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4859 if (!empty($obj->youtube)) {
4860 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4862 if (!empty($obj->whatsapp)) {
4863 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4865 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4866 $obj->socialnetworks =
'[]';
4868 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4869 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4870 $sqlupd .=
', skype=null';
4871 $sqlupd .=
', twitter=null';
4872 $sqlupd .=
', facebook=null';
4873 $sqlupd .=
', linkedin=null';
4874 $sqlupd .=
', instagram=null';
4875 $sqlupd .=
', snapchat=null';
4876 $sqlupd .=
', googleplus=null';
4877 $sqlupd .=
', youtube=null';
4878 $sqlupd .=
', whatsapp=null';
4879 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4881 $resqlupd = $db->query($sqlupd);
4896 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4912 print
'<tr><td colspan="4">';
4913 $sql =
'SELECT rowid, socialnetworks';
4914 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4915 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4916 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4917 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4918 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4919 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4920 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4921 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4922 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4923 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4924 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4926 $resql = $db->query($sql);
4928 while ($obj = $db->fetch_object(
$resql)) {
4929 $arraysocialnetworks = array();
4930 if (!empty($obj->jabberid)) {
4931 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4933 if (!empty($obj->skype)) {
4934 $arraysocialnetworks[
'skype'] = $obj->skype;
4936 if (!empty($obj->twitter)) {
4937 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4939 if (!empty($obj->facebook)) {
4940 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4942 if (!empty($obj->linkedin)) {
4943 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4945 if (!empty($obj->instagram)) {
4946 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4948 if (!empty($obj->snapchat)) {
4949 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4951 if (!empty($obj->googleplus)) {
4952 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4954 if (!empty($obj->youtube)) {
4955 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4957 if (!empty($obj->whatsapp)) {
4958 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4960 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4961 $obj->socialnetworks =
'[]';
4963 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4964 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4965 $sqlupd .=
', jabberid=null';
4966 $sqlupd .=
', skype=null';
4967 $sqlupd .=
', twitter=null';
4968 $sqlupd .=
', facebook=null';
4969 $sqlupd .=
', linkedin=null';
4970 $sqlupd .=
', instagram=null';
4971 $sqlupd .=
', snapchat=null';
4972 $sqlupd .=
', googleplus=null';
4973 $sqlupd .=
', youtube=null';
4974 $sqlupd .=
', whatsapp=null';
4975 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4977 $resqlupd = $db->query($sqlupd);
4992 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
5008 print
'<tr><td colspan="4">';
5009 $sql =
'SELECT rowid, socialnetworks';
5010 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
5011 $sql .=
" skype IS NOT NULL OR skype <> ''";
5012 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5013 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5014 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5015 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5016 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5017 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5018 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5019 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5021 $resql = $db->query($sql);
5023 while ($obj = $db->fetch_object(
$resql)) {
5024 $arraysocialnetworks = array();
5025 if (!empty($obj->skype)) {
5026 $arraysocialnetworks[
'skype'] = $obj->skype;
5028 if (!empty($obj->twitter)) {
5029 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5031 if (!empty($obj->facebook)) {
5032 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5034 if (!empty($obj->linkedin)) {
5035 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5037 if (!empty($obj->instagram)) {
5038 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5040 if (!empty($obj->snapchat)) {
5041 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5043 if (!empty($obj->googleplus)) {
5044 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5046 if (!empty($obj->youtube)) {
5047 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5049 if (!empty($obj->whatsapp)) {
5050 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5052 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5053 $obj->socialnetworks =
'[]';
5055 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5056 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
5057 $sqlupd .=
', skype=null';
5058 $sqlupd .=
', twitter=null';
5059 $sqlupd .=
', facebook=null';
5060 $sqlupd .=
', linkedin=null';
5061 $sqlupd .=
', instagram=null';
5062 $sqlupd .=
', snapchat=null';
5063 $sqlupd .=
', googleplus=null';
5064 $sqlupd .=
', youtube=null';
5065 $sqlupd .=
', whatsapp=null';
5066 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5068 $resqlupd = $db->query($sqlupd);
5083 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5103 print
'<tr class="trforrunsql"><td colspan="4">';
5104 $sql =
'SELECT rowid, field';
5105 if ($mode ==
'export') {
5108 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5109 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5111 $resql = $db->query($sql);
5113 while ($obj = $db->fetch_object(
$resql)) {
5114 $oldfield = $obj->field;
5115 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5117 if ($mode ==
'export') {
5118 $oldfilter = $obj->filter;
5119 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5125 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5126 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5127 if ($mode ==
'export') {
5128 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5130 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5131 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5132 $resqlupd = $db->query($sqlupd);
5148 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5151 if ($resultstring) {
5152 print $resultstring;
5154 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5172 print
'<tr class="trforrunsql"><td colspan="4">';
5173 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5175 $sql =
"SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM ".$db->prefix().
"contratdet as cd INNER JOIN ".$db->prefix().
"contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0";
5176 $sql .=
" ORDER BY c.rowid,cd.rowid";
5178 $resql = $db->query($sql);
5181 $current_contract=0;
5182 while ($obj = $db->fetch_object(
$resql)) {
5183 if (empty($current_contract) || $current_contract==$obj->cid) {
5189 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5190 $resultstring =
'.';
5191 print $resultstring;
5192 $resqlUpd = $db->query($sqlUpd);
5198 $current_contract = $obj->cid;
5211 if (!$resultstring) {
5212 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
run_sql($sqlfile, $silent=1, $entity='', $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0)
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Class to manage Blocked Log.
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Class to describe and enable/disable module Agenda.
Description and activation class for module Api.
Class to describe Barcode.
Class to describe a BlockedLog module.
Class to describe module Sales Orders.
Class to describe a Cron module.
Class to describe and enable module Deplacement.
Class to describe and enable module Donation.
Description and activation class for module ECM.
Description and activation class for module EventOrganization This module is base on this specificati...
Description and activation class for module ExpenseReport.
Description and activation class for module ExternalSite.
Class to describe module customer invoices.
Description and activation class for module Fournisseur.
Description and activation class for module holiday.
Description and activation class for module KnowledgeManagement.
Description and activation class for module opensurvey.
Description and activation class for module productdluo.
Class descriptor of Product module.
Class to describe and enable module Service.
Class to describe and enable module Societe.
Class to describe and enable module SupplierProposal.
Class to describe and enable module TakePos.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
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_is_file($pathoffile)
Return if path is a file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
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).
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.
div float
Buy price without taxes.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Reenable features modules.
migrate_project_task_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
if($db->connected) if($ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondance des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignement to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondance des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignement to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.