44define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
45include_once
'inc.php';
52 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").';
71@phan-var-force string $dolibarr_main_db_type
74require_once $dolibarr_main_document_root.
'/compta/facture/class/facture.class.php';
75require_once $dolibarr_main_document_root.
'/comm/propal/class/propal.class.php';
76require_once $dolibarr_main_document_root.
'/contrat/class/contrat.class.php';
77require_once $dolibarr_main_document_root.
'/commande/class/commande.class.php';
78require_once $dolibarr_main_document_root.
'/fourn/class/fournisseur.commande.class.php';
79require_once $dolibarr_main_document_root.
'/core/lib/price.lib.php';
80require_once $dolibarr_main_document_root.
'/core/class/menubase.class.php';
81require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
82require_once $dolibarr_main_document_root.
'/core/lib/files.lib.php';
83require_once $dolibarr_main_document_root.
'/user/class/user.class.php';
84require_once $dolibarr_main_document_root.
'/blockedlog/lib/blockedlog.lib.php';
93$err = error_reporting();
100error_reporting($err);
102$setuplang =
GETPOST(
"selectlang",
'aZ09', 3) ?
GETPOST(
"selectlang",
'aZ09', 3) :
'auto';
103$langs->setDefaultLang($setuplang);
104$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
105$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
106$enablemodules =
GETPOST(
"enablemodules",
'alpha', 3) ?
GETPOST(
"enablemodules",
'alpha', 3) : (empty($argv[3]) ?
'' : $argv[3]);
108$langs->loadLangs(array(
"admin",
"install",
"bills",
"suppliers"));
110if ($dolibarr_main_db_type ==
'mysqli') {
113if ($dolibarr_main_db_type ==
'pgsql') {
116if ($dolibarr_main_db_type ==
'mssql') {
121dolibarr_install_syslog(
"--- upgrade2: entering upgrade2.php page ".$versionfrom.
" ".$versionto.
" ".$enablemodules);
122if (!is_object(
$conf)) {
132if ((!$versionfrom || preg_match(
'/version/', $versionfrom)) && (!$versionto || preg_match(
'/version/', $versionto))) {
133 print
'Error: Parameter versionfrom or versionto missing or having a bad format.'.
"\n";
134 print
'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'.
"\n";
136 $sapi_type = php_sapi_name();
137 $script_file = basename(__FILE__);
138 if (substr($sapi_type, 0, 3) ==
'cli') {
139 print
'Syntax from command line: '.$script_file.
" x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
140 print
'Example, upgrade from 19 to 20: '.$script_file.
" 19.0.0 20.0.0\n";
141 print
'Example, enable a module only: '.$script_file.
" 0.0.0 0.0.0 MAIN_MODULE_Adherent\n";
147pHeader(
'',
'step5',
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'upgrade',
'versionfrom='.$versionfrom.
'&versionto='.$versionto,
'',
'main-inside main-inside-borderbottom');
152if (!
GETPOST(
'action',
'aZ09') || preg_match(
'/upgrade/i',
GETPOST(
'action',
'aZ09'))) {
153 print
'<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> ';
154 print
'<span class="inline-block valignmiddle">'.$langs->trans(
'DataMigration').
'</span></h3>';
156 print
'<table class="centpercent">';
159 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/(crypted|dolcrypt):/i', (
string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
160 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
161 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
162 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', (
string) $dolibarr_main_db_pass);
163 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
164 $dolibarr_main_db_pass =
dol_decode((
string) $dolibarr_main_db_pass);
165 } elseif (preg_match(
'/dolcrypt:/i', (
string) $dolibarr_main_db_pass)) {
166 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
167 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
169 $dolibarr_main_db_pass =
dol_decode((
string) $dolibarr_main_db_encrypted_pass);
174 $conf->db->type = $dolibarr_main_db_type;
175 $conf->db->host = $dolibarr_main_db_host;
176 $conf->db->port = $dolibarr_main_db_port;
177 $conf->db->name = $dolibarr_main_db_name;
178 $conf->db->user = $dolibarr_main_db_user;
179 $conf->db->pass = $dolibarr_main_db_pass;
183 if (!$db->connected) {
184 print
'<tr><td colspan="4">'.$langs->trans(
"ErrorFailedToConnectToDatabase",
$conf->db->name).
'</td><td class="right">'.$langs->trans(
'Error').
'</td></tr>';
190 if ($db->database_selected) {
197 if (empty($dolibarr_main_db_encryption)) {
198 $dolibarr_main_db_encryption = 0;
200 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
201 if (empty($dolibarr_main_db_cryptkey)) {
202 $dolibarr_main_db_cryptkey =
'';
204 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
207 $conf->setValues($db);
211 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
212 $conf->modules[
'syslog'] =
'syslog';
213 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
214 if (!defined(
'SYSLOG_HANDLERS')) {
215 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
217 if (!defined(
'SYSLOG_FILE')) {
218 if (@is_writable(
'/tmp')) {
219 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
220 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
221 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
222 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
223 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
224 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
225 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
226 } elseif (@is_writable(
'../../')) {
227 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
231 if (defined(
'SYSLOG_FILE')) {
232 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
234 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
235 define(
'SYSLOG_FILE_NO_ERROR', 1);
238 $handlers = array(
'mod_syslog_file');
239 foreach ($handlers as $handler) {
240 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
241 if (!file_exists($file)) {
242 throw new Exception(
'Missing log handler file '.$handler.
'.php');
246 $loghandlerinstance =
new $handler();
247 if (!$loghandlerinstance instanceof
LogHandler) {
248 throw new Exception(
'Log handler does not extend LogHandler');
251 if (empty(
$conf->loghandlers[$handler])) {
252 $conf->loghandlers[$handler] = $loghandlerinstance;
257 $listofentities = array(1);
260 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
262 $hookmanager->initHooks(array(
'upgrade2'));
264 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
267 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
268 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
270 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
280 dol_syslog(
"Process upgrade2 (step common to all entities)");
283 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
285 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
287 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
289 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
291 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
293 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
295 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
297 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
299 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
301 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
303 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
309 foreach ($listofentities as $entity) {
310 dol_syslog(
"Process upgrade2 (step a) for entity ".$entity);
313 $conf->setEntityValues($db, $entity);
316 if (defined(
'SYSLOG_FILE')) {
317 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
320 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
322 $versiontoarray = array();
323 $versionranarray = array();
325 dol_syslog(
"Process upgrade2 (step b) for entity ".$entity);
328 if (count($listofentities) > 1) {
329 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
340 $versiontoarray = explode(
'.', $versionto);
341 $versionranarray = explode(
'.', DOL_VERSION);
343 $afterversionarray = explode(
'.',
'2.0.0');
344 $beforeversionarray = explode(
'.',
'2.7.9');
346 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
407 $afterversionarray = explode(
'.',
'2.7.9');
408 $beforeversionarray = explode(
'.',
'2.8.9');
411 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
435 $afterversionarray = explode(
'.',
'2.8.9');
436 $beforeversionarray = explode(
'.',
'2.9.9');
438 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
450 $afterversionarray = explode(
'.',
'2.9.9');
451 $beforeversionarray = explode(
'.',
'3.0.9');
457 $afterversionarray = explode(
'.',
'3.0.9');
458 $beforeversionarray = explode(
'.',
'3.1.9');
460 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
468 $afterversionarray = explode(
'.',
'3.1.9');
469 $beforeversionarray = explode(
'.',
'3.2.9');
471 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
481 $afterversionarray = explode(
'.',
'3.2.9');
482 $beforeversionarray = explode(
'.',
'3.3.9');
484 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
493 $afterversionarray = explode(
'.',
'3.6.9');
494 $beforeversionarray = explode(
'.',
'3.7.9');
496 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
502 $afterversionarray = explode(
'.',
'3.7.9');
503 $beforeversionarray = explode(
'.',
'3.8.9');
509 $afterversionarray = explode(
'.',
'3.9.9');
510 $beforeversionarray = explode(
'.',
'4.0.9');
512 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
518 $afterversionarray = explode(
'.',
'4.0.9');
519 $beforeversionarray = explode(
'.',
'5.0.9');
521 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
531 $afterversionarray = explode(
'.',
'5.0.9');
532 $beforeversionarray = explode(
'.',
'6.0.9');
535 global $multicompany_transverse_mode;
538 if (empty($multicompany_transverse_mode)) {
539 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
551 $afterversionarray = explode(
'.',
'6.0.9');
552 $beforeversionarray = explode(
'.',
'7.0.9');
554 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
563 $afterversionarray = explode(
'.',
'7.0.9');
564 $beforeversionarray = explode(
'.',
'8.0.9');
566 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
572 $afterversionarray = explode(
'.',
'8.0.9');
573 $beforeversionarray = explode(
'.',
'9.0.9');
579 $afterversionarray = explode(
'.',
'10.0.9');
580 $beforeversionarray = explode(
'.',
'11.0.9');
582 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
591 $afterversionarray = explode(
'.',
'13.0.9');
592 $beforeversionarray = explode(
'.',
'14.0.9');
594 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
601 $afterversionarray = explode(
'.',
'15.0.9');
602 $beforeversionarray = explode(
'.',
'16.0.9');
604 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
611 $afterversionarray = explode(
'.',
'16.0.9');
612 $beforeversionarray = explode(
'.',
'17.0.9');
614 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
620 $afterversionarray = explode(
'.',
'17.0.9');
621 $beforeversionarray = explode(
'.',
'18.0.9');
623 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
637 $afterversionarray = explode(
'.',
'19.0.9');
638 $beforeversionarray = explode(
'.',
'20.0.9');
640 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
646 $afterversionarray = explode(
'.',
'20.0.9');
647 $beforeversionarray = explode(
'.',
'21.0.9');
651 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
657 $afterversionarray = explode(
'.',
'21.0.9');
658 $beforeversionarray = explode(
'.',
'22.0.9');
660 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
666 $afterversionarray = explode(
'.',
'22.0.9');
667 $beforeversionarray = explode(
'.',
'23.0.9');
669 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
679 $afterversionarray = explode(
'.',
'23.0.9');
680 $beforeversionarray = explode(
'.',
'24.0.9');
682 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
692 dol_syslog(
"Run migrate_... if migration is LAST ONE");
695 $listofmodule = array(
696 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
697 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
698 'MAIN_MODULE_BOM' =>
'menuonly',
699 'MAIN_MODULE_BANQUE' =>
'menuonly',
700 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
701 'MAIN_MODULE_CRON' =>
'newboxdefonly',
702 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
703 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
704 'MAIN_MODULE_DON' =>
'newboxdefonly',
705 'MAIN_MODULE_ECM' =>
'newboxdefonly',
706 'MAIN_MODULE_EVENTORGANIZATION' =>
'newboxdefonly',
707 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
708 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
709 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
710 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
711 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
712 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
713 'MAIN_MODULE_MARGIN' =>
'menuonly',
714 'MAIN_MODULE_MRP' =>
'menuonly',
715 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
716 'MAIN_MODULE_PARTNERSHIP' =>
'newboxdefonly',
717 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
718 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
719 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
720 'MAIN_MODULE_RESOURCE' =>
'noboxes',
721 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
722 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
724 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
725 'MAIN_MODULE_STRIPE' =>
'menuonly',
726 'MAIN_MODULE_SUBTOTALS' =>
'menuonly',
727 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
728 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
729 'MAIN_MODULE_USER' =>
'newboxdefonly',
730 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
731 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
757 if (!$error && $enablemodules) {
759 $listofmodules = array();
760 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
761 $tmplistofmodules = explode(
',', $enablemodules);
762 foreach ($tmplistofmodules as $value) {
763 $listofmodules[$value] =
'forceactivate';
767 if ($resultreloadmodules < 0) {
775 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
778 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
779 if ($hookmanager->resNbOfHooks > 0) {
781 print
'<tr><td colspan="4">';
782 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
783 print $hookmanager->error;
784 print
"<!-- (".$reshook.
") -->";
787 print
'<tr class="trforrunsql"><td colspan="4">';
788 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
789 print
"<!-- (".$reshook.
") -->";
794 if (!empty(
$conf->modules_parts[
'hooks'])) {
795 print
'<tr class="trforrunsql"><td colspan="4">';
796 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
807 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
822 foreach ($listofentities as $entity) {
824 $conf->setEntityValues($db, $entity);
826 if (defined(
'SYSLOG_FILE')) {
827 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
829 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
833 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
834 $destroot = DOL_DATA_ROOT.
'/medias';
847 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
850 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
851 if ($hookmanager->resNbOfHooks > 0) {
853 print
'<tr><td colspan="4">';
854 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
855 print $hookmanager->error;
856 print
"<!-- (".$reshook.
") -->";
859 print
'<tr class="trforrunsql"><td colspan="4">';
860 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
861 print
"<!-- (".$reshook.
") -->";
866 if (!empty(
$conf->modules_parts[
'hooks'])) {
867 print
'<tr class="trforrunsql"><td colspan="4">';
868 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
878 print
'<table width="100%">';
879 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
880 print
'<td class="right">';
884 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
888 print
'<script type="text/javascript">
889 jQuery(document).ready(function() {
890 function init_trrunsql()
892 console.log("toggle .trforrunsql");
893 jQuery(".trforrunsql").toggle();
896 jQuery(".trforrunsqlshowhide").click(function() {
901 print
'<a class="reposition trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
904 print
'</td></tr>'.
"\n";
910 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
915if ($error && isset($argv[1])) {
921pFooter($error ? 2 : 0, $setuplang);
923if ($db !==
null && $db->connected) {
944 print
'<tr><td colspan="4">';
947 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
949 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
950 $obj = $db->fetch_object($result);
952 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
953 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
954 $sql .=
" WHERE p.fk_facture > 0";
956 $resql = $db->query($sql);
963 $num = $db->num_rows($resql);
966 $obj = $db->fetch_object($resql);
967 $row[$i][0] = $obj->rowid;
968 $row[$i][1] = $obj->fk_facture;
969 $row[$i][2] = $obj->amount;
973 dol_print_error($db);
977 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
981 for ($i = 0; $i < $num; $i++) {
982 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
983 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
985 $res += $db->query($sql);
987 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
989 $res += $db->query($sql);
991 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
995 if (is_array($row) && $res == (2 * count($row))) {
997 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1000 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1003 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
1006 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
1024 print
'<tr><td colspan="4">';
1027 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
1029 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
1030 $obj = $db->fetch_object($result);
1033 $sql =
"SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1034 $sql .=
" bu2.url_id as socid";
1035 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
1036 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
1037 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
1038 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
1039 $sql .=
" AND b.rappro = 1";
1040 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1042 $resql = $db->query($sql);
1048 $num = $db->num_rows($resql);
1051 $obj = $db->fetch_object($resql);
1052 if ($obj->pamount == $obj->bamount && $obj->socid) {
1053 $row[$j][
'paymentid'] = $obj->rowid;
1054 $row[$j][
'pamount'] = $obj->pamount;
1055 $row[$j][
'fk_bank'] = $obj->fk_bank;
1056 $row[$j][
'bamount'] = $obj->bamount;
1057 $row[$j][
'socid'] = $obj->socid;
1058 $row[$j][
'datec'] = $obj->datec;
1064 dol_print_error($db);
1068 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
1073 for ($i = 0; $i < $num; $i++) {
1075 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>';
1079 $sql =
" SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1080 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1081 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1082 $sql .=
" AND pf.fk_facture IS NULL";
1083 $sql .=
" ORDER BY f.fk_statut";
1085 $resql = $db->query($sql);
1087 $num = $db->num_rows($resql);
1090 $obj = $db->fetch_object($resql);
1091 $facid = $obj->rowid;
1093 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1094 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1096 $res += $db->query($sql);
1098 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1106 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1108 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1113 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1116 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1134 print
'<tr><td colspan="4">';
1137 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
1139 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
1140 $obj = $db->fetch_object($result);
1143 $sql =
"SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1144 $sql .=
" bu2.url_id as socid";
1145 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
1146 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
1147 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
1148 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
1149 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1151 $resql = $db->query($sql);
1157 $num = $db->num_rows($resql);
1160 $obj = $db->fetch_object($resql);
1161 if ($obj->pamount == $obj->bamount && $obj->socid) {
1162 $row[$j][
'paymentid'] = $obj->rowid;
1163 $row[$j][
'pamount'] = $obj->pamount;
1164 $row[$j][
'fk_bank'] = $obj->fk_bank;
1165 $row[$j][
'bamount'] = $obj->bamount;
1166 $row[$j][
'socid'] = $obj->socid;
1167 $row[$j][
'datec'] = $obj->datec;
1173 dol_print_error($db);
1180 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
1184 for ($i = 0; $i < $num; $i++) {
1186 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>';
1190 $sql =
" SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1191 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1192 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1193 $sql .=
" AND pf.fk_facture IS NULL";
1194 $sql .=
" ORDER BY f.fk_statut";
1196 $resql = $db->query($sql);
1198 $num = $db->num_rows($resql);
1201 $obj = $db->fetch_object($resql);
1202 $facid = $obj->rowid;
1204 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1205 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1207 $res += $db->query($sql);
1209 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1218 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1220 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1225 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1231 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1241 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1258 print
'<tr><td colspan="4">';
1263 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1265 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1266 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1268 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1269 $sql .=
" ON c.fk_product = p.rowid";
1270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1271 $sql .=
" ON c.rowid=cd.fk_contrat";
1272 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1273 $resql = $db->query($sql);
1279 $num = $db->num_rows($resql);
1282 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1286 $obj = $db->fetch_object($resql);
1288 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1289 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1290 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1291 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1292 $sql .=
" VALUES (";
1293 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1295 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1296 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1299 $sql .= ((float) $obj->tva_tx).
", 1, ";
1300 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1304 if ($db->query($sql)) {
1305 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1307 dol_print_error($db);
1317 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1320 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1323 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1326 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1343 print
'<tr><td colspan="4">';
1348 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1350 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1351 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1352 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1353 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1354 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1355 $sql .=
" AND bu.fk_bank IS NULL";
1356 $resql = $db->query($sql);
1362 $num = $db->num_rows($resql);
1365 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1369 $obj = $db->fetch_object($resql);
1371 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1372 $sql .=
"fk_bank, url_id, url, label, type";
1374 $sql .=
" VALUES (";
1375 $sql .= ((int) $obj->barowid).
",".((int) $obj->bbrowid).
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1381 if (!$db->query($sql)) {
1382 dol_print_error($db);
1392 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1395 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1398 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1401 dol_print_error($db);
1417 print
'<tr><td colspan="4">';
1420 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1422 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1424 $resql = $db->query($sql);
1426 dol_print_error($db);
1428 if ($db->affected_rows($resql) > 0) {
1429 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1431 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1434 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1436 $resql = $db->query($sql);
1438 dol_print_error($db);
1440 if ($db->affected_rows($resql) > 0) {
1441 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1443 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1459 print
'<tr><td colspan="4">';
1464 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1466 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1468 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1469 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1470 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1471 $resql = $db->query($sql);
1477 $num = $db->num_rows($resql);
1480 $nbcontratsmodifie = 0;
1484 $obj = $db->fetch_object($resql);
1485 if ($obj->date_contrat > $obj->datemin) {
1486 $datemin = $db->jdate($obj->datemin);
1488 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1489 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1490 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1491 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1492 $resql2 = $db->query($sql);
1494 dol_print_error($db);
1497 $nbcontratsmodifie++;
1504 if ($nbcontratsmodifie) {
1505 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1507 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1511 dol_print_error($db);
1527 print
'<tr><td colspan="4">';
1530 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1532 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1534 $resql = $db->query($sql);
1536 dol_print_error($db);
1538 if ($db->affected_rows($resql) > 0) {
1539 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1541 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1557 print
'<tr><td colspan="4">';
1560 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1562 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1563 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1565 $resql = $db->query($sql);
1567 dol_print_error($db);
1569 if ($db->affected_rows($resql) > 0) {
1572 $num = $db->num_rows($resql);
1575 $nbcontratsmodifie = 0;
1579 $obj = $db->fetch_object($resql);
1581 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1582 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1583 $sql .=
" SET statut = 1";
1584 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1585 $resql2 = $db->query($sql);
1587 dol_print_error($db);
1590 $nbcontratsmodifie++;
1597 if ($nbcontratsmodifie) {
1598 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1600 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1604 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1622 print
'<tr><td colspan="4">';
1624 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1627 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1628 $obj = $db->fetch_object($result);
1633 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1634 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1635 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1638 $select_resql = $db->query($select_sql);
1639 if ($select_resql) {
1640 $select_num = $db->num_rows($select_resql);
1644 while (($i < $select_num) && (!$error)) {
1645 $select_obj = $db->fetch_object($select_resql);
1648 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1649 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1650 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1651 $check_resql = $db->query($check_sql);
1653 $check_num = $db->num_rows($check_resql);
1654 if ($check_num == 0) {
1658 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1659 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1662 print
'<tr class="oddeven">';
1663 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1665 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1666 $insert_sql .=
' fk_paiementfourn = \''.((int) $select_obj->rowid).
'\',
';
1667 $insert_sql .= ' fk_facturefourn = \
''.((int) $select_obj->fk_facture_fourn).
'\',
';
1668 $insert_sql .= ' amount = \
''.((float) $select_obj->amount).
'\'';
1669 $insert_resql = $db->query($insert_sql);
1671 if ($insert_resql) {
1673 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1675 print
'<td><span class="error">Error on insert</span></td>';
1691 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1695 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1698 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1702 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1719 $tmpmysoc->setMysoc(
$conf);
1723 print
'<tr><td colspan="4">';
1726 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1729 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1730 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1731 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1732 $sql .=
" WHERE fd.fk_facture = f.rowid";
1733 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1737 $resql = $db->query($sql);
1739 $num = $db->num_rows($resql);
1743 $obj = $db->fetch_object($resql);
1745 $rowid = $obj->rowid;
1747 $pu = $obj->subprice;
1748 $vatrate = $obj->vatrate;
1749 $remise_percent = $obj->remise_percent;
1750 $remise_percent_global = $obj->remise_percent_global;
1751 $total_ttc_f = $obj->total_ttc_f;
1752 $info_bits = $obj->info_bits;
1756 $facligne->fetch($rowid);
1758 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1759 $total_ht = $result[0];
1760 $total_tva = $result[1];
1761 $total_ttc = $result[2];
1763 $facligne->total_ht = (float) $total_ht;
1764 $facligne->total_tva = (float) $total_tva;
1765 $facligne->total_ttc = (float) $total_ttc;
1767 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);
1769 $facligne->update_total();
1773 if (!$total_ttc_f) {
1775 $facture->id = $obj->facid;
1777 if ($facture->fetch($facture->id) >= 0) {
1778 if ($facture->update_price() > 0) {
1781 print
"Error id=".$facture->id;
1794 print $langs->trans(
"AlreadyDone");
1800 print
"Error #1 ".$db->error();
1822 $tmpmysoc->setMysoc(
$conf);
1826 print
'<tr><td colspan="4">';
1829 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1832 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1833 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1834 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1835 $sql .=
" WHERE pd.fk_propal = p.rowid";
1836 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1839 $resql = $db->query($sql);
1841 $num = $db->num_rows($resql);
1845 $obj = $db->fetch_object($resql);
1847 $rowid = $obj->rowid;
1849 $pu = $obj->subprice;
1850 $vatrate = $obj->vatrate;
1851 $remise_percent = $obj->remise_percent;
1852 $remise_percent_global = $obj->remise_percent_global;
1853 $info_bits = $obj->info_bits;
1857 $propalligne->fetch($rowid);
1859 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1860 $total_ht = $result[0];
1861 $total_tva = $result[1];
1862 $total_ttc = $result[2];
1864 $propalligne->total_ht = (float) $total_ht;
1865 $propalligne->total_tva = (float) $total_tva;
1866 $propalligne->total_ttc = (float) $total_ttc;
1868 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);
1870 $propalligne->update_total();
1875 print $langs->trans(
"AlreadyDone");
1882 print
"Error #1 ".$db->error();
1905 $tmpmysoc->setMysoc(
$conf);
1906 if (empty($tmpmysoc->country_id)) {
1907 $tmpmysoc->country_id = 0;
1910 print
'<tr><td colspan="4">';
1913 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1916 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1917 $sql .=
" c.rowid as contratid";
1918 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1919 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1920 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1923 $resql = $db->query($sql);
1925 $num = $db->num_rows($resql);
1929 $obj = $db->fetch_object($resql);
1931 $rowid = $obj->rowid;
1933 $pu = $obj->subprice;
1934 $vatrate = $obj->vatrate;
1935 $remise_percent = $obj->remise_percent;
1936 $info_bits = $obj->info_bits;
1941 $contratligne->fetch($rowid);
1943 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1944 $total_ht = $result[0];
1945 $total_tva = $result[1];
1946 $total_ttc = $result[2];
1948 $contratligne->total_ht = (float) $total_ht;
1949 $contratligne->total_tva = (float) $total_tva;
1950 $contratligne->total_ttc = (float) $total_ttc;
1952 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);
1954 $contratligne->update_total();
1959 print $langs->trans(
"AlreadyDone");
1966 print
"Error #1 ".$db->error();
1989 $tmpmysoc->setMysoc(
$conf);
1991 print
'<tr><td colspan="4">';
1994 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
1997 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1998 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
1999 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
2000 $sql .=
" WHERE cd.fk_commande = c.rowid";
2001 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2004 $resql = $db->query($sql);
2006 $num = $db->num_rows($resql);
2010 $obj = $db->fetch_object($resql);
2012 $rowid = $obj->rowid;
2014 $pu = $obj->subprice;
2015 $vatrate = $obj->vatrate;
2016 $remise_percent = $obj->remise_percent;
2017 $remise_percent_global = $obj->remise_percent_global;
2018 $info_bits = $obj->info_bits;
2022 $commandeligne->fetch($rowid);
2024 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
2025 $total_ht = $result[0];
2026 $total_tva = $result[1];
2027 $total_ttc = $result[2];
2029 $commandeligne->total_ht = (float) $total_ht;
2030 $commandeligne->total_tva = (float) $total_tva;
2031 $commandeligne->total_ttc = (float) $total_ttc;
2033 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);
2035 $commandeligne->update_total();
2040 print $langs->trans(
"AlreadyDone");
2057 print
"Error #1 ".$db->error();
2082 $tmpmysoc->setMysoc(
$conf);
2084 print
'<tr><td colspan="4">';
2087 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
2090 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2091 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
2092 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
2093 $sql .=
" WHERE cd.fk_commande = c.rowid";
2094 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2097 $resql = $db->query($sql);
2099 $num = $db->num_rows($resql);
2103 $obj = $db->fetch_object($resql);
2105 $rowid = $obj->rowid;
2107 $pu = $obj->subprice;
2108 $vatrate = $obj->vatrate;
2109 $remise_percent = $obj->remise_percent;
2110 $remise_percent_global = $obj->remise_percent_global;
2111 $info_bits = $obj->info_bits;
2115 $commandeligne->fetch($rowid);
2117 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type,
$mysoc);
2118 $total_ht = $result[0];
2119 $total_tva = $result[1];
2120 $total_ttc = $result[2];
2122 $commandeligne->total_ht = (float) $total_ht;
2123 $commandeligne->total_tva = (float) $total_tva;
2124 $commandeligne->total_ttc = (float) $total_ttc;
2126 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);
2128 $commandeligne->update_total();
2133 print $langs->trans(
"AlreadyDone");
2150 print
"Error #1 ".$db->error();
2176 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2178 if (count($modellist) == 0) {
2180 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2181 $resql = $db->query($sql);
2183 dol_print_error($db);
2189 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2191 if (count($modellist) == 0) {
2193 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2194 $resql = $db->query($sql);
2196 dol_print_error($db);
2202 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2204 if (count($modellist) == 0) {
2206 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2207 $resql = $db->query($sql);
2209 dol_print_error($db);
2230 print
'<tr><td colspan="4">';
2233 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2235 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2236 $obj = $db->fetch_object($result);
2242 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2243 $resql = $db->query($sql);
2246 $num = $db->num_rows($resql);
2250 $obj = $db->fetch_object($resql);
2252 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2253 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2254 $resql2 = $db->query($sql);
2258 dol_print_error($db);
2267 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2268 print $langs->trans(
'FieldRenamed').
"<br>\n";
2274 dol_print_error($db);
2278 print $langs->trans(
'AlreadyDone').
"<br>\n";
2295 print
'<tr><td colspan="4">';
2298 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2300 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2301 $obj = $db->fetch_object($result);
2307 $sql =
"SELECT l.rowid, l.fk_commande,";
2308 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2310 $sql .=
" WHERE c.rowid = l.fk_commande";
2311 $resql = $db->query($sql);
2314 $num = $db->num_rows($resql);
2318 $obj = $db->fetch_object($resql);
2320 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2321 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2322 $resql2 = $db->query($sql);
2325 $delivery_date = $db->jdate($obj->delivery_date);
2327 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2328 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2329 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2330 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2331 $resql3 = $db->query($sqlu);
2334 dol_print_error($db);
2338 dol_print_error($db);
2347 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2348 print $langs->trans(
'FieldRenamed').
"<br>\n";
2354 dol_print_error($db);
2358 print $langs->trans(
'AlreadyDone').
"<br>\n";
2375 print
'<tr><td colspan="4">';
2378 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2382 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2383 $obj = $db->fetch_object($result);
2389 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2390 $sql .=
", ld.fk_livraison";
2391 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2392 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2393 $resql = $db->query($sql);
2396 $num = $db->num_rows($resql);
2400 $obj = $db->fetch_object($resql);
2402 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2403 $sql .=
" fk_product = ".((int) $obj->fk_product);
2404 $sql .=
",description = '".$db->escape($obj->description).
"'";
2405 $sql .=
",subprice = ".price2num($obj->subprice);
2406 $sql .=
",total_ht = ".price2num($obj->total_ht);
2407 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2408 $resql2 = $db->query($sql);
2411 $sql =
"SELECT total_ht";
2412 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2413 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2414 $resql3 = $db->query($sql);
2417 $obju = $db->fetch_object($resql3);
2418 $total_ht = $obju->total_ht + $obj->total_ht;
2420 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2421 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2422 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2423 $resql4 = $db->query($sqlu);
2426 dol_print_error($db);
2430 dol_print_error($db);
2434 dol_print_error($db);
2443 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2444 print $langs->trans(
'FieldRenamed').
"<br>\n";
2450 dol_print_error($db);
2454 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2455 $obj = $db->fetch_object($result);
2457 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2460 print $langs->trans(
'AlreadyDone').
"<br>\n";
2477 print
'<tr><td colspan="4">';
2480 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2486 $sql =
"SELECT SUM(reel) as total, fk_product";
2487 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2488 $sql .=
" GROUP BY fk_product";
2489 $resql = $db->query($sql);
2492 $num = $db->num_rows($resql);
2496 $obj = $db->fetch_object($resql);
2498 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2499 $sql .=
" stock = ".price2num($obj->total,
'MS');
2500 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2502 $resql2 = $db->query($sql);
2506 dol_print_error($db);
2519 dol_print_error($db);
2539 print
'<tr><td colspan="4">';
2542 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2546 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2549 $sql =
"SELECT m.rowid, mc.action";
2550 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2551 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2552 $sql .=
" AND m.enabled = '1'";
2553 $resql = $db->query($sql);
2556 $num = $db->num_rows($resql);
2559 $obj = $db->fetch_object($resql);
2561 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2562 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2563 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2564 $sql .=
" AND enabled = '1'";
2566 $resql2 = $db->query($sql);
2570 dol_print_error($db);
2583 dol_print_error($db);
2587 print $langs->trans(
'AlreadyDone').
"<br>\n";
2606 print
'<tr><td colspan="4">';
2609 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2613 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2616 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2618 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2619 $sql .=
" WHERE c.rowid = ce.fk_commande";
2620 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2622 $resql = $db->query($sql);
2625 $num = $db->num_rows($resql);
2629 $obj = $db->fetch_object($resql);
2631 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2632 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2633 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2635 $resql2 = $db->query($sql);
2638 dol_print_error($db);
2644 print $langs->trans(
'AlreadyDone').
"<br>\n";
2653 dol_print_error($db);
2657 print $langs->trans(
'AlreadyDone').
"<br>\n";
2676 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2678 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2682 print
'<tr><td colspan="4">';
2685 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2691 $table1 =
'facturedet';
2692 $field1 =
'fk_remise_except';
2693 $table2 =
'societe_remise_except';
2694 $field2 =
'fk_facture_line';
2698 $sql =
"SELECT t1.rowid, t1.".$db->sanitize($field1).
" as field";
2699 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($table1).
" as t1";
2700 $sql .=
" WHERE t1.".$db->sanitize($field1).
" IS NOT NULL AND t1.".$db->sanitize($field1).
" NOT IN";
2701 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2).
" as t2";
2702 $sql .=
" WHERE t1.rowid = t2.".$db->sanitize($field2).
")";
2705 $resql = $db->query($sql);
2708 $num = $db->num_rows($resql);
2712 $obj = $db->fetch_object($resql);
2714 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2716 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2717 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2718 $sql .=
" WHERE rowid = ".((int) $obj->field);
2720 $resql2 = $db->query($sql);
2723 dol_print_error($db);
2729 print $langs->trans(
'AlreadyDone').
"<br>\n";
2738 dol_print_error($db);
2745 print
'<tr><td colspan="4">';
2748 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2751 $table2 =
'facturedet';
2752 $field2 =
'fk_remise_except';
2753 $table1 =
'societe_remise_except';
2754 $field1 =
'fk_facture_line';
2758 $sql =
"SELECT t1.rowid, t1.".$db->sanitize($field1).
" as field";
2759 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($table1).
" as t1";
2760 $sql .=
" WHERE t1.".$db->sanitize($field1).
" IS NOT NULL AND t1.".$db->sanitize($field1).
" NOT IN";
2761 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2).
" as t2";
2762 $sql .=
" WHERE t1.rowid = t2.".$db->sanitize($field2).
")";
2765 $resql = $db->query($sql);
2768 $num = $db->num_rows($resql);
2772 $obj = $db->fetch_object($resql);
2774 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2776 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2777 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2778 $sql .=
" WHERE rowid = ".((int) $obj->field);
2780 $resql2 = $db->query($sql);
2783 dol_print_error($db);
2789 print $langs->trans(
'AlreadyDone').
"<br>\n";
2798 dol_print_error($db);
2804 return ($error ? -1 : 1);
2819 print
'<tr><td colspan="4">';
2822 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2824 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2825 $obj = $db->fetch_object($result);
2831 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2832 $resql = $db->query($sql);
2835 $num = $db->num_rows($resql);
2839 $obj = $db->fetch_object($resql);
2841 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2842 $sql2 .=
"datecreate";
2843 $sql2 .=
", statut";
2844 $sql2 .=
", element_id";
2845 $sql2 .=
", fk_c_type_contact";
2846 $sql2 .=
", fk_socpeople";
2847 $sql2 .=
") VALUES (";
2848 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2850 $sql2 .=
", ".((int) $obj->rowid);
2852 $sql2 .=
", ".((int) $obj->fk_user_resp);
2855 if ($obj->fk_user_resp > 0) {
2856 $resql2 = $db->query($sql2);
2859 dol_print_error($db);
2869 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2870 if ($db->query($sqlDrop)) {
2879 dol_print_error($db);
2883 print $langs->trans(
'AlreadyDone').
"<br>\n";
2900 print
'<tr><td colspan="4">';
2903 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2905 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2910 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2911 $resql = $db->query($sql);
2914 $num = $db->num_rows($resql);
2918 $obj = $db->fetch_object($resql);
2920 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2921 $sql2 .=
"datecreate";
2922 $sql2 .=
", statut";
2923 $sql2 .=
", element_id";
2924 $sql2 .=
", fk_c_type_contact";
2925 $sql2 .=
", fk_socpeople";
2926 $sql2 .=
") VALUES (";
2927 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2929 $sql2 .=
", ".((int) $obj->fk_project_task);
2931 $sql2 .=
", ".((int) $obj->fk_user);
2934 $resql2 = $db->query($sql2);
2938 dol_print_error($db);
2946 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2947 if ($db->query($sqlDrop)) {
2956 dol_print_error($db);
2960 print $langs->trans(
'AlreadyDone').
"<br>\n";
2980 print
'<tr><td colspan="4">';
2983 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2987 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2992 $sqlSelect =
"SELECT ".$db->sanitize($fk_source).
", ".$db->sanitize($fk_target);
2993 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
2995 $resql = $db->query($sqlSelect);
2998 $num = $db->num_rows($resql);
3002 $obj = $db->fetch_object($resql);
3004 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3005 $sqlInsert .=
"fk_source";
3006 $sqlInsert .=
", sourcetype";
3007 $sqlInsert .=
", fk_target";
3008 $sqlInsert .=
", targettype";
3009 $sqlInsert .=
") VALUES (";
3010 $sqlInsert .= ((int) $obj->$fk_source);
3011 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
3012 $sqlInsert .=
", ".((int) $obj->$fk_target);
3013 $sqlInsert .=
", '".$db->escape($targettype).
"'";
3016 $result = $db->query($sqlInsert);
3019 dol_print_error($db);
3025 print $langs->trans(
'AlreadyDone').
"<br>\n";
3029 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$db->sanitize($table);
3030 if ($db->query($sqlDrop)) {
3039 dol_print_error($db);
3043 print $langs->trans(
'AlreadyDone').
"<br>\n";
3061 print
'<tr><td colspan="4">';
3064 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
3070 $sql =
"SELECT rowid, fk_element, element_duration";
3071 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
3072 $resql = $db->query($sql);
3075 $num = $db->num_rows($resql);
3078 $totaltime = array();
3082 $obj = $db->fetch_object($resql);
3084 if ($obj->element_duration > 0) {
3087 list($hour, $min) = explode(
'.', $obj->element_duration);
3088 $hour = (int) $hour * 60 * 60;
3089 $min = (int) ((
float) (
'.'.$min)) * 3600;
3090 $newtime = $hour + $min;
3092 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
3093 $sql2 .=
" element_duration = ".((int) $newtime);
3094 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
3096 $resql2 = $db->query($sql2);
3099 dol_print_error($db);
3103 if (!empty($totaltime[$obj->fk_element])) {
3104 $totaltime[$obj->fk_element] += $newtime;
3106 $totaltime[$obj->fk_element] = $newtime;
3109 if (!empty($totaltime[$obj->fk_element])) {
3110 $totaltime[$obj->fk_element] += $obj->element_duration;
3112 $totaltime[$obj->fk_element] = $obj->element_duration;
3121 foreach ($totaltime as $taskid => $total_duration) {
3122 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
3123 $sql .=
" duration_effective = ".((int) $total_duration);
3124 $sql .=
" WHERE rowid = ".((int) $taskid);
3126 $resql = $db->query($sql);
3129 dol_print_error($db);
3133 print $langs->trans(
'AlreadyDone').
"<br>\n";
3136 dol_print_error($db);
3139 print $langs->trans(
'AlreadyDone').
"<br>\n";
3142 dol_print_error($db);
3164 print
'<tr><td colspan="4">';
3167 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3171 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3172 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3173 $obj1 = $db->fetch_object($result1);
3174 $obj2 = $db->fetch_object($result2);
3175 if (!$obj1 && !$obj2) {
3180 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3181 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3183 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3184 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3185 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3186 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3187 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3188 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3189 $sqlSelect .=
" AND el.targettype = 'shipping'";
3191 $resql = $db->query($sqlSelect);
3194 $num = $db->num_rows($resql);
3198 $obj = $db->fetch_object($resql);
3200 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3201 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3202 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3203 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3205 $result = $db->query($sqlUpdate);
3208 dol_print_error($db);
3214 print $langs->trans(
'AlreadyDone').
"<br>\n";
3220 dol_print_error($db);
3224 dol_print_error($db);
3228 dol_print_error($db);
3232 print $langs->trans(
'AlreadyDone').
"<br>\n";
3248 print
'<tr><td colspan="4">';
3251 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3255 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3256 $obj = $db->fetch_object($result);
3262 $sqlSelect =
"SELECT rowid, fk_expedition";
3263 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3264 $sqlSelect .=
" WHERE fk_expedition is not null";
3266 $resql = $db->query($sqlSelect);
3269 $num = $db->num_rows($resql);
3273 $obj = $db->fetch_object($resql);
3275 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3276 $sqlInsert .=
"fk_source";
3277 $sqlInsert .=
", sourcetype";
3278 $sqlInsert .=
", fk_target";
3279 $sqlInsert .=
", targettype";
3280 $sqlInsert .=
") VALUES (";
3281 $sqlInsert .= ((int) $obj->fk_expedition);
3282 $sqlInsert .=
", 'shipping'";
3283 $sqlInsert .=
", ".((int) $obj->rowid);
3284 $sqlInsert .=
", 'delivery'";
3287 $result = $db->query($sqlInsert);
3289 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3290 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3292 $result = $db->query($sqlUpdate);
3295 dol_print_error($db);
3300 dol_print_error($db);
3305 print $langs->trans(
'AlreadyDone').
"<br>\n";
3309 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3310 $db->query($sqlDelete);
3315 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3316 $db->query($sqlDrop);
3318 dol_print_error($db);
3322 dol_print_error($db);
3326 print $langs->trans(
'AlreadyDone').
"<br>\n";
3343 print
'<tr><td colspan="4">';
3346 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3354 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3355 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3356 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3357 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3358 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3359 $sqlSelect .=
" AND el.targettype = 'delivery'";
3360 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3361 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3363 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3364 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3366 $resql = $db->query($sqlSelect);
3369 $num = $db->num_rows($resql);
3373 $obj = $db->fetch_object($resql);
3375 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3376 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3377 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3378 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3380 $result = $db->query($sqlUpdate);
3383 dol_print_error($db);
3389 print $langs->trans(
'AlreadyDone').
"<br>\n";
3395 dol_print_error($db);
3399 dol_print_error($db);
3416 print
'<tr><td colspan="4">';
3419 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3422 'propal' =>
'propalrowid',
3423 'order' =>
'fk_commande',
3424 'invoice' =>
'fk_facture',
3425 'contract' =>
'fk_contract',
3426 'order_supplier' =>
'fk_supplier_order',
3427 'invoice_supplier' =>
'fk_supplier_invoice'
3430 foreach ($elements as $type => $field) {
3431 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3432 $obj = $db->fetch_object($result);
3438 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3439 $sql .=
"fk_element = ".$db->sanitize($field).
", elementtype = '".$db->escape($type).
"'";
3440 $sql .=
" WHERE ".$db->sanitize($field).
" IS NOT NULL";
3441 $sql .=
" AND fk_element IS NULL";
3442 $sql .=
" AND elementtype IS NULL";
3444 $resql = $db->query($sql);
3454 dol_print_error($db);
3458 print $langs->trans(
'AlreadyDone').
"<br>\n";
3475 print
'<tr><td colspan="4">';
3478 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3481 'old_id' => array(5, 8, 9, 10, 11),
3482 'new_id' => array(50, 51, 52, 53, 54),
3483 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3484 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3488 foreach ($elements[
'old_id'] as $key => $old_id) {
3493 $sqlSelect =
"SELECT id";
3494 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3495 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3496 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3498 $resql = $db->query($sqlSelect);
3500 $num = $db->num_rows($resql);
3506 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3507 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3508 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3509 $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]).
"')";
3510 $resqla = $db->query($sqla);
3512 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3513 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3514 $sql .=
" WHERE id = ".((int) $old_id);
3515 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3516 $resql = $db->query($sql);
3518 if ($resqla && $resql) {
3519 foreach ($elements[
'tables'] as $table) {
3520 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table).
" SET ";
3521 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3522 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3524 $resql = $db->query($sql);
3526 dol_print_error($db);
3535 dol_print_error($db);
3539 dol_print_error($db);
3547 print $langs->trans(
'AlreadyDone').
"<br>\n";
3565 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3567 $obj = $db->fetch_object($result);
3570 $children = array();
3571 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3572 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3574 $resql = $db->query($sql);
3576 $num = $db->num_rows($resql);
3577 while ($obj = $db->fetch_object($resql)) {
3578 if (!isset($children[$obj->fk_categorie_fille])) {
3579 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3580 $children[$obj->fk_categorie_fille] = 1;
3581 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3589 if (count($couples) > 0 && $num > count($couples)) {
3595 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3597 $resqld = $db->query($sql);
3600 foreach ($couples as $key => $val) {
3601 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3602 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3604 $resqli = $db->query($sql);
3612 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3613 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3616 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3617 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3622 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3623 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3640 print
'<tr><td colspan="4">';
3643 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3647 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3652 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3653 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3655 $resql = $db->query($sqlSelect);
3658 $num = $db->num_rows($resql);
3662 $obj = $db->fetch_object($resql);
3664 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3665 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3666 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3668 $result = $db->query($sqlUpdate);
3671 dol_print_error($db);
3677 print $langs->trans(
'AlreadyDone').
"<br>\n";
3686 dol_print_error($db);
3690 print $langs->trans(
'AlreadyDone').
"<br>\n";
3706 print
'<tr><td colspan="4">';
3709 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3717 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3718 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3719 $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";
3720 $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')";
3721 $sqlSelect .=
" ORDER BY a.id";
3724 $resql = $db->query($sqlSelect);
3727 $num = $db->num_rows($resql);
3731 $obj = $db->fetch_object($resql);
3733 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3734 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3736 $result = $db->query($sqlUpdate);
3739 dol_print_error($db);
3745 print $langs->trans(
'AlreadyDone').
"<br>\n";
3754 dol_print_error($db);
3772 print
'<tr><td colspan="4">';
3775 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3783 $sqlSelect =
"SELECT a.id, a.fk_contact";
3784 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3785 $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";
3786 $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')";
3787 $sqlSelect .=
" ORDER BY a.id";
3790 $resql = $db->query($sqlSelect);
3793 $num = $db->num_rows($resql);
3797 $obj = $db->fetch_object($resql);
3799 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3800 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3802 $result = $db->query($sqlUpdate);
3805 dol_print_error($db);
3811 print $langs->trans(
'AlreadyDone').
"<br>\n";
3820 dol_print_error($db);
3841 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3843 print
'<tr><td colspan="4">';
3846 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3854 $sqlSelect =
"SELECT DISTINCT entity";
3855 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3859 $resql = $db->query($sqlSelect);
3862 $num = $db->num_rows($resql);
3866 $obj = $db->fetch_object($resql);
3868 print
'Process entity '.$obj->entity;
3870 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3871 $resqlSearch = $db->query($sqlSearch);
3873 $objSearch = $db->fetch_object($resqlSearch);
3875 if ($objSearch && $objSearch->nb == 0) {
3876 print
' - Record for entity must be reset...';
3878 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3879 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3880 $resqlUpdate = $db->query($sqlUpdate);
3881 if (!$resqlUpdate) {
3883 dol_print_error($db);
3890 $object->entity = $obj->entity;
3894 $b->setObjectData(
$object,
'MODULE_SET', 0, $user, 0);
3896 $res = $b->create($user);
3902 print
' - '.$langs->trans(
'AlreadyDone').
'<br>';
3905 dol_print_error($db);
3911 print $langs->trans(
'NothingToDo').
"<br>\n";
3920 dol_print_error($db);
3938 print
'<tr><td colspan="4">';
3941 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3949 $sqlSelect =
"SELECT sr.rowid, s.entity";
3950 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3951 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3955 $resql = $db->query($sqlSelect);
3958 $num = $db->num_rows($resql);
3962 $obj = $db->fetch_object($resql);
3964 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3965 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3966 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3968 $result = $db->query($sqlUpdate);
3971 dol_print_error($db);
3978 print $langs->trans(
'AlreadyDone').
"<br>\n";
3987 dol_print_error($db);
4004 print
'<tr><td colspan="4">';
4007 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
4015 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
4016 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
4019 $resql = $db->query($sqlSelect);
4022 $num = $db->num_rows($resql);
4026 $obj = $db->fetch_object($resql);
4028 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
4029 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
4031 $sqlSelect2 =
"SELECT f.entity";
4032 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
4033 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
4034 } elseif (!empty($obj->fk_facture_line)) {
4035 $sqlSelect2 =
"SELECT f.entity";
4036 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
4037 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
4038 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
4040 $sqlSelect2 =
"SELECT s.entity";
4041 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4042 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
4045 $resql2 = $db->query($sqlSelect2);
4047 if ($db->num_rows($resql2) > 0) {
4048 $obj2 = $db->fetch_object($resql2);
4050 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
4051 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
4052 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
4054 $result = $db->query($sqlUpdate);
4057 dol_print_error($db);
4062 dol_print_error($db);
4069 print $langs->trans(
'AlreadyDone').
"<br>\n";
4078 dol_print_error($db);
4109 array(
'to' => array(
'produit',
'product_advance',
'read_supplier_prices'),
'from' => array(array(
'produit',
'lire',
''), array(
'produit',
'creer',
''))),
4110 array(
'to' => array(
'produit',
'product_advance',
'write_supplier_prices'),
'from' => array(array(
'produit',
'creer',
''))),
4111 array(
'to' => array(
'service',
'service_advance',
'read_supplier_prices'),
'from' => array(array(
'service',
'lire',
''))),
4117 foreach ($rules as $rule) {
4120 if ($targetid <= 0) {
4125 $sourceids = array();
4126 foreach ($rule[
'from'] as $from) {
4132 if (empty($sourceids)) {
4135 $sourcelist = implode(
',', $sourceids);
4138 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"usergroup_rights (entity, fk_usergroup, fk_id)";
4139 $sql .=
" SELECT DISTINCT gr.entity, gr.fk_usergroup, ".((int) $targetid);
4140 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as gr";
4141 $sql .=
" WHERE gr.fk_id IN (".$db->sanitize($sourcelist).
")";
4142 $sql .=
" AND NOT EXISTS (SELECT 1 FROM ".MAIN_DB_PREFIX.
"usergroup_rights as ex WHERE ex.fk_usergroup = gr.fk_usergroup AND ex.entity = gr.entity AND ex.fk_id = ".((int) $targetid).
")";
4143 if (!$db->query($sql)) {
4149 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_rights (entity, fk_user, fk_id)";
4150 $sql .=
" SELECT DISTINCT ur.entity, ur.fk_user, ".((int) $targetid);
4151 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur";
4152 $sql .=
" WHERE ur.fk_id IN (".$db->sanitize($sourcelist).
")";
4153 $sql .=
" AND NOT EXISTS (SELECT 1 FROM ".MAIN_DB_PREFIX.
"user_rights as ex WHERE ex.fk_user = ur.fk_user AND ex.entity = ur.entity AND ex.fk_id = ".((int) $targetid).
")";
4154 if (!$db->query($sql)) {
4179 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"rights_def";
4180 $sql .=
" WHERE module = '".$db->escape(
$module).
"'";
4181 $sql .=
" AND perms = '".$db->escape($perms).
"'";
4182 if ($subperms ===
'') {
4183 $sql .=
" AND (subperms IS NULL OR subperms = '')";
4185 $sql .=
" AND subperms = '".$db->escape($subperms).
"'";
4187 $resql = $db->query($sql);
4191 $obj = $db->fetch_object($resql);
4192 return $obj ? (int) $obj->id : 0;
4205 print
'<tr><td colspan="4">';
4207 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
4215 $sqlSelect =
"SELECT u.rowid, u.entity";
4216 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
4217 $sqlSelect .=
" WHERE u.entity > 1";
4220 $resql = $db->query($sqlSelect);
4223 $num = $db->num_rows($resql);
4227 $obj = $db->fetch_object($resql);
4229 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
4230 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4231 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
4233 $result = $db->query($sqlUpdate);
4236 dol_print_error($db);
4243 print $langs->trans(
'AlreadyDone').
"<br>\n";
4252 dol_print_error($db);
4270 print
'<tr><td colspan="4">';
4272 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4280 $sqlSelect =
"SELECT u.rowid, u.entity";
4281 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4282 $sqlSelect .=
" WHERE u.entity > 1";
4285 $resql = $db->query($sqlSelect);
4288 $num = $db->num_rows($resql);
4292 $obj = $db->fetch_object($resql);
4294 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4295 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4296 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4298 $result = $db->query($sqlUpdate);
4301 dol_print_error($db);
4308 print $langs->trans(
'AlreadyDone').
"<br>\n";
4317 dol_print_error($db);
4339 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4340 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4341 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4344 dolCopyDir(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname,
'0', 1);
4364 $filetodeletearray = array(
4365 '/core/ajax/ajaxcompanies.php',
4366 '/core/triggers/interface_demo.class.php',
4367 '/core/menus/barre_left/default.php',
4368 '/core/menus/barre_top/default.php',
4369 '/core/modules/modComptabiliteExpert.class.php',
4370 '/core/modules/modCommercial.class.php',
4371 '/core/modules/modPaybox.class.php',
4372 '/core/modules/modProduit.class.php',
4373 '/core/modules/modSkype.class.php',
4374 '/core/modules/modactivite.class.php',
4375 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4376 '/core/triggers/interface_modCommande_Ecotax.class.php',
4377 '/core/triggers/interface_modCommande_fraisport.class.php',
4378 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4379 '/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php',
4380 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4381 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4382 '/core/menus/smartphone/iphone.lib.php',
4383 '/core/menus/smartphone/iphone_backoffice.php',
4384 '/core/menus/smartphone/iphone_frontoffice.php',
4385 '/core/menus/standard/auguria_backoffice.php',
4386 '/core/menus/standard/auguria_frontoffice.php',
4387 '/core/menus/standard/eldy_backoffice.php',
4388 '/core/menus/standard/eldy_frontoffice.php',
4389 '/core/modules/export/export_excel.modules.php',
4390 '/core/modules/export/export_csv.modules.php',
4391 '/core/modules/export/exportcsv.modules.php',
4392 '/core/modules/export/export_excel2007new.modules.php',
4393 '/core/modules/facture/pdf_crabe.modules.php',
4394 '/core/modules/commande/doc/pdf_einstein.modules.php',
4395 '/core/modules/expedition/doc/pdf_rouget.modules.php',
4396 '/core/modules/propale/doc/pdf_azur.modules.php',
4397 '/core/modules/supplier_order/doc/pdf_muscadet.modules.php',
4398 '/core/modules/supplier_proposal/doc/pdf_aurore.modules.php',
4399 '/core/modules/facture/pdf_oursin.modules.php',
4400 '/core/modules/mailings/contacts2.modules.php',
4401 '/core/modules/mailings/contacts3.modules.php',
4402 '/core/modules/mailings/contacts4.modules.php',
4403 '/core/modules/mailings/framboise.modules.php',
4404 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4405 '/core/modules/mailings/peche.modules.php',
4406 '/core/modules/mailings/poire.modules.php',
4407 '/core/modules/mailings/kiwi.modules.php',
4408 '/core/modules/syslog/mod_syslog_chromephp.php',
4409 '/core/modules/syslog/mod_syslog_firephp.php',
4410 '/core/modules/syslog/logHandlerInterface.php',
4411 '/core/boxes/box_members.php',
4413 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4414 '/includes/nusoap/lib/class.*',
4415 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4416 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4418 '/api/class/api_generic.class.php',
4419 '/asterisk/cidlookup.php',
4420 '/categories/class/api_category.class.php',
4421 '/categories/class/api_deprecated_category.class.php',
4422 '/compta/facture/class/api_invoice.class.php',
4423 '/commande/class/api_commande.class.php',
4424 '/partnership/class/api_partnership.class.php',
4425 '/product/class/api_product.class.php',
4426 '/recruitment/class/api_recruitment.class.php',
4427 '/societe/class/api_contact.class.php',
4428 '/societe/class/api_thirdparty.class.php',
4429 '/support/online.php',
4430 '/takepos/class/actions_takepos.class.php',
4431 '/user/class/api_user.class.php',
4433 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4434 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4435 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4436 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4437 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4438 '/install/mysql/tables/llx_c_ticketsup_type.sql',
4440 '/install/mysql/tables/llx_categorie_mo-mrp_mo.sql',
4441 '/install/mysql/tables/llx_categorie_mo-mrp_mo.key.sql'
4450 foreach ($filetodeletearray as $filetodelete) {
4452 if (preg_match(
'/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4454 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match(
'/\*/', $filetodelete) ? 1 : 0), 0,
null,
true, 0);
4456 $langs->load(
"errors");
4457 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4458 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4483 $filetodeletearray = array(
4484 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4485 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4489 if (!empty($_SERVER[
"WINDIR"])) {
4490 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4493 foreach ($filetodeletearray as $filetodelete) {
4495 if (file_exists($filetodelete)) {
4499 $langs->load(
"errors");
4500 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4501 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4525 if (count($listofmodule) == 0) {
4529 if (!is_object($user)) {
4530 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4531 $user =
new User($db);
4534 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)), LOG_NOTICE);
4536 $reloadactionformodules = array(
4537 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4538 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4539 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4540 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4541 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4542 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4543 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4544 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4545 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4546 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4547 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4548 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4549 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4550 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4551 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4552 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4553 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4554 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4555 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4556 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4557 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4558 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4559 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4560 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4561 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4562 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4563 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4566 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4567 $modulekey = preg_replace(
'/^MAIN_MODULE_/',
'', $moduletoreload);
4569 if (empty($moduletoreload) || (!
isModEnabled(strtolower($modulekey)) && !$force)) {
4575 if (!empty($reloadactionformodules[$moduletoreload])) {
4576 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4578 $val = $reloadactionformodules[$moduletoreload];
4579 $classformodule = $val[
'class'];
4580 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4582 $mod =
new $classformodule($db);
4583 if (!empty($val[
'remove'])) {
4584 $mod->remove(
'noboxes');
4586 if (!empty($val[
'deleteinsertmenus'])) {
4588 $mod->delete_menus();
4589 $mod->insert_menus();
4591 $mod->init($reloadmode);
4596 preg_match(
'/([a-zA-Z0-9]+)/', $modulekey, $reg);
4597 if (!empty($reg[1])) {
4598 if (strtoupper($moduletoreload) == $moduletoreload) {
4599 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4601 $moduletoreloadshort = $reg[1];
4604 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)", LOG_NOTICE);
4606 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4608 $classname =
'mod'.$moduletoreloadshort;
4609 $mod =
new $classname($db);
4610 '@phan-var-force DolibarrModules $mod';
4613 $mod->delete_menus();
4614 $mod->init($reloadmode);
4616 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4618 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4620 $classname =
'mod'.$moduletoreloadshort;
4621 $mod =
new $classname($db);
4622 '@phan-var-force DolibarrModules $mod';
4623 $mod->init($reloadmode);
4625 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4626 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4632 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4637 if (!empty($mod) && is_object($mod)) {
4638 print
'<tr class="trforrunsql"><td colspan="4">';
4639 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4640 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4641 print
"<!-- (".$reloadmode.
") -->";
4666 $listofmenuhandler = array();
4669 $listofmenuhandler[
'auguria'] = 1;
4672 foreach ($listofmenuhandler as $key => $val) {
4673 print
'<tr class="trforrunsql"><td colspan="4">';
4677 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4680 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4681 $file =
'init_menu_'.$key.
'.sql';
4682 if (file_exists($dir.$file)) {
4683 $result =
run_sql($dir.$file, 1, 0, 1, $key);
4699 global
$conf, $db, $langs, $user;
4701 if (!is_object($user)) {
4702 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4703 $user =
new User($db);
4706 print
'<tr><td colspan="4">';
4708 print
'<b>'.$langs->trans(
'MigrationProductLotPath').
"</b><br>\n";
4710 $sql =
"SELECT rowid, entity, batch, fk_product from ".MAIN_DB_PREFIX.
"product_lot";
4711 $resql = $db->query($sql);
4714 $modulepart =
"product_batch";
4718 while ($obj = $db->fetch_object($resql)) {
4719 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4721 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/'.
$conf->productbatch->multidir_output[$entity];
4723 $dir =
$conf->productbatch->multidir_output[$entity];
4727 $lot->id = (int) $obj->rowid;
4728 $lot->ref = (string) $obj->rowid;
4729 $lot->batch = $obj->batch;
4730 $lot->entity = $obj->entity;
4731 $lot->fk_product = $obj->fk_product;
4733 $savref = $lot->ref;
4735 $lot->ref = $obj->batch;
4736 $origin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4738 $lot->ref = $savref;
4739 $destin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4761 global
$conf, $db, $langs, $user;
4763 print
'<tr><td colspan="4">';
4765 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4767 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4768 $fuser =
new User($db);
4769 if (!is_object($user)) {
4773 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4774 $resql = $db->query($sql);
4776 while ($obj = $db->fetch_object($resql)) {
4778 $fuser->id = $obj->uid;
4779 $fuser->entity = $obj->entity;
4782 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4784 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4786 $dir =
$conf->user->multidir_output[$entity];
4791 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4792 $destin = $dir.
'/'.$fuser->id;
4800 $handle = opendir($origin_osencoded);
4801 if (is_resource($handle)) {
4802 while (($file = readdir($handle)) !==
false) {
4803 if ($file ==
'.' || $file ==
'..') {
4808 $thumbs = opendir($origin_osencoded.
'/'.$file);
4809 if (is_resource($thumbs)) {
4811 while (($thumb = readdir($thumbs)) !==
false) {
4813 if ($thumb ==
'.' || $thumb ==
'..') {
4819 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4829 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4850 global $db, $langs, $user;
4852 print
'<tr><td colspan="4">';
4854 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4856 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4857 $fuser =
new User($db);
4858 if (!is_object($user)) {
4862 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4863 $resql = $db->query($sql);
4865 while ($obj = $db->fetch_object($resql)) {
4867 $fuser->id = $obj->uid;
4868 $fuser->entity = $obj->entity;
4869 $fuser->photo = $obj->photo;
4872 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4874 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4876 $dir = DOL_DATA_ROOT.
'/users';
4881 $origin = $dir.
'/'.$fuser->id;
4882 $destin = $dir.
'/'.$fuser->id.
'/photos';
4890 $handle = opendir($origin_osencoded);
4891 if (is_resource($handle)) {
4892 while (($file = readdir($handle)) !==
false) {
4893 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4896 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4901 $thumbs = opendir($origin_osencoded.
'/'.$file);
4902 if (is_resource($thumbs)) {
4904 while (($thumb = readdir($thumbs)) !==
false) {
4906 if ($thumb ==
'.' || $thumb ==
'..') {
4912 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4921 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4943 global
$conf, $db, $langs;
4945 print
'<tr class="trforrunsql"><td>';
4947 print
'<b>'.$langs->trans(
'MigrationHolidayPath').
"</b><br>\n";
4949 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
4952 $sql =
"SELECT rowid as uid, ref, entity from ".MAIN_DB_PREFIX.
"holiday";
4954 $resql = $db->query($sql);
4956 while ($obj = $db->fetch_object($resql)) {
4958 $holiday->id = $obj->uid;
4959 $holiday->ref = $obj->ref;
4960 $holiday->entity = $obj->entity;
4963 $entity = (empty($holiday->entity) ? 1 : $holiday->entity);
4965 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/holiday';
4967 $dir =
$conf->holiday->multidir_output[$entity];
4972 $origin = $dir.
'/'.
get_exdir($holiday->id, 2, 0, 1, $holiday,
'holiday');
4973 $destin = $dir.
'/'.$holiday->ref;
4981 $handle = opendir($origin_osencoded);
4982 if (is_resource($handle)) {
4983 while (($file = readdir($handle)) !==
false) {
4984 if ($file ==
'.' || $file ==
'..') {
4989 $thumbs = opendir($origin_osencoded.
'/'.$file);
4990 if (is_resource($thumbs)) {
4992 while (($thumb = readdir($thumbs)) !==
false) {
4994 if ($thumb ==
'.' || $thumb ==
'..') {
5000 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
5010 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
5047 print
'<tr><td colspan="4">';
5048 $sql =
'SELECT rowid, socialnetworks';
5049 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
5050 $sql .=
" skype IS NOT NULL OR skype <> ''";
5051 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5052 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5053 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5054 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5055 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5056 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5057 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5058 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5060 $resql = $db->query($sql);
5062 while ($obj = $db->fetch_object($resql)) {
5063 $arraysocialnetworks = array();
5064 if (!empty($obj->skype)) {
5065 $arraysocialnetworks[
'skype'] = $obj->skype;
5067 if (!empty($obj->twitter)) {
5068 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5070 if (!empty($obj->facebook)) {
5071 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5073 if (!empty($obj->linkedin)) {
5074 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5076 if (!empty($obj->instagram)) {
5077 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5079 if (!empty($obj->snapchat)) {
5080 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5082 if (!empty($obj->googleplus)) {
5083 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5085 if (!empty($obj->youtube)) {
5086 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5088 if (!empty($obj->whatsapp)) {
5089 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5091 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5092 $obj->socialnetworks =
'[]';
5094 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5095 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5096 $sqlupd .=
', skype=null';
5097 $sqlupd .=
', twitter=null';
5098 $sqlupd .=
', facebook=null';
5099 $sqlupd .=
', linkedin=null';
5100 $sqlupd .=
', instagram=null';
5101 $sqlupd .=
', snapchat=null';
5102 $sqlupd .=
', googleplus=null';
5103 $sqlupd .=
', youtube=null';
5104 $sqlupd .=
', whatsapp=null';
5105 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5107 $resqlupd = $db->query($sqlupd);
5109 dol_print_error($db);
5119 dol_print_error($db);
5122 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
5136 print
'<tr><td colspan="4">';
5139 print
'<tr><td colspan="4">';
5140 $sql =
'SELECT rowid, socialnetworks';
5141 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
5142 $sql .=
" skype IS NOT NULL OR skype <> ''";
5143 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5144 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5145 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5146 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5147 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5148 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5149 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5150 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5152 $resql = $db->query($sql);
5154 while ($obj = $db->fetch_object($resql)) {
5155 $arraysocialnetworks = array();
5156 if (!empty($obj->skype)) {
5157 $arraysocialnetworks[
'skype'] = $obj->skype;
5159 if (!empty($obj->twitter)) {
5160 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5162 if (!empty($obj->facebook)) {
5163 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5165 if (!empty($obj->linkedin)) {
5166 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5168 if (!empty($obj->instagram)) {
5169 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5171 if (!empty($obj->snapchat)) {
5172 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5174 if (!empty($obj->googleplus)) {
5175 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5177 if (!empty($obj->youtube)) {
5178 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5180 if (!empty($obj->whatsapp)) {
5181 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5183 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5184 $obj->socialnetworks =
'[]';
5186 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5187 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5188 $sqlupd .=
', skype=null';
5189 $sqlupd .=
', twitter=null';
5190 $sqlupd .=
', facebook=null';
5191 $sqlupd .=
', linkedin=null';
5192 $sqlupd .=
', instagram=null';
5193 $sqlupd .=
', snapchat=null';
5194 $sqlupd .=
', googleplus=null';
5195 $sqlupd .=
', youtube=null';
5196 $sqlupd .=
', whatsapp=null';
5197 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5199 $resqlupd = $db->query($sqlupd);
5201 dol_print_error($db);
5211 dol_print_error($db);
5214 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
5230 print
'<tr><td colspan="4">';
5231 $sql =
'SELECT rowid, socialnetworks';
5232 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
5233 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
5234 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
5235 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5236 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5237 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5238 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5239 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5240 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5241 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5242 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5244 $resql = $db->query($sql);
5246 while ($obj = $db->fetch_object($resql)) {
5247 $arraysocialnetworks = array();
5248 if (!empty($obj->jabberid)) {
5249 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
5251 if (!empty($obj->skype)) {
5252 $arraysocialnetworks[
'skype'] = $obj->skype;
5254 if (!empty($obj->twitter)) {
5255 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5257 if (!empty($obj->facebook)) {
5258 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5260 if (!empty($obj->linkedin)) {
5261 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5263 if (!empty($obj->instagram)) {
5264 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5266 if (!empty($obj->snapchat)) {
5267 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5269 if (!empty($obj->googleplus)) {
5270 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5272 if (!empty($obj->youtube)) {
5273 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5275 if (!empty($obj->whatsapp)) {
5276 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5278 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5279 $obj->socialnetworks =
'[]';
5281 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5282 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5283 $sqlupd .=
', jabberid=null';
5284 $sqlupd .=
', skype=null';
5285 $sqlupd .=
', twitter=null';
5286 $sqlupd .=
', facebook=null';
5287 $sqlupd .=
', linkedin=null';
5288 $sqlupd .=
', instagram=null';
5289 $sqlupd .=
', snapchat=null';
5290 $sqlupd .=
', googleplus=null';
5291 $sqlupd .=
', youtube=null';
5292 $sqlupd .=
', whatsapp=null';
5293 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5295 $resqlupd = $db->query($sqlupd);
5297 dol_print_error($db);
5307 dol_print_error($db);
5310 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
5326 print
'<tr><td colspan="4">';
5327 $sql =
'SELECT rowid, socialnetworks';
5328 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
5329 $sql .=
" skype IS NOT NULL OR skype <> ''";
5330 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5331 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5332 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5333 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5334 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5335 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5336 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5337 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5339 $resql = $db->query($sql);
5341 while ($obj = $db->fetch_object($resql)) {
5342 $arraysocialnetworks = array();
5343 if (!empty($obj->skype)) {
5344 $arraysocialnetworks[
'skype'] = $obj->skype;
5346 if (!empty($obj->twitter)) {
5347 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5349 if (!empty($obj->facebook)) {
5350 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5352 if (!empty($obj->linkedin)) {
5353 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5355 if (!empty($obj->instagram)) {
5356 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5358 if (!empty($obj->snapchat)) {
5359 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5361 if (!empty($obj->googleplus)) {
5362 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5364 if (!empty($obj->youtube)) {
5365 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5367 if (!empty($obj->whatsapp)) {
5368 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5370 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5371 $obj->socialnetworks =
'[]';
5373 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5374 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5375 $sqlupd .=
', skype=null';
5376 $sqlupd .=
', twitter=null';
5377 $sqlupd .=
', facebook=null';
5378 $sqlupd .=
', linkedin=null';
5379 $sqlupd .=
', instagram=null';
5380 $sqlupd .=
', snapchat=null';
5381 $sqlupd .=
', googleplus=null';
5382 $sqlupd .=
', youtube=null';
5383 $sqlupd .=
', whatsapp=null';
5384 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5386 $resqlupd = $db->query($sqlupd);
5388 dol_print_error($db);
5398 dol_print_error($db);
5401 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5421 print
'<tr class="trforrunsql"><td colspan="4">';
5422 $sql =
'SELECT rowid, field';
5423 if ($mode ==
'export') {
5426 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5427 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5429 $resql = $db->query($sql);
5431 while ($obj = $db->fetch_object($resql)) {
5432 $oldfield = $obj->field;
5433 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5435 if ($mode ==
'export') {
5436 $oldfilter = $obj->filter;
5437 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5443 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5444 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5445 if ($mode ==
'export') {
5446 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5448 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5449 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5450 $resqlupd = $db->query($sqlupd);
5452 dol_print_error($db);
5463 dol_print_error($db);
5466 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5469 if ($resultstring) {
5470 print $resultstring;
5472 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5489 print
'<tr class="trforrunsql"><td colspan="4">';
5490 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5492 $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";
5493 $sql .=
" ORDER BY c.rowid,cd.rowid";
5495 $resql = $db->query($sql);
5498 $current_contract = 0;
5499 while ($obj = $db->fetch_object($resql)) {
5500 if (empty($current_contract) || $current_contract == $obj->cid) {
5506 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5507 $resultstring =
'.';
5508 print $resultstring;
5509 $resqlUpd = $db->query($sqlUpd);
5511 dol_print_error($db);
5515 $current_contract = $obj->cid;
5528 if (!$resultstring) {
5529 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5544 $firstInstallVersion =
getDolGlobalString(
'MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5545 $migrationNeeded = (
versioncompare(explode(
'.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5547 print
'<tr class="trforrunsql"><td colspan="4">';
5548 print
'<b>'.$langs->trans(
'InvoiceExportModelsMigration').
"</b>: \n";
5550 if (! $migrationNeeded) {
5551 print $langs->trans(
"AlreadyDone");
5553 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
5560 $sql1 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5562 $resql1 = $db->query($sql1);
5565 dol_print_error($db);
5571 $modified1 = $db->affected_rows($resql1);
5573 print str_repeat(
'.', $modified1);
5577 $sql2 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5579 $resql2 = $db->query($sql2);
5582 dol_print_error($db);
5588 $modified2 = $db->affected_rows($resql2);
5590 print str_repeat(
'.', $modified2);
5594 if (empty($modified1 + $modified2)) {
5595 print $langs->trans(
'NothingToDo');
5600 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
5617 $bookKeepingAddon =
'';
5621 dolibarr_set_const($db,
'BOOKKEEPING_ADDON',
'mod_bookkeeping_neon',
'chaine', 0,
'', $entity);
5622 $bookKeepingAddon =
'mod_bookkeeping_neon';
5625 print
'<tr class="trforrunsql"><td colspan="4">';
5626 print
'<b>'.$langs->trans(
'MigrationAccountancyBookkeeping').
"</b><br>\n";
5629 if ($bookKeepingAddon ===
'mod_bookkeeping_argon') {
5632 $sql =
"SELECT DISTINCT YEAR(doc_date) as doc_year, MONTH(doc_date) as doc_month, code_journal, piece_num FROM ".$db->prefix().
"accounting_bookkeeping";
5633 $sql .=
" WHERE ref IS NULL AND entity = ".((int) $entity);
5634 $sql .=
" ORDER BY doc_year, doc_month, code_journal, piece_num";
5636 $resql = $db->query($sql);
5638 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeeping.class.php';
5641 while ($obj = $db->fetch_object($resql)) {
5642 $bookkeeping->doc_date =
dol_mktime(0, 0, 0, $obj->doc_month, 1, $obj->doc_year);
5643 $bookkeeping->code_journal = $obj->code_journal;
5644 $ref = $bookkeeping->getNextNumRef();
5646 $sqlUpd =
"UPDATE ".$db->prefix().
"accounting_bookkeeping SET ref = '".$db->escape($ref).
"' WHERE piece_num = '".$db->escape($obj->piece_num).
"' AND entity = ".((int) $entity);
5647 $resultstring =
'.';
5648 print $resultstring;
5649 $resqlUpd = $db->query($sqlUpd);
5651 dol_print_error($db);
5668 if (!$resultstring) {
5669 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5680 global
$conf, $db, $langs;
5682 print
'<tr class="trforrunsql"><td colspan="4">';
5683 print
'<b>'.$langs->trans(
'MigrationApiRestTokens').
"</b>:\n";
5687 $allexistingtokens = array();
5691 $sqlforalltokens =
"SELECT oat.tokenstring";
5692 $sqlforalltokens .=
" FROM ".$db->prefix().
"oauth_token AS oat";
5693 $sqlforalltokens .=
" WHERE oat.service = 'dolibarr_rest_api'";
5695 $resalltoken = $db->query($sqlforalltokens);
5698 while ($tokenobj = $db->fetch_object($resalltoken)) {
5699 $allexistingtokens[] =
dolDecrypt($tokenobj->tokenstring);
5703 dol_print_error($db);
5708 $sql =
"SELECT 'dolibarr_rest_api' AS service, u.api_key AS tokenstring, u.rowid AS fk_user, u.entity";
5709 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user AS u";
5710 $sql .=
" WHERE u.api_key IS NOT NULL AND u.api_key <> ''";
5712 $result = $db->query($sql);
5715 $tmpuser =
new User($db);
5717 while ($obj = $db->fetch_object($result)) {
5718 if (!in_array(
dolDecrypt($obj->tokenstring), $allexistingtokens)) {
5720 unset($tmpuser->conf);
5722 $tmpuser->fetch((
int) $obj->fk_user,
'',
'', 1, ($obj->entity ? $obj->entity :
$conf->entity));
5724 $sqlforinsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token (service, tokenstring, fk_user, datec, entity, apicount_total)";
5725 $sqlforinsert .=
" VALUES ('".$db->escape($obj->service).
"', '".$db->escape(
dolEncrypt(
dolDecrypt($obj->tokenstring))).
"', ";
5726 $sqlforinsert .= ((int) $obj->fk_user).
", '".$db->idate(
dol_now()).
"', ".((
int) $obj->entity).
", ";
5727 $sqlforinsert .=
getDolUserInt(
'API_COUNT_CALL', 0, $tmpuser);
5728 $sqlforinsert .=
")";
5730 $insertresult = $db->query($sqlforinsert);
5731 if (!$insertresult) {
5733 dol_print_error($db);
5746 dol_print_error($db);
5751 if (!$nbofmigration) {
5752 print $langs->trans(
"NothingToDo").
"\n";
5754 print $langs->trans(
'MigratedTokens', $nbofmigration);
5769 global
$conf, $db, $langs;
5771 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
5772 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5774 print
'<tr class="trforrunsql"><td colspan="4">';
5775 print
'<b>'.$langs->trans(
'InitAHMACKeyForBlockedLog').
"</b>:\n";
5781 if (empty($hmac_encoded_secret_key)) {
5783 $randomsecret = bin2hex(random_bytes(32));
5785 $hmac_secret_key =
'BLOCKEDLOGHMAC'.$randomsecret;
5787 $result =
dolibarr_set_const($db,
'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key,
'chaine', 0,
'The secret key for HMAC used for blockedlog record',
$conf->entity);
5790 dol_print_error($db);
5797 print $langs->trans(
'Done');
5798 } elseif (!preg_match(
'/^(dolcrypt|dolobfuscation)/', $hmac_encoded_secret_key)) {
5803 $result =
dolibarr_set_const($db,
'BLOCKEDLOG_HMAC_KEY', $hmac_encoded_secret_key,
'chaine', 0,
'The secret key for HMAC used for blockedlog record',
$conf->entity);
5805 dol_print_error($db);
5811 print $langs->trans(
'Done').
" (BLOCKEDLOG_HMAC_KEY was stored in clear, it has been encrypted)\n";
5814 $hmac_secret_key =
dolDecrypt($hmac_encoded_secret_key);
5816 if (! preg_match(
'/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
5817 print
'Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY using the $dolibarr_main_crypt_key. A value was found in config parameters in database but decoding failed. May be the database data were restored onto another environment and the coding/decoding key $dolibarr_main_dolcrypt_key was not restored with the same value in conf.php file.';
5818 print
'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.';
5819 print
'If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.';
5826 print $langs->trans(
"NothingToDo").
"\n";
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
migrate_blockedlog_add_end_file()
Migrate an old database to add the .end flag.
Class to manage Blocked Log.
Class to manage Ledger (General Ledger and Subledger)
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
Class of the module paid holiday.
Parent class for log handlers.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage order lines.
Class with list of lots and properties.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
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, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.
migrate_supplier_prices_permissions($db, $langs, $conf)
Grant the "supplier prices" advanced permissions introduced in 23.0 (product/service read_supplier_pr...
if($db !==null && $db->connected) if( $ret migrate_paiements)($db, $langs, $conf)
Records payment links for an invoice in a join table (link n<-->n for payments<-->invoices)
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Re-enable features modules.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a Link in llx_societe_remis...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_holiday_path()
Migrate file from old path to new one for users.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
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)
Reopen the contracts that have at least one line that is not closed (/completed).
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_accountingbookkeeping(int $entity)
Migrate Ref in bookkeeping lines.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration of the stock field in the Products table.
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)
Migrate the Order Details in the Delivery Details.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: select...
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Update the contracts (Contract Management + Contract Detail)
migrate_get_rights_def_id($db, $module, $perms, $subperms)
Return the permission id (llx_rights_def.id) matching a module/perms/subperms triplet,...
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)
Relations between the Shipping and Client Order in the table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_blockedlog_add_hmac_key()
Add the HMAC key for blockedlog v2+ Note that this is used on old version only.
migrate_productlot_path()
Migrate file from old path to new one for lot path.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_invoice_export_models()
Invoice exports been shifted (facture_1 => facture_0, facture_2 => facture_1) in version 20,...
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignment to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondence of the deliveries and the Customer Orders in the table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment to owner.
migrate_contracts_date1($db, $langs, $conf)
Update missing Contract Dates.
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.
migrate_apiresttokens()
Migrate API key in oauth_token table.