44define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
45include_once
'inc.php';
46if (!file_exists($conffile)) {
47 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").';
49require_once $conffile;
50require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
51require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
52require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
53require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
54require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
55require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
56require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
57require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
68$err = error_reporting();
71 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
77$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
78$langs->setDefaultLang($setuplang);
79$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
80$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
81$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
83$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
85if ($dolibarr_main_db_type ==
'mysqli') {
88if ($dolibarr_main_db_type ==
'pgsql') {
91if ($dolibarr_main_db_type ==
'mssql') {
96dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
97if (!is_object($conf)) {
107if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
108 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
109 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
111 $sapi_type = php_sapi_name();
112 $script_file = basename(__FILE__);
114 if (substr($sapi_type, 0, 3) ==
'cli') {
115 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
120pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
123if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
124 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
125 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
127 print
'<table border="0" width="100%">';
130 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
131 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
132 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
133 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
134 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
135 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
137 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
142 $conf->db->type = $dolibarr_main_db_type;
143 $conf->db->host = $dolibarr_main_db_host;
144 $conf->db->port = $dolibarr_main_db_port;
145 $conf->db->name = $dolibarr_main_db_name;
146 $conf->db->user = $dolibarr_main_db_user;
147 $conf->db->pass = $dolibarr_main_db_pass;
149 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
151 if (!$db->connected) {
152 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
153 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
158 if ($db->database_selected) {
165 if (empty($dolibarr_main_db_encryption)) {
166 $dolibarr_main_db_encryption = 0;
168 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
169 if (empty($dolibarr_main_db_cryptkey)) {
170 $dolibarr_main_db_cryptkey =
'';
172 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
175 $conf->setValues($db);
178 $listofentities = array(1);
181 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
183 $hookmanager->initHooks(array(
'upgrade2'));
185 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
188 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
189 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
191 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
220 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
222 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
228 foreach ($listofentities as $entity) {
230 $conf->setEntityValues($db, $entity);
232 if (defined(
'SYSLOG_FILE')) {
233 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
235 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
237 $versiontoarray = array();
238 $versionranarray = array();
241 if (count($listofentities) > 1) {
242 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
247 $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 :
''));
253 $versiontoarray = explode(
'.', $versionto);
254 $versionranarray = explode(
'.', DOL_VERSION);
257 $afterversionarray = explode(
'.',
'2.0.0');
258 $beforeversionarray = explode(
'.',
'2.7.9');
319 $afterversionarray = explode(
'.',
'2.7.9');
320 $beforeversionarray = explode(
'.',
'2.8.9');
345 $afterversionarray = explode(
'.',
'2.8.9');
346 $beforeversionarray = explode(
'.',
'2.9.9');
358 $afterversionarray = explode(
'.',
'2.9.9');
359 $beforeversionarray = explode(
'.',
'3.0.9');
365 $afterversionarray = explode(
'.',
'3.0.9');
366 $beforeversionarray = explode(
'.',
'3.1.9');
374 $afterversionarray = explode(
'.',
'3.1.9');
375 $beforeversionarray = explode(
'.',
'3.2.9');
385 $afterversionarray = explode(
'.',
'3.2.9');
386 $beforeversionarray = explode(
'.',
'3.3.9');
395 $afterversionarray = explode(
'.',
'3.6.9');
396 $beforeversionarray = explode(
'.',
'3.7.9');
402 $afterversionarray = explode(
'.',
'3.7.9');
403 $beforeversionarray = explode(
'.',
'3.8.9');
409 $afterversionarray = explode(
'.',
'3.9.9');
410 $beforeversionarray = explode(
'.',
'4.0.9');
416 $afterversionarray = explode(
'.',
'4.0.9');
417 $beforeversionarray = explode(
'.',
'5.0.9');
427 $afterversionarray = explode(
'.',
'5.0.9');
428 $beforeversionarray = explode(
'.',
'6.0.9');
430 if (isModEnabled(
'multicompany')) {
431 global $multicompany_transverse_mode;
434 if (empty($multicompany_transverse_mode)) {
445 $afterversionarray = explode(
'.',
'6.0.9');
446 $beforeversionarray = explode(
'.',
'7.0.9');
455 $afterversionarray = explode(
'.',
'7.0.9');
456 $beforeversionarray = explode(
'.',
'8.0.9');
462 $afterversionarray = explode(
'.',
'8.0.9');
463 $beforeversionarray = explode(
'.',
'9.0.9');
469 $afterversionarray = explode(
'.',
'10.0.9');
470 $beforeversionarray = explode(
'.',
'11.0.9');
479 $afterversionarray = explode(
'.',
'13.0.9');
480 $beforeversionarray = explode(
'.',
'14.0.9');
487 $afterversionarray = explode(
'.',
'15.0.9');
488 $beforeversionarray = explode(
'.',
'16.0.9');
495 $afterversionarray = explode(
'.',
'16.0.9');
496 $beforeversionarray = explode(
'.',
'17.0.9');
502 $afterversionarray = explode(
'.',
'17.0.9');
503 $beforeversionarray = explode(
'.',
'18.0.9');
522 $listofmodule = array(
523 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
524 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
525 'MAIN_MODULE_BOM' =>
'menuonly',
526 'MAIN_MODULE_BANQUE' =>
'menuonly',
527 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
528 'MAIN_MODULE_CRON' =>
'newboxdefonly',
529 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
530 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
531 'MAIN_MODULE_DEPLACEMENT' =>
'newboxdefonly',
532 'MAIN_MODULE_DON' =>
'newboxdefonly',
533 'MAIN_MODULE_ECM' =>
'newboxdefonly',
534 'MAIN_MODULE_EXTERNALSITE' =>
'newboxdefonly',
535 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
536 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
537 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
538 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
539 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
540 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
541 'MAIN_MODULE_MARGIN' =>
'menuonly',
542 'MAIN_MODULE_MRP' =>
'menuonly',
543 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
544 'MAIN_MODULE_PAYBOX' =>
'newboxdefonly',
545 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
546 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
547 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
548 'MAIN_MODULE_RESOURCE' =>
'noboxes',
549 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
550 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
551 'MAIN_MODULE_SYSLOG' =>
'newboxdefonly',
552 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
553 'MAIN_MODULE_STRIPE' =>
'menuonly',
554 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
555 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
556 'MAIN_MODULE_USER' =>
'newboxdefonly',
557 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
558 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
574 if (!$error && $enablemodules) {
576 $listofmodules = array();
577 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
578 $tmplistofmodules = explode(
',', $enablemodules);
579 foreach ($tmplistofmodules as $value) {
580 $listofmodules[$value] =
'forceactivate';
584 if ($resultreloadmodules < 0) {
592 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
595 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
596 if ($hookmanager->resNbOfHooks > 0) {
598 print
'<tr><td colspan="4">';
599 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
600 print $hookmanager->error;
601 print
"<!-- (".$reshook.
") -->";
604 print
'<tr class="trforrunsql"><td colspan="4">';
605 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
606 print
"<!-- (".$reshook.
") -->";
611 if (!empty($conf->modules_parts[
'hooks'])) {
612 print
'<tr class="trforrunsql"><td colspan="4">';
613 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
624 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
639 foreach ($listofentities as $entity) {
641 $conf->setEntityValues($db, $entity);
643 if (defined(
'SYSLOG_FILE')) {
644 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
646 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
650 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
651 $destroot = DOL_DATA_ROOT.
'/medias';
664 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
667 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
668 if ($hookmanager->resNbOfHooks > 0) {
670 print
'<tr><td colspan="4">';
671 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
672 print $hookmanager->error;
673 print
"<!-- (".$reshook.
") -->";
676 print
'<tr class="trforrunsql"><td colspan="4">';
677 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
678 print
"<!-- (".$reshook.
") -->";
683 if (!empty($conf->modules_parts[
'hooks'])) {
684 print
'<tr class="trforrunsql"><td colspan="4">';
685 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
695 print
'<table width="100%">';
696 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
697 print
'<td class="right">';
701 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
705 print
'<script type="text/javascript">
706 jQuery(document).ready(function() {
707 function init_trrunsql()
709 console.log("toggle .trforrunsql");
710 jQuery(".trforrunsql").toggle();
713 jQuery(".trforrunsqlshowhide").click(function() {
718 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
721 print
'</td></tr>'.
"\n";
727 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
732if ($error && isset($argv[1])) {
738pFooter($error ? 2 : 0, $setuplang);
761 print
'<tr><td colspan="4">';
764 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
766 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
767 $obj = $db->fetch_object($result);
769 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
770 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
771 $sql .=
" WHERE p.fk_facture > 0";
773 $resql = $db->query($sql);
780 $num = $db->num_rows($resql);
783 $obj = $db->fetch_object($resql);
784 $row[$i][0] = $obj->rowid;
785 $row[$i][1] = $obj->fk_facture;
786 $row[$i][2] = $obj->amount;
794 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
798 for ($i = 0; $i < $num; $i++) {
799 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
800 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
802 $res += $db->query($sql);
804 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
806 $res += $db->query($sql);
808 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
812 if (is_array($row) && $res == (2 * count($row))) {
814 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
817 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
820 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
823 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
841 print
'<tr><td colspan="4">';
844 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
846 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
847 $obj = $db->fetch_object($result);
850 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
851 $sql .=
" bu2.url_id as socid";
852 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
853 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
854 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
855 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
856 $sql .=
" AND b.rappro = 1";
857 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
859 $resql = $db->query($sql);
865 $num = $db->num_rows($resql);
868 $obj = $db->fetch_object($resql);
869 if ($obj->pamount == $obj->bamount && $obj->socid) {
870 $row[$j][
'paymentid'] = $obj->rowid;
871 $row[$j][
'pamount'] = $obj->pamount;
872 $row[$j][
'fk_bank'] = $obj->fk_bank;
873 $row[$j][
'bamount'] = $obj->bamount;
874 $row[$j][
'socid'] = $obj->socid;
875 $row[$j][
'datec'] = $obj->datec;
885 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
890 for ($i = 0; $i < $num; $i++) {
892 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>';
896 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
897 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
898 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
899 $sql .=
" AND pf.fk_facture IS NULL";
900 $sql .=
" ORDER BY f.fk_statut";
902 $resql = $db->query($sql);
904 $num = $db->num_rows($resql);
907 $obj = $db->fetch_object($resql);
908 $facid = $obj->rowid;
910 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
911 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
913 $res += $db->query($sql);
915 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
923 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
925 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
930 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
933 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
951 print
'<tr><td colspan="4">';
954 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
956 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
957 $obj = $db->fetch_object($result);
960 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
961 $sql .=
" bu2.url_id as socid";
962 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
963 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
964 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
965 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
966 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
968 $resql = $db->query($sql);
974 $num = $db->num_rows($resql);
977 $obj = $db->fetch_object($resql);
978 if ($obj->pamount == $obj->bamount && $obj->socid) {
979 $row[$j][
'paymentid'] = $obj->rowid;
980 $row[$j][
'pamount'] = $obj->pamount;
981 $row[$j][
'fk_bank'] = $obj->fk_bank;
982 $row[$j][
'bamount'] = $obj->bamount;
983 $row[$j][
'socid'] = $obj->socid;
984 $row[$j][
'datec'] = $obj->datec;
997 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
1001 for ($i = 0; $i < $num; $i++) {
1003 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>';
1007 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1008 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1009 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1010 $sql .=
" AND pf.fk_facture IS NULL";
1011 $sql .=
" ORDER BY f.fk_statut";
1013 $resql = $db->query($sql);
1015 $num = $db->num_rows($resql);
1018 $obj = $db->fetch_object($resql);
1019 $facid = $obj->rowid;
1021 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1022 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1024 $res += $db->query($sql);
1026 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1035 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1037 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1042 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1048 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1058 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1075 print
'<tr><td colspan="4">';
1080 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1082 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1083 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1084 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1085 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1086 $sql .=
" ON c.fk_product = p.rowid";
1087 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1088 $sql .=
" ON c.rowid=cd.fk_contrat";
1089 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1090 $resql = $db->query($sql);
1096 $num = $db->num_rows($resql);
1099 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1103 $obj = $db->fetch_object($resql);
1105 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1106 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1107 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1108 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1109 $sql .=
" VALUES (";
1110 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1112 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1113 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1116 $sql .= ((float) $obj->tva_tx).
", 1, ";
1117 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1121 if ($db->query($sql)) {
1122 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1134 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1137 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1140 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1143 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1160 print
'<tr><td colspan="4">';
1165 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1167 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1168 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1169 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1170 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1171 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1172 $sql .=
" AND bu.fk_bank IS NULL";
1173 $resql = $db->query($sql);
1179 $num = $db->num_rows($resql);
1182 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1186 $obj = $db->fetch_object($resql);
1188 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1189 $sql .=
"fk_bank, url_id, url, label, type";
1191 $sql .=
" VALUES (";
1192 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1198 if (!$db->query($sql)) {
1209 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1212 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1215 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1234 print
'<tr><td colspan="4">';
1237 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1239 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1241 $resql = $db->query($sql);
1245 if ($db->affected_rows($resql) > 0) {
1246 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1248 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1251 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1253 $resql = $db->query($sql);
1257 if ($db->affected_rows($resql) > 0) {
1258 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1260 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1276 print
'<tr><td colspan="4">';
1281 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1283 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1285 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1286 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1287 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1288 $resql = $db->query($sql);
1294 $num = $db->num_rows($resql);
1297 $nbcontratsmodifie = 0;
1301 $obj = $db->fetch_object($resql);
1302 if ($obj->date_contrat > $obj->datemin) {
1303 $datemin = $db->jdate($obj->datemin);
1305 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1306 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1307 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1308 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1309 $resql2 = $db->query($sql);
1314 $nbcontratsmodifie++;
1321 if ($nbcontratsmodifie) {
1322 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1324 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1344 print
'<tr><td colspan="4">';
1347 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1349 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1351 $resql = $db->query($sql);
1355 if ($db->affected_rows($resql) > 0) {
1356 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1358 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1374 print
'<tr><td colspan="4">';
1377 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1379 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1380 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1382 $resql = $db->query($sql);
1386 if ($db->affected_rows($resql) > 0) {
1389 $num = $db->num_rows($resql);
1392 $nbcontratsmodifie = 0;
1396 $obj = $db->fetch_object($resql);
1398 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1399 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1400 $sql .=
" SET statut = 1";
1401 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1402 $resql2 = $db->query($sql);
1407 $nbcontratsmodifie++;
1414 if ($nbcontratsmodifie) {
1415 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1417 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1421 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1439 print
'<tr><td colspan="4">';
1441 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1444 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1445 $obj = $db->fetch_object($result);
1450 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1451 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1452 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1455 $select_resql = $db->query($select_sql);
1456 if ($select_resql) {
1457 $select_num = $db->num_rows($select_resql);
1461 while (($i < $select_num) && (!$error)) {
1462 $select_obj = $db->fetch_object($select_resql);
1465 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1466 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1467 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1468 $check_resql = $db->query($check_sql);
1470 $check_num = $db->num_rows($check_resql);
1471 if ($check_num == 0) {
1475 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1476 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1479 print
'<tr class="oddeven">';
1480 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1482 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1483 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1484 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1485 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1486 $insert_resql = $db->query($insert_sql);
1488 if ($insert_resql) {
1490 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1492 print
'<td><span class="error">Error on insert</span></td>';
1508 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1512 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1515 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1519 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1536 $tmpmysoc->setMysoc($conf);
1540 print
'<tr><td colspan="4">';
1543 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1546 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1547 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1549 $sql .=
" WHERE fd.fk_facture = f.rowid";
1550 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1554 $resql = $db->query($sql);
1556 $num = $db->num_rows($resql);
1560 $obj = $db->fetch_object($resql);
1562 $rowid = $obj->rowid;
1564 $pu = $obj->subprice;
1565 $vatrate = $obj->vatrate;
1566 $remise_percent = $obj->remise_percent;
1567 $remise_percent_global = $obj->remise_percent_global;
1568 $total_ttc_f = $obj->total_ttc_f;
1569 $info_bits = $obj->info_bits;
1573 $facligne->fetch($rowid);
1575 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1576 $total_ht = $result[0];
1577 $total_tva = $result[1];
1578 $total_ttc = $result[2];
1580 $facligne->total_ht = $total_ht;
1581 $facligne->total_tva = $total_tva;
1582 $facligne->total_ttc = $total_ttc;
1584 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);
1586 $facligne->update_total();
1590 if (!$total_ttc_f) {
1592 $facture->id = $obj->facid;
1594 if ($facture->fetch($facture->id) >= 0) {
1595 if ($facture->update_price() > 0) {
1598 print
"Error id=".$facture->id;
1611 print $langs->trans(
"AlreadyDone");
1617 print
"Error #1 ".$db->error();
1639 $tmpmysoc->setMysoc($conf);
1643 print
'<tr><td colspan="4">';
1646 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1649 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1650 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1651 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1652 $sql .=
" WHERE pd.fk_propal = p.rowid";
1653 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1656 $resql = $db->query($sql);
1658 $num = $db->num_rows($resql);
1662 $obj = $db->fetch_object($resql);
1664 $rowid = $obj->rowid;
1666 $pu = $obj->subprice;
1667 $vatrate = $obj->vatrate;
1668 $remise_percent = $obj->remise_percent;
1669 $remise_percent_global = $obj->remise_percent_global;
1670 $info_bits = $obj->info_bits;
1674 $propalligne->fetch($rowid);
1676 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1677 $total_ht = $result[0];
1678 $total_tva = $result[1];
1679 $total_ttc = $result[2];
1681 $propalligne->total_ht = $total_ht;
1682 $propalligne->total_tva = $total_tva;
1683 $propalligne->total_ttc = $total_ttc;
1685 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);
1687 $propalligne->update_total();
1692 print $langs->trans(
"AlreadyDone");
1699 print
"Error #1 ".$db->error();
1722 $tmpmysoc->setMysoc($conf);
1723 if (empty($tmpmysoc->country_id)) {
1724 $tmpmysoc->country_id = 0;
1727 print
'<tr><td colspan="4">';
1730 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1733 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1734 $sql .=
" c.rowid as contratid";
1735 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1736 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1737 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1740 $resql = $db->query($sql);
1742 $num = $db->num_rows($resql);
1746 $obj = $db->fetch_object($resql);
1748 $rowid = $obj->rowid;
1750 $pu = $obj->subprice;
1751 $vatrate = $obj->vatrate;
1752 $remise_percent = $obj->remise_percent;
1753 $info_bits = $obj->info_bits;
1758 $contratligne->fetch($rowid);
1760 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1761 $total_ht = $result[0];
1762 $total_tva = $result[1];
1763 $total_ttc = $result[2];
1765 $contratligne->total_ht = $total_ht;
1766 $contratligne->total_tva = $total_tva;
1767 $contratligne->total_ttc = $total_ttc;
1769 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);
1771 $contratligne->update_total();
1776 print $langs->trans(
"AlreadyDone");
1783 print
"Error #1 ".$db->error();
1806 $tmpmysoc->setMysoc($conf);
1808 print
'<tr><td colspan="4">';
1811 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1814 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1815 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1816 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1817 $sql .=
" WHERE cd.fk_commande = c.rowid";
1818 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1821 $resql = $db->query($sql);
1823 $num = $db->num_rows($resql);
1827 $obj = $db->fetch_object($resql);
1829 $rowid = $obj->rowid;
1831 $pu = $obj->subprice;
1832 $vatrate = $obj->vatrate;
1833 $remise_percent = $obj->remise_percent;
1834 $remise_percent_global = $obj->remise_percent_global;
1835 $info_bits = $obj->info_bits;
1839 $commandeligne->fetch($rowid);
1841 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1842 $total_ht = $result[0];
1843 $total_tva = $result[1];
1844 $total_ttc = $result[2];
1846 $commandeligne->total_ht = $total_ht;
1847 $commandeligne->total_tva = $total_tva;
1848 $commandeligne->total_ttc = $total_ttc;
1850 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);
1852 $commandeligne->update_total();
1857 print $langs->trans(
"AlreadyDone");
1874 print
"Error #1 ".$db->error();
1899 $tmpmysoc->setMysoc($conf);
1901 print
'<tr><td colspan="4">';
1904 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1907 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1908 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1909 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1910 $sql .=
" WHERE cd.fk_commande = c.rowid";
1911 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1914 $resql = $db->query($sql);
1916 $num = $db->num_rows($resql);
1920 $obj = $db->fetch_object($resql);
1922 $rowid = $obj->rowid;
1924 $pu = $obj->subprice;
1925 $vatrate = $obj->vatrate;
1926 $remise_percent = $obj->remise_percent;
1927 $remise_percent_global = $obj->remise_percent_global;
1928 $info_bits = $obj->info_bits;
1932 $commandeligne->fetch($rowid);
1934 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $mysoc);
1935 $total_ht = $result[0];
1936 $total_tva = $result[1];
1937 $total_ttc = $result[2];
1939 $commandeligne->total_ht = $total_ht;
1940 $commandeligne->total_tva = $total_tva;
1941 $commandeligne->total_ttc = $total_ttc;
1943 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);
1945 $commandeligne->update_total();
1950 print $langs->trans(
"AlreadyDone");
1967 print
"Error #1 ".$db->error();
1992 if (isModEnabled(
'invoice')) {
1993 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1995 if (count($modellist) == 0) {
1997 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
1998 $resql = $db->query($sql);
2005 if (isModEnabled(
'order')) {
2006 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2008 if (count($modellist) == 0) {
2010 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2011 $resql = $db->query($sql);
2018 if (isModEnabled(
"shipping")) {
2019 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2021 if (count($modellist) == 0) {
2023 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2024 $resql = $db->query($sql);
2047 print
'<tr><td colspan="4">';
2050 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2052 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2053 $obj = $db->fetch_object($result);
2059 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2060 $resql = $db->query($sql);
2063 $num = $db->num_rows($resql);
2067 $obj = $db->fetch_object($resql);
2069 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2070 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2071 $resql2 = $db->query($sql);
2084 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2085 print $langs->trans(
'FieldRenamed').
"<br>\n";
2095 print $langs->trans(
'AlreadyDone').
"<br>\n";
2112 print
'<tr><td colspan="4">';
2115 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2117 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2118 $obj = $db->fetch_object($result);
2124 $sql =
"SELECT l.rowid, l.fk_commande,";
2125 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2126 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2127 $sql .=
" WHERE c.rowid = l.fk_commande";
2128 $resql = $db->query($sql);
2131 $num = $db->num_rows($resql);
2135 $obj = $db->fetch_object($resql);
2137 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2138 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2139 $resql2 = $db->query($sql);
2142 $delivery_date = $db->jdate($obj->delivery_date);
2144 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2145 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2146 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2147 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2148 $resql3 = $db->query($sqlu);
2164 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2165 print $langs->trans(
'FieldRenamed').
"<br>\n";
2175 print $langs->trans(
'AlreadyDone').
"<br>\n";
2192 print
'<tr><td colspan="4">';
2195 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2199 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2200 $obj = $db->fetch_object($result);
2206 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2207 $sql .=
", ld.fk_livraison";
2208 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2209 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2210 $resql = $db->query($sql);
2213 $num = $db->num_rows($resql);
2217 $obj = $db->fetch_object($resql);
2219 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2220 $sql .=
" fk_product = ".((int) $obj->fk_product);
2221 $sql .=
",description = '".$db->escape($obj->description).
"'";
2222 $sql .=
",subprice = ".price2num($obj->subprice);
2223 $sql .=
",total_ht = ".price2num($obj->total_ht);
2224 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2225 $resql2 = $db->query($sql);
2228 $sql =
"SELECT total_ht";
2229 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2230 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2231 $resql3 = $db->query($sql);
2234 $obju = $db->fetch_object($resql3);
2235 $total_ht = $obju->total_ht + $obj->total_ht;
2237 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2238 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2239 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2240 $resql4 = $db->query($sqlu);
2260 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2261 print $langs->trans(
'FieldRenamed').
"<br>\n";
2271 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2272 $obj = $db->fetch_object($result);
2274 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2277 print $langs->trans(
'AlreadyDone').
"<br>\n";
2294 print
'<tr><td colspan="4">';
2297 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2303 $sql =
"SELECT SUM(reel) as total, fk_product";
2304 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2305 $sql .=
" GROUP BY fk_product";
2306 $resql = $db->query($sql);
2309 $num = $db->num_rows($resql);
2313 $obj = $db->fetch_object($resql);
2315 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2316 $sql .=
" stock = ".price2num($obj->total,
'MS');
2317 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2319 $resql2 = $db->query($sql);
2356 print
'<tr><td colspan="4">';
2359 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2363 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2366 $sql =
"SELECT m.rowid, mc.action";
2367 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2368 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2369 $sql .=
" AND m.enabled = '1'";
2370 $resql = $db->query($sql);
2373 $num = $db->num_rows($resql);
2376 $obj = $db->fetch_object($resql);
2378 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2379 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2380 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2381 $sql .=
" AND enabled = '1'";
2383 $resql2 = $db->query($sql);
2404 print $langs->trans(
'AlreadyDone').
"<br>\n";
2423 print
'<tr><td colspan="4">';
2426 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2430 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2433 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2434 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2435 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2436 $sql .=
" WHERE c.rowid = ce.fk_commande";
2437 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2439 $resql = $db->query($sql);
2442 $num = $db->num_rows($resql);
2446 $obj = $db->fetch_object($resql);
2448 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2449 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2450 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2452 $resql2 = $db->query($sql);
2461 print $langs->trans(
'AlreadyDone').
"<br>\n";
2474 print $langs->trans(
'AlreadyDone').
"<br>\n";
2493 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2495 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2499 print
'<tr><td colspan="4">';
2502 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2508 $table1 =
'facturedet';
2509 $field1 =
'fk_remise_except';
2510 $table2 =
'societe_remise_except';
2511 $field2 =
'fk_facture_line';
2515 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2516 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2517 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2518 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2519 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2522 $resql = $db->query($sql);
2525 $num = $db->num_rows($resql);
2529 $obj = $db->fetch_object($resql);
2531 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2533 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2534 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2535 $sql .=
" WHERE rowid = ".((int) $obj->field);
2537 $resql2 = $db->query($sql);
2546 print $langs->trans(
'AlreadyDone').
"<br>\n";
2562 print
'<tr><td colspan="4">';
2565 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2568 $table2 =
'facturedet';
2569 $field2 =
'fk_remise_except';
2570 $table1 =
'societe_remise_except';
2571 $field1 =
'fk_facture_line';
2575 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2576 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2577 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2578 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2579 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2582 $resql = $db->query($sql);
2585 $num = $db->num_rows($resql);
2589 $obj = $db->fetch_object($resql);
2591 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2593 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2594 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2595 $sql .=
" WHERE rowid = ".((int) $obj->field);
2597 $resql2 = $db->query($sql);
2606 print $langs->trans(
'AlreadyDone').
"<br>\n";
2621 return ($error ? -1 : 1);
2636 print
'<tr><td colspan="4">';
2639 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2641 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2642 $obj = $db->fetch_object($result);
2648 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2649 $resql = $db->query($sql);
2652 $num = $db->num_rows($resql);
2656 $obj = $db->fetch_object($resql);
2658 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2659 $sql2 .=
"datecreate";
2660 $sql2 .=
", statut";
2661 $sql2 .=
", element_id";
2662 $sql2 .=
", fk_c_type_contact";
2663 $sql2 .=
", fk_socpeople";
2664 $sql2 .=
") VALUES (";
2665 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2667 $sql2 .=
", ".$obj->rowid;
2669 $sql2 .=
", ".$obj->fk_user_resp;
2672 if ($obj->fk_user_resp > 0) {
2673 $resql2 = $db->query($sql2);
2686 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2687 if ($db->query($sqlDrop)) {
2700 print $langs->trans(
'AlreadyDone').
"<br>\n";
2717 print
'<tr><td colspan="4">';
2720 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2722 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2727 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2728 $resql = $db->query($sql);
2731 $num = $db->num_rows($resql);
2735 $obj = $db->fetch_object($resql);
2737 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2738 $sql2 .=
"datecreate";
2739 $sql2 .=
", statut";
2740 $sql2 .=
", element_id";
2741 $sql2 .=
", fk_c_type_contact";
2742 $sql2 .=
", fk_socpeople";
2743 $sql2 .=
") VALUES (";
2744 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2746 $sql2 .=
", ".$obj->fk_project_task;
2748 $sql2 .=
", ".$obj->fk_user;
2751 $resql2 = $db->query($sql2);
2763 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2764 if ($db->query($sqlDrop)) {
2777 print $langs->trans(
'AlreadyDone').
"<br>\n";
2797 print
'<tr><td colspan="4">';
2800 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2804 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2809 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2810 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2812 $resql = $db->query($sqlSelect);
2815 $num = $db->num_rows($resql);
2819 $obj = $db->fetch_object($resql);
2821 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2822 $sqlInsert .=
"fk_source";
2823 $sqlInsert .=
", sourcetype";
2824 $sqlInsert .=
", fk_target";
2825 $sqlInsert .=
", targettype";
2826 $sqlInsert .=
") VALUES (";
2827 $sqlInsert .= $obj->$fk_source;
2828 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2829 $sqlInsert .=
", ".$obj->$fk_target;
2830 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2833 $result = $db->query($sqlInsert);
2842 print $langs->trans(
'AlreadyDone').
"<br>\n";
2846 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2847 if ($db->query($sqlDrop)) {
2860 print $langs->trans(
'AlreadyDone').
"<br>\n";
2878 print
'<tr><td colspan="4">';
2881 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2887 $sql =
"SELECT rowid, fk_element, element_duration";
2888 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2889 $resql = $db->query($sql);
2892 $num = $db->num_rows($resql);
2895 $totaltime = array();
2899 $obj = $db->fetch_object($resql);
2901 if ($obj->element_duration > 0) {
2904 list($hour, $min) = explode(
'.', $obj->element_duration);
2905 $hour = (int) $hour * 60 * 60;
2906 $min = (int) ((
float) (
'.'.$min)) * 3600;
2907 $newtime = $hour + $min;
2909 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2910 $sql2 .=
" element_duration = ".((int) $newtime);
2911 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2913 $resql2 = $db->query($sql2);
2920 if (!empty($totaltime[$obj->fk_element])) {
2921 $totaltime[$obj->fk_element] += $newtime;
2923 $totaltime[$obj->fk_element] = $newtime;
2926 if (!empty($totaltime[$obj->fk_element])) {
2927 $totaltime[$obj->fk_element] += $obj->element_duration;
2929 $totaltime[$obj->fk_element] = $obj->element_duration;
2938 foreach ($totaltime as $taskid => $total_duration) {
2939 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2940 $sql .=
" duration_effective = ".((int) $total_duration);
2941 $sql .=
" WHERE rowid = ".((int) $taskid);
2943 $resql = $db->query($sql);
2950 print $langs->trans(
'AlreadyDone').
"<br>\n";
2956 print $langs->trans(
'AlreadyDone').
"<br>\n";
2981 print
'<tr><td colspan="4">';
2984 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
2988 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
2989 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
2990 $obj1 = $db->fetch_object($result1);
2991 $obj2 = $db->fetch_object($result2);
2992 if (!$obj1 && !$obj2) {
2997 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
2998 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3000 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3001 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3002 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3003 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3004 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3005 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3006 $sqlSelect .=
" AND el.targettype = 'shipping'";
3008 $resql = $db->query($sqlSelect);
3011 $num = $db->num_rows($resql);
3015 $obj = $db->fetch_object($resql);
3017 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3018 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3019 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3020 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3022 $result = $db->query($sqlUpdate);
3031 print $langs->trans(
'AlreadyDone').
"<br>\n";
3049 print $langs->trans(
'AlreadyDone').
"<br>\n";
3065 print
'<tr><td colspan="4">';
3068 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3072 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3073 $obj = $db->fetch_object($result);
3079 $sqlSelect =
"SELECT rowid, fk_expedition";
3080 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3081 $sqlSelect .=
" WHERE fk_expedition is not null";
3083 $resql = $db->query($sqlSelect);
3086 $num = $db->num_rows($resql);
3090 $obj = $db->fetch_object($resql);
3092 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3093 $sqlInsert .=
"fk_source";
3094 $sqlInsert .=
", sourcetype";
3095 $sqlInsert .=
", fk_target";
3096 $sqlInsert .=
", targettype";
3097 $sqlInsert .=
") VALUES (";
3098 $sqlInsert .= $obj->fk_expedition;
3099 $sqlInsert .=
", 'shipping'";
3100 $sqlInsert .=
", ".$obj->rowid;
3101 $sqlInsert .=
", 'delivery'";
3104 $result = $db->query($sqlInsert);
3106 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3107 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3109 $result = $db->query($sqlUpdate);
3122 print $langs->trans(
'AlreadyDone').
"<br>\n";
3126 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3127 $db->query($sqlDelete);
3132 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3133 $db->query($sqlDrop);
3143 print $langs->trans(
'AlreadyDone').
"<br>\n";
3160 print
'<tr><td colspan="4">';
3163 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3171 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3172 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3173 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3174 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3175 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3176 $sqlSelect .=
" AND el.targettype = 'delivery'";
3177 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3178 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3180 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3181 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3183 $resql = $db->query($sqlSelect);
3186 $num = $db->num_rows($resql);
3190 $obj = $db->fetch_object($resql);
3192 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3193 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3194 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3195 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3197 $result = $db->query($sqlUpdate);
3206 print $langs->trans(
'AlreadyDone').
"<br>\n";
3233 print
'<tr><td colspan="4">';
3236 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3239 'propal' =>
'propalrowid',
3240 'order' =>
'fk_commande',
3241 'invoice' =>
'fk_facture',
3242 'contract' =>
'fk_contract',
3243 'order_supplier' =>
'fk_supplier_order',
3244 'invoice_supplier' =>
'fk_supplier_invoice'
3247 foreach ($elements as $type => $field) {
3248 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3249 $obj = $db->fetch_object($result);
3255 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3256 $sql .=
"fk_element = ".$db->sanitize($field).
", elementtype = '".$db->escape($type).
"'";
3257 $sql .=
" WHERE ".$db->sanitize($field).
" IS NOT NULL";
3258 $sql .=
" AND fk_element IS NULL";
3259 $sql .=
" AND elementtype IS NULL";
3261 $resql = $db->query($sql);
3275 print $langs->trans(
'AlreadyDone').
"<br>\n";
3292 print
'<tr><td colspan="4">';
3295 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3298 'old_id' => array(5, 8, 9, 10, 11),
3299 'new_id' => array(50, 51, 52, 53, 54),
3300 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3301 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3305 foreach ($elements[
'old_id'] as $key => $old_id) {
3310 $sqlSelect =
"SELECT id";
3311 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3312 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3313 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3315 $resql = $db->query($sqlSelect);
3317 $num = $db->num_rows($resql);
3323 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3324 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3325 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3326 $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]).
"')";
3327 $resqla = $db->query($sqla);
3329 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3330 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3331 $sql .=
" WHERE id = ".((int) $old_id);
3332 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3333 $resql = $db->query($sql);
3335 if ($resqla && $resql) {
3336 foreach ($elements[
'tables'] as $table) {
3337 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3338 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3339 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3341 $resql = $db->query($sql);
3364 print $langs->trans(
'AlreadyDone').
"<br>\n";
3382 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3384 $obj = $db->fetch_object($result);
3387 $children = array();
3388 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3389 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3391 $resql = $db->query($sql);
3393 $num = $db->num_rows($resql);
3394 while ($obj = $db->fetch_object($resql)) {
3395 if (!isset($children[$obj->fk_categorie_fille])) {
3396 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3397 $children[$obj->fk_categorie_fille] = 1;
3398 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3406 if (count($couples) > 0 && $num > count($couples)) {
3412 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3414 $resqld = $db->query($sql);
3417 foreach ($couples as $key => $val) {
3418 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3419 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3421 $resqli = $db->query($sql);
3429 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3430 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3433 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3434 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3439 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3440 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3457 print
'<tr><td colspan="4">';
3460 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3464 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3469 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3470 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3472 $resql = $db->query($sqlSelect);
3475 $num = $db->num_rows($resql);
3479 $obj = $db->fetch_object($resql);
3481 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3482 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3483 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3485 $result = $db->query($sqlUpdate);
3494 print $langs->trans(
'AlreadyDone').
"<br>\n";
3507 print $langs->trans(
'AlreadyDone').
"<br>\n";
3523 print
'<tr><td colspan="4">';
3526 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3534 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3535 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3536 $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";
3537 $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')";
3538 $sqlSelect .=
" ORDER BY a.id";
3541 $resql = $db->query($sqlSelect);
3544 $num = $db->num_rows($resql);
3548 $obj = $db->fetch_object($resql);
3550 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3551 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3553 $result = $db->query($sqlUpdate);
3562 print $langs->trans(
'AlreadyDone').
"<br>\n";
3589 print
'<tr><td colspan="4">';
3592 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3600 $sqlSelect =
"SELECT a.id, a.fk_contact";
3601 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3602 $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";
3603 $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')";
3604 $sqlSelect .=
" ORDER BY a.id";
3607 $resql = $db->query($sqlSelect);
3610 $num = $db->num_rows($resql);
3614 $obj = $db->fetch_object($resql);
3616 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3617 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3619 $result = $db->query($sqlUpdate);
3628 print $langs->trans(
'AlreadyDone').
"<br>\n";
3658 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3660 print
'<tr><td colspan="4">';
3663 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3671 $sqlSelect =
"SELECT DISTINCT entity";
3672 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3676 $resql = $db->query($sqlSelect);
3679 $num = $db->num_rows($resql);
3683 $obj = $db->fetch_object($resql);
3685 print
'Process entity '.$obj->entity;
3687 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3688 $resqlSearch = $db->query($sqlSearch);
3690 $objSearch = $db->fetch_object($resqlSearch);
3692 if ($objSearch && $objSearch->nb == 0) {
3693 print
' - Record for entity must be reset...';
3695 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3696 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3697 $resqlUpdate = $db->query($sqlUpdate);
3698 if (!$resqlUpdate) {
3707 $object->entity = $obj->entity;
3711 $b->setObjectData(
$object,
'MODULE_SET', 0);
3713 $res = $b->create($user);
3719 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3728 print $langs->trans(
'NothingToDo').
"<br>\n";
3755 print
'<tr><td colspan="4">';
3758 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3766 $sqlSelect =
"SELECT sr.rowid, s.entity";
3767 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3768 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3772 $resql = $db->query($sqlSelect);
3775 $num = $db->num_rows($resql);
3779 $obj = $db->fetch_object($resql);
3781 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3782 $sqlUpdate .=
" entity = ".$obj->entity;
3783 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3785 $result = $db->query($sqlUpdate);
3795 print $langs->trans(
'AlreadyDone').
"<br>\n";
3821 print
'<tr><td colspan="4">';
3824 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3832 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3833 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3836 $resql = $db->query($sqlSelect);
3839 $num = $db->num_rows($resql);
3843 $obj = $db->fetch_object($resql);
3845 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3846 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3848 $sqlSelect2 =
"SELECT f.entity";
3849 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3850 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3851 } elseif (!empty($obj->fk_facture_line)) {
3852 $sqlSelect2 =
"SELECT f.entity";
3853 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3854 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3855 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3857 $sqlSelect2 =
"SELECT s.entity";
3858 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3859 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3862 $resql2 = $db->query($sqlSelect2);
3864 if ($db->num_rows($resql2) > 0) {
3865 $obj2 = $db->fetch_object($resql2);
3867 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3868 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3869 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3871 $result = $db->query($sqlUpdate);
3886 print $langs->trans(
'AlreadyDone').
"<br>\n";
3913 print
'<tr><td colspan="4">';
3915 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3923 $sqlSelect =
"SELECT u.rowid, u.entity";
3924 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3925 $sqlSelect .=
" WHERE u.entity > 1";
3928 $resql = $db->query($sqlSelect);
3931 $num = $db->num_rows($resql);
3935 $obj = $db->fetch_object($resql);
3937 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3938 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3939 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3941 $result = $db->query($sqlUpdate);
3951 print $langs->trans(
'AlreadyDone').
"<br>\n";
3978 print
'<tr><td colspan="4">';
3980 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
3988 $sqlSelect =
"SELECT u.rowid, u.entity";
3989 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
3990 $sqlSelect .=
" WHERE u.entity > 1";
3993 $resql = $db->query($sqlSelect);
3996 $num = $db->num_rows($resql);
4000 $obj = $db->fetch_object($resql);
4002 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4003 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4004 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4006 $result = $db->query($sqlUpdate);
4016 print $langs->trans(
'AlreadyDone').
"<br>\n";
4047 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4048 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4049 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4069 $filetodeletearray = array(
4070 '/core/ajax/ajaxcompanies.php',
4071 '/core/triggers/interface_demo.class.php',
4072 '/core/menus/barre_left/default.php',
4073 '/core/menus/barre_top/default.php',
4074 '/core/modules/modComptabiliteExpert.class.php',
4075 '/core/modules/modCommercial.class.php',
4076 '/core/modules/modProduit.class.php',
4077 '/core/modules/modSkype.class.php',
4078 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4079 '/core/triggers/interface_modCommande_Ecotax.class.php',
4080 '/core/triggers/interface_modCommande_fraisport.class.php',
4081 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4082 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4083 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4084 '/core/menus/smartphone/iphone.lib.php',
4085 '/core/menus/smartphone/iphone_backoffice.php',
4086 '/core/menus/smartphone/iphone_frontoffice.php',
4087 '/core/menus/standard/auguria_backoffice.php',
4088 '/core/menus/standard/auguria_frontoffice.php',
4089 '/core/menus/standard/eldy_backoffice.php',
4090 '/core/menus/standard/eldy_frontoffice.php',
4091 '/core/modules/export/export_excel.modules.php',
4092 '/core/modules/export/export_csv.modules.php',
4093 '/core/modules/export/exportcsv.modules.php',
4094 '/core/modules/export/export_excel2007new.modules.php',
4095 '/core/modules/facture/pdf_crabe.modules.php',
4096 '/core/modules/facture/pdf_oursin.modules.php',
4097 '/core/modules/mailings/contacts2.modules.php',
4098 '/core/modules/mailings/contacts3.modules.php',
4099 '/core/modules/mailings/contacts4.modules.php',
4100 '/core/modules/mailings/framboise.modules.php',
4101 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4102 '/core/modules/mailings/peche.modules.php',
4103 '/core/modules/mailings/poire.modules.php',
4104 '/core/modules/mailings/kiwi.modules.php',
4105 '/core/boxes/box_members.php',
4107 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4108 '/includes/nusoap/lib/class.*',
4109 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4110 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4112 '/api/class/api_generic.class.php',
4113 '/asterisk/cidlookup.php',
4114 '/categories/class/api_category.class.php',
4115 '/categories/class/api_deprecated_category.class.php',
4116 '/compta/facture/class/api_invoice.class.php',
4117 '/commande/class/api_commande.class.php',
4118 '/partnership/class/api_partnership.class.php',
4119 '/product/class/api_product.class.php',
4120 '/recruitment/class/api_recruitment.class.php',
4121 '/societe/class/api_contact.class.php',
4122 '/societe/class/api_thirdparty.class.php',
4123 '/support/online.php',
4124 '/takepos/class/actions_takepos.class.php',
4125 '/user/class/api_user.class.php',
4127 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4128 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4129 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4130 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4131 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4132 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4141 foreach ($filetodeletearray as $filetodelete) {
4143 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete) || preg_match(
'/\*/', $filetodelete)) {
4145 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true, 0);
4147 $langs->load(
"errors");
4148 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4149 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4174 $filetodeletearray = array(
4175 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4176 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4180 if (!empty($_SERVER[
"WINDIR"])) {
4181 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4184 foreach ($filetodeletearray as $filetodelete) {
4186 if (file_exists($filetodelete)) {
4190 $langs->load(
"errors");
4191 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4192 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4216 if (count($listofmodule) == 0) {
4220 if (!is_object($user)) {
4221 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4222 $user =
new User($db);
4225 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)));
4227 $reloadactionformodules = array(
4228 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4229 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4230 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4231 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4232 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4233 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove' => 1),
4234 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4235 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4236 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4237 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4238 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4239 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4240 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4241 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4242 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4243 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4244 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4245 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4246 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4247 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4248 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4249 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove' => 1),
4250 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4251 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4252 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4253 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4254 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4255 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4256 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4259 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4260 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4266 if (!empty($reloadactionformodules[$moduletoreload])) {
4267 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4269 $val = $reloadactionformodules[$moduletoreload];
4270 $classformodule = $val[
'class'];
4271 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4273 $mod =
new $classformodule($db);
4274 if (!empty($val[
'remove'])) {
4275 $mod->remove(
'noboxes');
4277 if (!empty($val[
'deleteinsertmenus'])) {
4279 $mod->delete_menus();
4280 $mod->insert_menus();
4282 $mod->init($reloadmode);
4287 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4288 if (!empty($reg[1])) {
4289 if (strtoupper($moduletoreload) == $moduletoreload) {
4290 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4292 $moduletoreloadshort = $reg[1];
4295 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4297 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4299 $classname =
'mod'.$moduletoreloadshort;
4300 $mod =
new $classname($db);
4301 '@phan-var-force DolibarrModules $mod';
4304 $mod->delete_menus();
4305 $mod->init($reloadmode);
4307 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4309 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4311 $classname =
'mod'.$moduletoreloadshort;
4312 $mod =
new $classname($db);
4313 '@phan-var-force DolibarrModules $mod';
4314 $mod->init($reloadmode);
4316 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4317 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4323 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4328 if (!empty($mod) && is_object($mod)) {
4329 print
'<tr class="trforrunsql"><td colspan="4">';
4330 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4331 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4332 print
"<!-- (".$reloadmode.
") -->";
4357 $listofmenuhandler = array();
4360 $listofmenuhandler[
'auguria'] = 1;
4363 foreach ($listofmenuhandler as $key => $val) {
4364 print
'<tr class="trforrunsql"><td colspan="4">';
4368 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4371 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4372 $file =
'init_menu_'.$key.
'.sql';
4373 if (file_exists($dir.$file)) {
4374 $result =
run_sql($dir.$file, 1, 0, 1, $key);
4390 global $conf, $db, $langs, $user;
4392 print
'<tr><td colspan="4">';
4394 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4396 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4397 $fuser =
new User($db);
4398 if (!is_object($user)) {
4402 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4403 $resql = $db->query($sql);
4405 while ($obj = $db->fetch_object($resql)) {
4407 $fuser->id = $obj->uid;
4408 $fuser->entity = $obj->entity;
4411 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4413 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4415 $dir = $conf->user->multidir_output[$entity];
4420 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4421 $destin = $dir.
'/'.$fuser->id;
4429 $handle = opendir($origin_osencoded);
4430 if (is_resource($handle)) {
4431 while (($file = readdir($handle)) !==
false) {
4432 if ($file ==
'.' || $file ==
'..') {
4437 $thumbs = opendir($origin_osencoded.
'/'.$file);
4438 if (is_resource($thumbs)) {
4440 while (($thumb = readdir($thumbs)) !==
false) {
4442 if ($thumb ==
'.' || $thumb ==
'..') {
4448 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4458 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4479 global $db, $langs, $user;
4481 print
'<tr><td colspan="4">';
4483 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4485 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4486 $fuser =
new User($db);
4487 if (!is_object($user)) {
4491 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4492 $resql = $db->query($sql);
4494 while ($obj = $db->fetch_object($resql)) {
4496 $fuser->id = $obj->uid;
4497 $fuser->entity = $obj->entity;
4498 $fuser->photo = $obj->photo;
4501 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4503 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4505 $dir = DOL_DATA_ROOT.
'/users';
4510 $origin = $dir.
'/'.$fuser->id;
4511 $destin = $dir.
'/'.$fuser->id.
'/photos';
4519 $handle = opendir($origin_osencoded);
4520 if (is_resource($handle)) {
4521 while (($file = readdir($handle)) !==
false) {
4522 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4525 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4530 $thumbs = opendir($origin_osencoded.
'/'.$file);
4531 if (is_resource($thumbs)) {
4533 while (($thumb = readdir($thumbs)) !==
false) {
4535 if ($thumb ==
'.' || $thumb ==
'..') {
4541 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4550 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4587 print
'<tr><td colspan="4">';
4588 $sql =
'SELECT rowid, socialnetworks';
4589 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4590 $sql .=
" skype IS NOT NULL OR skype <> ''";
4591 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4592 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4593 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4594 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4595 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4596 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4597 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4598 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4600 $resql = $db->query($sql);
4602 while ($obj = $db->fetch_object($resql)) {
4603 $arraysocialnetworks = array();
4604 if (!empty($obj->skype)) {
4605 $arraysocialnetworks[
'skype'] = $obj->skype;
4607 if (!empty($obj->twitter)) {
4608 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4610 if (!empty($obj->facebook)) {
4611 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4613 if (!empty($obj->linkedin)) {
4614 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4616 if (!empty($obj->instagram)) {
4617 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4619 if (!empty($obj->snapchat)) {
4620 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4622 if (!empty($obj->googleplus)) {
4623 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4625 if (!empty($obj->youtube)) {
4626 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4628 if (!empty($obj->whatsapp)) {
4629 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4631 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4632 $obj->socialnetworks =
'[]';
4634 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4635 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4636 $sqlupd .=
', skype=null';
4637 $sqlupd .=
', twitter=null';
4638 $sqlupd .=
', facebook=null';
4639 $sqlupd .=
', linkedin=null';
4640 $sqlupd .=
', instagram=null';
4641 $sqlupd .=
', snapchat=null';
4642 $sqlupd .=
', googleplus=null';
4643 $sqlupd .=
', youtube=null';
4644 $sqlupd .=
', whatsapp=null';
4645 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4647 $resqlupd = $db->query($sqlupd);
4662 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4676 print
'<tr><td colspan="4">';
4679 print
'<tr><td colspan="4">';
4680 $sql =
'SELECT rowid, socialnetworks';
4681 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4682 $sql .=
" skype IS NOT NULL OR skype <> ''";
4683 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4684 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4685 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4686 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4687 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4688 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4689 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4690 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4692 $resql = $db->query($sql);
4694 while ($obj = $db->fetch_object($resql)) {
4695 $arraysocialnetworks = array();
4696 if (!empty($obj->skype)) {
4697 $arraysocialnetworks[
'skype'] = $obj->skype;
4699 if (!empty($obj->twitter)) {
4700 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4702 if (!empty($obj->facebook)) {
4703 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4705 if (!empty($obj->linkedin)) {
4706 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4708 if (!empty($obj->instagram)) {
4709 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4711 if (!empty($obj->snapchat)) {
4712 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4714 if (!empty($obj->googleplus)) {
4715 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4717 if (!empty($obj->youtube)) {
4718 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4720 if (!empty($obj->whatsapp)) {
4721 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4723 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4724 $obj->socialnetworks =
'[]';
4726 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4727 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4728 $sqlupd .=
', skype=null';
4729 $sqlupd .=
', twitter=null';
4730 $sqlupd .=
', facebook=null';
4731 $sqlupd .=
', linkedin=null';
4732 $sqlupd .=
', instagram=null';
4733 $sqlupd .=
', snapchat=null';
4734 $sqlupd .=
', googleplus=null';
4735 $sqlupd .=
', youtube=null';
4736 $sqlupd .=
', whatsapp=null';
4737 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4739 $resqlupd = $db->query($sqlupd);
4754 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4770 print
'<tr><td colspan="4">';
4771 $sql =
'SELECT rowid, socialnetworks';
4772 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4773 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4774 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4775 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4776 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4777 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4778 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4779 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4780 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4781 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4782 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4784 $resql = $db->query($sql);
4786 while ($obj = $db->fetch_object($resql)) {
4787 $arraysocialnetworks = array();
4788 if (!empty($obj->jabberid)) {
4789 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4791 if (!empty($obj->skype)) {
4792 $arraysocialnetworks[
'skype'] = $obj->skype;
4794 if (!empty($obj->twitter)) {
4795 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4797 if (!empty($obj->facebook)) {
4798 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4800 if (!empty($obj->linkedin)) {
4801 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4803 if (!empty($obj->instagram)) {
4804 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4806 if (!empty($obj->snapchat)) {
4807 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4809 if (!empty($obj->googleplus)) {
4810 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4812 if (!empty($obj->youtube)) {
4813 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4815 if (!empty($obj->whatsapp)) {
4816 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4818 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4819 $obj->socialnetworks =
'[]';
4821 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4822 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4823 $sqlupd .=
', jabberid=null';
4824 $sqlupd .=
', skype=null';
4825 $sqlupd .=
', twitter=null';
4826 $sqlupd .=
', facebook=null';
4827 $sqlupd .=
', linkedin=null';
4828 $sqlupd .=
', instagram=null';
4829 $sqlupd .=
', snapchat=null';
4830 $sqlupd .=
', googleplus=null';
4831 $sqlupd .=
', youtube=null';
4832 $sqlupd .=
', whatsapp=null';
4833 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4835 $resqlupd = $db->query($sqlupd);
4850 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4866 print
'<tr><td colspan="4">';
4867 $sql =
'SELECT rowid, socialnetworks';
4868 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4869 $sql .=
" skype IS NOT NULL OR skype <> ''";
4870 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4871 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4872 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4873 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4874 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4875 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4876 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4877 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4879 $resql = $db->query($sql);
4881 while ($obj = $db->fetch_object($resql)) {
4882 $arraysocialnetworks = array();
4883 if (!empty($obj->skype)) {
4884 $arraysocialnetworks[
'skype'] = $obj->skype;
4886 if (!empty($obj->twitter)) {
4887 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4889 if (!empty($obj->facebook)) {
4890 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4892 if (!empty($obj->linkedin)) {
4893 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4895 if (!empty($obj->instagram)) {
4896 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4898 if (!empty($obj->snapchat)) {
4899 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4901 if (!empty($obj->googleplus)) {
4902 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4904 if (!empty($obj->youtube)) {
4905 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4907 if (!empty($obj->whatsapp)) {
4908 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4910 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4911 $obj->socialnetworks =
'[]';
4913 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4914 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4915 $sqlupd .=
', skype=null';
4916 $sqlupd .=
', twitter=null';
4917 $sqlupd .=
', facebook=null';
4918 $sqlupd .=
', linkedin=null';
4919 $sqlupd .=
', instagram=null';
4920 $sqlupd .=
', snapchat=null';
4921 $sqlupd .=
', googleplus=null';
4922 $sqlupd .=
', youtube=null';
4923 $sqlupd .=
', whatsapp=null';
4924 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4926 $resqlupd = $db->query($sqlupd);
4941 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
4961 print
'<tr class="trforrunsql"><td colspan="4">';
4962 $sql =
'SELECT rowid, field';
4963 if ($mode ==
'export') {
4966 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
4967 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
4969 $resql = $db->query($sql);
4971 while ($obj = $db->fetch_object($resql)) {
4972 $oldfield = $obj->field;
4973 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
4975 if ($mode ==
'export') {
4976 $oldfilter = $obj->filter;
4977 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
4983 if ($oldfield != $newfield || $oldfilter != $newfilter) {
4984 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
4985 if ($mode ==
'export') {
4986 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
4988 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4989 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
4990 $resqlupd = $db->query($sqlupd);
5006 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5009 if ($resultstring) {
5010 print $resultstring;
5012 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5029 print
'<tr class="trforrunsql"><td colspan="4">';
5030 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5032 $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";
5033 $sql .=
" ORDER BY c.rowid,cd.rowid";
5035 $resql = $db->query($sql);
5038 $current_contract = 0;
5039 while ($obj = $db->fetch_object($resql)) {
5040 if (empty($current_contract) || $current_contract == $obj->cid) {
5046 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5047 $resultstring =
'.';
5048 print $resultstring;
5049 $resqlUpd = $db->query($sqlUpd);
5055 $current_contract = $obj->cid;
5068 if (!$resultstring) {
5069 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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 modules.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: 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/Re-enable 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 Link in llx_societe_remis...
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)
Records payment links for an invoice in a join table (link n<-->n for payments<-->invoices)
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)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: 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)
Correspondence 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 assignment to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondence des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment 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.