42define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
43include_once
'inc.php';
44if (!file_exists($conffile)) {
45 print
'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
47require_once $conffile;
48require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
49require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
50require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
51require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
52require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
53require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
54require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
55require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
66$err = error_reporting();
69 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
75$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
76$langs->setDefaultLang($setuplang);
77$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
78$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
79$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
81$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
83if ($dolibarr_main_db_type ==
'mysqli') {
86if ($dolibarr_main_db_type ==
'pgsql') {
89if ($dolibarr_main_db_type ==
'mssql') {
94dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
95if (!is_object($conf)) {
105if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
106 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
107 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
109 $sapi_type = php_sapi_name();
110 $script_file = basename(__FILE__);
112 if (substr($sapi_type, 0, 3) ==
'cli') {
113 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
118pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
121if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
122 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
123 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
125 print
'<table border="0" width="100%">';
128 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
129 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
130 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
131 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
132 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
133 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
135 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
140 $conf->db->type = $dolibarr_main_db_type;
141 $conf->db->host = $dolibarr_main_db_host;
142 $conf->db->port = $dolibarr_main_db_port;
143 $conf->db->name = $dolibarr_main_db_name;
144 $conf->db->user = $dolibarr_main_db_user;
145 $conf->db->pass = $dolibarr_main_db_pass;
147 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
149 if (!$db->connected) {
150 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
151 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
156 if ($db->database_selected) {
163 if (empty($dolibarr_main_db_encryption)) {
164 $dolibarr_main_db_encryption = 0;
166 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
167 if (empty($dolibarr_main_db_cryptkey)) {
168 $dolibarr_main_db_cryptkey =
'';
170 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
173 $conf->setValues($db);
176 $listofentities = array(1);
179 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
181 $hookmanager->initHooks(array(
'upgrade2'));
183 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
186 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters, $object, $action);
187 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
189 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
200 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
202 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
204 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
206 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
208 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
210 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
212 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
214 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
216 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
218 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
220 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
226 foreach ($listofentities as $entity) {
228 $conf->setEntityValues($db, $entity);
230 if (defined(
'SYSLOG_FILE')) {
231 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
233 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
236 if (count($listofentities) > 1) {
237 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
242 $dolibarrlastupgradeversionarray = preg_split(
'/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL :
''));
248 $versiontoarray = explode(
'.', $versionto);
249 $versionranarray = explode(
'.', DOL_VERSION);
252 $afterversionarray = explode(
'.',
'2.0.0');
253 $beforeversionarray = explode(
'.',
'2.7.9');
314 $afterversionarray = explode(
'.',
'2.7.9');
315 $beforeversionarray = explode(
'.',
'2.8.9');
340 $afterversionarray = explode(
'.',
'2.8.9');
341 $beforeversionarray = explode(
'.',
'2.9.9');
353 $afterversionarray = explode(
'.',
'2.9.9');
354 $beforeversionarray = explode(
'.',
'3.0.9');
360 $afterversionarray = explode(
'.',
'3.0.9');
361 $beforeversionarray = explode(
'.',
'3.1.9');
369 $afterversionarray = explode(
'.',
'3.1.9');
370 $beforeversionarray = explode(
'.',
'3.2.9');
380 $afterversionarray = explode(
'.',
'3.2.9');
381 $beforeversionarray = explode(
'.',
'3.3.9');
390 $afterversionarray = explode(
'.',
'3.6.9');
391 $beforeversionarray = explode(
'.',
'3.7.9');
397 $afterversionarray = explode(
'.',
'3.7.9');
398 $beforeversionarray = explode(
'.',
'3.8.9');
404 $afterversionarray = explode(
'.',
'3.9.9');
405 $beforeversionarray = explode(
'.',
'4.0.9');
411 $afterversionarray = explode(
'.',
'4.0.9');
412 $beforeversionarray = explode(
'.',
'5.0.9');
422 $afterversionarray = explode(
'.',
'5.0.9');
423 $beforeversionarray = explode(
'.',
'6.0.9');
425 if (isModEnabled(
'multicompany')) {
426 global $multicompany_transverse_mode;
429 if (empty($multicompany_transverse_mode)) {
440 $afterversionarray = explode(
'.',
'6.0.9');
441 $beforeversionarray = explode(
'.',
'7.0.9');
450 $afterversionarray = explode(
'.',
'7.0.9');
451 $beforeversionarray = explode(
'.',
'8.0.9');
457 $afterversionarray = explode(
'.',
'8.0.9');
458 $beforeversionarray = explode(
'.',
'9.0.9');
464 $afterversionarray = explode(
'.',
'10.0.9');
465 $beforeversionarray = explode(
'.',
'11.0.9');
474 $afterversionarray = explode(
'.',
'13.0.9');
475 $beforeversionarray = explode(
'.',
'14.0.9');
482 $afterversionarray = explode(
'.',
'15.0.9');
483 $beforeversionarray = explode(
'.',
'16.0.9');
490 $afterversionarray = explode(
'.',
'16.0.9');
491 $beforeversionarray = explode(
'.',
'17.0.9');
497 $afterversionarray = explode(
'.',
'17.0.9');
498 $beforeversionarray = explode(
'.',
'18.0.9');
517 $listofmodule = array(
518 'MAIN_MODULE_ACCOUNTING'=>
'newboxdefonly',
519 'MAIN_MODULE_AGENDA'=>
'newboxdefonly',
520 'MAIN_MODULE_BOM'=>
'menuonly',
521 'MAIN_MODULE_BANQUE'=>
'menuonly',
522 'MAIN_MODULE_BARCODE'=>
'newboxdefonly',
523 'MAIN_MODULE_CRON'=>
'newboxdefonly',
524 'MAIN_MODULE_COMMANDE'=>
'newboxdefonly',
525 'MAIN_MODULE_BLOCKEDLOG'=>
'noboxes',
526 'MAIN_MODULE_DEPLACEMENT'=>
'newboxdefonly',
527 'MAIN_MODULE_DON'=>
'newboxdefonly',
528 'MAIN_MODULE_ECM'=>
'newboxdefonly',
529 'MAIN_MODULE_EXTERNALSITE'=>
'newboxdefonly',
530 'MAIN_MODULE_EXPENSEREPORT'=>
'newboxdefonly',
531 'MAIN_MODULE_FACTURE'=>
'newboxdefonly',
532 'MAIN_MODULE_FOURNISSEUR'=>
'newboxdefonly',
533 'MAIN_MODULE_FICHEINTER'=>
'newboxdefonly',
534 'MAIN_MODULE_HOLIDAY'=>
'newboxdefonly',
535 'MAIN_MODULE_MARGIN'=>
'menuonly',
536 'MAIN_MODULE_MRP'=>
'menuonly',
537 'MAIN_MODULE_OPENSURVEY'=>
'newboxdefonly',
538 'MAIN_MODULE_PAYBOX'=>
'newboxdefonly',
539 'MAIN_MODULE_PRINTING'=>
'newboxdefonly',
540 'MAIN_MODULE_PRODUIT'=>
'newboxdefonly',
541 'MAIN_MODULE_RECRUITMENT'=>
'menuonly',
542 'MAIN_MODULE_RESOURCE'=>
'noboxes',
543 'MAIN_MODULE_SALARIES'=>
'newboxdefonly',
544 'MAIN_MODULE_SERVICE'=>
'newboxdefonly',
545 'MAIN_MODULE_SYSLOG'=>
'newboxdefonly',
546 'MAIN_MODULE_SOCIETE'=>
'newboxdefonly',
547 'MAIN_MODULE_STRIPE'=>
'menuonly',
548 'MAIN_MODULE_TICKET'=>
'newboxdefonly',
549 'MAIN_MODULE_TAKEPOS'=>
'newboxdefonly',
550 'MAIN_MODULE_USER'=>
'newboxdefonly',
551 'MAIN_MODULE_VARIANTS'=>
'newboxdefonly',
552 'MAIN_MODULE_WEBSITE'=>
'newboxdefonly',
568 if (!$error && $enablemodules) {
570 $listofmodules = array();
571 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
572 $tmplistofmodules = explode(
',', $enablemodules);
573 foreach ($tmplistofmodules as $value) {
574 $listofmodules[$value] =
'forceactivate';
578 if ($resultreloadmodules < 0) {
586 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
589 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters, $object, $action);
590 if ($hookmanager->resNbOfHooks > 0) {
592 print
'<tr><td colspan="4">';
593 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
594 print $hookmanager->error;
595 print
"<!-- (".$reshook.
") -->";
598 print
'<tr class="trforrunsql"><td colspan="4">';
599 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
600 print
"<!-- (".$reshook.
") -->";
605 if (!empty($conf->modules_parts[
'hooks'])) {
606 print
'<tr class="trforrunsql"><td colspan="4">';
607 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
618 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
633 foreach ($listofentities as $entity) {
635 $conf->setEntityValues($db, $entity);
637 if (defined(
'SYSLOG_FILE')) {
638 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
640 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
644 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
645 $destroot = DOL_DATA_ROOT.
'/medias';
658 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf'=>$conf);
661 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters, $object, $action);
662 if ($hookmanager->resNbOfHooks > 0) {
664 print
'<tr><td colspan="4">';
665 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
666 print $hookmanager->error;
667 print
"<!-- (".$reshook.
") -->";
670 print
'<tr class="trforrunsql"><td colspan="4">';
671 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
672 print
"<!-- (".$reshook.
") -->";
677 if (!empty($conf->modules_parts[
'hooks'])) {
678 print
'<tr class="trforrunsql"><td colspan="4">';
679 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
689 print
'<table width="100%">';
690 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
691 print
'<td class="right">';
695 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
699 print
'<script type="text/javascript">
700 jQuery(document).ready(function() {
701 function init_trrunsql()
703 console.log("toggle .trforrunsql");
704 jQuery(".trforrunsql").toggle();
707 jQuery(".trforrunsqlshowhide").click(function() {
712 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
715 print
'</td></tr>'.
"\n";
721 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
726if ($error && isset($argv[1])) {
732pFooter($error ? 2 : 0, $setuplang);
755 print
'<tr><td colspan="4">';
758 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
760 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
761 $obj = $db->fetch_object($result);
763 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
764 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
765 $sql .=
" WHERE p.fk_facture > 0";
767 $resql = $db->query($sql);
773 $num = $db->num_rows($resql);
776 $obj = $db->fetch_object($resql);
777 $row[$i][0] = $obj->rowid;
778 $row[$i][1] = $obj->fk_facture;
779 $row[$i][2] = $obj->amount;
787 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
791 for ($i = 0; $i < $num; $i++) {
792 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
793 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
795 $res += $db->query($sql);
797 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
799 $res += $db->query($sql);
801 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
805 if ($res == (2 * count($row))) {
807 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
810 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
813 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
816 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
834 print
'<tr><td colspan="4">';
837 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
839 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
840 $obj = $db->fetch_object($result);
843 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
844 $sql .=
" bu2.url_id as socid";
845 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
846 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
847 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
848 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
849 $sql .=
" AND b.rappro = 1";
850 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
852 $resql = $db->query($sql);
858 $num = $db->num_rows($resql);
861 $obj = $db->fetch_object($resql);
862 if ($obj->pamount == $obj->bamount && $obj->socid) {
863 $row[$j][
'paymentid'] = $obj->rowid;
864 $row[$j][
'pamount'] = $obj->pamount;
865 $row[$j][
'fk_bank'] = $obj->fk_bank;
866 $row[$j][
'bamount'] = $obj->bamount;
867 $row[$j][
'socid'] = $obj->socid;
868 $row[$j][
'datec'] = $obj->datec;
878 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
883 for ($i = 0; $i < $num; $i++) {
885 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>';
889 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
890 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
891 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
892 $sql .=
" AND pf.fk_facture IS NULL";
893 $sql .=
" ORDER BY f.fk_statut";
895 $resql = $db->query($sql);
897 $num = $db->num_rows($resql);
900 $obj = $db->fetch_object($resql);
901 $facid = $obj->rowid;
903 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
904 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
906 $res += $db->query($sql);
908 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
916 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
918 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
923 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
926 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
944 print
'<tr><td colspan="4">';
947 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
949 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
950 $obj = $db->fetch_object($result);
953 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
954 $sql .=
" bu2.url_id as socid";
955 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
956 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
957 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
958 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
959 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
961 $resql = $db->query($sql);
967 $num = $db->num_rows($resql);
970 $obj = $db->fetch_object($resql);
971 if ($obj->pamount == $obj->bamount && $obj->socid) {
972 $row[$j][
'paymentid'] = $obj->rowid;
973 $row[$j][
'pamount'] = $obj->pamount;
974 $row[$j][
'fk_bank'] = $obj->fk_bank;
975 $row[$j][
'bamount'] = $obj->bamount;
976 $row[$j][
'socid'] = $obj->socid;
977 $row[$j][
'datec'] = $obj->datec;
990 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
994 for ($i = 0; $i < $num; $i++) {
996 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>';
1000 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1001 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1002 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1003 $sql .=
" AND pf.fk_facture IS NULL";
1004 $sql .=
" ORDER BY f.fk_statut";
1006 $resql = $db->query($sql);
1008 $num = $db->num_rows($resql);
1011 $obj = $db->fetch_object($resql);
1012 $facid = $obj->rowid;
1014 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1015 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1017 $res += $db->query($sql);
1019 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1028 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1030 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1035 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1041 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1051 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1068 print
'<tr><td colspan="4">';
1073 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1075 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1076 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1077 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1078 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1079 $sql .=
" ON c.fk_product = p.rowid";
1080 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1081 $sql .=
" ON c.rowid=cd.fk_contrat";
1082 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1083 $resql = $db->query($sql);
1089 $num = $db->num_rows($resql);
1092 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1096 $obj = $db->fetch_object($resql);
1098 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1099 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1100 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1101 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1102 $sql .=
" VALUES (";
1103 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1105 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1106 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1109 $sql .= ((float) $obj->tva_tx).
", 1, ";
1110 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1114 if ($db->query($sql)) {
1115 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1127 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1130 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1133 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1136 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1153 print
'<tr><td colspan="4">';
1158 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1160 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1162 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1163 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1164 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1165 $sql .=
" AND bu.fk_bank IS NULL";
1166 $resql = $db->query($sql);
1172 $num = $db->num_rows($resql);
1175 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1179 $obj = $db->fetch_object($resql);
1181 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1182 $sql .=
"fk_bank, url_id, url, label, type";
1184 $sql .=
" VALUES (";
1185 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1191 if (!$db->query($sql)) {
1202 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1205 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1208 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1227 print
'<tr><td colspan="4">';
1230 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1232 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1234 $resql = $db->query($sql);
1238 if ($db->affected_rows($resql) > 0) {
1239 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1241 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1244 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1246 $resql = $db->query($sql);
1250 if ($db->affected_rows($resql) > 0) {
1251 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1253 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1269 print
'<tr><td colspan="4">';
1274 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1276 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1278 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1279 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1280 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1281 $resql = $db->query($sql);
1287 $num = $db->num_rows($resql);
1290 $nbcontratsmodifie = 0;
1294 $obj = $db->fetch_object($resql);
1295 if ($obj->date_contrat > $obj->datemin) {
1296 $datemin = $db->jdate($obj->datemin);
1298 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1299 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1300 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1301 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1302 $resql2 = $db->query($sql);
1307 $nbcontratsmodifie++;
1314 if ($nbcontratsmodifie) {
1315 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1317 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1337 print
'<tr><td colspan="4">';
1340 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1342 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1344 $resql = $db->query($sql);
1348 if ($db->affected_rows($resql) > 0) {
1349 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1351 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1367 print
'<tr><td colspan="4">';
1370 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1372 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1373 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1375 $resql = $db->query($sql);
1379 if ($db->affected_rows($resql) > 0) {
1382 $num = $db->num_rows($resql);
1385 $nbcontratsmodifie = 0;
1389 $obj = $db->fetch_object($resql);
1391 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1392 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1393 $sql .=
" SET statut = 1";
1394 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1395 $resql2 = $db->query($sql);
1400 $nbcontratsmodifie++;
1407 if ($nbcontratsmodifie) {
1408 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1410 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1414 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1432 print
'<tr><td colspan="4">';
1434 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1437 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1438 $obj = $db->fetch_object($result);
1443 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1444 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1445 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1448 $select_resql = $db->query($select_sql);
1449 if ($select_resql) {
1450 $select_num = $db->num_rows($select_resql);
1454 while (($i < $select_num) && (!$error)) {
1455 $select_obj = $db->fetch_object($select_resql);
1458 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1459 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1460 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1461 $check_resql = $db->query($check_sql);
1463 $check_num = $db->num_rows($check_resql);
1464 if ($check_num == 0) {
1468 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1469 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1472 print
'<tr class="oddeven">';
1473 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1475 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1476 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1477 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1478 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1479 $insert_resql = $db->query($insert_sql);
1481 if ($insert_resql) {
1483 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1485 print
'<td><span class="error">Error on insert</span></td>';
1501 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1505 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1508 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1512 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1529 $tmpmysoc->setMysoc($conf);
1533 print
'<tr><td colspan="4">';
1536 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1539 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1540 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1541 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1542 $sql .=
" WHERE fd.fk_facture = f.rowid";
1543 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1547 $resql = $db->query($sql);
1549 $num = $db->num_rows($resql);
1553 $obj = $db->fetch_object($resql);
1555 $rowid = $obj->rowid;
1557 $pu = $obj->subprice;
1558 $vatrate = $obj->vatrate;
1559 $remise_percent = $obj->remise_percent;
1560 $remise_percent_global = $obj->remise_percent_global;
1561 $total_ttc_f = $obj->total_ttc_f;
1562 $info_bits = $obj->info_bits;
1566 $facligne->fetch($rowid);
1568 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1569 $total_ht = $result[0];
1570 $total_tva = $result[1];
1571 $total_ttc = $result[2];
1573 $facligne->total_ht = $total_ht;
1574 $facligne->total_tva = $total_tva;
1575 $facligne->total_ttc = $total_ttc;
1577 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);
1579 $facligne->update_total();
1583 if (!$total_ttc_f) {
1585 $facture->id = $obj->facid;
1587 if ($facture->fetch($facture->id) >= 0) {
1588 if ($facture->update_price() > 0) {
1591 print
"Error id=".$facture->id;
1604 print $langs->trans(
"AlreadyDone");
1610 print
"Error #1 ".$db->error();
1632 $tmpmysoc->setMysoc($conf);
1636 print
'<tr><td colspan="4">';
1639 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1642 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1643 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1644 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1645 $sql .=
" WHERE pd.fk_propal = p.rowid";
1646 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1649 $resql = $db->query($sql);
1651 $num = $db->num_rows($resql);
1655 $obj = $db->fetch_object($resql);
1657 $rowid = $obj->rowid;
1659 $pu = $obj->subprice;
1660 $vatrate = $obj->vatrate;
1661 $remise_percent = $obj->remise_percent;
1662 $remise_percent_global = $obj->remise_percent_global;
1663 $info_bits = $obj->info_bits;
1667 $propalligne->fetch($rowid);
1669 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1670 $total_ht = $result[0];
1671 $total_tva = $result[1];
1672 $total_ttc = $result[2];
1674 $propalligne->total_ht = $total_ht;
1675 $propalligne->total_tva = $total_tva;
1676 $propalligne->total_ttc = $total_ttc;
1678 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);
1680 $propalligne->update_total();
1705 print $langs->trans(
"AlreadyDone");
1712 print
"Error #1 ".$db->error();
1735 $tmpmysoc->setMysoc($conf);
1736 if (empty($tmpmysoc->country_id)) {
1737 $tmpmysoc->country_id = 0;
1740 print
'<tr><td colspan="4">';
1743 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1746 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1747 $sql .=
" c.rowid as contratid";
1748 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1749 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1750 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1753 $resql = $db->query($sql);
1755 $num = $db->num_rows($resql);
1759 $obj = $db->fetch_object($resql);
1761 $rowid = $obj->rowid;
1763 $pu = $obj->subprice;
1764 $vatrate = $obj->vatrate;
1765 $remise_percent = $obj->remise_percent;
1766 $info_bits = $obj->info_bits;
1771 $contratligne->fetch($rowid);
1773 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1774 $total_ht = $result[0];
1775 $total_tva = $result[1];
1776 $total_ttc = $result[2];
1778 $contratligne->total_ht = $total_ht;
1779 $contratligne->total_tva = $total_tva;
1780 $contratligne->total_ttc = $total_ttc;
1782 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);
1784 $contratligne->update_total();
1789 print $langs->trans(
"AlreadyDone");
1796 print
"Error #1 ".$db->error();
1819 $tmpmysoc->setMysoc($conf);
1821 print
'<tr><td colspan="4">';
1824 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1827 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1828 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1829 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1830 $sql .=
" WHERE cd.fk_commande = c.rowid";
1831 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1834 $resql = $db->query($sql);
1836 $num = $db->num_rows($resql);
1840 $obj = $db->fetch_object($resql);
1842 $rowid = $obj->rowid;
1844 $pu = $obj->subprice;
1845 $vatrate = $obj->vatrate;
1846 $remise_percent = $obj->remise_percent;
1847 $remise_percent_global = $obj->remise_percent_global;
1848 $info_bits = $obj->info_bits;
1852 $commandeligne->fetch($rowid);
1854 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1855 $total_ht = $result[0];
1856 $total_tva = $result[1];
1857 $total_ttc = $result[2];
1859 $commandeligne->total_ht = $total_ht;
1860 $commandeligne->total_tva = $total_tva;
1861 $commandeligne->total_ttc = $total_ttc;
1863 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);
1865 $commandeligne->update_total();
1889 print $langs->trans(
"AlreadyDone");
1906 print
"Error #1 ".$db->error();
1931 $tmpmysoc->setMysoc($conf);
1933 print
'<tr><td colspan="4">';
1936 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1939 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1940 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1941 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1942 $sql .=
" WHERE cd.fk_commande = c.rowid";
1943 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1946 $resql = $db->query($sql);
1948 $num = $db->num_rows($resql);
1952 $obj = $db->fetch_object($resql);
1954 $rowid = $obj->rowid;
1956 $pu = $obj->subprice;
1957 $vatrate = $obj->vatrate;
1958 $remise_percent = $obj->remise_percent;
1959 $remise_percent_global = $obj->remise_percent_global;
1960 $info_bits = $obj->info_bits;
1964 $commandeligne->fetch($rowid);
1966 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $mysoc);
1967 $total_ht = $result[0];
1968 $total_tva = $result[1];
1969 $total_ttc = $result[2];
1971 $commandeligne->total_ht = $total_ht;
1972 $commandeligne->total_tva = $total_tva;
1973 $commandeligne->total_ttc = $total_ttc;
1975 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);
1977 $commandeligne->update_total();
2001 print $langs->trans(
"AlreadyDone");
2018 print
"Error #1 ".$db->error();
2043 if (isModEnabled(
'facture')) {
2044 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2046 if (count($modellist) == 0) {
2048 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2049 $resql = $db->query($sql);
2056 if (isModEnabled(
'commande')) {
2057 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2059 if (count($modellist) == 0) {
2061 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2062 $resql = $db->query($sql);
2069 if (isModEnabled(
"expedition")) {
2070 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2072 if (count($modellist) == 0) {
2074 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2075 $resql = $db->query($sql);
2098 print
'<tr><td colspan="4">';
2101 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2103 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2104 $obj = $db->fetch_object($result);
2110 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2111 $resql = $db->query($sql);
2114 $num = $db->num_rows($resql);
2118 $obj = $db->fetch_object($resql);
2120 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2121 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2122 $resql2 = $db->query($sql);
2135 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2136 print $langs->trans(
'FieldRenamed').
"<br>\n";
2146 print $langs->trans(
'AlreadyDone').
"<br>\n";
2163 print
'<tr><td colspan="4">';
2166 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2168 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2169 $obj = $db->fetch_object($result);
2175 $sql =
"SELECT l.rowid, l.fk_commande,";
2176 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2177 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2178 $sql .=
" WHERE c.rowid = l.fk_commande";
2179 $resql = $db->query($sql);
2182 $num = $db->num_rows($resql);
2186 $obj = $db->fetch_object($resql);
2188 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2189 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2190 $resql2 = $db->query($sql);
2193 $delivery_date = $db->jdate($obj->delivery_date);
2195 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2196 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2197 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2198 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2199 $resql3 = $db->query($sqlu);
2215 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2216 print $langs->trans(
'FieldRenamed').
"<br>\n";
2226 print $langs->trans(
'AlreadyDone').
"<br>\n";
2243 print
'<tr><td colspan="4">';
2246 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2250 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2251 $obj = $db->fetch_object($result);
2257 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2258 $sql .=
", ld.fk_livraison";
2259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2260 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2261 $resql = $db->query($sql);
2264 $num = $db->num_rows($resql);
2268 $obj = $db->fetch_object($resql);
2270 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2271 $sql .=
" fk_product = ".((int) $obj->fk_product);
2272 $sql .=
",description = '".$db->escape($obj->description).
"'";
2273 $sql .=
",subprice = ".price2num($obj->subprice);
2274 $sql .=
",total_ht = ".price2num($obj->total_ht);
2275 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2276 $resql2 = $db->query($sql);
2279 $sql =
"SELECT total_ht";
2280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2281 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2282 $resql3 = $db->query($sql);
2285 $obju = $db->fetch_object($resql3);
2286 $total_ht = $obju->total_ht + $obj->total_ht;
2288 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2289 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2290 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2291 $resql4 = $db->query($sqlu);
2311 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2312 print $langs->trans(
'FieldRenamed').
"<br>\n";
2322 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2323 $obj = $db->fetch_object($result);
2325 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2328 print $langs->trans(
'AlreadyDone').
"<br>\n";
2345 print
'<tr><td colspan="4">';
2348 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2354 $sql =
"SELECT SUM(reel) as total, fk_product";
2355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2356 $sql .=
" GROUP BY fk_product";
2357 $resql = $db->query($sql);
2360 $num = $db->num_rows($resql);
2364 $obj = $db->fetch_object($resql);
2366 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2367 $sql .=
" stock = ".price2num($obj->total,
'MS');
2368 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2370 $resql2 = $db->query($sql);
2407 print
'<tr><td colspan="4">';
2410 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2414 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2417 $sql =
"SELECT m.rowid, mc.action";
2418 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2419 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2420 $sql .=
" AND m.enabled = '1'";
2421 $resql = $db->query($sql);
2424 $num = $db->num_rows($resql);
2427 $obj = $db->fetch_object($resql);
2429 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2430 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2431 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2432 $sql .=
" AND enabled = '1'";
2434 $resql2 = $db->query($sql);
2455 print $langs->trans(
'AlreadyDone').
"<br>\n";
2474 print
'<tr><td colspan="4">';
2477 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2481 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2484 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2485 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2486 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2487 $sql .=
" WHERE c.rowid = ce.fk_commande";
2488 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2490 $resql = $db->query($sql);
2493 $num = $db->num_rows($resql);
2497 $obj = $db->fetch_object($resql);
2499 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2500 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2501 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2503 $resql2 = $db->query($sql);
2512 print $langs->trans(
'AlreadyDone').
"<br>\n";
2525 print $langs->trans(
'AlreadyDone').
"<br>\n";
2544 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2546 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2550 print
'<tr><td colspan="4">';
2553 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2559 $table1 =
'facturedet';
2560 $field1 =
'fk_remise_except';
2561 $table2 =
'societe_remise_except';
2562 $field2 =
'fk_facture_line';
2566 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2567 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2568 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2569 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2570 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2573 $resql = $db->query($sql);
2576 $num = $db->num_rows($resql);
2580 $obj = $db->fetch_object($resql);
2582 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2583 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2584 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2585 $sql .=
" WHERE rowid = ".((int) $obj->field);
2587 $resql2 = $db->query($sql);
2596 print $langs->trans(
'AlreadyDone').
"<br>\n";
2612 print
'<tr><td colspan="4">';
2615 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2618 $table2 =
'facturedet';
2619 $field2 =
'fk_remise_except';
2620 $table1 =
'societe_remise_except';
2621 $field1 =
'fk_facture_line';
2625 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2626 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2627 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2628 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2629 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2632 $resql = $db->query($sql);
2635 $num = $db->num_rows($resql);
2639 $obj = $db->fetch_object($resql);
2641 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2642 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2643 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2644 $sql .=
" WHERE rowid = ".((int) $obj->field);
2646 $resql2 = $db->query($sql);
2655 print $langs->trans(
'AlreadyDone').
"<br>\n";
2670 return ($error ? -1 : 1);
2685 print
'<tr><td colspan="4">';
2688 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2690 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2691 $obj = $db->fetch_object($result);
2697 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2698 $resql = $db->query($sql);
2701 $num = $db->num_rows($resql);
2705 $obj = $db->fetch_object($resql);
2707 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2708 $sql2 .=
"datecreate";
2709 $sql2 .=
", statut";
2710 $sql2 .=
", element_id";
2711 $sql2 .=
", fk_c_type_contact";
2712 $sql2 .=
", fk_socpeople";
2713 $sql2 .=
") VALUES (";
2714 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2716 $sql2 .=
", ".$obj->rowid;
2718 $sql2 .=
", ".$obj->fk_user_resp;
2721 if ($obj->fk_user_resp > 0) {
2722 $resql2 = $db->query($sql2);
2735 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2736 if ($db->query($sqlDrop)) {
2749 print $langs->trans(
'AlreadyDone').
"<br>\n";
2766 print
'<tr><td colspan="4">';
2769 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2771 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2776 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2777 $resql = $db->query($sql);
2780 $num = $db->num_rows($resql);
2784 $obj = $db->fetch_object($resql);
2786 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2787 $sql2 .=
"datecreate";
2788 $sql2 .=
", statut";
2789 $sql2 .=
", element_id";
2790 $sql2 .=
", fk_c_type_contact";
2791 $sql2 .=
", fk_socpeople";
2792 $sql2 .=
") VALUES (";
2793 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2795 $sql2 .=
", ".$obj->fk_project_task;
2797 $sql2 .=
", ".$obj->fk_user;
2800 $resql2 = $db->query($sql2);
2812 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2813 if ($db->query($sqlDrop)) {
2826 print $langs->trans(
'AlreadyDone').
"<br>\n";
2846 print
'<tr><td colspan="4">';
2849 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2853 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2858 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2859 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2861 $resql = $db->query($sqlSelect);
2864 $num = $db->num_rows($resql);
2868 $obj = $db->fetch_object($resql);
2870 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2871 $sqlInsert .=
"fk_source";
2872 $sqlInsert .=
", sourcetype";
2873 $sqlInsert .=
", fk_target";
2874 $sqlInsert .=
", targettype";
2875 $sqlInsert .=
") VALUES (";
2876 $sqlInsert .= $obj->$fk_source;
2877 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2878 $sqlInsert .=
", ".$obj->$fk_target;
2879 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2882 $result = $db->query($sqlInsert);
2891 print $langs->trans(
'AlreadyDone').
"<br>\n";
2895 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2896 if ($db->query($sqlDrop)) {
2909 print $langs->trans(
'AlreadyDone').
"<br>\n";
2927 print
'<tr><td colspan="4">';
2930 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2936 $sql =
"SELECT rowid, fk_element, element_duration";
2937 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2938 $resql = $db->query($sql);
2941 $num = $db->num_rows($resql);
2944 $totaltime = array();
2948 $obj = $db->fetch_object($resql);
2950 if ($obj->element_duration > 0) {
2953 list($hour, $min) = explode(
'.', $obj->element_duration);
2954 $hour = $hour * 60 * 60;
2955 $min = ($min / 100) * 60 * 60;
2956 $newtime = $hour + $min;
2958 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2959 $sql2 .=
" element_duration = ".((int) $newtime);
2960 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2962 $resql2 = $db->query($sql2);
2969 if (!empty($totaltime[$obj->fk_element])) {
2970 $totaltime[$obj->fk_element] += $newtime;
2972 $totaltime[$obj->fk_element] = $newtime;
2975 if (!empty($totaltime[$obj->fk_element])) {
2976 $totaltime[$obj->fk_element] += $obj->element_duration;
2978 $totaltime[$obj->fk_element] = $obj->element_duration;
2987 foreach ($totaltime as $taskid => $total_duration) {
2988 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2989 $sql .=
" duration_effective = ".((int) $total_duration);
2990 $sql .=
" WHERE rowid = ".((int) $taskid);
2992 $resql = $db->query($sql);
2999 print $langs->trans(
'AlreadyDone').
"<br>\n";
3005 print $langs->trans(
'AlreadyDone').
"<br>\n";
3030 print
'<tr><td colspan="4">';
3033 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3037 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3038 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3039 $obj1 = $db->fetch_object($result1);
3040 $obj2 = $db->fetch_object($result2);
3041 if (!$obj1 && !$obj2) {
3046 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3047 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3049 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3050 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3051 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3052 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3053 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3054 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3055 $sqlSelect .=
" AND el.targettype = 'shipping'";
3057 $resql = $db->query($sqlSelect);
3060 $num = $db->num_rows($resql);
3064 $obj = $db->fetch_object($resql);
3066 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3067 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3068 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3069 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3071 $result = $db->query($sqlUpdate);
3080 print $langs->trans(
'AlreadyDone').
"<br>\n";
3098 print $langs->trans(
'AlreadyDone').
"<br>\n";
3114 print
'<tr><td colspan="4">';
3117 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3121 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3122 $obj = $db->fetch_object($result);
3128 $sqlSelect =
"SELECT rowid, fk_expedition";
3129 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3130 $sqlSelect .=
" WHERE fk_expedition is not null";
3132 $resql = $db->query($sqlSelect);
3135 $num = $db->num_rows($resql);
3139 $obj = $db->fetch_object($resql);
3141 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3142 $sqlInsert .=
"fk_source";
3143 $sqlInsert .=
", sourcetype";
3144 $sqlInsert .=
", fk_target";
3145 $sqlInsert .=
", targettype";
3146 $sqlInsert .=
") VALUES (";
3147 $sqlInsert .= $obj->fk_expedition;
3148 $sqlInsert .=
", 'shipping'";
3149 $sqlInsert .=
", ".$obj->rowid;
3150 $sqlInsert .=
", 'delivery'";
3153 $result = $db->query($sqlInsert);
3155 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3156 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3158 $result = $db->query($sqlUpdate);
3171 print $langs->trans(
'AlreadyDone').
"<br>\n";
3175 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3176 $db->query($sqlDelete);
3181 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3182 $db->query($sqlDrop);
3192 print $langs->trans(
'AlreadyDone').
"<br>\n";
3209 print
'<tr><td colspan="4">';
3212 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3220 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3221 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3222 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3223 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3224 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3225 $sqlSelect .=
" AND el.targettype = 'delivery'";
3226 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3227 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3229 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3230 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3232 $resql = $db->query($sqlSelect);
3235 $num = $db->num_rows($resql);
3239 $obj = $db->fetch_object($resql);
3241 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3242 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3243 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3244 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3246 $result = $db->query($sqlUpdate);
3255 print $langs->trans(
'AlreadyDone').
"<br>\n";
3282 print
'<tr><td colspan="4">';
3285 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3288 'propal' =>
'propalrowid',
3289 'order' =>
'fk_commande',
3290 'invoice' =>
'fk_facture',
3291 'contract' =>
'fk_contract',
3292 'order_supplier' =>
'fk_supplier_order',
3293 'invoice_supplier' =>
'fk_supplier_invoice'
3296 foreach ($elements as $type => $field) {
3297 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3298 $obj = $db->fetch_object($result);
3304 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3305 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3306 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3307 $sql .=
" AND fk_element IS NULL";
3308 $sql .=
" AND elementtype IS NULL";
3310 $resql = $db->query($sql);
3324 print $langs->trans(
'AlreadyDone').
"<br>\n";
3341 print
'<tr><td colspan="4">';
3344 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3347 'old_id' => array(5, 8, 9, 10, 11),
3348 'new_id' => array(50, 51, 52, 53, 54),
3349 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3350 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3354 foreach ($elements[
'old_id'] as $key => $old_id) {
3359 $sqlSelect =
"SELECT id";
3360 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3361 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3362 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3364 $resql = $db->query($sqlSelect);
3366 $num = $db->num_rows($resql);
3372 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3373 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3374 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3375 $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]).
"')";
3376 $resqla = $db->query($sqla);
3378 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3379 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3380 $sql .=
" WHERE id = ".((int) $old_id);
3381 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3382 $resql = $db->query($sql);
3384 if ($resqla && $resql) {
3385 foreach ($elements[
'tables'] as $table) {
3386 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3387 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3388 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3390 $resql = $db->query($sql);
3413 print $langs->trans(
'AlreadyDone').
"<br>\n";
3431 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3433 $obj = $db->fetch_object($result);
3437 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3438 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3440 $resql = $db->query($sql);
3442 $num = $db->num_rows($resql);
3443 while ($obj = $db->fetch_object($resql)) {
3444 if (!isset($filles[$obj->fk_categorie_fille])) {
3445 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3446 $filles[$obj->fk_categorie_fille] = 1;
3447 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere'=>$obj->fk_categorie_mere,
'fille'=>$obj->fk_categorie_fille);
3455 if (count($couples) > 0 && $num > count($couples)) {
3461 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3463 $resqld = $db->query($sql);
3466 foreach ($couples as $key => $val) {
3467 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3468 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3470 $resqli = $db->query($sql);
3478 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3479 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3482 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3483 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3488 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3489 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3506 print
'<tr><td colspan="4">';
3509 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3513 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3518 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3519 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3521 $resql = $db->query($sqlSelect);
3524 $num = $db->num_rows($resql);
3528 $obj = $db->fetch_object($resql);
3530 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3531 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3532 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3534 $result = $db->query($sqlUpdate);
3543 print $langs->trans(
'AlreadyDone').
"<br>\n";
3556 print $langs->trans(
'AlreadyDone').
"<br>\n";
3572 print
'<tr><td colspan="4">';
3575 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3583 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3584 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3585 $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";
3586 $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')";
3587 $sqlSelect .=
" ORDER BY a.id";
3590 $resql = $db->query($sqlSelect);
3593 $num = $db->num_rows($resql);
3597 $obj = $db->fetch_object($resql);
3599 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3600 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3602 $result = $db->query($sqlUpdate);
3611 print $langs->trans(
'AlreadyDone').
"<br>\n";
3638 print
'<tr><td colspan="4">';
3641 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3649 $sqlSelect =
"SELECT a.id, a.fk_contact";
3650 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3651 $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";
3652 $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')";
3653 $sqlSelect .=
" ORDER BY a.id";
3656 $resql = $db->query($sqlSelect);
3659 $num = $db->num_rows($resql);
3663 $obj = $db->fetch_object($resql);
3665 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3666 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3668 $result = $db->query($sqlUpdate);
3677 print $langs->trans(
'AlreadyDone').
"<br>\n";
3707 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3709 print
'<tr><td colspan="4">';
3712 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3720 $sqlSelect =
"SELECT DISTINCT entity";
3721 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3725 $resql = $db->query($sqlSelect);
3728 $num = $db->num_rows($resql);
3732 $obj = $db->fetch_object($resql);
3734 print
'Process entity '.$obj->entity;
3736 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3737 $resqlSearch = $db->query($sqlSearch);
3739 $objSearch = $db->fetch_object($resqlSearch);
3741 if ($objSearch && $objSearch->nb == 0) {
3742 print
' - Record for entity must be reset...';
3744 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3745 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3746 $resqlUpdate = $db->query($sqlUpdate);
3747 if (!$resqlUpdate) {
3754 $object->element =
'module';
3755 $object->ref =
'systemevent';
3756 $object->entity = $obj->entity;
3760 $b->setObjectData($object,
'MODULE_SET', 0);
3762 $res = $b->create($user);
3768 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3777 print $langs->trans(
'NothingToDo').
"<br>\n";
3804 print
'<tr><td colspan="4">';
3807 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3815 $sqlSelect =
"SELECT sr.rowid, s.entity";
3816 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3817 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3821 $resql = $db->query($sqlSelect);
3824 $num = $db->num_rows($resql);
3828 $obj = $db->fetch_object($resql);
3830 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3831 $sqlUpdate .=
" entity = ".$obj->entity;
3832 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3834 $result = $db->query($sqlUpdate);
3844 print $langs->trans(
'AlreadyDone').
"<br>\n";
3870 print
'<tr><td colspan="4">';
3873 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3881 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3882 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3885 $resql = $db->query($sqlSelect);
3888 $num = $db->num_rows($resql);
3892 $obj = $db->fetch_object($resql);
3894 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3895 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3897 $sqlSelect2 =
"SELECT f.entity";
3898 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3899 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3900 } elseif (!empty($obj->fk_facture_line)) {
3901 $sqlSelect2 =
"SELECT f.entity";
3902 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3903 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3904 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3906 $sqlSelect2 =
"SELECT s.entity";
3907 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3908 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3911 $resql2 = $db->query($sqlSelect2);
3913 if ($db->num_rows($resql2) > 0) {
3914 $obj2 = $db->fetch_object($resql2);
3916 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3917 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3918 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3920 $result = $db->query($sqlUpdate);
3935 print $langs->trans(
'AlreadyDone').
"<br>\n";
3962 print
'<tr><td colspan="4">';
3964 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3972 $sqlSelect =
"SELECT u.rowid, u.entity";
3973 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3974 $sqlSelect .=
" WHERE u.entity > 1";
3977 $resql = $db->query($sqlSelect);
3980 $num = $db->num_rows($resql);
3984 $obj = $db->fetch_object($resql);
3986 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3987 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3988 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3990 $result = $db->query($sqlUpdate);
4000 print $langs->trans(
'AlreadyDone').
"<br>\n";
4027 print
'<tr><td colspan="4">';
4029 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4037 $sqlSelect =
"SELECT u.rowid, u.entity";
4038 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4039 $sqlSelect .=
" WHERE u.entity > 1";
4042 $resql = $db->query($sqlSelect);
4045 $num = $db->num_rows($resql);
4049 $obj = $db->fetch_object($resql);
4051 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4052 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4053 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4055 $result = $db->query($sqlUpdate);
4065 print $langs->trans(
'AlreadyDone').
"<br>\n";
4096 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4097 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4098 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4118 $filetodeletearray = array(
4119 '/core/ajax/ajaxcompanies.php',
4120 '/core/triggers/interface_demo.class.php',
4121 '/core/menus/barre_left/default.php',
4122 '/core/menus/barre_top/default.php',
4123 '/core/modules/modComptabiliteExpert.class.php',
4124 '/core/modules/modCommercial.class.php',
4125 '/core/modules/modProduit.class.php',
4126 '/core/modules/modSkype.class.php',
4127 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4128 '/core/triggers/interface_modCommande_Ecotax.class.php',
4129 '/core/triggers/interface_modCommande_fraisport.class.php',
4130 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4131 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4132 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4133 '/core/menus/smartphone/iphone.lib.php',
4134 '/core/menus/smartphone/iphone_backoffice.php',
4135 '/core/menus/smartphone/iphone_frontoffice.php',
4136 '/core/menus/standard/auguria_backoffice.php',
4137 '/core/menus/standard/auguria_frontoffice.php',
4138 '/core/menus/standard/eldy_backoffice.php',
4139 '/core/menus/standard/eldy_frontoffice.php',
4140 '/core/modules/export/export_excel.modules.php',
4141 '/core/modules/export/export_csv.modules.php',
4142 '/core/modules/export/exportcsv.modules.php',
4143 '/core/modules/export/export_excel2007new.modules.php',
4144 '/core/modules/facture/pdf_crabe.modules.php',
4145 '/core/modules/facture/pdf_oursin.modules.php',
4146 '/core/modules/mailings/contacts2.modules.php',
4147 '/core/modules/mailings/contacts3.modules.php',
4148 '/core/modules/mailings/contacts4.modules.php',
4149 '/core/modules/mailings/framboise.modules.php',
4150 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4151 '/core/modules/mailings/peche.modules.php',
4152 '/core/modules/mailings/poire.modules.php',
4153 '/core/modules/mailings/kiwi.modules.php',
4154 '/core/boxes/box_members.php',
4156 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4157 '/includes/nusoap/lib/class.*',
4158 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4159 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4161 '/api/class/api_generic.class.php',
4162 '/asterisk/cidlookup.php',
4163 '/categories/class/api_category.class.php',
4164 '/categories/class/api_deprecated_category.class.php',
4165 '/compta/facture/class/api_invoice.class.php',
4166 '/commande/class/api_commande.class.php',
4167 '/partnership/class/api_partnership.class.php',
4168 '/product/class/api_product.class.php',
4169 '/recruitment/class/api_recruitment.class.php',
4170 '/societe/class/api_contact.class.php',
4171 '/societe/class/api_thirdparty.class.php',
4172 '/support/online.php',
4173 '/takepos/class/actions_takepos.class.php',
4174 '/user/class/api_user.class.php',
4176 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4177 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4178 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4179 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4180 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4181 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4190 foreach ($filetodeletearray as $filetodelete) {
4192 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete) || preg_match(
'/\*/', $filetodelete)) {
4194 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true,
false);
4196 $langs->load(
"errors");
4197 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4198 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4223 $filetodeletearray = array(
4224 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4225 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4229 if (!empty($_SERVER[
"WINDIR"])) {
4230 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4233 foreach ($filetodeletearray as $filetodelete) {
4235 if (file_exists($filetodelete)) {
4239 $langs->load(
"errors");
4240 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4241 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4265 if (count($listofmodule) == 0) {
4269 if (!is_object($user)) {
4270 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4271 $user =
new User($db);
4274 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".join(
',', array_keys($listofmodule)));
4276 $reloadactionformodules = array(
4277 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove'=> 1),
4278 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4279 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove'=> 1),
4280 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus'=> 1),
4281 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove'=> 1),
4282 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove'=> 1),
4283 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove'=> 1),
4284 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4285 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4286 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4287 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4288 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheInter'),
4289 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4290 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove'=>1),
4291 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4292 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4293 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4294 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove'=>1),
4295 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove'=>1),
4296 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove'=>1),
4297 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove'=>1),
4298 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4299 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove'=>1),
4300 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove'=>1),
4301 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove'=>1),
4302 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove'=>1),
4303 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove'=>1),
4306 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4307 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4313 if (!empty($reloadactionformodules[$moduletoreload])) {
4314 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4316 $val = $reloadactionformodules[$moduletoreload];
4317 $classformodule = $val[
'class'];
4318 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4320 $mod =
new $classformodule($db);
4321 if (!empty($val[
'remove'])) {
4322 $mod->remove(
'noboxes');
4324 if (!empty($val[
'deleteinsertmenus'])) {
4326 $mod->delete_menus();
4327 $mod->insert_menus();
4329 $mod->init($reloadmode);
4334 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4335 if (!empty($reg[1])) {
4336 if (strtoupper($moduletoreload) == $moduletoreload) {
4337 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4339 $moduletoreloadshort = $reg[1];
4342 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4344 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4346 $classname =
'mod'.$moduletoreloadshort;
4347 $mod =
new $classname($db);
4350 $mod->delete_menus();
4351 $mod->init($reloadmode);
4353 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4355 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4357 $classname =
'mod'.$moduletoreloadshort;
4358 $mod =
new $classname($db);
4359 $mod->init($reloadmode);
4361 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4362 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4368 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4373 if (!empty($mod) && is_object($mod)) {
4374 print
'<tr class="trforrunsql"><td colspan="4">';
4375 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4376 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4377 print
"<!-- (".$reloadmode.
") -->";
4402 $listofmenuhandler = array();
4405 $listofmenuhandler[
'auguria'] = 1;
4408 foreach ($listofmenuhandler as $key => $val) {
4409 print
'<tr class="trforrunsql"><td colspan="4">';
4413 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4416 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4417 $file =
'init_menu_'.$key.
'.sql';
4418 if (file_exists($dir.$file)) {
4419 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4435 global $conf, $db, $langs, $user;
4437 print
'<tr><td colspan="4">';
4439 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4441 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4442 $fuser =
new User($db);
4443 if (!is_object($user)) {
4447 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4448 $resql = $db->query($sql);
4450 while ($obj = $db->fetch_object($resql)) {
4452 $fuser->id = $obj->uid;
4453 $fuser->entity = $obj->entity;
4456 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4458 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4460 $dir = $conf->user->multidir_output[$entity];
4465 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4466 $destin = $dir.
'/'.$fuser->id;
4474 $handle = opendir($origin_osencoded);
4475 if (is_resource($handle)) {
4476 while (($file = readdir($handle)) !==
false) {
4477 if ($file ==
'.' || $file ==
'..') {
4482 $thumbs = opendir($origin_osencoded.
'/'.$file);
4483 if (is_resource($thumbs)) {
4485 while (($thumb = readdir($thumbs)) !==
false) {
4487 if ($thumb ==
'.' || $thumb ==
'..') {
4493 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4503 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4524 global $db, $langs, $user;
4526 print
'<tr><td colspan="4">';
4528 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4530 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4531 $fuser =
new User($db);
4532 if (!is_object($user)) {
4536 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4537 $resql = $db->query($sql);
4539 while ($obj = $db->fetch_object($resql)) {
4541 $fuser->id = $obj->uid;
4542 $fuser->entity = $obj->entity;
4543 $fuser->photo = $obj->photo;
4546 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4548 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4550 $dir = DOL_DATA_ROOT.
'/users';
4555 $origin = $dir.
'/'.$fuser->id;
4556 $destin = $dir.
'/'.$fuser->id.
'/photos';
4564 $handle = opendir($origin_osencoded);
4565 if (is_resource($handle)) {
4566 while (($file = readdir($handle)) !==
false) {
4567 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4570 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4575 $thumbs = opendir($origin_osencoded.
'/'.$file);
4576 if (is_resource($thumbs)) {
4578 while (($thumb = readdir($thumbs)) !==
false) {
4580 if ($thumb ==
'.' || $thumb ==
'..') {
4586 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4595 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4632 print
'<tr><td colspan="4">';
4633 $sql =
'SELECT rowid, socialnetworks';
4634 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4635 $sql .=
" skype IS NOT NULL OR skype <> ''";
4636 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4637 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4638 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4639 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4640 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4641 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4642 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4643 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4645 $resql = $db->query($sql);
4647 while ($obj = $db->fetch_object($resql)) {
4648 $arraysocialnetworks = array();
4649 if (!empty($obj->skype)) {
4650 $arraysocialnetworks[
'skype'] = $obj->skype;
4652 if (!empty($obj->twitter)) {
4653 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4655 if (!empty($obj->facebook)) {
4656 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4658 if (!empty($obj->linkedin)) {
4659 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4661 if (!empty($obj->instagram)) {
4662 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4664 if (!empty($obj->snapchat)) {
4665 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4667 if (!empty($obj->googleplus)) {
4668 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4670 if (!empty($obj->youtube)) {
4671 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4673 if (!empty($obj->whatsapp)) {
4674 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4676 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4677 $obj->socialnetworks =
'[]';
4679 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4680 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4681 $sqlupd .=
', skype=null';
4682 $sqlupd .=
', twitter=null';
4683 $sqlupd .=
', facebook=null';
4684 $sqlupd .=
', linkedin=null';
4685 $sqlupd .=
', instagram=null';
4686 $sqlupd .=
', snapchat=null';
4687 $sqlupd .=
', googleplus=null';
4688 $sqlupd .=
', youtube=null';
4689 $sqlupd .=
', whatsapp=null';
4690 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4692 $resqlupd = $db->query($sqlupd);
4707 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4721 print
'<tr><td colspan="4">';
4724 print
'<tr><td colspan="4">';
4725 $sql =
'SELECT rowid, socialnetworks';
4726 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4727 $sql .=
" skype IS NOT NULL OR skype <> ''";
4728 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4729 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4730 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4731 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4732 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4733 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4734 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4735 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4737 $resql = $db->query($sql);
4739 while ($obj = $db->fetch_object($resql)) {
4740 $arraysocialnetworks = array();
4741 if (!empty($obj->skype)) {
4742 $arraysocialnetworks[
'skype'] = $obj->skype;
4744 if (!empty($obj->twitter)) {
4745 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4747 if (!empty($obj->facebook)) {
4748 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4750 if (!empty($obj->linkedin)) {
4751 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4753 if (!empty($obj->instagram)) {
4754 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4756 if (!empty($obj->snapchat)) {
4757 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4759 if (!empty($obj->googleplus)) {
4760 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4762 if (!empty($obj->youtube)) {
4763 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4765 if (!empty($obj->whatsapp)) {
4766 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4768 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4769 $obj->socialnetworks =
'[]';
4771 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4772 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4773 $sqlupd .=
', skype=null';
4774 $sqlupd .=
', twitter=null';
4775 $sqlupd .=
', facebook=null';
4776 $sqlupd .=
', linkedin=null';
4777 $sqlupd .=
', instagram=null';
4778 $sqlupd .=
', snapchat=null';
4779 $sqlupd .=
', googleplus=null';
4780 $sqlupd .=
', youtube=null';
4781 $sqlupd .=
', whatsapp=null';
4782 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4784 $resqlupd = $db->query($sqlupd);
4799 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4815 print
'<tr><td colspan="4">';
4816 $sql =
'SELECT rowid, socialnetworks';
4817 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4818 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4819 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4820 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4821 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4822 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4823 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4824 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4825 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4826 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4827 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4829 $resql = $db->query($sql);
4831 while ($obj = $db->fetch_object($resql)) {
4832 $arraysocialnetworks = array();
4833 if (!empty($obj->jabberid)) {
4834 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4836 if (!empty($obj->skype)) {
4837 $arraysocialnetworks[
'skype'] = $obj->skype;
4839 if (!empty($obj->twitter)) {
4840 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4842 if (!empty($obj->facebook)) {
4843 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4845 if (!empty($obj->linkedin)) {
4846 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4848 if (!empty($obj->instagram)) {
4849 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4851 if (!empty($obj->snapchat)) {
4852 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4854 if (!empty($obj->googleplus)) {
4855 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4857 if (!empty($obj->youtube)) {
4858 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4860 if (!empty($obj->whatsapp)) {
4861 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4863 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4864 $obj->socialnetworks =
'[]';
4866 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4867 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4868 $sqlupd .=
', jabberid=null';
4869 $sqlupd .=
', skype=null';
4870 $sqlupd .=
', twitter=null';
4871 $sqlupd .=
', facebook=null';
4872 $sqlupd .=
', linkedin=null';
4873 $sqlupd .=
', instagram=null';
4874 $sqlupd .=
', snapchat=null';
4875 $sqlupd .=
', googleplus=null';
4876 $sqlupd .=
', youtube=null';
4877 $sqlupd .=
', whatsapp=null';
4878 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4880 $resqlupd = $db->query($sqlupd);
4895 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4911 print
'<tr><td colspan="4">';
4912 $sql =
'SELECT rowid, socialnetworks';
4913 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4914 $sql .=
" skype IS NOT NULL OR skype <> ''";
4915 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4916 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4917 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4918 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4919 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4920 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4921 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4922 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4924 $resql = $db->query($sql);
4926 while ($obj = $db->fetch_object($resql)) {
4927 $arraysocialnetworks = array();
4928 if (!empty($obj->skype)) {
4929 $arraysocialnetworks[
'skype'] = $obj->skype;
4931 if (!empty($obj->twitter)) {
4932 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4934 if (!empty($obj->facebook)) {
4935 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4937 if (!empty($obj->linkedin)) {
4938 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4940 if (!empty($obj->instagram)) {
4941 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4943 if (!empty($obj->snapchat)) {
4944 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4946 if (!empty($obj->googleplus)) {
4947 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4949 if (!empty($obj->youtube)) {
4950 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4952 if (!empty($obj->whatsapp)) {
4953 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4955 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4956 $obj->socialnetworks =
'[]';
4958 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4959 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks,
true)).
"'";
4960 $sqlupd .=
', skype=null';
4961 $sqlupd .=
', twitter=null';
4962 $sqlupd .=
', facebook=null';
4963 $sqlupd .=
', linkedin=null';
4964 $sqlupd .=
', instagram=null';
4965 $sqlupd .=
', snapchat=null';
4966 $sqlupd .=
', googleplus=null';
4967 $sqlupd .=
', youtube=null';
4968 $sqlupd .=
', whatsapp=null';
4969 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4971 $resqlupd = $db->query($sqlupd);
4986 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5006 print
'<tr class="trforrunsql"><td colspan="4">';
5007 $sql =
'SELECT rowid, field';
5008 if ($mode ==
'export') {
5011 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5012 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5014 $resql = $db->query($sql);
5016 while ($obj = $db->fetch_object($resql)) {
5017 $oldfield = $obj->field;
5018 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5020 if ($mode ==
'export') {
5021 $oldfilter = $obj->filter;
5022 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5028 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5029 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5030 if ($mode ==
'export') {
5031 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5033 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5034 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5035 $resqlupd = $db->query($sqlupd);
5051 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5054 if ($resultstring) {
5055 print $resultstring;
5057 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5074 print
'<tr class="trforrunsql"><td colspan="4">';
5075 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5077 $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";
5078 $sql .=
" ORDER BY c.rowid,cd.rowid";
5080 $resql = $db->query($sql);
5083 $current_contract=0;
5084 while ($obj = $db->fetch_object($resql)) {
5085 if (empty($current_contract) || $current_contract==$obj->cid) {
5091 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5092 $resultstring =
'.';
5093 print $resultstring;
5094 $resqlUpd = $db->query($sqlUpd);
5100 $current_contract = $obj->cid;
5113 if (!$resultstring) {
5114 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Class to manage Blocked Log.
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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.
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/Reenable features modules.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
if($db->connected) if( $ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondance des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignement to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondance des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignement to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_element_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.