dolibarr 23.0.3
upgrade2.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
3 * Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 *
24 * Upgrade2 scripts can be ran from command line with syntax:
25 *
26 * cd htdocs/install
27 * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion]
28 * php upgrade2.php 3.4.0 3.5.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
29 *
30 * And for final step:
31 * php step5.php 3.4.0 3.5.0
32 *
33 * Return code is 0 if OK, >0 if error
34 *
35 * Note: To just enable a module from command line, use this syntax:
36 * php upgrade2.php 0.0.0 0.0.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
37 */
38
44define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
45include_once 'inc.php';
46
51if (!file_exists($conffile)) {
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").';
53}
54require_once $conffile;
70require_once $dolibarr_main_document_root.'/compta/facture/class/facture.class.php';
71require_once $dolibarr_main_document_root.'/comm/propal/class/propal.class.php';
72require_once $dolibarr_main_document_root.'/contrat/class/contrat.class.php';
73require_once $dolibarr_main_document_root.'/commande/class/commande.class.php';
74require_once $dolibarr_main_document_root.'/fourn/class/fournisseur.commande.class.php';
75require_once $dolibarr_main_document_root.'/core/lib/price.lib.php';
76require_once $dolibarr_main_document_root.'/core/class/menubase.class.php';
77require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
78require_once $dolibarr_main_document_root.'/core/lib/files.lib.php';
79require_once $dolibarr_main_document_root.'/user/class/user.class.php';
80
81global $langs;
82
83
84$error = 0;
85
86
87// This page can be long. We increase the allowed delay, but this does not work when we are in safe_mode.
88$err = error_reporting();
89error_reporting(0);
90if (getDolGlobalInt('MAIN_OVERRIDE_TIME_LIMIT')) {
91 @set_time_limit(getDolGlobalInt('MAIN_OVERRIDE_TIME_LIMIT'));
92} else {
93 @set_time_limit(600);
94}
95error_reporting($err);
96
97$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : 'auto';
98$langs->setDefaultLang($setuplang);
99$versionfrom = GETPOST("versionfrom", 'alpha', 3) ? GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
100$versionto = GETPOST("versionto", 'alpha', 3) ? GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
101$enablemodules = GETPOST("enablemodules", 'alpha', 3) ? GETPOST("enablemodules", 'alpha', 3) : (empty($argv[3]) ? '' : $argv[3]);
102
103$langs->loadLangs(array("admin", "install", "bills", "suppliers"));
104
105if ($dolibarr_main_db_type == 'mysqli') {
106 $choix = 1;
107}
108if ($dolibarr_main_db_type == 'pgsql') {
109 $choix = 2;
110}
111if ($dolibarr_main_db_type == 'mssql') {
112 $choix = 3;
113}
114
115
116dolibarr_install_syslog("--- upgrade2: entering upgrade2.php page ".$versionfrom." ".$versionto." ".$enablemodules);
117if (!is_object($conf)) {
118 dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
119}
120
121
122
123/*
124 * View
125 */
126
127if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto || preg_match('/version/', $versionto))) {
128 print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\n";
129 print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
130 // Test if batch mode
131 $sapi_type = php_sapi_name();
132 $script_file = basename(__FILE__);
133 if (substr($sapi_type, 0, 3) == 'cli') {
134 print 'Syntax from command line: '.$script_file." x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
135 print 'Example, upgrade from 19 to 20: '.$script_file." 19.0.0 20.0.0\n";
136 print 'Example, enable a module only: '.$script_file." 0.0.0 0.0.0 MAIN_MODULE_Adherent\n";
137 print "\n";
138 }
139 exit;
140}
141
142pHeader('', 'step5', GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'upgrade', 'versionfrom='.$versionfrom.'&versionto='.$versionto, '', 'main-inside main-inside-borderbottom');
143
144
145if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) {
146 print '<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> ';
147 print '<span class="inline-block valignmiddle">'.$langs->trans('DataMigration').'</span></h3>';
148
149 print '<table class="centpercent">';
150
151 // If password is encoded, we decode it
152 if ((!empty($dolibarr_main_db_pass) && preg_match('/(crypted|dolcrypt):/i', (string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
153 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
154 if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
155 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', (string) $dolibarr_main_db_pass);
156 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
157 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_pass);
158 } elseif (preg_match('/dolcrypt:/i', (string) $dolibarr_main_db_pass)) {
159 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
160 $dolibarr_main_db_pass = dolDecrypt((string) $dolibarr_main_db_pass);
161 } else {
162 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_encrypted_pass);
163 }
164 }
165
166 // $conf is already instantiated inside inc.php
167 $conf->db->type = $dolibarr_main_db_type;
168 $conf->db->host = $dolibarr_main_db_host;
169 $conf->db->port = $dolibarr_main_db_port;
170 $conf->db->name = $dolibarr_main_db_name;
171 $conf->db->user = $dolibarr_main_db_user;
172 $conf->db->pass = $dolibarr_main_db_pass;
173
174 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
175
176 if (!$db->connected) {
177 print '<tr><td colspan="4">'.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).'</td><td class="right">'.$langs->trans('Error').'</td></tr>';
178 dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR);
179 $error++;
180 }
181
182 if (!$error) {
183 if ($db->database_selected) {
184 dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name);
185 } else {
186 $error++;
187 }
188 }
189
190 if (empty($dolibarr_main_db_encryption)) {
191 $dolibarr_main_db_encryption = 0;
192 }
193 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
194 if (empty($dolibarr_main_db_cryptkey)) {
195 $dolibarr_main_db_cryptkey = '';
196 }
197 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
198
199 // Load global conf
200 $conf->setValues($db);
201
202
203 // Reforce log activation (samecode than into the inc.php)
204 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
205 $conf->modules['syslog'] = 'syslog';
206 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
207 if (!defined('SYSLOG_HANDLERS')) {
208 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
209 }
210 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
211 if (@is_writable('/tmp')) {
212 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
213 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
214 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
215 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
216 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
217 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
218 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
219 } elseif (@is_writable('../../')) {
220 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
221 }
222 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
223 }
224 if (defined('SYSLOG_FILE')) {
225 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
226 }
227 if (!defined('SYSLOG_FILE_NO_ERROR')) {
228 define('SYSLOG_FILE_NO_ERROR', 1);
229 }
230 // We init log handler for install
231 $handlers = array('mod_syslog_file');
232 foreach ($handlers as $handler) {
233 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
234 if (!file_exists($file)) {
235 throw new Exception('Missing log handler file '.$handler.'.php');
236 }
237
238 require_once $file;
239 $loghandlerinstance = new $handler();
240 if (!$loghandlerinstance instanceof LogHandler) {
241 throw new Exception('Log handler does not extend LogHandler');
242 }
243
244 if (empty($conf->loghandlers[$handler])) {
245 $conf->loghandlers[$handler] = $loghandlerinstance;
246 }
247 }
248
249
250 $listofentities = array(1);
251
252 // Create the global $hookmanager object
253 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
254 $hookmanager = new HookManager($db);
255 $hookmanager->initHooks(array('upgrade2'));
256
257 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto);
258 $object = new stdClass();
259 $action = "upgrade";
260 $reshook = $hookmanager->executeHooks('doUpgradeBefore', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
261 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
262 // Example: $hookmanager->resArray = array(2, 3, 10);
263 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
264 }
265
266
267 /***************************************************************************************
268 *
269 * Migration of data
270 *
271 ***************************************************************************************/
272
273 dol_syslog("Process upgrade2 (step common to all entities)");
274
275 // Force to execute this at begin to avoid the new core code into Dolibarr to be broken.
276 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN birth date';
277 $db->query($sql, 1);
278 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemployment date';
279 $db->query($sql, 1);
280 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemploymentend date';
281 $db->query($sql, 1);
282 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_range integer';
283 $db->query($sql, 1);
284 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_c_exp_tax_cat integer';
285 $db->query($sql, 1);
286 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN langs varchar(24)';
287 $db->query($sql, 1);
288 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fieldcomputed text';
289 $db->query($sql, 1);
290 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fielddefault varchar(255)';
291 $db->query($sql, 1);
292 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX."extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
293 $db->query($sql, 1);
294 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN help text';
295 $db->query($sql, 1);
296 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
297 $db->query($sql, 1);
298
299
300 $db->begin();
301
302 foreach ($listofentities as $entity) {
303 dol_syslog("Process upgrade2 (step a) for entity ".$entity);
304
305 // Set $conf context for entity
306 $conf->setEntityValues($db, $entity);
307
308 // Reset forced setup after the setValues
309 if (defined('SYSLOG_FILE')) {
310 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
311 }
312
313 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; // Add also log into conf->logbuffer.
314
315 $versiontoarray = array();
316 $versionranarray = array();
317
318 dol_syslog("Process upgrade2 (step b) for entity ".$entity);
319
320 if (!$error) {
321 if (count($listofentities) > 1) {
322 print '<tr><td colspan="4">*** '.$langs->trans("Entity").' '.$entity.'</td></tr>'."\n";
323 }
324
325 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
326 // Version to install is DOL_VERSION
327 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')));
328
329 // Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec
330 // dans la 1ere colonne, la description de l'action a faire
331 // dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
332
333 $versiontoarray = explode('.', $versionto);
334 $versionranarray = explode('.', DOL_VERSION);
335
336 $afterversionarray = explode('.', '2.0.0');
337 $beforeversionarray = explode('.', '2.7.9');
338 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
339 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
340
341 // Script pour V2 -> V2.1
342 migrate_paiements($db, $langs, $conf);
343
344 migrate_contracts_det($db, $langs, $conf);
345
346 migrate_contracts_date1($db, $langs, $conf);
347
348 migrate_contracts_date2($db, $langs, $conf);
349
350 migrate_contracts_date3($db, $langs, $conf);
351
352 migrate_contracts_open($db, $langs, $conf);
353
354 migrate_modeles($db, $langs, $conf);
355
356 migrate_price_propal($db, $langs, $conf);
357
358 migrate_price_commande($db, $langs, $conf);
359
360 migrate_price_commande_fournisseur($db, $langs, $conf);
361
362 migrate_price_contrat($db, $langs, $conf);
363
364 migrate_paiementfourn_facturefourn($db, $langs, $conf);
365
366
367 // Script pour V2.1 -> V2.2
368 migrate_paiements_orphelins_1($db, $langs, $conf);
369
370 migrate_paiements_orphelins_2($db, $langs, $conf);
371
372 migrate_links_transfert($db, $langs, $conf);
373
374
375 // Script pour V2.2 -> V2.4
376 migrate_commande_expedition($db, $langs, $conf);
377
378 migrate_commande_livraison($db, $langs, $conf);
379
380 migrate_detail_livraison($db, $langs, $conf);
381
382
383 // Script pour V2.5 -> V2.6
384 migrate_stocks($db, $langs, $conf);
385
386
387 // Script pour V2.6 -> V2.7
388 migrate_menus($db, $langs, $conf);
389
390 migrate_commande_deliveryaddress($db, $langs, $conf);
391
392 migrate_restore_missing_links($db, $langs, $conf);
393
394 migrate_rename_directories($db, $langs, $conf, '/compta', '/banque');
395
396 migrate_rename_directories($db, $langs, $conf, '/societe', '/mycompany');
397 }
398
399 // Script for 2.8
400 $afterversionarray = explode('.', '2.7.9');
401 $beforeversionarray = explode('.', '2.8.9');
402 //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
403 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
404 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
405
406 migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx
407
408 migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping');
409
410 migrate_relationship_tables($db, $langs, $conf, 'pr_exp', 'fk_propal', 'propal', 'fk_expedition', 'shipping');
411
412 migrate_relationship_tables($db, $langs, $conf, 'pr_liv', 'fk_propal', 'propal', 'fk_livraison', 'delivery');
413
414 migrate_relationship_tables($db, $langs, $conf, 'co_liv', 'fk_commande', 'commande', 'fk_livraison', 'delivery');
415
416 migrate_relationship_tables($db, $langs, $conf, 'co_pr', 'fk_propale', 'propal', 'fk_commande', 'commande');
417
418 migrate_relationship_tables($db, $langs, $conf, 'fa_pr', 'fk_propal', 'propal', 'fk_facture', 'facture');
419
420 migrate_relationship_tables($db, $langs, $conf, 'co_fa', 'fk_commande', 'commande', 'fk_facture', 'facture');
421
422 migrate_project_user_resp($db, $langs, $conf);
423
424 migrate_project_task_actors($db, $langs, $conf);
425 }
426
427 // Script for 2.9
428 $afterversionarray = explode('.', '2.8.9');
429 $beforeversionarray = explode('.', '2.9.9');
430 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
431 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
432
433 migrate_element_time($db, $langs, $conf);
434
435 migrate_customerorder_shipping($db, $langs, $conf);
436
437 migrate_shipping_delivery($db, $langs, $conf);
438
439 migrate_shipping_delivery2($db, $langs, $conf);
440 }
441
442 // Script for 3.0
443 $afterversionarray = explode('.', '2.9.9');
444 $beforeversionarray = explode('.', '3.0.9');
445 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
446 // No particular code
447 //}
448
449 // Script for 3.1
450 $afterversionarray = explode('.', '3.0.9');
451 $beforeversionarray = explode('.', '3.1.9');
452 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
453 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
454
455 migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss');
456
457 migrate_actioncomm_element($db, $langs, $conf);
458 }
459
460 // Script for 3.2
461 $afterversionarray = explode('.', '3.1.9');
462 $beforeversionarray = explode('.', '3.2.9');
463 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
464 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
465
466 migrate_price_contrat($db, $langs, $conf);
467
468 migrate_mode_reglement($db, $langs, $conf);
469
470 migrate_clean_association($db, $langs, $conf);
471 }
472
473 // Script for 3.3
474 $afterversionarray = explode('.', '3.2.9');
475 $beforeversionarray = explode('.', '3.3.9');
476 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
477 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
478
479 migrate_categorie_association($db, $langs, $conf);
480 }
481
482 // Script for 3.4
483 // No specific scripts
484
485 // Tasks to do always and only into last targeted version
486 $afterversionarray = explode('.', '3.6.9'); // target is after this
487 $beforeversionarray = explode('.', '3.7.9'); // target is before this
488 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
489 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
490
491 migrate_event_assignement($db, $langs, $conf);
492 }
493
494 // Scripts for 3.9
495 $afterversionarray = explode('.', '3.7.9');
496 $beforeversionarray = explode('.', '3.8.9');
497 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
498 // No particular code
499 //}
500
501 // Scripts for 4.0
502 $afterversionarray = explode('.', '3.9.9');
503 $beforeversionarray = explode('.', '4.0.9');
504 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
505 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
506
507 migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias');
508 }
509
510 // Scripts for 5.0
511 $afterversionarray = explode('.', '4.0.9');
512 $beforeversionarray = explode('.', '5.0.9');
513 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
514 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
515
516 // Migrate to add entity value into llx_societe_remise
517 migrate_remise_entity($db, $langs, $conf);
518
519 // Migrate to add entity value into llx_societe_remise_except
520 migrate_remise_except_entity($db, $langs, $conf);
521 }
522
523 // Scripts for 6.0
524 $afterversionarray = explode('.', '5.0.9');
525 $beforeversionarray = explode('.', '6.0.9');
526 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
527 if (isModEnabled('multicompany')) {
528 global $multicompany_transverse_mode;
529
530 // Only if the transverse mode is not used
531 if (empty($multicompany_transverse_mode)) {
532 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
533
534 // Migrate to add entity value into llx_user_rights
535 migrate_user_rights_entity($db, $langs, $conf);
536
537 // Migrate to add entity value into llx_usergroup_rights
538 migrate_usergroup_rights_entity($db, $langs, $conf);
539 }
540 }
541 }
542
543 // Scripts for 7.0
544 $afterversionarray = explode('.', '6.0.9');
545 $beforeversionarray = explode('.', '7.0.9');
546 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
547 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
548
549 // Migrate contact association
550 migrate_event_assignement_contact($db, $langs, $conf);
551
552 migrate_reset_blocked_log($db, $langs, $conf);
553 }
554
555 // Scripts for 8.0
556 $afterversionarray = explode('.', '7.0.9');
557 $beforeversionarray = explode('.', '8.0.9');
558 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
559 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
560
561 migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract');
562 }
563
564 // Scripts for 9.0
565 $afterversionarray = explode('.', '8.0.9');
566 $beforeversionarray = explode('.', '9.0.9');
567 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
568 //migrate_user_photospath();
569 //}
570
571 // Scripts for 11.0
572 $afterversionarray = explode('.', '10.0.9');
573 $beforeversionarray = explode('.', '11.0.9');
574 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
575 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
576
581 }
582
583 // Scripts for 14.0
584 $afterversionarray = explode('.', '13.0.9');
585 $beforeversionarray = explode('.', '14.0.9');
586 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
587 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
588
591 }
592
593 // Scripts for 16.0
594 $afterversionarray = explode('.', '15.0.9');
595 $beforeversionarray = explode('.', '16.0.9');
596 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
597 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
598
601 }
602
603 // Scripts for 17.0
604 $afterversionarray = explode('.', '16.0.9');
605 $beforeversionarray = explode('.', '17.0.9');
606 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
607 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
608
610 }
611
612 // Scripts for 18.0
613 $afterversionarray = explode('.', '17.0.9');
614 $beforeversionarray = explode('.', '18.0.9');
615 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
616 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
617
619 }
620
621 // Scripts for 19.0
622 /*
623 $afterversionarray = explode('.', '18.0.9');
624 $beforeversionarray = explode('.', '19.0.9');
625 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
626 }
627 */
628
629 // Scripts for 20.0
630 $afterversionarray = explode('.', '19.0.9');
631 $beforeversionarray = explode('.', '20.0.9');
632 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
633 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
634
636 }
637
638 // Scripts for 21.0
639 $afterversionarray = explode('.', '20.0.9');
640 $beforeversionarray = explode('.', '21.0.9');
641
642
643 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
644 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
645
647 }
648
649 // Scripts for 22.0
650 $afterversionarray = explode('.', '21.0.9');
651 $beforeversionarray = explode('.', '22.0.9');
652 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
653 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
654
656 }
657
658 // Scripts for 23.0
659 $afterversionarray = explode('.', '22.0.9');
660 $beforeversionarray = explode('.', '23.0.9');
661 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
662 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
663
665
667
669 }
670 }
671
672 // Code executed only if migration is LAST ONE. Must always be done.
673 if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3) {
674 dol_syslog("Run migrate_... if migration is LAST ONE");
675
676 // Reload modules (this must be always done and only into last targeted version, because code to reload module may need table structure of last version)
677 $listofmodule = array(
678 'MAIN_MODULE_ACCOUNTING' => 'newboxdefonly',
679 'MAIN_MODULE_AGENDA' => 'newboxdefonly',
680 'MAIN_MODULE_BOM' => 'menuonly',
681 'MAIN_MODULE_BANQUE' => 'menuonly',
682 'MAIN_MODULE_BARCODE' => 'newboxdefonly',
683 'MAIN_MODULE_CRON' => 'newboxdefonly',
684 'MAIN_MODULE_COMMANDE' => 'newboxdefonly',
685 'MAIN_MODULE_BLOCKEDLOG' => 'noboxes',
686 'MAIN_MODULE_DON' => 'newboxdefonly',
687 'MAIN_MODULE_ECM' => 'newboxdefonly',
688 'MAIN_MODULE_EVENTORGANIZATION' => 'newboxdefonly',
689 'MAIN_MODULE_EXPENSEREPORT' => 'newboxdefonly',
690 'MAIN_MODULE_FACTURE' => 'newboxdefonly',
691 'MAIN_MODULE_FOURNISSEUR' => 'newboxdefonly',
692 'MAIN_MODULE_FICHEINTER' => 'newboxdefonly',
693 'MAIN_MODULE_HOLIDAY' => 'newboxdefonly',
694 'MAIN_MODULE_LOAN' => 'newboxdefonly',
695 'MAIN_MODULE_MARGIN' => 'menuonly',
696 'MAIN_MODULE_MRP' => 'menuonly',
697 'MAIN_MODULE_OPENSURVEY' => 'newboxdefonly',
698 'MAIN_MODULE_PARTNERSHIP' => 'newboxdefonly',
699 'MAIN_MODULE_PRINTING' => 'newboxdefonly',
700 'MAIN_MODULE_PRODUIT' => 'newboxdefonly',
701 'MAIN_MODULE_RECRUITMENT' => 'menuonly',
702 'MAIN_MODULE_RESOURCE' => 'noboxes',
703 'MAIN_MODULE_SALARIES' => 'newboxdefonly',
704 'MAIN_MODULE_SERVICE' => 'newboxdefonly',
705 'MAIN_MODULE_SYSLOG' => 'newboxdefonly',
706 'MAIN_MODULE_SOCIETE' => 'newboxdefonly',
707 'MAIN_MODULE_STRIPE' => 'menuonly',
708 'MAIN_MODULE_TICKET' => 'newboxdefonly',
709 'MAIN_MODULE_TAKEPOS' => 'newboxdefonly',
710 'MAIN_MODULE_USER' => 'newboxdefonly', //This one must be always done and only into last targeted version)
711 'MAIN_MODULE_VARIANTS' => 'newboxdefonly',
712 'MAIN_MODULE_WEBSITE' => 'newboxdefonly',
713 );
714
715 $result = migrate_reload_modules($db, $langs, $conf, $listofmodule);
716 if ($result < 0) {
717 $error++;
718 }
719
720 // Reload menus (this must be always done, and only into last targeted version)
721 // This reload the auguria menu.To reload a dynamic menu defined into module descriptor, see previours step
722 $result = migrate_reload_menu($db, $langs, $conf);
723 if ($result < 0) {
724 $error++;
725 }
726 }
727
728 // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...'
729 // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line.
730 if (!$error && $enablemodules) {
731 // Reload modules (this must be always done and only into last targeted version)
732 $listofmodules = array();
733 $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules);
734 $tmplistofmodules = explode(',', $enablemodules);
735 foreach ($tmplistofmodules as $value) {
736 $listofmodules[$value] = 'forceactivate';
737 }
738
739 $resultreloadmodules = migrate_reload_modules($db, $langs, $conf, $listofmodules, 1);
740 if ($resultreloadmodules < 0) {
741 $error++;
742 }
743 }
744
745
746 // Can call a dedicated external upgrade process with hook doUpgradeAfterDB()
747 if (!$error) {
748 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
749 $object = new stdClass();
750 $action = "upgrade";
751 $reshook = $hookmanager->executeHooks('doUpgradeAfterDB', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
752 if ($hookmanager->resNbOfHooks > 0) {
753 if ($reshook < 0) {
754 print '<tr><td colspan="4">';
755 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
756 print $hookmanager->error;
757 print "<!-- (".$reshook.") -->";
758 print '</td></tr>';
759 } else {
760 print '<tr class="trforrunsql"><td colspan="4">';
761 print '<b>'.$langs->trans('UpgradeExternalModule').' (DB)</b>: <span class="ok">OK</span>';
762 print "<!-- (".$reshook.") -->";
763 print '</td></tr>';
764 }
765 } else {
766 //if (!empty($conf->modules))
767 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
768 print '<tr class="trforrunsql"><td colspan="4">';
769 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterDB");
770 print '</td></tr>';
771 }
772 }
773 }
774 }
775
776 print '</table>';
777
778 if (!$error) {
779 // Set constant to ask to remake a new ping to inform about upgrade (if ping was already done and OK)
780 $sql = 'UPDATE '.MAIN_DB_PREFIX."const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'"; // This should be useless now because constant is uniqueid+' v'+version
781 $db->query($sql, 1);
782 }
783
784 // We always commit.
785 // Process is designed so we can run it several times whatever is situation.
786 $db->commit();
787
788
789 /***************************************************************************************
790 *
791 * Migration of files
792 *
793 ***************************************************************************************/
794
795 foreach ($listofentities as $entity) {
796 // Set $conf context for entity
797 $conf->setEntityValues($db, $entity);
798 // Reset forced setup after the setValues
799 if (defined('SYSLOG_FILE')) {
800 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
801 }
802 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
803
804
805 // Copy directory medias
806 $srcroot = DOL_DOCUMENT_ROOT.'/install/medias';
807 $destroot = DOL_DATA_ROOT.'/medias';
808 dolCopyDir($srcroot, $destroot, '0', 0);
809
810
811 // Actions for all versions (no database change but delete some files and directories)
812 migrate_delete_old_files($db, $langs, $conf);
813 migrate_delete_old_dir($db, $langs, $conf);
814 // Actions for all versions (no database change but create some directories)
815 dol_mkdir(DOL_DATA_ROOT.'/bank');
816 // Actions for all versions (no database change but rename some directories)
817 migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits');
818
819
820 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
821 $object = new stdClass();
822 $action = "upgrade";
823 $reshook = $hookmanager->executeHooks('doUpgradeAfterFiles', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
824 if ($hookmanager->resNbOfHooks > 0) {
825 if ($reshook < 0) {
826 print '<tr><td colspan="4">';
827 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
828 print $hookmanager->error;
829 print "<!-- (".$reshook.") -->";
830 print '</td></tr>';
831 } else {
832 print '<tr class="trforrunsql"><td colspan="4">';
833 print '<b>'.$langs->trans('UpgradeExternalModule').' (Files)</b>: <span class="ok">OK</span>';
834 print "<!-- (".$reshook.") -->";
835 print '</td></tr>';
836 }
837 } else {
838 //if (!empty($conf->modules))
839 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
840 print '<tr class="trforrunsql"><td colspan="4">';
841 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterFiles");
842 print '</td></tr>';
843 }
844 }
845 }
846
847 $db->close();
848
849 $silent = 0;
850 if (!$silent) {
851 print '<table width="100%">';
852 print '<tr><td style="width: 30%">'.$langs->trans("MigrationFinished").'</td>';
853 print '<td class="right">';
854 if ($error == 0) {
855 //print '<span class="ok">'.$langs->trans("OK").'</span> - '; // $error = 0 does not mean there is no error (error are not always trapped)
856 } else {
857 print '<span class="error">'.$langs->trans("Error").'</span> - ';
858 }
859
860 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
861 print '<script type="text/javascript">
862 jQuery(document).ready(function() {
863 function init_trrunsql()
864 {
865 console.log("toggle .trforrunsql");
866 jQuery(".trforrunsql").toggle();
867 }
868 init_trrunsql();
869 jQuery(".trforrunsqlshowhide").click(function() {
870 init_trrunsql();
871 });
872 });
873 </script>';
874 print '<a class="trforrunsqlshowhide" href="#">'.$langs->trans("ShowHideDetails").'</a>';
875 //}
876
877 print '</td></tr>'."\n";
878 print '</table>';
879 }
880
881 //print '<div><br>'.$langs->trans("MigrationFinished").'</div>';
882} else {
883 print '<div class="error">'.$langs->trans('ErrorWrongParameters').'</div>';
884 $error++;
885}
886
887$ret = 0;
888if ($error && isset($argv[1])) {
889 $ret = 1;
890}
891dolibarr_install_syslog("Exit ".$ret);
892
893dolibarr_install_syslog("--- upgrade2: end");
894pFooter($error ? 2 : 0, $setuplang);
895
896if ($db->connected) {
897 $db->close();
898}
899
900// Return code if ran from command line
901if ($ret) {
902 exit($ret);
903}
904
905
906
915function migrate_paiements($db, $langs, $conf)
916{
917 print '<tr><td colspan="4">';
918
919 print '<br>';
920 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
921
922 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
923 $obj = $db->fetch_object($result);
924 if ($obj) {
925 $sql = "SELECT p.rowid, p.fk_facture, p.amount";
926 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
927 $sql .= " WHERE p.fk_facture > 0";
928
929 $resql = $db->query($sql);
930 $row = array();
931 $num = 0;
932
933 dolibarr_install_syslog("upgrade2::migrate_paiements");
934 if ($resql) {
935 $i = 0;
936 $num = $db->num_rows($resql);
937
938 while ($i < $num) {
939 $obj = $db->fetch_object($resql);
940 $row[$i][0] = $obj->rowid;
941 $row[$i][1] = $obj->fk_facture;
942 $row[$i][2] = $obj->amount;
943 $i++;
944 }
945 } else {
946 dol_print_error($db);
947 }
948
949 if ($num) {
950 print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."<br>\n";
951 $res = 0;
952 if ($db->begin()) {
953 $num = count($row);
954 for ($i = 0; $i < $num; $i++) {
955 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
956 $sql .= " VALUES (".((int) $row[$i][1]).",".((int) $row[$i][0]).",".((float) $row[$i][2]).")";
957
958 $res += $db->query($sql);
959
960 $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
961
962 $res += $db->query($sql);
963
964 print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."<br>\n";
965 }
966 }
967
968 if (is_array($row) && $res == (2 * count($row))) {
969 $db->commit();
970 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
971 } else {
972 $db->rollback();
973 print $langs->trans('MigrationUpdateFailed').'<br>';
974 }
975 } else {
976 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
977 }
978 } else {
979 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
980 }
981
982 print '</td></tr>';
983}
984
995function migrate_paiements_orphelins_1($db, $langs, $conf)
996{
997 print '<tr><td colspan="4">';
998
999 print '<br>';
1000 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1001
1002 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1003 $obj = $db->fetch_object($result);
1004 if ($obj) {
1005 // All answer of this requests should have a parent into llx_paiement_facture
1006 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1007 $sql .= " bu2.url_id as socid";
1008 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1009 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1010 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
1011 $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
1012 $sql .= " AND b.rappro = 1";
1013 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1014
1015 $resql = $db->query($sql);
1016
1017 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1");
1018 $row = array();
1019 if ($resql) {
1020 $i = $j = 0;
1021 $num = $db->num_rows($resql);
1022
1023 while ($i < $num) {
1024 $obj = $db->fetch_object($resql);
1025 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1026 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1027 $row[$j]['pamount'] = $obj->pamount;
1028 $row[$j]['fk_bank'] = $obj->fk_bank;
1029 $row[$j]['bamount'] = $obj->bamount;
1030 $row[$j]['socid'] = $obj->socid;
1031 $row[$j]['datec'] = $obj->datec;
1032 $j++;
1033 }
1034 $i++;
1035 }
1036 } else {
1037 dol_print_error($db);
1038 }
1039
1040 if (count($row)) {
1041 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."<br>\n";
1042 $db->begin();
1043
1044 $res = 0;
1045 $num = count($row);
1046 for ($i = 0; $i < $num; $i++) {
1047 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1048 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>';
1049 }
1050
1051 // Look for invoices without payment relations with the same amount and same comppany
1052 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1053 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1054 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1055 $sql .= " AND pf.fk_facture IS NULL";
1056 $sql .= " ORDER BY f.fk_statut";
1057 //print $sql.'<br>';
1058 $resql = $db->query($sql);
1059 if ($resql) {
1060 $num = $db->num_rows($resql);
1061 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1062 if ($num >= 1) {
1063 $obj = $db->fetch_object($resql);
1064 $facid = $obj->rowid;
1065
1066 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1067 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1068
1069 $res += $db->query($sql);
1070
1071 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1072 }
1073 } else {
1074 print 'ERROR';
1075 }
1076 }
1077
1078 if ($res > 0) {
1079 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1080 } else {
1081 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1082 }
1083
1084 $db->commit();
1085 } else {
1086 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1087 }
1088 } else {
1089 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1090 }
1091
1092 print '</td></tr>';
1093}
1094
1105function migrate_paiements_orphelins_2($db, $langs, $conf)
1106{
1107 print '<tr><td colspan="4">';
1108
1109 print '<br>';
1110 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1111
1112 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1113 $obj = $db->fetch_object($result);
1114 if ($obj) {
1115 // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
1116 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1117 $sql .= " bu2.url_id as socid";
1118 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1119 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1120 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
1121 $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
1122 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1123
1124 $resql = $db->query($sql);
1125
1126 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2");
1127 $row = array();
1128 if ($resql) {
1129 $i = $j = 0;
1130 $num = $db->num_rows($resql);
1131
1132 while ($i < $num) {
1133 $obj = $db->fetch_object($resql);
1134 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1135 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1136 $row[$j]['pamount'] = $obj->pamount;
1137 $row[$j]['fk_bank'] = $obj->fk_bank;
1138 $row[$j]['bamount'] = $obj->bamount;
1139 $row[$j]['socid'] = $obj->socid;
1140 $row[$j]['datec'] = $obj->datec;
1141 $j++;
1142 }
1143 $i++;
1144 }
1145 } else {
1146 dol_print_error($db);
1147 }
1148
1149 $nberr = 0;
1150
1151 $num = count($row);
1152 if ($num) {
1153 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."<br>\n";
1154 $db->begin();
1155
1156 $res = 0;
1157 for ($i = 0; $i < $num; $i++) {
1158 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1159 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>';
1160 }
1161
1162 // Look for invoices without payment relations with the same amount and same comppany
1163 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1164 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1165 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1166 $sql .= " AND pf.fk_facture IS NULL";
1167 $sql .= " ORDER BY f.fk_statut";
1168 //print $sql.'<br>';
1169 $resql = $db->query($sql);
1170 if ($resql) {
1171 $num = $db->num_rows($resql);
1172 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1173 if ($num >= 1) {
1174 $obj = $db->fetch_object($resql);
1175 $facid = $obj->rowid;
1176
1177 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1178 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1179
1180 $res += $db->query($sql);
1181
1182 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1183 }
1184 } else {
1185 print 'ERROR';
1186 $nberr++;
1187 }
1188 }
1189
1190 if ($res > 0) {
1191 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1192 } else {
1193 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1194 }
1195
1196 $db->commit();
1197 } else {
1198 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1199 }
1200
1201 // Delete obsolete fields fk_facture
1202 $db->begin();
1203
1204 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture";
1205 $db->query($sql);
1206
1207 if (!$nberr) {
1208 $db->commit();
1209 } else {
1210 print 'ERROR';
1211 $db->rollback();
1212 }
1213 } else {
1214 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1215 }
1216
1217 print '</td></tr>';
1218}
1219
1220
1229function migrate_contracts_det($db, $langs, $conf)
1230{
1231 print '<tr><td colspan="4">';
1232
1233 $nberr = 0;
1234
1235 print '<br>';
1236 print '<b>'.$langs->trans('MigrationContractsUpdate')."</b><br>\n";
1237
1238 $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1239 $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1240 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
1241 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p";
1242 $sql .= " ON c.fk_product = p.rowid";
1243 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd";
1244 $sql .= " ON c.rowid=cd.fk_contrat";
1245 $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1246 $resql = $db->query($sql);
1247
1248 dolibarr_install_syslog("upgrade2::migrate_contracts_det");
1249 if ($resql) {
1250 $i = 0;
1251 $row = array();
1252 $num = $db->num_rows($resql);
1253
1254 if ($num) {
1255 print $langs->trans('MigrationContractsNumberToUpdate', $num)."<br>\n";
1256 $db->begin();
1257
1258 while ($i < $num) {
1259 $obj = $db->fetch_object($resql);
1260
1261 $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet (";
1262 $sql .= "fk_contrat, fk_product, statut, label, description,";
1263 $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1264 $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)";
1265 $sql .= " VALUES (";
1266 $sql .= ((int) $obj->cref).", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).", ";
1267 $sql .= "0, ";
1268 $sql .= "'".$db->escape($obj->label)."', null, ";
1269 $sql .= ($obj->date_contrat ? "'".$db->idate($db->jdate($obj->date_contrat))."'" : "null").", ";
1270 $sql .= "null, ";
1271 $sql .= "null, ";
1272 $sql .= ((float) $obj->tva_tx).", 1, ";
1273 $sql .= ((float) $obj->price).", ".((float) $obj->price).", ".((int) $obj->fk_user_author).",";
1274 $sql .= "null";
1275 $sql .= ")";
1276
1277 if ($db->query($sql)) {
1278 print $langs->trans('MigrationContractsLineCreation', $obj->cref)."<br>\n";
1279 } else {
1280 dol_print_error($db);
1281 $nberr++;
1282 }
1283
1284 $i++;
1285 }
1286
1287 if (!$nberr) {
1288 // $db->rollback();
1289 $db->commit();
1290 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1291 } else {
1292 $db->rollback();
1293 print $langs->trans('MigrationUpdateFailed').'<br>';
1294 }
1295 } else {
1296 print $langs->trans('MigrationContractsNothingToUpdate')."<br>\n";
1297 }
1298 } else {
1299 print $langs->trans('MigrationContractsFieldDontExist')."<br>\n";
1300 // dol_print_error($db);
1301 }
1302
1303 print '</td></tr>';
1304}
1305
1314function migrate_links_transfert($db, $langs, $conf)
1315{
1316 print '<tr><td colspan="4">';
1317
1318 $nberr = 0;
1319
1320 print '<br>';
1321 print '<b>'.$langs->trans('MigrationBankTransfertsUpdate')."</b><br>\n";
1322
1323 $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1324 $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba";
1325 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid";
1326 $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1327 $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec";
1328 $sql .= " AND bu.fk_bank IS NULL";
1329 $resql = $db->query($sql);
1330
1331 dolibarr_install_syslog("upgrade2::migrate_links_transfert");
1332 if ($resql) {
1333 $i = 0;
1334 $row = array();
1335 $num = $db->num_rows($resql);
1336
1337 if ($num) {
1338 print $langs->trans('MigrationBankTransfertsToUpdate', $num)."<br>\n";
1339 $db->begin();
1340
1341 while ($i < $num) {
1342 $obj = $db->fetch_object($resql);
1343
1344 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
1345 $sql .= "fk_bank, url_id, url, label, type";
1346 $sql .= ")";
1347 $sql .= " VALUES (";
1348 $sql .= $obj->barowid.",".$obj->bbrowid.", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1349 $sql .= ")";
1350
1351 //print $sql.'<br>';
1352 dolibarr_install_syslog("migrate_links_transfert");
1353
1354 if (!$db->query($sql)) {
1355 dol_print_error($db);
1356 $nberr++;
1357 }
1358
1359 $i++;
1360 }
1361
1362 if (!$nberr) {
1363 // $db->rollback();
1364 $db->commit();
1365 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1366 } else {
1367 $db->rollback();
1368 print $langs->trans('MigrationUpdateFailed').'<br>';
1369 }
1370 } else {
1371 print $langs->trans('MigrationBankTransfertsNothingToUpdate')."<br>\n";
1372 }
1373 } else {
1374 dol_print_error($db);
1375 }
1376
1377 print '</td></tr>';
1378}
1379
1388function migrate_contracts_date1($db, $langs, $conf)
1389{
1390 print '<tr><td colspan="4">';
1391
1392 print '<br>';
1393 print '<b>'.$langs->trans('MigrationContractsEmptyDatesUpdate')."</b><br>\n";
1394
1395 $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null";
1396 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1397 $resql = $db->query($sql);
1398 if (!$resql) {
1399 dol_print_error($db);
1400 }
1401 if ($db->affected_rows($resql) > 0) {
1402 print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."<br>\n";
1403 } else {
1404 print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."<br>\n";
1405 }
1406
1407 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null";
1408 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1409 $resql = $db->query($sql);
1410 if (!$resql) {
1411 dol_print_error($db);
1412 }
1413 if ($db->affected_rows($resql) > 0) {
1414 print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."<br>\n";
1415 } else {
1416 print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."<br>\n";
1417 }
1418
1419 print '</td></tr>';
1420}
1421
1430function migrate_contracts_date2($db, $langs, $conf)
1431{
1432 print '<tr><td colspan="4">';
1433
1434 $nberr = 0;
1435
1436 print '<br>';
1437 print '<b>'.$langs->trans('MigrationContractsInvalidDatesUpdate')."</b><br>\n";
1438
1439 $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1440 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
1441 $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
1442 $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1443 $sql .= " GROUP BY c.rowid, c.date_contrat";
1444 $resql = $db->query($sql);
1445
1446 dolibarr_install_syslog("upgrade2::migrate_contracts_date2");
1447 if ($resql) {
1448 $i = 0;
1449 $row = array();
1450 $num = $db->num_rows($resql);
1451
1452 if ($num) {
1453 $nbcontratsmodifie = 0;
1454 $db->begin();
1455
1456 while ($i < $num) {
1457 $obj = $db->fetch_object($resql);
1458 if ($obj->date_contrat > $obj->datemin) {
1459 $datemin = $db->jdate($obj->datemin);
1460
1461 print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."<br>\n";
1462 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1463 $sql .= " SET date_contrat='".$db->idate($datemin)."'";
1464 $sql .= " WHERE rowid = ".((int) $obj->cref);
1465 $resql2 = $db->query($sql);
1466 if (!$resql2) {
1467 dol_print_error($db);
1468 }
1469
1470 $nbcontratsmodifie++;
1471 }
1472 $i++;
1473 }
1474
1475 $db->commit();
1476
1477 if ($nbcontratsmodifie) {
1478 print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."<br>\n";
1479 } else {
1480 print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."<br>\n";
1481 }
1482 }
1483 } else {
1484 dol_print_error($db);
1485 }
1486
1487 print '</td></tr>';
1488}
1489
1498function migrate_contracts_date3($db, $langs, $conf)
1499{
1500 print '<tr><td colspan="4">';
1501
1502 print '<br>';
1503 print '<b>'.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."</b><br>\n";
1504
1505 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat";
1506 dolibarr_install_syslog("upgrade2::migrate_contracts_date3");
1507 $resql = $db->query($sql);
1508 if (!$resql) {
1509 dol_print_error($db);
1510 }
1511 if ($db->affected_rows($resql) > 0) {
1512 print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."<br>\n";
1513 } else {
1514 print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."<br>\n";
1515 }
1516
1517 print '</td></tr>';
1518}
1519
1528function migrate_contracts_open($db, $langs, $conf)
1529{
1530 print '<tr><td colspan="4">';
1531
1532 print '<br>';
1533 print '<b>'.$langs->trans('MigrationReopeningContracts')."</b><br>\n";
1534
1535 $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd";
1536 $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1537 dolibarr_install_syslog("upgrade2::migrate_contracts_open");
1538 $resql = $db->query($sql);
1539 if (!$resql) {
1540 dol_print_error($db);
1541 }
1542 if ($db->affected_rows($resql) > 0) {
1543 $i = 0;
1544 $row = array();
1545 $num = $db->num_rows($resql);
1546
1547 if ($num) {
1548 $nbcontratsmodifie = 0;
1549 $db->begin();
1550
1551 while ($i < $num) {
1552 $obj = $db->fetch_object($resql);
1553
1554 print $langs->trans('MigrationReopenThisContract', $obj->cref)."<br>\n";
1555 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1556 $sql .= " SET statut = 1";
1557 $sql .= " WHERE rowid = ".((int) $obj->cref);
1558 $resql2 = $db->query($sql);
1559 if (!$resql2) {
1560 dol_print_error($db);
1561 }
1562
1563 $nbcontratsmodifie++;
1564
1565 $i++;
1566 }
1567
1568 $db->commit();
1569
1570 if ($nbcontratsmodifie) {
1571 print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."<br>\n";
1572 } else {
1573 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1574 }
1575 }
1576 } else {
1577 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1578 }
1579
1580 print '</td></tr>';
1581}
1582
1591function migrate_paiementfourn_facturefourn($db, $langs, $conf)
1592{
1593 global $bc;
1594
1595 print '<tr><td colspan="4">';
1596 print '<br>';
1597 print '<b>'.$langs->trans('SuppliersInvoices')."</b><br>\n";
1598 print '</td></tr>';
1599
1600 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn");
1601 $obj = $db->fetch_object($result);
1602 if ($obj) {
1603 $error = 0;
1604 $nb = 0;
1605
1606 $select_sql = 'SELECT rowid, fk_facture_fourn, amount';
1607 $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn';
1608 $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL';
1609
1610 dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn");
1611 $select_resql = $db->query($select_sql);
1612 if ($select_resql) {
1613 $select_num = $db->num_rows($select_resql);
1614 $i = 0;
1615
1616 // Pour chaque paiement fournisseur, on insere une ligne dans paiementfourn_facturefourn
1617 while (($i < $select_num) && (!$error)) {
1618 $select_obj = $db->fetch_object($select_resql);
1619
1620 // Verifier si la ligne est deja dans la nouvelle table. On ne veut pas inserer de doublons.
1621 $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn';
1622 $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
1623 $check_sql .= ' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1624 $check_resql = $db->query($check_sql);
1625 if ($check_resql) {
1626 $check_num = $db->num_rows($check_resql);
1627 if ($check_num == 0) {
1628 $db->begin();
1629
1630 if ($nb == 0) {
1631 print '<tr><td colspan="4" class="nowrap"><b>'.$langs->trans('SuppliersInvoices').'</b></td></tr>';
1632 print '<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans('Amount').'</td><td>&nbsp;</td></tr>';
1633 }
1634
1635 print '<tr class="oddeven">';
1636 print '<td>'.$select_obj->rowid.'</td><td>'.$select_obj->fk_facture_fourn.'</td><td>'.$select_obj->amount.'</td>';
1637
1638 $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET ';
1639 $insert_sql .= ' fk_paiementfourn = \''.$select_obj->rowid.'\',';
1640 $insert_sql .= ' fk_facturefourn = \''.$select_obj->fk_facture_fourn.'\',';
1641 $insert_sql .= ' amount = \''.$select_obj->amount.'\'';
1642 $insert_resql = $db->query($insert_sql);
1643
1644 if ($insert_resql) {
1645 $nb++;
1646 print '<td><span class="ok">'.$langs->trans("OK").'</span></td>';
1647 } else {
1648 print '<td><span class="error">Error on insert</span></td>';
1649 $error++;
1650 }
1651 print '</tr>';
1652 }
1653 } else {
1654 $error++;
1655 }
1656 $i++;
1657 }
1658 } else {
1659 $error++;
1660 }
1661
1662 if (!$error) {
1663 if (!$nb) {
1664 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1665 }
1666 $db->commit();
1667
1668 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn";
1669 $db->query($sql);
1670 } else {
1671 print '<tr><td>'.$langs->trans("Error").'</td></tr>';
1672 $db->rollback();
1673 }
1674 } else {
1675 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1676 }
1677}
1678
1687function migrate_price_facture($db, $langs, $conf)
1688{
1689 $err = 0;
1690
1691 $tmpmysoc = new Societe($db);
1692 $tmpmysoc->setMysoc($conf);
1693
1694 $db->begin();
1695
1696 print '<tr><td colspan="4">';
1697
1698 print '<br>';
1699 print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n";
1700
1701 // List of invoice lines not up to date
1702 $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1703 $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1704 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
1705 $sql .= " WHERE fd.fk_facture = f.rowid";
1706 $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1707 //print $sql;
1708
1709 dolibarr_install_syslog("upgrade2::migrate_price_facture");
1710 $resql = $db->query($sql);
1711 if ($resql) {
1712 $num = $db->num_rows($resql);
1713 $i = 0;
1714 if ($num) {
1715 while ($i < $num) {
1716 $obj = $db->fetch_object($resql);
1717
1718 $rowid = $obj->rowid;
1719 $qty = $obj->qty;
1720 $pu = $obj->subprice;
1721 $vatrate = $obj->vatrate;
1722 $remise_percent = $obj->remise_percent;
1723 $remise_percent_global = $obj->remise_percent_global;
1724 $total_ttc_f = $obj->total_ttc_f;
1725 $info_bits = $obj->info_bits;
1726
1727 // On met a jour les 3 nouveaux champs
1728 $facligne = new FactureLigne($db);
1729 $facligne->fetch($rowid);
1730
1731 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1732 $total_ht = $result[0];
1733 $total_tva = $result[1];
1734 $total_ttc = $result[2];
1735
1736 $facligne->total_ht = (float) $total_ht;
1737 $facligne->total_tva = (float) $total_tva;
1738 $facligne->total_ttc = (float) $total_ttc;
1739
1740 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);
1741 print '. ';
1742 $facligne->update_total();
1743
1744
1745 /* On touche a facture mere uniquement si total_ttc = 0 */
1746 if (!$total_ttc_f) {
1747 $facture = new Facture($db);
1748 $facture->id = $obj->facid;
1749
1750 if ($facture->fetch($facture->id) >= 0) {
1751 if ($facture->update_price() > 0) {
1752 //print $facture->id;
1753 } else {
1754 print "Error id=".$facture->id;
1755 $err++;
1756 }
1757 } else {
1758 print "Error #3";
1759 $err++;
1760 }
1761 }
1762 print " ";
1763
1764 $i++;
1765 }
1766 } else {
1767 print $langs->trans("AlreadyDone");
1768 }
1769 $db->free($resql);
1770
1771 $db->commit();
1772 } else {
1773 print "Error #1 ".$db->error();
1774 $err++;
1775
1776 $db->rollback();
1777 }
1778
1779 print '<br>';
1780
1781 print '</td></tr>';
1782}
1783
1792function migrate_price_propal($db, $langs, $conf)
1793{
1794 $tmpmysoc = new Societe($db);
1795 $tmpmysoc->setMysoc($conf);
1796
1797 $db->begin();
1798
1799 print '<tr><td colspan="4">';
1800
1801 print '<br>';
1802 print '<b>'.$langs->trans('MigrationProposal')."</b><br>\n";
1803
1804 // List of proposal lines not up to date
1805 $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1806 $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global";
1807 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p";
1808 $sql .= " WHERE pd.fk_propal = p.rowid";
1809 $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1810
1811 dolibarr_install_syslog("upgrade2::migrate_price_propal");
1812 $resql = $db->query($sql);
1813 if ($resql) {
1814 $num = $db->num_rows($resql);
1815 $i = 0;
1816 if ($num) {
1817 while ($i < $num) {
1818 $obj = $db->fetch_object($resql);
1819
1820 $rowid = $obj->rowid;
1821 $qty = $obj->qty;
1822 $pu = $obj->subprice;
1823 $vatrate = $obj->vatrate;
1824 $remise_percent = $obj->remise_percent;
1825 $remise_percent_global = $obj->remise_percent_global;
1826 $info_bits = $obj->info_bits;
1827
1828 // On met a jour les 3 nouveaux champs
1829 $propalligne = new PropaleLigne($db);
1830 $propalligne->fetch($rowid);
1831
1832 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1833 $total_ht = $result[0];
1834 $total_tva = $result[1];
1835 $total_ttc = $result[2];
1836
1837 $propalligne->total_ht = (float) $total_ht;
1838 $propalligne->total_tva = (float) $total_tva;
1839 $propalligne->total_ttc = (float) $total_ttc;
1840
1841 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);
1842 print '. ';
1843 $propalligne->update_total();
1844
1845 $i++;
1846 }
1847 } else {
1848 print $langs->trans("AlreadyDone");
1849 }
1850
1851 $db->free($resql);
1852
1853 $db->commit();
1854 } else {
1855 print "Error #1 ".$db->error();
1856
1857 $db->rollback();
1858 }
1859
1860 print '<br>';
1861
1862 print '</td></tr>';
1863}
1864
1873function migrate_price_contrat($db, $langs, $conf)
1874{
1875 $db->begin();
1876
1877 $tmpmysoc = new Societe($db);
1878 $tmpmysoc->setMysoc($conf);
1879 if (empty($tmpmysoc->country_id)) {
1880 $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
1881 }
1882
1883 print '<tr><td colspan="4">';
1884
1885 print '<br>';
1886 print '<b>'.$langs->trans('MigrationContract')."</b><br>\n";
1887
1888 // List of contract lines not up to date
1889 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1890 $sql .= " c.rowid as contratid";
1891 $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
1892 $sql .= " WHERE cd.fk_contrat = c.rowid";
1893 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1894
1895 dolibarr_install_syslog("upgrade2::migrate_price_contrat");
1896 $resql = $db->query($sql);
1897 if ($resql) {
1898 $num = $db->num_rows($resql);
1899 $i = 0;
1900 if ($num) {
1901 while ($i < $num) {
1902 $obj = $db->fetch_object($resql);
1903
1904 $rowid = $obj->rowid;
1905 $qty = $obj->qty;
1906 $pu = $obj->subprice;
1907 $vatrate = $obj->vatrate;
1908 $remise_percent = $obj->remise_percent;
1909 $info_bits = $obj->info_bits;
1910
1911 // On met a jour les 3 nouveaux champs
1912 $contratligne = new ContratLigne($db);
1913 //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis
1914 $contratligne->fetch($rowid);
1915
1916 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1917 $total_ht = $result[0];
1918 $total_tva = $result[1];
1919 $total_ttc = $result[2];
1920
1921 $contratligne->total_ht = (float) $total_ht;
1922 $contratligne->total_tva = (float) $total_tva;
1923 $contratligne->total_ttc = (float) $total_ttc;
1924
1925 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);
1926 print '. ';
1927 $contratligne->update_total();
1928
1929 $i++;
1930 }
1931 } else {
1932 print $langs->trans("AlreadyDone");
1933 }
1934
1935 $db->free($resql);
1936
1937 $db->commit();
1938 } else {
1939 print "Error #1 ".$db->error();
1940
1941 $db->rollback();
1942 }
1943
1944 print '<br>';
1945
1946 print '</td></tr>';
1947}
1948
1957function migrate_price_commande($db, $langs, $conf)
1958{
1959 $db->begin();
1960
1961 $tmpmysoc = new Societe($db);
1962 $tmpmysoc->setMysoc($conf);
1963
1964 print '<tr><td colspan="4">';
1965
1966 print '<br>';
1967 print '<b>'.$langs->trans('MigrationOrder')."</b><br>\n";
1968
1969 // List of sales orders lines not up to date
1970 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1971 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
1972 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c";
1973 $sql .= " WHERE cd.fk_commande = c.rowid";
1974 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1975
1976 dolibarr_install_syslog("upgrade2::migrate_price_commande");
1977 $resql = $db->query($sql);
1978 if ($resql) {
1979 $num = $db->num_rows($resql);
1980 $i = 0;
1981 if ($num) {
1982 while ($i < $num) {
1983 $obj = $db->fetch_object($resql);
1984
1985 $rowid = $obj->rowid;
1986 $qty = $obj->qty;
1987 $pu = $obj->subprice;
1988 $vatrate = $obj->vatrate;
1989 $remise_percent = $obj->remise_percent;
1990 $remise_percent_global = $obj->remise_percent_global;
1991 $info_bits = $obj->info_bits;
1992
1993 // On met a jour les 3 nouveaux champs
1994 $commandeligne = new OrderLine($db);
1995 $commandeligne->fetch($rowid);
1996
1997 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1998 $total_ht = $result[0];
1999 $total_tva = $result[1];
2000 $total_ttc = $result[2];
2001
2002 $commandeligne->total_ht = (float) $total_ht;
2003 $commandeligne->total_tva = (float) $total_tva;
2004 $commandeligne->total_ttc = (float) $total_ttc;
2005
2006 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);
2007 print '. ';
2008 $commandeligne->update_total();
2009
2010 $i++;
2011 }
2012 } else {
2013 print $langs->trans("AlreadyDone");
2014 }
2015
2016 $db->free($resql);
2017
2018 /*
2019 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
2020 $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
2021 $resql=$db->query($sql);
2022 if (! $resql)
2023 {
2024 dol_print_error($db);
2025 }
2026 */
2027
2028 $db->commit();
2029 } else {
2030 print "Error #1 ".$db->error();
2031
2032 $db->rollback();
2033 }
2034
2035 print '<br>';
2036
2037 print '</td></tr>';
2038}
2039
2048function migrate_price_commande_fournisseur($db, $langs, $conf)
2049{
2050 global $mysoc;
2051
2052 $db->begin();
2053
2054 $tmpmysoc = new Societe($db);
2055 $tmpmysoc->setMysoc($conf);
2056
2057 print '<tr><td colspan="4">';
2058
2059 print '<br>';
2060 print '<b>'.$langs->trans('MigrationSupplierOrder')."</b><br>\n";
2061
2062 // List of purchase order lines not up to date
2063 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2064 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
2065 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c";
2066 $sql .= " WHERE cd.fk_commande = c.rowid";
2067 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2068
2069 dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur");
2070 $resql = $db->query($sql);
2071 if ($resql) {
2072 $num = $db->num_rows($resql);
2073 $i = 0;
2074 if ($num) {
2075 while ($i < $num) {
2076 $obj = $db->fetch_object($resql);
2077
2078 $rowid = $obj->rowid;
2079 $qty = $obj->qty;
2080 $pu = $obj->subprice;
2081 $vatrate = $obj->vatrate;
2082 $remise_percent = $obj->remise_percent;
2083 $remise_percent_global = $obj->remise_percent_global;
2084 $info_bits = $obj->info_bits;
2085
2086 // On met a jour les 3 nouveaux champs
2087 $commandeligne = new CommandeFournisseurLigne($db);
2088 $commandeligne->fetch($rowid);
2089
2090 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $mysoc);
2091 $total_ht = $result[0];
2092 $total_tva = $result[1];
2093 $total_ttc = $result[2];
2094
2095 $commandeligne->total_ht = (float) $total_ht;
2096 $commandeligne->total_tva = (float) $total_tva;
2097 $commandeligne->total_ttc = (float) $total_ttc;
2098
2099 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);
2100 print '. ';
2101 $commandeligne->update_total();
2102
2103 $i++;
2104 }
2105 } else {
2106 print $langs->trans("AlreadyDone");
2107 }
2108
2109 $db->free($resql);
2110
2111 /*
2112 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
2113 $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
2114 $resql=$db->query($sql);
2115 if (! $resql)
2116 {
2117 dol_print_error($db);
2118 }
2119 */
2120
2121 $db->commit();
2122 } else {
2123 print "Error #1 ".$db->error();
2124
2125 $db->rollback();
2126 }
2127
2128 print '<br>';
2129
2130 print '</td></tr>';
2131}
2132
2141function migrate_modeles($db, $langs, $conf)
2142{
2143 //print '<br>';
2144 //print '<b>'.$langs->trans('UpdateModelsTable')."</b><br>\n";
2145
2146 dolibarr_install_syslog("upgrade2::migrate_modeles");
2147
2148 if (isModEnabled('invoice')) {
2149 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
2150 $modellist = ModelePDFFactures::liste_modeles($db);
2151 if (count($modellist) == 0) {
2152 // Aucun model par default.
2153 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')";
2154 $resql = $db->query($sql);
2155 if (!$resql) {
2156 dol_print_error($db);
2157 }
2158 }
2159 }
2160
2161 if (isModEnabled('order')) {
2162 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2163 $modellist = ModelePDFCommandes::liste_modeles($db);
2164 if (count($modellist) == 0) {
2165 // Aucun model par default.
2166 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')";
2167 $resql = $db->query($sql);
2168 if (!$resql) {
2169 dol_print_error($db);
2170 }
2171 }
2172 }
2173
2174 if (isModEnabled("shipping")) {
2175 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
2176 $modellist = ModelePdfExpedition::liste_modeles($db);
2177 if (count($modellist) == 0) {
2178 // Aucun model par default.
2179 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')";
2180 $resql = $db->query($sql);
2181 if (!$resql) {
2182 dol_print_error($db);
2183 }
2184 }
2185 }
2186
2187 //print $langs->trans("AlreadyDone");
2188}
2189
2190
2199function migrate_commande_expedition($db, $langs, $conf)
2200{
2201 dolibarr_install_syslog("upgrade2::migrate_commande_expedition");
2202
2203 print '<tr><td colspan="4">';
2204
2205 print '<br>';
2206 print '<b>'.$langs->trans('MigrationShipmentOrderMatching')."</b><br>\n";
2207
2208 $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande");
2209 $obj = $db->fetch_object($result);
2210 if ($obj) {
2211 $error = 0;
2212
2213 $db->begin();
2214
2215 $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
2216 $resql = $db->query($sql);
2217 if ($resql) {
2218 $i = 0;
2219 $num = $db->num_rows($resql);
2220
2221 if ($num) {
2222 while ($i < $num) {
2223 $obj = $db->fetch_object($resql);
2224
2225 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
2226 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2227 $resql2 = $db->query($sql);
2228
2229 if (!$resql2) {
2230 $error++;
2231 dol_print_error($db);
2232 }
2233 print '. ';
2234 $i++;
2235 }
2236 }
2237
2238 if ($error == 0) {
2239 $db->commit();
2240 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
2241 print $langs->trans('FieldRenamed')."<br>\n";
2242 $db->query($sql);
2243 } else {
2244 $db->rollback();
2245 }
2246 } else {
2247 dol_print_error($db);
2248 $db->rollback();
2249 }
2250 } else {
2251 print $langs->trans('AlreadyDone')."<br>\n";
2252 }
2253 print '</td></tr>';
2254}
2255
2264function migrate_commande_livraison($db, $langs, $conf)
2265{
2266 dolibarr_install_syslog("upgrade2::migrate_commande_livraison");
2267
2268 print '<tr><td colspan="4">';
2269
2270 print '<br>';
2271 print '<b>'.$langs->trans('MigrationDeliveryOrderMatching')."</b><br>\n";
2272
2273 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande");
2274 $obj = $db->fetch_object($result);
2275 if ($obj) {
2276 $error = 0;
2277
2278 $db->begin();
2279
2280 $sql = "SELECT l.rowid, l.fk_commande,";
2281 $sql .= " c.ref_client, c.date_livraison as delivery_date";
2282 $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
2283 $sql .= " WHERE c.rowid = l.fk_commande";
2284 $resql = $db->query($sql);
2285 if ($resql) {
2286 $i = 0;
2287 $num = $db->num_rows($resql);
2288
2289 if ($num) {
2290 while ($i < $num) {
2291 $obj = $db->fetch_object($resql);
2292
2293 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)";
2294 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2295 $resql2 = $db->query($sql);
2296
2297 if ($resql2) {
2298 $delivery_date = $db->jdate($obj->delivery_date);
2299
2300 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2301 $sqlu .= " ref_client = '".$db->escape($obj->ref_client)."'";
2302 $sqlu .= ", date_livraison = '".$db->idate($delivery_date)."'";
2303 $sqlu .= " WHERE rowid = ".((int) $obj->rowid);
2304 $resql3 = $db->query($sqlu);
2305 if (!$resql3) {
2306 $error++;
2307 dol_print_error($db);
2308 }
2309 } else {
2310 $error++;
2311 dol_print_error($db);
2312 }
2313 print '. ';
2314 $i++;
2315 }
2316 }
2317
2318 if ($error == 0) {
2319 $db->commit();
2320 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
2321 print $langs->trans('FieldRenamed')."<br>\n";
2322 $db->query($sql);
2323 } else {
2324 $db->rollback();
2325 }
2326 } else {
2327 dol_print_error($db);
2328 $db->rollback();
2329 }
2330 } else {
2331 print $langs->trans('AlreadyDone')."<br>\n";
2332 }
2333 print '</td></tr>';
2334}
2335
2344function migrate_detail_livraison($db, $langs, $conf)
2345{
2346 dolibarr_install_syslog("upgrade2::migrate_detail_livraison");
2347
2348 print '<tr><td colspan="4">';
2349
2350 print '<br>';
2351 print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n";
2352
2353 // This is done if field fk_commande_ligne exists.
2354 // If not this means migration was already done.
2355 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne");
2356 $obj = $db->fetch_object($result);
2357 if ($obj) {
2358 $error = 0;
2359
2360 $db->begin();
2361
2362 $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2363 $sql .= ", ld.fk_livraison";
2364 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
2365 $sql .= " WHERE ld.fk_commande_ligne = cd.rowid";
2366 $resql = $db->query($sql);
2367 if ($resql) {
2368 $i = 0;
2369 $num = $db->num_rows($resql);
2370
2371 if ($num) {
2372 while ($i < $num) {
2373 $obj = $db->fetch_object($resql);
2374
2375 $sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET";
2376 $sql .= " fk_product = ".((int) $obj->fk_product);
2377 $sql .= ",description = '".$db->escape($obj->description)."'";
2378 $sql .= ",subprice = ".price2num($obj->subprice);
2379 $sql .= ",total_ht = ".price2num($obj->total_ht);
2380 $sql .= " WHERE fk_commande_ligne = ".((int) $obj->rowid);
2381 $resql2 = $db->query($sql);
2382
2383 if ($resql2) {
2384 $sql = "SELECT total_ht";
2385 $sql .= " FROM ".MAIN_DB_PREFIX."livraison";
2386 $sql .= " WHERE rowid = ".((int) $obj->fk_livraison);
2387 $resql3 = $db->query($sql);
2388
2389 if ($resql3) {
2390 $obju = $db->fetch_object($resql3);
2391 $total_ht = $obju->total_ht + $obj->total_ht;
2392
2393 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2394 $sqlu .= " total_ht = ".price2num($total_ht, 'MT');
2395 $sqlu .= " WHERE rowid = ".((int) $obj->fk_livraison);
2396 $resql4 = $db->query($sqlu);
2397 if (!$resql4) {
2398 $error++;
2399 dol_print_error($db);
2400 }
2401 } else {
2402 $error++;
2403 dol_print_error($db);
2404 }
2405 } else {
2406 $error++;
2407 dol_print_error($db);
2408 }
2409 print '. ';
2410 $i++;
2411 }
2412 }
2413
2414 if ($error == 0) {
2415 $db->commit();
2416 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2417 print $langs->trans('FieldRenamed')."<br>\n";
2418 $db->query($sql);
2419 } else {
2420 $db->rollback();
2421 }
2422 } else {
2423 dol_print_error($db);
2424 $db->rollback();
2425 }
2426 } else {
2427 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line");
2428 $obj = $db->fetch_object($result);
2429 if (!$obj) {
2430 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2431 $db->query($sql);
2432 }
2433 print $langs->trans('AlreadyDone')."<br>\n";
2434 }
2435 print '</td></tr>';
2436}
2437
2446function migrate_stocks($db, $langs, $conf)
2447{
2448 dolibarr_install_syslog("upgrade2::migrate_stocks");
2449
2450 print '<tr><td colspan="4">';
2451
2452 print '<br>';
2453 print '<b>'.$langs->trans('MigrationStockDetail')."</b><br>\n";
2454
2455 $error = 0;
2456
2457 $db->begin();
2458
2459 $sql = "SELECT SUM(reel) as total, fk_product";
2460 $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
2461 $sql .= " GROUP BY fk_product";
2462 $resql = $db->query($sql);
2463 if ($resql) {
2464 $i = 0;
2465 $num = $db->num_rows($resql);
2466
2467 if ($num) {
2468 while ($i < $num) {
2469 $obj = $db->fetch_object($resql);
2470
2471 $sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
2472 $sql .= " stock = ".price2num($obj->total, 'MS');
2473 $sql .= " WHERE rowid = ".((int) $obj->fk_product);
2474
2475 $resql2 = $db->query($sql);
2476 if ($resql2) {
2477 } else {
2478 $error++;
2479 dol_print_error($db);
2480 }
2481 print '. ';
2482 $i++;
2483 }
2484 }
2485
2486 if ($error == 0) {
2487 $db->commit();
2488 } else {
2489 $db->rollback();
2490 }
2491 } else {
2492 dol_print_error($db);
2493 $db->rollback();
2494 }
2495
2496 print '</td></tr>';
2497}
2498
2508function migrate_menus($db, $langs, $conf)
2509{
2510 dolibarr_install_syslog("upgrade2::migrate_menus");
2511
2512 print '<tr><td colspan="4">';
2513
2514 print '<br>';
2515 print '<b>'.$langs->trans('MigrationMenusDetail')."</b><br>\n";
2516
2517 $error = 0;
2518
2519 if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) {
2520 $db->begin();
2521
2522 $sql = "SELECT m.rowid, mc.action";
2523 $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m";
2524 $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2525 $sql .= " AND m.enabled = '1'";
2526 $resql = $db->query($sql);
2527 if ($resql) {
2528 $i = 0;
2529 $num = $db->num_rows($resql);
2530 if ($num) {
2531 while ($i < $num) {
2532 $obj = $db->fetch_object($resql);
2533
2534 $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
2535 $sql .= " enabled = '".$db->escape($obj->action)."'";
2536 $sql .= " WHERE rowid = ".((int) $obj->rowid);
2537 $sql .= " AND enabled = '1'";
2538
2539 $resql2 = $db->query($sql);
2540 if ($resql2) {
2541 } else {
2542 $error++;
2543 dol_print_error($db);
2544 }
2545 print '. ';
2546 $i++;
2547 }
2548 }
2549
2550 if ($error == 0) {
2551 $db->commit();
2552 } else {
2553 $db->rollback();
2554 }
2555 } else {
2556 dol_print_error($db);
2557 $db->rollback();
2558 }
2559 } else {
2560 print $langs->trans('AlreadyDone')."<br>\n";
2561 }
2562
2563 print '</td></tr>';
2564}
2565
2575function migrate_commande_deliveryaddress($db, $langs, $conf)
2576{
2577 dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress");
2578
2579 print '<tr><td colspan="4">';
2580
2581 print '<br>';
2582 print '<b>'.$langs->trans('MigrationDeliveryAddress')."</b><br>\n";
2583
2584 $error = 0;
2585
2586 if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) {
2587 $db->begin();
2588
2589 $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition";
2590 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
2591 $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce";
2592 $sql .= " WHERE c.rowid = ce.fk_commande";
2593 $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2594
2595 $resql = $db->query($sql);
2596 if ($resql) {
2597 $i = 0;
2598 $num = $db->num_rows($resql);
2599
2600 if ($num) {
2601 while ($i < $num) {
2602 $obj = $db->fetch_object($resql);
2603
2604 $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
2605 $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'";
2606 $sql .= " WHERE rowid = ".((int) $obj->fk_expedition);
2607
2608 $resql2 = $db->query($sql);
2609 if (!$resql2) {
2610 $error++;
2611 dol_print_error($db);
2612 }
2613 print '. ';
2614 $i++;
2615 }
2616 } else {
2617 print $langs->trans('AlreadyDone')."<br>\n";
2618 }
2619
2620 if ($error == 0) {
2621 $db->commit();
2622 } else {
2623 $db->rollback();
2624 }
2625 } else {
2626 dol_print_error($db);
2627 $db->rollback();
2628 }
2629 } else {
2630 print $langs->trans('AlreadyDone')."<br>\n";
2631 }
2632
2633 print '</td></tr>';
2634}
2635
2645function migrate_restore_missing_links($db, $langs, $conf)
2646{
2647 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
2648
2649 if (($db->type == 'mysql' || $db->type == 'mysqli')) {
2650 if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
2651 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2652 return 0;
2653 }
2654 }
2655 print '<tr><td colspan="4">';
2656
2657 print '<br>';
2658 print '<b>'.$langs->trans('MigrationFixData')."</b> (1)<br>\n";
2659
2660 $error = 0;
2661
2662
2663 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1.
2664 $table1 = 'facturedet';
2665 $field1 = 'fk_remise_except';
2666 $table2 = 'societe_remise_except';
2667 $field2 = 'fk_facture_line';
2668
2669 $db->begin();
2670
2671 $sql = "SELECT t1.rowid, t1.".$field1." as field";
2672 $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1";
2673 $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN";
2674 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2";
2675 $sql .= " WHERE t1.rowid = t2.".$field2.")";
2676
2677 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1");
2678 $resql = $db->query($sql);
2679 if ($resql) {
2680 $i = 0;
2681 $num = $db->num_rows($resql);
2682
2683 if ($num) {
2684 while ($i < $num) {
2685 $obj = $db->fetch_object($resql);
2686
2687 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2688
2689 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2690 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2691 $sql .= " WHERE rowid = ".((int) $obj->field);
2692
2693 $resql2 = $db->query($sql);
2694 if (!$resql2) {
2695 $error++;
2696 dol_print_error($db);
2697 }
2698 //print '. ';
2699 $i++;
2700 }
2701 } else {
2702 print $langs->trans('AlreadyDone')."<br>\n";
2703 }
2704
2705 if ($error == 0) {
2706 $db->commit();
2707 } else {
2708 $db->rollback();
2709 }
2710 } else {
2711 dol_print_error($db);
2712 $db->rollback();
2713 }
2714
2715 print '</td></tr>';
2716
2717
2718 print '<tr><td colspan="4">';
2719
2720 print '<br>';
2721 print '<b>'.$langs->trans('MigrationFixData')."</b> (2)<br>\n";
2722
2723 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2.
2724 $table2 = 'facturedet';
2725 $field2 = 'fk_remise_except';
2726 $table1 = 'societe_remise_except';
2727 $field1 = 'fk_facture_line';
2728
2729 $db->begin();
2730
2731 $sql = "SELECT t1.rowid, t1.".$field1." as field";
2732 $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1";
2733 $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN";
2734 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2";
2735 $sql .= " WHERE t1.rowid = t2.".$field2.")";
2736
2737 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2");
2738 $resql = $db->query($sql);
2739 if ($resql) {
2740 $i = 0;
2741 $num = $db->num_rows($resql);
2742
2743 if ($num) {
2744 while ($i < $num) {
2745 $obj = $db->fetch_object($resql);
2746
2747 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2748
2749 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2750 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2751 $sql .= " WHERE rowid = ".((int) $obj->field);
2752
2753 $resql2 = $db->query($sql);
2754 if (!$resql2) {
2755 $error++;
2756 dol_print_error($db);
2757 }
2758 //print '. ';
2759 $i++;
2760 }
2761 } else {
2762 print $langs->trans('AlreadyDone')."<br>\n";
2763 }
2764
2765 if ($error == 0) {
2766 $db->commit();
2767 } else {
2768 $db->rollback();
2769 }
2770 } else {
2771 dol_print_error($db);
2772 $db->rollback();
2773 }
2774
2775 print '</td></tr>';
2776
2777 return ($error ? -1 : 1);
2778}
2779
2788function migrate_project_user_resp($db, $langs, $conf)
2789{
2790 dolibarr_install_syslog("upgrade2::migrate_project_user_resp");
2791
2792 print '<tr><td colspan="4">';
2793
2794 print '<br>';
2795 print '<b>'.$langs->trans('MigrationProjectUserResp')."</b><br>\n";
2796
2797 $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp");
2798 $obj = $db->fetch_object($result);
2799 if ($obj) {
2800 $error = 0;
2801
2802 $db->begin();
2803
2804 $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet";
2805 $resql = $db->query($sql);
2806 if ($resql) {
2807 $i = 0;
2808 $num = $db->num_rows($resql);
2809
2810 if ($num) {
2811 while ($i < $num) {
2812 $obj = $db->fetch_object($resql);
2813
2814 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2815 $sql2 .= "datecreate";
2816 $sql2 .= ", statut";
2817 $sql2 .= ", element_id";
2818 $sql2 .= ", fk_c_type_contact";
2819 $sql2 .= ", fk_socpeople";
2820 $sql2 .= ") VALUES (";
2821 $sql2 .= "'".$db->idate(dol_now())."'";
2822 $sql2 .= ", '4'";
2823 $sql2 .= ", ".$obj->rowid;
2824 $sql2 .= ", '160'";
2825 $sql2 .= ", ".$obj->fk_user_resp;
2826 $sql2 .= ")";
2827
2828 if ($obj->fk_user_resp > 0) {
2829 $resql2 = $db->query($sql2);
2830 if (!$resql2) {
2831 $error++;
2832 dol_print_error($db);
2833 }
2834 }
2835 print '. ';
2836
2837 $i++;
2838 }
2839 }
2840
2841 if ($error == 0) {
2842 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp";
2843 if ($db->query($sqlDrop)) {
2844 $db->commit();
2845 } else {
2846 $db->rollback();
2847 }
2848 } else {
2849 $db->rollback();
2850 }
2851 } else {
2852 dol_print_error($db);
2853 $db->rollback();
2854 }
2855 } else {
2856 print $langs->trans('AlreadyDone')."<br>\n";
2857 }
2858 print '</td></tr>';
2859}
2860
2869function migrate_project_task_actors($db, $langs, $conf)
2870{
2871 dolibarr_install_syslog("upgrade2::migrate_project_task_actors");
2872
2873 print '<tr><td colspan="4">';
2874
2875 print '<br>';
2876 print '<b>'.$langs->trans('MigrationProjectTaskActors')."</b><br>\n";
2877
2878 if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) {
2879 $error = 0;
2880
2881 $db->begin();
2882
2883 $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors";
2884 $resql = $db->query($sql);
2885 if ($resql) {
2886 $i = 0;
2887 $num = $db->num_rows($resql);
2888
2889 if ($num) {
2890 while ($i < $num) {
2891 $obj = $db->fetch_object($resql);
2892
2893 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2894 $sql2 .= "datecreate";
2895 $sql2 .= ", statut";
2896 $sql2 .= ", element_id";
2897 $sql2 .= ", fk_c_type_contact";
2898 $sql2 .= ", fk_socpeople";
2899 $sql2 .= ") VALUES (";
2900 $sql2 .= "'".$db->idate(dol_now())."'";
2901 $sql2 .= ", '4'";
2902 $sql2 .= ", ".$obj->fk_project_task;
2903 $sql2 .= ", '180'";
2904 $sql2 .= ", ".$obj->fk_user;
2905 $sql2 .= ")";
2906
2907 $resql2 = $db->query($sql2);
2908
2909 if (!$resql2) {
2910 $error++;
2911 dol_print_error($db);
2912 }
2913 print '. ';
2914 $i++;
2915 }
2916 }
2917
2918 if ($error == 0) {
2919 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors";
2920 if ($db->query($sqlDrop)) {
2921 $db->commit();
2922 } else {
2923 $db->rollback();
2924 }
2925 } else {
2926 $db->rollback();
2927 }
2928 } else {
2929 dol_print_error($db);
2930 $db->rollback();
2931 }
2932 } else {
2933 print $langs->trans('AlreadyDone')."<br>\n";
2934 }
2935 print '</td></tr>';
2936}
2937
2951function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
2952{
2953 print '<tr><td colspan="4">';
2954
2955 print '<br>';
2956 print '<b>'.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."</b><br>\n";
2957
2958 $error = 0;
2959
2960 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2961 dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table);
2962
2963 $db->begin();
2964
2965 $sqlSelect = "SELECT ".$fk_source.", ".$fk_target;
2966 $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table;
2967
2968 $resql = $db->query($sqlSelect);
2969 if ($resql) {
2970 $i = 0;
2971 $num = $db->num_rows($resql);
2972
2973 if ($num) {
2974 while ($i < $num) {
2975 $obj = $db->fetch_object($resql);
2976
2977 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
2978 $sqlInsert .= "fk_source";
2979 $sqlInsert .= ", sourcetype";
2980 $sqlInsert .= ", fk_target";
2981 $sqlInsert .= ", targettype";
2982 $sqlInsert .= ") VALUES (";
2983 $sqlInsert .= $obj->$fk_source;
2984 $sqlInsert .= ", '".$db->escape($sourcetype)."'";
2985 $sqlInsert .= ", ".$obj->$fk_target;
2986 $sqlInsert .= ", '".$db->escape($targettype)."'";
2987 $sqlInsert .= ")";
2988
2989 $result = $db->query($sqlInsert);
2990 if (!$result) {
2991 $error++;
2992 dol_print_error($db);
2993 }
2994 print '. ';
2995 $i++;
2996 }
2997 } else {
2998 print $langs->trans('AlreadyDone')."<br>\n";
2999 }
3000
3001 if ($error == 0) {
3002 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$table;
3003 if ($db->query($sqlDrop)) {
3004 $db->commit();
3005 } else {
3006 $db->rollback();
3007 }
3008 } else {
3009 $db->rollback();
3010 }
3011 } else {
3012 dol_print_error($db);
3013 $db->rollback();
3014 }
3015 } else {
3016 print $langs->trans('AlreadyDone')."<br>\n";
3017 }
3018
3019 print '</td></tr>';
3020}
3021
3030function migrate_element_time($db, $langs, $conf)
3031{
3032 dolibarr_install_syslog("upgrade2::migrate_element_time");
3033
3034 print '<tr><td colspan="4">';
3035
3036 print '<br>';
3037 print '<b>'.$langs->trans('MigrationProjectTaskTime')."</b><br>\n";
3038
3039 $error = 0;
3040
3041 $db->begin();
3042
3043 $sql = "SELECT rowid, fk_element, element_duration";
3044 $sql .= " FROM ".MAIN_DB_PREFIX."element_time";
3045 $resql = $db->query($sql);
3046 if ($resql) {
3047 $i = 0;
3048 $num = $db->num_rows($resql);
3049
3050 if ($num) {
3051 $totaltime = array();
3052 $oldtime = 0;
3053
3054 while ($i < $num) {
3055 $obj = $db->fetch_object($resql);
3056
3057 if ($obj->element_duration > 0) {
3058 // convert to second
3059 // only for int time and float time ex: 1.75 for 1h45
3060 list($hour, $min) = explode('.', $obj->element_duration);
3061 $hour = (int) $hour * 60 * 60;
3062 $min = (int) ((float) ('.'.$min)) * 3600;
3063 $newtime = $hour + $min;
3064
3065 $sql2 = "UPDATE ".MAIN_DB_PREFIX."element_time SET";
3066 $sql2 .= " element_duration = ".((int) $newtime);
3067 $sql2 .= " WHERE rowid = ".((int) $obj->rowid);
3068
3069 $resql2 = $db->query($sql2);
3070 if (!$resql2) {
3071 $error++;
3072 dol_print_error($db);
3073 }
3074 print '. ';
3075 $oldtime++;
3076 if (!empty($totaltime[$obj->fk_element])) {
3077 $totaltime[$obj->fk_element] += $newtime;
3078 } else {
3079 $totaltime[$obj->fk_element] = $newtime;
3080 }
3081 } else {
3082 if (!empty($totaltime[$obj->fk_element])) {
3083 $totaltime[$obj->fk_element] += $obj->element_duration;
3084 } else {
3085 $totaltime[$obj->fk_element] = $obj->element_duration;
3086 }
3087 }
3088
3089 $i++;
3090 }
3091
3092 if ($error == 0) {
3093 if ($oldtime > 0) {
3094 foreach ($totaltime as $taskid => $total_duration) {
3095 $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
3096 $sql .= " duration_effective = ".((int) $total_duration);
3097 $sql .= " WHERE rowid = ".((int) $taskid);
3098
3099 $resql = $db->query($sql);
3100 if (!$resql) {
3101 $error++;
3102 dol_print_error($db);
3103 }
3104 }
3105 } else {
3106 print $langs->trans('AlreadyDone')."<br>\n";
3107 }
3108 } else {
3109 dol_print_error($db);
3110 }
3111 } else {
3112 print $langs->trans('AlreadyDone')."<br>\n";
3113 }
3114 } else {
3115 dol_print_error($db);
3116 }
3117
3118 if ($error == 0) {
3119 $db->commit();
3120 } else {
3121 $db->rollback();
3122 }
3123
3124 print '</td></tr>';
3125}
3126
3135function migrate_customerorder_shipping($db, $langs, $conf)
3136{
3137 print '<tr><td colspan="4">';
3138
3139 print '<br>';
3140 print '<b>'.$langs->trans('MigrationCustomerOrderShipping')."</b><br>\n";
3141
3142 $error = 0;
3143
3144 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer");
3145 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery");
3146 $obj1 = $db->fetch_object($result1);
3147 $obj2 = $db->fetch_object($result2);
3148 if (!$obj1 && !$obj2) {
3149 dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping");
3150
3151 $db->begin();
3152
3153 $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3154 $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3155
3156 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3157 $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3158 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e";
3159 $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el";
3160 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3161 $sqlSelect .= " WHERE e.rowid = el.fk_target";
3162 $sqlSelect .= " AND el.targettype = 'shipping'";
3163
3164 $resql = $db->query($sqlSelect);
3165 if ($resql) {
3166 $i = 0;
3167 $num = $db->num_rows($resql);
3168
3169 if ($num) {
3170 while ($i < $num) {
3171 $obj = $db->fetch_object($resql);
3172
3173 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
3174 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'";
3175 $sqlUpdate .= ", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date : 'null')."'";
3176 $sqlUpdate .= " WHERE rowid = ".((int) $obj->shipping_id);
3177
3178 $result = $db->query($sqlUpdate);
3179 if (!$result) {
3180 $error++;
3181 dol_print_error($db);
3182 }
3183 print '. ';
3184 $i++;
3185 }
3186 } else {
3187 print $langs->trans('AlreadyDone')."<br>\n";
3188 }
3189
3190 if ($error == 0) {
3191 $db->commit();
3192 } else {
3193 dol_print_error($db);
3194 $db->rollback();
3195 }
3196 } else {
3197 dol_print_error($db);
3198 $db->rollback();
3199 }
3200 } else {
3201 dol_print_error($db);
3202 $db->rollback();
3203 }
3204 } else {
3205 print $langs->trans('AlreadyDone')."<br>\n";
3206 }
3207
3208 print '</td></tr>';
3209}
3210
3219function migrate_shipping_delivery($db, $langs, $conf)
3220{
3221 print '<tr><td colspan="4">';
3222
3223 print '<br>';
3224 print '<b>'.$langs->trans('MigrationShippingDelivery')."</b><br>\n";
3225
3226 $error = 0;
3227
3228 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition");
3229 $obj = $db->fetch_object($result);
3230 if ($obj) {
3231 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery");
3232
3233 $db->begin();
3234
3235 $sqlSelect = "SELECT rowid, fk_expedition";
3236 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison";
3237 $sqlSelect .= " WHERE fk_expedition is not null";
3238
3239 $resql = $db->query($sqlSelect);
3240 if ($resql) {
3241 $i = 0;
3242 $num = $db->num_rows($resql);
3243
3244 if ($num) {
3245 while ($i < $num) {
3246 $obj = $db->fetch_object($resql);
3247
3248 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
3249 $sqlInsert .= "fk_source";
3250 $sqlInsert .= ", sourcetype";
3251 $sqlInsert .= ", fk_target";
3252 $sqlInsert .= ", targettype";
3253 $sqlInsert .= ") VALUES (";
3254 $sqlInsert .= $obj->fk_expedition;
3255 $sqlInsert .= ", 'shipping'";
3256 $sqlInsert .= ", ".$obj->rowid;
3257 $sqlInsert .= ", 'delivery'";
3258 $sqlInsert .= ")";
3259
3260 $result = $db->query($sqlInsert);
3261 if ($result) {
3262 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL";
3263 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3264
3265 $result = $db->query($sqlUpdate);
3266 if (!$result) {
3267 $error++;
3268 dol_print_error($db);
3269 }
3270 print '. ';
3271 } else {
3272 $error++;
3273 dol_print_error($db);
3274 }
3275 $i++;
3276 }
3277 } else {
3278 print $langs->trans('AlreadyDone')."<br>\n";
3279 }
3280
3281 if ($error == 0) {
3282 $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3283 $db->query($sqlDelete);
3284
3285 $db->commit();
3286
3287 // DDL commands must not be inside a transaction
3288 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition";
3289 $db->query($sqlDrop);
3290 } else {
3291 dol_print_error($db);
3292 $db->rollback();
3293 }
3294 } else {
3295 dol_print_error($db);
3296 $db->rollback();
3297 }
3298 } else {
3299 print $langs->trans('AlreadyDone')."<br>\n";
3300 }
3301
3302 print '</td></tr>';
3303}
3304
3314function migrate_shipping_delivery2($db, $langs, $conf)
3315{
3316 print '<tr><td colspan="4">';
3317
3318 print '<br>';
3319 print '<b>'.$langs->trans('MigrationShippingDelivery2')."</b><br>\n";
3320
3321 $error = 0;
3322
3323 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2");
3324
3325 $db->begin();
3326
3327 $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3328 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,";
3329 $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,";
3330 $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e";
3331 $sqlSelect .= " WHERE l.rowid = el.fk_target";
3332 $sqlSelect .= " AND el.targettype = 'delivery'";
3333 $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3334 $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null
3335 // Add condition to know if we never migrate this record
3336 $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")";
3337 $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")";
3338
3339 $resql = $db->query($sqlSelect);
3340 if ($resql) {
3341 $i = 0;
3342 $num = $db->num_rows($resql);
3343
3344 if ($num) {
3345 while ($i < $num) {
3346 $obj = $db->fetch_object($resql);
3347
3348 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
3349 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',";
3350 $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null');
3351 $sqlUpdate .= " WHERE rowid = ".((int) $obj->delivery_id);
3352
3353 $result = $db->query($sqlUpdate);
3354 if (!$result) {
3355 $error++;
3356 dol_print_error($db);
3357 }
3358 print '. ';
3359 $i++;
3360 }
3361 } else {
3362 print $langs->trans('AlreadyDone')."<br>\n";
3363 }
3364
3365 if ($error == 0) {
3366 $db->commit();
3367 } else {
3368 dol_print_error($db);
3369 $db->rollback();
3370 }
3371 } else {
3372 dol_print_error($db);
3373 $db->rollback();
3374 }
3375
3376 print '</td></tr>';
3377}
3378
3387function migrate_actioncomm_element($db, $langs, $conf)
3388{
3389 print '<tr><td colspan="4">';
3390
3391 print '<br>';
3392 print '<b>'.$langs->trans('MigrationActioncommElement')."</b><br>\n";
3393
3394 $elements = array(
3395 'propal' => 'propalrowid',
3396 'order' => 'fk_commande',
3397 'invoice' => 'fk_facture',
3398 'contract' => 'fk_contract',
3399 'order_supplier' => 'fk_supplier_order',
3400 'invoice_supplier' => 'fk_supplier_invoice'
3401 );
3402
3403 foreach ($elements as $type => $field) {
3404 $result = $db->DDLDescTable(MAIN_DB_PREFIX."actioncomm", $field);
3405 $obj = $db->fetch_object($result);
3406 if ($obj) {
3407 dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=".$field);
3408
3409 $db->begin();
3410
3411 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ";
3412 $sql .= "fk_element = ".$db->sanitize($field).", elementtype = '".$db->escape($type)."'";
3413 $sql .= " WHERE ".$db->sanitize($field)." IS NOT NULL";
3414 $sql .= " AND fk_element IS NULL";
3415 $sql .= " AND elementtype IS NULL";
3416
3417 $resql = $db->query($sql);
3418 if ($resql) {
3419 $db->commit();
3420
3421 // DDL commands must not be inside a transaction
3422 // We will drop at next version because a migrate should be runnable several times if it fails.
3423 //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
3424 //$db->query($sqlDrop);
3425 //print '. ';
3426 } else {
3427 dol_print_error($db);
3428 $db->rollback();
3429 }
3430 } else {
3431 print $langs->trans('AlreadyDone')."<br>\n";
3432 }
3433 }
3434
3435 print '</td></tr>';
3436}
3437
3446function migrate_mode_reglement($db, $langs, $conf)
3447{
3448 print '<tr><td colspan="4">';
3449
3450 print '<br>';
3451 print '<b>'.$langs->trans('MigrationPaymentMode')."</b><br>\n";
3452
3453 $elements = array(
3454 'old_id' => array(5, 8, 9, 10, 11),
3455 'new_id' => array(50, 51, 52, 53, 54),
3456 'code' => array('VAD', 'TRA', 'LCR', 'FAC', 'PRO'),
3457 'tables' => array('commande_fournisseur', 'commande', 'facture_rec', 'facture', 'propal')
3458 );
3459 $count = 0;
3460
3461 foreach ($elements['old_id'] as $key => $old_id) {
3462 $error = 0;
3463
3464 dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);
3465
3466 $sqlSelect = "SELECT id";
3467 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."c_paiement";
3468 $sqlSelect .= " WHERE id = ".((int) $old_id);
3469 $sqlSelect .= " AND code = '".$db->escape($elements['code'][$key])."'";
3470
3471 $resql = $db->query($sqlSelect);
3472 if ($resql) {
3473 $num = $db->num_rows($resql);
3474 if ($num) {
3475 $count++;
3476
3477 $db->begin();
3478
3479 $sqla = "UPDATE ".MAIN_DB_PREFIX."paiement SET";
3480 $sqla .= " fk_paiement = ".((int) $elements['new_id'][$key]);
3481 $sqla .= " WHERE fk_paiement = ".((int) $old_id);
3482 $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])."')";
3483 $resqla = $db->query($sqla);
3484
3485 $sql = "UPDATE ".MAIN_DB_PREFIX."c_paiement SET";
3486 $sql .= " id = ".((int) $elements['new_id'][$key]);
3487 $sql .= " WHERE id = ".((int) $old_id);
3488 $sql .= " AND code = '".$db->escape($elements['code'][$key])."'";
3489 $resql = $db->query($sql);
3490
3491 if ($resqla && $resql) {
3492 foreach ($elements['tables'] as $table) {
3493 $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
3494 $sql .= "fk_mode_reglement = ".((int) $elements['new_id'][$key]);
3495 $sql .= " WHERE fk_mode_reglement = ".((int) $old_id);
3496
3497 $resql = $db->query($sql);
3498 if (!$resql) {
3499 dol_print_error($db);
3500 $error++;
3501 }
3502 print '. ';
3503 }
3504
3505 if (!$error) {
3506 $db->commit();
3507 } else {
3508 dol_print_error($db);
3509 $db->rollback();
3510 }
3511 } else {
3512 dol_print_error($db);
3513 $db->rollback();
3514 }
3515 }
3516 }
3517 }
3518
3519 if ($count == 0) {
3520 print $langs->trans('AlreadyDone')."<br>\n";
3521 }
3522
3523
3524 print '</td></tr>';
3525}
3526
3527
3536function migrate_clean_association($db, $langs, $conf)
3537{
3538 $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association");
3539 if ($result) { // result defined for version 3.2 or -
3540 $obj = $db->fetch_object($result);
3541 if ($obj) { // It table categorie_association exists
3542 $couples = array();
3543 $children = array();
3544 $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
3545 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3546 dolibarr_install_syslog("upgrade: search duplicate");
3547 $resql = $db->query($sql);
3548 if ($resql) {
3549 $num = $db->num_rows($resql);
3550 while ($obj = $db->fetch_object($resql)) {
3551 if (!isset($children[$obj->fk_categorie_fille])) { // Only one record as child (a child has only on parent).
3552 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3553 $children[$obj->fk_categorie_fille] = 1; // Set record for this child
3554 $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere' => $obj->fk_categorie_mere, 'fille' => $obj->fk_categorie_fille);
3555 }
3556 }
3557 }
3558
3559 dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
3560
3561 // If there is duplicates couples or child with two parents
3562 if (count($couples) > 0 && $num > count($couples)) {
3563 $error = 0;
3564
3565 $db->begin();
3566
3567 // We delete all
3568 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
3569 dolibarr_install_syslog("upgrade: delete association");
3570 $resqld = $db->query($sql);
3571 if ($resqld) {
3572 // And we insert only each record once
3573 foreach ($couples as $key => $val) {
3574 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
3575 $sql .= " VALUES(".((int) $val['mere']).", ".((int) $val['fille']).")";
3576 dolibarr_install_syslog("upgrade: insert association");
3577 $resqli = $db->query($sql);
3578 if (!$resqli) {
3579 $error++;
3580 }
3581 }
3582 }
3583
3584 if (!$error) {
3585 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3586 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
3587 $db->commit();
3588 } else {
3589 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3590 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").'</td></tr>';
3591 $db->rollback();
3592 }
3593 }
3594 } else {
3595 print '<tr><td>'.$langs->trans("Error").'</td>';
3596 print '<td class="right"><div class="error">'.$db->lasterror().'</div></td></tr>';
3597 }
3598 }
3599 }
3600}
3601
3602
3611function migrate_categorie_association($db, $langs, $conf)
3612{
3613 print '<tr><td colspan="4">';
3614
3615 print '<br>';
3616 print '<b>'.$langs->trans('MigrationCategorieAssociation')."</b><br>\n";
3617
3618 $error = 0;
3619
3620 if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association")) {
3621 dolibarr_install_syslog("upgrade2::migrate_categorie_association");
3622
3623 $db->begin();
3624
3625 $sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
3626 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3627
3628 $resql = $db->query($sqlSelect);
3629 if ($resql) {
3630 $i = 0;
3631 $num = $db->num_rows($resql);
3632
3633 if ($num) {
3634 while ($i < $num) {
3635 $obj = $db->fetch_object($resql);
3636
3637 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
3638 $sqlUpdate .= "fk_parent = ".((int) $obj->fk_categorie_mere);
3639 $sqlUpdate .= " WHERE rowid = ".((int) $obj->fk_categorie_fille);
3640
3641 $result = $db->query($sqlUpdate);
3642 if (!$result) {
3643 $error++;
3644 dol_print_error($db);
3645 }
3646 print '. ';
3647 $i++;
3648 }
3649 } else {
3650 print $langs->trans('AlreadyDone')."<br>\n";
3651 }
3652
3653 if (!$error) {
3654 $db->commit();
3655 } else {
3656 $db->rollback();
3657 }
3658 } else {
3659 dol_print_error($db);
3660 $db->rollback();
3661 }
3662 } else {
3663 print $langs->trans('AlreadyDone')."<br>\n";
3664 }
3665
3666 print '</td></tr>';
3667}
3668
3677function migrate_event_assignement($db, $langs, $conf)
3678{
3679 print '<tr><td colspan="4">';
3680
3681 print '<br>';
3682 print '<b>'.$langs->trans('MigrationEvents')."</b><br>\n";
3683
3684 $error = 0;
3685
3686 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3687
3688 $db->begin();
3689
3690 $sqlSelect = "SELECT a.id, a.fk_user_action";
3691 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3692 $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";
3693 $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')";
3694 $sqlSelect .= " ORDER BY a.id";
3695 //print $sqlSelect;
3696
3697 $resql = $db->query($sqlSelect);
3698 if ($resql) {
3699 $i = 0;
3700 $num = $db->num_rows($resql);
3701
3702 if ($num) {
3703 while ($i < $num) {
3704 $obj = $db->fetch_object($resql);
3705
3706 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3707 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'user', ".((int) $obj->fk_user_action).")";
3708
3709 $result = $db->query($sqlUpdate);
3710 if (!$result) {
3711 $error++;
3712 dol_print_error($db);
3713 }
3714 print '. ';
3715 $i++;
3716 }
3717 } else {
3718 print $langs->trans('AlreadyDone')."<br>\n";
3719 }
3720
3721 if (!$error) {
3722 $db->commit();
3723 } else {
3724 $db->rollback();
3725 }
3726 } else {
3727 dol_print_error($db);
3728 $db->rollback();
3729 }
3730
3731
3732 print '</td></tr>';
3733}
3734
3743function migrate_event_assignement_contact($db, $langs, $conf)
3744{
3745 print '<tr><td colspan="4">';
3746
3747 print '<br>';
3748 print '<b>'.$langs->trans('MigrationEventsContact')."</b><br>\n";
3749
3750 $error = 0;
3751
3752 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3753
3754 $db->begin();
3755
3756 $sqlSelect = "SELECT a.id, a.fk_contact";
3757 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3758 $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";
3759 $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')";
3760 $sqlSelect .= " ORDER BY a.id";
3761 //print $sqlSelect;
3762
3763 $resql = $db->query($sqlSelect);
3764 if ($resql) {
3765 $i = 0;
3766 $num = $db->num_rows($resql);
3767
3768 if ($num) {
3769 while ($i < $num) {
3770 $obj = $db->fetch_object($resql);
3771
3772 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3773 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'socpeople', ".((int) $obj->fk_contact).")";
3774
3775 $result = $db->query($sqlUpdate);
3776 if (!$result) {
3777 $error++;
3778 dol_print_error($db);
3779 }
3780 print '. ';
3781 $i++;
3782 }
3783 } else {
3784 print $langs->trans('AlreadyDone')."<br>\n";
3785 }
3786
3787 if (!$error) {
3788 $db->commit();
3789 } else {
3790 $db->rollback();
3791 }
3792 } else {
3793 dol_print_error($db);
3794 $db->rollback();
3795 }
3796
3797
3798 print '</td></tr>';
3799}
3800
3801
3810function migrate_reset_blocked_log($db, $langs, $conf)
3811{
3812 global $user;
3813
3814 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
3815
3816 print '<tr><td colspan="4">';
3817
3818 print '<br>';
3819 print '<b>'.$langs->trans('MigrationResetBlockedLog')."</b><br>\n";
3820
3821 $error = 0;
3822
3823 dolibarr_install_syslog("upgrade2::migrate_reset_blocked_log");
3824
3825 $db->begin();
3826
3827 $sqlSelect = "SELECT DISTINCT entity";
3828 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."blockedlog";
3829
3830 //print $sqlSelect;
3831
3832 $resql = $db->query($sqlSelect);
3833 if ($resql) {
3834 $i = 0;
3835 $num = $db->num_rows($resql);
3836
3837 if ($num) {
3838 while ($i < $num) {
3839 $obj = $db->fetch_object($resql);
3840
3841 print 'Process entity '.$obj->entity;
3842
3843 $sqlSearch = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3844 $resqlSearch = $db->query($sqlSearch);
3845 if ($resqlSearch) {
3846 $objSearch = $db->fetch_object($resqlSearch);
3847 //var_dump($objSearch);
3848 if ($objSearch && $objSearch->nb == 0) {
3849 print ' - Record for entity must be reset...';
3850
3851 $sqlUpdate = "DELETE FROM ".MAIN_DB_PREFIX."blockedlog";
3852 $sqlUpdate .= " WHERE entity = ".((int) $obj->entity);
3853 $resqlUpdate = $db->query($sqlUpdate);
3854 if (!$resqlUpdate) {
3855 $error++;
3856 dol_print_error($db);
3857 } else {
3858 // Add set line
3859 $object = new stdClass();
3860 $object->id = 1;
3861 $object->element = 'module';
3862 $object->ref = 'systemevent';
3863 $object->entity = $obj->entity;
3864 $object->date = dol_now();
3865
3866 $b = new BlockedLog($db);
3867 $b->setObjectData($object, 'MODULE_SET', 0, $user, null);
3868
3869 $res = $b->create($user);
3870 if ($res <= 0) {
3871 $error++;
3872 }
3873 }
3874 } else {
3875 print ' - '.$langs->trans('AlreadyInV7').'<br>';
3876 }
3877 } else {
3878 dol_print_error($db);
3879 }
3880
3881 $i++;
3882 }
3883 } else {
3884 print $langs->trans('NothingToDo')."<br>\n";
3885 }
3886
3887 if (!$error) {
3888 $db->commit();
3889 } else {
3890 $db->rollback();
3891 }
3892 } else {
3893 dol_print_error($db);
3894 $db->rollback();
3895 }
3896
3897 print '</td></tr>';
3898}
3899
3900
3909function migrate_remise_entity($db, $langs, $conf)
3910{
3911 print '<tr><td colspan="4">';
3912
3913 print '<br>';
3914 print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\n";
3915
3916 $error = 0;
3917
3918 dolibarr_install_syslog("upgrade2::migrate_remise_entity");
3919
3920 $db->begin();
3921
3922 $sqlSelect = "SELECT sr.rowid, s.entity";
3923 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s";
3924 $sqlSelect .= " WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3925
3926 //print $sqlSelect;
3927
3928 $resql = $db->query($sqlSelect);
3929 if ($resql) {
3930 $i = 0;
3931 $num = $db->num_rows($resql);
3932
3933 if ($num) {
3934 while ($i < $num) {
3935 $obj = $db->fetch_object($resql);
3936
3937 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
3938 $sqlUpdate .= " entity = ".$obj->entity;
3939 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3940
3941 $result = $db->query($sqlUpdate);
3942 if (!$result) {
3943 $error++;
3944 dol_print_error($db);
3945 }
3946
3947 print '. ';
3948 $i++;
3949 }
3950 } else {
3951 print $langs->trans('AlreadyDone')."<br>\n";
3952 }
3953
3954 if (!$error) {
3955 $db->commit();
3956 } else {
3957 $db->rollback();
3958 }
3959 } else {
3960 dol_print_error($db);
3961 $db->rollback();
3962 }
3963
3964 print '</td></tr>';
3965}
3966
3975function migrate_remise_except_entity($db, $langs, $conf)
3976{
3977 print '<tr><td colspan="4">';
3978
3979 print '<br>';
3980 print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\n";
3981
3982 $error = 0;
3983
3984 dolibarr_install_syslog("upgrade2::migrate_remise_except_entity");
3985
3986 $db->begin();
3987
3988 $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3989 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
3990 //print $sqlSelect;
3991
3992 $resql = $db->query($sqlSelect);
3993 if ($resql) {
3994 $i = 0;
3995 $num = $db->num_rows($resql);
3996
3997 if ($num) {
3998 while ($i < $num) {
3999 $obj = $db->fetch_object($resql);
4000
4001 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
4002 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
4003
4004 $sqlSelect2 = "SELECT f.entity";
4005 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
4006 $sqlSelect2 .= " WHERE f.rowid = ".((int) $fk_facture);
4007 } elseif (!empty($obj->fk_facture_line)) {
4008 $sqlSelect2 = "SELECT f.entity";
4009 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
4010 $sqlSelect2 .= " WHERE fd.rowid = ".((int) $obj->fk_facture_line);
4011 $sqlSelect2 .= " AND fd.fk_facture = f.rowid";
4012 } else {
4013 $sqlSelect2 = "SELECT s.entity";
4014 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."societe as s";
4015 $sqlSelect2 .= " WHERE s.rowid = ".((int) $obj->fk_soc);
4016 }
4017
4018 $resql2 = $db->query($sqlSelect2);
4019 if ($resql2) {
4020 if ($db->num_rows($resql2) > 0) {
4021 $obj2 = $db->fetch_object($resql2);
4022
4023 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
4024 $sqlUpdate .= " entity = ".((int) $obj2->entity);
4025 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
4026
4027 $result = $db->query($sqlUpdate);
4028 if (!$result) {
4029 $error++;
4030 dol_print_error($db);
4031 }
4032 }
4033 } else {
4034 $error++;
4035 dol_print_error($db);
4036 }
4037
4038 print '. ';
4039 $i++;
4040 }
4041 } else {
4042 print $langs->trans('AlreadyDone')."<br>\n";
4043 }
4044
4045 if (!$error) {
4046 $db->commit();
4047 } else {
4048 $db->rollback();
4049 }
4050 } else {
4051 dol_print_error($db);
4052 $db->rollback();
4053 }
4054
4055
4056 print '</td></tr>';
4057}
4058
4067function migrate_user_rights_entity($db, $langs, $conf)
4068{
4069 print '<tr><td colspan="4">';
4070
4071 print '<b>'.$langs->trans('MigrationUserRightsEntity')."</b><br>\n";
4072
4073 $error = 0;
4074
4075 dolibarr_install_syslog("upgrade2::migrate_user_rights_entity");
4076
4077 $db->begin();
4078
4079 $sqlSelect = "SELECT u.rowid, u.entity";
4080 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."user as u";
4081 $sqlSelect .= " WHERE u.entity > 1";
4082 //print $sqlSelect;
4083
4084 $resql = $db->query($sqlSelect);
4085 if ($resql) {
4086 $i = 0;
4087 $num = $db->num_rows($resql);
4088
4089 if ($num) {
4090 while ($i < $num) {
4091 $obj = $db->fetch_object($resql);
4092
4093 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
4094 $sqlUpdate .= " entity = ".((int) $obj->entity);
4095 $sqlUpdate .= " WHERE fk_user = ".((int) $obj->rowid);
4096
4097 $result = $db->query($sqlUpdate);
4098 if (!$result) {
4099 $error++;
4100 dol_print_error($db);
4101 }
4102
4103 print '. ';
4104 $i++;
4105 }
4106 } else {
4107 print $langs->trans('AlreadyDone')."<br>\n";
4108 }
4109
4110 if (!$error) {
4111 $db->commit();
4112 } else {
4113 $db->rollback();
4114 }
4115 } else {
4116 dol_print_error($db);
4117 $db->rollback();
4118 }
4119
4120
4121 print '</td></tr>';
4122}
4123
4132function migrate_usergroup_rights_entity($db, $langs, $conf)
4133{
4134 print '<tr><td colspan="4">';
4135
4136 print '<b>'.$langs->trans('MigrationUserGroupRightsEntity')."</b><br>\n";
4137
4138 $error = 0;
4139
4140 dolibarr_install_syslog("upgrade2::migrate_usergroup_rights_entity");
4141
4142 $db->begin();
4143
4144 $sqlSelect = "SELECT u.rowid, u.entity";
4145 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."usergroup as u";
4146 $sqlSelect .= " WHERE u.entity > 1";
4147 //print $sqlSelect;
4148
4149 $resql = $db->query($sqlSelect);
4150 if ($resql) {
4151 $i = 0;
4152 $num = $db->num_rows($resql);
4153
4154 if ($num) {
4155 while ($i < $num) {
4156 $obj = $db->fetch_object($resql);
4157
4158 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
4159 $sqlUpdate .= " entity = ".((int) $obj->entity);
4160 $sqlUpdate .= " WHERE fk_usergroup = ".((int) $obj->rowid);
4161
4162 $result = $db->query($sqlUpdate);
4163 if (!$result) {
4164 $error++;
4165 dol_print_error($db);
4166 }
4167
4168 print '. ';
4169 $i++;
4170 }
4171 } else {
4172 print $langs->trans('AlreadyDone')."<br>\n";
4173 }
4174
4175 if (!$error) {
4176 $db->commit();
4177 } else {
4178 $db->rollback();
4179 }
4180 } else {
4181 dol_print_error($db);
4182 $db->rollback();
4183 }
4184
4185
4186 print '</td></tr>';
4187}
4188
4199function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
4200{
4201 dolibarr_install_syslog("upgrade2::migrate_rename_directories");
4202
4203 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4204 dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname);
4205 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4206 }
4207}
4208
4209
4218function migrate_delete_old_files($db, $langs, $conf)
4219{
4220 $ret = true;
4221
4222 dolibarr_install_syslog("upgrade2::migrate_delete_old_files");
4223
4224 // List of files to delete
4225 $filetodeletearray = array(
4226 '/core/ajax/ajaxcompanies.php',
4227 '/core/triggers/interface_demo.class.php',
4228 '/core/menus/barre_left/default.php',
4229 '/core/menus/barre_top/default.php',
4230 '/core/modules/modComptabiliteExpert.class.php',
4231 '/core/modules/modCommercial.class.php',
4232 '/core/modules/modProduit.class.php',
4233 '/core/modules/modSkype.class.php',
4234 '/core/modules/modactivite.class.php', // A file from external module that should not be here
4235 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4236 '/core/triggers/interface_modCommande_Ecotax.class.php',
4237 '/core/triggers/interface_modCommande_fraisport.class.php',
4238 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4239 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4240 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4241 '/core/menus/smartphone/iphone.lib.php',
4242 '/core/menus/smartphone/iphone_backoffice.php',
4243 '/core/menus/smartphone/iphone_frontoffice.php',
4244 '/core/menus/standard/auguria_backoffice.php',
4245 '/core/menus/standard/auguria_frontoffice.php',
4246 '/core/menus/standard/eldy_backoffice.php',
4247 '/core/menus/standard/eldy_frontoffice.php',
4248 '/core/modules/export/export_excel.modules.php',
4249 '/core/modules/export/export_csv.modules.php',
4250 '/core/modules/export/exportcsv.modules.php',
4251 '/core/modules/export/export_excel2007new.modules.php',
4252 '/core/modules/facture/pdf_crabe.modules.php',
4253 '/core/modules/facture/pdf_oursin.modules.php',
4254 '/core/modules/mailings/contacts2.modules.php',
4255 '/core/modules/mailings/contacts3.modules.php',
4256 '/core/modules/mailings/contacts4.modules.php',
4257 '/core/modules/mailings/framboise.modules.php',
4258 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4259 '/core/modules/mailings/peche.modules.php',
4260 '/core/modules/mailings/poire.modules.php',
4261 '/core/modules/mailings/kiwi.modules.php',
4262 '/core/modules/syslog/mod_syslog_chromephp.php',
4263 '/core/modules/syslog/mod_syslog_firephp.php',
4264 '/core/modules/syslog/logHandlerInterface.php',
4265 '/core/boxes/box_members.php',
4266
4267 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4268 '/includes/nusoap/lib/class.*',
4269 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4270 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4271
4272 '/api/class/api_generic.class.php',
4273 '/asterisk/cidlookup.php',
4274 '/categories/class/api_category.class.php',
4275 '/categories/class/api_deprecated_category.class.php',
4276 '/compta/facture/class/api_invoice.class.php',
4277 '/commande/class/api_commande.class.php',
4278 '/partnership/class/api_partnership.class.php',
4279 '/product/class/api_product.class.php',
4280 '/recruitment/class/api_recruitment.class.php',
4281 '/societe/class/api_contact.class.php',
4282 '/societe/class/api_thirdparty.class.php',
4283 '/support/online.php',
4284 '/takepos/class/actions_takepos.class.php',
4285 '/user/class/api_user.class.php',
4286
4287 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4288 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4289 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4290 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4291 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4292 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4293 );
4294
4295 /*
4296 print '<tr><td colspan="4">';
4297 print '<b>'.$langs->trans('DeleteOldFiles')."</b><br>\n";
4298 print '</td></tr>';
4299 */
4300
4301 foreach ($filetodeletearray as $filetodelete) {
4302 //print '<b>'DOL_DOCUMENT_ROOT.$filetodelete."</b><br>\n";
4303 if (preg_match('/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4304 //print "Process file ".$filetodelete."\n";
4305 $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match('/\*/', $filetodelete) ? 1 : 0), 0, null, true, 0);
4306 if (!$result) {
4307 $langs->load("errors");
4308 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4309 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4310 } else {
4311 //print $langs->trans("FileWasRemoved", $filetodelete).'<br>';
4312 }
4313 }
4314 }
4315
4316 return $ret;
4317}
4318
4327function migrate_delete_old_dir($db, $langs, $conf)
4328{
4329 $ret = true;
4330
4331 dolibarr_install_syslog("upgrade2::migrate_delete_old_dir");
4332
4333 // List of files to delete
4334 $filetodeletearray = array(
4335 DOL_DOCUMENT_ROOT.'/core/modules/facture/terre',
4336 DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure',
4337 );
4338
4339 // On linux, we can also removed old directory with a different case than new directory.
4340 if (!empty($_SERVER["WINDIR"])) {
4341 $filetodeletearray[] = DOL_DOCUMENT_ROOT.'/includes/phpoffice/PhpSpreadsheet';
4342 }
4343
4344 foreach ($filetodeletearray as $filetodelete) {
4345 $result = 1;
4346 if (file_exists($filetodelete)) {
4347 $result = dol_delete_dir_recursive($filetodelete);
4348 }
4349 if (!$result) {
4350 $langs->load("errors");
4351 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete);
4352 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4353 }
4354 }
4355
4356 return $ret;
4357}
4358
4359
4372function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $force = 0)
4373{
4374 global $user;
4375
4376 if (count($listofmodule) == 0) {
4377 return 0;
4378 }
4379
4380 if (!is_object($user)) {
4381 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4382 $user = new User($db); // To avoid error during migration
4383 }
4384
4385 dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".implode(',', array_keys($listofmodule)), LOG_NOTICE);
4386
4387 $reloadactionformodules = array(
4388 'MAIN_MODULE_AGENDA' => array('class' => 'modAgenda', 'remove' => 1),
4389 'MAIN_MODULE_API' => array('class' => 'modApi'),
4390 'MAIN_MODULE_BARCODE' => array('class' => 'modBarcode', 'remove' => 1),
4391 'MAIN_MODULE_BLOCKEDLOG' => array('class' => 'modBlockedLog', 'deleteinsertmenus' => 1),
4392 'MAIN_MODULE_CRON' => array('class' => 'modCron', 'remove' => 1),
4393 'MAIN_MODULE_SOCIETE' => array('class' => 'modSociete', 'remove' => 1),
4394 'MAIN_MODULE_PRODUIT' => array('class' => 'modProduct'),
4395 'MAIN_MODULE_SERVICE' => array('class' => 'modService'),
4396 'MAIN_MODULE_COMMANDE' => array('class' => 'modCommande'),
4397 'MAIN_MODULE_DON' => array('class' => 'modDon'),
4398 'MAIN_MODULE_FACTURE' => array('class' => 'modFacture'),
4399 'MAIN_MODULE_FICHEINTER' => array('class' => 'modFicheinter'),
4400 'MAIN_MODULE_FOURNISSEUR' => array('class' => 'modFournisseur'),
4401 'MAIN_MODULE_EXPEDITION' => array('class' => 'modExpedition'),
4402 'MAIN_MODULE_EXPENSEREPORT' => array('class' => 'modExpenseReport'),
4403 'MAIN_MODULE_EVENTORGANIZATION' => array('class' => 'modEventOrganization', 'remove' => 1),
4404 'MAIN_MODULE_ECM' => array('class' => 'modECM', 'remove' => 1),
4405 'MAIN_MODULE_HOLIDAY' => array('class' => 'modHoliday', 'remove' => 1),
4406 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array('class' => 'modKnowledgeManagement', 'remove' => 1),
4407 'MAIN_MODULE_LOAN' => array('class' => 'modLoan', 'remove' => 1),
4408 'MAIN_MODULE_PAYBOX' => array('class' => 'modPaybox', 'remove' => 1),
4409 'MAIN_MODULE_PROPAL' => array('class' => 'modPropale'),
4410 'MAIN_MODULE_SUPPLIERPROPOSAL' => array('class' => 'modSupplierProposal', 'remove' => 1),
4411 'MAIN_MODULE_OPENSURVEY' => array('class' => 'modOpenSurvey', 'remove' => 1),
4412 'MAIN_MODULE_PRODUCTBATCH' => array('class' => 'modProductBatch', 'remove' => 1),
4413 'MAIN_MODULE_TAKEPOS' => array('class' => 'modTakePos', 'remove' => 1),
4414 'MAIN_MODULE_VARIANTS' => array('class' => 'modVariants', 'remove' => 1),
4415 'MAIN_MODULE_EMAILCOLLECTOR' => array('class' => 'modEmailCollector', 'remove' => 1),
4416 );
4417
4418 foreach ($listofmodule as $moduletoreload => $reloadmode) { // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
4419 $modulekey = preg_replace('/^MAIN_MODULE_/', '', $moduletoreload);
4420
4421 if (empty($moduletoreload) || (!isModEnabled(strtolower($modulekey)) && !$force)) {
4422 continue; // Discard reload if module not enabled
4423 }
4424
4425 $mod = null;
4426
4427 if (!empty($reloadactionformodules[$moduletoreload])) {
4428 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload." with mode ".$reloadmode);
4429
4430 $val = $reloadactionformodules[$moduletoreload];
4431 $classformodule = $val['class'];
4432 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/'.$classformodule.'.class.php';
4433 if ($res) {
4434 $mod = new $classformodule($db);
4435 if (!empty($val['remove'])) {
4436 $mod->remove('noboxes');
4437 }
4438 if (!empty($val['deleteinsertmenus'])) {
4439 // We only reload menus
4440 $mod->delete_menus();
4441 $mod->insert_menus();
4442 } else {
4443 $mod->init($reloadmode);
4444 }
4445 }
4446 } else { // Other generic cases/modules
4447 $reg = array();
4448 preg_match('/([a-zA-Z0-9]+)/', $modulekey, $reg);
4449 if (!empty($reg[1])) {
4450 if (strtoupper($moduletoreload) == $moduletoreload) { // If key has at least one uppercase
4451 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4452 } else { // If key is a mix of up and low case
4453 $moduletoreloadshort = $reg[1];
4454 }
4455
4456 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort." with mode ".$reloadmode." (generic code)", LOG_NOTICE);
4457
4458 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php';
4459 if ($res) {
4460 $classname = 'mod'.$moduletoreloadshort;
4461 $mod = new $classname($db);
4462 '@phan-var-force DolibarrModules $mod';
4463
4464 //$mod->remove('noboxes');
4465 $mod->delete_menus(); // We must delete to be sure it is inserted with new values
4466 $mod->init($reloadmode);
4467 } else {
4468 dolibarr_install_syslog('Failed to include '.DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4469
4470 $res = @dol_include_once(strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
4471 if ($res) {
4472 $classname = 'mod'.$moduletoreloadshort;
4473 $mod = new $classname($db);
4474 '@phan-var-force DolibarrModules $mod';
4475 $mod->init($reloadmode);
4476 } else {
4477 dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4478 print "Error, can't find module with name ".$moduletoreload."\n";
4479 return -1;
4480 }
4481 }
4482 } else {
4483 dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_ERR);
4484 print "Error, can't find module with name ".$moduletoreload."\n";
4485 return -1;
4486 }
4487 }
4488
4489 if (!empty($mod) && is_object($mod)) {
4490 print '<tr class="trforrunsql"><td colspan="4">';
4491 print '<b>'.$langs->trans('Upgrade').'</b>: ';
4492 print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
4493 print "<!-- (".$reloadmode.") -->";
4494 print "<br>\n";
4495 print '</td></tr>';
4496 }
4497 }
4498
4499 return 1;
4500}
4501
4502
4503
4512function migrate_reload_menu($db, $langs, $conf)
4513{
4514 global $conf;
4515 dolibarr_install_syslog("upgrade2::migrate_reload_menu");
4516
4517 // Define list of menu handlers to initialize
4518 $listofmenuhandler = array();
4519 if (getDolGlobalString('MAIN_MENU_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENU_SMARTPHONE') == 'auguria_menu'
4520 || getDolGlobalString('MAIN_MENUFRONT_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE') == 'auguria_menu') {
4521 $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers
4522 }
4523
4524 foreach ($listofmenuhandler as $key => $val) {
4525 print '<tr class="trforrunsql"><td colspan="4">';
4526
4527 //print "x".$key;
4528 print '<br>';
4529 print '<b>'.$langs->trans('Upgrade').'</b>: '.$langs->trans('MenuHandler')." ".$key."<br>\n";
4530
4531 // Load sql ini_menu_handler.sql file
4532 $dir = DOL_DOCUMENT_ROOT."/core/menus/";
4533 $file = 'init_menu_'.$key.'.sql';
4534 if (file_exists($dir.$file)) {
4535 $result = run_sql($dir.$file, 1, 0, 1, $key);
4536 }
4537
4538 print '</td></tr>';
4539 }
4540
4541 return 1;
4542}
4543
4550{
4551 global $conf, $db, $langs, $user;
4552
4553 if (!is_object($user)) {
4554 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4555 $user = new User($db); // To avoid error during migration
4556 }
4557
4558 print '<tr><td colspan="4">';
4559
4560 print '<b>'.$langs->trans('MigrationProductLotPath')."</b><br>\n";
4561
4562 $sql = "SELECT rowid, entity, batch, fk_product from ".MAIN_DB_PREFIX."product_lot";
4563 $resql = $db->query($sql);
4564
4565 if ($resql) {
4566 $modulepart="product_batch";
4567
4568 $lot = new Productlot($db);
4569
4570 while ($obj = $db->fetch_object($resql)) {
4571 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4572 if ($entity > 1) {
4573 $dir = DOL_DATA_ROOT.'/'.$entity.'/'.$conf->productbatch->multidir_output[$entity];
4574 } else {
4575 $dir = $conf->productbatch->multidir_output[$entity];
4576 }
4577
4578 if ($dir) {
4579 $lot->id = (int) $obj->rowid;
4580 $lot->ref = (string) $obj->rowid; // No ref for the moment
4581 $lot->batch = $obj->batch;
4582 $lot->entity = $obj->entity;
4583 $lot->fk_product = $obj->fk_product;
4584
4585 $savref = $lot->ref;
4586
4587 $lot->ref = $obj->batch;
4588 $origin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4589
4590 $lot->ref = $savref; // So restore the id
4591 $destin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4592
4593 //var_dump($origin.' -> '.$destin.' '.$lot->batch.' dir origin is '.dol_is_dir($origin));exit;
4594
4595 if (dol_is_dir($origin) && !dol_is_dir($destin)) {
4596 dol_move_dir($origin, $destin, 0);
4597 }
4598 }
4599 }
4600 }
4601 print '</td></tr>';
4602
4603 return 1;
4604}
4605
4612{
4613 global $conf, $db, $langs, $user;
4614
4615 print '<tr><td colspan="4">';
4616
4617 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4618
4619 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4620 $fuser = new User($db);
4621 if (!is_object($user)) {
4622 $user = $fuser; // To avoid error during migration
4623 }
4624
4625 $sql = "SELECT rowid as uid, entity from ".MAIN_DB_PREFIX."user"; // Get list of all users
4626 $resql = $db->query($sql);
4627 if ($resql) {
4628 while ($obj = $db->fetch_object($resql)) {
4629 //$fuser->fetch($obj->uid);
4630 $fuser->id = $obj->uid;
4631 $fuser->entity = $obj->entity;
4632
4633 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4634 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4635 if ($entity > 1) {
4636 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4637 } else {
4638 $dir = $conf->user->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4639 }
4640
4641 if ($dir) {
4642 //print "Process user id ".$fuser->id."<br>\n";
4643 $origin = $dir.'/'.get_exdir($fuser->id, 2, 0, 1, $fuser, 'user'); // Use old behaviour to get x/y path
4644 $destin = $dir.'/'.$fuser->id;
4645
4646 $origin_osencoded = dol_osencode($origin);
4647
4648 dol_mkdir($destin);
4649
4650 //echo '<hr>'.$origin.' -> '.$destin;
4651 if (dol_is_dir($origin)) {
4652 $handle = opendir($origin_osencoded);
4653 if (is_resource($handle)) {
4654 while (($file = readdir($handle)) !== false) {
4655 if ($file == '.' || $file == '..') {
4656 continue;
4657 }
4658
4659 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4660 $thumbs = opendir($origin_osencoded.'/'.$file);
4661 if (is_resource($thumbs)) {
4662 dol_mkdir($destin.'/'.$file);
4663 while (($thumb = readdir($thumbs)) !== false) {
4664 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4665 if ($thumb == '.' || $thumb == '..') {
4666 continue;
4667 }
4668
4669 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4670 print '.';
4671 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4672 //var_dump('aaa');exit;
4673 }
4674 }
4675 // dol_delete_dir($origin.'/'.$file);
4676 }
4677 } else { // it is a file
4678 if (!dol_is_file($destin.'/'.$file)) {
4679 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4680 print '.';
4681 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4682 //var_dump('eee');exit;
4683 }
4684 }
4685 }
4686 }
4687 }
4688 }
4689 }
4690 }
4691
4692 print '</td></tr>';
4693}
4694
4701{
4702 global $db, $langs, $user;
4703
4704 print '<tr><td colspan="4">';
4705
4706 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4707
4708 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4709 $fuser = new User($db);
4710 if (!is_object($user)) {
4711 $user = $fuser; // To avoid error during migration
4712 }
4713
4714 $sql = "SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX."user"; // Get list of all users
4715 $resql = $db->query($sql);
4716 if ($resql) {
4717 while ($obj = $db->fetch_object($resql)) {
4718 //$fuser->fetch($obj->uid);
4719 $fuser->id = $obj->uid;
4720 $fuser->entity = $obj->entity;
4721 $fuser->photo = $obj->photo;
4722
4723 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4724 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4725 if ($entity > 1) {
4726 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4727 } else {
4728 $dir = DOL_DATA_ROOT.'/users';
4729 }
4730
4731 if ($dir) {
4732 //print "Process user id ".$fuser->id."<br>\n";
4733 $origin = $dir.'/'.$fuser->id;
4734 $destin = $dir.'/'.$fuser->id.'/photos';
4735
4736 $origin_osencoded = dol_osencode($origin);
4737
4738 dol_mkdir($destin);
4739
4740 //echo '<hr>'.$origin.' -> '.$destin;
4741 if (dol_is_dir($origin)) {
4742 $handle = opendir($origin_osencoded);
4743 if (is_resource($handle)) {
4744 while (($file = readdir($handle)) !== false) {
4745 if ($file == '.' || $file == '..' || $file == 'photos') {
4746 continue;
4747 }
4748 if (!empty($fuser->photo) && ($file != $fuser->photo && $file != 'thumbs')) {
4749 continue;
4750 }
4751
4752 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4753 $thumbs = opendir($origin_osencoded.'/'.$file);
4754 if (is_resource($thumbs)) {
4755 dol_mkdir($destin.'/'.$file);
4756 while (($thumb = readdir($thumbs)) !== false) {
4757 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4758 if ($thumb == '.' || $thumb == '..') {
4759 continue;
4760 }
4761
4762 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4763 print '.';
4764 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4765 }
4766 }
4767 // dol_delete_dir($origin.'/'.$file);
4768 }
4769 } else { // it is a file
4770 if (!dol_is_file($destin.'/'.$file)) {
4771 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4772 print '.';
4773 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4774 }
4775 }
4776 }
4777 }
4778 }
4779 }
4780 }
4781 }
4782
4783 print '</td></tr>';
4784}
4785
4786
4787
4794{
4795 global $conf, $db, $langs;
4796
4797 print '<tr class="trforrunsql"><td>';
4798
4799 print '<b>'.$langs->trans('MigrationHolidayPath')."</b><br>\n";
4800
4801 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
4802 $holiday = new Holiday($db);
4803
4804 $sql = "SELECT rowid as uid, ref, entity from ".MAIN_DB_PREFIX."holiday"; // Get list of all holiday
4805
4806 $resql = $db->query($sql);
4807 if ($resql) {
4808 while ($obj = $db->fetch_object($resql)) {
4809 //$holiday->fetch($obj->uid);
4810 $holiday->id = $obj->uid;
4811 $holiday->ref = $obj->ref;
4812 $holiday->entity = $obj->entity;
4813
4814 //echo '<hr>'.$holiday->id.' -> '.$holiday->entity;
4815 $entity = (empty($holiday->entity) ? 1 : $holiday->entity);
4816 if ($entity > 1) {
4817 $dir = DOL_DATA_ROOT.'/'.$entity.'/holiday';
4818 } else {
4819 $dir = $conf->holiday->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4820 }
4821
4822 if ($dir) {
4823 //print "Process holiday id ".$holiday->id."<br>\n";
4824 $origin = $dir.'/'.get_exdir($holiday->id, 2, 0, 1, $holiday, 'holiday'); // Use old behaviour to get x/y path
4825 $destin = $dir.'/'.$holiday->ref;
4826
4827 $origin_osencoded = dol_osencode($origin);
4828
4829 dol_mkdir($destin);
4830
4831 //echo $origin.' -> '.$destin."<br>\n";
4832 if (dol_is_dir($origin)) {
4833 $handle = opendir($origin_osencoded);
4834 if (is_resource($handle)) {
4835 while (($file = readdir($handle)) !== false) {
4836 if ($file == '.' || $file == '..') {
4837 continue;
4838 }
4839
4840 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4841 $thumbs = opendir($origin_osencoded.'/'.$file);
4842 if (is_resource($thumbs)) {
4843 dol_mkdir($destin.'/'.$file);
4844 while (($thumb = readdir($thumbs)) !== false) {
4845 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4846 if ($thumb == '.' || $thumb == '..') {
4847 continue;
4848 }
4849
4850 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4851 print '.';
4852 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4853 //var_dump('aaa');exit;
4854 }
4855 }
4856 // dol_delete_dir($origin.'/'.$file);
4857 }
4858 } else { // it is a file
4859 if (!dol_is_file($destin.'/'.$file)) {
4860 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4861 print '.';
4862 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4863 //var_dump('eee');exit;
4864 }
4865 }
4866 }
4867 }
4868 }
4869 }
4870 }
4871 }
4872
4873 print '</td></tr>';
4874}
4875
4876
4877/* A faire egalement: Modif statut paye et fk_facture des factures payes completement
4878
4879On recherche facture incorrecte:
4880select f.rowid, f.total_ttc as t1, sum(pf.amount) as t2 from llx_facture as f, llx_paiement_facture as pf where pf.fk_facture=f.rowid and f.fk_statut in(2,3) and paye=0 and close_code is null group by f.rowid
4881having f.total_ttc = sum(pf.amount)
4882
4883On les corrige:
4884update llx_facture set paye=1, fk_statut=2 where close_code is null
4885and rowid in (...)
4886*/
4887
4895{
4896 global $db, $langs;
4897 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
4898 $error = 0;
4899 $db->begin();
4900 print '<tr><td colspan="4">';
4901 $sql = 'SELECT rowid, socialnetworks';
4902 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE';
4903 $sql .= " skype IS NOT NULL OR skype <> ''";
4904 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4905 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4906 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4907 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4908 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4909 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4910 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4911 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4912 //print $sql;
4913 $resql = $db->query($sql);
4914 if ($resql) {
4915 while ($obj = $db->fetch_object($resql)) {
4916 $arraysocialnetworks = array();
4917 if (!empty($obj->skype)) {
4918 $arraysocialnetworks['skype'] = $obj->skype;
4919 }
4920 if (!empty($obj->twitter)) {
4921 $arraysocialnetworks['twitter'] = $obj->twitter;
4922 }
4923 if (!empty($obj->facebook)) {
4924 $arraysocialnetworks['facebook'] = $obj->facebook;
4925 }
4926 if (!empty($obj->linkedin)) {
4927 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4928 }
4929 if (!empty($obj->instagram)) {
4930 $arraysocialnetworks['instagram'] = $obj->instagram;
4931 }
4932 if (!empty($obj->snapchat)) {
4933 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4934 }
4935 if (!empty($obj->googleplus)) {
4936 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4937 }
4938 if (!empty($obj->youtube)) {
4939 $arraysocialnetworks['youtube'] = $obj->youtube;
4940 }
4941 if (!empty($obj->whatsapp)) {
4942 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4943 }
4944 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4945 $obj->socialnetworks = '[]';
4946 }
4947 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4948 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4949 $sqlupd .= ', skype=null';
4950 $sqlupd .= ', twitter=null';
4951 $sqlupd .= ', facebook=null';
4952 $sqlupd .= ', linkedin=null';
4953 $sqlupd .= ', instagram=null';
4954 $sqlupd .= ', snapchat=null';
4955 $sqlupd .= ', googleplus=null';
4956 $sqlupd .= ', youtube=null';
4957 $sqlupd .= ', whatsapp=null';
4958 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4959 //print $sqlupd."<br>";
4960 $resqlupd = $db->query($sqlupd);
4961 if (!$resqlupd) {
4962 dol_print_error($db);
4963 $error++;
4964 }
4965 }
4966 } else {
4967 $error++;
4968 }
4969 if (!$error) {
4970 $db->commit();
4971 } else {
4972 dol_print_error($db);
4973 $db->rollback();
4974 }
4975 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."</b><br>\n";
4976 print '</td></tr>';
4977}
4978
4986{
4987 global $db, $langs;
4988
4989 print '<tr><td colspan="4">';
4990 $error = 0;
4991 $db->begin();
4992 print '<tr><td colspan="4">';
4993 $sql = 'SELECT rowid, socialnetworks';
4994 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE ';
4995 $sql .= " skype IS NOT NULL OR skype <> ''";
4996 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4997 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4998 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4999 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5000 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5001 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5002 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5003 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5004 //print $sql;
5005 $resql = $db->query($sql);
5006 if ($resql) {
5007 while ($obj = $db->fetch_object($resql)) {
5008 $arraysocialnetworks = array();
5009 if (!empty($obj->skype)) {
5010 $arraysocialnetworks['skype'] = $obj->skype;
5011 }
5012 if (!empty($obj->twitter)) {
5013 $arraysocialnetworks['twitter'] = $obj->twitter;
5014 }
5015 if (!empty($obj->facebook)) {
5016 $arraysocialnetworks['facebook'] = $obj->facebook;
5017 }
5018 if (!empty($obj->linkedin)) {
5019 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5020 }
5021 if (!empty($obj->instagram)) {
5022 $arraysocialnetworks['instagram'] = $obj->instagram;
5023 }
5024 if (!empty($obj->snapchat)) {
5025 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5026 }
5027 if (!empty($obj->googleplus)) {
5028 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5029 }
5030 if (!empty($obj->youtube)) {
5031 $arraysocialnetworks['youtube'] = $obj->youtube;
5032 }
5033 if (!empty($obj->whatsapp)) {
5034 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5035 }
5036 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5037 $obj->socialnetworks = '[]';
5038 }
5039 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5040 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5041 $sqlupd .= ', skype=null';
5042 $sqlupd .= ', twitter=null';
5043 $sqlupd .= ', facebook=null';
5044 $sqlupd .= ', linkedin=null';
5045 $sqlupd .= ', instagram=null';
5046 $sqlupd .= ', snapchat=null';
5047 $sqlupd .= ', googleplus=null';
5048 $sqlupd .= ', youtube=null';
5049 $sqlupd .= ', whatsapp=null';
5050 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5051 //print $sqlupd."<br>";
5052 $resqlupd = $db->query($sqlupd);
5053 if (!$resqlupd) {
5054 dol_print_error($db);
5055 $error++;
5056 }
5057 }
5058 } else {
5059 $error++;
5060 }
5061 if (!$error) {
5062 $db->commit();
5063 } else {
5064 dol_print_error($db);
5065 $db->rollback();
5066 }
5067 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."</b><br>\n";
5068 print '</td></tr>';
5069}
5070
5078{
5079 global $db, $langs;
5080 // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5081 $error = 0;
5082 $db->begin();
5083 print '<tr><td colspan="4">';
5084 $sql = 'SELECT rowid, socialnetworks';
5085 $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE';
5086 $sql .= " jabberid IS NOT NULL OR jabberid <> ''";
5087 $sql .= " OR skype IS NOT NULL OR skype <> ''";
5088 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5089 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5090 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5091 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5092 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5093 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5094 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5095 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5096 //print $sql;
5097 $resql = $db->query($sql);
5098 if ($resql) {
5099 while ($obj = $db->fetch_object($resql)) {
5100 $arraysocialnetworks = array();
5101 if (!empty($obj->jabberid)) {
5102 $arraysocialnetworks['jabber'] = $obj->jabberid;
5103 }
5104 if (!empty($obj->skype)) {
5105 $arraysocialnetworks['skype'] = $obj->skype;
5106 }
5107 if (!empty($obj->twitter)) {
5108 $arraysocialnetworks['twitter'] = $obj->twitter;
5109 }
5110 if (!empty($obj->facebook)) {
5111 $arraysocialnetworks['facebook'] = $obj->facebook;
5112 }
5113 if (!empty($obj->linkedin)) {
5114 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5115 }
5116 if (!empty($obj->instagram)) {
5117 $arraysocialnetworks['instagram'] = $obj->instagram;
5118 }
5119 if (!empty($obj->snapchat)) {
5120 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5121 }
5122 if (!empty($obj->googleplus)) {
5123 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5124 }
5125 if (!empty($obj->youtube)) {
5126 $arraysocialnetworks['youtube'] = $obj->youtube;
5127 }
5128 if (!empty($obj->whatsapp)) {
5129 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5130 }
5131 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5132 $obj->socialnetworks = '[]';
5133 }
5134 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5135 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5136 $sqlupd .= ', jabberid=null';
5137 $sqlupd .= ', skype=null';
5138 $sqlupd .= ', twitter=null';
5139 $sqlupd .= ', facebook=null';
5140 $sqlupd .= ', linkedin=null';
5141 $sqlupd .= ', instagram=null';
5142 $sqlupd .= ', snapchat=null';
5143 $sqlupd .= ', googleplus=null';
5144 $sqlupd .= ', youtube=null';
5145 $sqlupd .= ', whatsapp=null';
5146 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5147 //print $sqlupd."<br>";
5148 $resqlupd = $db->query($sqlupd);
5149 if (!$resqlupd) {
5150 dol_print_error($db);
5151 $error++;
5152 }
5153 }
5154 } else {
5155 $error++;
5156 }
5157 if (!$error) {
5158 $db->commit();
5159 } else {
5160 dol_print_error($db);
5161 $db->rollback();
5162 }
5163 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."</b><br>\n";
5164 print '</td></tr>';
5165}
5166
5174{
5175 global $db, $langs;
5176 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5177 $error = 0;
5178 $db->begin();
5179 print '<tr><td colspan="4">';
5180 $sql = 'SELECT rowid, socialnetworks';
5181 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE ';
5182 $sql .= " skype IS NOT NULL OR skype <> ''";
5183 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5184 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5185 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5186 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5187 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5188 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5189 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5190 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5191 //print $sql;
5192 $resql = $db->query($sql);
5193 if ($resql) {
5194 while ($obj = $db->fetch_object($resql)) {
5195 $arraysocialnetworks = array();
5196 if (!empty($obj->skype)) {
5197 $arraysocialnetworks['skype'] = $obj->skype;
5198 }
5199 if (!empty($obj->twitter)) {
5200 $arraysocialnetworks['twitter'] = $obj->twitter;
5201 }
5202 if (!empty($obj->facebook)) {
5203 $arraysocialnetworks['facebook'] = $obj->facebook;
5204 }
5205 if (!empty($obj->linkedin)) {
5206 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5207 }
5208 if (!empty($obj->instagram)) {
5209 $arraysocialnetworks['instagram'] = $obj->instagram;
5210 }
5211 if (!empty($obj->snapchat)) {
5212 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5213 }
5214 if (!empty($obj->googleplus)) {
5215 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5216 }
5217 if (!empty($obj->youtube)) {
5218 $arraysocialnetworks['youtube'] = $obj->youtube;
5219 }
5220 if (!empty($obj->whatsapp)) {
5221 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5222 }
5223 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5224 $obj->socialnetworks = '[]';
5225 }
5226 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5227 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5228 $sqlupd .= ', skype=null';
5229 $sqlupd .= ', twitter=null';
5230 $sqlupd .= ', facebook=null';
5231 $sqlupd .= ', linkedin=null';
5232 $sqlupd .= ', instagram=null';
5233 $sqlupd .= ', snapchat=null';
5234 $sqlupd .= ', googleplus=null';
5235 $sqlupd .= ', youtube=null';
5236 $sqlupd .= ', whatsapp=null';
5237 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5238 //print $sqlupd."<br>";
5239 $resqlupd = $db->query($sqlupd);
5240 if (!$resqlupd) {
5241 dol_print_error($db);
5242 $error++;
5243 }
5244 }
5245 } else {
5246 $error++;
5247 }
5248 if (!$error) {
5249 $db->commit();
5250 } else {
5251 dol_print_error($db);
5252 $db->rollback();
5253 }
5254 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."</b><br>\n";
5255 print '</td></tr>';
5256}
5257
5258
5265function migrate_export_import_profiles($mode = 'export')
5266{
5267 global $db, $langs;
5268
5269 $error = 0;
5270 $resultstring = '';
5271
5272 $db->begin();
5273
5274 print '<tr class="trforrunsql"><td colspan="4">';
5275 $sql = 'SELECT rowid, field';
5276 if ($mode == 'export') {
5277 $sql .= ', filter';
5278 }
5279 $sql .= ' FROM '.MAIN_DB_PREFIX.$mode.'_model WHERE';
5280 $sql .= " type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5281 //print $sql;
5282 $resql = $db->query($sql);
5283 if ($resql) {
5284 while ($obj = $db->fetch_object($resql)) {
5285 $oldfield = $obj->field;
5286 $newfield = str_replace(array(',f.facnumber', 'f.facnumber,', 'f.total,', 'f.tva,'), array(',f.ref', 'f.ref,', 'f.total_ht,', 'f.total_tva,'), $oldfield);
5287
5288 if ($mode == 'export') {
5289 $oldfilter = $obj->filter;
5290 $newfilter = str_replace(array('f.facnumber=', 'f.total=', 'f.tva='), array('f.ref=', 'f.total_ht=', 'f.total_tva='), $oldfilter);
5291 } else {
5292 $oldfilter = '';
5293 $newfilter = '';
5294 }
5295
5296 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5297 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX.$mode."_model SET field = '".$db->escape($newfield)."'";
5298 if ($mode == 'export') {
5299 $sqlupd .= ", filter = '".$db->escape($newfilter)."'";
5300 }
5301 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5302 $resultstring .= '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd."</td></tr>\n";
5303 $resqlupd = $db->query($sqlupd);
5304 if (!$resqlupd) {
5305 dol_print_error($db);
5306 $error++;
5307 }
5308 }
5309 }
5310 } else {
5311 $error++;
5312 }
5313 if (!$error) {
5314 $db->commit();
5315 } else {
5316 dol_print_error($db);
5317 $db->rollback();
5318 }
5319 print '<b>'.$langs->trans('MigrationImportOrExportProfiles', $mode)."</b><br>\n";
5320 print '</td></tr>';
5321
5322 if ($resultstring) {
5323 print $resultstring;
5324 } else {
5325 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5326 }
5327}
5328
5335{
5336 global $db, $langs;
5337
5338 $error = 0;
5339 $resultstring = '';
5340
5341 $db->begin();
5342 print '<tr class="trforrunsql"><td colspan="4">';
5343 print '<b>'.$langs->trans('MigrationContractLineRank')."</b><br>\n";
5344
5345 $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";
5346 $sql .= " ORDER BY c.rowid,cd.rowid";
5347
5348 $resql = $db->query($sql);
5349 if ($resql) {
5350 $currentRank = 0;
5351 $current_contract = 0;
5352 while ($obj = $db->fetch_object($resql)) {
5353 if (empty($current_contract) || $current_contract == $obj->cid) {
5354 $currentRank++;
5355 } else {
5356 $currentRank = 1;
5357 }
5358
5359 $sqlUpd = "UPDATE ".$db->prefix()."contratdet SET rang=".(int) $currentRank." WHERE rowid=".(int) $obj->cdid;
5360 $resultstring = '.';
5361 print $resultstring;
5362 $resqlUpd = $db->query($sqlUpd);
5363 if (!$resqlUpd) {
5364 dol_print_error($db);
5365 $error++;
5366 }
5367
5368 $current_contract = $obj->cid;
5369 }
5370 } else {
5371 $error++;
5372 }
5373 if (!$error) {
5374 $db->commit();
5375 } else {
5376 $db->rollback();
5377 }
5378
5379 print '</td></tr>';
5380
5381 if (!$resultstring) {
5382 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5383 }
5384}
5385
5392{
5393 global $db, $langs;
5394
5395 $lock = getDolGlobalInt('MIGRATION_FLAG_INVOICE_MODELS_V20');
5396
5397 $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5398 $migrationNeeded = (versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5399
5400 print '<tr class="trforrunsql"><td colspan="4">';
5401 print '<b>'.$langs->trans('InvoiceExportModelsMigration')."</b>: \n";
5402
5403 if (! $migrationNeeded) {
5404 print $langs->trans("AlreadyDone");
5405 print '</td></tr>';
5406 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5407 return;
5408 }
5409
5410
5411 $db->begin();
5412
5413 $sql1 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5414
5415 $resql1 = $db->query($sql1);
5416
5417 if (! $resql1) {
5418 dol_print_error($db);
5419 $db->rollback();
5420 print '</td></tr>';
5421 return;
5422 }
5423
5424 $modified1 = $db->affected_rows($resql1);
5425
5426 print str_repeat('.', $modified1);
5427
5428 $db->free($resql1);
5429
5430 $sql2 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5431
5432 $resql2 = $db->query($sql2);
5433
5434 if (! $resql2) {
5435 dol_print_error($db);
5436 $db->rollback();
5437 print '</td></tr>';
5438 return;
5439 }
5440
5441 $modified2 = $db->affected_rows($resql2);
5442
5443 print str_repeat('.', $modified2);
5444
5445 $db->free($resql2);
5446
5447 if (empty($modified1 + $modified2)) {
5448 print $langs->trans('NothingToDo');
5449 }
5450
5451 $db->commit();
5452
5453 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5454
5455 echo '</td></tr>';
5456}
5457
5465{
5466 global $db, $langs;
5467
5468 $error = 0;
5469 $resultstring = '';
5470 $bookKeepingAddon = '';
5471
5472 // For the moment we set the numbering rule to neon (the rule argon has a lot of critical bugs to fix first).
5473 if (getDolGlobalString('BOOKKEEPING_ADDON') == '') {
5474 dolibarr_set_const($db, 'BOOKKEEPING_ADDON', 'mod_bookkeeping_neon', 'chaine', 0, '', $entity);
5475 $bookKeepingAddon = 'mod_bookkeeping_neon';
5476 }
5477
5478 print '<tr class="trforrunsql"><td colspan="4">';
5479 print '<b>'.$langs->trans('MigrationAccountancyBookkeeping')."</b><br>\n";
5480
5481 // TODO
5482 if ($bookKeepingAddon === 'mod_bookkeeping_argon') {
5483 $db->begin();
5484
5485 $sql = "SELECT DISTINCT YEAR(doc_date) as doc_year, MONTH(doc_date) as doc_month, code_journal, piece_num FROM ".$db->prefix()."accounting_bookkeeping";
5486 $sql .= " WHERE ref IS NULL AND entity = ".((int) $entity);
5487 $sql .= " ORDER BY doc_year, doc_month, code_journal, piece_num";
5488
5489 $resql = $db->query($sql);
5490
5491 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
5492 $bookkeeping = new BookKeeping($db);
5493 if ($resql) {
5494 while ($obj = $db->fetch_object($resql)) {
5495 $bookkeeping->doc_date = dol_mktime(0, 0, 0, $obj->doc_month, 1, $obj->doc_year);
5496 $bookkeeping->code_journal = $obj->code_journal;
5497 $ref = $bookkeeping->getNextNumRef();
5498
5499 $sqlUpd = "UPDATE ".$db->prefix()."accounting_bookkeeping SET ref = '".$db->escape($ref)."' WHERE piece_num = '".$db->escape($obj->piece_num)."' AND entity = ".((int) $entity);
5500 $resultstring = '.';
5501 print $resultstring;
5502 $resqlUpd = $db->query($sqlUpd);
5503 if (!$resqlUpd) {
5504 dol_print_error($db);
5505 $error++;
5506 }
5507 }
5508 } else {
5509 $error++;
5510 }
5511
5512 if (!$error) {
5513 $db->commit();
5514 } else {
5515 $db->rollback();
5516 }
5517 }
5518
5519 print '</td></tr>';
5520
5521 if (!$resultstring) {
5522 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5523 }
5524}
5525
5532{
5533 global $conf, $db, $langs;
5534
5535 print '<tr class="trforrunsql"><td colspan="4">';
5536 print '<b>'.$langs->trans('MigrationApiRestTokens')."</b>:\n";
5537
5538 $error = 0;
5539 $nbofmigration = 0;
5540 $allexistingtokens = array();
5541
5542 $db->begin();
5543
5544 $sqlforalltokens = "SELECT oat.tokenstring";
5545 $sqlforalltokens .= " FROM ".$db->prefix()."oauth_token AS oat";
5546 $sqlforalltokens .= " WHERE oat.service = 'dolibarr_rest_api'";
5547
5548 $resalltoken = $db->query($sqlforalltokens);
5549
5550 if ($resalltoken) {
5551 while ($tokenobj = $db->fetch_object($resalltoken)) {
5552 $allexistingtokens[] = dolDecrypt($tokenobj->tokenstring);
5553 }
5554 } else {
5555 $error++;
5556 dol_print_error($db);
5557 $db->rollback();
5558 }
5559
5560 if (!$error) {
5561 $sql = "SELECT 'dolibarr_rest_api' AS service, u.api_key AS tokenstring, u.rowid AS fk_user, u.entity";
5562 $sql .= " FROM llx_user AS u";
5563 $sql .= " WHERE u.api_key IS NOT NULL AND u.api_key <> ''";
5564
5565 $result = $db->query($sql);
5566
5567 if ($result) {
5568 $tmpuser = new User($db);
5569
5570 while ($obj = $db->fetch_object($result)) {
5571 if (!in_array(dolDecrypt($obj->tokenstring), $allexistingtokens)) {
5572 // Load the object of the user of token so we can get the API_COUNT_CALL
5573 unset($tmpuser->conf); $tmpuser->conf = new stdClass();
5574 $tmpuser->fetch((int) $obj->fk_user, '', '', 1, ($obj->entity ? $obj->entity : $conf->entity));
5575
5576 $sqlforinsert = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, tokenstring, fk_user, datec, entity, apicount_total)";
5577 $sqlforinsert .= " VALUES ('".$db->escape($obj->service)."', '".$db->escape(dolEncrypt(dolDecrypt($obj->tokenstring)))."', ";
5578 $sqlforinsert .= ((int) $obj->fk_user).", '".$db->idate(dol_now())."', ".((int) $obj->entity).", ";
5579 $sqlforinsert .= getDolUserInt('API_COUNT_CALL', 0, $tmpuser);
5580 $sqlforinsert .= ")";
5581
5582 $insertresult = $db->query($sqlforinsert);
5583 if (!$insertresult) {
5584 $error++;
5585 dol_print_error($db);
5586 } else {
5587 $nbofmigration++;
5588 }
5589 }
5590 }
5591
5592 if (!$error) {
5593 $db->commit();
5594 } else {
5595 $db->rollback();
5596 }
5597 } else {
5598 dol_print_error($db);
5599 $db->rollback();
5600 }
5601 }
5602
5603 if (!$nbofmigration) {
5604 print $langs->trans("NothingToDo")."\n";
5605 } else {
5606 print $langs->trans('MigratedTokens', $nbofmigration);
5607 }
5608 print '</td></tr>';
5609}
5610
5611
5618{
5619 global $conf, $db, $langs;
5620
5621 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
5622 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
5623
5624 print '<tr class="trforrunsql"><td colspan="4">';
5625 print '<b>'.$langs->trans('InitAHMACKeyForBlockedLog')."</b>:\n";
5626
5627 $db->begin();
5628
5629 // Create HMAC if it does not exists yet
5630 $hmac_encoded_secret_key = getDolGlobalString('BLOCKEDLOG_HMAC_KEY');
5631 if (empty($hmac_encoded_secret_key)) {
5632 // Add key
5633 $hmac_secret_key = 'BLOCKEDLOGHMAC'.getRandomPassword(true); // This is using random_int for 32 chars
5634
5635 $result = dolibarr_set_const($db, 'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key, 'chaine', 0, 'The secret key for HMAC used for blockedlog record', 0); // Will encrypt the value using dolCrypt and store it.
5636
5637 if ($result < 0) {
5638 dol_print_error($db);
5639 $db->rollback();
5640
5641 print '</td></tr>';
5642 return -1;
5643 }
5644
5645 print $langs->trans('Done');
5646 } else {
5647 // Decode the HMAC key
5648 $hmac_secret_key = dolDecrypt($hmac_encoded_secret_key);
5649
5650 if (! preg_match('/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
5651 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.';
5652 print 'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.';
5653 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.';
5654 $db->rollback();
5655
5656 print '</td></tr>';
5657 return -1;
5658 }
5659
5660 print $langs->trans("NothingToDo")."\n";
5661 }
5662
5663 $db->commit();
5664
5665 print '</td></tr>';
5666 return 1;
5667}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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,...
Definition admin.lib.php:71
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.
Class to manage hooks.
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.
global $mysoc
$conffile
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...
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)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return 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)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:541
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:635
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:699
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $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.
Definition price.lib.php:90
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:466
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
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...
Definition upgrade2.php:995
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.
if($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)
Definition upgrade2.php:915
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
migrate_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 du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
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)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondence des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_blockedlog_add_hmac_key()
Add the HMAC key for blockedlog v2.
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 des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_element_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.
migrate_apiresttokens()
Migrate API key in oauth_token table.