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";
116 print
'Example, upgrade from 19 to 20: '.$script_file.
" 19.0.0 20.0.0\n";
117 print
'Example, enable a module only: '.$script_file.
" 0.0.0 0.0.0 MAIN_MODULE_Adherent\n";
123pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
126if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
127 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
128 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
130 print
'<table border="0" width="100%">';
133 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
134 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
135 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
136 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
137 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
138 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
140 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
145 $conf->db->type = $dolibarr_main_db_type;
146 $conf->db->host = $dolibarr_main_db_host;
147 $conf->db->port = $dolibarr_main_db_port;
148 $conf->db->name = $dolibarr_main_db_name;
149 $conf->db->user = $dolibarr_main_db_user;
150 $conf->db->pass = $dolibarr_main_db_pass;
154 if (!$db->connected) {
155 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase",
$conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
161 if ($db->database_selected) {
168 if (empty($dolibarr_main_db_encryption)) {
169 $dolibarr_main_db_encryption = 0;
171 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
172 if (empty($dolibarr_main_db_cryptkey)) {
173 $dolibarr_main_db_cryptkey =
'';
175 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
178 $conf->setValues($db);
181 $listofentities = array(1);
184 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
186 $hookmanager->initHooks(array(
'upgrade2'));
188 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
191 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
192 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
194 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
205 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
207 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
209 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
211 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
213 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
215 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
217 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
219 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
221 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
223 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
225 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
231 foreach ($listofentities as $entity) {
233 $conf->setEntityValues($db, $entity);
235 if (defined(
'SYSLOG_FILE')) {
236 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
238 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
240 $versiontoarray = array();
241 $versionranarray = array();
244 if (count($listofentities) > 1) {
245 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
250 $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 :
''));
256 $versiontoarray = explode(
'.', $versionto);
257 $versionranarray = explode(
'.', DOL_VERSION);
260 $afterversionarray = explode(
'.',
'2.0.0');
261 $beforeversionarray = explode(
'.',
'2.7.9');
322 $afterversionarray = explode(
'.',
'2.7.9');
323 $beforeversionarray = explode(
'.',
'2.8.9');
348 $afterversionarray = explode(
'.',
'2.8.9');
349 $beforeversionarray = explode(
'.',
'2.9.9');
361 $afterversionarray = explode(
'.',
'2.9.9');
362 $beforeversionarray = explode(
'.',
'3.0.9');
368 $afterversionarray = explode(
'.',
'3.0.9');
369 $beforeversionarray = explode(
'.',
'3.1.9');
377 $afterversionarray = explode(
'.',
'3.1.9');
378 $beforeversionarray = explode(
'.',
'3.2.9');
388 $afterversionarray = explode(
'.',
'3.2.9');
389 $beforeversionarray = explode(
'.',
'3.3.9');
398 $afterversionarray = explode(
'.',
'3.6.9');
399 $beforeversionarray = explode(
'.',
'3.7.9');
405 $afterversionarray = explode(
'.',
'3.7.9');
406 $beforeversionarray = explode(
'.',
'3.8.9');
412 $afterversionarray = explode(
'.',
'3.9.9');
413 $beforeversionarray = explode(
'.',
'4.0.9');
419 $afterversionarray = explode(
'.',
'4.0.9');
420 $beforeversionarray = explode(
'.',
'5.0.9');
430 $afterversionarray = explode(
'.',
'5.0.9');
431 $beforeversionarray = explode(
'.',
'6.0.9');
433 if (isModEnabled(
'multicompany')) {
434 global $multicompany_transverse_mode;
437 if (empty($multicompany_transverse_mode)) {
448 $afterversionarray = explode(
'.',
'6.0.9');
449 $beforeversionarray = explode(
'.',
'7.0.9');
458 $afterversionarray = explode(
'.',
'7.0.9');
459 $beforeversionarray = explode(
'.',
'8.0.9');
465 $afterversionarray = explode(
'.',
'8.0.9');
466 $beforeversionarray = explode(
'.',
'9.0.9');
472 $afterversionarray = explode(
'.',
'10.0.9');
473 $beforeversionarray = explode(
'.',
'11.0.9');
482 $afterversionarray = explode(
'.',
'13.0.9');
483 $beforeversionarray = explode(
'.',
'14.0.9');
490 $afterversionarray = explode(
'.',
'15.0.9');
491 $beforeversionarray = explode(
'.',
'16.0.9');
498 $afterversionarray = explode(
'.',
'16.0.9');
499 $beforeversionarray = explode(
'.',
'17.0.9');
505 $afterversionarray = explode(
'.',
'17.0.9');
506 $beforeversionarray = explode(
'.',
'18.0.9');
526 $afterversionarray = explode(
'.',
'20.0.9');
527 $beforeversionarray = explode(
'.',
'21.0.9');
537 $listofmodule = array(
538 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
539 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
540 'MAIN_MODULE_BOM' =>
'menuonly',
541 'MAIN_MODULE_BANQUE' =>
'menuonly',
542 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
543 'MAIN_MODULE_CRON' =>
'newboxdefonly',
544 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
545 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
546 'MAIN_MODULE_DEPLACEMENT' =>
'newboxdefonly',
547 'MAIN_MODULE_DON' =>
'newboxdefonly',
548 'MAIN_MODULE_ECM' =>
'newboxdefonly',
549 'MAIN_MODULE_EXTERNALSITE' =>
'newboxdefonly',
550 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
551 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
552 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
553 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
554 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
555 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
556 'MAIN_MODULE_MARGIN' =>
'menuonly',
557 'MAIN_MODULE_MRP' =>
'menuonly',
558 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
559 'MAIN_MODULE_PAYBOX' =>
'newboxdefonly',
560 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
561 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
562 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
563 'MAIN_MODULE_RESOURCE' =>
'noboxes',
564 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
565 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
566 'MAIN_MODULE_SYSLOG' =>
'newboxdefonly',
567 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
568 'MAIN_MODULE_STRIPE' =>
'menuonly',
569 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
570 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
571 'MAIN_MODULE_USER' =>
'newboxdefonly',
572 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
573 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
589 if (!$error && $enablemodules) {
591 $listofmodules = array();
592 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
593 $tmplistofmodules = explode(
',', $enablemodules);
594 foreach ($tmplistofmodules as $value) {
595 $listofmodules[$value] =
'forceactivate';
599 if ($resultreloadmodules < 0) {
607 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
610 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
611 if ($hookmanager->resNbOfHooks > 0) {
613 print
'<tr><td colspan="4">';
614 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
615 print $hookmanager->error;
616 print
"<!-- (".$reshook.
") -->";
619 print
'<tr class="trforrunsql"><td colspan="4">';
620 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
621 print
"<!-- (".$reshook.
") -->";
626 if (!empty(
$conf->modules_parts[
'hooks'])) {
627 print
'<tr class="trforrunsql"><td colspan="4">';
628 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
639 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
654 foreach ($listofentities as $entity) {
656 $conf->setEntityValues($db, $entity);
658 if (defined(
'SYSLOG_FILE')) {
659 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
661 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
665 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
666 $destroot = DOL_DATA_ROOT.
'/medias';
679 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
682 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
683 if ($hookmanager->resNbOfHooks > 0) {
685 print
'<tr><td colspan="4">';
686 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
687 print $hookmanager->error;
688 print
"<!-- (".$reshook.
") -->";
691 print
'<tr class="trforrunsql"><td colspan="4">';
692 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
693 print
"<!-- (".$reshook.
") -->";
698 if (!empty(
$conf->modules_parts[
'hooks'])) {
699 print
'<tr class="trforrunsql"><td colspan="4">';
700 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
710 print
'<table width="100%">';
711 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
712 print
'<td class="right">';
716 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
720 print
'<script type="text/javascript">
721 jQuery(document).ready(function() {
722 function init_trrunsql()
724 console.log("toggle .trforrunsql");
725 jQuery(".trforrunsql").toggle();
728 jQuery(".trforrunsqlshowhide").click(function() {
733 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
736 print
'</td></tr>'.
"\n";
742 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
747if ($error && isset($argv[1])) {
753pFooter($error ? 2 : 0, $setuplang);
776 print
'<tr><td colspan="4">';
779 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
781 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
782 $obj = $db->fetch_object($result);
784 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
785 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
786 $sql .=
" WHERE p.fk_facture > 0";
788 $resql = $db->query($sql);
795 $num = $db->num_rows($resql);
798 $obj = $db->fetch_object($resql);
799 $row[$i][0] = $obj->rowid;
800 $row[$i][1] = $obj->fk_facture;
801 $row[$i][2] = $obj->amount;
809 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
813 for ($i = 0; $i < $num; $i++) {
814 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
815 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
817 $res += $db->query($sql);
819 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
821 $res += $db->query($sql);
823 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
827 if (is_array($row) && $res == (2 * count($row))) {
829 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
832 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
835 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
838 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
856 print
'<tr><td colspan="4">';
859 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
861 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
862 $obj = $db->fetch_object($result);
865 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
866 $sql .=
" bu2.url_id as socid";
867 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
868 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
869 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
870 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
871 $sql .=
" AND b.rappro = 1";
872 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
874 $resql = $db->query($sql);
880 $num = $db->num_rows($resql);
883 $obj = $db->fetch_object($resql);
884 if ($obj->pamount == $obj->bamount && $obj->socid) {
885 $row[$j][
'paymentid'] = $obj->rowid;
886 $row[$j][
'pamount'] = $obj->pamount;
887 $row[$j][
'fk_bank'] = $obj->fk_bank;
888 $row[$j][
'bamount'] = $obj->bamount;
889 $row[$j][
'socid'] = $obj->socid;
890 $row[$j][
'datec'] = $obj->datec;
900 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
905 for ($i = 0; $i < $num; $i++) {
907 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>';
911 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
912 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
913 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
914 $sql .=
" AND pf.fk_facture IS NULL";
915 $sql .=
" ORDER BY f.fk_statut";
917 $resql = $db->query($sql);
919 $num = $db->num_rows($resql);
922 $obj = $db->fetch_object($resql);
923 $facid = $obj->rowid;
925 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
926 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
928 $res += $db->query($sql);
930 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
938 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
940 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
945 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
948 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
966 print
'<tr><td colspan="4">';
969 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
971 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
972 $obj = $db->fetch_object($result);
975 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
976 $sql .=
" bu2.url_id as socid";
977 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
978 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
979 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
980 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
981 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
983 $resql = $db->query($sql);
989 $num = $db->num_rows($resql);
992 $obj = $db->fetch_object($resql);
993 if ($obj->pamount == $obj->bamount && $obj->socid) {
994 $row[$j][
'paymentid'] = $obj->rowid;
995 $row[$j][
'pamount'] = $obj->pamount;
996 $row[$j][
'fk_bank'] = $obj->fk_bank;
997 $row[$j][
'bamount'] = $obj->bamount;
998 $row[$j][
'socid'] = $obj->socid;
999 $row[$j][
'datec'] = $obj->datec;
1012 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
1016 for ($i = 0; $i < $num; $i++) {
1018 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>';
1022 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1023 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1024 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1025 $sql .=
" AND pf.fk_facture IS NULL";
1026 $sql .=
" ORDER BY f.fk_statut";
1028 $resql = $db->query($sql);
1030 $num = $db->num_rows($resql);
1033 $obj = $db->fetch_object($resql);
1034 $facid = $obj->rowid;
1036 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1037 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1039 $res += $db->query($sql);
1041 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1050 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1052 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1057 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1063 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1073 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1090 print
'<tr><td colspan="4">';
1095 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1097 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1098 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1099 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1100 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1101 $sql .=
" ON c.fk_product = p.rowid";
1102 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1103 $sql .=
" ON c.rowid=cd.fk_contrat";
1104 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1105 $resql = $db->query($sql);
1111 $num = $db->num_rows($resql);
1114 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1118 $obj = $db->fetch_object($resql);
1120 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1121 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1122 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1123 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1124 $sql .=
" VALUES (";
1125 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1127 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1128 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1131 $sql .= ((float) $obj->tva_tx).
", 1, ";
1132 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1136 if ($db->query($sql)) {
1137 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1149 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1152 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1155 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1158 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1175 print
'<tr><td colspan="4">';
1180 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1182 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1183 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1184 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1185 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1186 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1187 $sql .=
" AND bu.fk_bank IS NULL";
1188 $resql = $db->query($sql);
1194 $num = $db->num_rows($resql);
1197 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1201 $obj = $db->fetch_object($resql);
1203 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1204 $sql .=
"fk_bank, url_id, url, label, type";
1206 $sql .=
" VALUES (";
1207 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1213 if (!$db->query($sql)) {
1224 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1227 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1230 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1249 print
'<tr><td colspan="4">';
1252 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1254 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1256 $resql = $db->query($sql);
1260 if ($db->affected_rows($resql) > 0) {
1261 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1263 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1266 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1268 $resql = $db->query($sql);
1272 if ($db->affected_rows($resql) > 0) {
1273 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1275 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1291 print
'<tr><td colspan="4">';
1296 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1298 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1300 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1301 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1302 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1303 $resql = $db->query($sql);
1309 $num = $db->num_rows($resql);
1312 $nbcontratsmodifie = 0;
1316 $obj = $db->fetch_object($resql);
1317 if ($obj->date_contrat > $obj->datemin) {
1318 $datemin = $db->jdate($obj->datemin);
1320 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1321 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1322 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1323 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1324 $resql2 = $db->query($sql);
1329 $nbcontratsmodifie++;
1336 if ($nbcontratsmodifie) {
1337 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1339 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1359 print
'<tr><td colspan="4">';
1362 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1364 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1366 $resql = $db->query($sql);
1370 if ($db->affected_rows($resql) > 0) {
1371 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1373 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1389 print
'<tr><td colspan="4">';
1392 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1394 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1395 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1397 $resql = $db->query($sql);
1401 if ($db->affected_rows($resql) > 0) {
1404 $num = $db->num_rows($resql);
1407 $nbcontratsmodifie = 0;
1411 $obj = $db->fetch_object($resql);
1413 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1414 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1415 $sql .=
" SET statut = 1";
1416 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1417 $resql2 = $db->query($sql);
1422 $nbcontratsmodifie++;
1429 if ($nbcontratsmodifie) {
1430 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1432 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1436 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1454 print
'<tr><td colspan="4">';
1456 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1459 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1460 $obj = $db->fetch_object($result);
1465 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1466 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1467 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1470 $select_resql = $db->query($select_sql);
1471 if ($select_resql) {
1472 $select_num = $db->num_rows($select_resql);
1476 while (($i < $select_num) && (!$error)) {
1477 $select_obj = $db->fetch_object($select_resql);
1480 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1481 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1482 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1483 $check_resql = $db->query($check_sql);
1485 $check_num = $db->num_rows($check_resql);
1486 if ($check_num == 0) {
1490 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1491 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1494 print
'<tr class="oddeven">';
1495 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1497 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1498 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1499 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1500 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1501 $insert_resql = $db->query($insert_sql);
1503 if ($insert_resql) {
1505 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1507 print
'<td><span class="error">Error on insert</span></td>';
1523 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1527 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1530 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1534 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1551 $tmpmysoc->setMysoc(
$conf);
1555 print
'<tr><td colspan="4">';
1558 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1561 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1562 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1563 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1564 $sql .=
" WHERE fd.fk_facture = f.rowid";
1565 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1569 $resql = $db->query($sql);
1571 $num = $db->num_rows($resql);
1575 $obj = $db->fetch_object($resql);
1577 $rowid = $obj->rowid;
1579 $pu = $obj->subprice;
1580 $vatrate = $obj->vatrate;
1581 $remise_percent = $obj->remise_percent;
1582 $remise_percent_global = $obj->remise_percent_global;
1583 $total_ttc_f = $obj->total_ttc_f;
1584 $info_bits = $obj->info_bits;
1588 $facligne->fetch($rowid);
1590 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1591 $total_ht = $result[0];
1592 $total_tva = $result[1];
1593 $total_ttc = $result[2];
1595 $facligne->total_ht = (float) $total_ht;
1596 $facligne->total_tva = (float) $total_tva;
1597 $facligne->total_ttc = (float) $total_ttc;
1599 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);
1601 $facligne->update_total();
1605 if (!$total_ttc_f) {
1607 $facture->id = $obj->facid;
1609 if ($facture->fetch($facture->id) >= 0) {
1610 if ($facture->update_price() > 0) {
1613 print
"Error id=".$facture->id;
1626 print $langs->trans(
"AlreadyDone");
1632 print
"Error #1 ".$db->error();
1654 $tmpmysoc->setMysoc(
$conf);
1658 print
'<tr><td colspan="4">';
1661 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1664 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1665 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1666 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1667 $sql .=
" WHERE pd.fk_propal = p.rowid";
1668 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1671 $resql = $db->query($sql);
1673 $num = $db->num_rows($resql);
1677 $obj = $db->fetch_object($resql);
1679 $rowid = $obj->rowid;
1681 $pu = $obj->subprice;
1682 $vatrate = $obj->vatrate;
1683 $remise_percent = $obj->remise_percent;
1684 $remise_percent_global = $obj->remise_percent_global;
1685 $info_bits = $obj->info_bits;
1689 $propalligne->fetch($rowid);
1691 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1692 $total_ht = $result[0];
1693 $total_tva = $result[1];
1694 $total_ttc = $result[2];
1696 $propalligne->total_ht = (float) $total_ht;
1697 $propalligne->total_tva = (float) $total_tva;
1698 $propalligne->total_ttc = (float) $total_ttc;
1700 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);
1702 $propalligne->update_total();
1707 print $langs->trans(
"AlreadyDone");
1714 print
"Error #1 ".$db->error();
1737 $tmpmysoc->setMysoc(
$conf);
1738 if (empty($tmpmysoc->country_id)) {
1739 $tmpmysoc->country_id = 0;
1742 print
'<tr><td colspan="4">';
1745 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1748 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1749 $sql .=
" c.rowid as contratid";
1750 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1751 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1752 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1755 $resql = $db->query($sql);
1757 $num = $db->num_rows($resql);
1761 $obj = $db->fetch_object($resql);
1763 $rowid = $obj->rowid;
1765 $pu = $obj->subprice;
1766 $vatrate = $obj->vatrate;
1767 $remise_percent = $obj->remise_percent;
1768 $info_bits = $obj->info_bits;
1773 $contratligne->fetch($rowid);
1775 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1776 $total_ht = $result[0];
1777 $total_tva = $result[1];
1778 $total_ttc = $result[2];
1780 $contratligne->total_ht = (float) $total_ht;
1781 $contratligne->total_tva = (float) $total_tva;
1782 $contratligne->total_ttc = (float) $total_ttc;
1784 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);
1786 $contratligne->update_total();
1791 print $langs->trans(
"AlreadyDone");
1798 print
"Error #1 ".$db->error();
1821 $tmpmysoc->setMysoc(
$conf);
1823 print
'<tr><td colspan="4">';
1826 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1829 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1830 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1831 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1832 $sql .=
" WHERE cd.fk_commande = c.rowid";
1833 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1836 $resql = $db->query($sql);
1838 $num = $db->num_rows($resql);
1842 $obj = $db->fetch_object($resql);
1844 $rowid = $obj->rowid;
1846 $pu = $obj->subprice;
1847 $vatrate = $obj->vatrate;
1848 $remise_percent = $obj->remise_percent;
1849 $remise_percent_global = $obj->remise_percent_global;
1850 $info_bits = $obj->info_bits;
1854 $commandeligne->fetch($rowid);
1856 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1857 $total_ht = $result[0];
1858 $total_tva = $result[1];
1859 $total_ttc = $result[2];
1861 $commandeligne->total_ht = (float) $total_ht;
1862 $commandeligne->total_tva = (float) $total_tva;
1863 $commandeligne->total_ttc = (float) $total_ttc;
1865 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);
1867 $commandeligne->update_total();
1872 print $langs->trans(
"AlreadyDone");
1889 print
"Error #1 ".$db->error();
1914 $tmpmysoc->setMysoc(
$conf);
1916 print
'<tr><td colspan="4">';
1919 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1922 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1923 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1924 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1925 $sql .=
" WHERE cd.fk_commande = c.rowid";
1926 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1929 $resql = $db->query($sql);
1931 $num = $db->num_rows($resql);
1935 $obj = $db->fetch_object($resql);
1937 $rowid = $obj->rowid;
1939 $pu = $obj->subprice;
1940 $vatrate = $obj->vatrate;
1941 $remise_percent = $obj->remise_percent;
1942 $remise_percent_global = $obj->remise_percent_global;
1943 $info_bits = $obj->info_bits;
1947 $commandeligne->fetch($rowid);
1949 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $mysoc);
1950 $total_ht = $result[0];
1951 $total_tva = $result[1];
1952 $total_ttc = $result[2];
1954 $commandeligne->total_ht = (float) $total_ht;
1955 $commandeligne->total_tva = (float) $total_tva;
1956 $commandeligne->total_ttc = (float) $total_ttc;
1958 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);
1960 $commandeligne->update_total();
1965 print $langs->trans(
"AlreadyDone");
1982 print
"Error #1 ".$db->error();
2007 if (isModEnabled(
'invoice')) {
2008 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2010 if (count($modellist) == 0) {
2012 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2013 $resql = $db->query($sql);
2020 if (isModEnabled(
'order')) {
2021 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2023 if (count($modellist) == 0) {
2025 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2026 $resql = $db->query($sql);
2033 if (isModEnabled(
"shipping")) {
2034 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2036 if (count($modellist) == 0) {
2038 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2039 $resql = $db->query($sql);
2062 print
'<tr><td colspan="4">';
2065 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2067 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2068 $obj = $db->fetch_object($result);
2074 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2075 $resql = $db->query($sql);
2078 $num = $db->num_rows($resql);
2082 $obj = $db->fetch_object($resql);
2084 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2085 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2086 $resql2 = $db->query($sql);
2099 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2100 print $langs->trans(
'FieldRenamed').
"<br>\n";
2110 print $langs->trans(
'AlreadyDone').
"<br>\n";
2127 print
'<tr><td colspan="4">';
2130 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2132 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2133 $obj = $db->fetch_object($result);
2139 $sql =
"SELECT l.rowid, l.fk_commande,";
2140 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2141 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2142 $sql .=
" WHERE c.rowid = l.fk_commande";
2143 $resql = $db->query($sql);
2146 $num = $db->num_rows($resql);
2150 $obj = $db->fetch_object($resql);
2152 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2153 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2154 $resql2 = $db->query($sql);
2157 $delivery_date = $db->jdate($obj->delivery_date);
2159 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2160 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2161 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2162 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2163 $resql3 = $db->query($sqlu);
2179 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2180 print $langs->trans(
'FieldRenamed').
"<br>\n";
2190 print $langs->trans(
'AlreadyDone').
"<br>\n";
2207 print
'<tr><td colspan="4">';
2210 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2214 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2215 $obj = $db->fetch_object($result);
2221 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2222 $sql .=
", ld.fk_livraison";
2223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2224 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2225 $resql = $db->query($sql);
2228 $num = $db->num_rows($resql);
2232 $obj = $db->fetch_object($resql);
2234 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2235 $sql .=
" fk_product = ".((int) $obj->fk_product);
2236 $sql .=
",description = '".$db->escape($obj->description).
"'";
2237 $sql .=
",subprice = ".price2num($obj->subprice);
2238 $sql .=
",total_ht = ".price2num($obj->total_ht);
2239 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2240 $resql2 = $db->query($sql);
2243 $sql =
"SELECT total_ht";
2244 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2245 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2246 $resql3 = $db->query($sql);
2249 $obju = $db->fetch_object($resql3);
2250 $total_ht = $obju->total_ht + $obj->total_ht;
2252 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2253 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2254 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2255 $resql4 = $db->query($sqlu);
2275 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2276 print $langs->trans(
'FieldRenamed').
"<br>\n";
2286 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2287 $obj = $db->fetch_object($result);
2289 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2292 print $langs->trans(
'AlreadyDone').
"<br>\n";
2309 print
'<tr><td colspan="4">';
2312 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2318 $sql =
"SELECT SUM(reel) as total, fk_product";
2319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2320 $sql .=
" GROUP BY fk_product";
2321 $resql = $db->query($sql);
2324 $num = $db->num_rows($resql);
2328 $obj = $db->fetch_object($resql);
2330 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2331 $sql .=
" stock = ".price2num($obj->total,
'MS');
2332 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2334 $resql2 = $db->query($sql);
2371 print
'<tr><td colspan="4">';
2374 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2378 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2381 $sql =
"SELECT m.rowid, mc.action";
2382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2383 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2384 $sql .=
" AND m.enabled = '1'";
2385 $resql = $db->query($sql);
2388 $num = $db->num_rows($resql);
2391 $obj = $db->fetch_object($resql);
2393 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2394 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2395 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2396 $sql .=
" AND enabled = '1'";
2398 $resql2 = $db->query($sql);
2419 print $langs->trans(
'AlreadyDone').
"<br>\n";
2438 print
'<tr><td colspan="4">';
2441 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2445 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2448 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2450 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2451 $sql .=
" WHERE c.rowid = ce.fk_commande";
2452 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2454 $resql = $db->query($sql);
2457 $num = $db->num_rows($resql);
2461 $obj = $db->fetch_object($resql);
2463 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2464 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2465 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2467 $resql2 = $db->query($sql);
2476 print $langs->trans(
'AlreadyDone').
"<br>\n";
2489 print $langs->trans(
'AlreadyDone').
"<br>\n";
2508 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2510 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2514 print
'<tr><td colspan="4">';
2517 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2523 $table1 =
'facturedet';
2524 $field1 =
'fk_remise_except';
2525 $table2 =
'societe_remise_except';
2526 $field2 =
'fk_facture_line';
2530 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2531 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2532 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2533 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2534 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2537 $resql = $db->query($sql);
2540 $num = $db->num_rows($resql);
2544 $obj = $db->fetch_object($resql);
2546 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2548 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2549 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2550 $sql .=
" WHERE rowid = ".((int) $obj->field);
2552 $resql2 = $db->query($sql);
2561 print $langs->trans(
'AlreadyDone').
"<br>\n";
2577 print
'<tr><td colspan="4">';
2580 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2583 $table2 =
'facturedet';
2584 $field2 =
'fk_remise_except';
2585 $table1 =
'societe_remise_except';
2586 $field1 =
'fk_facture_line';
2590 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2591 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2592 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2593 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2594 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2597 $resql = $db->query($sql);
2600 $num = $db->num_rows($resql);
2604 $obj = $db->fetch_object($resql);
2606 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2608 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2609 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2610 $sql .=
" WHERE rowid = ".((int) $obj->field);
2612 $resql2 = $db->query($sql);
2621 print $langs->trans(
'AlreadyDone').
"<br>\n";
2636 return ($error ? -1 : 1);
2651 print
'<tr><td colspan="4">';
2654 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2656 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2657 $obj = $db->fetch_object($result);
2663 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2664 $resql = $db->query($sql);
2667 $num = $db->num_rows($resql);
2671 $obj = $db->fetch_object($resql);
2673 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2674 $sql2 .=
"datecreate";
2675 $sql2 .=
", statut";
2676 $sql2 .=
", element_id";
2677 $sql2 .=
", fk_c_type_contact";
2678 $sql2 .=
", fk_socpeople";
2679 $sql2 .=
") VALUES (";
2680 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2682 $sql2 .=
", ".$obj->rowid;
2684 $sql2 .=
", ".$obj->fk_user_resp;
2687 if ($obj->fk_user_resp > 0) {
2688 $resql2 = $db->query($sql2);
2701 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2702 if ($db->query($sqlDrop)) {
2715 print $langs->trans(
'AlreadyDone').
"<br>\n";
2732 print
'<tr><td colspan="4">';
2735 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2737 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2742 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2743 $resql = $db->query($sql);
2746 $num = $db->num_rows($resql);
2750 $obj = $db->fetch_object($resql);
2752 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2753 $sql2 .=
"datecreate";
2754 $sql2 .=
", statut";
2755 $sql2 .=
", element_id";
2756 $sql2 .=
", fk_c_type_contact";
2757 $sql2 .=
", fk_socpeople";
2758 $sql2 .=
") VALUES (";
2759 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2761 $sql2 .=
", ".$obj->fk_project_task;
2763 $sql2 .=
", ".$obj->fk_user;
2766 $resql2 = $db->query($sql2);
2778 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2779 if ($db->query($sqlDrop)) {
2792 print $langs->trans(
'AlreadyDone').
"<br>\n";
2812 print
'<tr><td colspan="4">';
2815 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2819 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2824 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2825 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2827 $resql = $db->query($sqlSelect);
2830 $num = $db->num_rows($resql);
2834 $obj = $db->fetch_object($resql);
2836 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2837 $sqlInsert .=
"fk_source";
2838 $sqlInsert .=
", sourcetype";
2839 $sqlInsert .=
", fk_target";
2840 $sqlInsert .=
", targettype";
2841 $sqlInsert .=
") VALUES (";
2842 $sqlInsert .= $obj->$fk_source;
2843 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2844 $sqlInsert .=
", ".$obj->$fk_target;
2845 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2848 $result = $db->query($sqlInsert);
2857 print $langs->trans(
'AlreadyDone').
"<br>\n";
2861 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2862 if ($db->query($sqlDrop)) {
2875 print $langs->trans(
'AlreadyDone').
"<br>\n";
2893 print
'<tr><td colspan="4">';
2896 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2902 $sql =
"SELECT rowid, fk_element, element_duration";
2903 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2904 $resql = $db->query($sql);
2907 $num = $db->num_rows($resql);
2910 $totaltime = array();
2914 $obj = $db->fetch_object($resql);
2916 if ($obj->element_duration > 0) {
2919 list($hour, $min) = explode(
'.', $obj->element_duration);
2920 $hour = (int) $hour * 60 * 60;
2921 $min = (int) ((
float) (
'.'.$min)) * 3600;
2922 $newtime = $hour + $min;
2924 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2925 $sql2 .=
" element_duration = ".((int) $newtime);
2926 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2928 $resql2 = $db->query($sql2);
2935 if (!empty($totaltime[$obj->fk_element])) {
2936 $totaltime[$obj->fk_element] += $newtime;
2938 $totaltime[$obj->fk_element] = $newtime;
2941 if (!empty($totaltime[$obj->fk_element])) {
2942 $totaltime[$obj->fk_element] += $obj->element_duration;
2944 $totaltime[$obj->fk_element] = $obj->element_duration;
2953 foreach ($totaltime as $taskid => $total_duration) {
2954 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2955 $sql .=
" duration_effective = ".((int) $total_duration);
2956 $sql .=
" WHERE rowid = ".((int) $taskid);
2958 $resql = $db->query($sql);
2965 print $langs->trans(
'AlreadyDone').
"<br>\n";
2971 print $langs->trans(
'AlreadyDone').
"<br>\n";
2996 print
'<tr><td colspan="4">';
2999 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3003 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3004 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3005 $obj1 = $db->fetch_object($result1);
3006 $obj2 = $db->fetch_object($result2);
3007 if (!$obj1 && !$obj2) {
3012 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3013 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3015 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3016 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3017 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3018 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3019 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3020 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3021 $sqlSelect .=
" AND el.targettype = 'shipping'";
3023 $resql = $db->query($sqlSelect);
3026 $num = $db->num_rows($resql);
3030 $obj = $db->fetch_object($resql);
3032 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3033 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3034 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3035 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3037 $result = $db->query($sqlUpdate);
3046 print $langs->trans(
'AlreadyDone').
"<br>\n";
3064 print $langs->trans(
'AlreadyDone').
"<br>\n";
3080 print
'<tr><td colspan="4">';
3083 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3087 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3088 $obj = $db->fetch_object($result);
3094 $sqlSelect =
"SELECT rowid, fk_expedition";
3095 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3096 $sqlSelect .=
" WHERE fk_expedition is not null";
3098 $resql = $db->query($sqlSelect);
3101 $num = $db->num_rows($resql);
3105 $obj = $db->fetch_object($resql);
3107 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3108 $sqlInsert .=
"fk_source";
3109 $sqlInsert .=
", sourcetype";
3110 $sqlInsert .=
", fk_target";
3111 $sqlInsert .=
", targettype";
3112 $sqlInsert .=
") VALUES (";
3113 $sqlInsert .= $obj->fk_expedition;
3114 $sqlInsert .=
", 'shipping'";
3115 $sqlInsert .=
", ".$obj->rowid;
3116 $sqlInsert .=
", 'delivery'";
3119 $result = $db->query($sqlInsert);
3121 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3122 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3124 $result = $db->query($sqlUpdate);
3137 print $langs->trans(
'AlreadyDone').
"<br>\n";
3141 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3142 $db->query($sqlDelete);
3147 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3148 $db->query($sqlDrop);
3158 print $langs->trans(
'AlreadyDone').
"<br>\n";
3175 print
'<tr><td colspan="4">';
3178 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3186 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3187 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3188 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3189 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3190 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3191 $sqlSelect .=
" AND el.targettype = 'delivery'";
3192 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3193 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3195 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3196 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3198 $resql = $db->query($sqlSelect);
3201 $num = $db->num_rows($resql);
3205 $obj = $db->fetch_object($resql);
3207 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3208 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3209 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3210 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3212 $result = $db->query($sqlUpdate);
3221 print $langs->trans(
'AlreadyDone').
"<br>\n";
3248 print
'<tr><td colspan="4">';
3251 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3254 'propal' =>
'propalrowid',
3255 'order' =>
'fk_commande',
3256 'invoice' =>
'fk_facture',
3257 'contract' =>
'fk_contract',
3258 'order_supplier' =>
'fk_supplier_order',
3259 'invoice_supplier' =>
'fk_supplier_invoice'
3262 foreach ($elements as $type => $field) {
3263 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3264 $obj = $db->fetch_object($result);
3270 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3271 $sql .=
"fk_element = ".$db->sanitize($field).
", elementtype = '".$db->escape($type).
"'";
3272 $sql .=
" WHERE ".$db->sanitize($field).
" IS NOT NULL";
3273 $sql .=
" AND fk_element IS NULL";
3274 $sql .=
" AND elementtype IS NULL";
3276 $resql = $db->query($sql);
3290 print $langs->trans(
'AlreadyDone').
"<br>\n";
3307 print
'<tr><td colspan="4">';
3310 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3313 'old_id' => array(5, 8, 9, 10, 11),
3314 'new_id' => array(50, 51, 52, 53, 54),
3315 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3316 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3320 foreach ($elements[
'old_id'] as $key => $old_id) {
3325 $sqlSelect =
"SELECT id";
3326 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3327 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3328 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3330 $resql = $db->query($sqlSelect);
3332 $num = $db->num_rows($resql);
3338 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3339 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3340 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3341 $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]).
"')";
3342 $resqla = $db->query($sqla);
3344 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3345 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3346 $sql .=
" WHERE id = ".((int) $old_id);
3347 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3348 $resql = $db->query($sql);
3350 if ($resqla && $resql) {
3351 foreach ($elements[
'tables'] as $table) {
3352 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3353 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3354 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3356 $resql = $db->query($sql);
3379 print $langs->trans(
'AlreadyDone').
"<br>\n";
3397 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3399 $obj = $db->fetch_object($result);
3402 $children = array();
3403 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3404 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3406 $resql = $db->query($sql);
3408 $num = $db->num_rows($resql);
3409 while ($obj = $db->fetch_object($resql)) {
3410 if (!isset($children[$obj->fk_categorie_fille])) {
3411 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3412 $children[$obj->fk_categorie_fille] = 1;
3413 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3421 if (count($couples) > 0 && $num > count($couples)) {
3427 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3429 $resqld = $db->query($sql);
3432 foreach ($couples as $key => $val) {
3433 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3434 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3436 $resqli = $db->query($sql);
3444 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3445 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3448 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3449 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3454 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3455 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3472 print
'<tr><td colspan="4">';
3475 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3479 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3484 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3485 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3487 $resql = $db->query($sqlSelect);
3490 $num = $db->num_rows($resql);
3494 $obj = $db->fetch_object($resql);
3496 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3497 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3498 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3500 $result = $db->query($sqlUpdate);
3509 print $langs->trans(
'AlreadyDone').
"<br>\n";
3522 print $langs->trans(
'AlreadyDone').
"<br>\n";
3538 print
'<tr><td colspan="4">';
3541 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3549 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3550 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3551 $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";
3552 $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')";
3553 $sqlSelect .=
" ORDER BY a.id";
3556 $resql = $db->query($sqlSelect);
3559 $num = $db->num_rows($resql);
3563 $obj = $db->fetch_object($resql);
3565 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3566 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3568 $result = $db->query($sqlUpdate);
3577 print $langs->trans(
'AlreadyDone').
"<br>\n";
3604 print
'<tr><td colspan="4">';
3607 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3615 $sqlSelect =
"SELECT a.id, a.fk_contact";
3616 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3617 $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";
3618 $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')";
3619 $sqlSelect .=
" ORDER BY a.id";
3622 $resql = $db->query($sqlSelect);
3625 $num = $db->num_rows($resql);
3629 $obj = $db->fetch_object($resql);
3631 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3632 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3634 $result = $db->query($sqlUpdate);
3643 print $langs->trans(
'AlreadyDone').
"<br>\n";
3673 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3675 print
'<tr><td colspan="4">';
3678 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3686 $sqlSelect =
"SELECT DISTINCT entity";
3687 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3691 $resql = $db->query($sqlSelect);
3694 $num = $db->num_rows($resql);
3698 $obj = $db->fetch_object($resql);
3700 print
'Process entity '.$obj->entity;
3702 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3703 $resqlSearch = $db->query($sqlSearch);
3705 $objSearch = $db->fetch_object($resqlSearch);
3707 if ($objSearch && $objSearch->nb == 0) {
3708 print
' - Record for entity must be reset...';
3710 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3711 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3712 $resqlUpdate = $db->query($sqlUpdate);
3713 if (!$resqlUpdate) {
3722 $object->entity = $obj->entity;
3726 $b->setObjectData(
$object,
'MODULE_SET', 0);
3728 $res = $b->create($user);
3734 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3743 print $langs->trans(
'NothingToDo').
"<br>\n";
3770 print
'<tr><td colspan="4">';
3773 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3781 $sqlSelect =
"SELECT sr.rowid, s.entity";
3782 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3783 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3787 $resql = $db->query($sqlSelect);
3790 $num = $db->num_rows($resql);
3794 $obj = $db->fetch_object($resql);
3796 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3797 $sqlUpdate .=
" entity = ".$obj->entity;
3798 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3800 $result = $db->query($sqlUpdate);
3810 print $langs->trans(
'AlreadyDone').
"<br>\n";
3836 print
'<tr><td colspan="4">';
3839 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3847 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3848 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3851 $resql = $db->query($sqlSelect);
3854 $num = $db->num_rows($resql);
3858 $obj = $db->fetch_object($resql);
3860 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3861 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3863 $sqlSelect2 =
"SELECT f.entity";
3864 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3865 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3866 } elseif (!empty($obj->fk_facture_line)) {
3867 $sqlSelect2 =
"SELECT f.entity";
3868 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3869 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3870 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3872 $sqlSelect2 =
"SELECT s.entity";
3873 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3874 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3877 $resql2 = $db->query($sqlSelect2);
3879 if ($db->num_rows($resql2) > 0) {
3880 $obj2 = $db->fetch_object($resql2);
3882 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3883 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3884 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3886 $result = $db->query($sqlUpdate);
3901 print $langs->trans(
'AlreadyDone').
"<br>\n";
3928 print
'<tr><td colspan="4">';
3930 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3938 $sqlSelect =
"SELECT u.rowid, u.entity";
3939 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3940 $sqlSelect .=
" WHERE u.entity > 1";
3943 $resql = $db->query($sqlSelect);
3946 $num = $db->num_rows($resql);
3950 $obj = $db->fetch_object($resql);
3952 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3953 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3954 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3956 $result = $db->query($sqlUpdate);
3966 print $langs->trans(
'AlreadyDone').
"<br>\n";
3993 print
'<tr><td colspan="4">';
3995 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4003 $sqlSelect =
"SELECT u.rowid, u.entity";
4004 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4005 $sqlSelect .=
" WHERE u.entity > 1";
4008 $resql = $db->query($sqlSelect);
4011 $num = $db->num_rows($resql);
4015 $obj = $db->fetch_object($resql);
4017 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4018 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4019 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4021 $result = $db->query($sqlUpdate);
4031 print $langs->trans(
'AlreadyDone').
"<br>\n";
4062 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4063 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4064 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4084 $filetodeletearray = array(
4085 '/core/ajax/ajaxcompanies.php',
4086 '/core/triggers/interface_demo.class.php',
4087 '/core/menus/barre_left/default.php',
4088 '/core/menus/barre_top/default.php',
4089 '/core/modules/modComptabiliteExpert.class.php',
4090 '/core/modules/modCommercial.class.php',
4091 '/core/modules/modProduit.class.php',
4092 '/core/modules/modSkype.class.php',
4093 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4094 '/core/triggers/interface_modCommande_Ecotax.class.php',
4095 '/core/triggers/interface_modCommande_fraisport.class.php',
4096 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4097 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4098 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4099 '/core/menus/smartphone/iphone.lib.php',
4100 '/core/menus/smartphone/iphone_backoffice.php',
4101 '/core/menus/smartphone/iphone_frontoffice.php',
4102 '/core/menus/standard/auguria_backoffice.php',
4103 '/core/menus/standard/auguria_frontoffice.php',
4104 '/core/menus/standard/eldy_backoffice.php',
4105 '/core/menus/standard/eldy_frontoffice.php',
4106 '/core/modules/export/export_excel.modules.php',
4107 '/core/modules/export/export_csv.modules.php',
4108 '/core/modules/export/exportcsv.modules.php',
4109 '/core/modules/export/export_excel2007new.modules.php',
4110 '/core/modules/facture/pdf_crabe.modules.php',
4111 '/core/modules/facture/pdf_oursin.modules.php',
4112 '/core/modules/mailings/contacts2.modules.php',
4113 '/core/modules/mailings/contacts3.modules.php',
4114 '/core/modules/mailings/contacts4.modules.php',
4115 '/core/modules/mailings/framboise.modules.php',
4116 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4117 '/core/modules/mailings/peche.modules.php',
4118 '/core/modules/mailings/poire.modules.php',
4119 '/core/modules/mailings/kiwi.modules.php',
4120 '/core/boxes/box_members.php',
4122 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4123 '/includes/nusoap/lib/class.*',
4124 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4125 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4127 '/api/class/api_generic.class.php',
4128 '/asterisk/cidlookup.php',
4129 '/categories/class/api_category.class.php',
4130 '/categories/class/api_deprecated_category.class.php',
4131 '/compta/facture/class/api_invoice.class.php',
4132 '/commande/class/api_commande.class.php',
4133 '/partnership/class/api_partnership.class.php',
4134 '/product/class/api_product.class.php',
4135 '/recruitment/class/api_recruitment.class.php',
4136 '/societe/class/api_contact.class.php',
4137 '/societe/class/api_thirdparty.class.php',
4138 '/support/online.php',
4139 '/takepos/class/actions_takepos.class.php',
4140 '/user/class/api_user.class.php',
4142 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4143 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4144 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4145 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4146 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4147 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4156 foreach ($filetodeletearray as $filetodelete) {
4158 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete) || preg_match(
'/\*/', $filetodelete)) {
4160 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true, 0);
4162 $langs->load(
"errors");
4163 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4164 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4189 $filetodeletearray = array(
4190 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4191 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4195 if (!empty($_SERVER[
"WINDIR"])) {
4196 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4199 foreach ($filetodeletearray as $filetodelete) {
4201 if (file_exists($filetodelete)) {
4205 $langs->load(
"errors");
4206 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4207 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4231 if (count($listofmodule) == 0) {
4235 if (!is_object($user)) {
4236 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4237 $user =
new User($db);
4240 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)));
4242 $reloadactionformodules = array(
4243 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4244 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4245 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4246 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4247 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4248 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove' => 1),
4249 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4250 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4251 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4252 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4253 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4254 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4255 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4256 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4257 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4258 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4259 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4260 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4261 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4262 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4263 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4264 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove' => 1),
4265 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4266 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4267 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4268 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4269 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4270 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4271 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4274 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4275 if (empty($moduletoreload) || (empty(
$conf->global->$moduletoreload) && !$force)) {
4281 if (!empty($reloadactionformodules[$moduletoreload])) {
4282 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4284 $val = $reloadactionformodules[$moduletoreload];
4285 $classformodule = $val[
'class'];
4286 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4288 $mod =
new $classformodule($db);
4289 if (!empty($val[
'remove'])) {
4290 $mod->remove(
'noboxes');
4292 if (!empty($val[
'deleteinsertmenus'])) {
4294 $mod->delete_menus();
4295 $mod->insert_menus();
4297 $mod->init($reloadmode);
4302 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4303 if (!empty($reg[1])) {
4304 if (strtoupper($moduletoreload) == $moduletoreload) {
4305 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4307 $moduletoreloadshort = $reg[1];
4310 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4312 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4314 $classname =
'mod'.$moduletoreloadshort;
4315 $mod =
new $classname($db);
4316 '@phan-var-force DolibarrModules $mod';
4319 $mod->delete_menus();
4320 $mod->init($reloadmode);
4322 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4324 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4326 $classname =
'mod'.$moduletoreloadshort;
4327 $mod =
new $classname($db);
4328 '@phan-var-force DolibarrModules $mod';
4329 $mod->init($reloadmode);
4331 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4332 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4338 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4343 if (!empty($mod) && is_object($mod)) {
4344 print
'<tr class="trforrunsql"><td colspan="4">';
4345 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4346 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4347 print
"<!-- (".$reloadmode.
") -->";
4372 $listofmenuhandler = array();
4375 $listofmenuhandler[
'auguria'] = 1;
4378 foreach ($listofmenuhandler as $key => $val) {
4379 print
'<tr class="trforrunsql"><td colspan="4">';
4383 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4386 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4387 $file =
'init_menu_'.$key.
'.sql';
4388 if (file_exists($dir.$file)) {
4389 $result =
run_sql($dir.$file, 1, 0, 1, $key);
4405 global
$conf, $db, $langs, $user;
4407 if (!is_object($user)) {
4408 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4409 $user =
new User($db);
4412 print
'<tr><td colspan="4">';
4414 print
'<b>'.$langs->trans(
'MigrationProductLotPath').
"</b><br>\n";
4416 $sql =
"SELECT rowid , entity, batch, fk_product from ".MAIN_DB_PREFIX.
"product_lot";
4417 $resql = $db->query($sql);
4419 $modulepart=
"product_batch";
4420 while ($obj = $db->fetch_object($resql)) {
4421 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4423 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/'.
$conf->productbatch->multidir_output[$entity];
4425 $dir =
$conf->productbatch->multidir_output[$entity];
4429 $res = $lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);
4431 if ($dir && $res > 0) {
4432 $lot->ref = $obj->batch;
4433 $origin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4435 $lot->fetch($obj->rowid, $obj->fk_product, $obj->batch);
4436 $destin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4454 global
$conf, $db, $langs, $user;
4456 print
'<tr><td colspan="4">';
4458 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4460 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4461 $fuser =
new User($db);
4462 if (!is_object($user)) {
4466 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4467 $resql = $db->query($sql);
4469 while ($obj = $db->fetch_object($resql)) {
4471 $fuser->id = $obj->uid;
4472 $fuser->entity = $obj->entity;
4475 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4477 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4479 $dir =
$conf->user->multidir_output[$entity];
4484 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4485 $destin = $dir.
'/'.$fuser->id;
4493 $handle = opendir($origin_osencoded);
4494 if (is_resource($handle)) {
4495 while (($file = readdir($handle)) !==
false) {
4496 if ($file ==
'.' || $file ==
'..') {
4501 $thumbs = opendir($origin_osencoded.
'/'.$file);
4502 if (is_resource($thumbs)) {
4504 while (($thumb = readdir($thumbs)) !==
false) {
4506 if ($thumb ==
'.' || $thumb ==
'..') {
4512 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4522 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4543 global $db, $langs, $user;
4545 print
'<tr><td colspan="4">';
4547 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4549 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4550 $fuser =
new User($db);
4551 if (!is_object($user)) {
4555 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4556 $resql = $db->query($sql);
4558 while ($obj = $db->fetch_object($resql)) {
4560 $fuser->id = $obj->uid;
4561 $fuser->entity = $obj->entity;
4562 $fuser->photo = $obj->photo;
4565 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4567 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4569 $dir = DOL_DATA_ROOT.
'/users';
4574 $origin = $dir.
'/'.$fuser->id;
4575 $destin = $dir.
'/'.$fuser->id.
'/photos';
4583 $handle = opendir($origin_osencoded);
4584 if (is_resource($handle)) {
4585 while (($file = readdir($handle)) !==
false) {
4586 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4589 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4594 $thumbs = opendir($origin_osencoded.
'/'.$file);
4595 if (is_resource($thumbs)) {
4597 while (($thumb = readdir($thumbs)) !==
false) {
4599 if ($thumb ==
'.' || $thumb ==
'..') {
4605 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4614 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4651 print
'<tr><td colspan="4">';
4652 $sql =
'SELECT rowid, socialnetworks';
4653 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4654 $sql .=
" skype IS NOT NULL OR skype <> ''";
4655 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4656 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4657 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4658 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4659 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4660 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4661 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4662 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4664 $resql = $db->query($sql);
4666 while ($obj = $db->fetch_object($resql)) {
4667 $arraysocialnetworks = array();
4668 if (!empty($obj->skype)) {
4669 $arraysocialnetworks[
'skype'] = $obj->skype;
4671 if (!empty($obj->twitter)) {
4672 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4674 if (!empty($obj->facebook)) {
4675 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4677 if (!empty($obj->linkedin)) {
4678 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4680 if (!empty($obj->instagram)) {
4681 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4683 if (!empty($obj->snapchat)) {
4684 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4686 if (!empty($obj->googleplus)) {
4687 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4689 if (!empty($obj->youtube)) {
4690 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4692 if (!empty($obj->whatsapp)) {
4693 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4695 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4696 $obj->socialnetworks =
'[]';
4698 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4699 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4700 $sqlupd .=
', skype=null';
4701 $sqlupd .=
', twitter=null';
4702 $sqlupd .=
', facebook=null';
4703 $sqlupd .=
', linkedin=null';
4704 $sqlupd .=
', instagram=null';
4705 $sqlupd .=
', snapchat=null';
4706 $sqlupd .=
', googleplus=null';
4707 $sqlupd .=
', youtube=null';
4708 $sqlupd .=
', whatsapp=null';
4709 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4711 $resqlupd = $db->query($sqlupd);
4726 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4740 print
'<tr><td colspan="4">';
4743 print
'<tr><td colspan="4">';
4744 $sql =
'SELECT rowid, socialnetworks';
4745 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4746 $sql .=
" skype IS NOT NULL OR skype <> ''";
4747 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4748 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4749 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4750 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4751 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4752 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4753 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4754 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4756 $resql = $db->query($sql);
4758 while ($obj = $db->fetch_object($resql)) {
4759 $arraysocialnetworks = array();
4760 if (!empty($obj->skype)) {
4761 $arraysocialnetworks[
'skype'] = $obj->skype;
4763 if (!empty($obj->twitter)) {
4764 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4766 if (!empty($obj->facebook)) {
4767 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4769 if (!empty($obj->linkedin)) {
4770 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4772 if (!empty($obj->instagram)) {
4773 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4775 if (!empty($obj->snapchat)) {
4776 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4778 if (!empty($obj->googleplus)) {
4779 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4781 if (!empty($obj->youtube)) {
4782 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4784 if (!empty($obj->whatsapp)) {
4785 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4787 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4788 $obj->socialnetworks =
'[]';
4790 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4791 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4792 $sqlupd .=
', skype=null';
4793 $sqlupd .=
', twitter=null';
4794 $sqlupd .=
', facebook=null';
4795 $sqlupd .=
', linkedin=null';
4796 $sqlupd .=
', instagram=null';
4797 $sqlupd .=
', snapchat=null';
4798 $sqlupd .=
', googleplus=null';
4799 $sqlupd .=
', youtube=null';
4800 $sqlupd .=
', whatsapp=null';
4801 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4803 $resqlupd = $db->query($sqlupd);
4818 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4834 print
'<tr><td colspan="4">';
4835 $sql =
'SELECT rowid, socialnetworks';
4836 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4837 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4838 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4839 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4840 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4841 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4842 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4843 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4844 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4845 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4846 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4848 $resql = $db->query($sql);
4850 while ($obj = $db->fetch_object($resql)) {
4851 $arraysocialnetworks = array();
4852 if (!empty($obj->jabberid)) {
4853 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4855 if (!empty($obj->skype)) {
4856 $arraysocialnetworks[
'skype'] = $obj->skype;
4858 if (!empty($obj->twitter)) {
4859 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4861 if (!empty($obj->facebook)) {
4862 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4864 if (!empty($obj->linkedin)) {
4865 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4867 if (!empty($obj->instagram)) {
4868 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4870 if (!empty($obj->snapchat)) {
4871 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4873 if (!empty($obj->googleplus)) {
4874 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4876 if (!empty($obj->youtube)) {
4877 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4879 if (!empty($obj->whatsapp)) {
4880 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4882 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4883 $obj->socialnetworks =
'[]';
4885 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4886 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4887 $sqlupd .=
', jabberid=null';
4888 $sqlupd .=
', skype=null';
4889 $sqlupd .=
', twitter=null';
4890 $sqlupd .=
', facebook=null';
4891 $sqlupd .=
', linkedin=null';
4892 $sqlupd .=
', instagram=null';
4893 $sqlupd .=
', snapchat=null';
4894 $sqlupd .=
', googleplus=null';
4895 $sqlupd .=
', youtube=null';
4896 $sqlupd .=
', whatsapp=null';
4897 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4899 $resqlupd = $db->query($sqlupd);
4914 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4930 print
'<tr><td colspan="4">';
4931 $sql =
'SELECT rowid, socialnetworks';
4932 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4933 $sql .=
" skype IS NOT NULL OR skype <> ''";
4934 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4935 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4936 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4937 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4938 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4939 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4940 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4941 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4943 $resql = $db->query($sql);
4945 while ($obj = $db->fetch_object($resql)) {
4946 $arraysocialnetworks = array();
4947 if (!empty($obj->skype)) {
4948 $arraysocialnetworks[
'skype'] = $obj->skype;
4950 if (!empty($obj->twitter)) {
4951 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4953 if (!empty($obj->facebook)) {
4954 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4956 if (!empty($obj->linkedin)) {
4957 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4959 if (!empty($obj->instagram)) {
4960 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4962 if (!empty($obj->snapchat)) {
4963 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4965 if (!empty($obj->googleplus)) {
4966 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4968 if (!empty($obj->youtube)) {
4969 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4971 if (!empty($obj->whatsapp)) {
4972 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4974 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4975 $obj->socialnetworks =
'[]';
4977 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4978 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4979 $sqlupd .=
', skype=null';
4980 $sqlupd .=
', twitter=null';
4981 $sqlupd .=
', facebook=null';
4982 $sqlupd .=
', linkedin=null';
4983 $sqlupd .=
', instagram=null';
4984 $sqlupd .=
', snapchat=null';
4985 $sqlupd .=
', googleplus=null';
4986 $sqlupd .=
', youtube=null';
4987 $sqlupd .=
', whatsapp=null';
4988 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4990 $resqlupd = $db->query($sqlupd);
5005 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5025 print
'<tr class="trforrunsql"><td colspan="4">';
5026 $sql =
'SELECT rowid, field';
5027 if ($mode ==
'export') {
5030 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5031 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5033 $resql = $db->query($sql);
5035 while ($obj = $db->fetch_object($resql)) {
5036 $oldfield = $obj->field;
5037 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5039 if ($mode ==
'export') {
5040 $oldfilter = $obj->filter;
5041 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5047 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5048 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5049 if ($mode ==
'export') {
5050 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5052 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5053 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5054 $resqlupd = $db->query($sqlupd);
5070 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5073 if ($resultstring) {
5074 print $resultstring;
5076 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5093 print
'<tr class="trforrunsql"><td colspan="4">';
5094 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5096 $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";
5097 $sql .=
" ORDER BY c.rowid,cd.rowid";
5099 $resql = $db->query($sql);
5102 $current_contract = 0;
5103 while ($obj = $db->fetch_object($resql)) {
5104 if (empty($current_contract) || $current_contract == $obj->cid) {
5110 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5111 $resultstring =
'.';
5112 print $resultstring;
5113 $resqlUpd = $db->query($sqlUpd);
5119 $current_contract = $obj->cid;
5132 if (!$resultstring) {
5133 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 with list of lots and properties.
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.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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_productlot_path()
Migrate file from old path to new one for lot path.
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.