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);
210 require_once $dolibarr_main_document_root.
'/societe/class/societe.class.php';
216 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
217 $conf->modules[
'syslog'] =
'syslog';
218 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
219 if (!defined(
'SYSLOG_HANDLERS')) {
220 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
222 if (!defined(
'SYSLOG_FILE')) {
223 if (@is_writable(
'/tmp')) {
224 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
225 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
226 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
227 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
228 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
229 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
230 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
231 } elseif (@is_writable(
'../../')) {
232 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
236 if (defined(
'SYSLOG_FILE')) {
237 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
239 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
240 define(
'SYSLOG_FILE_NO_ERROR', 1);
243 $handlers = array(
'mod_syslog_file');
244 foreach ($handlers as $handler) {
245 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
246 if (!file_exists($file)) {
247 throw new Exception(
'Missing log handler file '.$handler.
'.php');
251 $loghandlerinstance =
new $handler();
252 if (!$loghandlerinstance instanceof
LogHandler) {
253 throw new Exception(
'Log handler does not extend LogHandler');
256 if (empty(
$conf->loghandlers[$handler])) {
257 $conf->loghandlers[$handler] = $loghandlerinstance;
262 $listofentities = array(1);
265 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
267 $hookmanager->initHooks(array(
'upgrade2'));
269 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto);
272 $reshook = $hookmanager->executeHooks(
'doUpgradeBefore', $parameters,
$object, $action);
273 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
275 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
285 dol_syslog(
"Process upgrade2 (step common to all entities)");
288 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN birth date';
290 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemployment date';
292 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN dateemploymentend date';
294 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_range integer';
296 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user ADD COLUMN default_c_exp_tax_cat integer';
298 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN langs varchar(24)';
300 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fieldcomputed text';
302 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN fielddefault varchar(255)';
304 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
"extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
306 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'extrafields ADD COLUMN help text';
308 $sql =
'ALTER TABLE '.MAIN_DB_PREFIX.
'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
314 foreach ($listofentities as $entity) {
315 dol_syslog(
"Process upgrade2 (step a) for entity ".$entity);
318 $conf->setEntityValues($db, $entity);
321 if (defined(
'SYSLOG_FILE')) {
322 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
325 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
327 $versiontoarray = array();
328 $versionranarray = array();
330 dol_syslog(
"Process upgrade2 (step b) for entity ".$entity);
333 if (count($listofentities) > 1) {
334 print
'<tr><td colspan="4">*** '.$langs->trans(
"Entity").
' '.$entity.
'</td></tr>'.
"\n";
345 $versiontoarray = explode(
'.', $versionto);
346 $versionranarray = explode(
'.', DOL_VERSION);
348 $afterversionarray = explode(
'.',
'2.0.0');
349 $beforeversionarray = explode(
'.',
'2.7.9');
351 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
412 $afterversionarray = explode(
'.',
'2.7.9');
413 $beforeversionarray = explode(
'.',
'2.8.9');
416 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
440 $afterversionarray = explode(
'.',
'2.8.9');
441 $beforeversionarray = explode(
'.',
'2.9.9');
443 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
455 $afterversionarray = explode(
'.',
'2.9.9');
456 $beforeversionarray = explode(
'.',
'3.0.9');
462 $afterversionarray = explode(
'.',
'3.0.9');
463 $beforeversionarray = explode(
'.',
'3.1.9');
465 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
473 $afterversionarray = explode(
'.',
'3.1.9');
474 $beforeversionarray = explode(
'.',
'3.2.9');
476 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
486 $afterversionarray = explode(
'.',
'3.2.9');
487 $beforeversionarray = explode(
'.',
'3.3.9');
489 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
498 $afterversionarray = explode(
'.',
'3.6.9');
499 $beforeversionarray = explode(
'.',
'3.7.9');
501 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
507 $afterversionarray = explode(
'.',
'3.7.9');
508 $beforeversionarray = explode(
'.',
'3.8.9');
514 $afterversionarray = explode(
'.',
'3.9.9');
515 $beforeversionarray = explode(
'.',
'4.0.9');
517 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
523 $afterversionarray = explode(
'.',
'4.0.9');
524 $beforeversionarray = explode(
'.',
'5.0.9');
526 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
536 $afterversionarray = explode(
'.',
'5.0.9');
537 $beforeversionarray = explode(
'.',
'6.0.9');
540 global $multicompany_transverse_mode;
543 if (empty($multicompany_transverse_mode)) {
544 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
556 $afterversionarray = explode(
'.',
'6.0.9');
557 $beforeversionarray = explode(
'.',
'7.0.9');
559 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
568 $afterversionarray = explode(
'.',
'7.0.9');
569 $beforeversionarray = explode(
'.',
'8.0.9');
571 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
577 $afterversionarray = explode(
'.',
'8.0.9');
578 $beforeversionarray = explode(
'.',
'9.0.9');
584 $afterversionarray = explode(
'.',
'10.0.9');
585 $beforeversionarray = explode(
'.',
'11.0.9');
587 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
596 $afterversionarray = explode(
'.',
'13.0.9');
597 $beforeversionarray = explode(
'.',
'14.0.9');
599 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
606 $afterversionarray = explode(
'.',
'15.0.9');
607 $beforeversionarray = explode(
'.',
'16.0.9');
609 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
616 $afterversionarray = explode(
'.',
'16.0.9');
617 $beforeversionarray = explode(
'.',
'17.0.9');
619 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
625 $afterversionarray = explode(
'.',
'17.0.9');
626 $beforeversionarray = explode(
'.',
'18.0.9');
628 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
642 $afterversionarray = explode(
'.',
'19.0.9');
643 $beforeversionarray = explode(
'.',
'20.0.9');
645 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
651 $afterversionarray = explode(
'.',
'20.0.9');
652 $beforeversionarray = explode(
'.',
'21.0.9');
656 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
662 $afterversionarray = explode(
'.',
'21.0.9');
663 $beforeversionarray = explode(
'.',
'22.0.9');
665 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
671 $afterversionarray = explode(
'.',
'22.0.9');
672 $beforeversionarray = explode(
'.',
'23.0.9');
674 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
684 $afterversionarray = explode(
'.',
'23.0.9');
685 $beforeversionarray = explode(
'.',
'24.0.9');
687 dol_syslog(
"Run migrate_... versionto is between ".json_encode($afterversionarray).
" and ".json_encode($beforeversionarray));
697 dol_syslog(
"Run migrate_... if migration is LAST ONE");
700 $listofmodule = array(
701 'MAIN_MODULE_ACCOUNTING' =>
'newboxdefonly',
702 'MAIN_MODULE_AGENDA' =>
'newboxdefonly',
703 'MAIN_MODULE_BOM' =>
'menuonly',
704 'MAIN_MODULE_BANQUE' =>
'menuonly',
705 'MAIN_MODULE_BARCODE' =>
'newboxdefonly',
706 'MAIN_MODULE_CRON' =>
'newboxdefonly',
707 'MAIN_MODULE_COMMANDE' =>
'newboxdefonly',
708 'MAIN_MODULE_BLOCKEDLOG' =>
'noboxes',
709 'MAIN_MODULE_DON' =>
'newboxdefonly',
710 'MAIN_MODULE_ECM' =>
'newboxdefonly',
711 'MAIN_MODULE_EVENTORGANIZATION' =>
'newboxdefonly',
712 'MAIN_MODULE_EXPENSEREPORT' =>
'newboxdefonly',
713 'MAIN_MODULE_FACTURE' =>
'newboxdefonly',
714 'MAIN_MODULE_FOURNISSEUR' =>
'newboxdefonly',
715 'MAIN_MODULE_FICHEINTER' =>
'newboxdefonly',
716 'MAIN_MODULE_HOLIDAY' =>
'newboxdefonly',
717 'MAIN_MODULE_LOAN' =>
'newboxdefonly',
718 'MAIN_MODULE_MARGIN' =>
'menuonly',
719 'MAIN_MODULE_MRP' =>
'menuonly',
720 'MAIN_MODULE_OPENSURVEY' =>
'newboxdefonly',
721 'MAIN_MODULE_PARTNERSHIP' =>
'newboxdefonly',
722 'MAIN_MODULE_PRINTING' =>
'newboxdefonly',
723 'MAIN_MODULE_PRODUIT' =>
'newboxdefonly',
724 'MAIN_MODULE_RECRUITMENT' =>
'menuonly',
725 'MAIN_MODULE_RESOURCE' =>
'noboxes',
726 'MAIN_MODULE_SALARIES' =>
'newboxdefonly',
727 'MAIN_MODULE_SERVICE' =>
'newboxdefonly',
729 'MAIN_MODULE_SOCIETE' =>
'newboxdefonly',
730 'MAIN_MODULE_STRIPE' =>
'menuonly',
731 'MAIN_MODULE_SUBTOTALS' =>
'menuonly',
732 'MAIN_MODULE_TICKET' =>
'newboxdefonly',
733 'MAIN_MODULE_TAKEPOS' =>
'newboxdefonly',
734 'MAIN_MODULE_USER' =>
'newboxdefonly',
735 'MAIN_MODULE_VARIANTS' =>
'newboxdefonly',
736 'MAIN_MODULE_WEBSITE' =>
'newboxdefonly',
762 if (!$error && $enablemodules) {
764 $listofmodules = array();
765 $enablemodules = preg_replace(
'/enablemodules=/',
'', $enablemodules);
766 $tmplistofmodules = explode(
',', $enablemodules);
767 foreach ($tmplistofmodules as $value) {
768 $listofmodules[$value] =
'forceactivate';
772 if ($resultreloadmodules < 0) {
780 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
783 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterDB', $parameters,
$object, $action);
784 if ($hookmanager->resNbOfHooks > 0) {
786 print
'<tr><td colspan="4">';
787 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
788 print $hookmanager->error;
789 print
"<!-- (".$reshook.
") -->";
792 print
'<tr class="trforrunsql"><td colspan="4">';
793 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (DB)</b>: <span class="ok">OK</span>';
794 print
"<!-- (".$reshook.
") -->";
799 if (!empty(
$conf->modules_parts[
'hooks'])) {
800 print
'<tr class="trforrunsql"><td colspan="4">';
801 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterDB");
812 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
827 foreach ($listofentities as $entity) {
829 $conf->setEntityValues($db, $entity);
831 if (defined(
'SYSLOG_FILE')) {
832 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
834 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
838 $srcroot = DOL_DOCUMENT_ROOT.
'/install/medias';
839 $destroot = DOL_DATA_ROOT.
'/medias';
852 $parameters = array(
'versionfrom' => $versionfrom,
'versionto' => $versionto,
'conf' =>
$conf);
855 $reshook = $hookmanager->executeHooks(
'doUpgradeAfterFiles', $parameters,
$object, $action);
856 if ($hookmanager->resNbOfHooks > 0) {
858 print
'<tr><td colspan="4">';
859 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: ';
860 print $hookmanager->error;
861 print
"<!-- (".$reshook.
") -->";
864 print
'<tr class="trforrunsql"><td colspan="4">';
865 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
' (Files)</b>: <span class="ok">OK</span>';
866 print
"<!-- (".$reshook.
") -->";
871 if (!empty(
$conf->modules_parts[
'hooks'])) {
872 print
'<tr class="trforrunsql"><td colspan="4">';
873 print
'<b>'.$langs->trans(
'UpgradeExternalModule').
'</b>: '.$langs->trans(
"NodoUpgradeAfterFiles");
883 print
'<table width="100%">';
884 print
'<tr><td style="width: 30%">'.$langs->trans(
"MigrationFinished").
'</td>';
885 print
'<td class="right">';
889 print
'<span class="error">'.$langs->trans(
"Error").
'</span> - ';
893 print
'<script type="text/javascript">
894 jQuery(document).ready(function() {
895 function init_trrunsql()
897 console.log("toggle .trforrunsql");
898 jQuery(".trforrunsql").toggle();
901 jQuery(".trforrunsqlshowhide").click(function() {
906 print
'<a class="reposition trforrunsqlshowhide" href="#">'.$langs->trans(
"ShowHideDetails").
'</a>';
909 print
'</td></tr>'.
"\n";
915 print
'<div class="error">'.$langs->trans(
'ErrorWrongParameters').
'</div>';
920if ($error && isset($argv[1])) {
926pFooter($error ? 2 : 0, $setuplang);
928if ($db !==
null && $db->connected) {
949 print
'<tr><td colspan="4">';
952 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
954 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
955 $obj = $db->fetch_object($result);
957 $sql =
"SELECT p.rowid, p.fk_facture, p.amount";
958 $sql .=
" FROM ".MAIN_DB_PREFIX.
"paiement as p";
959 $sql .=
" WHERE p.fk_facture > 0";
961 $resql = $db->query($sql);
968 $num = $db->num_rows($resql);
971 $obj = $db->fetch_object($resql);
972 $row[$i][0] = $obj->rowid;
973 $row[$i][1] = $obj->fk_facture;
974 $row[$i][2] = $obj->amount;
978 dol_print_error($db);
982 print $langs->trans(
'MigrationPaymentsNumberToUpdate', $num).
"<br>\n";
986 for ($i = 0; $i < $num; $i++) {
987 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
988 $sql .=
" VALUES (".((int) $row[$i][1]).
",".((int) $row[$i][0]).
",".((float) $row[$i][2]).
")";
990 $res += $db->query($sql);
992 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
994 $res += $db->query($sql);
996 print $langs->trans(
'MigrationProcessPaymentUpdate', $row[$i][0]).
"<br>\n";
1000 if (is_array($row) && $res == (2 * count($row))) {
1002 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1005 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1008 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
1011 print $langs->trans(
'MigrationPaymentsNothingToUpdate').
"<br>\n";
1029 print
'<tr><td colspan="4">';
1032 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
1034 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
1035 $obj = $db->fetch_object($result);
1038 $sql =
"SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1039 $sql .=
" bu2.url_id as socid";
1040 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
1041 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
1042 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
1043 $sql .=
" WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
1044 $sql .=
" AND b.rappro = 1";
1045 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1047 $resql = $db->query($sql);
1053 $num = $db->num_rows($resql);
1056 $obj = $db->fetch_object($resql);
1057 if ($obj->pamount == $obj->bamount && $obj->socid) {
1058 $row[$j][
'paymentid'] = $obj->rowid;
1059 $row[$j][
'pamount'] = $obj->pamount;
1060 $row[$j][
'fk_bank'] = $obj->fk_bank;
1061 $row[$j][
'bamount'] = $obj->bamount;
1062 $row[$j][
'socid'] = $obj->socid;
1063 $row[$j][
'datec'] = $obj->datec;
1069 dol_print_error($db);
1073 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 1).
': '.count($row).
"<br>\n";
1078 for ($i = 0; $i < $num; $i++) {
1080 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>';
1084 $sql =
" SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1085 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1086 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1087 $sql .=
" AND pf.fk_facture IS NULL";
1088 $sql .=
" ORDER BY f.fk_statut";
1090 $resql = $db->query($sql);
1092 $num = $db->num_rows($resql);
1095 $obj = $db->fetch_object($resql);
1096 $facid = $obj->rowid;
1098 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1099 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1101 $res += $db->query($sql);
1103 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1111 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1113 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1118 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1121 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1139 print
'<tr><td colspan="4">';
1142 print
'<b>'.$langs->trans(
'MigrationPaymentsUpdate').
"</b><br>\n";
1144 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiement",
"fk_facture");
1145 $obj = $db->fetch_object($result);
1148 $sql =
"SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1149 $sql .=
" bu2.url_id as socid";
1150 $sql .=
" FROM (".MAIN_DB_PREFIX.
"paiement as p, ".MAIN_DB_PREFIX.
"bank_url as bu, ".MAIN_DB_PREFIX.
"bank as b)";
1151 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON pf.fk_paiement = p.rowid";
1152 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
1153 $sql .=
" WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
1154 $sql .=
" AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1156 $resql = $db->query($sql);
1162 $num = $db->num_rows($resql);
1165 $obj = $db->fetch_object($resql);
1166 if ($obj->pamount == $obj->bamount && $obj->socid) {
1167 $row[$j][
'paymentid'] = $obj->rowid;
1168 $row[$j][
'pamount'] = $obj->pamount;
1169 $row[$j][
'fk_bank'] = $obj->fk_bank;
1170 $row[$j][
'bamount'] = $obj->bamount;
1171 $row[$j][
'socid'] = $obj->socid;
1172 $row[$j][
'datec'] = $obj->datec;
1178 dol_print_error($db);
1185 print $langs->trans(
'OrphelinsPaymentsDetectedByMethod', 2).
': '.count($row).
"<br>\n";
1189 for ($i = 0; $i < $num; $i++) {
1191 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>';
1195 $sql =
" SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX.
"facture as f";
1196 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"paiement_facture as pf ON f.rowid = pf.fk_facture";
1197 $sql .=
" WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i][
'socid']).
" AND total_ttc = ".((float) $row[$i][
'pamount']);
1198 $sql .=
" AND pf.fk_facture IS NULL";
1199 $sql .=
" ORDER BY f.fk_statut";
1201 $resql = $db->query($sql);
1203 $num = $db->num_rows($resql);
1206 $obj = $db->fetch_object($resql);
1207 $facid = $obj->rowid;
1209 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"paiement_facture (fk_facture, fk_paiement, amount)";
1210 $sql .=
" VALUES (".((int) $facid).
",".((int) $row[$i][
'paymentid']).
", ".((float) $row[$i][
'pamount']).
")";
1212 $res += $db->query($sql);
1214 print $langs->trans(
'MigrationProcessPaymentUpdate',
'facid='.$facid.
'-paymentid='.$row[$i][
'paymentid'].
'-amount='.$row[$i][
'pamount']).
"<br>\n";
1223 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1225 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1230 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1236 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiement DROP COLUMN fk_facture";
1246 print $langs->trans(
'MigrationPaymentsNothingUpdatable').
"<br>\n";
1263 print
'<tr><td colspan="4">';
1268 print
'<b>'.$langs->trans(
'MigrationContractsUpdate').
"</b><br>\n";
1270 $sql =
"SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1271 $sql .=
" p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
1273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p";
1274 $sql .=
" ON c.fk_product = p.rowid";
1275 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd";
1276 $sql .=
" ON c.rowid=cd.fk_contrat";
1277 $sql .=
" WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1278 $resql = $db->query($sql);
1284 $num = $db->num_rows($resql);
1287 print $langs->trans(
'MigrationContractsNumberToUpdate', $num).
"<br>\n";
1291 $obj = $db->fetch_object($resql);
1293 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet (";
1294 $sql .=
"fk_contrat, fk_product, statut, label, description,";
1295 $sql .=
"date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1296 $sql .=
"subprice, price_ht, fk_user_author, fk_user_ouverture)";
1297 $sql .=
" VALUES (";
1298 $sql .= ((int) $obj->cref).
", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).
", ";
1300 $sql .=
"'".$db->escape($obj->label).
"', null, ";
1301 $sql .= ($obj->date_contrat ?
"'".$db->idate($db->jdate($obj->date_contrat)).
"'" :
"null").
", ";
1304 $sql .= ((float) $obj->tva_tx).
", 1, ";
1305 $sql .= ((float) $obj->price).
", ".((float) $obj->price).
", ".((int) $obj->fk_user_author).
",";
1309 if ($db->query($sql)) {
1310 print $langs->trans(
'MigrationContractsLineCreation', $obj->cref).
"<br>\n";
1312 dol_print_error($db);
1322 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1325 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1328 print $langs->trans(
'MigrationContractsNothingToUpdate').
"<br>\n";
1331 print $langs->trans(
'MigrationContractsFieldDontExist').
"<br>\n";
1348 print
'<tr><td colspan="4">';
1353 print
'<b>'.$langs->trans(
'MigrationBankTransfertsUpdate').
"</b><br>\n";
1355 $sql =
"SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1356 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank as bb, ".MAIN_DB_PREFIX.
"bank as ba";
1357 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank_url as bu ON bu.fk_bank = ba.rowid";
1358 $sql .=
" WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1359 $sql .=
" AND ba.datev = bb.datev AND ba.datec = bb.datec";
1360 $sql .=
" AND bu.fk_bank IS NULL";
1361 $resql = $db->query($sql);
1367 $num = $db->num_rows($resql);
1370 print $langs->trans(
'MigrationBankTransfertsToUpdate', $num).
"<br>\n";
1374 $obj = $db->fetch_object($resql);
1376 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"bank_url (";
1377 $sql .=
"fk_bank, url_id, url, label, type";
1379 $sql .=
" VALUES (";
1380 $sql .= ((int) $obj->barowid).
",".((int) $obj->bbrowid).
", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1386 if (!$db->query($sql)) {
1387 dol_print_error($db);
1397 print $langs->trans(
'MigrationSuccessfullUpdate').
"<br>";
1400 print $langs->trans(
'MigrationUpdateFailed').
'<br>';
1403 print $langs->trans(
'MigrationBankTransfertsNothingToUpdate').
"<br>\n";
1406 dol_print_error($db);
1422 print
'<tr><td colspan="4">';
1425 print
'<b>'.$langs->trans(
'MigrationContractsEmptyDatesUpdate').
"</b><br>\n";
1427 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set date_contrat=tms where date_contrat is null";
1429 $resql = $db->query($sql);
1431 dol_print_error($db);
1433 if ($db->affected_rows($resql) > 0) {
1434 print $langs->trans(
'MigrationContractsEmptyDatesUpdateSuccess').
"<br>\n";
1436 print $langs->trans(
'MigrationContractsEmptyDatesNothingToUpdate').
"<br>\n";
1439 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=tms where datec is null";
1441 $resql = $db->query($sql);
1443 dol_print_error($db);
1445 if ($db->affected_rows($resql) > 0) {
1446 print $langs->trans(
'MigrationContractsEmptyCreationDatesUpdateSuccess').
"<br>\n";
1448 print $langs->trans(
'MigrationContractsEmptyCreationDatesNothingToUpdate').
"<br>\n";
1464 print
'<tr><td colspan="4">';
1469 print
'<b>'.$langs->trans(
'MigrationContractsInvalidDatesUpdate').
"</b><br>\n";
1471 $sql =
"SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1472 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c,";
1473 $sql .=
" ".MAIN_DB_PREFIX.
"contratdet as cd";
1474 $sql .=
" WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1475 $sql .=
" GROUP BY c.rowid, c.date_contrat";
1476 $resql = $db->query($sql);
1482 $num = $db->num_rows($resql);
1485 $nbcontratsmodifie = 0;
1489 $obj = $db->fetch_object($resql);
1490 if ($obj->date_contrat > $obj->datemin) {
1491 $datemin = $db->jdate($obj->datemin);
1493 print $langs->trans(
'MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin).
"<br>\n";
1494 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1495 $sql .=
" SET date_contrat='".$db->idate($datemin).
"'";
1496 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1497 $resql2 = $db->query($sql);
1499 dol_print_error($db);
1502 $nbcontratsmodifie++;
1509 if ($nbcontratsmodifie) {
1510 print $langs->trans(
'MigrationContractsInvalidDatesNumber', $nbcontratsmodifie).
"<br>\n";
1512 print $langs->trans(
'MigrationContractsInvalidDatesNothingToUpdate').
"<br>\n";
1516 dol_print_error($db);
1532 print
'<tr><td colspan="4">';
1535 print
'<b>'.$langs->trans(
'MigrationContractsIncoherentCreationDateUpdate').
"</b><br>\n";
1537 $sql =
"update ".MAIN_DB_PREFIX.
"contrat set datec=date_contrat where datec is null or datec > date_contrat";
1539 $resql = $db->query($sql);
1541 dol_print_error($db);
1543 if ($db->affected_rows($resql) > 0) {
1544 print $langs->trans(
'MigrationContractsIncoherentCreationDateUpdateSuccess').
"<br>\n";
1546 print $langs->trans(
'MigrationContractsIncoherentCreationDateNothingToUpdate').
"<br>\n";
1562 print
'<tr><td colspan="4">';
1565 print
'<b>'.$langs->trans(
'MigrationReopeningContracts').
"</b><br>\n";
1567 $sql =
"SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX.
"contrat as c, ".MAIN_DB_PREFIX.
"contratdet as cd";
1568 $sql .=
" WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1570 $resql = $db->query($sql);
1572 dol_print_error($db);
1574 if ($db->affected_rows($resql) > 0) {
1577 $num = $db->num_rows($resql);
1580 $nbcontratsmodifie = 0;
1584 $obj = $db->fetch_object($resql);
1586 print $langs->trans(
'MigrationReopenThisContract', $obj->cref).
"<br>\n";
1587 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat";
1588 $sql .=
" SET statut = 1";
1589 $sql .=
" WHERE rowid = ".((int) $obj->cref);
1590 $resql2 = $db->query($sql);
1592 dol_print_error($db);
1595 $nbcontratsmodifie++;
1602 if ($nbcontratsmodifie) {
1603 print $langs->trans(
'MigrationReopenedContractsNumber', $nbcontratsmodifie).
"<br>\n";
1605 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1609 print $langs->trans(
'MigrationReopeningContractsNothingToUpdate').
"<br>\n";
1627 print
'<tr><td colspan="4">';
1629 print
'<b>'.$langs->trans(
'SuppliersInvoices').
"</b><br>\n";
1632 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"paiementfourn",
"fk_facture_fourn");
1633 $obj = $db->fetch_object($result);
1638 $select_sql =
'SELECT rowid, fk_facture_fourn, amount';
1639 $select_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn';
1640 $select_sql .=
' WHERE fk_facture_fourn IS NOT NULL';
1643 $select_resql = $db->query($select_sql);
1644 if ($select_resql) {
1645 $select_num = $db->num_rows($select_resql);
1649 while (($i < $select_num) && (!$error)) {
1650 $select_obj = $db->fetch_object($select_resql);
1653 $check_sql =
'SELECT fk_paiementfourn, fk_facturefourn';
1654 $check_sql .=
' FROM '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn';
1655 $check_sql .=
' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).
' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1656 $check_resql = $db->query($check_sql);
1658 $check_num = $db->num_rows($check_resql);
1659 if ($check_num == 0) {
1663 print
'<tr><td colspan="4" class="nowrap"><b>'.$langs->trans(
'SuppliersInvoices').
'</b></td></tr>';
1664 print
'<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans(
'Amount').
'</td><td> </td></tr>';
1667 print
'<tr class="oddeven">';
1668 print
'<td>'.$select_obj->rowid.
'</td><td>'.$select_obj->fk_facture_fourn.
'</td><td>'.$select_obj->amount.
'</td>';
1670 $insert_sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'paiementfourn_facturefourn SET ';
1671 $insert_sql .=
' fk_paiementfourn = \''.((int) $select_obj->rowid).
'\',
';
1672 $insert_sql .= ' fk_facturefourn = \
''.((int) $select_obj->fk_facture_fourn).
'\',
';
1673 $insert_sql .= ' amount = \
''.((float) $select_obj->amount).
'\'';
1674 $insert_resql = $db->query($insert_sql);
1676 if ($insert_resql) {
1678 print
'<td><span class="ok">'.$langs->trans(
"OK").
'</span></td>';
1680 print
'<td><span class="error">Error on insert</span></td>';
1696 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1700 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"paiementfourn DROP COLUMN fk_facture_fourn";
1703 print
'<tr><td>'.$langs->trans(
"Error").
'</td></tr>';
1707 print
'<tr><td>'.$langs->trans(
"AlreadyDone").
'</td></tr>';
1724 $tmpmysoc->setMysoc(
$conf);
1728 print
'<tr><td colspan="4">';
1731 print
'<b>'.$langs->trans(
'MigrationInvoice').
"</b><br>\n";
1734 $sql =
"SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1735 $sql .=
" f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1736 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facturedet as fd, ".MAIN_DB_PREFIX.
"facture as f";
1737 $sql .=
" WHERE fd.fk_facture = f.rowid";
1738 $sql .=
" AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1742 $resql = $db->query($sql);
1744 $num = $db->num_rows($resql);
1748 $obj = $db->fetch_object($resql);
1750 $rowid = $obj->rowid;
1752 $pu = $obj->subprice;
1753 $vatrate = $obj->vatrate;
1754 $remise_percent = $obj->remise_percent;
1755 $remise_percent_global = $obj->remise_percent_global;
1756 $total_ttc_f = $obj->total_ttc_f;
1757 $info_bits = $obj->info_bits;
1761 $facligne->fetch($rowid);
1763 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1764 $total_ht = $result[0];
1765 $total_tva = $result[1];
1766 $total_ttc = $result[2];
1768 $facligne->total_ht = (float) $total_ht;
1769 $facligne->total_tva = (float) $total_tva;
1770 $facligne->total_ttc = (float) $total_ttc;
1772 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);
1774 $facligne->update_total();
1778 if (!$total_ttc_f) {
1780 $facture->id = $obj->facid;
1782 if ($facture->fetch($facture->id) >= 0) {
1783 if ($facture->update_price() > 0) {
1786 print
"Error id=".$facture->id;
1799 print $langs->trans(
"AlreadyDone");
1805 print
"Error #1 ".$db->error();
1827 $tmpmysoc->setMysoc(
$conf);
1831 print
'<tr><td colspan="4">';
1834 print
'<b>'.$langs->trans(
'MigrationProposal').
"</b><br>\n";
1837 $sql =
"SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1838 $sql .=
" p.rowid as propalid, p.remise_percent as remise_percent_global";
1839 $sql .=
" FROM ".MAIN_DB_PREFIX.
"propaldet as pd, ".MAIN_DB_PREFIX.
"propal as p";
1840 $sql .=
" WHERE pd.fk_propal = p.rowid";
1841 $sql .=
" AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1844 $resql = $db->query($sql);
1846 $num = $db->num_rows($resql);
1850 $obj = $db->fetch_object($resql);
1852 $rowid = $obj->rowid;
1854 $pu = $obj->subprice;
1855 $vatrate = $obj->vatrate;
1856 $remise_percent = $obj->remise_percent;
1857 $remise_percent_global = $obj->remise_percent_global;
1858 $info_bits = $obj->info_bits;
1862 $propalligne->fetch($rowid);
1864 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1865 $total_ht = $result[0];
1866 $total_tva = $result[1];
1867 $total_ttc = $result[2];
1869 $propalligne->total_ht = (float) $total_ht;
1870 $propalligne->total_tva = (float) $total_tva;
1871 $propalligne->total_ttc = (float) $total_ttc;
1873 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);
1875 $propalligne->update_total();
1880 print $langs->trans(
"AlreadyDone");
1887 print
"Error #1 ".$db->error();
1910 $tmpmysoc->setMysoc(
$conf);
1911 if (empty($tmpmysoc->country_id)) {
1912 $tmpmysoc->country_id = 0;
1915 print
'<tr><td colspan="4">';
1918 print
'<b>'.$langs->trans(
'MigrationContract').
"</b><br>\n";
1921 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1922 $sql .=
" c.rowid as contratid";
1923 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd, ".MAIN_DB_PREFIX.
"contrat as c";
1924 $sql .=
" WHERE cd.fk_contrat = c.rowid";
1925 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1928 $resql = $db->query($sql);
1930 $num = $db->num_rows($resql);
1934 $obj = $db->fetch_object($resql);
1936 $rowid = $obj->rowid;
1938 $pu = $obj->subprice;
1939 $vatrate = $obj->vatrate;
1940 $remise_percent = $obj->remise_percent;
1941 $info_bits = $obj->info_bits;
1946 $contratligne->fetch($rowid);
1948 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0,
'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1949 $total_ht = $result[0];
1950 $total_tva = $result[1];
1951 $total_ttc = $result[2];
1953 $contratligne->total_ht = (float) $total_ht;
1954 $contratligne->total_tva = (float) $total_tva;
1955 $contratligne->total_ttc = (float) $total_ttc;
1957 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);
1959 $contratligne->update_total();
1964 print $langs->trans(
"AlreadyDone");
1971 print
"Error #1 ".$db->error();
1994 $tmpmysoc->setMysoc(
$conf);
1996 print
'<tr><td colspan="4">';
1999 print
'<b>'.$langs->trans(
'MigrationOrder').
"</b><br>\n";
2002 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2003 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
2004 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"commande as c";
2005 $sql .=
" WHERE cd.fk_commande = c.rowid";
2006 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2009 $resql = $db->query($sql);
2011 $num = $db->num_rows($resql);
2015 $obj = $db->fetch_object($resql);
2017 $rowid = $obj->rowid;
2019 $pu = $obj->subprice;
2020 $vatrate = $obj->vatrate;
2021 $remise_percent = $obj->remise_percent;
2022 $remise_percent_global = $obj->remise_percent_global;
2023 $info_bits = $obj->info_bits;
2027 $commandeligne->fetch($rowid);
2029 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
2030 $total_ht = $result[0];
2031 $total_tva = $result[1];
2032 $total_ttc = $result[2];
2034 $commandeligne->total_ht = (float) $total_ht;
2035 $commandeligne->total_tva = (float) $total_tva;
2036 $commandeligne->total_ttc = (float) $total_ttc;
2038 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);
2040 $commandeligne->update_total();
2045 print $langs->trans(
"AlreadyDone");
2062 print
"Error #1 ".$db->error();
2087 $tmpmysoc->setMysoc(
$conf);
2089 print
'<tr><td colspan="4">';
2092 print
'<b>'.$langs->trans(
'MigrationSupplierOrder').
"</b><br>\n";
2095 $sql =
"SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2096 $sql .=
" c.rowid as commandeid, c.remise_percent as remise_percent_global";
2097 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as cd, ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
2098 $sql .=
" WHERE cd.fk_commande = c.rowid";
2099 $sql .=
" AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2102 $resql = $db->query($sql);
2104 $num = $db->num_rows($resql);
2108 $obj = $db->fetch_object($resql);
2110 $rowid = $obj->rowid;
2112 $pu = $obj->subprice;
2113 $vatrate = $obj->vatrate;
2114 $remise_percent = $obj->remise_percent;
2115 $remise_percent_global = $obj->remise_percent_global;
2116 $info_bits = $obj->info_bits;
2120 $commandeligne->fetch($rowid);
2122 $result =
calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global,
'HT', $info_bits, $commandeligne->product_type,
$mysoc);
2123 $total_ht = $result[0];
2124 $total_tva = $result[1];
2125 $total_ttc = $result[2];
2127 $commandeligne->total_ht = (float) $total_ht;
2128 $commandeligne->total_tva = (float) $total_tva;
2129 $commandeligne->total_ttc = (float) $total_ttc;
2131 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);
2133 $commandeligne->update_total();
2138 print $langs->trans(
"AlreadyDone");
2155 print
"Error #1 ".$db->error();
2181 include_once DOL_DOCUMENT_ROOT.
'/core/modules/facture/modules_facture.php';
2183 if (count($modellist) == 0) {
2185 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('crabe','invoice')";
2186 $resql = $db->query($sql);
2188 dol_print_error($db);
2194 include_once DOL_DOCUMENT_ROOT.
'/core/modules/commande/modules_commande.php';
2196 if (count($modellist) == 0) {
2198 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('einstein','order')";
2199 $resql = $db->query($sql);
2201 dol_print_error($db);
2207 include_once DOL_DOCUMENT_ROOT.
'/core/modules/expedition/modules_expedition.php';
2209 if (count($modellist) == 0) {
2211 $sql =
" insert into ".MAIN_DB_PREFIX.
"document_model(nom,type) values('rouget','shipping')";
2212 $resql = $db->query($sql);
2214 dol_print_error($db);
2235 print
'<tr><td colspan="4">';
2238 print
'<b>'.$langs->trans(
'MigrationShipmentOrderMatching').
"</b><br>\n";
2240 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"fk_commande");
2241 $obj = $db->fetch_object($result);
2247 $sql =
"SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX.
"expedition as e";
2248 $resql = $db->query($sql);
2251 $num = $db->num_rows($resql);
2255 $obj = $db->fetch_object($resql);
2257 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_exp (fk_expedition,fk_commande)";
2258 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2259 $resql2 = $db->query($sql);
2263 dol_print_error($db);
2272 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition DROP COLUMN fk_commande";
2273 print $langs->trans(
'FieldRenamed').
"<br>\n";
2279 dol_print_error($db);
2283 print $langs->trans(
'AlreadyDone').
"<br>\n";
2300 print
'<tr><td colspan="4">';
2303 print
'<b>'.$langs->trans(
'MigrationDeliveryOrderMatching').
"</b><br>\n";
2305 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_commande");
2306 $obj = $db->fetch_object($result);
2312 $sql =
"SELECT l.rowid, l.fk_commande,";
2313 $sql .=
" c.ref_client, c.date_livraison as delivery_date";
2314 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l, ".MAIN_DB_PREFIX.
"commande as c";
2315 $sql .=
" WHERE c.rowid = l.fk_commande";
2316 $resql = $db->query($sql);
2319 $num = $db->num_rows($resql);
2323 $obj = $db->fetch_object($resql);
2325 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"co_liv (fk_livraison,fk_commande)";
2326 $sql .=
" VALUES (".((int) $obj->rowid).
", ".((int) $obj->fk_commande).
")";
2327 $resql2 = $db->query($sql);
2330 $delivery_date = $db->jdate($obj->delivery_date);
2332 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2333 $sqlu .=
" ref_client = '".$db->escape($obj->ref_client).
"'";
2334 $sqlu .=
", date_livraison = '".$db->idate($delivery_date).
"'";
2335 $sqlu .=
" WHERE rowid = ".((int) $obj->rowid);
2336 $resql3 = $db->query($sqlu);
2339 dol_print_error($db);
2343 dol_print_error($db);
2352 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_commande";
2353 print $langs->trans(
'FieldRenamed').
"<br>\n";
2359 dol_print_error($db);
2363 print $langs->trans(
'AlreadyDone').
"<br>\n";
2380 print
'<tr><td colspan="4">';
2383 print
'<b>'.$langs->trans(
'MigrationDeliveryDetail').
"</b><br>\n";
2387 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_commande_ligne");
2388 $obj = $db->fetch_object($result);
2394 $sql =
"SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2395 $sql .=
", ld.fk_livraison";
2396 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commandedet as cd, ".MAIN_DB_PREFIX.
"livraisondet as ld";
2397 $sql .=
" WHERE ld.fk_commande_ligne = cd.rowid";
2398 $resql = $db->query($sql);
2401 $num = $db->num_rows($resql);
2405 $obj = $db->fetch_object($resql);
2407 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"livraisondet SET";
2408 $sql .=
" fk_product = ".((int) $obj->fk_product);
2409 $sql .=
",description = '".$db->escape($obj->description).
"'";
2410 $sql .=
",subprice = ".price2num($obj->subprice);
2411 $sql .=
",total_ht = ".price2num($obj->total_ht);
2412 $sql .=
" WHERE fk_commande_ligne = ".((int) $obj->rowid);
2413 $resql2 = $db->query($sql);
2416 $sql =
"SELECT total_ht";
2417 $sql .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
2418 $sql .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2419 $resql3 = $db->query($sql);
2422 $obju = $db->fetch_object($resql3);
2423 $total_ht = $obju->total_ht + $obj->total_ht;
2425 $sqlu =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
2426 $sqlu .=
" total_ht = ".price2num($total_ht,
'MT');
2427 $sqlu .=
" WHERE rowid = ".((int) $obj->fk_livraison);
2428 $resql4 = $db->query($sqlu);
2431 dol_print_error($db);
2435 dol_print_error($db);
2439 dol_print_error($db);
2448 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2449 print $langs->trans(
'FieldRenamed').
"<br>\n";
2455 dol_print_error($db);
2459 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraisondet",
"fk_origin_line");
2460 $obj = $db->fetch_object($result);
2462 $sql =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2465 print $langs->trans(
'AlreadyDone').
"<br>\n";
2482 print
'<tr><td colspan="4">';
2485 print
'<b>'.$langs->trans(
'MigrationStockDetail').
"</b><br>\n";
2491 $sql =
"SELECT SUM(reel) as total, fk_product";
2492 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product_stock as ps";
2493 $sql .=
" GROUP BY fk_product";
2494 $resql = $db->query($sql);
2497 $num = $db->num_rows($resql);
2501 $obj = $db->fetch_object($resql);
2503 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"product SET";
2504 $sql .=
" stock = ".price2num($obj->total,
'MS');
2505 $sql .=
" WHERE rowid = ".((int) $obj->fk_product);
2507 $resql2 = $db->query($sql);
2511 dol_print_error($db);
2524 dol_print_error($db);
2544 print
'<tr><td colspan="4">';
2547 print
'<b>'.$langs->trans(
'MigrationMenusDetail').
"</b><br>\n";
2551 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"menu_constraint")) {
2554 $sql =
"SELECT m.rowid, mc.action";
2555 $sql .=
" FROM ".MAIN_DB_PREFIX.
"menu_constraint as mc, ".MAIN_DB_PREFIX.
"menu_const as md, ".MAIN_DB_PREFIX.
"menu as m";
2556 $sql .=
" WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2557 $sql .=
" AND m.enabled = '1'";
2558 $resql = $db->query($sql);
2561 $num = $db->num_rows($resql);
2564 $obj = $db->fetch_object($resql);
2566 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"menu SET";
2567 $sql .=
" enabled = '".$db->escape($obj->action).
"'";
2568 $sql .=
" WHERE rowid = ".((int) $obj->rowid);
2569 $sql .=
" AND enabled = '1'";
2571 $resql2 = $db->query($sql);
2575 dol_print_error($db);
2588 dol_print_error($db);
2592 print $langs->trans(
'AlreadyDone').
"<br>\n";
2611 print
'<tr><td colspan="4">';
2614 print
'<b>'.$langs->trans(
'MigrationDeliveryAddress').
"</b><br>\n";
2618 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"co_exp")) {
2621 $sql =
"SELECT c.fk_adresse_livraison, ce.fk_expedition";
2622 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande as c";
2623 $sql .=
", ".MAIN_DB_PREFIX.
"co_exp as ce";
2624 $sql .=
" WHERE c.rowid = ce.fk_commande";
2625 $sql .=
" AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2627 $resql = $db->query($sql);
2630 $num = $db->num_rows($resql);
2634 $obj = $db->fetch_object($resql);
2636 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
2637 $sql .=
" fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison).
"'";
2638 $sql .=
" WHERE rowid = ".((int) $obj->fk_expedition);
2640 $resql2 = $db->query($sql);
2643 dol_print_error($db);
2649 print $langs->trans(
'AlreadyDone').
"<br>\n";
2658 dol_print_error($db);
2662 print $langs->trans(
'AlreadyDone').
"<br>\n";
2681 if (($db->type ==
'mysql' || $db->type ==
'mysqli')) {
2683 dolibarr_install_syslog(
"upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2687 print
'<tr><td colspan="4">';
2690 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (1)<br>\n";
2696 $table1 =
'facturedet';
2697 $field1 =
'fk_remise_except';
2698 $table2 =
'societe_remise_except';
2699 $field2 =
'fk_facture_line';
2703 $sql =
"SELECT t1.rowid, t1.".$db->sanitize($field1).
" as field";
2704 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($table1).
" as t1";
2705 $sql .=
" WHERE t1.".$db->sanitize($field1).
" IS NOT NULL AND t1.".$db->sanitize($field1).
" NOT IN";
2706 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2).
" as t2";
2707 $sql .=
" WHERE t1.rowid = t2.".$db->sanitize($field2).
")";
2710 $resql = $db->query($sql);
2713 $num = $db->num_rows($resql);
2717 $obj = $db->fetch_object($resql);
2719 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2721 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2722 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2723 $sql .=
" WHERE rowid = ".((int) $obj->field);
2725 $resql2 = $db->query($sql);
2728 dol_print_error($db);
2734 print $langs->trans(
'AlreadyDone').
"<br>\n";
2743 dol_print_error($db);
2750 print
'<tr><td colspan="4">';
2753 print
'<b>'.$langs->trans(
'MigrationFixData').
"</b> (2)<br>\n";
2756 $table2 =
'facturedet';
2757 $field2 =
'fk_remise_except';
2758 $table1 =
'societe_remise_except';
2759 $field1 =
'fk_facture_line';
2763 $sql =
"SELECT t1.rowid, t1.".$db->sanitize($field1).
" as field";
2764 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($table1).
" as t1";
2765 $sql .=
" WHERE t1.".$db->sanitize($field1).
" IS NOT NULL AND t1.".$db->sanitize($field1).
" NOT IN";
2766 $sql .=
" (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2).
" as t2";
2767 $sql .=
" WHERE t1.rowid = t2.".$db->sanitize($field2).
")";
2770 $resql = $db->query($sql);
2773 $num = $db->num_rows($resql);
2777 $obj = $db->fetch_object($resql);
2779 print
'Line '.$obj->rowid.
' in '.$table1.
' is linked to record '.$obj->field.
' in '.$table2.
' that has no link to '.$table1.
'. We fix this.<br>';
2781 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2).
" SET";
2782 $sql .=
" ".$db->sanitize($field2).
" = '".$db->escape($obj->rowid).
"'";
2783 $sql .=
" WHERE rowid = ".((int) $obj->field);
2785 $resql2 = $db->query($sql);
2788 dol_print_error($db);
2794 print $langs->trans(
'AlreadyDone').
"<br>\n";
2803 dol_print_error($db);
2809 return ($error ? -1 : 1);
2824 print
'<tr><td colspan="4">';
2827 print
'<b>'.$langs->trans(
'MigrationProjectUserResp').
"</b><br>\n";
2829 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"projet",
"fk_user_resp");
2830 $obj = $db->fetch_object($result);
2836 $sql =
"SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX.
"projet";
2837 $resql = $db->query($sql);
2840 $num = $db->num_rows($resql);
2844 $obj = $db->fetch_object($resql);
2846 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2847 $sql2 .=
"datecreate";
2848 $sql2 .=
", statut";
2849 $sql2 .=
", element_id";
2850 $sql2 .=
", fk_c_type_contact";
2851 $sql2 .=
", fk_socpeople";
2852 $sql2 .=
") VALUES (";
2853 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2855 $sql2 .=
", ".((int) $obj->rowid);
2857 $sql2 .=
", ".((int) $obj->fk_user_resp);
2860 if ($obj->fk_user_resp > 0) {
2861 $resql2 = $db->query($sql2);
2864 dol_print_error($db);
2874 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"projet DROP COLUMN fk_user_resp";
2875 if ($db->query($sqlDrop)) {
2884 dol_print_error($db);
2888 print $langs->trans(
'AlreadyDone').
"<br>\n";
2905 print
'<tr><td colspan="4">';
2908 print
'<b>'.$langs->trans(
'MigrationProjectTaskActors').
"</b><br>\n";
2910 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"projet_task_actors")) {
2915 $sql =
"SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX.
"projet_task_actors";
2916 $resql = $db->query($sql);
2919 $num = $db->num_rows($resql);
2923 $obj = $db->fetch_object($resql);
2925 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_contact (";
2926 $sql2 .=
"datecreate";
2927 $sql2 .=
", statut";
2928 $sql2 .=
", element_id";
2929 $sql2 .=
", fk_c_type_contact";
2930 $sql2 .=
", fk_socpeople";
2931 $sql2 .=
") VALUES (";
2932 $sql2 .=
"'".$db->idate(
dol_now()).
"'";
2934 $sql2 .=
", ".((int) $obj->fk_project_task);
2936 $sql2 .=
", ".((int) $obj->fk_user);
2939 $resql2 = $db->query($sql2);
2943 dol_print_error($db);
2951 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.
"projet_task_actors";
2952 if ($db->query($sqlDrop)) {
2961 dol_print_error($db);
2965 print $langs->trans(
'AlreadyDone').
"<br>\n";
2985 print
'<tr><td colspan="4">';
2988 print
'<b>'.$langs->trans(
'MigrationRelationshipTables', MAIN_DB_PREFIX.$table).
"</b><br>\n";
2992 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2997 $sqlSelect =
"SELECT ".$db->sanitize($fk_source).
", ".$db->sanitize($fk_target);
2998 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.$table;
3000 $resql = $db->query($sqlSelect);
3003 $num = $db->num_rows($resql);
3007 $obj = $db->fetch_object($resql);
3009 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3010 $sqlInsert .=
"fk_source";
3011 $sqlInsert .=
", sourcetype";
3012 $sqlInsert .=
", fk_target";
3013 $sqlInsert .=
", targettype";
3014 $sqlInsert .=
") VALUES (";
3015 $sqlInsert .= ((int) $obj->$fk_source);
3016 $sqlInsert .=
", '".$db->escape($sourcetype).
"'";
3017 $sqlInsert .=
", ".((int) $obj->$fk_target);
3018 $sqlInsert .=
", '".$db->escape($targettype).
"'";
3021 $result = $db->query($sqlInsert);
3024 dol_print_error($db);
3030 print $langs->trans(
'AlreadyDone').
"<br>\n";
3034 $sqlDrop =
"DROP TABLE ".MAIN_DB_PREFIX.$db->sanitize($table);
3035 if ($db->query($sqlDrop)) {
3044 dol_print_error($db);
3048 print $langs->trans(
'AlreadyDone').
"<br>\n";
3066 print
'<tr><td colspan="4">';
3069 print
'<b>'.$langs->trans(
'MigrationProjectTaskTime').
"</b><br>\n";
3075 $sql =
"SELECT rowid, fk_element, element_duration";
3076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"element_time";
3077 $resql = $db->query($sql);
3080 $num = $db->num_rows($resql);
3083 $totaltime = array();
3087 $obj = $db->fetch_object($resql);
3089 if ($obj->element_duration > 0) {
3092 list($hour, $min) = explode(
'.', $obj->element_duration);
3093 $hour = (int) $hour * 60 * 60;
3094 $min = (int) ((
float) (
'.'.$min)) * 3600;
3095 $newtime = $hour + $min;
3097 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"element_time SET";
3098 $sql2 .=
" element_duration = ".((int) $newtime);
3099 $sql2 .=
" WHERE rowid = ".((int) $obj->rowid);
3101 $resql2 = $db->query($sql2);
3104 dol_print_error($db);
3108 if (!empty($totaltime[$obj->fk_element])) {
3109 $totaltime[$obj->fk_element] += $newtime;
3111 $totaltime[$obj->fk_element] = $newtime;
3114 if (!empty($totaltime[$obj->fk_element])) {
3115 $totaltime[$obj->fk_element] += $obj->element_duration;
3117 $totaltime[$obj->fk_element] = $obj->element_duration;
3126 foreach ($totaltime as $taskid => $total_duration) {
3127 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET";
3128 $sql .=
" duration_effective = ".((int) $total_duration);
3129 $sql .=
" WHERE rowid = ".((int) $taskid);
3131 $resql = $db->query($sql);
3134 dol_print_error($db);
3138 print $langs->trans(
'AlreadyDone').
"<br>\n";
3141 dol_print_error($db);
3144 print $langs->trans(
'AlreadyDone').
"<br>\n";
3147 dol_print_error($db);
3169 print
'<tr><td colspan="4">';
3172 print
'<b>'.$langs->trans(
'MigrationCustomerOrderShipping').
"</b><br>\n";
3176 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"ref_customer");
3177 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX.
"expedition",
"date_delivery");
3178 $obj1 = $db->fetch_object($result1);
3179 $obj2 = $db->fetch_object($result2);
3180 if (!$obj1 && !$obj2) {
3185 $sqlAdd1 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3186 $sqlAdd2 =
"ALTER TABLE ".MAIN_DB_PREFIX.
"expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3188 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3189 $sqlSelect =
"SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3190 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"expedition as e";
3191 $sqlSelect .=
", ".MAIN_DB_PREFIX.
"element_element as el";
3192 $sqlSelect .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3193 $sqlSelect .=
" WHERE e.rowid = el.fk_target";
3194 $sqlSelect .=
" AND el.targettype = 'shipping'";
3196 $resql = $db->query($sqlSelect);
3199 $num = $db->num_rows($resql);
3203 $obj = $db->fetch_object($resql);
3205 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"expedition SET";
3206 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_client).
"'";
3207 $sqlUpdate .=
", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date :
'null').
"'";
3208 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->shipping_id);
3210 $result = $db->query($sqlUpdate);
3213 dol_print_error($db);
3219 print $langs->trans(
'AlreadyDone').
"<br>\n";
3225 dol_print_error($db);
3229 dol_print_error($db);
3233 dol_print_error($db);
3237 print $langs->trans(
'AlreadyDone').
"<br>\n";
3253 print
'<tr><td colspan="4">';
3256 print
'<b>'.$langs->trans(
'MigrationShippingDelivery').
"</b><br>\n";
3260 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"livraison",
"fk_expedition");
3261 $obj = $db->fetch_object($result);
3267 $sqlSelect =
"SELECT rowid, fk_expedition";
3268 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison";
3269 $sqlSelect .=
" WHERE fk_expedition is not null";
3271 $resql = $db->query($sqlSelect);
3274 $num = $db->num_rows($resql);
3278 $obj = $db->fetch_object($resql);
3280 $sqlInsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
3281 $sqlInsert .=
"fk_source";
3282 $sqlInsert .=
", sourcetype";
3283 $sqlInsert .=
", fk_target";
3284 $sqlInsert .=
", targettype";
3285 $sqlInsert .=
") VALUES (";
3286 $sqlInsert .= ((int) $obj->fk_expedition);
3287 $sqlInsert .=
", 'shipping'";
3288 $sqlInsert .=
", ".((int) $obj->rowid);
3289 $sqlInsert .=
", 'delivery'";
3292 $result = $db->query($sqlInsert);
3294 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET fk_expedition = NULL";
3295 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3297 $result = $db->query($sqlUpdate);
3300 dol_print_error($db);
3305 dol_print_error($db);
3310 print $langs->trans(
'AlreadyDone').
"<br>\n";
3314 $sqlDelete =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3315 $db->query($sqlDelete);
3320 $sqlDrop =
"ALTER TABLE ".MAIN_DB_PREFIX.
"livraison DROP COLUMN fk_expedition";
3321 $db->query($sqlDrop);
3323 dol_print_error($db);
3327 dol_print_error($db);
3331 print $langs->trans(
'AlreadyDone').
"<br>\n";
3348 print
'<tr><td colspan="4">';
3351 print
'<b>'.$langs->trans(
'MigrationShippingDelivery2').
"</b><br>\n";
3359 $sqlSelect =
"SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3360 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"livraison as l,";
3361 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"element_element as el,";
3362 $sqlSelect .=
" ".MAIN_DB_PREFIX.
"expedition as e";
3363 $sqlSelect .=
" WHERE l.rowid = el.fk_target";
3364 $sqlSelect .=
" AND el.targettype = 'delivery'";
3365 $sqlSelect .=
" AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3366 $sqlSelect .=
" AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)";
3368 $sqlSelect .=
" AND (l.ref_customer IS NULL".($db->type !=
'pgsql' ?
" or l.ref_customer = ''" :
"").
")";
3369 $sqlSelect .=
" AND (l.date_delivery IS NULL".($db->type !=
'pgsql' ?
" or l.date_delivery = ''" :
"").
")";
3371 $resql = $db->query($sqlSelect);
3374 $num = $db->num_rows($resql);
3378 $obj = $db->fetch_object($resql);
3380 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"livraison SET";
3381 $sqlUpdate .=
" ref_customer = '".$db->escape($obj->ref_customer).
"',";
3382 $sqlUpdate .=
" date_delivery = ".($obj->date_delivery ?
"'".$db->escape($obj->date_delivery).
"'" :
'null');
3383 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->delivery_id);
3385 $result = $db->query($sqlUpdate);
3388 dol_print_error($db);
3394 print $langs->trans(
'AlreadyDone').
"<br>\n";
3400 dol_print_error($db);
3404 dol_print_error($db);
3421 print
'<tr><td colspan="4">';
3424 print
'<b>'.$langs->trans(
'MigrationActioncommElement').
"</b><br>\n";
3427 'propal' =>
'propalrowid',
3428 'order' =>
'fk_commande',
3429 'invoice' =>
'fk_facture',
3430 'contract' =>
'fk_contract',
3431 'order_supplier' =>
'fk_supplier_order',
3432 'invoice_supplier' =>
'fk_supplier_invoice'
3435 foreach ($elements as $type => $field) {
3436 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"actioncomm", $field);
3437 $obj = $db->fetch_object($result);
3443 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ";
3444 $sql .=
"fk_element = ".$db->sanitize($field).
", elementtype = '".$db->escape($type).
"'";
3445 $sql .=
" WHERE ".$db->sanitize($field).
" IS NOT NULL";
3446 $sql .=
" AND fk_element IS NULL";
3447 $sql .=
" AND elementtype IS NULL";
3449 $resql = $db->query($sql);
3459 dol_print_error($db);
3463 print $langs->trans(
'AlreadyDone').
"<br>\n";
3480 print
'<tr><td colspan="4">';
3483 print
'<b>'.$langs->trans(
'MigrationPaymentMode').
"</b><br>\n";
3486 'old_id' => array(5, 8, 9, 10, 11),
3487 'new_id' => array(50, 51, 52, 53, 54),
3488 'code' => array(
'VAD',
'TRA',
'LCR',
'FAC',
'PRO'),
3489 'tables' => array(
'commande_fournisseur',
'commande',
'facture_rec',
'facture',
'propal')
3493 foreach ($elements[
'old_id'] as $key => $old_id) {
3498 $sqlSelect =
"SELECT id";
3499 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement";
3500 $sqlSelect .=
" WHERE id = ".((int) $old_id);
3501 $sqlSelect .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3503 $resql = $db->query($sqlSelect);
3505 $num = $db->num_rows($resql);
3511 $sqla =
"UPDATE ".MAIN_DB_PREFIX.
"paiement SET";
3512 $sqla .=
" fk_paiement = ".((int) $elements[
'new_id'][$key]);
3513 $sqla .=
" WHERE fk_paiement = ".((int) $old_id);
3514 $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]).
"')";
3515 $resqla = $db->query($sqla);
3517 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"c_paiement SET";
3518 $sql .=
" id = ".((int) $elements[
'new_id'][$key]);
3519 $sql .=
" WHERE id = ".((int) $old_id);
3520 $sql .=
" AND code = '".$db->escape($elements[
'code'][$key]).
"'";
3521 $resql = $db->query($sql);
3523 if ($resqla && $resql) {
3524 foreach ($elements[
'tables'] as $table) {
3525 $sql =
"UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table).
" SET ";
3526 $sql .=
"fk_mode_reglement = ".((int) $elements[
'new_id'][$key]);
3527 $sql .=
" WHERE fk_mode_reglement = ".((int) $old_id);
3529 $resql = $db->query($sql);
3531 dol_print_error($db);
3540 dol_print_error($db);
3544 dol_print_error($db);
3552 print $langs->trans(
'AlreadyDone').
"<br>\n";
3570 $result = $db->DDLDescTable(MAIN_DB_PREFIX.
"categorie_association");
3572 $obj = $db->fetch_object($result);
3575 $children = array();
3576 $sql =
"SELECT fk_categorie_mere, fk_categorie_fille";
3577 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3579 $resql = $db->query($sql);
3581 $num = $db->num_rows($resql);
3582 while ($obj = $db->fetch_object($resql)) {
3583 if (!isset($children[$obj->fk_categorie_fille])) {
3584 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3585 $children[$obj->fk_categorie_fille] = 1;
3586 $couples[$obj->fk_categorie_mere.
'_'.$obj->fk_categorie_fille] = array(
'mere' => $obj->fk_categorie_mere,
'fille' => $obj->fk_categorie_fille);
3594 if (count($couples) > 0 && $num > count($couples)) {
3600 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_association";
3602 $resqld = $db->query($sql);
3605 foreach ($couples as $key => $val) {
3606 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_association(fk_categorie_mere,fk_categorie_fille)";
3607 $sql .=
" VALUES(".((int) $val[
'mere']).
", ".((int) $val[
'fille']).
")";
3609 $resqli = $db->query($sql);
3617 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3618 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Success").
' ('.$num.
'=>'.count($couples).
')</td></tr>';
3621 print
'<tr><td>'.$langs->trans(
"MigrationCategorieAssociation").
'</td>';
3622 print
'<td class="right">'.$langs->trans(
"RemoveDuplicates").
' '.$langs->trans(
"Failed").
'</td></tr>';
3627 print
'<tr><td>'.$langs->trans(
"Error").
'</td>';
3628 print
'<td class="right"><div class="error">'.$db->lasterror().
'</div></td></tr>';
3645 print
'<tr><td colspan="4">';
3648 print
'<b>'.$langs->trans(
'MigrationCategorieAssociation').
"</b><br>\n";
3652 if ($db->DDLInfoTable(MAIN_DB_PREFIX.
"categorie_association")) {
3657 $sqlSelect =
"SELECT fk_categorie_mere, fk_categorie_fille";
3658 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"categorie_association";
3660 $resql = $db->query($sqlSelect);
3663 $num = $db->num_rows($resql);
3667 $obj = $db->fetch_object($resql);
3669 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"categorie SET ";
3670 $sqlUpdate .=
"fk_parent = ".((int) $obj->fk_categorie_mere);
3671 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->fk_categorie_fille);
3673 $result = $db->query($sqlUpdate);
3676 dol_print_error($db);
3682 print $langs->trans(
'AlreadyDone').
"<br>\n";
3691 dol_print_error($db);
3695 print $langs->trans(
'AlreadyDone').
"<br>\n";
3711 print
'<tr><td colspan="4">';
3714 print
'<b>'.$langs->trans(
'MigrationEvents').
"</b><br>\n";
3722 $sqlSelect =
"SELECT a.id, a.fk_user_action";
3723 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3724 $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";
3725 $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')";
3726 $sqlSelect .=
" ORDER BY a.id";
3729 $resql = $db->query($sqlSelect);
3732 $num = $db->num_rows($resql);
3736 $obj = $db->fetch_object($resql);
3738 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3739 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'user', ".((int) $obj->fk_user_action).
")";
3741 $result = $db->query($sqlUpdate);
3744 dol_print_error($db);
3750 print $langs->trans(
'AlreadyDone').
"<br>\n";
3759 dol_print_error($db);
3777 print
'<tr><td colspan="4">';
3780 print
'<b>'.$langs->trans(
'MigrationEventsContact').
"</b><br>\n";
3788 $sqlSelect =
"SELECT a.id, a.fk_contact";
3789 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
3790 $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";
3791 $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')";
3792 $sqlSelect .=
" ORDER BY a.id";
3795 $resql = $db->query($sqlSelect);
3798 $num = $db->num_rows($resql);
3802 $obj = $db->fetch_object($resql);
3804 $sqlUpdate =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3805 $sqlUpdate .=
"VALUES(".((int) $obj->id).
", 'socpeople', ".((int) $obj->fk_contact).
")";
3807 $result = $db->query($sqlUpdate);
3810 dol_print_error($db);
3816 print $langs->trans(
'AlreadyDone').
"<br>\n";
3825 dol_print_error($db);
3846 require_once DOL_DOCUMENT_ROOT.
'/blockedlog/class/blockedlog.class.php';
3848 print
'<tr><td colspan="4">';
3851 print
'<b>'.$langs->trans(
'MigrationResetBlockedLog').
"</b><br>\n";
3859 $sqlSelect =
"SELECT DISTINCT entity";
3860 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog";
3864 $resql = $db->query($sqlSelect);
3867 $num = $db->num_rows($resql);
3871 $obj = $db->fetch_object($resql);
3873 print
'Process entity '.$obj->entity;
3875 $sqlSearch =
"SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX.
"blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3876 $resqlSearch = $db->query($sqlSearch);
3878 $objSearch = $db->fetch_object($resqlSearch);
3880 if ($objSearch && $objSearch->nb == 0) {
3881 print
' - Record for entity must be reset...';
3883 $sqlUpdate =
"DELETE FROM ".MAIN_DB_PREFIX.
"blockedlog";
3884 $sqlUpdate .=
" WHERE entity = ".((int) $obj->entity);
3885 $resqlUpdate = $db->query($sqlUpdate);
3886 if (!$resqlUpdate) {
3888 dol_print_error($db);
3895 $object->entity = $obj->entity;
3899 $b->setObjectData(
$object,
'MODULE_SET', 0, $user, 0);
3901 $res = $b->create($user);
3907 print
' - '.$langs->trans(
'AlreadyDone').
'<br>';
3910 dol_print_error($db);
3916 print $langs->trans(
'NothingToDo').
"<br>\n";
3925 dol_print_error($db);
3943 print
'<tr><td colspan="4">';
3946 print
'<b>'.$langs->trans(
'MigrationRemiseEntity').
"</b><br>\n";
3954 $sqlSelect =
"SELECT sr.rowid, s.entity";
3955 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise as sr, ".MAIN_DB_PREFIX.
"societe as s";
3956 $sqlSelect .=
" WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3960 $resql = $db->query($sqlSelect);
3963 $num = $db->num_rows($resql);
3967 $obj = $db->fetch_object($resql);
3969 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise SET";
3970 $sqlUpdate .=
" entity = ".((int) $obj->entity);
3971 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
3973 $result = $db->query($sqlUpdate);
3976 dol_print_error($db);
3983 print $langs->trans(
'AlreadyDone').
"<br>\n";
3992 dol_print_error($db);
4009 print
'<tr><td colspan="4">';
4012 print
'<b>'.$langs->trans(
'MigrationRemiseExceptEntity').
"</b><br>\n";
4020 $sqlSelect =
"SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
4021 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as sr";
4024 $resql = $db->query($sqlSelect);
4027 $num = $db->num_rows($resql);
4031 $obj = $db->fetch_object($resql);
4033 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
4034 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
4036 $sqlSelect2 =
"SELECT f.entity";
4037 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
4038 $sqlSelect2 .=
" WHERE f.rowid = ".((int) $fk_facture);
4039 } elseif (!empty($obj->fk_facture_line)) {
4040 $sqlSelect2 =
"SELECT f.entity";
4041 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f, ".MAIN_DB_PREFIX.
"facturedet as fd";
4042 $sqlSelect2 .=
" WHERE fd.rowid = ".((int) $obj->fk_facture_line);
4043 $sqlSelect2 .=
" AND fd.fk_facture = f.rowid";
4045 $sqlSelect2 =
"SELECT s.entity";
4046 $sqlSelect2 .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
4047 $sqlSelect2 .=
" WHERE s.rowid = ".((int) $obj->fk_soc);
4050 $resql2 = $db->query($sqlSelect2);
4052 if ($db->num_rows($resql2) > 0) {
4053 $obj2 = $db->fetch_object($resql2);
4055 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"societe_remise_except SET";
4056 $sqlUpdate .=
" entity = ".((int) $obj2->entity);
4057 $sqlUpdate .=
" WHERE rowid = ".((int) $obj->rowid);
4059 $result = $db->query($sqlUpdate);
4062 dol_print_error($db);
4067 dol_print_error($db);
4074 print $langs->trans(
'AlreadyDone').
"<br>\n";
4083 dol_print_error($db);
4114 array(
'to' => array(
'produit',
'product_advance',
'read_supplier_prices'),
'from' => array(array(
'produit',
'lire',
''), array(
'produit',
'creer',
''))),
4115 array(
'to' => array(
'produit',
'product_advance',
'write_supplier_prices'),
'from' => array(array(
'produit',
'creer',
''))),
4116 array(
'to' => array(
'service',
'service_advance',
'read_supplier_prices'),
'from' => array(array(
'service',
'lire',
''))),
4122 foreach ($rules as $rule) {
4125 if ($targetid <= 0) {
4130 $sourceids = array();
4131 foreach ($rule[
'from'] as $from) {
4137 if (empty($sourceids)) {
4140 $sourcelist = implode(
',', $sourceids);
4143 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"usergroup_rights (entity, fk_usergroup, fk_id)";
4144 $sql .=
" SELECT DISTINCT gr.entity, gr.fk_usergroup, ".((int) $targetid);
4145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as gr";
4146 $sql .=
" WHERE gr.fk_id IN (".$db->sanitize($sourcelist).
")";
4147 $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).
")";
4148 if (!$db->query($sql)) {
4154 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_rights (entity, fk_user, fk_id)";
4155 $sql .=
" SELECT DISTINCT ur.entity, ur.fk_user, ".((int) $targetid);
4156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur";
4157 $sql .=
" WHERE ur.fk_id IN (".$db->sanitize($sourcelist).
")";
4158 $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).
")";
4159 if (!$db->query($sql)) {
4184 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"rights_def";
4185 $sql .=
" WHERE module = '".$db->escape(
$module).
"'";
4186 $sql .=
" AND perms = '".$db->escape($perms).
"'";
4187 if ($subperms ===
'') {
4188 $sql .=
" AND (subperms IS NULL OR subperms = '')";
4190 $sql .=
" AND subperms = '".$db->escape($subperms).
"'";
4192 $resql = $db->query($sql);
4196 $obj = $db->fetch_object($resql);
4197 return $obj ? (int) $obj->id : 0;
4210 print
'<tr><td colspan="4">';
4212 print
'<b>'.$langs->trans(
'MigrationUserRightsEntity').
"</b><br>\n";
4220 $sqlSelect =
"SELECT u.rowid, u.entity";
4221 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
4222 $sqlSelect .=
" WHERE u.entity > 1";
4225 $resql = $db->query($sqlSelect);
4228 $num = $db->num_rows($resql);
4232 $obj = $db->fetch_object($resql);
4234 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"user_rights SET";
4235 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4236 $sqlUpdate .=
" WHERE fk_user = ".((int) $obj->rowid);
4238 $result = $db->query($sqlUpdate);
4241 dol_print_error($db);
4248 print $langs->trans(
'AlreadyDone').
"<br>\n";
4257 dol_print_error($db);
4275 print
'<tr><td colspan="4">';
4277 print
'<b>'.$langs->trans(
'MigrationUserGroupRightsEntity').
"</b><br>\n";
4285 $sqlSelect =
"SELECT u.rowid, u.entity";
4286 $sqlSelect .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as u";
4287 $sqlSelect .=
" WHERE u.entity > 1";
4290 $resql = $db->query($sqlSelect);
4293 $num = $db->num_rows($resql);
4297 $obj = $db->fetch_object($resql);
4299 $sqlUpdate =
"UPDATE ".MAIN_DB_PREFIX.
"usergroup_rights SET";
4300 $sqlUpdate .=
" entity = ".((int) $obj->entity);
4301 $sqlUpdate .=
" WHERE fk_usergroup = ".((int) $obj->rowid);
4303 $result = $db->query($sqlUpdate);
4306 dol_print_error($db);
4313 print $langs->trans(
'AlreadyDone').
"<br>\n";
4322 dol_print_error($db);
4344 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4345 dolibarr_install_syslog(
"upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.
' into '.DOL_DATA_ROOT.$newname);
4346 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4349 dolCopyDir(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname,
'0', 1);
4369 $filetodeletearray = array(
4370 '/core/ajax/ajaxcompanies.php',
4371 '/core/triggers/interface_demo.class.php',
4372 '/core/menus/barre_left/default.php',
4373 '/core/menus/barre_top/default.php',
4374 '/core/modules/modComptabiliteExpert.class.php',
4375 '/core/modules/modCommercial.class.php',
4376 '/core/modules/modPaybox.class.php',
4377 '/core/modules/modProduit.class.php',
4378 '/core/modules/modSkype.class.php',
4379 '/core/modules/modactivite.class.php',
4380 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4381 '/core/triggers/interface_modCommande_Ecotax.class.php',
4382 '/core/triggers/interface_modCommande_fraisport.class.php',
4383 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4384 '/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php',
4385 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4386 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4387 '/core/menus/smartphone/iphone.lib.php',
4388 '/core/menus/smartphone/iphone_backoffice.php',
4389 '/core/menus/smartphone/iphone_frontoffice.php',
4390 '/core/menus/standard/auguria_backoffice.php',
4391 '/core/menus/standard/auguria_frontoffice.php',
4392 '/core/menus/standard/eldy_backoffice.php',
4393 '/core/menus/standard/eldy_frontoffice.php',
4394 '/core/modules/export/export_excel.modules.php',
4395 '/core/modules/export/export_csv.modules.php',
4396 '/core/modules/export/exportcsv.modules.php',
4397 '/core/modules/export/export_excel2007new.modules.php',
4398 '/core/modules/facture/pdf_crabe.modules.php',
4399 '/core/modules/commande/doc/pdf_einstein.modules.php',
4400 '/core/modules/expedition/doc/pdf_rouget.modules.php',
4401 '/core/modules/propale/doc/pdf_azur.modules.php',
4402 '/core/modules/supplier_order/doc/pdf_muscadet.modules.php',
4403 '/core/modules/supplier_proposal/doc/pdf_aurore.modules.php',
4404 '/core/modules/facture/pdf_oursin.modules.php',
4405 '/core/modules/cheque/doc/pdf_blochet.class.php',
4406 '/core/modules/mailings/contacts2.modules.php',
4407 '/core/modules/mailings/contacts3.modules.php',
4408 '/core/modules/mailings/contacts4.modules.php',
4409 '/core/modules/mailings/framboise.modules.php',
4410 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4411 '/core/modules/mailings/peche.modules.php',
4412 '/core/modules/mailings/poire.modules.php',
4413 '/core/modules/mailings/kiwi.modules.php',
4414 '/core/modules/syslog/mod_syslog_chromephp.php',
4415 '/core/modules/syslog/mod_syslog_firephp.php',
4416 '/core/modules/syslog/logHandlerInterface.php',
4417 '/core/boxes/box_members.php',
4419 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4420 '/includes/nusoap/lib/class.*',
4421 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4422 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4424 '/api/class/api_generic.class.php',
4425 '/asterisk/cidlookup.php',
4426 '/categories/class/api_category.class.php',
4427 '/categories/class/api_deprecated_category.class.php',
4428 '/compta/facture/class/api_invoice.class.php',
4429 '/commande/class/api_commande.class.php',
4430 '/partnership/class/api_partnership.class.php',
4431 '/product/class/api_product.class.php',
4432 '/recruitment/class/api_recruitment.class.php',
4433 '/societe/class/api_contact.class.php',
4434 '/societe/class/api_thirdparty.class.php',
4435 '/support/online.php',
4436 '/takepos/class/actions_takepos.class.php',
4437 '/user/class/api_user.class.php',
4439 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4440 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4441 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4442 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4443 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4444 '/install/mysql/tables/llx_c_ticketsup_type.sql',
4446 '/install/mysql/tables/llx_categorie_mo-mrp_mo.sql',
4447 '/install/mysql/tables/llx_categorie_mo-mrp_mo.key.sql'
4456 foreach ($filetodeletearray as $filetodelete) {
4458 if (preg_match(
'/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4460 $result =
dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match(
'/\*/', $filetodelete) ? 1 : 0), 0,
null,
true, 0);
4462 $langs->load(
"errors");
4463 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4464 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4489 $filetodeletearray = array(
4490 DOL_DOCUMENT_ROOT.
'/core/modules/facture/terre',
4491 DOL_DOCUMENT_ROOT.
'/core/modules/facture/mercure',
4495 if (!empty($_SERVER[
"WINDIR"])) {
4496 $filetodeletearray[] = DOL_DOCUMENT_ROOT.
'/includes/phpoffice/PhpSpreadsheet';
4499 foreach ($filetodeletearray as $filetodelete) {
4501 if (file_exists($filetodelete)) {
4505 $langs->load(
"errors");
4506 print
'<div class="error">'.$langs->trans(
"Error").
': '.$langs->trans(
"ErrorFailToDeleteDir", $filetodelete);
4507 print
' '.$langs->trans(
"RemoveItManuallyAndPressF5ToContinue").
'</div>';
4531 if (count($listofmodule) == 0) {
4535 if (!is_object($user)) {
4536 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4537 $user =
new User($db);
4540 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules force=".$force.
", listofmodule=".implode(
',', array_keys($listofmodule)), LOG_NOTICE);
4542 $reloadactionformodules = array(
4543 'MAIN_MODULE_AGENDA' => array(
'class' =>
'modAgenda',
'remove' => 1),
4544 'MAIN_MODULE_API' => array(
'class' =>
'modApi'),
4545 'MAIN_MODULE_BARCODE' => array(
'class' =>
'modBarcode',
'remove' => 1),
4546 'MAIN_MODULE_BLOCKEDLOG' => array(
'class' =>
'modBlockedLog',
'deleteinsertmenus' => 1),
4547 'MAIN_MODULE_CRON' => array(
'class' =>
'modCron',
'remove' => 1),
4548 'MAIN_MODULE_SOCIETE' => array(
'class' =>
'modSociete',
'remove' => 1),
4549 'MAIN_MODULE_PRODUIT' => array(
'class' =>
'modProduct'),
4550 'MAIN_MODULE_SERVICE' => array(
'class' =>
'modService'),
4551 'MAIN_MODULE_COMMANDE' => array(
'class' =>
'modCommande'),
4552 'MAIN_MODULE_DON' => array(
'class' =>
'modDon'),
4553 'MAIN_MODULE_FACTURE' => array(
'class' =>
'modFacture'),
4554 'MAIN_MODULE_FICHEINTER' => array(
'class' =>
'modFicheinter'),
4555 'MAIN_MODULE_FOURNISSEUR' => array(
'class' =>
'modFournisseur'),
4556 'MAIN_MODULE_EXPEDITION' => array(
'class' =>
'modExpedition'),
4557 'MAIN_MODULE_EXPENSEREPORT' => array(
'class' =>
'modExpenseReport'),
4558 'MAIN_MODULE_EVENTORGANIZATION' => array(
'class' =>
'modEventOrganization',
'remove' => 1),
4559 'MAIN_MODULE_ECM' => array(
'class' =>
'modECM',
'remove' => 1),
4560 'MAIN_MODULE_HOLIDAY' => array(
'class' =>
'modHoliday',
'remove' => 1),
4561 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array(
'class' =>
'modKnowledgeManagement',
'remove' => 1),
4562 'MAIN_MODULE_LOAN' => array(
'class' =>
'modLoan',
'remove' => 1),
4563 'MAIN_MODULE_PROPAL' => array(
'class' =>
'modPropale'),
4564 'MAIN_MODULE_SUPPLIERPROPOSAL' => array(
'class' =>
'modSupplierProposal',
'remove' => 1),
4565 'MAIN_MODULE_OPENSURVEY' => array(
'class' =>
'modOpenSurvey',
'remove' => 1),
4566 'MAIN_MODULE_PRODUCTBATCH' => array(
'class' =>
'modProductBatch',
'remove' => 1),
4567 'MAIN_MODULE_TAKEPOS' => array(
'class' =>
'modTakePos',
'remove' => 1),
4568 'MAIN_MODULE_VARIANTS' => array(
'class' =>
'modVariants',
'remove' => 1),
4569 'MAIN_MODULE_EMAILCOLLECTOR' => array(
'class' =>
'modEmailCollector',
'remove' => 1),
4572 foreach ($listofmodule as $moduletoreload => $reloadmode) {
4573 $modulekey = preg_replace(
'/^MAIN_MODULE_/',
'', $moduletoreload);
4575 if (empty($moduletoreload) || (!
isModEnabled(strtolower($modulekey)) && !$force)) {
4581 if (!empty($reloadactionformodules[$moduletoreload])) {
4582 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload.
" with mode ".$reloadmode);
4584 $val = $reloadactionformodules[$moduletoreload];
4585 $classformodule = $val[
'class'];
4586 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/'.$classformodule.
'.class.php';
4588 $mod =
new $classformodule($db);
4589 if (!empty($val[
'remove'])) {
4590 $mod->remove(
'noboxes');
4592 if (!empty($val[
'deleteinsertmenus'])) {
4594 $mod->delete_menus();
4595 $mod->insert_menus();
4597 $mod->init($reloadmode);
4602 preg_match(
'/([a-zA-Z0-9]+)/', $modulekey, $reg);
4603 if (!empty($reg[1])) {
4604 if (strtoupper($moduletoreload) == $moduletoreload) {
4605 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4607 $moduletoreloadshort = $reg[1];
4610 dolibarr_install_syslog(
"upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort.
" with mode ".$reloadmode.
" (generic code)", LOG_NOTICE);
4612 $res = @include_once DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php';
4614 $classname =
'mod'.$moduletoreloadshort;
4615 $mod =
new $classname($db);
4616 '@phan-var-force DolibarrModules $mod';
4619 $mod->delete_menus();
4620 $mod->init($reloadmode);
4622 dolibarr_install_syslog(
'Failed to include '.DOL_DOCUMENT_ROOT.
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4624 $res = @
dol_include_once(strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php');
4626 $classname =
'mod'.$moduletoreloadshort;
4627 $mod =
new $classname($db);
4628 '@phan-var-force DolibarrModules $mod';
4629 $mod->init($reloadmode);
4631 dolibarr_install_syslog(
'Failed to include '.strtolower($moduletoreloadshort).
'/core/modules/mod'.$moduletoreloadshort.
'.class.php', LOG_ERR);
4632 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4638 print
"Error, can't find module with name ".$moduletoreload.
"\n";
4643 if (!empty($mod) && is_object($mod)) {
4644 print
'<tr class="trforrunsql"><td colspan="4">';
4645 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: ';
4646 print $langs->trans(
'MigrationReloadModule').
' '.$mod->getName();
4647 print
"<!-- (".$reloadmode.
") -->";
4672 $listofmenuhandler = array();
4674 $listofmenuhandler[
'auguria'] = 1;
4677 foreach ($listofmenuhandler as $key => $val) {
4678 print
'<tr class="trforrunsql"><td colspan="4">';
4682 print
'<b>'.$langs->trans(
'Upgrade').
'</b>: '.$langs->trans(
'MenuHandler').
" ".$key.
"<br>\n";
4685 $dir = DOL_DOCUMENT_ROOT.
"/core/menus/";
4686 $file =
'init_menu_'.$key.
'.sql';
4687 if (file_exists($dir.$file)) {
4688 $result =
run_sql($dir.$file, 1, 0, 1, $key);
4704 global
$conf, $db, $langs, $user;
4706 if (!is_object($user)) {
4707 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4708 $user =
new User($db);
4711 print
'<tr><td colspan="4">';
4713 print
'<b>'.$langs->trans(
'MigrationProductLotPath').
"</b><br>\n";
4715 $sql =
"SELECT rowid, entity, batch, fk_product from ".MAIN_DB_PREFIX.
"product_lot";
4716 $resql = $db->query($sql);
4719 $modulepart =
"product_batch";
4723 while ($obj = $db->fetch_object($resql)) {
4724 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4726 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/'.
$conf->productbatch->multidir_output[$entity];
4728 $dir =
$conf->productbatch->multidir_output[$entity];
4732 $lot->id = (int) $obj->rowid;
4733 $lot->ref = (string) $obj->rowid;
4734 $lot->batch = $obj->batch;
4735 $lot->entity = $obj->entity;
4736 $lot->fk_product = $obj->fk_product;
4738 $savref = $lot->ref;
4740 $lot->ref = $obj->batch;
4741 $origin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4743 $lot->ref = $savref;
4744 $destin = $dir .
'/' .
get_exdir(0, 0, 0, 1, $lot, $modulepart);
4766 global
$conf, $db, $langs, $user;
4768 print
'<tr><td colspan="4">';
4770 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4772 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4773 $fuser =
new User($db);
4774 if (!is_object($user)) {
4778 $sql =
"SELECT rowid as uid, entity from ".MAIN_DB_PREFIX.
"user";
4779 $resql = $db->query($sql);
4781 while ($obj = $db->fetch_object($resql)) {
4783 $fuser->id = $obj->uid;
4784 $fuser->entity = $obj->entity;
4787 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4789 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4791 $dir =
$conf->user->multidir_output[$entity];
4796 $origin = $dir.
'/'.
get_exdir($fuser->id, 2, 0, 1, $fuser,
'user');
4797 $destin = $dir.
'/'.$fuser->id;
4805 $handle = opendir($origin_osencoded);
4806 if (is_resource($handle)) {
4807 while (($file = readdir($handle)) !==
false) {
4808 if ($file ==
'.' || $file ==
'..') {
4813 $thumbs = opendir($origin_osencoded.
'/'.$file);
4814 if (is_resource($thumbs)) {
4816 while (($thumb = readdir($thumbs)) !==
false) {
4818 if ($thumb ==
'.' || $thumb ==
'..') {
4824 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4834 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4855 global $db, $langs, $user;
4857 print
'<tr><td colspan="4">';
4859 print
'<b>'.$langs->trans(
'MigrationUserPhotoPath').
"</b><br>\n";
4861 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4862 $fuser =
new User($db);
4863 if (!is_object($user)) {
4867 $sql =
"SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX.
"user";
4868 $resql = $db->query($sql);
4870 while ($obj = $db->fetch_object($resql)) {
4872 $fuser->id = $obj->uid;
4873 $fuser->entity = $obj->entity;
4874 $fuser->photo = $obj->photo;
4877 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4879 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/users';
4881 $dir = DOL_DATA_ROOT.
'/users';
4886 $origin = $dir.
'/'.$fuser->id;
4887 $destin = $dir.
'/'.$fuser->id.
'/photos';
4895 $handle = opendir($origin_osencoded);
4896 if (is_resource($handle)) {
4897 while (($file = readdir($handle)) !==
false) {
4898 if ($file ==
'.' || $file ==
'..' || $file ==
'photos') {
4901 if (!empty($fuser->photo) && ($file != $fuser->photo && $file !=
'thumbs')) {
4906 $thumbs = opendir($origin_osencoded.
'/'.$file);
4907 if (is_resource($thumbs)) {
4909 while (($thumb = readdir($thumbs)) !==
false) {
4911 if ($thumb ==
'.' || $thumb ==
'..') {
4917 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
4926 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
4948 global
$conf, $db, $langs;
4950 print
'<tr class="trforrunsql"><td>';
4952 print
'<b>'.$langs->trans(
'MigrationHolidayPath').
"</b><br>\n";
4954 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
4957 $sql =
"SELECT rowid as uid, ref, entity from ".MAIN_DB_PREFIX.
"holiday";
4959 $resql = $db->query($sql);
4961 while ($obj = $db->fetch_object($resql)) {
4963 $holiday->id = $obj->uid;
4964 $holiday->ref = $obj->ref;
4965 $holiday->entity = $obj->entity;
4968 $entity = (empty($holiday->entity) ? 1 : $holiday->entity);
4970 $dir = DOL_DATA_ROOT.
'/'.$entity.
'/holiday';
4972 $dir =
$conf->holiday->multidir_output[$entity];
4977 $origin = $dir.
'/'.
get_exdir($holiday->id, 2, 0, 1, $holiday,
'holiday');
4978 $destin = $dir.
'/'.$holiday->ref;
4986 $handle = opendir($origin_osencoded);
4987 if (is_resource($handle)) {
4988 while (($file = readdir($handle)) !==
false) {
4989 if ($file ==
'.' || $file ==
'..') {
4994 $thumbs = opendir($origin_osencoded.
'/'.$file);
4995 if (is_resource($thumbs)) {
4997 while (($thumb = readdir($thumbs)) !==
false) {
4999 if ($thumb ==
'.' || $thumb ==
'..') {
5005 dol_copy($origin.
'/'.$file.
'/'.$thumb, $destin.
'/'.$file.
'/'.$thumb,
'0', 0);
5015 dol_copy($origin.
'/'.$file, $destin.
'/'.$file,
'0', 0);
5052 print
'<tr><td colspan="4">';
5053 $sql =
'SELECT rowid, socialnetworks';
5054 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'user WHERE';
5055 $sql .=
" skype IS NOT NULL OR skype <> ''";
5056 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5057 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5058 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5059 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5060 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5061 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5062 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5063 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5065 $resql = $db->query($sql);
5067 while ($obj = $db->fetch_object($resql)) {
5068 $arraysocialnetworks = array();
5069 if (!empty($obj->skype)) {
5070 $arraysocialnetworks[
'skype'] = $obj->skype;
5072 if (!empty($obj->twitter)) {
5073 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5075 if (!empty($obj->facebook)) {
5076 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5078 if (!empty($obj->linkedin)) {
5079 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5081 if (!empty($obj->instagram)) {
5082 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5084 if (!empty($obj->snapchat)) {
5085 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5087 if (!empty($obj->googleplus)) {
5088 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5090 if (!empty($obj->youtube)) {
5091 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5093 if (!empty($obj->whatsapp)) {
5094 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5096 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5097 $obj->socialnetworks =
'[]';
5099 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5100 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"user SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5101 $sqlupd .=
', skype=null';
5102 $sqlupd .=
', twitter=null';
5103 $sqlupd .=
', facebook=null';
5104 $sqlupd .=
', linkedin=null';
5105 $sqlupd .=
', instagram=null';
5106 $sqlupd .=
', snapchat=null';
5107 $sqlupd .=
', googleplus=null';
5108 $sqlupd .=
', youtube=null';
5109 $sqlupd .=
', whatsapp=null';
5110 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5112 $resqlupd = $db->query($sqlupd);
5114 dol_print_error($db);
5124 dol_print_error($db);
5127 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Users').
"</b><br>\n";
5141 print
'<tr><td colspan="4">';
5144 print
'<tr><td colspan="4">';
5145 $sql =
'SELECT rowid, socialnetworks';
5146 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'adherent WHERE ';
5147 $sql .=
" skype IS NOT NULL OR skype <> ''";
5148 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5149 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5150 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5151 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5152 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5153 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5154 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5155 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5157 $resql = $db->query($sql);
5159 while ($obj = $db->fetch_object($resql)) {
5160 $arraysocialnetworks = array();
5161 if (!empty($obj->skype)) {
5162 $arraysocialnetworks[
'skype'] = $obj->skype;
5164 if (!empty($obj->twitter)) {
5165 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5167 if (!empty($obj->facebook)) {
5168 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5170 if (!empty($obj->linkedin)) {
5171 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5173 if (!empty($obj->instagram)) {
5174 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5176 if (!empty($obj->snapchat)) {
5177 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5179 if (!empty($obj->googleplus)) {
5180 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5182 if (!empty($obj->youtube)) {
5183 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5185 if (!empty($obj->whatsapp)) {
5186 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5188 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5189 $obj->socialnetworks =
'[]';
5191 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5192 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5193 $sqlupd .=
', skype=null';
5194 $sqlupd .=
', twitter=null';
5195 $sqlupd .=
', facebook=null';
5196 $sqlupd .=
', linkedin=null';
5197 $sqlupd .=
', instagram=null';
5198 $sqlupd .=
', snapchat=null';
5199 $sqlupd .=
', googleplus=null';
5200 $sqlupd .=
', youtube=null';
5201 $sqlupd .=
', whatsapp=null';
5202 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5204 $resqlupd = $db->query($sqlupd);
5206 dol_print_error($db);
5216 dol_print_error($db);
5219 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Members').
"</b><br>\n";
5235 print
'<tr><td colspan="4">';
5236 $sql =
'SELECT rowid, socialnetworks';
5237 $sql .=
', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'socpeople WHERE';
5238 $sql .=
" jabberid IS NOT NULL OR jabberid <> ''";
5239 $sql .=
" OR skype IS NOT NULL OR skype <> ''";
5240 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5241 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5242 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5243 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5244 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5245 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5246 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5247 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5249 $resql = $db->query($sql);
5251 while ($obj = $db->fetch_object($resql)) {
5252 $arraysocialnetworks = array();
5253 if (!empty($obj->jabberid)) {
5254 $arraysocialnetworks[
'jabber'] = $obj->jabberid;
5256 if (!empty($obj->skype)) {
5257 $arraysocialnetworks[
'skype'] = $obj->skype;
5259 if (!empty($obj->twitter)) {
5260 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5262 if (!empty($obj->facebook)) {
5263 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5265 if (!empty($obj->linkedin)) {
5266 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5268 if (!empty($obj->instagram)) {
5269 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5271 if (!empty($obj->snapchat)) {
5272 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5274 if (!empty($obj->googleplus)) {
5275 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5277 if (!empty($obj->youtube)) {
5278 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5280 if (!empty($obj->whatsapp)) {
5281 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5283 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5284 $obj->socialnetworks =
'[]';
5286 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5287 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5288 $sqlupd .=
', jabberid=null';
5289 $sqlupd .=
', skype=null';
5290 $sqlupd .=
', twitter=null';
5291 $sqlupd .=
', facebook=null';
5292 $sqlupd .=
', linkedin=null';
5293 $sqlupd .=
', instagram=null';
5294 $sqlupd .=
', snapchat=null';
5295 $sqlupd .=
', googleplus=null';
5296 $sqlupd .=
', youtube=null';
5297 $sqlupd .=
', whatsapp=null';
5298 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5300 $resqlupd = $db->query($sqlupd);
5302 dol_print_error($db);
5312 dol_print_error($db);
5315 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Contacts').
"</b><br>\n";
5331 print
'<tr><td colspan="4">';
5332 $sql =
'SELECT rowid, socialnetworks';
5333 $sql .=
', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.
'societe WHERE ';
5334 $sql .=
" skype IS NOT NULL OR skype <> ''";
5335 $sql .=
" OR twitter IS NOT NULL OR twitter <> ''";
5336 $sql .=
" OR facebook IS NOT NULL OR facebook <> ''";
5337 $sql .=
" OR linkedin IS NOT NULL OR linkedin <> ''";
5338 $sql .=
" OR instagram IS NOT NULL OR instagram <> ''";
5339 $sql .=
" OR snapchat IS NOT NULL OR snapchat <> ''";
5340 $sql .=
" OR googleplus IS NOT NULL OR googleplus <> ''";
5341 $sql .=
" OR youtube IS NOT NULL OR youtube <> ''";
5342 $sql .=
" OR whatsapp IS NOT NULL OR whatsapp <> ''";
5344 $resql = $db->query($sql);
5346 while ($obj = $db->fetch_object($resql)) {
5347 $arraysocialnetworks = array();
5348 if (!empty($obj->skype)) {
5349 $arraysocialnetworks[
'skype'] = $obj->skype;
5351 if (!empty($obj->twitter)) {
5352 $arraysocialnetworks[
'twitter'] = $obj->twitter;
5354 if (!empty($obj->facebook)) {
5355 $arraysocialnetworks[
'facebook'] = $obj->facebook;
5357 if (!empty($obj->linkedin)) {
5358 $arraysocialnetworks[
'linkedin'] = $obj->linkedin;
5360 if (!empty($obj->instagram)) {
5361 $arraysocialnetworks[
'instagram'] = $obj->instagram;
5363 if (!empty($obj->snapchat)) {
5364 $arraysocialnetworks[
'snapchat'] = $obj->snapchat;
5366 if (!empty($obj->googleplus)) {
5367 $arraysocialnetworks[
'googleplus'] = $obj->googleplus;
5369 if (!empty($obj->youtube)) {
5370 $arraysocialnetworks[
'youtube'] = $obj->youtube;
5372 if (!empty($obj->whatsapp)) {
5373 $arraysocialnetworks[
'whatsapp'] = $obj->whatsapp;
5375 if ($obj->socialnetworks ==
'' || is_null($obj->socialnetworks)) {
5376 $obj->socialnetworks =
'[]';
5378 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks,
true));
5379 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.
"societe SET socialnetworks='".$db->escape(json_encode($socialnetworks)).
"'";
5380 $sqlupd .=
', skype=null';
5381 $sqlupd .=
', twitter=null';
5382 $sqlupd .=
', facebook=null';
5383 $sqlupd .=
', linkedin=null';
5384 $sqlupd .=
', instagram=null';
5385 $sqlupd .=
', snapchat=null';
5386 $sqlupd .=
', googleplus=null';
5387 $sqlupd .=
', youtube=null';
5388 $sqlupd .=
', whatsapp=null';
5389 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5391 $resqlupd = $db->query($sqlupd);
5393 dol_print_error($db);
5403 dol_print_error($db);
5406 print
'<b>'.$langs->trans(
'MigrationFieldsSocialNetworks',
'Thirdparties').
"</b><br>\n";
5426 print
'<tr class="trforrunsql"><td colspan="4">';
5427 $sql =
'SELECT rowid, field';
5428 if ($mode ==
'export') {
5431 $sql .=
' FROM '.MAIN_DB_PREFIX.$mode.
'_model WHERE';
5432 $sql .=
" type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5434 $resql = $db->query($sql);
5436 while ($obj = $db->fetch_object($resql)) {
5437 $oldfield = $obj->field;
5438 $newfield = str_replace(array(
',f.facnumber',
'f.facnumber,',
'f.total,',
'f.tva,'), array(
',f.ref',
'f.ref,',
'f.total_ht,',
'f.total_tva,'), $oldfield);
5440 if ($mode ==
'export') {
5441 $oldfilter = $obj->filter;
5442 $newfilter = str_replace(array(
'f.facnumber=',
'f.total=',
'f.tva='), array(
'f.ref=',
'f.total_ht=',
'f.total_tva='), $oldfilter);
5448 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5449 $sqlupd =
'UPDATE '.MAIN_DB_PREFIX.$mode.
"_model SET field = '".$db->escape($newfield).
"'";
5450 if ($mode ==
'export') {
5451 $sqlupd .=
", filter = '".$db->escape($newfilter).
"'";
5453 $sqlupd .=
' WHERE rowid = '.((int) $obj->rowid);
5454 $resultstring .=
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd.
"</td></tr>\n";
5455 $resqlupd = $db->query($sqlupd);
5457 dol_print_error($db);
5468 dol_print_error($db);
5471 print
'<b>'.$langs->trans(
'MigrationImportOrExportProfiles', $mode).
"</b><br>\n";
5474 if ($resultstring) {
5475 print $resultstring;
5477 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5494 print
'<tr class="trforrunsql"><td colspan="4">';
5495 print
'<b>'.$langs->trans(
'MigrationContractLineRank').
"</b><br>\n";
5497 $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";
5498 $sql .=
" ORDER BY c.rowid,cd.rowid";
5500 $resql = $db->query($sql);
5503 $current_contract = 0;
5504 while ($obj = $db->fetch_object($resql)) {
5505 if (empty($current_contract) || $current_contract == $obj->cid) {
5511 $sqlUpd =
"UPDATE ".$db->prefix().
"contratdet SET rang=".(int) $currentRank.
" WHERE rowid=".(
int) $obj->cdid;
5512 $resultstring =
'.';
5513 print $resultstring;
5514 $resqlUpd = $db->query($sqlUpd);
5516 dol_print_error($db);
5520 $current_contract = $obj->cid;
5533 if (!$resultstring) {
5534 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5549 $firstInstallVersion =
getDolGlobalString(
'MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5550 $migrationNeeded = (
versioncompare(explode(
'.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5552 print
'<tr class="trforrunsql"><td colspan="4">';
5553 print
'<b>'.$langs->trans(
'InvoiceExportModelsMigration').
"</b>: \n";
5555 if (! $migrationNeeded) {
5556 print $langs->trans(
"AlreadyDone");
5558 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
5565 $sql1 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5567 $resql1 = $db->query($sql1);
5570 dol_print_error($db);
5576 $modified1 = $db->affected_rows($resql1);
5578 print str_repeat(
'.', $modified1);
5582 $sql2 =
"UPDATE ".$db->prefix().
"export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5584 $resql2 = $db->query($sql2);
5587 dol_print_error($db);
5593 $modified2 = $db->affected_rows($resql2);
5595 print str_repeat(
'.', $modified2);
5599 if (empty($modified1 + $modified2)) {
5600 print $langs->trans(
'NothingToDo');
5605 dolibarr_set_const($db,
'MIGRATION_FLAG_INVOICE_MODELS_V20', 1,
'chaine', 0,
'To flag the upgrade of invoice template has been set', 0);
5622 $bookKeepingAddon =
'';
5626 dolibarr_set_const($db,
'BOOKKEEPING_ADDON',
'mod_bookkeeping_neon',
'chaine', 0,
'', $entity);
5627 $bookKeepingAddon =
'mod_bookkeeping_neon';
5630 print
'<tr class="trforrunsql"><td colspan="4">';
5631 print
'<b>'.$langs->trans(
'MigrationAccountancyBookkeeping').
"</b><br>\n";
5634 if ($bookKeepingAddon ===
'mod_bookkeeping_argon') {
5637 $sql =
"SELECT DISTINCT YEAR(doc_date) as doc_year, MONTH(doc_date) as doc_month, code_journal, piece_num FROM ".$db->prefix().
"accounting_bookkeeping";
5638 $sql .=
" WHERE ref IS NULL AND entity = ".((int) $entity);
5639 $sql .=
" ORDER BY doc_year, doc_month, code_journal, piece_num";
5641 $resql = $db->query($sql);
5643 require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeeping.class.php';
5646 while ($obj = $db->fetch_object($resql)) {
5647 $bookkeeping->doc_date =
dol_mktime(0, 0, 0, $obj->doc_month, 1, $obj->doc_year);
5648 $bookkeeping->code_journal = $obj->code_journal;
5649 $ref = $bookkeeping->getNextNumRef();
5651 $sqlUpd =
"UPDATE ".$db->prefix().
"accounting_bookkeeping SET ref = '".$db->escape($ref).
"' WHERE piece_num = '".$db->escape($obj->piece_num).
"' AND entity = ".((int) $entity);
5652 $resultstring =
'.';
5653 print $resultstring;
5654 $resqlUpd = $db->query($sqlUpd);
5656 dol_print_error($db);
5673 if (!$resultstring) {
5674 print
'<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans(
"NothingToDo").
"</td></tr>\n";
5685 global
$conf, $db, $langs;
5687 print
'<tr class="trforrunsql"><td colspan="4">';
5688 print
'<b>'.$langs->trans(
'MigrationApiRestTokens').
"</b>:\n";
5692 $allexistingtokens = array();
5696 $sqlforalltokens =
"SELECT oat.tokenstring";
5697 $sqlforalltokens .=
" FROM ".$db->prefix().
"oauth_token AS oat";
5698 $sqlforalltokens .=
" WHERE oat.service = 'dolibarr_rest_api'";
5700 $resalltoken = $db->query($sqlforalltokens);
5703 while ($tokenobj = $db->fetch_object($resalltoken)) {
5704 $allexistingtokens[] =
dolDecrypt($tokenobj->tokenstring);
5708 dol_print_error($db);
5713 $sql =
"SELECT 'dolibarr_rest_api' AS service, u.api_key AS tokenstring, u.rowid AS fk_user, u.entity";
5714 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user AS u";
5715 $sql .=
" WHERE u.api_key IS NOT NULL AND u.api_key <> ''";
5717 $result = $db->query($sql);
5720 $tmpuser =
new User($db);
5722 while ($obj = $db->fetch_object($result)) {
5723 if (!in_array(
dolDecrypt($obj->tokenstring), $allexistingtokens)) {
5725 unset($tmpuser->conf);
5727 $tmpuser->fetch((
int) $obj->fk_user,
'',
'', 1, ($obj->entity ? $obj->entity :
$conf->entity));
5729 $sqlforinsert =
"INSERT INTO ".MAIN_DB_PREFIX.
"oauth_token (service, tokenstring, fk_user, datec, entity, apicount_total)";
5730 $sqlforinsert .=
" VALUES ('".$db->escape($obj->service).
"', '".$db->escape(
dolEncrypt(
dolDecrypt($obj->tokenstring),
'',
'',
'dolibarr')).
"', ";
5731 $sqlforinsert .= ((int) $obj->fk_user).
", '".$db->idate(
dol_now()).
"', ".((
int) $obj->entity).
", ";
5732 $sqlforinsert .=
getDolUserInt(
'API_COUNT_CALL', 0, $tmpuser);
5733 $sqlforinsert .=
")";
5735 $insertresult = $db->query($sqlforinsert);
5736 if (!$insertresult) {
5738 dol_print_error($db);
5751 dol_print_error($db);
5756 if (!$nbofmigration) {
5757 print $langs->trans(
"NothingToDo").
"\n";
5759 print $langs->trans(
'MigratedTokens', $nbofmigration);
5774 global
$conf, $db, $langs;
5776 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
5777 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5779 print
'<tr class="trforrunsql"><td colspan="4">';
5780 print
'<b>'.$langs->trans(
'InitAHMACKeyForBlockedLog').
"</b>:\n";
5786 if (empty($hmac_encoded_secret_key)) {
5788 $randomsecret = bin2hex(random_bytes(32));
5790 $hmac_secret_key =
'BLOCKEDLOGHMAC'.$randomsecret;
5792 $result =
dolibarr_set_const($db,
'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key,
'chaine', 0,
'The secret key for HMAC used for blockedlog record',
$conf->entity);
5795 dol_print_error($db);
5802 print $langs->trans(
'Done');
5803 } elseif (!preg_match(
'/^(dolcrypt|dolobfuscation)/', $hmac_encoded_secret_key)) {
5808 $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);
5810 dol_print_error($db);
5816 print $langs->trans(
'Done').
" (BLOCKEDLOG_HMAC_KEY was stored in clear, it has been encrypted)\n";
5819 $hmac_secret_key =
dolDecrypt($hmac_encoded_secret_key);
5821 if (! preg_match(
'/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
5822 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.';
5823 print
'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.';
5824 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.';
5831 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.