42define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
43include_once
'inc.php';
44if (!file_exists($conffile)) {
45 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").';
47require_once $conffile;
48require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
49require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
50require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
51require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
52require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
53require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
54require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
55require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
66$err = error_reporting();
68if (!empty($conf->global->MAIN_OVERRIDE_TIME_LIMIT)) {
69 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
75$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
76$langs->setDefaultLang($setuplang);
77$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
78$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
79$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
81$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
83if ($dolibarr_main_db_type ==
'mysqli') {
86if ($dolibarr_main_db_type ==
'pgsql') {
89if ($dolibarr_main_db_type ==
'mssql') {
94dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
95if (!is_object($conf)) {
105if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
106 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
107 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
109 $sapi_type = php_sapi_name();
110 $script_file = basename(__FILE__);
112 if (substr($sapi_type, 0, 3) ==
'cli') {
113 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
118pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
121if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
122 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
123 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
125 print
'<table border="0" width="100%">';
128 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
129 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
130 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
131 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
132 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
133 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
135 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
140 $conf->db->type = $dolibarr_main_db_type;
141 $conf->db->host = $dolibarr_main_db_host;
142 $conf->db->port = $dolibarr_main_db_port;
143 $conf->db->name = $dolibarr_main_db_name;
144 $conf->db->user = $dolibarr_main_db_user;
145 $conf->db->pass = $dolibarr_main_db_pass;
147 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
149 if (!$db->connected) {
150 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
151 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
156 if ($db->database_selected) {
163 if (empty($dolibarr_main_db_encryption)) {
164 $dolibarr_main_db_encryption = 0;
166 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
167 if (empty($dolibarr_main_db_cryptkey)) {
168 $dolibarr_main_db_cryptkey =
'';
170 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
173 $conf->setValues($db);
176 $listofentities = array(1);
179 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
181 $hookmanager->initHooks(array(
'upgrade2'));
183 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
184 $object =
new stdClass();
186 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters, $object, $action);
187 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
189 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
200 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
220 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
226 foreach ($listofentities as $entity) {
228 $conf->setEntityValues($db, $entity);
230 if (defined(
'SYSLOG_FILE')) {
231 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
233 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
236 if (count($listofentities) > 1) {
237 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
242 $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 :
''));
248 $versiontoarray = explode(
'.', $versionto);
249 $versionranarray = explode(
'.', DOL_VERSION);
252 $afterversionarray = explode(
'.',
'2.0.0');
253 $beforeversionarray = explode(
'.',
'2.7.9');
314 $afterversionarray = explode(
'.',
'2.7.9');
315 $beforeversionarray = explode(
'.',
'2.8.9');
340 $afterversionarray = explode(
'.',
'2.8.9');
341 $beforeversionarray = explode(
'.',
'2.9.9');
353 $afterversionarray = explode(
'.',
'2.9.9');
354 $beforeversionarray = explode(
'.',
'3.0.9');
360 $afterversionarray = explode(
'.',
'3.0.9');
361 $beforeversionarray = explode(
'.',
'3.1.9');
369 $afterversionarray = explode(
'.',
'3.1.9');
370 $beforeversionarray = explode(
'.',
'3.2.9');
380 $afterversionarray = explode(
'.',
'3.2.9');
381 $beforeversionarray = explode(
'.',
'3.3.9');
390 $afterversionarray = explode(
'.',
'3.6.9');
391 $beforeversionarray = explode(
'.',
'3.7.9');
397 $afterversionarray = explode(
'.',
'3.7.9');
398 $beforeversionarray = explode(
'.',
'3.8.9');
404 $afterversionarray = explode(
'.',
'3.9.9');
405 $beforeversionarray = explode(
'.',
'4.0.9');
411 $afterversionarray = explode(
'.',
'4.0.9');
412 $beforeversionarray = explode(
'.',
'5.0.9');
422 $afterversionarray = explode(
'.',
'5.0.9');
423 $beforeversionarray = explode(
'.',
'6.0.9');
425 if (isModEnabled(
'multicompany')) {
426 global $multicompany_transverse_mode;
429 if (empty($multicompany_transverse_mode)) {
440 $afterversionarray = explode(
'.',
'6.0.9');
441 $beforeversionarray = explode(
'.',
'7.0.9');
450 $afterversionarray = explode(
'.',
'7.0.9');
451 $beforeversionarray = explode(
'.',
'8.0.9');
457 $afterversionarray = explode(
'.',
'8.0.9');
458 $beforeversionarray = explode(
'.',
'9.0.9');
464 $afterversionarray = explode(
'.',
'10.0.9');
465 $beforeversionarray = explode(
'.',
'11.0.9');
474 $afterversionarray = explode(
'.',
'13.0.9');
475 $beforeversionarray = explode(
'.',
'14.0.9');
482 $afterversionarray = explode(
'.',
'15.0.9');
483 $beforeversionarray = explode(
'.',
'16.0.9');
490 $afterversionarray = explode(
'.',
'16.0.9');
491 $beforeversionarray = explode(
'.',
'17.0.9');
497 $afterversionarray = explode(
'.',
'17.0.9');
498 $beforeversionarray = explode(
'.',
'18.0.9');
508 $listofmodule = array(
509 'MAIN_MODULE_ACCOUNTING'=>
'newboxdefonly',
510 'MAIN_MODULE_AGENDA'=>
'newboxdefonly',
511 'MAIN_MODULE_BOM'=>
'menuonly',
512 'MAIN_MODULE_BANQUE'=>
'menuonly',
513 'MAIN_MODULE_BARCODE'=>
'newboxdefonly',
514 'MAIN_MODULE_CRON'=>
'newboxdefonly',
515 'MAIN_MODULE_COMMANDE'=>
'newboxdefonly',
516 'MAIN_MODULE_BLOCKEDLOG'=>
'noboxes',
517 'MAIN_MODULE_DEPLACEMENT'=>
'newboxdefonly',
518 'MAIN_MODULE_DON'=>
'newboxdefonly',
519 'MAIN_MODULE_ECM'=>
'newboxdefonly',
520 'MAIN_MODULE_EXTERNALSITE'=>
'newboxdefonly',
521 'MAIN_MODULE_EXPENSEREPORT'=>
'newboxdefonly',
522 'MAIN_MODULE_FACTURE'=>
'newboxdefonly',
523 'MAIN_MODULE_FOURNISSEUR'=>
'newboxdefonly',
524 'MAIN_MODULE_HOLIDAY'=>
'newboxdefonly',
525 'MAIN_MODULE_MARGIN'=>
'menuonly',
526 'MAIN_MODULE_MRP'=>
'menuonly',
527 'MAIN_MODULE_OPENSURVEY'=>
'newboxdefonly',
528 'MAIN_MODULE_PAYBOX'=>
'newboxdefonly',
529 'MAIN_MODULE_PRINTING'=>
'newboxdefonly',
530 'MAIN_MODULE_PRODUIT'=>
'newboxdefonly',
531 'MAIN_MODULE_RECRUITMENT'=>
'menuonly',
532 'MAIN_MODULE_RESOURCE'=>
'noboxes',
533 'MAIN_MODULE_SALARIES'=>
'newboxdefonly',
534 'MAIN_MODULE_SERVICE'=>
'newboxdefonly',
535 'MAIN_MODULE_SYSLOG'=>
'newboxdefonly',
536 'MAIN_MODULE_SOCIETE'=>
'newboxdefonly',
537 'MAIN_MODULE_STRIPE'=>
'menuonly',
538 'MAIN_MODULE_TICKET'=>
'newboxdefonly',
539 'MAIN_MODULE_TAKEPOS'=>
'newboxdefonly',
540 'MAIN_MODULE_USER'=>
'newboxdefonly',
541 'MAIN_MODULE_VARIANTS'=>
'newboxdefonly',
542 'MAIN_MODULE_WEBSITE'=>
'newboxdefonly',
558 if (!$error && $enablemodules) {
560 $listofmodules = array();
561 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
562 $tmplistofmodules = explode(
',', $enablemodules);
563 foreach ($tmplistofmodules as $value) {
564 $listofmodules[$value] =
'forceactivate';
568 if ($resultreloadmodules < 0) {
576 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
577 $object =
new stdClass();
579 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters, $object, $action);
580 if ($hookmanager->resNbOfHooks > 0) {
582 print
'<tr><td colspan="4">';
583 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
584 print $hookmanager->error;
585 print
"<!-- (".$reshook.
") -->";
588 print
'<tr class="trforrunsql"><td colspan="4">';
589 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
590 print
"<!-- (".$reshook.
") -->";
595 if (!empty($conf->modules_parts[
'hooks'])) {
596 print
'<tr class="trforrunsql"><td colspan="4">';
597 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
608 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
623 foreach ($listofentities as $entity) {
625 $conf->setEntityValues($db, $entity);
627 if (defined(
'SYSLOG_FILE')) {
628 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
630 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
634 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
635 $destroot = DOL_DATA_ROOT.
'/medias';
648 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
649 $object =
new stdClass();
651 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters, $object, $action);
652 if ($hookmanager->resNbOfHooks > 0) {
654 print
'<tr><td colspan="4">';
655 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
656 print $hookmanager->error;
657 print
"<!-- (".$reshook.
") -->";
660 print
'<tr class="trforrunsql"><td colspan="4">';
661 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
662 print
"<!-- (".$reshook.
") -->";
667 if (!empty($conf->modules_parts[
'hooks'])) {
668 print
'<tr class="trforrunsql"><td colspan="4">';
669 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
679 print
'<table width="100%">';
680 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
681 print
'<td class="right">';
685 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
689 print
'<script type="text/javascript">
690 jQuery(document).ready(function() {
691 function init_trrunsql()
693 console.log("toggle .trforrunsql");
694 jQuery(".trforrunsql").toggle();
697 jQuery(".trforrunsqlshowhide").click(function() {
702 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
705 print
'</td></tr>'.
"\n";
711 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
716if ($error && isset($argv[1])) {
722pFooter($error ? 2 : 0, $setuplang);
745 print
'<tr><td colspan="4">';
748 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
750 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
751 $obj = $db->fetch_object($result);
753 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
754 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
755 $sql .=
" WHERE p.fk_facture > 0";
757 $resql = $db->query($sql);
763 $num = $db->num_rows($resql);
766 $obj = $db->fetch_object($resql);
767 $row[$i][0] = $obj->rowid;
768 $row[$i][1] = $obj->fk_facture;
769 $row[$i][2] = $obj->amount;
777 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
781 for ($i = 0; $i < $num; $i++) {
782 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
783 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
785 $res += $db->query($sql);
787 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
789 $res += $db->query($sql);
791 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
795 if ($res == (2 * count($row))) {
797 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
800 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
803 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
806 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
824 print
'<tr><td colspan="4">';
827 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
829 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
830 $obj = $db->fetch_object($result);
833 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
834 $sql .=
" bu2.url_id as socid";
835 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
836 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
837 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
838 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
839 $sql .=
" AND b.rappro = 1";
840 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
842 $resql = $db->query($sql);
848 $num = $db->num_rows($resql);
851 $obj = $db->fetch_object($resql);
852 if ($obj->pamount == $obj->bamount && $obj->socid) {
853 $row[$j][
'paymentid'] = $obj->rowid;
854 $row[$j][
'pamount'] = $obj->pamount;
855 $row[$j][
'fk_bank'] = $obj->fk_bank;
856 $row[$j][
'bamount'] = $obj->bamount;
857 $row[$j][
'socid'] = $obj->socid;
858 $row[$j][
'datec'] = $obj->datec;
868 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
873 for ($i = 0; $i < $num; $i++) {
874 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
875 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>';
879 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
880 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
881 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
882 $sql .=
" AND pf.fk_facture IS NULL";
883 $sql .=
" ORDER BY f.fk_statut";
885 $resql = $db->query($sql);
887 $num = $db->num_rows($resql);
890 $obj = $db->fetch_object($resql);
891 $facid = $obj->rowid;
893 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
894 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
896 $res += $db->query($sql);
898 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
906 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
908 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
913 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
916 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
934 print
'<tr><td colspan="4">';
937 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
939 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
940 $obj = $db->fetch_object($result);
943 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
944 $sql .=
" bu2.url_id as socid";
945 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
946 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
947 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
948 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
949 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
951 $resql = $db->query($sql);
957 $num = $db->num_rows($resql);
960 $obj = $db->fetch_object($resql);
961 if ($obj->pamount == $obj->bamount && $obj->socid) {
962 $row[$j][
'paymentid'] = $obj->rowid;
963 $row[$j][
'pamount'] = $obj->pamount;
964 $row[$j][
'fk_bank'] = $obj->fk_bank;
965 $row[$j][
'bamount'] = $obj->bamount;
966 $row[$j][
'socid'] = $obj->socid;
967 $row[$j][
'datec'] = $obj->datec;
980 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
984 for ($i = 0; $i < $num; $i++) {
985 if ($conf->global->MAIN_FEATURES_LEVEL == 2) {
986 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>';
990 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
991 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
992 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
993 $sql .=
" AND pf.fk_facture IS NULL";
994 $sql .=
" ORDER BY f.fk_statut";
996 $resql = $db->query($sql);
998 $num = $db->num_rows($resql);
1001 $obj = $db->fetch_object($resql);
1002 $facid = $obj->rowid;
1004 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1005 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1007 $res += $db->query($sql);
1009 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1018 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1020 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1025 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1031 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1041 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1058 print
'<tr><td colspan="4">';
1063 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1065 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1066 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1067 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1068 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1069 $sql .=
" ON c.fk_product = p.rowid";
1070 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1071 $sql .=
" ON c.rowid=cd.fk_contrat";
1072 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1073 $resql = $db->query($sql);
1079 $num = $db->num_rows($resql);
1082 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1086 $obj = $db->fetch_object($resql);
1088 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1089 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1090 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1091 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1092 $sql .=
" VALUES (";
1093 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1095 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1096 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1099 $sql .= ((float) $obj->tva_tx).
", 1, ";
1100 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1104 if ($db->query($sql)) {
1105 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1117 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1120 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1123 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1126 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1143 print
'<tr><td colspan="4">';
1148 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1150 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1152 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1153 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1154 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1155 $sql .=
" AND bu.fk_bank IS NULL";
1156 $resql = $db->query($sql);
1162 $num = $db->num_rows($resql);
1165 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1169 $obj = $db->fetch_object($resql);
1171 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1172 $sql .=
"fk_bank, url_id, url, label, type";
1174 $sql .=
" VALUES (";
1175 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1181 if (!$db->query($sql)) {
1192 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1195 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1198 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1217 print
'<tr><td colspan="4">';
1220 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1222 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1224 $resql = $db->query($sql);
1228 if ($db->affected_rows($resql) > 0) {
1229 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1231 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1234 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1236 $resql = $db->query($sql);
1240 if ($db->affected_rows($resql) > 0) {
1241 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1243 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1259 print
'<tr><td colspan="4">';
1264 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1266 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1268 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1269 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1270 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1271 $resql = $db->query($sql);
1277 $num = $db->num_rows($resql);
1280 $nbcontratsmodifie = 0;
1284 $obj = $db->fetch_object($resql);
1285 if ($obj->date_contrat > $obj->datemin) {
1286 $datemin = $db->jdate($obj->datemin);
1288 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1289 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1290 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1291 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1292 $resql2 = $db->query($sql);
1297 $nbcontratsmodifie++;
1304 if ($nbcontratsmodifie) {
1305 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1307 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1327 print
'<tr><td colspan="4">';
1330 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1332 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1334 $resql = $db->query($sql);
1338 if ($db->affected_rows($resql) > 0) {
1339 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1341 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1357 print
'<tr><td colspan="4">';
1360 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1362 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1363 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1365 $resql = $db->query($sql);
1369 if ($db->affected_rows($resql) > 0) {
1372 $num = $db->num_rows($resql);
1375 $nbcontratsmodifie = 0;
1379 $obj = $db->fetch_object($resql);
1381 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1382 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1383 $sql .=
" SET statut = 1";
1384 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1385 $resql2 = $db->query($sql);
1390 $nbcontratsmodifie++;
1397 if ($nbcontratsmodifie) {
1398 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1400 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1404 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1422 print
'<tr><td colspan="4">';
1424 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1427 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1428 $obj = $db->fetch_object($result);
1433 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1434 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1435 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1438 $select_resql = $db->query($select_sql);
1439 if ($select_resql) {
1440 $select_num = $db->num_rows($select_resql);
1444 while (($i < $select_num) && (!$error)) {
1445 $select_obj = $db->fetch_object($select_resql);
1448 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1449 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1450 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1451 $check_resql = $db->query($check_sql);
1453 $check_num = $db->num_rows($check_resql);
1454 if ($check_num == 0) {
1458 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1459 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1462 print
'<tr class="oddeven">';
1463 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1465 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1466 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1467 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1468 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1469 $insert_resql = $db->query($insert_sql);
1471 if ($insert_resql) {
1473 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1475 print
'<td><span class="error">Error on insert</span></td>';
1491 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1495 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1498 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1502 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1519 $tmpmysoc->setMysoc($conf);
1523 print
'<tr><td colspan="4">';
1526 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1529 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1530 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1531 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1532 $sql .=
" WHERE fd.fk_facture = f.rowid";
1533 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1537 $resql = $db->query($sql);
1539 $num = $db->num_rows($resql);
1543 $obj = $db->fetch_object($resql);
1545 $rowid = $obj->rowid;
1547 $pu = $obj->subprice;
1548 $vatrate = $obj->vatrate;
1549 $remise_percent = $obj->remise_percent;
1550 $remise_percent_global = $obj->remise_percent_global;
1551 $total_ttc_f = $obj->total_ttc_f;
1552 $info_bits = $obj->info_bits;
1556 $facligne->fetch($rowid);
1558 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1559 $total_ht = $result[0];
1560 $total_tva = $result[1];
1561 $total_ttc = $result[2];
1563 $facligne->total_ht = $total_ht;
1564 $facligne->total_tva = $total_tva;
1565 $facligne->total_ttc = $total_ttc;
1567 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);
1569 $facligne->update_total();
1573 if (!$total_ttc_f) {
1575 $facture->id = $obj->facid;
1577 if ($facture->fetch($facture->id) >= 0) {
1578 if ($facture->update_price() > 0) {
1581 print
"Error id=".$facture->id;
1594 print $langs->trans(
"AlreadyDone");
1600 print
"Error #1 ".$db->error();
1622 $tmpmysoc->setMysoc($conf);
1626 print
'<tr><td colspan="4">';
1629 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1632 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1633 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1634 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1635 $sql .=
" WHERE pd.fk_propal = p.rowid";
1636 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1639 $resql = $db->query($sql);
1641 $num = $db->num_rows($resql);
1645 $obj = $db->fetch_object($resql);
1647 $rowid = $obj->rowid;
1649 $pu = $obj->subprice;
1650 $vatrate = $obj->vatrate;
1651 $remise_percent = $obj->remise_percent;
1652 $remise_percent_global = $obj->remise_percent_global;
1653 $info_bits = $obj->info_bits;
1657 $propalligne->fetch($rowid);
1659 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1660 $total_ht = $result[0];
1661 $total_tva = $result[1];
1662 $total_ttc = $result[2];
1664 $propalligne->total_ht = $total_ht;
1665 $propalligne->total_tva = $total_tva;
1666 $propalligne->total_ttc = $total_ttc;
1668 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);
1670 $propalligne->update_total();
1695 print $langs->trans(
"AlreadyDone");
1702 print
"Error #1 ".$db->error();
1725 $tmpmysoc->setMysoc($conf);
1726 if (empty($tmpmysoc->country_id)) {
1727 $tmpmysoc->country_id = 0;
1730 print
'<tr><td colspan="4">';
1733 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1736 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1737 $sql .=
" c.rowid as contratid";
1738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1739 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1740 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1743 $resql = $db->query($sql);
1745 $num = $db->num_rows($resql);
1749 $obj = $db->fetch_object($resql);
1751 $rowid = $obj->rowid;
1753 $pu = $obj->subprice;
1754 $vatrate = $obj->vatrate;
1755 $remise_percent = $obj->remise_percent;
1756 $info_bits = $obj->info_bits;
1761 $contratligne->fetch($rowid);
1763 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1764 $total_ht = $result[0];
1765 $total_tva = $result[1];
1766 $total_ttc = $result[2];
1768 $contratligne->total_ht = $total_ht;
1769 $contratligne->total_tva = $total_tva;
1770 $contratligne->total_ttc = $total_ttc;
1772 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);
1774 $contratligne->update_total();
1779 print $langs->trans(
"AlreadyDone");
1786 print
"Error #1 ".$db->error();
1809 $tmpmysoc->setMysoc($conf);
1811 print
'<tr><td colspan="4">';
1814 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1817 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1818 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1819 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1820 $sql .=
" WHERE cd.fk_commande = c.rowid";
1821 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1824 $resql = $db->query($sql);
1826 $num = $db->num_rows($resql);
1830 $obj = $db->fetch_object($resql);
1832 $rowid = $obj->rowid;
1834 $pu = $obj->subprice;
1835 $vatrate = $obj->vatrate;
1836 $remise_percent = $obj->remise_percent;
1837 $remise_percent_global = $obj->remise_percent_global;
1838 $info_bits = $obj->info_bits;
1842 $commandeligne->fetch($rowid);
1844 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1845 $total_ht = $result[0];
1846 $total_tva = $result[1];
1847 $total_ttc = $result[2];
1849 $commandeligne->total_ht = $total_ht;
1850 $commandeligne->total_tva = $total_tva;
1851 $commandeligne->total_ttc = $total_ttc;
1853 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);
1855 $commandeligne->update_total();
1879 print $langs->trans(
"AlreadyDone");
1896 print
"Error #1 ".$db->error();
1919 $tmpmysoc->setMysoc($conf);
1921 print
'<tr><td colspan="4">';
1924 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1927 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1928 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1929 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1930 $sql .=
" WHERE cd.fk_commande = c.rowid";
1931 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1934 $resql = $db->query($sql);
1936 $num = $db->num_rows($resql);
1940 $obj = $db->fetch_object($resql);
1942 $rowid = $obj->rowid;
1944 $pu = $obj->subprice;
1945 $vatrate = $obj->vatrate;
1946 $remise_percent = $obj->remise_percent;
1947 $remise_percent_global = $obj->remise_percent_global;
1948 $info_bits = $obj->info_bits;
1952 $commandeligne->fetch($rowid);
1954 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpsoc);
1955 $total_ht = $result[0];
1956 $total_tva = $result[1];
1957 $total_ttc = $result[2];
1959 $commandeligne->total_ht = $total_ht;
1960 $commandeligne->total_tva = $total_tva;
1961 $commandeligne->total_ttc = $total_ttc;
1963 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);
1965 $commandeligne->update_total();
1989 print $langs->trans(
"AlreadyDone");
2006 print
"Error #1 ".$db->error();
2031 if (isModEnabled(
'facture')) {
2032 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2034 if (count($modellist) == 0) {
2036 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2037 $resql = $db->query($sql);
2044 if (isModEnabled(
'commande')) {
2045 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2047 if (count($modellist) == 0) {
2049 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2050 $resql = $db->query($sql);
2057 if (isModEnabled(
"expedition")) {
2058 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2060 if (count($modellist) == 0) {
2062 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2063 $resql = $db->query($sql);
2086 print
'<tr><td colspan="4">';
2089 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2091 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2092 $obj = $db->fetch_object($result);
2098 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2099 $resql = $db->query($sql);
2102 $num = $db->num_rows($resql);
2106 $obj = $db->fetch_object($resql);
2108 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2109 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2110 $resql2 = $db->query($sql);
2123 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2124 print $langs->trans(
'FieldRenamed').
"<br>\n";
2134 print $langs->trans(
'AlreadyDone').
"<br>\n";
2151 print
'<tr><td colspan="4">';
2154 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2156 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2157 $obj = $db->fetch_object($result);
2163 $sql =
"SELECT l.rowid, l.fk_commande,";
2164 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2165 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2166 $sql .=
" WHERE c.rowid = l.fk_commande";
2167 $resql = $db->query($sql);
2170 $num = $db->num_rows($resql);
2174 $obj = $db->fetch_object($resql);
2176 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2177 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2178 $resql2 = $db->query($sql);
2181 $delivery_date = $db->jdate($obj->delivery_date);
2183 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2184 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2185 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2186 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2187 $resql3 = $db->query($sqlu);
2203 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2204 print $langs->trans(
'FieldRenamed').
"<br>\n";
2214 print $langs->trans(
'AlreadyDone').
"<br>\n";
2231 print
'<tr><td colspan="4">';
2234 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2238 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2239 $obj = $db->fetch_object($result);
2245 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2246 $sql .=
", ld.fk_livraison";
2247 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2248 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2249 $resql = $db->query($sql);
2252 $num = $db->num_rows($resql);
2256 $obj = $db->fetch_object($resql);
2258 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2259 $sql .=
" fk_product = ".((int) $obj->fk_product);
2260 $sql .=
",description = '".$db->escape($obj->description).
"'";
2261 $sql .=
",subprice = ".price2num($obj->subprice);
2262 $sql .=
",total_ht = ".price2num($obj->total_ht);
2263 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2264 $resql2 = $db->query($sql);
2267 $sql =
"SELECT total_ht";
2268 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2269 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2270 $resql3 = $db->query($sql);
2273 $obju = $db->fetch_object($resql3);
2274 $total_ht = $obju->total_ht + $obj->total_ht;
2276 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2277 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2278 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2279 $resql4 = $db->query($sqlu);
2299 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2300 print $langs->trans(
'FieldRenamed').
"<br>\n";
2310 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2311 $obj = $db->fetch_object($result);
2313 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2316 print $langs->trans(
'AlreadyDone').
"<br>\n";
2333 print
'<tr><td colspan="4">';
2336 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2342 $sql =
"SELECT SUM(reel) as total, fk_product";
2343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2344 $sql .=
" GROUP BY fk_product";
2345 $resql = $db->query($sql);
2348 $num = $db->num_rows($resql);
2352 $obj = $db->fetch_object($resql);
2354 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2355 $sql .=
" stock = ".price2num($obj->total,
'MS');
2356 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2358 $resql2 = $db->query($sql);
2395 print
'<tr><td colspan="4">';
2398 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2402 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2405 $sql =
"SELECT m.rowid, mc.action";
2406 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2407 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2408 $sql .=
" AND m.enabled = '1'";
2409 $resql = $db->query($sql);
2412 $num = $db->num_rows($resql);
2415 $obj = $db->fetch_object($resql);
2417 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2418 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2419 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2420 $sql .=
" AND enabled = '1'";
2422 $resql2 = $db->query($sql);
2443 print $langs->trans(
'AlreadyDone').
"<br>\n";
2462 print
'<tr><td colspan="4">';
2465 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2469 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2472 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2473 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2474 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2475 $sql .=
" WHERE c.rowid = ce.fk_commande";
2476 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2478 $resql = $db->query($sql);
2481 $num = $db->num_rows($resql);
2485 $obj = $db->fetch_object($resql);
2487 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2488 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2489 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2491 $resql2 = $db->query($sql);
2500 print $langs->trans(
'AlreadyDone').
"<br>\n";
2513 print $langs->trans(
'AlreadyDone').
"<br>\n";
2532 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2534 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2538 print
'<tr><td colspan="4">';
2541 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2547 $table1 =
'facturedet'; $field1 =
'fk_remise_except';
2548 $table2 =
'societe_remise_except'; $field2 =
'fk_facture_line';
2552 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2553 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2554 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2555 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2556 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2559 $resql = $db->query($sql);
2562 $num = $db->num_rows($resql);
2566 $obj = $db->fetch_object($resql);
2568 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2569 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2570 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2571 $sql .=
" WHERE rowid = ".((int) $obj->field);
2573 $resql2 = $db->query($sql);
2582 print $langs->trans(
'AlreadyDone').
"<br>\n";
2598 print
'<tr><td colspan="4">';
2601 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2604 $table2 =
'facturedet'; $field2 =
'fk_remise_except';
2605 $table1 =
'societe_remise_except'; $field1 =
'fk_facture_line';
2609 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2610 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2611 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2612 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2613 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2616 $resql = $db->query($sql);
2619 $num = $db->num_rows($resql);
2623 $obj = $db->fetch_object($resql);
2625 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2626 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2627 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2628 $sql .=
" WHERE rowid = ".((int) $obj->field);
2630 $resql2 = $db->query($sql);
2639 print $langs->trans(
'AlreadyDone').
"<br>\n";
2654 return ($error ? -1 : 1);
2669 print
'<tr><td colspan="4">';
2672 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2674 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2675 $obj = $db->fetch_object($result);
2681 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2682 $resql = $db->query($sql);
2685 $num = $db->num_rows($resql);
2689 $obj = $db->fetch_object($resql);
2691 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2692 $sql2 .=
"datecreate";
2693 $sql2 .=
", statut";
2694 $sql2 .=
", element_id";
2695 $sql2 .=
", fk_c_type_contact";
2696 $sql2 .=
", fk_socpeople";
2697 $sql2 .=
") VALUES (";
2698 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2700 $sql2 .=
", ".$obj->rowid;
2702 $sql2 .=
", ".$obj->fk_user_resp;
2705 if ($obj->fk_user_resp > 0) {
2706 $resql2 = $db->query($sql2);
2719 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2720 if ($db->query($sqlDrop)) {
2733 print $langs->trans(
'AlreadyDone').
"<br>\n";
2750 print
'<tr><td colspan="4">';
2753 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2755 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2760 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2761 $resql = $db->query($sql);
2764 $num = $db->num_rows($resql);
2768 $obj = $db->fetch_object($resql);
2770 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2771 $sql2 .=
"datecreate";
2772 $sql2 .=
", statut";
2773 $sql2 .=
", element_id";
2774 $sql2 .=
", fk_c_type_contact";
2775 $sql2 .=
", fk_socpeople";
2776 $sql2 .=
") VALUES (";
2777 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2779 $sql2 .=
", ".$obj->fk_project_task;
2781 $sql2 .=
", ".$obj->fk_user;
2784 $resql2 = $db->query($sql2);
2796 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2797 if ($db->query($sqlDrop)) {
2810 print $langs->trans(
'AlreadyDone').
"<br>\n";
2830 print
'<tr><td colspan="4">';
2833 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2837 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2842 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2843 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2845 $resql = $db->query($sqlSelect);
2848 $num = $db->num_rows($resql);
2852 $obj = $db->fetch_object($resql);
2854 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2855 $sqlInsert .=
"fk_source";
2856 $sqlInsert .=
", sourcetype";
2857 $sqlInsert .=
", fk_target";
2858 $sqlInsert .=
", targettype";
2859 $sqlInsert .=
") VALUES (";
2860 $sqlInsert .= $obj->$fk_source;
2861 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2862 $sqlInsert .=
", ".$obj->$fk_target;
2863 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2866 $result = $db->query($sqlInsert);
2875 print $langs->trans(
'AlreadyDone').
"<br>\n";
2879 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2880 if ($db->query($sqlDrop)) {
2893 print $langs->trans(
'AlreadyDone').
"<br>\n";
2911 print
'<tr><td colspan="4">';
2914 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2920 $sql =
"SELECT rowid, fk_element, element_duration";
2921 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2922 $resql = $db->query($sql);
2925 $num = $db->num_rows($resql);
2928 $totaltime = array();
2932 $obj = $db->fetch_object($resql);
2934 if ($obj->element_duration > 0) {
2937 list($hour, $min) = explode(
'.', $obj->element_duration);
2938 $hour = $hour * 60 * 60;
2939 $min = ($min / 100) * 60 * 60;
2940 $newtime = $hour + $min;
2942 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2943 $sql2 .=
" element_duration = ".((int) $newtime);
2944 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2946 $resql2 = $db->query($sql2);
2953 if (!empty($totaltime[$obj->fk_element])) {
2954 $totaltime[$obj->fk_element] += $newtime;
2956 $totaltime[$obj->fk_element] = $newtime;
2959 if (!empty($totaltime[$obj->fk_element])) {
2960 $totaltime[$obj->fk_element] += $obj->element_duration;
2962 $totaltime[$obj->fk_element] = $obj->element_duration;
2971 foreach ($totaltime as $taskid => $total_duration) {
2972 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2973 $sql .=
" duration_effective = ".((int) $total_duration);
2974 $sql .=
" WHERE rowid = ".((int) $taskid);
2976 $resql = $db->query($sql);
2983 print $langs->trans(
'AlreadyDone').
"<br>\n";
2989 print $langs->trans(
'AlreadyDone').
"<br>\n";
3014 print
'<tr><td colspan="4">';
3017 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3021 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3022 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3023 $obj1 = $db->fetch_object($result1);
3024 $obj2 = $db->fetch_object($result2);
3025 if (!$obj1 && !$obj2) {
3030 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3031 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3033 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3034 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3035 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3036 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3037 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3038 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3039 $sqlSelect .=
" AND el.targettype = 'shipping'";
3041 $resql = $db->query($sqlSelect);
3044 $num = $db->num_rows($resql);
3048 $obj = $db->fetch_object($resql);
3050 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3051 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3052 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3053 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3055 $result = $db->query($sqlUpdate);
3064 print $langs->trans(
'AlreadyDone').
"<br>\n";
3082 print $langs->trans(
'AlreadyDone').
"<br>\n";
3098 print
'<tr><td colspan="4">';
3101 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3105 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3106 $obj = $db->fetch_object($result);
3112 $sqlSelect =
"SELECT rowid, fk_expedition";
3113 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3114 $sqlSelect .=
" WHERE fk_expedition is not null";
3116 $resql = $db->query($sqlSelect);
3119 $num = $db->num_rows($resql);
3123 $obj = $db->fetch_object($resql);
3125 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3126 $sqlInsert .=
"fk_source";
3127 $sqlInsert .=
", sourcetype";
3128 $sqlInsert .=
", fk_target";
3129 $sqlInsert .=
", targettype";
3130 $sqlInsert .=
") VALUES (";
3131 $sqlInsert .= $obj->fk_expedition;
3132 $sqlInsert .=
", 'shipping'";
3133 $sqlInsert .=
", ".$obj->rowid;
3134 $sqlInsert .=
", 'delivery'";
3137 $result = $db->query($sqlInsert);
3139 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3140 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3142 $result = $db->query($sqlUpdate);
3155 print $langs->trans(
'AlreadyDone').
"<br>\n";
3159 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3160 $db->query($sqlDelete);
3165 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3166 $db->query($sqlDrop);
3176 print $langs->trans(
'AlreadyDone').
"<br>\n";
3193 print
'<tr><td colspan="4">';
3196 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3204 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3205 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3206 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3207 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3208 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3209 $sqlSelect .=
" AND el.targettype = 'delivery'";
3210 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3211 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3213 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3214 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3216 $resql = $db->query($sqlSelect);
3219 $num = $db->num_rows($resql);
3223 $obj = $db->fetch_object($resql);
3225 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3226 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3227 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3228 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3230 $result = $db->query($sqlUpdate);
3239 print $langs->trans(
'AlreadyDone').
"<br>\n";
3266 print
'<tr><td colspan="4">';
3269 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3272 'propal' =>
'propalrowid',
3273 'order' =>
'fk_commande',
3274 'invoice' =>
'fk_facture',
3275 'contract' =>
'fk_contract',
3276 'order_supplier' =>
'fk_supplier_order',
3277 'invoice_supplier' =>
'fk_supplier_invoice'
3280 foreach ($elements as $type => $field) {
3281 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3282 $obj = $db->fetch_object($result);
3288 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3289 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3290 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3291 $sql .=
" AND fk_element IS NULL";
3292 $sql .=
" AND elementtype IS NULL";
3294 $resql = $db->query($sql);
3308 print $langs->trans(
'AlreadyDone').
"<br>\n";
3325 print
'<tr><td colspan="4">';
3328 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3331 'old_id' => array(5, 8, 9, 10, 11),
3332 'new_id' => array(50, 51, 52, 53, 54),
3333 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3334 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3338 foreach ($elements[
'old_id'] as $key => $old_id) {
3343 $sqlSelect =
"SELECT id";
3344 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3345 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3346 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3348 $resql = $db->query($sqlSelect);
3350 $num = $db->num_rows($resql);
3356 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3357 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3358 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3359 $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]).
"')";
3360 $resqla = $db->query($sqla);
3362 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3363 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3364 $sql .=
" WHERE id = ".((int) $old_id);
3365 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3366 $resql = $db->query($sql);
3368 if ($resqla && $resql) {
3369 foreach ($elements[
'tables'] as $table) {
3370 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3371 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3372 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3374 $resql = $db->query($sql);
3397 print $langs->trans(
'AlreadyDone').
"<br>\n";
3415 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3417 $obj = $db->fetch_object($result);
3421 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3422 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3424 $resql = $db->query($sql);
3426 $num = $db->num_rows($resql);
3427 while ($obj = $db->fetch_object($resql)) {
3428 if (!isset($filles[$obj->fk_categorie_fille])) {
3429 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3430 $filles[$obj->fk_categorie_fille] = 1;
3431 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere'=>$obj->fk_categorie_mere,
'fille'=>$obj->fk_categorie_fille);
3439 if (count($couples) > 0 && $num > count($couples)) {
3445 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3447 $resqld = $db->query($sql);
3450 foreach ($couples as $key => $val) {
3451 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3452 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3454 $resqli = $db->query($sql);
3462 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3463 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3466 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3467 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3472 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3473 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3490 print
'<tr><td colspan="4">';
3493 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3497 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3502 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3503 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3505 $resql = $db->query($sqlSelect);
3508 $num = $db->num_rows($resql);
3512 $obj = $db->fetch_object($resql);
3514 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3515 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3516 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3518 $result = $db->query($sqlUpdate);
3527 print $langs->trans(
'AlreadyDone').
"<br>\n";
3540 print $langs->trans(
'AlreadyDone').
"<br>\n";
3556 print
'<tr><td colspan="4">';
3559 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3567 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3568 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3569 $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";
3570 $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')";
3571 $sqlSelect .=
" ORDER BY a.id";
3574 $resql = $db->query($sqlSelect);
3577 $num = $db->num_rows($resql);
3581 $obj = $db->fetch_object($resql);
3583 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3584 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3586 $result = $db->query($sqlUpdate);
3595 print $langs->trans(
'AlreadyDone').
"<br>\n";
3622 print
'<tr><td colspan="4">';
3625 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3633 $sqlSelect =
"SELECT a.id, a.fk_contact";
3634 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3635 $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";
3636 $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')";
3637 $sqlSelect .=
" ORDER BY a.id";
3640 $resql = $db->query($sqlSelect);
3643 $num = $db->num_rows($resql);
3647 $obj = $db->fetch_object($resql);
3649 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3650 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3652 $result = $db->query($sqlUpdate);
3661 print $langs->trans(
'AlreadyDone').
"<br>\n";
3691 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3693 print
'<tr><td colspan="4">';
3696 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3704 $sqlSelect =
"SELECT DISTINCT entity";
3705 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3709 $resql = $db->query($sqlSelect);
3712 $num = $db->num_rows($resql);
3716 $obj = $db->fetch_object($resql);
3718 print
'Process entity '.$obj->entity;
3720 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3721 $resqlSearch = $db->query($sqlSearch);
3723 $objSearch = $db->fetch_object($resqlSearch);
3725 if ($objSearch && $objSearch->nb == 0) {
3726 print
' - Record for entity must be reset...';
3728 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3729 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3730 $resqlUpdate = $db->query($sqlUpdate);
3731 if (!$resqlUpdate) {
3736 $object =
new stdClass();
3738 $object->element =
'module';
3739 $object->ref =
'systemevent';
3740 $object->entity = $obj->entity;
3744 $b->setObjectData($object,
'MODULE_SET', 0);
3746 $res = $b->create($user);
3752 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3761 print $langs->trans(
'NothingToDo').
"<br>\n";
3788 print
'<tr><td colspan="4">';
3791 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3799 $sqlSelect =
"SELECT sr.rowid, s.entity";
3800 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3801 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3805 $resql = $db->query($sqlSelect);
3808 $num = $db->num_rows($resql);
3812 $obj = $db->fetch_object($resql);
3814 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3815 $sqlUpdate .=
" entity = ".$obj->entity;
3816 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3818 $result = $db->query($sqlUpdate);
3828 print $langs->trans(
'AlreadyDone').
"<br>\n";
3854 print
'<tr><td colspan="4">';
3857 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3865 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3866 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3869 $resql = $db->query($sqlSelect);
3872 $num = $db->num_rows($resql);
3876 $obj = $db->fetch_object($resql);
3878 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3879 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3881 $sqlSelect2 =
"SELECT f.entity";
3882 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3883 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3884 } elseif (!empty($obj->fk_facture_line)) {
3885 $sqlSelect2 =
"SELECT f.entity";
3886 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3887 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3888 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3890 $sqlSelect2 =
"SELECT s.entity";
3891 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3892 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3895 $resql2 = $db->query($sqlSelect2);
3897 if ($db->num_rows($resql2) > 0) {
3898 $obj2 = $db->fetch_object($resql2);
3900 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3901 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3902 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3904 $result = $db->query($sqlUpdate);
3919 print $langs->trans(
'AlreadyDone').
"<br>\n";
3946 print
'<tr><td colspan="4">';
3948 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3956 $sqlSelect =
"SELECT u.rowid, u.entity";
3957 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3958 $sqlSelect .=
" WHERE u.entity > 1";
3961 $resql = $db->query($sqlSelect);
3964 $num = $db->num_rows($resql);
3968 $obj = $db->fetch_object($resql);
3970 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3971 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3972 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3974 $result = $db->query($sqlUpdate);
3984 print $langs->trans(
'AlreadyDone').
"<br>\n";
4011 print
'<tr><td colspan="4">';
4013 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4021 $sqlSelect =
"SELECT u.rowid, u.entity";
4022 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4023 $sqlSelect .=
" WHERE u.entity > 1";
4026 $resql = $db->query($sqlSelect);
4029 $num = $db->num_rows($resql);
4033 $obj = $db->fetch_object($resql);
4035 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4036 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4037 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4039 $result = $db->query($sqlUpdate);
4049 print $langs->trans(
'AlreadyDone').
"<br>\n";
4080 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4081 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4082 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4102 $filetodeletearray = array(
4103 '/core/ajax/ajaxcompanies.php',
4104 '/core/triggers/interface_demo.class.php',
4105 '/core/menus/barre_left/default.php',
4106 '/core/menus/barre_top/default.php',
4107 '/core/modules/modComptabiliteExpert.class.php',
4108 '/core/modules/modCommercial.class.php',
4109 '/core/modules/modProduit.class.php',
4110 '/core/modules/modSkype.class.php',
4111 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4112 '/core/triggers/interface_modCommande_Ecotax.class.php',
4113 '/core/triggers/interface_modCommande_fraisport.class.php',
4114 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4115 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4116 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4117 '/core/menus/smartphone/iphone.lib.php',
4118 '/core/menus/smartphone/iphone_backoffice.php',
4119 '/core/menus/smartphone/iphone_frontoffice.php',
4120 '/core/menus/standard/auguria_backoffice.php',
4121 '/core/menus/standard/auguria_frontoffice.php',
4122 '/core/menus/standard/eldy_backoffice.php',
4123 '/core/menus/standard/eldy_frontoffice.php',
4124 '/core/modules/export/export_excel.modules.php',
4125 '/core/modules/export/export_csv.modules.php',
4126 '/core/modules/export/exportcsv.modules.php',
4127 '/core/modules/export/export_excel2007new.modules.php',
4128 '/core/modules/facture/pdf_crabe.modules.php',
4129 '/core/modules/facture/pdf_oursin.modules.php',
4130 '/core/modules/mailings/contacts2.modules.php',
4131 '/core/modules/mailings/contacts3.modules.php',
4132 '/core/modules/mailings/contacts4.modules.php',
4133 '/core/modules/mailings/framboise.modules.php',
4134 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4135 '/core/modules/mailings/peche.modules.php',
4136 '/core/modules/mailings/poire.modules.php',
4137 '/core/modules/mailings/kiwi.modules.php',
4138 '/core/boxes/box_members.php',
4140 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4141 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4142 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4144 '/api/class/api_generic.class.php',
4145 '/asterisk/cidlookup.php',
4146 '/categories/class/api_category.class.php',
4147 '/categories/class/api_deprecated_category.class.php',
4148 '/compta/facture/class/api_invoice.class.php',
4149 '/commande/class/api_commande.class.php',
4150 '/user/class/api_user.class.php',
4151 '/product/class/api_product.class.php',
4152 '/societe/class/api_contact.class.php',
4153 '/societe/class/api_thirdparty.class.php',
4154 '/support/online.php',
4155 '/takepos/class/actions_takepos.class.php',
4157 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4158 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4159 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4160 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4161 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4162 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4165 foreach ($filetodeletearray as $filetodelete) {
4167 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4168 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true,
false);
4170 $langs->load(
"errors");
4171 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4172 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4197 $filetodeletearray = array(
4198 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4199 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4203 if (!empty($_SERVER[
"WINDIR"])) {
4204 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4207 foreach ($filetodeletearray as $filetodelete) {
4209 if (file_exists($filetodelete)) {
4213 $langs->load(
"errors");
4214 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4215 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4239 if (count($listofmodule) == 0) {
4243 if (!is_object($user)) {
4244 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4245 $user =
new User($db);
4248 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".join(
',', array_keys($listofmodule)));
4250 $reloadactionformodules = array(
4251 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove'=> 1),
4252 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4253 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove'=> 1),
4254 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus'=> 1),
4255 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove'=> 1),
4256 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove'=> 1),
4257 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove'=> 1),
4258 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4259 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4260 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4261 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4262 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4263 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove'=>1),
4264 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4265 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4266 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove'=>1),
4267 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove'=>1),
4268 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove'=>1),
4269 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove'=>1),
4270 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove'=>1),
4271 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove'=>1),
4272 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove'=>1),
4273 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove'=>1),
4274 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove'=>1),
4277 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4278 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4284 if (!empty($reloadactionformodules[$moduletoreload])) {
4285 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4287 $val = $reloadactionformodules[$moduletoreload];
4288 $classformodule = $val[
'class'];
4289 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4291 $mod =
new $classformodule($db);
4292 if (!empty($val[
'remove'])) {
4293 $mod->remove(
'noboxes');
4295 if (!empty($val[
'deleteinsertmenus'])) {
4297 $mod->delete_menus();
4298 $mod->insert_menus();
4300 $mod->init($reloadmode);
4305 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4306 if (!empty($reg[1])) {
4307 if (strtoupper($moduletoreload) == $moduletoreload) {
4308 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4311 $moduletoreloadshort = $reg[1];
4314 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4316 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4318 $classname =
'mod'.$moduletoreloadshort;
4319 $mod =
new $classname($db);
4322 $mod->delete_menus();
4323 $mod->init($reloadmode);
4325 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4327 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4329 $classname =
'mod'.$moduletoreloadshort;
4330 $mod =
new $classname($db);
4331 $mod->init($reloadmode);
4333 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4334 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4340 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4345 if (!empty($mod) && is_object($mod)) {
4346 print
'<tr class="trforrunsql"><td colspan="4">';
4347 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4348 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4349 print
"<!-- (".$reloadmode.
") -->";
4374 $listofmenuhandler = array();
4375 if ($conf->global->MAIN_MENU_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENU_SMARTPHONE ==
'auguria_menu'
4376 || $conf->global->MAIN_MENUFRONT_STANDARD ==
'auguria_menu' || $conf->global->MAIN_MENUFRONT_SMARTPHONE ==
'auguria_menu') {
4377 $listofmenuhandler[
'auguria'] = 1;
4380 foreach ($listofmenuhandler as $key => $val) {
4381 print
'<tr class="trforrunsql"><td colspan="4">';
4385 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4388 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4389 $file =
'init_menu_'.$key.
'.sql';
4390 if (file_exists($dir.$file)) {
4391 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4407 global $conf, $db, $langs, $user;
4409 print
'<tr><td colspan="4">';
4411 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4413 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4414 $fuser =
new User($db);
4415 if (!is_object($user)) {
4419 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4420 $resql = $db->query($sql);
4422 while ($obj = $db->fetch_object($resql)) {
4424 $fuser->id = $obj->uid;
4425 $fuser->entity = $obj->entity;
4428 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4430 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4432 $dir = $conf->user->multidir_output[$entity];
4437 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4438 $destin = $dir.
'/'.$fuser->id;
4446 $handle = opendir($origin_osencoded);
4447 if (is_resource($handle)) {
4448 while (($file = readdir($handle)) !==
false) {
4449 if ($file ==
'.' || $file ==
'..') {
4454 $thumbs = opendir($origin_osencoded.
'/'.$file);
4455 if (is_resource($thumbs)) {
4457 while (($thumb = readdir($thumbs)) !==
false) {
4459 if ($thumb ==
'.' || $thumb ==
'..') {
4465 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4475 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4496 global $db, $langs, $user;
4498 print
'<tr><td colspan="4">';
4500 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4502 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4503 $fuser =
new User($db);
4504 if (!is_object($user)) {
4508 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4509 $resql = $db->query($sql);
4511 while ($obj = $db->fetch_object($resql)) {
4513 $fuser->id = $obj->uid;
4514 $fuser->entity = $obj->entity;
4515 $fuser->photo = $obj->photo;
4518 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4520 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4522 $dir = DOL_DATA_ROOT.
'/users';
4527 $origin = $dir.
'/'.$fuser->id;
4528 $destin = $dir.
'/'.$fuser->id.
'/photos';
4536 $handle = opendir($origin_osencoded);
4537 if (is_resource($handle)) {
4538 while (($file = readdir($handle)) !==
false) {
4539 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4542 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4547 $thumbs = opendir($origin_osencoded.
'/'.$file);
4548 if (is_resource($thumbs)) {
4550 while (($thumb = readdir($thumbs)) !==
false) {
4552 if ($thumb ==
'.' || $thumb ==
'..') {
4558 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4567 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4604 print
'<tr><td colspan="4">';
4605 $sql =
'SELECT rowid, socialnetworks';
4606 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4607 $sql .=
" skype IS NOT NULL OR skype <> ''";
4608 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4609 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4610 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4611 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4612 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4613 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4614 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4615 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4617 $resql = $db->query($sql);
4619 while ($obj = $db->fetch_object($resql)) {
4620 $arraysocialnetworks = array();
4621 if (!empty($obj->skype)) {
4622 $arraysocialnetworks[
'skype'] = $obj->skype;
4624 if (!empty($obj->twitter)) {
4625 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4627 if (!empty($obj->facebook)) {
4628 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4630 if (!empty($obj->linkedin)) {
4631 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4633 if (!empty($obj->instagram)) {
4634 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4636 if (!empty($obj->snapchat)) {
4637 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4639 if (!empty($obj->googleplus)) {
4640 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4642 if (!empty($obj->youtube)) {
4643 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4645 if (!empty($obj->whatsapp)) {
4646 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4648 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4649 $obj->socialnetworks =
'[]';
4651 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4652 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4653 $sqlupd .=
', skype=null';
4654 $sqlupd .=
', twitter=null';
4655 $sqlupd .=
', facebook=null';
4656 $sqlupd .=
', linkedin=null';
4657 $sqlupd .=
', instagram=null';
4658 $sqlupd .=
', snapchat=null';
4659 $sqlupd .=
', googleplus=null';
4660 $sqlupd .=
', youtube=null';
4661 $sqlupd .=
', whatsapp=null';
4662 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4664 $resqlupd = $db->query($sqlupd);
4679 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4693 print
'<tr><td colspan="4">';
4696 print
'<tr><td colspan="4">';
4697 $sql =
'SELECT rowid, socialnetworks';
4698 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4699 $sql .=
" skype IS NOT NULL OR skype <> ''";
4700 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4701 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4702 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4703 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4704 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4705 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4706 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4707 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4709 $resql = $db->query($sql);
4711 while ($obj = $db->fetch_object($resql)) {
4712 $arraysocialnetworks = array();
4713 if (!empty($obj->skype)) {
4714 $arraysocialnetworks[
'skype'] = $obj->skype;
4716 if (!empty($obj->twitter)) {
4717 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4719 if (!empty($obj->facebook)) {
4720 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4722 if (!empty($obj->linkedin)) {
4723 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4725 if (!empty($obj->instagram)) {
4726 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4728 if (!empty($obj->snapchat)) {
4729 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4731 if (!empty($obj->googleplus)) {
4732 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4734 if (!empty($obj->youtube)) {
4735 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4737 if (!empty($obj->whatsapp)) {
4738 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4740 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4741 $obj->socialnetworks =
'[]';
4743 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4744 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4745 $sqlupd .=
', skype=null';
4746 $sqlupd .=
', twitter=null';
4747 $sqlupd .=
', facebook=null';
4748 $sqlupd .=
', linkedin=null';
4749 $sqlupd .=
', instagram=null';
4750 $sqlupd .=
', snapchat=null';
4751 $sqlupd .=
', googleplus=null';
4752 $sqlupd .=
', youtube=null';
4753 $sqlupd .=
', whatsapp=null';
4754 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4756 $resqlupd = $db->query($sqlupd);
4771 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4787 print
'<tr><td colspan="4">';
4788 $sql =
'SELECT rowid, socialnetworks';
4789 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4790 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4791 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4792 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4793 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4794 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4795 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4796 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4797 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4798 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4799 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4801 $resql = $db->query($sql);
4803 while ($obj = $db->fetch_object($resql)) {
4804 $arraysocialnetworks = array();
4805 if (!empty($obj->jabberid)) {
4806 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4808 if (!empty($obj->skype)) {
4809 $arraysocialnetworks[
'skype'] = $obj->skype;
4811 if (!empty($obj->twitter)) {
4812 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4814 if (!empty($obj->facebook)) {
4815 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4817 if (!empty($obj->linkedin)) {
4818 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4820 if (!empty($obj->instagram)) {
4821 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4823 if (!empty($obj->snapchat)) {
4824 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4826 if (!empty($obj->googleplus)) {
4827 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4829 if (!empty($obj->youtube)) {
4830 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4832 if (!empty($obj->whatsapp)) {
4833 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4835 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4836 $obj->socialnetworks =
'[]';
4838 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4839 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4840 $sqlupd .=
', jabberid=null';
4841 $sqlupd .=
', skype=null';
4842 $sqlupd .=
', twitter=null';
4843 $sqlupd .=
', facebook=null';
4844 $sqlupd .=
', linkedin=null';
4845 $sqlupd .=
', instagram=null';
4846 $sqlupd .=
', snapchat=null';
4847 $sqlupd .=
', googleplus=null';
4848 $sqlupd .=
', youtube=null';
4849 $sqlupd .=
', whatsapp=null';
4850 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4852 $resqlupd = $db->query($sqlupd);
4867 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4883 print
'<tr><td colspan="4">';
4884 $sql =
'SELECT rowid, socialnetworks';
4885 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4886 $sql .=
" skype IS NOT NULL OR skype <> ''";
4887 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4888 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4889 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4890 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4891 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4892 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4893 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4894 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4896 $resql = $db->query($sql);
4898 while ($obj = $db->fetch_object($resql)) {
4899 $arraysocialnetworks = array();
4900 if (!empty($obj->skype)) {
4901 $arraysocialnetworks[
'skype'] = $obj->skype;
4903 if (!empty($obj->twitter)) {
4904 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4906 if (!empty($obj->facebook)) {
4907 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4909 if (!empty($obj->linkedin)) {
4910 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4912 if (!empty($obj->instagram)) {
4913 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4915 if (!empty($obj->snapchat)) {
4916 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4918 if (!empty($obj->googleplus)) {
4919 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4921 if (!empty($obj->youtube)) {
4922 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4924 if (!empty($obj->whatsapp)) {
4925 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4927 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4928 $obj->socialnetworks =
'[]';
4930 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4931 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4932 $sqlupd .=
', skype=null';
4933 $sqlupd .=
', twitter=null';
4934 $sqlupd .=
', facebook=null';
4935 $sqlupd .=
', linkedin=null';
4936 $sqlupd .=
', instagram=null';
4937 $sqlupd .=
', snapchat=null';
4938 $sqlupd .=
', googleplus=null';
4939 $sqlupd .=
', youtube=null';
4940 $sqlupd .=
', whatsapp=null';
4941 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4943 $resqlupd = $db->query($sqlupd);
4958 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
4978 print
'<tr class="trforrunsql"><td colspan="4">';
4979 $sql =
'SELECT rowid, field';
4980 if ($mode ==
'export') {
4983 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
4984 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
4986 $resql = $db->query($sql);
4988 while ($obj = $db->fetch_object($resql)) {
4989 $oldfield = $obj->field;
4990 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
4992 if ($mode ==
'export') {
4993 $oldfilter = $obj->filter;
4994 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5000 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5001 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5002 if ($mode ==
'export') {
5003 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5005 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5006 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5007 $resqlupd = $db->query($sqlupd);
5023 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5026 if ($resultstring) {
5027 print $resultstring;
5029 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5047 print
'<tr class="trforrunsql"><td colspan="4">';
5048 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5050 $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";
5051 $sql .=
" ORDER BY c.rowid,cd.rowid";
5053 $resql = $db->query($sql);
5056 $current_contract=0;
5057 while ($obj = $db->fetch_object($resql)) {
5058 if (empty($current_contract) || $current_contract==$obj->cid) {
5064 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5065 $resultstring =
'.';
5066 print $resultstring;
5067 $resqlUpd = $db->query($sqlUpd);
5073 $current_contract = $obj->cid;
5086 if (!$resultstring) {
5087 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
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.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
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.
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_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.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another 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...
dol_now($mode='auto')
Return date for now.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
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_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.
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_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.
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_element_time($db, $langs, $conf)
Migrate duration in seconds.
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.