43define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
44include_once
'inc.php';
45if (!file_exists($conffile)) {
46 print
'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
48require_once $conffile;
49require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
50require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
51require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
52require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
53require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
54require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
55require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
56require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
67$err = error_reporting();
70 @set_time_limit((
int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
76$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
77$langs->setDefaultLang($setuplang);
78$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
79$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
80$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
82$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
84if ($dolibarr_main_db_type ==
'mysqli') {
87if ($dolibarr_main_db_type ==
'pgsql') {
90if ($dolibarr_main_db_type ==
'mssql') {
95dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
96if (!is_object($conf)) {
106if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
107 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
108 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
110 $sapi_type = php_sapi_name();
111 $script_file = basename(__FILE__);
113 if (substr($sapi_type, 0, 3) ==
'cli') {
114 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
119pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
122if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
123 print
'<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
124 print
'<span class="inline-block">'.$langs->trans(
'DataMigration').
'</span></h3>';
126 print
'<table border="0" width="100%">';
129 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
130 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
131 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
132 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
133 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
134 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
136 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
141 $conf->db->type = $dolibarr_main_db_type;
142 $conf->db->host = $dolibarr_main_db_host;
143 $conf->db->port = $dolibarr_main_db_port;
144 $conf->db->name = $dolibarr_main_db_name;
145 $conf->db->user = $dolibarr_main_db_user;
146 $conf->db->pass = $dolibarr_main_db_pass;
148 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
150 if (!$db->connected) {
151 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase", $conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
152 dolibarr_install_syslog(
'upgrade2: failed to connect to database :'.$conf->db->name.
' on '.$conf->db->host.
' for user '.$conf->db->user, LOG_ERR);
157 if ($db->database_selected) {
164 if (empty($dolibarr_main_db_encryption)) {
165 $dolibarr_main_db_encryption = 0;
167 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
168 if (empty($dolibarr_main_db_cryptkey)) {
169 $dolibarr_main_db_cryptkey =
'';
171 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
174 $conf->setValues($db);
177 $listofentities = array(1);
180 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
182 $hookmanager->initHooks(array(
'upgrade2'));
184 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
187 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
188 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
190 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
201 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
203 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
205 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
207 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
209 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
211 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
213 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
215 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
217 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
219 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
221 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
227 foreach ($listofentities as $entity) {
229 $conf->setEntityValues($db, $entity);
231 if (defined(
'SYSLOG_FILE')) {
232 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
234 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
237 if (count($listofentities) > 1) {
238 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
243 $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 :
''));
249 $versiontoarray = explode(
'.', $versionto);
250 $versionranarray = explode(
'.', DOL_VERSION);
253 $afterversionarray = explode(
'.',
'2.0.0');
254 $beforeversionarray = explode(
'.',
'2.7.9');
315 $afterversionarray = explode(
'.',
'2.7.9');
316 $beforeversionarray = explode(
'.',
'2.8.9');
341 $afterversionarray = explode(
'.',
'2.8.9');
342 $beforeversionarray = explode(
'.',
'2.9.9');
354 $afterversionarray = explode(
'.',
'2.9.9');
355 $beforeversionarray = explode(
'.',
'3.0.9');
361 $afterversionarray = explode(
'.',
'3.0.9');
362 $beforeversionarray = explode(
'.',
'3.1.9');
370 $afterversionarray = explode(
'.',
'3.1.9');
371 $beforeversionarray = explode(
'.',
'3.2.9');
381 $afterversionarray = explode(
'.',
'3.2.9');
382 $beforeversionarray = explode(
'.',
'3.3.9');
391 $afterversionarray = explode(
'.',
'3.6.9');
392 $beforeversionarray = explode(
'.',
'3.7.9');
398 $afterversionarray = explode(
'.',
'3.7.9');
399 $beforeversionarray = explode(
'.',
'3.8.9');
405 $afterversionarray = explode(
'.',
'3.9.9');
406 $beforeversionarray = explode(
'.',
'4.0.9');
412 $afterversionarray = explode(
'.',
'4.0.9');
413 $beforeversionarray = explode(
'.',
'5.0.9');
423 $afterversionarray = explode(
'.',
'5.0.9');
424 $beforeversionarray = explode(
'.',
'6.0.9');
426 if (isModEnabled(
'multicompany')) {
427 global $multicompany_transverse_mode;
430 if (empty($multicompany_transverse_mode)) {
441 $afterversionarray = explode(
'.',
'6.0.9');
442 $beforeversionarray = explode(
'.',
'7.0.9');
451 $afterversionarray = explode(
'.',
'7.0.9');
452 $beforeversionarray = explode(
'.',
'8.0.9');
458 $afterversionarray = explode(
'.',
'8.0.9');
459 $beforeversionarray = explode(
'.',
'9.0.9');
465 $afterversionarray = explode(
'.',
'10.0.9');
466 $beforeversionarray = explode(
'.',
'11.0.9');
475 $afterversionarray = explode(
'.',
'13.0.9');
476 $beforeversionarray = explode(
'.',
'14.0.9');
483 $afterversionarray = explode(
'.',
'15.0.9');
484 $beforeversionarray = explode(
'.',
'16.0.9');
491 $afterversionarray = explode(
'.',
'16.0.9');
492 $beforeversionarray = explode(
'.',
'17.0.9');
498 $afterversionarray = explode(
'.',
'17.0.9');
499 $beforeversionarray = explode(
'.',
'18.0.9');
518 $listofmodule = array(
519 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
520 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
521 'MAIN_MODULE_BOM' =>
'menuonly',
522 'MAIN_MODULE_BANQUE' =>
'menuonly',
523 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
524 'MAIN_MODULE_CRON' =>
'newboxdefonly',
525 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
526 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
527 'MAIN_MODULE_DEPLACEMENT' =>
'newboxdefonly',
528 'MAIN_MODULE_DON' =>
'newboxdefonly',
529 'MAIN_MODULE_ECM' =>
'newboxdefonly',
530 'MAIN_MODULE_EXTERNALSITE' =>
'newboxdefonly',
531 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
532 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
533 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
534 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
535 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
536 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
537 'MAIN_MODULE_MARGIN' =>
'menuonly',
538 'MAIN_MODULE_MRP' =>
'menuonly',
539 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
540 'MAIN_MODULE_PAYBOX' =>
'newboxdefonly',
541 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
542 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
543 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
544 'MAIN_MODULE_RESOURCE' =>
'noboxes',
545 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
546 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
547 'MAIN_MODULE_SYSLOG' =>
'newboxdefonly',
548 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
549 'MAIN_MODULE_STRIPE' =>
'menuonly',
550 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
551 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
552 'MAIN_MODULE_USER' =>
'newboxdefonly',
553 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
554 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
570 if (!$error && $enablemodules) {
572 $listofmodules = array();
573 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
574 $tmplistofmodules = explode(
',', $enablemodules);
575 foreach ($tmplistofmodules as $value) {
576 $listofmodules[$value] =
'forceactivate';
580 if ($resultreloadmodules < 0) {
588 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
591 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
592 if ($hookmanager->resNbOfHooks > 0) {
594 print
'<tr><td colspan="4">';
595 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
596 print $hookmanager->error;
597 print
"<!-- (".$reshook.
") -->";
600 print
'<tr class="trforrunsql"><td colspan="4">';
601 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
602 print
"<!-- (".$reshook.
") -->";
607 if (!empty($conf->modules_parts[
'hooks'])) {
608 print
'<tr class="trforrunsql"><td colspan="4">';
609 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
620 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
635 foreach ($listofentities as $entity) {
637 $conf->setEntityValues($db, $entity);
639 if (defined(
'SYSLOG_FILE')) {
640 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
642 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
646 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
647 $destroot = DOL_DATA_ROOT.
'/medias';
660 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' => $conf);
663 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
664 if ($hookmanager->resNbOfHooks > 0) {
666 print
'<tr><td colspan="4">';
667 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
668 print $hookmanager->error;
669 print
"<!-- (".$reshook.
") -->";
672 print
'<tr class="trforrunsql"><td colspan="4">';
673 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
674 print
"<!-- (".$reshook.
") -->";
679 if (!empty($conf->modules_parts[
'hooks'])) {
680 print
'<tr class="trforrunsql"><td colspan="4">';
681 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
691 print
'<table width="100%">';
692 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
693 print
'<td class="right">';
697 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
701 print
'<script type="text/javascript">
702 jQuery(document).ready(function() {
703 function init_trrunsql()
705 console.log("toggle .trforrunsql");
706 jQuery(".trforrunsql").toggle();
709 jQuery(".trforrunsqlshowhide").click(function() {
714 print
'<a class="trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
717 print
'</td></tr>'.
"\n";
723 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
728if ($error && isset($argv[1])) {
734pFooter($error ? 2 : 0, $setuplang);
757 print
'<tr><td colspan="4">';
760 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
762 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
763 $obj = $db->fetch_object($result);
765 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
766 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
767 $sql .=
" WHERE p.fk_facture > 0";
769 $resql = $db->query($sql);
775 $num = $db->num_rows($resql);
778 $obj = $db->fetch_object($resql);
779 $row[$i][0] = $obj->rowid;
780 $row[$i][1] = $obj->fk_facture;
781 $row[$i][2] = $obj->amount;
789 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
793 for ($i = 0; $i < $num; $i++) {
794 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
795 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
797 $res += $db->query($sql);
799 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
801 $res += $db->query($sql);
803 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
807 if ($res == (2 * count($row))) {
809 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
812 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
815 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
818 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
836 print
'<tr><td colspan="4">';
839 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
841 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
842 $obj = $db->fetch_object($result);
845 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
846 $sql .=
" bu2.url_id as socid";
847 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
848 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
849 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
850 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
851 $sql .=
" AND b.rappro = 1";
852 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
854 $resql = $db->query($sql);
860 $num = $db->num_rows($resql);
863 $obj = $db->fetch_object($resql);
864 if ($obj->pamount == $obj->bamount && $obj->socid) {
865 $row[$j][
'paymentid'] = $obj->rowid;
866 $row[$j][
'pamount'] = $obj->pamount;
867 $row[$j][
'fk_bank'] = $obj->fk_bank;
868 $row[$j][
'bamount'] = $obj->bamount;
869 $row[$j][
'socid'] = $obj->socid;
870 $row[$j][
'datec'] = $obj->datec;
880 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
885 for ($i = 0; $i < $num; $i++) {
887 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>';
891 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
892 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
893 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
894 $sql .=
" AND pf.fk_facture IS NULL";
895 $sql .=
" ORDER BY f.fk_statut";
897 $resql = $db->query($sql);
899 $num = $db->num_rows($resql);
902 $obj = $db->fetch_object($resql);
903 $facid = $obj->rowid;
905 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
906 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
908 $res += $db->query($sql);
910 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
918 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
920 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
925 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
928 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
946 print
'<tr><td colspan="4">';
949 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
951 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
952 $obj = $db->fetch_object($result);
955 $sql =
"SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
956 $sql .=
" bu2.url_id as socid";
957 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
958 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
959 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
960 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
961 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
963 $resql = $db->query($sql);
969 $num = $db->num_rows($resql);
972 $obj = $db->fetch_object($resql);
973 if ($obj->pamount == $obj->bamount && $obj->socid) {
974 $row[$j][
'paymentid'] = $obj->rowid;
975 $row[$j][
'pamount'] = $obj->pamount;
976 $row[$j][
'fk_bank'] = $obj->fk_bank;
977 $row[$j][
'bamount'] = $obj->bamount;
978 $row[$j][
'socid'] = $obj->socid;
979 $row[$j][
'datec'] = $obj->datec;
992 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
996 for ($i = 0; $i < $num; $i++) {
998 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>';
1002 $sql =
" SELECT distinct f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1003 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1004 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1005 $sql .=
" AND pf.fk_facture IS NULL";
1006 $sql .=
" ORDER BY f.fk_statut";
1008 $resql = $db->query($sql);
1010 $num = $db->num_rows($resql);
1013 $obj = $db->fetch_object($resql);
1014 $facid = $obj->rowid;
1016 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1017 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1019 $res += $db->query($sql);
1021 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1030 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1032 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1037 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1043 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1053 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1070 print
'<tr><td colspan="4">';
1075 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1077 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1078 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1080 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1081 $sql .=
" ON c.fk_product = p.rowid";
1082 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1083 $sql .=
" ON c.rowid=cd.fk_contrat";
1084 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1085 $resql = $db->query($sql);
1091 $num = $db->num_rows($resql);
1094 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1098 $obj = $db->fetch_object($resql);
1100 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1101 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1102 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1103 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1104 $sql .=
" VALUES (";
1105 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1107 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1108 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1111 $sql .= ((float) $obj->tva_tx).
", 1, ";
1112 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1116 if ($db->query($sql)) {
1117 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1129 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1132 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1135 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1138 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1155 print
'<tr><td colspan="4">';
1160 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1162 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1163 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1164 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1165 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1166 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1167 $sql .=
" AND bu.fk_bank IS NULL";
1168 $resql = $db->query($sql);
1174 $num = $db->num_rows($resql);
1177 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1181 $obj = $db->fetch_object($resql);
1183 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1184 $sql .=
"fk_bank, url_id, url, label, type";
1186 $sql .=
" VALUES (";
1187 $sql .= $obj->barowid.
",".$obj->bbrowid.
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1193 if (!$db->query($sql)) {
1204 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1207 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1210 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1229 print
'<tr><td colspan="4">';
1232 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1234 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1236 $resql = $db->query($sql);
1240 if ($db->affected_rows($resql) > 0) {
1241 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1243 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1246 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1248 $resql = $db->query($sql);
1252 if ($db->affected_rows($resql) > 0) {
1253 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1255 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1271 print
'<tr><td colspan="4">';
1276 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1278 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1280 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1281 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1282 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1283 $resql = $db->query($sql);
1289 $num = $db->num_rows($resql);
1292 $nbcontratsmodifie = 0;
1296 $obj = $db->fetch_object($resql);
1297 if ($obj->date_contrat > $obj->datemin) {
1298 $datemin = $db->jdate($obj->datemin);
1300 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1301 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1302 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1303 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1304 $resql2 = $db->query($sql);
1309 $nbcontratsmodifie++;
1316 if ($nbcontratsmodifie) {
1317 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1319 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1339 print
'<tr><td colspan="4">';
1342 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1344 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1346 $resql = $db->query($sql);
1350 if ($db->affected_rows($resql) > 0) {
1351 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1353 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1369 print
'<tr><td colspan="4">';
1372 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1374 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1375 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1377 $resql = $db->query($sql);
1381 if ($db->affected_rows($resql) > 0) {
1384 $num = $db->num_rows($resql);
1387 $nbcontratsmodifie = 0;
1391 $obj = $db->fetch_object($resql);
1393 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1394 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1395 $sql .=
" SET statut = 1";
1396 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1397 $resql2 = $db->query($sql);
1402 $nbcontratsmodifie++;
1409 if ($nbcontratsmodifie) {
1410 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1412 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1416 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1434 print
'<tr><td colspan="4">';
1436 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1439 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1440 $obj = $db->fetch_object($result);
1445 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1446 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1447 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1450 $select_resql = $db->query($select_sql);
1451 if ($select_resql) {
1452 $select_num = $db->num_rows($select_resql);
1456 while (($i < $select_num) && (!$error)) {
1457 $select_obj = $db->fetch_object($select_resql);
1460 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1461 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1462 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1463 $check_resql = $db->query($check_sql);
1465 $check_num = $db->num_rows($check_resql);
1466 if ($check_num == 0) {
1470 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1471 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1474 print
'<tr class="oddeven">';
1475 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1477 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1478 $insert_sql .=
' fk_paiementfourn = \''.$select_obj->rowid.
'\',
';
1479 $insert_sql .= ' fk_facturefourn = \
''.$select_obj->fk_facture_fourn.
'\',
';
1480 $insert_sql .= ' amount = \
''.$select_obj->amount.
'\'';
1481 $insert_resql = $db->query($insert_sql);
1483 if ($insert_resql) {
1485 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1487 print
'<td><span class="error">Error on insert</span></td>';
1503 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1507 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1510 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1514 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1531 $tmpmysoc->setMysoc($conf);
1535 print
'<tr><td colspan="4">';
1538 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1541 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1542 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1543 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1544 $sql .=
" WHERE fd.fk_facture = f.rowid";
1545 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1549 $resql = $db->query($sql);
1551 $num = $db->num_rows($resql);
1555 $obj = $db->fetch_object($resql);
1557 $rowid = $obj->rowid;
1559 $pu = $obj->subprice;
1560 $vatrate = $obj->vatrate;
1561 $remise_percent = $obj->remise_percent;
1562 $remise_percent_global = $obj->remise_percent_global;
1563 $total_ttc_f = $obj->total_ttc_f;
1564 $info_bits = $obj->info_bits;
1568 $facligne->fetch($rowid);
1570 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1571 $total_ht = $result[0];
1572 $total_tva = $result[1];
1573 $total_ttc = $result[2];
1575 $facligne->total_ht = $total_ht;
1576 $facligne->total_tva = $total_tva;
1577 $facligne->total_ttc = $total_ttc;
1579 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);
1581 $facligne->update_total();
1585 if (!$total_ttc_f) {
1587 $facture->id = $obj->facid;
1589 if ($facture->fetch($facture->id) >= 0) {
1590 if ($facture->update_price() > 0) {
1593 print
"Error id=".$facture->id;
1606 print $langs->trans(
"AlreadyDone");
1612 print
"Error #1 ".$db->error();
1634 $tmpmysoc->setMysoc($conf);
1638 print
'<tr><td colspan="4">';
1641 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1644 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1645 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1646 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1647 $sql .=
" WHERE pd.fk_propal = p.rowid";
1648 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1651 $resql = $db->query($sql);
1653 $num = $db->num_rows($resql);
1657 $obj = $db->fetch_object($resql);
1659 $rowid = $obj->rowid;
1661 $pu = $obj->subprice;
1662 $vatrate = $obj->vatrate;
1663 $remise_percent = $obj->remise_percent;
1664 $remise_percent_global = $obj->remise_percent_global;
1665 $info_bits = $obj->info_bits;
1669 $propalligne->fetch($rowid);
1671 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1672 $total_ht = $result[0];
1673 $total_tva = $result[1];
1674 $total_ttc = $result[2];
1676 $propalligne->total_ht = $total_ht;
1677 $propalligne->total_tva = $total_tva;
1678 $propalligne->total_ttc = $total_ttc;
1680 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);
1682 $propalligne->update_total();
1687 print $langs->trans(
"AlreadyDone");
1694 print
"Error #1 ".$db->error();
1717 $tmpmysoc->setMysoc($conf);
1718 if (empty($tmpmysoc->country_id)) {
1719 $tmpmysoc->country_id = 0;
1722 print
'<tr><td colspan="4">';
1725 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1728 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1729 $sql .=
" c.rowid as contratid";
1730 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1731 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1732 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1735 $resql = $db->query($sql);
1737 $num = $db->num_rows($resql);
1741 $obj = $db->fetch_object($resql);
1743 $rowid = $obj->rowid;
1745 $pu = $obj->subprice;
1746 $vatrate = $obj->vatrate;
1747 $remise_percent = $obj->remise_percent;
1748 $info_bits = $obj->info_bits;
1753 $contratligne->fetch($rowid);
1755 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1756 $total_ht = $result[0];
1757 $total_tva = $result[1];
1758 $total_ttc = $result[2];
1760 $contratligne->total_ht = $total_ht;
1761 $contratligne->total_tva = $total_tva;
1762 $contratligne->total_ttc = $total_ttc;
1764 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);
1766 $contratligne->update_total();
1771 print $langs->trans(
"AlreadyDone");
1778 print
"Error #1 ".$db->error();
1801 $tmpmysoc->setMysoc($conf);
1803 print
'<tr><td colspan="4">';
1806 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1809 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1810 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1811 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
1812 $sql .=
" WHERE cd.fk_commande = c.rowid";
1813 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1816 $resql = $db->query($sql);
1818 $num = $db->num_rows($resql);
1822 $obj = $db->fetch_object($resql);
1824 $rowid = $obj->rowid;
1826 $pu = $obj->subprice;
1827 $vatrate = $obj->vatrate;
1828 $remise_percent = $obj->remise_percent;
1829 $remise_percent_global = $obj->remise_percent_global;
1830 $info_bits = $obj->info_bits;
1834 $commandeligne->fetch($rowid);
1836 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1837 $total_ht = $result[0];
1838 $total_tva = $result[1];
1839 $total_ttc = $result[2];
1841 $commandeligne->total_ht = $total_ht;
1842 $commandeligne->total_tva = $total_tva;
1843 $commandeligne->total_ttc = $total_ttc;
1845 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);
1847 $commandeligne->update_total();
1852 print $langs->trans(
"AlreadyDone");
1869 print
"Error #1 ".$db->error();
1894 $tmpmysoc->setMysoc($conf);
1896 print
'<tr><td colspan="4">';
1899 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
1902 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1903 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1904 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
1905 $sql .=
" WHERE cd.fk_commande = c.rowid";
1906 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1909 $resql = $db->query($sql);
1911 $num = $db->num_rows($resql);
1915 $obj = $db->fetch_object($resql);
1917 $rowid = $obj->rowid;
1919 $pu = $obj->subprice;
1920 $vatrate = $obj->vatrate;
1921 $remise_percent = $obj->remise_percent;
1922 $remise_percent_global = $obj->remise_percent_global;
1923 $info_bits = $obj->info_bits;
1927 $commandeligne->fetch($rowid);
1929 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $mysoc);
1930 $total_ht = $result[0];
1931 $total_tva = $result[1];
1932 $total_ttc = $result[2];
1934 $commandeligne->total_ht = $total_ht;
1935 $commandeligne->total_tva = $total_tva;
1936 $commandeligne->total_ttc = $total_ttc;
1938 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);
1940 $commandeligne->update_total();
1945 print $langs->trans(
"AlreadyDone");
1962 print
"Error #1 ".$db->error();
1987 if (isModEnabled(
'invoice')) {
1988 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
1990 if (count($modellist) == 0) {
1992 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
1993 $resql = $db->query($sql);
2000 if (isModEnabled(
'order')) {
2001 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2003 if (count($modellist) == 0) {
2005 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2006 $resql = $db->query($sql);
2013 if (isModEnabled(
"shipping")) {
2014 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2016 if (count($modellist) == 0) {
2018 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2019 $resql = $db->query($sql);
2042 print
'<tr><td colspan="4">';
2045 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2047 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2048 $obj = $db->fetch_object($result);
2054 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2055 $resql = $db->query($sql);
2058 $num = $db->num_rows($resql);
2062 $obj = $db->fetch_object($resql);
2064 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2065 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2066 $resql2 = $db->query($sql);
2079 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2080 print $langs->trans(
'FieldRenamed').
"<br>\n";
2090 print $langs->trans(
'AlreadyDone').
"<br>\n";
2107 print
'<tr><td colspan="4">';
2110 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2112 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2113 $obj = $db->fetch_object($result);
2119 $sql =
"SELECT l.rowid, l.fk_commande,";
2120 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2121 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2122 $sql .=
" WHERE c.rowid = l.fk_commande";
2123 $resql = $db->query($sql);
2126 $num = $db->num_rows($resql);
2130 $obj = $db->fetch_object($resql);
2132 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2133 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2134 $resql2 = $db->query($sql);
2137 $delivery_date = $db->jdate($obj->delivery_date);
2139 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2140 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2141 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2142 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2143 $resql3 = $db->query($sqlu);
2159 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2160 print $langs->trans(
'FieldRenamed').
"<br>\n";
2170 print $langs->trans(
'AlreadyDone').
"<br>\n";
2187 print
'<tr><td colspan="4">';
2190 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2194 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2195 $obj = $db->fetch_object($result);
2201 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2202 $sql .=
", ld.fk_livraison";
2203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2204 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2205 $resql = $db->query($sql);
2208 $num = $db->num_rows($resql);
2212 $obj = $db->fetch_object($resql);
2214 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2215 $sql .=
" fk_product = ".((int) $obj->fk_product);
2216 $sql .=
",description = '".$db->escape($obj->description).
"'";
2217 $sql .=
",subprice = ".price2num($obj->subprice);
2218 $sql .=
",total_ht = ".price2num($obj->total_ht);
2219 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2220 $resql2 = $db->query($sql);
2223 $sql =
"SELECT total_ht";
2224 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2225 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2226 $resql3 = $db->query($sql);
2229 $obju = $db->fetch_object($resql3);
2230 $total_ht = $obju->total_ht + $obj->total_ht;
2232 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2233 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2234 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2235 $resql4 = $db->query($sqlu);
2255 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2256 print $langs->trans(
'FieldRenamed').
"<br>\n";
2266 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2267 $obj = $db->fetch_object($result);
2269 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2272 print $langs->trans(
'AlreadyDone').
"<br>\n";
2289 print
'<tr><td colspan="4">';
2292 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2298 $sql =
"SELECT SUM(reel) as total, fk_product";
2299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2300 $sql .=
" GROUP BY fk_product";
2301 $resql = $db->query($sql);
2304 $num = $db->num_rows($resql);
2308 $obj = $db->fetch_object($resql);
2310 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2311 $sql .=
" stock = ".price2num($obj->total,
'MS');
2312 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2314 $resql2 = $db->query($sql);
2351 print
'<tr><td colspan="4">';
2354 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2358 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2361 $sql =
"SELECT m.rowid, mc.action";
2362 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2363 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2364 $sql .=
" AND m.enabled = '1'";
2365 $resql = $db->query($sql);
2368 $num = $db->num_rows($resql);
2371 $obj = $db->fetch_object($resql);
2373 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2374 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2375 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2376 $sql .=
" AND enabled = '1'";
2378 $resql2 = $db->query($sql);
2399 print $langs->trans(
'AlreadyDone').
"<br>\n";
2418 print
'<tr><td colspan="4">';
2421 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2425 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2428 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2429 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2430 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2431 $sql .=
" WHERE c.rowid = ce.fk_commande";
2432 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2434 $resql = $db->query($sql);
2437 $num = $db->num_rows($resql);
2441 $obj = $db->fetch_object($resql);
2443 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2444 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2445 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2447 $resql2 = $db->query($sql);
2456 print $langs->trans(
'AlreadyDone').
"<br>\n";
2469 print $langs->trans(
'AlreadyDone').
"<br>\n";
2488 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2490 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2494 print
'<tr><td colspan="4">';
2497 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2503 $table1 =
'facturedet';
2504 $field1 =
'fk_remise_except';
2505 $table2 =
'societe_remise_except';
2506 $field2 =
'fk_facture_line';
2510 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2511 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2512 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2513 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2514 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2517 $resql = $db->query($sql);
2520 $num = $db->num_rows($resql);
2524 $obj = $db->fetch_object($resql);
2526 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2527 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2528 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2529 $sql .=
" WHERE rowid = ".((int) $obj->field);
2531 $resql2 = $db->query($sql);
2540 print $langs->trans(
'AlreadyDone').
"<br>\n";
2556 print
'<tr><td colspan="4">';
2559 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2562 $table2 =
'facturedet';
2563 $field2 =
'fk_remise_except';
2564 $table1 =
'societe_remise_except';
2565 $field1 =
'fk_facture_line';
2569 $sql =
"SELECT t1.rowid, t1.".$field1.
" as field";
2570 $sql .=
" FROM ".MAIN_DB_PREFIX.$table1.
" as t1";
2571 $sql .=
" WHERE t1.".$field1.
" IS NOT NULL AND t1.".$field1.
" NOT IN";
2572 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2.
" as t2";
2573 $sql .=
" WHERE t1.rowid = t2.".$field2.
")";
2576 $resql = $db->query($sql);
2579 $num = $db->num_rows($resql);
2583 $obj = $db->fetch_object($resql);
2585 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2586 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table2.
" SET";
2587 $sql .=
" ".$field2.
" = '".$db->escape($obj->rowid).
"'";
2588 $sql .=
" WHERE rowid = ".((int) $obj->field);
2590 $resql2 = $db->query($sql);
2599 print $langs->trans(
'AlreadyDone').
"<br>\n";
2614 return ($error ? -1 : 1);
2629 print
'<tr><td colspan="4">';
2632 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2634 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2635 $obj = $db->fetch_object($result);
2641 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2642 $resql = $db->query($sql);
2645 $num = $db->num_rows($resql);
2649 $obj = $db->fetch_object($resql);
2651 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2652 $sql2 .=
"datecreate";
2653 $sql2 .=
", statut";
2654 $sql2 .=
", element_id";
2655 $sql2 .=
", fk_c_type_contact";
2656 $sql2 .=
", fk_socpeople";
2657 $sql2 .=
") VALUES (";
2658 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2660 $sql2 .=
", ".$obj->rowid;
2662 $sql2 .=
", ".$obj->fk_user_resp;
2665 if ($obj->fk_user_resp > 0) {
2666 $resql2 = $db->query($sql2);
2679 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2680 if ($db->query($sqlDrop)) {
2693 print $langs->trans(
'AlreadyDone').
"<br>\n";
2710 print
'<tr><td colspan="4">';
2713 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2715 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2720 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2721 $resql = $db->query($sql);
2724 $num = $db->num_rows($resql);
2728 $obj = $db->fetch_object($resql);
2730 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2731 $sql2 .=
"datecreate";
2732 $sql2 .=
", statut";
2733 $sql2 .=
", element_id";
2734 $sql2 .=
", fk_c_type_contact";
2735 $sql2 .=
", fk_socpeople";
2736 $sql2 .=
") VALUES (";
2737 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2739 $sql2 .=
", ".$obj->fk_project_task;
2741 $sql2 .=
", ".$obj->fk_user;
2744 $resql2 = $db->query($sql2);
2756 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2757 if ($db->query($sqlDrop)) {
2770 print $langs->trans(
'AlreadyDone').
"<br>\n";
2790 print
'<tr><td colspan="4">';
2793 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2797 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2802 $sqlSelect =
"SELECT ".$fk_source.
", ".$fk_target;
2803 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2805 $resql = $db->query($sqlSelect);
2808 $num = $db->num_rows($resql);
2812 $obj = $db->fetch_object($resql);
2814 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
2815 $sqlInsert .=
"fk_source";
2816 $sqlInsert .=
", sourcetype";
2817 $sqlInsert .=
", fk_target";
2818 $sqlInsert .=
", targettype";
2819 $sqlInsert .=
") VALUES (";
2820 $sqlInsert .= $obj->$fk_source;
2821 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
2822 $sqlInsert .=
", ".$obj->$fk_target;
2823 $sqlInsert .=
", '".$db->escape($targettype).
"'";
2826 $result = $db->query($sqlInsert);
2835 print $langs->trans(
'AlreadyDone').
"<br>\n";
2839 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$table;
2840 if ($db->query($sqlDrop)) {
2853 print $langs->trans(
'AlreadyDone').
"<br>\n";
2871 print
'<tr><td colspan="4">';
2874 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
2880 $sql =
"SELECT rowid, fk_element, element_duration";
2881 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
2882 $resql = $db->query($sql);
2885 $num = $db->num_rows($resql);
2888 $totaltime = array();
2892 $obj = $db->fetch_object($resql);
2894 if ($obj->element_duration > 0) {
2897 list($hour, $min) = explode(
'.', $obj->element_duration);
2898 $hour = $hour * 60 * 60;
2899 $min = ($min / 100) * 60 * 60;
2900 $newtime = $hour + $min;
2902 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
2903 $sql2 .=
" element_duration = ".((int) $newtime);
2904 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
2906 $resql2 = $db->query($sql2);
2913 if (!empty($totaltime[$obj->fk_element])) {
2914 $totaltime[$obj->fk_element] += $newtime;
2916 $totaltime[$obj->fk_element] = $newtime;
2919 if (!empty($totaltime[$obj->fk_element])) {
2920 $totaltime[$obj->fk_element] += $obj->element_duration;
2922 $totaltime[$obj->fk_element] = $obj->element_duration;
2931 foreach ($totaltime as $taskid => $total_duration) {
2932 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
2933 $sql .=
" duration_effective = ".((int) $total_duration);
2934 $sql .=
" WHERE rowid = ".((int) $taskid);
2936 $resql = $db->query($sql);
2943 print $langs->trans(
'AlreadyDone').
"<br>\n";
2949 print $langs->trans(
'AlreadyDone').
"<br>\n";
2974 print
'<tr><td colspan="4">';
2977 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
2981 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
2982 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
2983 $obj1 = $db->fetch_object($result1);
2984 $obj2 = $db->fetch_object($result2);
2985 if (!$obj1 && !$obj2) {
2990 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
2991 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
2993 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
2994 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
2995 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
2996 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
2997 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
2998 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
2999 $sqlSelect .=
" AND el.targettype = 'shipping'";
3001 $resql = $db->query($sqlSelect);
3004 $num = $db->num_rows($resql);
3008 $obj = $db->fetch_object($resql);
3010 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3011 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3012 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3013 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3015 $result = $db->query($sqlUpdate);
3024 print $langs->trans(
'AlreadyDone').
"<br>\n";
3042 print $langs->trans(
'AlreadyDone').
"<br>\n";
3058 print
'<tr><td colspan="4">';
3061 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3065 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3066 $obj = $db->fetch_object($result);
3072 $sqlSelect =
"SELECT rowid, fk_expedition";
3073 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3074 $sqlSelect .=
" WHERE fk_expedition is not null";
3076 $resql = $db->query($sqlSelect);
3079 $num = $db->num_rows($resql);
3083 $obj = $db->fetch_object($resql);
3085 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3086 $sqlInsert .=
"fk_source";
3087 $sqlInsert .=
", sourcetype";
3088 $sqlInsert .=
", fk_target";
3089 $sqlInsert .=
", targettype";
3090 $sqlInsert .=
") VALUES (";
3091 $sqlInsert .= $obj->fk_expedition;
3092 $sqlInsert .=
", 'shipping'";
3093 $sqlInsert .=
", ".$obj->rowid;
3094 $sqlInsert .=
", 'delivery'";
3097 $result = $db->query($sqlInsert);
3099 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3100 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3102 $result = $db->query($sqlUpdate);
3115 print $langs->trans(
'AlreadyDone').
"<br>\n";
3119 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3120 $db->query($sqlDelete);
3125 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3126 $db->query($sqlDrop);
3136 print $langs->trans(
'AlreadyDone').
"<br>\n";
3153 print
'<tr><td colspan="4">';
3156 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3164 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3165 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3166 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3167 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3168 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3169 $sqlSelect .=
" AND el.targettype = 'delivery'";
3170 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3171 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3173 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3174 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3176 $resql = $db->query($sqlSelect);
3179 $num = $db->num_rows($resql);
3183 $obj = $db->fetch_object($resql);
3185 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3186 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3187 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3188 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3190 $result = $db->query($sqlUpdate);
3199 print $langs->trans(
'AlreadyDone').
"<br>\n";
3226 print
'<tr><td colspan="4">';
3229 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3232 'propal' =>
'propalrowid',
3233 'order' =>
'fk_commande',
3234 'invoice' =>
'fk_facture',
3235 'contract' =>
'fk_contract',
3236 'order_supplier' =>
'fk_supplier_order',
3237 'invoice_supplier' =>
'fk_supplier_invoice'
3240 foreach ($elements as $type => $field) {
3241 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3242 $obj = $db->fetch_object($result);
3248 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3249 $sql .=
"fk_element = ".$field.
", elementtype = '".$db->escape($type).
"'";
3250 $sql .=
" WHERE ".$field.
" IS NOT NULL";
3251 $sql .=
" AND fk_element IS NULL";
3252 $sql .=
" AND elementtype IS NULL";
3254 $resql = $db->query($sql);
3268 print $langs->trans(
'AlreadyDone').
"<br>\n";
3285 print
'<tr><td colspan="4">';
3288 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3291 'old_id' => array(5, 8, 9, 10, 11),
3292 'new_id' => array(50, 51, 52, 53, 54),
3293 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3294 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3298 foreach ($elements[
'old_id'] as $key => $old_id) {
3303 $sqlSelect =
"SELECT id";
3304 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3305 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3306 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3308 $resql = $db->query($sqlSelect);
3310 $num = $db->num_rows($resql);
3316 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3317 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3318 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3319 $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]).
"')";
3320 $resqla = $db->query($sqla);
3322 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3323 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3324 $sql .=
" WHERE id = ".((int) $old_id);
3325 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3326 $resql = $db->query($sql);
3328 if ($resqla && $resql) {
3329 foreach ($elements[
'tables'] as $table) {
3330 $sql =
"UPDATE ".MAIN_DB_PREFIX.$table.
" SET ";
3331 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3332 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3334 $resql = $db->query($sql);
3357 print $langs->trans(
'AlreadyDone').
"<br>\n";
3375 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3377 $obj = $db->fetch_object($result);
3380 $children = array();
3381 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3384 $resql = $db->query($sql);
3386 $num = $db->num_rows($resql);
3387 while ($obj = $db->fetch_object($resql)) {
3388 if (!isset($children[$obj->fk_categorie_fille])) {
3389 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3390 $children[$obj->fk_categorie_fille] = 1;
3391 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3399 if (count($couples) > 0 && $num > count($couples)) {
3405 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3407 $resqld = $db->query($sql);
3410 foreach ($couples as $key => $val) {
3411 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3412 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3414 $resqli = $db->query($sql);
3422 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3423 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3426 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3427 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3432 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3433 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3450 print
'<tr><td colspan="4">';
3453 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3457 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3462 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3463 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3465 $resql = $db->query($sqlSelect);
3468 $num = $db->num_rows($resql);
3472 $obj = $db->fetch_object($resql);
3474 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3475 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3476 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3478 $result = $db->query($sqlUpdate);
3487 print $langs->trans(
'AlreadyDone').
"<br>\n";
3500 print $langs->trans(
'AlreadyDone').
"<br>\n";
3516 print
'<tr><td colspan="4">';
3519 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3527 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3528 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3529 $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";
3530 $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')";
3531 $sqlSelect .=
" ORDER BY a.id";
3534 $resql = $db->query($sqlSelect);
3537 $num = $db->num_rows($resql);
3541 $obj = $db->fetch_object($resql);
3543 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3544 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3546 $result = $db->query($sqlUpdate);
3555 print $langs->trans(
'AlreadyDone').
"<br>\n";
3582 print
'<tr><td colspan="4">';
3585 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3593 $sqlSelect =
"SELECT a.id, a.fk_contact";
3594 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3595 $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";
3596 $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')";
3597 $sqlSelect .=
" ORDER BY a.id";
3600 $resql = $db->query($sqlSelect);
3603 $num = $db->num_rows($resql);
3607 $obj = $db->fetch_object($resql);
3609 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3610 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3612 $result = $db->query($sqlUpdate);
3621 print $langs->trans(
'AlreadyDone').
"<br>\n";
3651 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3653 print
'<tr><td colspan="4">';
3656 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3664 $sqlSelect =
"SELECT DISTINCT entity";
3665 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3669 $resql = $db->query($sqlSelect);
3672 $num = $db->num_rows($resql);
3676 $obj = $db->fetch_object($resql);
3678 print
'Process entity '.$obj->entity;
3680 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3681 $resqlSearch = $db->query($sqlSearch);
3683 $objSearch = $db->fetch_object($resqlSearch);
3685 if ($objSearch && $objSearch->nb == 0) {
3686 print
' - Record for entity must be reset...';
3688 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3689 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3690 $resqlUpdate = $db->query($sqlUpdate);
3691 if (!$resqlUpdate) {
3700 $object->entity = $obj->entity;
3704 $b->setObjectData(
$object,
'MODULE_SET', 0);
3706 $res = $b->create($user);
3712 print
' - '.$langs->trans(
'AlreadyInV7').
'<br>';
3721 print $langs->trans(
'NothingToDo').
"<br>\n";
3748 print
'<tr><td colspan="4">';
3751 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3759 $sqlSelect =
"SELECT sr.rowid, s.entity";
3760 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3761 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3765 $resql = $db->query($sqlSelect);
3768 $num = $db->num_rows($resql);
3772 $obj = $db->fetch_object($resql);
3774 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3775 $sqlUpdate .=
" entity = ".$obj->entity;
3776 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3778 $result = $db->query($sqlUpdate);
3788 print $langs->trans(
'AlreadyDone').
"<br>\n";
3814 print
'<tr><td colspan="4">';
3817 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
3825 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3826 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
3829 $resql = $db->query($sqlSelect);
3832 $num = $db->num_rows($resql);
3836 $obj = $db->fetch_object($resql);
3838 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3839 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3841 $sqlSelect2 =
"SELECT f.entity";
3842 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
3843 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
3844 } elseif (!empty($obj->fk_facture_line)) {
3845 $sqlSelect2 =
"SELECT f.entity";
3846 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
3847 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3848 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
3850 $sqlSelect2 =
"SELECT s.entity";
3851 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
3852 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
3855 $resql2 = $db->query($sqlSelect2);
3857 if ($db->num_rows($resql2) > 0) {
3858 $obj2 = $db->fetch_object($resql2);
3860 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
3861 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
3862 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3864 $result = $db->query($sqlUpdate);
3879 print $langs->trans(
'AlreadyDone').
"<br>\n";
3906 print
'<tr><td colspan="4">';
3908 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
3916 $sqlSelect =
"SELECT u.rowid, u.entity";
3917 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3918 $sqlSelect .=
" WHERE u.entity > 1";
3921 $resql = $db->query($sqlSelect);
3924 $num = $db->num_rows($resql);
3928 $obj = $db->fetch_object($resql);
3930 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
3931 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3932 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
3934 $result = $db->query($sqlUpdate);
3944 print $langs->trans(
'AlreadyDone').
"<br>\n";
3971 print
'<tr><td colspan="4">';
3973 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
3981 $sqlSelect =
"SELECT u.rowid, u.entity";
3982 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
3983 $sqlSelect .=
" WHERE u.entity > 1";
3986 $resql = $db->query($sqlSelect);
3989 $num = $db->num_rows($resql);
3993 $obj = $db->fetch_object($resql);
3995 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
3996 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3997 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
3999 $result = $db->query($sqlUpdate);
4009 print $langs->trans(
'AlreadyDone').
"<br>\n";
4040 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4041 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4042 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4062 $filetodeletearray = array(
4063 '/core/ajax/ajaxcompanies.php',
4064 '/core/triggers/interface_demo.class.php',
4065 '/core/menus/barre_left/default.php',
4066 '/core/menus/barre_top/default.php',
4067 '/core/modules/modComptabiliteExpert.class.php',
4068 '/core/modules/modCommercial.class.php',
4069 '/core/modules/modProduit.class.php',
4070 '/core/modules/modSkype.class.php',
4071 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4072 '/core/triggers/interface_modCommande_Ecotax.class.php',
4073 '/core/triggers/interface_modCommande_fraisport.class.php',
4074 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4075 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4076 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4077 '/core/menus/smartphone/iphone.lib.php',
4078 '/core/menus/smartphone/iphone_backoffice.php',
4079 '/core/menus/smartphone/iphone_frontoffice.php',
4080 '/core/menus/standard/auguria_backoffice.php',
4081 '/core/menus/standard/auguria_frontoffice.php',
4082 '/core/menus/standard/eldy_backoffice.php',
4083 '/core/menus/standard/eldy_frontoffice.php',
4084 '/core/modules/export/export_excel.modules.php',
4085 '/core/modules/export/export_csv.modules.php',
4086 '/core/modules/export/exportcsv.modules.php',
4087 '/core/modules/export/export_excel2007new.modules.php',
4088 '/core/modules/facture/pdf_crabe.modules.php',
4089 '/core/modules/facture/pdf_oursin.modules.php',
4090 '/core/modules/mailings/contacts2.modules.php',
4091 '/core/modules/mailings/contacts3.modules.php',
4092 '/core/modules/mailings/contacts4.modules.php',
4093 '/core/modules/mailings/framboise.modules.php',
4094 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4095 '/core/modules/mailings/peche.modules.php',
4096 '/core/modules/mailings/poire.modules.php',
4097 '/core/modules/mailings/kiwi.modules.php',
4098 '/core/boxes/box_members.php',
4100 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4101 '/includes/nusoap/lib/class.*',
4102 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4103 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4105 '/api/class/api_generic.class.php',
4106 '/asterisk/cidlookup.php',
4107 '/categories/class/api_category.class.php',
4108 '/categories/class/api_deprecated_category.class.php',
4109 '/compta/facture/class/api_invoice.class.php',
4110 '/commande/class/api_commande.class.php',
4111 '/partnership/class/api_partnership.class.php',
4112 '/product/class/api_product.class.php',
4113 '/recruitment/class/api_recruitment.class.php',
4114 '/societe/class/api_contact.class.php',
4115 '/societe/class/api_thirdparty.class.php',
4116 '/support/online.php',
4117 '/takepos/class/actions_takepos.class.php',
4118 '/user/class/api_user.class.php',
4120 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4121 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4122 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4123 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4124 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4125 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4134 foreach ($filetodeletearray as $filetodelete) {
4136 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete) || preg_match(
'/\*/', $filetodelete)) {
4138 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0,
null,
true,
false);
4140 $langs->load(
"errors");
4141 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4142 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4167 $filetodeletearray = array(
4168 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4169 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4173 if (!empty($_SERVER[
"WINDIR"])) {
4174 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4177 foreach ($filetodeletearray as $filetodelete) {
4179 if (file_exists($filetodelete)) {
4183 $langs->load(
"errors");
4184 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4185 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4209 if (count($listofmodule) == 0) {
4213 if (!is_object($user)) {
4214 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4215 $user =
new User($db);
4218 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)));
4220 $reloadactionformodules = array(
4221 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4222 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4223 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4224 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4225 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4226 'MAIN_MODULE_EXTERNALSITE' => array(
'class' =>
'modExternalSite',
'remove' => 1),
4227 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4228 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4229 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4230 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4231 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4232 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4233 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4234 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4235 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4236 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4237 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4238 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4239 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4240 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4241 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4242 'MAIN_MODULE_PAYBOX' => array(
'class' =>
'modPaybox',
'remove' => 1),
4243 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4244 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4245 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4246 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4247 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4248 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4249 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4252 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4253 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4259 if (!empty($reloadactionformodules[$moduletoreload])) {
4260 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4262 $val = $reloadactionformodules[$moduletoreload];
4263 $classformodule = $val[
'class'];
4264 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4266 $mod =
new $classformodule($db);
4267 if (!empty($val[
'remove'])) {
4268 $mod->remove(
'noboxes');
4270 if (!empty($val[
'deleteinsertmenus'])) {
4272 $mod->delete_menus();
4273 $mod->insert_menus();
4275 $mod->init($reloadmode);
4280 $tmp = preg_match(
'/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4281 if (!empty($reg[1])) {
4282 if (strtoupper($moduletoreload) == $moduletoreload) {
4283 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4285 $moduletoreloadshort = $reg[1];
4288 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)");
4290 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4292 $classname =
'mod'.$moduletoreloadshort;
4293 $mod =
new $classname($db);
4296 $mod->delete_menus();
4297 $mod->init($reloadmode);
4299 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4301 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4303 $classname =
'mod'.$moduletoreloadshort;
4304 $mod =
new $classname($db);
4305 $mod->init($reloadmode);
4307 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4308 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4314 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4319 if (!empty($mod) && is_object($mod)) {
4320 print
'<tr class="trforrunsql"><td colspan="4">';
4321 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4322 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4323 print
"<!-- (".$reloadmode.
") -->";
4348 $listofmenuhandler = array();
4351 $listofmenuhandler[
'auguria'] = 1;
4354 foreach ($listofmenuhandler as $key => $val) {
4355 print
'<tr class="trforrunsql"><td colspan="4">';
4359 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4362 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4363 $file =
'init_menu_'.$key.
'.sql';
4364 if (file_exists($dir.$file)) {
4365 $result =
run_sql($dir.$file, 1,
'', 1, $key);
4381 global $conf, $db, $langs, $user;
4383 print
'<tr><td colspan="4">';
4385 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4387 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4388 $fuser =
new User($db);
4389 if (!is_object($user)) {
4393 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4394 $resql = $db->query($sql);
4396 while ($obj = $db->fetch_object($resql)) {
4398 $fuser->id = $obj->uid;
4399 $fuser->entity = $obj->entity;
4402 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4404 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4406 $dir = $conf->user->multidir_output[$entity];
4411 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4412 $destin = $dir.
'/'.$fuser->id;
4420 $handle = opendir($origin_osencoded);
4421 if (is_resource($handle)) {
4422 while (($file = readdir($handle)) !==
false) {
4423 if ($file ==
'.' || $file ==
'..') {
4428 $thumbs = opendir($origin_osencoded.
'/'.$file);
4429 if (is_resource($thumbs)) {
4431 while (($thumb = readdir($thumbs)) !==
false) {
4433 if ($thumb ==
'.' || $thumb ==
'..') {
4439 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4449 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4470 global $db, $langs, $user;
4472 print
'<tr><td colspan="4">';
4474 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4476 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4477 $fuser =
new User($db);
4478 if (!is_object($user)) {
4482 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4483 $resql = $db->query($sql);
4485 while ($obj = $db->fetch_object($resql)) {
4487 $fuser->id = $obj->uid;
4488 $fuser->entity = $obj->entity;
4489 $fuser->photo = $obj->photo;
4492 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4494 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4496 $dir = DOL_DATA_ROOT.
'/users';
4501 $origin = $dir.
'/'.$fuser->id;
4502 $destin = $dir.
'/'.$fuser->id.
'/photos';
4510 $handle = opendir($origin_osencoded);
4511 if (is_resource($handle)) {
4512 while (($file = readdir($handle)) !==
false) {
4513 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4516 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4521 $thumbs = opendir($origin_osencoded.
'/'.$file);
4522 if (is_resource($thumbs)) {
4524 while (($thumb = readdir($thumbs)) !==
false) {
4526 if ($thumb ==
'.' || $thumb ==
'..') {
4532 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb, 0, 0);
4541 dol_copy($origin.
'/'.$file, $destin.
'/'.$file, 0, 0);
4578 print
'<tr><td colspan="4">';
4579 $sql =
'SELECT rowid, socialnetworks';
4580 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
4581 $sql .=
" skype IS NOT NULL OR skype <> ''";
4582 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4583 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4584 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4585 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4586 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4587 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4588 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4589 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4591 $resql = $db->query($sql);
4593 while ($obj = $db->fetch_object($resql)) {
4594 $arraysocialnetworks = array();
4595 if (!empty($obj->skype)) {
4596 $arraysocialnetworks[
'skype'] = $obj->skype;
4598 if (!empty($obj->twitter)) {
4599 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4601 if (!empty($obj->facebook)) {
4602 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4604 if (!empty($obj->linkedin)) {
4605 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4607 if (!empty($obj->instagram)) {
4608 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4610 if (!empty($obj->snapchat)) {
4611 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4613 if (!empty($obj->googleplus)) {
4614 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4616 if (!empty($obj->youtube)) {
4617 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4619 if (!empty($obj->whatsapp)) {
4620 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4622 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4623 $obj->socialnetworks =
'[]';
4625 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4626 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4627 $sqlupd .=
', skype=null';
4628 $sqlupd .=
', twitter=null';
4629 $sqlupd .=
', facebook=null';
4630 $sqlupd .=
', linkedin=null';
4631 $sqlupd .=
', instagram=null';
4632 $sqlupd .=
', snapchat=null';
4633 $sqlupd .=
', googleplus=null';
4634 $sqlupd .=
', youtube=null';
4635 $sqlupd .=
', whatsapp=null';
4636 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4638 $resqlupd = $db->query($sqlupd);
4653 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
4667 print
'<tr><td colspan="4">';
4670 print
'<tr><td colspan="4">';
4671 $sql =
'SELECT rowid, socialnetworks';
4672 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
4673 $sql .=
" skype IS NOT NULL OR skype <> ''";
4674 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4675 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4676 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4677 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4678 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4679 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4680 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4681 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4683 $resql = $db->query($sql);
4685 while ($obj = $db->fetch_object($resql)) {
4686 $arraysocialnetworks = array();
4687 if (!empty($obj->skype)) {
4688 $arraysocialnetworks[
'skype'] = $obj->skype;
4690 if (!empty($obj->twitter)) {
4691 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4693 if (!empty($obj->facebook)) {
4694 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4696 if (!empty($obj->linkedin)) {
4697 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4699 if (!empty($obj->instagram)) {
4700 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4702 if (!empty($obj->snapchat)) {
4703 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4705 if (!empty($obj->googleplus)) {
4706 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4708 if (!empty($obj->youtube)) {
4709 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4711 if (!empty($obj->whatsapp)) {
4712 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4714 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4715 $obj->socialnetworks =
'[]';
4717 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4718 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4719 $sqlupd .=
', skype=null';
4720 $sqlupd .=
', twitter=null';
4721 $sqlupd .=
', facebook=null';
4722 $sqlupd .=
', linkedin=null';
4723 $sqlupd .=
', instagram=null';
4724 $sqlupd .=
', snapchat=null';
4725 $sqlupd .=
', googleplus=null';
4726 $sqlupd .=
', youtube=null';
4727 $sqlupd .=
', whatsapp=null';
4728 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4730 $resqlupd = $db->query($sqlupd);
4745 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
4761 print
'<tr><td colspan="4">';
4762 $sql =
'SELECT rowid, socialnetworks';
4763 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
4764 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
4765 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
4766 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4767 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4768 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4769 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4770 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4771 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4772 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4773 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4775 $resql = $db->query($sql);
4777 while ($obj = $db->fetch_object($resql)) {
4778 $arraysocialnetworks = array();
4779 if (!empty($obj->jabberid)) {
4780 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
4782 if (!empty($obj->skype)) {
4783 $arraysocialnetworks[
'skype'] = $obj->skype;
4785 if (!empty($obj->twitter)) {
4786 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4788 if (!empty($obj->facebook)) {
4789 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4791 if (!empty($obj->linkedin)) {
4792 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4794 if (!empty($obj->instagram)) {
4795 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4797 if (!empty($obj->snapchat)) {
4798 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4800 if (!empty($obj->googleplus)) {
4801 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4803 if (!empty($obj->youtube)) {
4804 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4806 if (!empty($obj->whatsapp)) {
4807 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4809 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4810 $obj->socialnetworks =
'[]';
4812 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4813 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4814 $sqlupd .=
', jabberid=null';
4815 $sqlupd .=
', skype=null';
4816 $sqlupd .=
', twitter=null';
4817 $sqlupd .=
', facebook=null';
4818 $sqlupd .=
', linkedin=null';
4819 $sqlupd .=
', instagram=null';
4820 $sqlupd .=
', snapchat=null';
4821 $sqlupd .=
', googleplus=null';
4822 $sqlupd .=
', youtube=null';
4823 $sqlupd .=
', whatsapp=null';
4824 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4826 $resqlupd = $db->query($sqlupd);
4841 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
4857 print
'<tr><td colspan="4">';
4858 $sql =
'SELECT rowid, socialnetworks';
4859 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
4860 $sql .=
" skype IS NOT NULL OR skype <> ''";
4861 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
4862 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
4863 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
4864 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
4865 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
4866 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
4867 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
4868 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
4870 $resql = $db->query($sql);
4872 while ($obj = $db->fetch_object($resql)) {
4873 $arraysocialnetworks = array();
4874 if (!empty($obj->skype)) {
4875 $arraysocialnetworks[
'skype'] = $obj->skype;
4877 if (!empty($obj->twitter)) {
4878 $arraysocialnetworks[
'twitter'] = $obj->twitter;
4880 if (!empty($obj->facebook)) {
4881 $arraysocialnetworks[
'facebook'] = $obj->facebook;
4883 if (!empty($obj->linkedin)) {
4884 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
4886 if (!empty($obj->instagram)) {
4887 $arraysocialnetworks[
'instagram'] = $obj->instagram;
4889 if (!empty($obj->snapchat)) {
4890 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
4892 if (!empty($obj->googleplus)) {
4893 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
4895 if (!empty($obj->youtube)) {
4896 $arraysocialnetworks[
'youtube'] = $obj->youtube;
4898 if (!empty($obj->whatsapp)) {
4899 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
4901 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
4902 $obj->socialnetworks =
'[]';
4904 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
4905 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
4906 $sqlupd .=
', skype=null';
4907 $sqlupd .=
', twitter=null';
4908 $sqlupd .=
', facebook=null';
4909 $sqlupd .=
', linkedin=null';
4910 $sqlupd .=
', instagram=null';
4911 $sqlupd .=
', snapchat=null';
4912 $sqlupd .=
', googleplus=null';
4913 $sqlupd .=
', youtube=null';
4914 $sqlupd .=
', whatsapp=null';
4915 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4917 $resqlupd = $db->query($sqlupd);
4932 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
4952 print
'<tr class="trforrunsql"><td colspan="4">';
4953 $sql =
'SELECT rowid, field';
4954 if ($mode ==
'export') {
4957 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
4958 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
4960 $resql = $db->query($sql);
4962 while ($obj = $db->fetch_object($resql)) {
4963 $oldfield = $obj->field;
4964 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
4966 if ($mode ==
'export') {
4967 $oldfilter = $obj->filter;
4968 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
4974 if ($oldfield != $newfield || $oldfilter != $newfilter) {
4975 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
4976 if ($mode ==
'export') {
4977 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
4979 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
4980 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
4981 $resqlupd = $db->query($sqlupd);
4997 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5000 if ($resultstring) {
5001 print $resultstring;
5003 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5020 print
'<tr class="trforrunsql"><td colspan="4">';
5021 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5023 $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";
5024 $sql .=
" ORDER BY c.rowid,cd.rowid";
5026 $resql = $db->query($sql);
5029 $current_contract = 0;
5030 while ($obj = $db->fetch_object($resql)) {
5031 if (empty($current_contract) || $current_contract == $obj->cid) {
5037 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5038 $resultstring =
'.';
5039 print $resultstring;
5040 $resqlUpd = $db->query($sqlUpd);
5046 $current_contract = $obj->cid;
5059 if (!$resultstring) {
5060 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Class to manage Blocked Log.
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Re-enable features modules.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
if($db->connected) if( $ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondence des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignment to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondence des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_element_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.