43define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
44include_once
'inc.php';
45if (!file_exists($conffile)) {
46 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").';
48require_once $conffile;
49require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
50require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
51require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
52require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
53require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
54require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
55require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
56require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
57require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
68$err = error_reporting();
71 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
77$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
78$langs->setDefaultLang($setuplang);
79$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
80$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
81$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
83$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
85if ($dolibarr_main_db_type ==
'mysqli') {
88if ($dolibarr_main_db_type ==
'pgsql') {
91if ($dolibarr_main_db_type ==
'mssql') {
96dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
97if (!is_object($conf)) {
107if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
108 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
109 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
111 $sapi_type = php_sapi_name();
112 $script_file = basename(__FILE__);
114 if (substr($sapi_type, 0, 3) ==
'cli') {
115 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
120pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
123if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
124 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
125 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
127 print
'<table border="0" width="100%">';
130 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
131 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
132 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
133 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
134 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
135 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
137 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
142 $conf->db->type = $dolibarr_main_db_type;
143 $conf->db->host = $dolibarr_main_db_host;
144 $conf->db->port = $dolibarr_main_db_port;
145 $conf->db->name = $dolibarr_main_db_name;
146 $conf->db->user = $dolibarr_main_db_user;
147 $conf->db->pass = $dolibarr_main_db_pass;
149 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
151 if (!$db->connected) {
152 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
153 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
158 if ($db->database_selected) {
165 if (empty($dolibarr_main_db_encryption)) {
166 $dolibarr_main_db_encryption = 0;
168 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
169 if (empty($dolibarr_main_db_cryptkey)) {
170 $dolibarr_main_db_cryptkey =
'';
172 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
175 $conf->setValues($db);
178 $listofentities = array(1);
181 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
183 $hookmanager->initHooks(array(
'upgrade2'));
185 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
188 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
189 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
191 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
220 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
222 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
228 foreach ($listofentities as $entity) {
230 $conf->setEntityValues($db, $entity);
232 if (defined(
'SYSLOG_FILE')) {
233 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
235 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
238 if (count($listofentities) > 1) {
239 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
244 $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 :
''));
250 $versiontoarray = explode(
'.', $versionto);
251 $versionranarray = explode(
'.', DOL_VERSION);
254 $afterversionarray = explode(
'.',
'2.0.0');
255 $beforeversionarray = explode(
'.',
'2.7.9');
316 $afterversionarray = explode(
'.',
'2.7.9');
317 $beforeversionarray = explode(
'.',
'2.8.9');
342 $afterversionarray = explode(
'.',
'2.8.9');
343 $beforeversionarray = explode(
'.',
'2.9.9');
355 $afterversionarray = explode(
'.',
'2.9.9');
356 $beforeversionarray = explode(
'.',
'3.0.9');
362 $afterversionarray = explode(
'.',
'3.0.9');
363 $beforeversionarray = explode(
'.',
'3.1.9');
371 $afterversionarray = explode(
'.',
'3.1.9');
372 $beforeversionarray = explode(
'.',
'3.2.9');
382 $afterversionarray = explode(
'.',
'3.2.9');
383 $beforeversionarray = explode(
'.',
'3.3.9');
392 $afterversionarray = explode(
'.',
'3.6.9');
393 $beforeversionarray = explode(
'.',
'3.7.9');
399 $afterversionarray = explode(
'.',
'3.7.9');
400 $beforeversionarray = explode(
'.',
'3.8.9');
406 $afterversionarray = explode(
'.',
'3.9.9');
407 $beforeversionarray = explode(
'.',
'4.0.9');
413 $afterversionarray = explode(
'.',
'4.0.9');
414 $beforeversionarray = explode(
'.',
'5.0.9');
424 $afterversionarray = explode(
'.',
'5.0.9');
425 $beforeversionarray = explode(
'.',
'6.0.9');
427 if (isModEnabled(
'multicompany')) {
428 global $multicompany_transverse_mode;
431 if (empty($multicompany_transverse_mode)) {
442 $afterversionarray = explode(
'.',
'6.0.9');
443 $beforeversionarray = explode(
'.',
'7.0.9');
452 $afterversionarray = explode(
'.',
'7.0.9');
453 $beforeversionarray = explode(
'.',
'8.0.9');
459 $afterversionarray = explode(
'.',
'8.0.9');
460 $beforeversionarray = explode(
'.',
'9.0.9');
466 $afterversionarray = explode(
'.',
'10.0.9');
467 $beforeversionarray = explode(
'.',
'11.0.9');
476 $afterversionarray = explode(
'.',
'13.0.9');
477 $beforeversionarray = explode(
'.',
'14.0.9');
484 $afterversionarray = explode(
'.',
'15.0.9');
485 $beforeversionarray = explode(
'.',
'16.0.9');
492 $afterversionarray = explode(
'.',
'16.0.9');
493 $beforeversionarray = explode(
'.',
'17.0.9');
499 $afterversionarray = explode(
'.',
'17.0.9');
500 $beforeversionarray = explode(
'.',
'18.0.9');
515 $afterversionarray = explode(
'.',
'19.0.9');
516 $beforeversionarray = explode(
'.',
'20.0.9');
526 $listofmodule = array(
527 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
528 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
529 'MAIN_MODULE_BOM' =>
'menuonly',
530 'MAIN_MODULE_BANQUE' =>
'menuonly',
531 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
532 'MAIN_MODULE_CRON' =>
'newboxdefonly',
533 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
534 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
535 'MAIN_MODULE_DEPLACEMENT' =>
'newboxdefonly',
536 'MAIN_MODULE_DON' =>
'newboxdefonly',
537 'MAIN_MODULE_ECM' =>
'newboxdefonly',
538 'MAIN_MODULE_EXTERNALSITE' =>
'newboxdefonly',
539 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
540 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
541 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
542 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
543 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
544 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
545 'MAIN_MODULE_MARGIN' =>
'menuonly',
546 'MAIN_MODULE_MRP' =>
'menuonly',
547 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
548 'MAIN_MODULE_PAYBOX' =>
'newboxdefonly',
549 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
550 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
551 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
552 'MAIN_MODULE_RESOURCE' =>
'noboxes',
553 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
554 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
555 'MAIN_MODULE_SYSLOG' =>
'newboxdefonly',
556 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
557 'MAIN_MODULE_STRIPE' =>
'menuonly',
558 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
559 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
560 'MAIN_MODULE_USER' =>
'newboxdefonly',
561 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
562 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
578 if (!$error && $enablemodules) {
580 $listofmodules = array();
581 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
582 $tmplistofmodules = explode(
',', $enablemodules);
583 foreach ($tmplistofmodules as $value) {
584 $listofmodules[$value] =
'forceactivate';
588 if ($resultreloadmodules < 0) {
596 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
599 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
600 if ($hookmanager->resNbOfHooks > 0) {
602 print
'<tr><td colspan="4">';
603 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
604 print $hookmanager->error;
605 print
"<!-- (".$reshook.
") -->";
608 print
'<tr class="trforrunsql"><td colspan="4">';
609 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
610 print
"<!-- (".$reshook.
") -->";
615 if (!empty($conf->modules_parts[
'hooks'])) {
616 print
'<tr class="trforrunsql"><td colspan="4">';
617 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
628 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
643 foreach ($listofentities as $entity) {
645 $conf->setEntityValues($db, $entity);
647 if (defined(
'SYSLOG_FILE')) {
648 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
650 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
654 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
655 $destroot = DOL_DATA_ROOT.
'/medias';
668 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
671 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
672 if ($hookmanager->resNbOfHooks > 0) {
674 print
'<tr><td colspan="4">';
675 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
676 print $hookmanager->error;
677 print
"<!-- (".$reshook.
") -->";
680 print
'<tr class="trforrunsql"><td colspan="4">';
681 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
682 print
"<!-- (".$reshook.
") -->";
687 if (!empty($conf->modules_parts[
'hooks'])) {
688 print
'<tr class="trforrunsql"><td colspan="4">';
689 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
699 print
'<table width="100%">';
700 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
701 print
'<td class="right">';
705 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
709 print
'<script type="text/javascript">
710 jQuery(document).ready(function() {
711 function init_trrunsql()
713 console.log("toggle .trforrunsql");
714 jQuery(".trforrunsql").toggle();
717 jQuery(".trforrunsqlshowhide").click(function() {
722 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
725 print
'</td></tr>'.
"\n";
731 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
736if ($error && isset($argv[1])) {
742pFooter($error ? 2 : 0, $setuplang);
765 print
'<tr><td colspan="4">';
768 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
770 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
771 $obj = $db->fetch_object($result);
773 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
774 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
775 $sql .=
" WHERE p.fk_facture > 0";
777 $resql = $db->query($sql);
783 $num = $db->num_rows($resql);
786 $obj = $db->fetch_object($resql);
787 $row[$i][0] = $obj->rowid;
788 $row[$i][1] = $obj->fk_facture;
789 $row[$i][2] = $obj->amount;
797 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
801 for ($i = 0; $i < $num; $i++) {
802 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
803 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
805 $res += $db->query($sql);
807 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
809 $res += $db->query($sql);
811 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
815 if ($res == (2 * count($row))) {
817 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
820 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
823 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
826 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
844 print
'<tr><td colspan="4">';
847 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
849 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
850 $obj = $db->fetch_object($result);
853 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
854 $sql .=
" bu2.url_id as socid";
855 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
856 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
857 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
858 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
859 $sql .=
" AND b.rappro = 1";
860 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
862 $resql = $db->query($sql);
868 $num = $db->num_rows($resql);
871 $obj = $db->fetch_object($resql);
872 if ($obj->pamount == $obj->bamount && $obj->socid) {
873 $row[$j][
'paymentid'] = $obj->rowid;
874 $row[$j][
'pamount'] = $obj->pamount;
875 $row[$j][
'fk_bank'] = $obj->fk_bank;
876 $row[$j][
'bamount'] = $obj->bamount;
877 $row[$j][
'socid'] = $obj->socid;
878 $row[$j][
'datec'] = $obj->datec;
888 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
893 for ($i = 0; $i < $num; $i++) {
895 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>';
899 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
900 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
901 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
902 $sql .=
" AND pf.fk_facture IS NULL";
903 $sql .=
" ORDER BY f.fk_statut";
905 $resql = $db->query($sql);
907 $num = $db->num_rows($resql);
910 $obj = $db->fetch_object($resql);
911 $facid = $obj->rowid;
913 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
914 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
916 $res += $db->query($sql);
918 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
926 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
928 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
933 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
936 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
954 print
'<tr><td colspan="4">';
957 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
959 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
960 $obj = $db->fetch_object($result);
963 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
964 $sql .=
" bu2.url_id as socid";
965 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
966 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
967 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
968 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
969 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
971 $resql = $db->query($sql);
977 $num = $db->num_rows($resql);
980 $obj = $db->fetch_object($resql);
981 if ($obj->pamount == $obj->bamount && $obj->socid) {
982 $row[$j][
'paymentid'] = $obj->rowid;
983 $row[$j][
'pamount'] = $obj->pamount;
984 $row[$j][
'fk_bank'] = $obj->fk_bank;
985 $row[$j][
'bamount'] = $obj->bamount;
986 $row[$j][
'socid'] = $obj->socid;
987 $row[$j][
'datec'] = $obj->datec;
1000 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
1004 for ($i = 0; $i < $num; $i++) {
1006 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>';
1010 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1011 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1012 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1013 $sql .=
" AND pf.fk_facture IS NULL";
1014 $sql .=
" ORDER BY f.fk_statut";
1016 $resql = $db->query($sql);
1018 $num = $db->num_rows($resql);
1021 $obj = $db->fetch_object($resql);
1022 $facid = $obj->rowid;
1024 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1025 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1027 $res += $db->query($sql);
1029 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1038 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1040 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1045 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1051 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1061 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1078 print
'<tr><td colspan="4">';
1083 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1085 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1086 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1087 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1088 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1089 $sql .=
" ON c.fk_product = p.rowid";
1090 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1091 $sql .=
" ON c.rowid=cd.fk_contrat";
1092 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1093 $resql = $db->query($sql);
1099 $num = $db->num_rows($resql);
1102 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1106 $obj = $db->fetch_object($resql);
1108 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1109 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1110 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1111 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1112 $sql .=
" VALUES (";
1113 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1115 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1116 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1119 $sql .= ((float) $obj->tva_tx).
", 1, ";
1120 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1124 if ($db->query($sql)) {
1125 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1137 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1140 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1143 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1146 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1163 print
'<tr><td colspan="4">';
1168 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1170 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1171 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1172 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1173 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1174 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1175 $sql .=
" AND bu.fk_bank IS NULL";
1176 $resql = $db->query($sql);
1182 $num = $db->num_rows($resql);
1185 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1189 $obj = $db->fetch_object($resql);
1191 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1192 $sql .=
"fk_bank, url_id, url, label, type";
1194 $sql .=
" VALUES (";
1195 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1201 if (!$db->query($sql)) {
1212 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1215 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1218 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1237 print
'<tr><td colspan="4">';
1240 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1242 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1244 $resql = $db->query($sql);
1248 if ($db->affected_rows($resql) > 0) {
1249 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1251 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1254 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1256 $resql = $db->query($sql);
1260 if ($db->affected_rows($resql) > 0) {
1261 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1263 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1279 print
'<tr><td colspan="4">';
1284 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1286 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1287 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1288 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1289 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1290 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1291 $resql = $db->query($sql);
1297 $num = $db->num_rows($resql);
1300 $nbcontratsmodifie = 0;
1304 $obj = $db->fetch_object($resql);
1305 if ($obj->date_contrat > $obj->datemin) {
1306 $datemin = $db->jdate($obj->datemin);
1308 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1309 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1310 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1311 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1312 $resql2 = $db->query($sql);
1317 $nbcontratsmodifie++;
1324 if ($nbcontratsmodifie) {
1325 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1327 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1347 print
'<tr><td colspan="4">';
1350 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1352 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1354 $resql = $db->query($sql);
1358 if ($db->affected_rows($resql) > 0) {
1359 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1361 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1377 print
'<tr><td colspan="4">';
1380 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1382 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1383 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1385 $resql = $db->query($sql);
1389 if ($db->affected_rows($resql) > 0) {
1392 $num = $db->num_rows($resql);
1395 $nbcontratsmodifie = 0;
1399 $obj = $db->fetch_object($resql);
1401 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1402 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1403 $sql .=
" SET statut = 1";
1404 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1405 $resql2 = $db->query($sql);
1410 $nbcontratsmodifie++;
1417 if ($nbcontratsmodifie) {
1418 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1420 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1424 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1442 print
'<tr><td colspan="4">';
1444 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1447 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1448 $obj = $db->fetch_object($result);
1453 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1454 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1455 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1458 $select_resql = $db->query($select_sql);
1459 if ($select_resql) {
1460 $select_num = $db->num_rows($select_resql);
1464 while (($i < $select_num) && (!$error)) {
1465 $select_obj = $db->fetch_object($select_resql);
1468 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1469 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1470 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1471 $check_resql = $db->query($check_sql);
1473 $check_num = $db->num_rows($check_resql);
1474 if ($check_num == 0) {
1478 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1479 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1482 print
'<tr class="oddeven">';
1483 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1485 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1486 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1487 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1488 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1489 $insert_resql = $db->query($insert_sql);
1491 if ($insert_resql) {
1493 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1495 print
'<td><span class="error">Error on insert</span></td>';
1511 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1515 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1518 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1522 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1539 $tmpmysoc->setMysoc($conf);
1543 print
'<tr><td colspan="4">';
1546 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1549 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1550 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1552 $sql .=
" WHERE fd.fk_facture = f.rowid";
1553 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1557 $resql = $db->query($sql);
1559 $num = $db->num_rows($resql);
1563 $obj = $db->fetch_object($resql);
1565 $rowid = $obj->rowid;
1567 $pu = $obj->subprice;
1568 $vatrate = $obj->vatrate;
1569 $remise_percent = $obj->remise_percent;
1570 $remise_percent_global = $obj->remise_percent_global;
1571 $total_ttc_f = $obj->total_ttc_f;
1572 $info_bits = $obj->info_bits;
1576 $facligne->fetch($rowid);
1578 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1579 $total_ht = $result[0];
1580 $total_tva = $result[1];
1581 $total_ttc = $result[2];
1583 $facligne->total_ht = $total_ht;
1584 $facligne->total_tva = $total_tva;
1585 $facligne->total_ttc = $total_ttc;
1587 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);
1589 $facligne->update_total();
1593 if (!$total_ttc_f) {
1595 $facture->id = $obj->facid;
1597 if ($facture->fetch($facture->id) >= 0) {
1598 if ($facture->update_price() > 0) {
1601 print
"Error id=".$facture->id;
1614 print $langs->trans(
"AlreadyDone");
1620 print
"Error #1 ".$db->error();
1642 $tmpmysoc->setMysoc($conf);
1646 print
'<tr><td colspan="4">';
1649 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1652 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1653 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1654 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1655 $sql .=
" WHERE pd.fk_propal = p.rowid";
1656 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1659 $resql = $db->query($sql);
1661 $num = $db->num_rows($resql);
1665 $obj = $db->fetch_object($resql);
1667 $rowid = $obj->rowid;
1669 $pu = $obj->subprice;
1670 $vatrate = $obj->vatrate;
1671 $remise_percent = $obj->remise_percent;
1672 $remise_percent_global = $obj->remise_percent_global;
1673 $info_bits = $obj->info_bits;
1677 $propalligne->fetch($rowid);
1679 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1680 $total_ht = $result[0];
1681 $total_tva = $result[1];
1682 $total_ttc = $result[2];
1684 $propalligne->total_ht = $total_ht;
1685 $propalligne->total_tva = $total_tva;
1686 $propalligne->total_ttc = $total_ttc;
1688 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);
1690 $propalligne->update_total();
1695 print $langs->trans(
"AlreadyDone");
1702 print
"Error #1 ".$db->error();
1725 $tmpmysoc->setMysoc($conf);
1726 if (empty($tmpmysoc->country_id)) {
1727 $tmpmysoc->country_id = 0;
1730 print
'<tr><td colspan="4">';
1733 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1736 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1737 $sql .=
" c.rowid as contratid";
1738 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1739 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1740 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1743 $resql = $db->query($sql);
1745 $num = $db->num_rows($resql);
1749 $obj = $db->fetch_object($resql);
1751 $rowid = $obj->rowid;
1753 $pu = $obj->subprice;
1754 $vatrate = $obj->vatrate;
1755 $remise_percent = $obj->remise_percent;
1756 $info_bits = $obj->info_bits;
1761 $contratligne->fetch($rowid);
1763 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1764 $total_ht = $result[0];
1765 $total_tva = $result[1];
1766 $total_ttc = $result[2];
1768 $contratligne->total_ht = $total_ht;
1769 $contratligne->total_tva = $total_tva;
1770 $contratligne->total_ttc = $total_ttc;
1772 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
": contratdetid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" -> ".$total_ht.
", ".$total_tva.
" , ".$total_ttc);
1774 $contratligne->update_total();
1779 print $langs->trans(
"AlreadyDone");
1786 print
"Error #1 ".$db->error();
1809 $tmpmysoc->setMysoc($conf);
1811 print
'<tr><td colspan="4">';
1814 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1817 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1818 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1819 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1820 $sql .=
" WHERE cd.fk_commande = c.rowid";
1821 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1824 $resql = $db->query($sql);
1826 $num = $db->num_rows($resql);
1830 $obj = $db->fetch_object($resql);
1832 $rowid = $obj->rowid;
1834 $pu = $obj->subprice;
1835 $vatrate = $obj->vatrate;
1836 $remise_percent = $obj->remise_percent;
1837 $remise_percent_global = $obj->remise_percent_global;
1838 $info_bits = $obj->info_bits;
1842 $commandeligne->fetch($rowid);
1844 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1845 $total_ht = $result[0];
1846 $total_tva = $result[1];
1847 $total_ttc = $result[2];
1849 $commandeligne->total_ht = $total_ht;
1850 $commandeligne->total_tva = $total_tva;
1851 $commandeligne->total_ttc = $total_ttc;
1853 dolibarr_install_syslog(
"upgrade2: Line ".$rowid.
" : commandeid=".$obj->rowid.
" pu=".$pu.
" qty=".$qty.
" vatrate=".$vatrate.
" remise_percent=".$remise_percent.
" remise_global=".$remise_percent_global.
" -> ".$total_ht.
", ".$total_tva.
", ".$total_ttc);
1855 $commandeligne->update_total();
1860 print $langs->trans(
"AlreadyDone");
1877 print
"Error #1 ".$db->error();
1902 $tmpmysoc->setMysoc($conf);
1904 print
'<tr><td colspan="4">';
1907 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1910 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1911 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1912 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1913 $sql .=
" WHERE cd.fk_commande = c.rowid";
1914 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1917 $resql = $db->query($sql);
1919 $num = $db->num_rows($resql);
1923 $obj = $db->fetch_object($resql);
1925 $rowid = $obj->rowid;
1927 $pu = $obj->subprice;
1928 $vatrate = $obj->vatrate;
1929 $remise_percent = $obj->remise_percent;
1930 $remise_percent_global = $obj->remise_percent_global;
1931 $info_bits = $obj->info_bits;
1935 $commandeligne->fetch($rowid);
1937 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $mysoc);
1938 $total_ht = $result[0];
1939 $total_tva = $result[1];
1940 $total_ttc = $result[2];
1942 $commandeligne->total_ht = $total_ht;
1943 $commandeligne->total_tva = $total_tva;
1944 $commandeligne->total_ttc = $total_ttc;
1946 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);
1948 $commandeligne->update_total();
1953 print $langs->trans(
"AlreadyDone");
1970 print
"Error #1 ".$db->error();
1995 if (isModEnabled(
'invoice')) {
1996 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1998 if (count($modellist) == 0) {
2000 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2001 $resql = $db->query($sql);
2008 if (isModEnabled(
'order')) {
2009 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2011 if (count($modellist) == 0) {
2013 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2014 $resql = $db->query($sql);
2021 if (isModEnabled(
"shipping")) {
2022 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2024 if (count($modellist) == 0) {
2026 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2027 $resql = $db->query($sql);
2050 print
'<tr><td colspan="4">';
2053 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2055 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2056 $obj = $db->fetch_object($result);
2062 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2063 $resql = $db->query($sql);
2066 $num = $db->num_rows($resql);
2070 $obj = $db->fetch_object($resql);
2072 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2073 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2074 $resql2 = $db->query($sql);
2087 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2088 print $langs->trans(
'FieldRenamed').
"<br>\n";
2098 print $langs->trans(
'AlreadyDone').
"<br>\n";
2115 print
'<tr><td colspan="4">';
2118 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2120 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2121 $obj = $db->fetch_object($result);
2127 $sql =
"SELECT l.rowid, l.fk_commande,";
2128 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2130 $sql .=
" WHERE c.rowid = l.fk_commande";
2131 $resql = $db->query($sql);
2134 $num = $db->num_rows($resql);
2138 $obj = $db->fetch_object($resql);
2140 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2141 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2142 $resql2 = $db->query($sql);
2145 $delivery_date = $db->jdate($obj->delivery_date);
2147 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2148 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2149 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2150 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2151 $resql3 = $db->query($sqlu);
2167 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2168 print $langs->trans(
'FieldRenamed').
"<br>\n";
2178 print $langs->trans(
'AlreadyDone').
"<br>\n";
2195 print
'<tr><td colspan="4">';
2198 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2202 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2203 $obj = $db->fetch_object($result);
2209 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2210 $sql .=
", ld.fk_livraison";
2211 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2212 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2213 $resql = $db->query($sql);
2216 $num = $db->num_rows($resql);
2220 $obj = $db->fetch_object($resql);
2222 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2223 $sql .=
" fk_product = ".((int) $obj->fk_product);
2224 $sql .=
",description = '".$db->escape($obj->description).
"'";
2225 $sql .=
",subprice = ".price2num($obj->subprice);
2226 $sql .=
",total_ht = ".price2num($obj->total_ht);
2227 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2228 $resql2 = $db->query($sql);
2231 $sql =
"SELECT total_ht";
2232 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2233 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2234 $resql3 = $db->query($sql);
2237 $obju = $db->fetch_object($resql3);
2238 $total_ht = $obju->total_ht + $obj->total_ht;
2240 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2241 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2242 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2243 $resql4 = $db->query($sqlu);
2263 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2264 print $langs->trans(
'FieldRenamed').
"<br>\n";
2274 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2275 $obj = $db->fetch_object($result);
2277 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2280 print $langs->trans(
'AlreadyDone').
"<br>\n";
2297 print
'<tr><td colspan="4">';
2300 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2306 $sql =
"SELECT SUM(reel) as total, fk_product";
2307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2308 $sql .=
" GROUP BY fk_product";
2309 $resql = $db->query($sql);
2312 $num = $db->num_rows($resql);
2316 $obj = $db->fetch_object($resql);
2318 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2319 $sql .=
" stock = ".price2num($obj->total,
'MS');
2320 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2322 $resql2 = $db->query($sql);
2359 print
'<tr><td colspan="4">';
2362 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2366 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2369 $sql =
"SELECT m.rowid, mc.action";
2370 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2371 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2372 $sql .=
" AND m.enabled = '1'";
2373 $resql = $db->query($sql);
2376 $num = $db->num_rows($resql);
2379 $obj = $db->fetch_object($resql);
2381 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2382 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2383 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2384 $sql .=
" AND enabled = '1'";
2386 $resql2 = $db->query($sql);
2407 print $langs->trans(
'AlreadyDone').
"<br>\n";
2426 print
'<tr><td colspan="4">';
2429 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2433 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2436 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2438 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2439 $sql .=
" WHERE c.rowid = ce.fk_commande";
2440 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2442 $resql = $db->query($sql);
2445 $num = $db->num_rows($resql);
2449 $obj = $db->fetch_object($resql);
2451 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2452 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2453 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2455 $resql2 = $db->query($sql);
2464 print $langs->trans(
'AlreadyDone').
"<br>\n";
2477 print $langs->trans(
'AlreadyDone').
"<br>\n";
2496 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2498 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2502 print
'<tr><td colspan="4">';
2505 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2511 $table1 =
'facturedet';
2512 $field1 =
'fk_remise_except';
2513 $table2 =
'societe_remise_except';
2514 $field2 =
'fk_facture_line';
2518 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2519 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2520 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2521 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2522 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2525 $resql = $db->query($sql);
2528 $num = $db->num_rows($resql);
2532 $obj = $db->fetch_object($resql);
2534 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2535 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2536 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2537 $sql .=
" WHERE rowid = ".((int) $obj->field);
2539 $resql2 = $db->query($sql);
2548 print $langs->trans(
'AlreadyDone').
"<br>\n";
2564 print
'<tr><td colspan="4">';
2567 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2570 $table2 =
'facturedet';
2571 $field2 =
'fk_remise_except';
2572 $table1 =
'societe_remise_except';
2573 $field1 =
'fk_facture_line';
2577 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2578 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2579 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2580 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2581 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2584 $resql = $db->query($sql);
2587 $num = $db->num_rows($resql);
2591 $obj = $db->fetch_object($resql);
2593 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2594 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2595 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2596 $sql .=
" WHERE rowid = ".((int) $obj->field);
2598 $resql2 = $db->query($sql);
2607 print $langs->trans(
'AlreadyDone').
"<br>\n";
2622 return ($error ? -1 : 1);
2637 print
'<tr><td colspan="4">';
2640 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2642 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2643 $obj = $db->fetch_object($result);
2649 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2650 $resql = $db->query($sql);
2653 $num = $db->num_rows($resql);
2657 $obj = $db->fetch_object($resql);
2659 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2660 $sql2 .=
"datecreate";
2661 $sql2 .=
", statut";
2662 $sql2 .=
", element_id";
2663 $sql2 .=
", fk_c_type_contact";
2664 $sql2 .=
", fk_socpeople";
2665 $sql2 .=
") VALUES (";
2666 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2668 $sql2 .=
", ".$obj->rowid;
2670 $sql2 .=
", ".$obj->fk_user_resp;
2673 if ($obj->fk_user_resp > 0) {
2674 $resql2 = $db->query($sql2);
2687 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2688 if ($db->query($sqlDrop)) {
2701 print $langs->trans(
'AlreadyDone').
"<br>\n";
2718 print
'<tr><td colspan="4">';
2721 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2723 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2728 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2729 $resql = $db->query($sql);
2732 $num = $db->num_rows($resql);
2736 $obj = $db->fetch_object($resql);
2738 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2739 $sql2 .=
"datecreate";
2740 $sql2 .=
", statut";
2741 $sql2 .=
", element_id";
2742 $sql2 .=
", fk_c_type_contact";
2743 $sql2 .=
", fk_socpeople";
2744 $sql2 .=
") VALUES (";
2745 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2747 $sql2 .=
", ".$obj->fk_project_task;
2749 $sql2 .=
", ".$obj->fk_user;
2752 $resql2 = $db->query($sql2);
2764 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2765 if ($db->query($sqlDrop)) {
2778 print $langs->trans(
'AlreadyDone').
"<br>\n";
2798 print
'<tr><td colspan="4">';
2801 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2805 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2810 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2811 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2813 $resql = $db->query($sqlSelect);
2816 $num = $db->num_rows($resql);
2820 $obj = $db->fetch_object($resql);
2822 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2823 $sqlInsert .=
"fk_source";
2824 $sqlInsert .=
", sourcetype";
2825 $sqlInsert .=
", fk_target";
2826 $sqlInsert .=
", targettype";
2827 $sqlInsert .=
") VALUES (";
2828 $sqlInsert .= $obj->$fk_source;
2829 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2830 $sqlInsert .=
", ".$obj->$fk_target;
2831 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2834 $result = $db->query($sqlInsert);
2843 print $langs->trans(
'AlreadyDone').
"<br>\n";
2847 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2848 if ($db->query($sqlDrop)) {
2861 print $langs->trans(
'AlreadyDone').
"<br>\n";
2879 print
'<tr><td colspan="4">';
2882 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2888 $sql =
"SELECT rowid, fk_element, element_duration";
2889 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2890 $resql = $db->query($sql);
2893 $num = $db->num_rows($resql);
2896 $totaltime = array();
2900 $obj = $db->fetch_object($resql);
2902 if ($obj->element_duration > 0) {
2905 list($hour, $min) = explode(
'.', $obj->element_duration);
2906 $hour = $hour * 60 * 60;
2907 $min = ($min / 100) * 60 * 60;
2908 $newtime = $hour + $min;
2910 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2911 $sql2 .=
" element_duration = ".((int) $newtime);
2912 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2914 $resql2 = $db->query($sql2);
2921 if (!empty($totaltime[$obj->fk_element])) {
2922 $totaltime[$obj->fk_element] += $newtime;
2924 $totaltime[$obj->fk_element] = $newtime;
2927 if (!empty($totaltime[$obj->fk_element])) {
2928 $totaltime[$obj->fk_element] += $obj->element_duration;
2930 $totaltime[$obj->fk_element] = $obj->element_duration;
2939 foreach ($totaltime as $taskid => $total_duration) {
2940 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2941 $sql .=
" duration_effective = ".((int) $total_duration);
2942 $sql .=
" WHERE rowid = ".((int) $taskid);
2944 $resql = $db->query($sql);
2951 print $langs->trans(
'AlreadyDone').
"<br>\n";
2957 print $langs->trans(
'AlreadyDone').
"<br>\n";
2982 print
'<tr><td colspan="4">';
2985 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
2989 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
2990 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
2991 $obj1 = $db->fetch_object($result1);
2992 $obj2 = $db->fetch_object($result2);
2993 if (!$obj1 && !$obj2) {
2998 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
2999 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3001 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3002 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3003 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3004 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3005 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3006 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3007 $sqlSelect .=
" AND el.targettype = 'shipping'";
3009 $resql = $db->query($sqlSelect);
3012 $num = $db->num_rows($resql);
3016 $obj = $db->fetch_object($resql);
3018 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3019 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3020 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3021 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3023 $result = $db->query($sqlUpdate);
3032 print $langs->trans(
'AlreadyDone').
"<br>\n";
3050 print $langs->trans(
'AlreadyDone').
"<br>\n";
3066 print
'<tr><td colspan="4">';
3069 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3073 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3074 $obj = $db->fetch_object($result);
3080 $sqlSelect =
"SELECT rowid, fk_expedition";
3081 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3082 $sqlSelect .=
" WHERE fk_expedition is not null";
3084 $resql = $db->query($sqlSelect);
3087 $num = $db->num_rows($resql);
3091 $obj = $db->fetch_object($resql);
3093 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3094 $sqlInsert .=
"fk_source";
3095 $sqlInsert .=
", sourcetype";
3096 $sqlInsert .=
", fk_target";
3097 $sqlInsert .=
", targettype";
3098 $sqlInsert .=
") VALUES (";
3099 $sqlInsert .= $obj->fk_expedition;
3100 $sqlInsert .=
", 'shipping'";
3101 $sqlInsert .=
", ".$obj->rowid;
3102 $sqlInsert .=
", 'delivery'";
3105 $result = $db->query($sqlInsert);
3107 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3108 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3110 $result = $db->query($sqlUpdate);
3123 print $langs->trans(
'AlreadyDone').
"<br>\n";
3127 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3128 $db->query($sqlDelete);
3133 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3134 $db->query($sqlDrop);
3144 print $langs->trans(
'AlreadyDone').
"<br>\n";
3161 print
'<tr><td colspan="4">';
3164 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3172 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3173 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3174 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3175 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3176 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3177 $sqlSelect .=
" AND el.targettype = 'delivery'";
3178 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3179 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3181 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3182 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3184 $resql = $db->query($sqlSelect);
3187 $num = $db->num_rows($resql);
3191 $obj = $db->fetch_object($resql);
3193 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3194 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3195 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3196 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3198 $result = $db->query($sqlUpdate);
3207 print $langs->trans(
'AlreadyDone').
"<br>\n";
3234 print
'<tr><td colspan="4">';
3237 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3240 'propal' =>
'propalrowid',
3241 'order' =>
'fk_commande',
3242 'invoice' =>
'fk_facture',
3243 'contract' =>
'fk_contract',
3244 'order_supplier' =>
'fk_supplier_order',
3245 'invoice_supplier' =>
'fk_supplier_invoice'
3248 foreach ($elements as $type => $field) {
3249 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3250 $obj = $db->fetch_object($result);
3256 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3257 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3258 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3259 $sql .=
" AND fk_element IS NULL";
3260 $sql .=
" AND elementtype IS NULL";
3262 $resql = $db->query($sql);
3276 print $langs->trans(
'AlreadyDone').
"<br>\n";
3293 print
'<tr><td colspan="4">';
3296 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3299 'old_id' => array(5, 8, 9, 10, 11),
3300 'new_id' => array(50, 51, 52, 53, 54),
3301 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3302 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3306 foreach ($elements[
'old_id'] as $key => $old_id) {
3311 $sqlSelect =
"SELECT id";
3312 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3313 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3314 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3316 $resql = $db->query($sqlSelect);
3318 $num = $db->num_rows($resql);
3324 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3325 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3326 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3327 $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]).
"')";
3328 $resqla = $db->query($sqla);
3330 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3331 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3332 $sql .=
" WHERE id = ".((int) $old_id);
3333 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3334 $resql = $db->query($sql);
3336 if ($resqla && $resql) {
3337 foreach ($elements[
'tables'] as $table) {
3338 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3339 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3340 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3342 $resql = $db->query($sql);
3365 print $langs->trans(
'AlreadyDone').
"<br>\n";
3383 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3385 $obj = $db->fetch_object($result);
3388 $children = array();
3389 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3392 $resql = $db->query($sql);
3394 $num = $db->num_rows($resql);
3395 while ($obj = $db->fetch_object($resql)) {
3396 if (!isset($children[$obj->fk_categorie_fille])) {
3397 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3398 $children[$obj->fk_categorie_fille] = 1;
3399 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3407 if (count($couples) > 0 && $num > count($couples)) {
3413 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3415 $resqld = $db->query($sql);
3418 foreach ($couples as $key => $val) {
3419 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3420 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3422 $resqli = $db->query($sql);
3430 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3431 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3434 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3435 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3440 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3441 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3458 print
'<tr><td colspan="4">';
3461 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3465 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3470 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3471 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3473 $resql = $db->query($sqlSelect);
3476 $num = $db->num_rows($resql);
3480 $obj = $db->fetch_object($resql);
3482 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3483 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3484 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3486 $result = $db->query($sqlUpdate);
3495 print $langs->trans(
'AlreadyDone').
"<br>\n";
3508 print $langs->trans(
'AlreadyDone').
"<br>\n";
3524 print
'<tr><td colspan="4">';
3527 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3535 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3536 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3537 $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";
3538 $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')";
3539 $sqlSelect .=
" ORDER BY a.id";
3542 $resql = $db->query($sqlSelect);
3545 $num = $db->num_rows($resql);
3549 $obj = $db->fetch_object($resql);
3551 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3552 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3554 $result = $db->query($sqlUpdate);
3563 print $langs->trans(
'AlreadyDone').
"<br>\n";
3590 print
'<tr><td colspan="4">';
3593 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3601 $sqlSelect =
"SELECT a.id, a.fk_contact";
3602 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3603 $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";
3604 $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')";
3605 $sqlSelect .=
" ORDER BY a.id";
3608 $resql = $db->query($sqlSelect);
3611 $num = $db->num_rows($resql);
3615 $obj = $db->fetch_object($resql);
3617 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3618 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3620 $result = $db->query($sqlUpdate);
3629 print $langs->trans(
'AlreadyDone').
"<br>\n";
3659 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3661 print
'<tr><td colspan="4">';
3664 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3672 $sqlSelect =
"SELECT DISTINCT entity";
3673 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3677 $resql = $db->query($sqlSelect);
3680 $num = $db->num_rows($resql);
3684 $obj = $db->fetch_object($resql);
3686 print
'Process entity '.$obj->entity;
3688 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3689 $resqlSearch = $db->query($sqlSearch);
3691 $objSearch = $db->fetch_object($resqlSearch);
3693 if ($objSearch && $objSearch->nb == 0) {
3694 print
' - Record for entity must be reset...';
3696 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3697 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3698 $resqlUpdate = $db->query($sqlUpdate);
3699 if (!$resqlUpdate) {
3708 $object->entity = $obj->entity;
3712 $b->setObjectData(
$object,
'MODULE_SET', 0);
3714 $res = $b->create($user);
3720 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3729 print $langs->trans(
'NothingToDo').
"<br>\n";
3756 print
'<tr><td colspan="4">';
3759 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3767 $sqlSelect =
"SELECT sr.rowid, s.entity";
3768 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3769 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3773 $resql = $db->query($sqlSelect);
3776 $num = $db->num_rows($resql);
3780 $obj = $db->fetch_object($resql);
3782 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3783 $sqlUpdate .=
" entity = ".$obj->entity;
3784 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3786 $result = $db->query($sqlUpdate);
3796 print $langs->trans(
'AlreadyDone').
"<br>\n";
3822 print
'<tr><td colspan="4">';
3825 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3833 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3834 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3837 $resql = $db->query($sqlSelect);
3840 $num = $db->num_rows($resql);
3844 $obj = $db->fetch_object($resql);
3846 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3847 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3849 $sqlSelect2 =
"SELECT f.entity";
3850 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3851 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3852 } elseif (!empty($obj->fk_facture_line)) {
3853 $sqlSelect2 =
"SELECT f.entity";
3854 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3855 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3856 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3858 $sqlSelect2 =
"SELECT s.entity";
3859 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3860 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3863 $resql2 = $db->query($sqlSelect2);
3865 if ($db->num_rows($resql2) > 0) {
3866 $obj2 = $db->fetch_object($resql2);
3868 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3869 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3870 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3872 $result = $db->query($sqlUpdate);
3887 print $langs->trans(
'AlreadyDone').
"<br>\n";
3914 print
'<tr><td colspan="4">';
3916 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3924 $sqlSelect =
"SELECT u.rowid, u.entity";
3925 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3926 $sqlSelect .=
" WHERE u.entity > 1";
3929 $resql = $db->query($sqlSelect);
3932 $num = $db->num_rows($resql);
3936 $obj = $db->fetch_object($resql);
3938 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3939 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3940 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3942 $result = $db->query($sqlUpdate);
3952 print $langs->trans(
'AlreadyDone').
"<br>\n";
3979 print
'<tr><td colspan="4">';
3981 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
3989 $sqlSelect =
"SELECT u.rowid, u.entity";
3990 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
3991 $sqlSelect .=
" WHERE u.entity > 1";
3994 $resql = $db->query($sqlSelect);
3997 $num = $db->num_rows($resql);
4001 $obj = $db->fetch_object($resql);
4003 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4004 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4005 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4007 $result = $db->query($sqlUpdate);
4017 print $langs->trans(
'AlreadyDone').
"<br>\n";
4048 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4049 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4050 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4070 $filetodeletearray = array(
4071 '/core/ajax/ajaxcompanies.php',
4072 '/core/triggers/interface_demo.class.php',
4073 '/core/menus/barre_left/default.php',
4074 '/core/menus/barre_top/default.php',
4075 '/core/modules/modComptabiliteExpert.class.php',
4076 '/core/modules/modCommercial.class.php',
4077 '/core/modules/modProduit.class.php',
4078 '/core/modules/modSkype.class.php',
4079 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4080 '/core/triggers/interface_modCommande_Ecotax.class.php',
4081 '/core/triggers/interface_modCommande_fraisport.class.php',
4082 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4083 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4084 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4085 '/core/menus/smartphone/iphone.lib.php',
4086 '/core/menus/smartphone/iphone_backoffice.php',
4087 '/core/menus/smartphone/iphone_frontoffice.php',
4088 '/core/menus/standard/auguria_backoffice.php',
4089 '/core/menus/standard/auguria_frontoffice.php',
4090 '/core/menus/standard/eldy_backoffice.php',
4091 '/core/menus/standard/eldy_frontoffice.php',
4092 '/core/modules/export/export_excel.modules.php',
4093 '/core/modules/export/export_csv.modules.php',
4094 '/core/modules/export/exportcsv.modules.php',
4095 '/core/modules/export/export_excel2007new.modules.php',
4096 '/core/modules/facture/pdf_crabe.modules.php',
4097 '/core/modules/facture/pdf_oursin.modules.php',
4098 '/core/modules/mailings/contacts2.modules.php',
4099 '/core/modules/mailings/contacts3.modules.php',
4100 '/core/modules/mailings/contacts4.modules.php',
4101 '/core/modules/mailings/framboise.modules.php',
4102 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4103 '/core/modules/mailings/peche.modules.php',
4104 '/core/modules/mailings/poire.modules.php',
4105 '/core/modules/mailings/kiwi.modules.php',
4106 '/core/boxes/box_members.php',
4108 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4109 '/includes/nusoap/lib/class.*',
4110 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4111 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4113 '/api/class/api_generic.class.php',
4114 '/asterisk/cidlookup.php',
4115 '/categories/class/api_category.class.php',
4116 '/categories/class/api_deprecated_category.class.php',
4117 '/compta/facture/class/api_invoice.class.php',
4118 '/commande/class/api_commande.class.php',
4119 '/partnership/class/api_partnership.class.php',
4120 '/product/class/api_product.class.php',
4121 '/recruitment/class/api_recruitment.class.php',
4122 '/societe/class/api_contact.class.php',
4123 '/societe/class/api_thirdparty.class.php',
4124 '/support/online.php',
4125 '/takepos/class/actions_takepos.class.php',
4126 '/user/class/api_user.class.php',
4128 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4129 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4130 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4131 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4132 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4133 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4142 foreach ($filetodeletearray as $filetodelete) {
4144 if (preg_match(
'/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4146 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match(
'/\*/', $filetodelete) ? 1 : 0), 0,
null,
true,
false);
4148 $langs->load(
"errors");
4149 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4150 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4175 $filetodeletearray = array(
4176 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4177 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4181 if (!empty($_SERVER[
"WINDIR"])) {
4182 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4185 foreach ($filetodeletearray as $filetodelete) {
4187 if (file_exists($filetodelete)) {
4191 $langs->load(
"errors");
4192 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4193 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4217 if (count($listofmodule) == 0) {
4221 if (!is_object($user)) {
4222 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4223 $user =
new User($db);
4226 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)));
4228 $reloadactionformodules = array(
4229 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4230 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4231 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4232 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4233 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4234 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove' => 1),
4235 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4236 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4237 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4238 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4239 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4240 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4241 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4242 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4243 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4244 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4245 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4246 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4247 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4248 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4249 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4250 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove' => 1),
4251 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4252 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4253 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4254 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4255 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4256 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4257 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4260 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4261 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4267 if (!empty($reloadactionformodules[$moduletoreload])) {
4268 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4270 $val = $reloadactionformodules[$moduletoreload];
4271 $classformodule = $val[
'class'];
4272 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4274 $mod =
new $classformodule($db);
4275 if (!empty($val[
'remove'])) {
4276 $mod->remove(
'noboxes');
4278 if (!empty($val[
'deleteinsertmenus'])) {
4280 $mod->delete_menus();
4281 $mod->insert_menus();
4283 $mod->init($reloadmode);
4288 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4289 if (!empty($reg[1])) {
4290 if (strtoupper($moduletoreload) == $moduletoreload) {
4291 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4293 $moduletoreloadshort = $reg[1];
4296 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4298 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4300 $classname =
'mod'.$moduletoreloadshort;
4301 $mod =
new $classname($db);
4304 $mod->delete_menus();
4305 $mod->init($reloadmode);
4307 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4309 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4311 $classname =
'mod'.$moduletoreloadshort;
4312 $mod =
new $classname($db);
4313 $mod->init($reloadmode);
4315 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4316 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4322 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4327 if (!empty($mod) && is_object($mod)) {
4328 print
'<tr class="trforrunsql"><td colspan="4">';
4329 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4330 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4331 print
"<!-- (".$reloadmode.
") -->";
4356 $listofmenuhandler = array();
4359 $listofmenuhandler[
'auguria'] = 1;
4362 foreach ($listofmenuhandler as $key => $val) {
4363 print
'<tr class="trforrunsql"><td colspan="4">';
4367 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4370 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4371 $file =
'init_menu_'.$key.
'.sql';
4372 if (file_exists($dir.$file)) {
4373 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4389 global $conf, $db, $langs, $user;
4391 print
'<tr><td colspan="4">';
4393 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4395 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4396 $fuser =
new User($db);
4397 if (!is_object($user)) {
4401 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4402 $resql = $db->query($sql);
4404 while ($obj = $db->fetch_object($resql)) {
4406 $fuser->id = $obj->uid;
4407 $fuser->entity = $obj->entity;
4410 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4412 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4414 $dir = $conf->user->multidir_output[$entity];
4419 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4420 $destin = $dir.
'/'.$fuser->id;
4428 $handle = opendir($origin_osencoded);
4429 if (is_resource($handle)) {
4430 while (($file = readdir($handle)) !==
false) {
4431 if ($file ==
'.' || $file ==
'..') {
4436 $thumbs = opendir($origin_osencoded.
'/'.$file);
4437 if (is_resource($thumbs)) {
4439 while (($thumb = readdir($thumbs)) !==
false) {
4441 if ($thumb ==
'.' || $thumb ==
'..') {
4447 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4457 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4478 global $db, $langs, $user;
4480 print
'<tr><td colspan="4">';
4482 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4484 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4485 $fuser =
new User($db);
4486 if (!is_object($user)) {
4490 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4491 $resql = $db->query($sql);
4493 while ($obj = $db->fetch_object($resql)) {
4495 $fuser->id = $obj->uid;
4496 $fuser->entity = $obj->entity;
4497 $fuser->photo = $obj->photo;
4500 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4502 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4504 $dir = DOL_DATA_ROOT.
'/users';
4509 $origin = $dir.
'/'.$fuser->id;
4510 $destin = $dir.
'/'.$fuser->id.
'/photos';
4518 $handle = opendir($origin_osencoded);
4519 if (is_resource($handle)) {
4520 while (($file = readdir($handle)) !==
false) {
4521 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4524 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4529 $thumbs = opendir($origin_osencoded.
'/'.$file);
4530 if (is_resource($thumbs)) {
4532 while (($thumb = readdir($thumbs)) !==
false) {
4534 if ($thumb ==
'.' || $thumb ==
'..') {
4540 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4549 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4586 print
'<tr><td colspan="4">';
4587 $sql =
'SELECT rowid, socialnetworks';
4588 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4589 $sql .=
" skype IS NOT NULL OR skype <> ''";
4590 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4591 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4592 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4593 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4594 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4595 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4596 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4597 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4599 $resql = $db->query($sql);
4601 while ($obj = $db->fetch_object($resql)) {
4602 $arraysocialnetworks = array();
4603 if (!empty($obj->skype)) {
4604 $arraysocialnetworks[
'skype'] = $obj->skype;
4606 if (!empty($obj->twitter)) {
4607 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4609 if (!empty($obj->facebook)) {
4610 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4612 if (!empty($obj->linkedin)) {
4613 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4615 if (!empty($obj->instagram)) {
4616 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4618 if (!empty($obj->snapchat)) {
4619 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4621 if (!empty($obj->googleplus)) {
4622 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4624 if (!empty($obj->youtube)) {
4625 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4627 if (!empty($obj->whatsapp)) {
4628 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4630 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4631 $obj->socialnetworks =
'[]';
4633 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4634 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4635 $sqlupd .=
', skype=null';
4636 $sqlupd .=
', twitter=null';
4637 $sqlupd .=
', facebook=null';
4638 $sqlupd .=
', linkedin=null';
4639 $sqlupd .=
', instagram=null';
4640 $sqlupd .=
', snapchat=null';
4641 $sqlupd .=
', googleplus=null';
4642 $sqlupd .=
', youtube=null';
4643 $sqlupd .=
', whatsapp=null';
4644 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4646 $resqlupd = $db->query($sqlupd);
4661 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4675 print
'<tr><td colspan="4">';
4678 print
'<tr><td colspan="4">';
4679 $sql =
'SELECT rowid, socialnetworks';
4680 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4681 $sql .=
" skype IS NOT NULL OR skype <> ''";
4682 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4683 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4684 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4685 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4686 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4687 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4688 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4689 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4691 $resql = $db->query($sql);
4693 while ($obj = $db->fetch_object($resql)) {
4694 $arraysocialnetworks = array();
4695 if (!empty($obj->skype)) {
4696 $arraysocialnetworks[
'skype'] = $obj->skype;
4698 if (!empty($obj->twitter)) {
4699 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4701 if (!empty($obj->facebook)) {
4702 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4704 if (!empty($obj->linkedin)) {
4705 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4707 if (!empty($obj->instagram)) {
4708 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4710 if (!empty($obj->snapchat)) {
4711 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4713 if (!empty($obj->googleplus)) {
4714 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4716 if (!empty($obj->youtube)) {
4717 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4719 if (!empty($obj->whatsapp)) {
4720 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4722 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4723 $obj->socialnetworks =
'[]';
4725 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4726 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4727 $sqlupd .=
', skype=null';
4728 $sqlupd .=
', twitter=null';
4729 $sqlupd .=
', facebook=null';
4730 $sqlupd .=
', linkedin=null';
4731 $sqlupd .=
', instagram=null';
4732 $sqlupd .=
', snapchat=null';
4733 $sqlupd .=
', googleplus=null';
4734 $sqlupd .=
', youtube=null';
4735 $sqlupd .=
', whatsapp=null';
4736 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4738 $resqlupd = $db->query($sqlupd);
4753 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4769 print
'<tr><td colspan="4">';
4770 $sql =
'SELECT rowid, socialnetworks';
4771 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4772 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4773 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4774 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4775 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4776 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4777 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4778 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4779 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4780 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4781 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4783 $resql = $db->query($sql);
4785 while ($obj = $db->fetch_object($resql)) {
4786 $arraysocialnetworks = array();
4787 if (!empty($obj->jabberid)) {
4788 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4790 if (!empty($obj->skype)) {
4791 $arraysocialnetworks[
'skype'] = $obj->skype;
4793 if (!empty($obj->twitter)) {
4794 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4796 if (!empty($obj->facebook)) {
4797 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4799 if (!empty($obj->linkedin)) {
4800 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4802 if (!empty($obj->instagram)) {
4803 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4805 if (!empty($obj->snapchat)) {
4806 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4808 if (!empty($obj->googleplus)) {
4809 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4811 if (!empty($obj->youtube)) {
4812 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4814 if (!empty($obj->whatsapp)) {
4815 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4817 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4818 $obj->socialnetworks =
'[]';
4820 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4821 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4822 $sqlupd .=
', jabberid=null';
4823 $sqlupd .=
', skype=null';
4824 $sqlupd .=
', twitter=null';
4825 $sqlupd .=
', facebook=null';
4826 $sqlupd .=
', linkedin=null';
4827 $sqlupd .=
', instagram=null';
4828 $sqlupd .=
', snapchat=null';
4829 $sqlupd .=
', googleplus=null';
4830 $sqlupd .=
', youtube=null';
4831 $sqlupd .=
', whatsapp=null';
4832 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4834 $resqlupd = $db->query($sqlupd);
4849 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4865 print
'<tr><td colspan="4">';
4866 $sql =
'SELECT rowid, socialnetworks';
4867 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4868 $sql .=
" skype IS NOT NULL OR skype <> ''";
4869 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4870 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4871 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4872 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4873 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4874 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4875 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4876 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4878 $resql = $db->query($sql);
4880 while ($obj = $db->fetch_object($resql)) {
4881 $arraysocialnetworks = array();
4882 if (!empty($obj->skype)) {
4883 $arraysocialnetworks[
'skype'] = $obj->skype;
4885 if (!empty($obj->twitter)) {
4886 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4888 if (!empty($obj->facebook)) {
4889 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4891 if (!empty($obj->linkedin)) {
4892 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4894 if (!empty($obj->instagram)) {
4895 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4897 if (!empty($obj->snapchat)) {
4898 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4900 if (!empty($obj->googleplus)) {
4901 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4903 if (!empty($obj->youtube)) {
4904 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4906 if (!empty($obj->whatsapp)) {
4907 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4909 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4910 $obj->socialnetworks =
'[]';
4912 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4913 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4914 $sqlupd .=
', skype=null';
4915 $sqlupd .=
', twitter=null';
4916 $sqlupd .=
', facebook=null';
4917 $sqlupd .=
', linkedin=null';
4918 $sqlupd .=
', instagram=null';
4919 $sqlupd .=
', snapchat=null';
4920 $sqlupd .=
', googleplus=null';
4921 $sqlupd .=
', youtube=null';
4922 $sqlupd .=
', whatsapp=null';
4923 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4925 $resqlupd = $db->query($sqlupd);
4940 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
4960 print
'<tr class="trforrunsql"><td colspan="4">';
4961 $sql =
'SELECT rowid, field';
4962 if ($mode ==
'export') {
4965 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
4966 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
4968 $resql = $db->query($sql);
4970 while ($obj = $db->fetch_object($resql)) {
4971 $oldfield = $obj->field;
4972 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
4974 if ($mode ==
'export') {
4975 $oldfilter = $obj->filter;
4976 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
4982 if ($oldfield != $newfield || $oldfilter != $newfilter) {
4983 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
4984 if ($mode ==
'export') {
4985 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
4987 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4988 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
4989 $resqlupd = $db->query($sqlupd);
5005 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5008 if ($resultstring) {
5009 print $resultstring;
5011 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5028 print
'<tr class="trforrunsql"><td colspan="4">';
5029 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5031 $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";
5032 $sql .=
" ORDER BY c.rowid,cd.rowid";
5034 $resql = $db->query($sql);
5037 $current_contract = 0;
5038 while ($obj = $db->fetch_object($resql)) {
5039 if (empty($current_contract) || $current_contract == $obj->cid) {
5045 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5046 $resultstring =
'.';
5047 print $resultstring;
5048 $resqlUpd = $db->query($sqlUpd);
5054 $current_contract = $obj->cid;
5067 if (!$resultstring) {
5068 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5083 $firstInstallVersion =
getDolGlobalString(
'MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5084 $migrationNeeded = (
versioncompare(explode(
'.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5086 print
'<tr class="trforrunsql"><td colspan="4">';
5087 print
'<b>'.$langs->trans(
'InvoiceExportModelsMigration').
"</b>: \n";
5089 if (! $migrationNeeded) {
5090 print $langs->trans(
"AlreadyDone");
5092 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
5099 $sql1 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5101 $resql1 = $db->query($sql1);
5110 $modified1 = $db->affected_rows($resql1);
5112 print str_repeat(
'.', $modified1);
5116 $sql2 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5118 $resql2 = $db->query($sql2);
5127 $modified2 = $db->affected_rows($resql2);
5129 print str_repeat(
'.', $modified2);
5133 if (empty($modified1 + $modified2)) {
5134 print $langs->trans(
'NothingToDo');
5139 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
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.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Class to manage Blocked Log.
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/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 lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
if($db->connected) if( $ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondence des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_invoice_export_models()
Invoice exports been shifted (facture_1 => facture_0, facture_2 => facture_1) in version 20,...
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.