dolibarr 20.0.0
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 *
23 * Upgrade2 scripts can be ran from command line with syntax:
24 *
25 * cd htdocs/install
26 * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion]
27 * php upgrade2.php 3.4.0 3.5.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
28 *
29 * And for final step:
30 * php step5.php 3.4.0 3.5.0
31 *
32 * Return code is 0 if OK, >0 if error
33 *
34 * Note: To just enable a module from command line, use this syntax:
35 * php upgrade2.php 0.0.0 0.0.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
36 */
37
43define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
44include_once 'inc.php';
45if (!file_exists($conffile)) {
46 print 'Error: Dolibarr config file was not found. This may means that Dolibarr is not installed yet. Please call the page "/install/index.php" instead of "/install/upgrade.php").';
47}
48require_once $conffile;
49require_once $dolibarr_main_document_root.'/compta/facture/class/facture.class.php';
50require_once $dolibarr_main_document_root.'/comm/propal/class/propal.class.php';
51require_once $dolibarr_main_document_root.'/contrat/class/contrat.class.php';
52require_once $dolibarr_main_document_root.'/commande/class/commande.class.php';
53require_once $dolibarr_main_document_root.'/fourn/class/fournisseur.commande.class.php';
54require_once $dolibarr_main_document_root.'/core/lib/price.lib.php';
55require_once $dolibarr_main_document_root.'/core/class/menubase.class.php';
56require_once $dolibarr_main_document_root.'/core/lib/files.lib.php';
57
58global $langs;
59
60$grant_query = '';
61$step = 2;
62$error = 0;
63
64
65// Cette page peut etre longue. On augmente le delai autorise.
66// Ne fonctionne que si on est pas en safe_mode.
67$err = error_reporting();
68error_reporting(0);
69if (getDolGlobalString('MAIN_OVERRIDE_TIME_LIMIT')) {
70 @set_time_limit((int) $conf->global->MAIN_OVERRIDE_TIME_LIMIT);
71} else {
72 @set_time_limit(600);
73}
74error_reporting($err);
75
76$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : 'auto';
77$langs->setDefaultLang($setuplang);
78$versionfrom = GETPOST("versionfrom", 'alpha', 3) ? GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
79$versionto = GETPOST("versionto", 'alpha', 3) ? GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
80$enablemodules = GETPOST("enablemodules", 'alpha', 3) ? GETPOST("enablemodules", 'alpha', 3) : (empty($argv[3]) ? '' : $argv[3]);
81
82$langs->loadLangs(array("admin", "install", "bills", "suppliers"));
83
84if ($dolibarr_main_db_type == 'mysqli') {
85 $choix = 1;
86}
87if ($dolibarr_main_db_type == 'pgsql') {
88 $choix = 2;
89}
90if ($dolibarr_main_db_type == 'mssql') {
91 $choix = 3;
92}
93
94
95dolibarr_install_syslog("--- upgrade2: entering upgrade2.php page ".$versionfrom." ".$versionto." ".$enablemodules);
96if (!is_object($conf)) {
97 dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
98}
99
100
101
102/*
103 * View
104 */
105
106if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto || preg_match('/version/', $versionto))) {
107 print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\n";
108 print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
109 // Test if batch mode
110 $sapi_type = php_sapi_name();
111 $script_file = basename(__FILE__);
112 $path = __DIR__.'/';
113 if (substr($sapi_type, 0, 3) == 'cli') {
114 print 'Syntax from command line: '.$script_file." x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
115 }
116 exit;
117}
118
119pHeader('', 'step5', GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'upgrade', 'versionfrom='.$versionfrom.'&versionto='.$versionto, '', 'main-inside main-inside-borderbottom');
120
121
122if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) {
123 print '<h3><img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/database.svg" width="20" alt="Database"> ';
124 print '<span class="inline-block">'.$langs->trans('DataMigration').'</span></h3>';
125
126 print '<table border="0" width="100%">';
127
128 // If password is encoded, we decode it
129 if ((!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
130 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
131 if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
132 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
133 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
134 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
135 } else {
136 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
137 }
138 }
139
140 // $conf is already instantiated inside inc.php
141 $conf->db->type = $dolibarr_main_db_type;
142 $conf->db->host = $dolibarr_main_db_host;
143 $conf->db->port = $dolibarr_main_db_port;
144 $conf->db->name = $dolibarr_main_db_name;
145 $conf->db->user = $dolibarr_main_db_user;
146 $conf->db->pass = $dolibarr_main_db_pass;
147
148 $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
149
150 if (!$db->connected) {
151 print '<tr><td colspan="4">'.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).'</td><td class="right">'.$langs->trans('Error').'</td></tr>';
152 dolibarr_install_syslog('upgrade2: failed to connect to database :'.$conf->db->name.' on '.$conf->db->host.' for user '.$conf->db->user, LOG_ERR);
153 $error++;
154 }
155
156 if (!$error) {
157 if ($db->database_selected) {
158 dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name);
159 } else {
160 $error++;
161 }
162 }
163
164 if (empty($dolibarr_main_db_encryption)) {
165 $dolibarr_main_db_encryption = 0;
166 }
167 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
168 if (empty($dolibarr_main_db_cryptkey)) {
169 $dolibarr_main_db_cryptkey = '';
170 }
171 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
172
173 // Load global conf
174 $conf->setValues($db);
175
176
177 $listofentities = array(1);
178
179 // Create the global $hookmanager object
180 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
181 $hookmanager = new HookManager($db);
182 $hookmanager->initHooks(array('upgrade2'));
183
184 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto);
185 $object = new stdClass();
186 $action = "upgrade";
187 $reshook = $hookmanager->executeHooks('doUpgradeBefore', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
188 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
189 // Example: $hookmanager->resArray = array(2, 3, 10);
190 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
191 }
192
193
194 /***************************************************************************************
195 *
196 * Migration of data
197 *
198 ***************************************************************************************/
199
200 // Force to execute this at begin to avoid the new core code into Dolibarr to be broken.
201 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN birth date';
202 $db->query($sql, 1);
203 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemployment date';
204 $db->query($sql, 1);
205 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemploymentend date';
206 $db->query($sql, 1);
207 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_range integer';
208 $db->query($sql, 1);
209 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_c_exp_tax_cat integer';
210 $db->query($sql, 1);
211 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN langs varchar(24)';
212 $db->query($sql, 1);
213 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fieldcomputed text';
214 $db->query($sql, 1);
215 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fielddefault varchar(255)';
216 $db->query($sql, 1);
217 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX."extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
218 $db->query($sql, 1);
219 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN help text';
220 $db->query($sql, 1);
221 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
222 $db->query($sql, 1);
223
224
225 $db->begin();
226
227 foreach ($listofentities as $entity) {
228 // Set $conf context for entity
229 $conf->setEntityValues($db, $entity);
230 // Reset forced setup after the setValues
231 if (defined('SYSLOG_FILE')) {
232 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
233 }
234 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
235
236 if (!$error) {
237 if (count($listofentities) > 1) {
238 print '<tr><td colspan="4">*** '.$langs->trans("Entity").' '.$entity.'</td></tr>'."\n";
239 }
240
241 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
242 // Version to install is DOL_VERSION
243 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', isset($conf->global->MAIN_VERSION_LAST_UPGRADE) ? $conf->global->MAIN_VERSION_LAST_UPGRADE : (isset($conf->global->MAIN_VERSION_LAST_INSTALL) ? $conf->global->MAIN_VERSION_LAST_INSTALL : ''));
244
245 // Chaque action de migration doit renvoyer une ligne sur 4 colonnes avec
246 // dans la 1ere colonne, la description de l'action a faire
247 // dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
248
249 $versiontoarray = explode('.', $versionto);
250 $versionranarray = explode('.', DOL_VERSION);
251
252
253 $afterversionarray = explode('.', '2.0.0');
254 $beforeversionarray = explode('.', '2.7.9');
255 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
256 // Script pour V2 -> V2.1
257 migrate_paiements($db, $langs, $conf);
258
259 migrate_contracts_det($db, $langs, $conf);
260
261 migrate_contracts_date1($db, $langs, $conf);
262
263 migrate_contracts_date2($db, $langs, $conf);
264
265 migrate_contracts_date3($db, $langs, $conf);
266
267 migrate_contracts_open($db, $langs, $conf);
268
269 migrate_modeles($db, $langs, $conf);
270
271 migrate_price_propal($db, $langs, $conf);
272
273 migrate_price_commande($db, $langs, $conf);
274
275 migrate_price_commande_fournisseur($db, $langs, $conf);
276
277 migrate_price_contrat($db, $langs, $conf);
278
279 migrate_paiementfourn_facturefourn($db, $langs, $conf);
280
281
282 // Script pour V2.1 -> V2.2
283 migrate_paiements_orphelins_1($db, $langs, $conf);
284
285 migrate_paiements_orphelins_2($db, $langs, $conf);
286
287 migrate_links_transfert($db, $langs, $conf);
288
289
290 // Script pour V2.2 -> V2.4
291 migrate_commande_expedition($db, $langs, $conf);
292
293 migrate_commande_livraison($db, $langs, $conf);
294
295 migrate_detail_livraison($db, $langs, $conf);
296
297
298 // Script pour V2.5 -> V2.6
299 migrate_stocks($db, $langs, $conf);
300
301
302 // Script pour V2.6 -> V2.7
303 migrate_menus($db, $langs, $conf);
304
305 migrate_commande_deliveryaddress($db, $langs, $conf);
306
307 migrate_restore_missing_links($db, $langs, $conf);
308
309 migrate_rename_directories($db, $langs, $conf, '/compta', '/banque');
310
311 migrate_rename_directories($db, $langs, $conf, '/societe', '/mycompany');
312 }
313
314 // Script for 2.8
315 $afterversionarray = explode('.', '2.7.9');
316 $beforeversionarray = explode('.', '2.8.9');
317 //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
318 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
319 migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx
320
321 migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping');
322
323 migrate_relationship_tables($db, $langs, $conf, 'pr_exp', 'fk_propal', 'propal', 'fk_expedition', 'shipping');
324
325 migrate_relationship_tables($db, $langs, $conf, 'pr_liv', 'fk_propal', 'propal', 'fk_livraison', 'delivery');
326
327 migrate_relationship_tables($db, $langs, $conf, 'co_liv', 'fk_commande', 'commande', 'fk_livraison', 'delivery');
328
329 migrate_relationship_tables($db, $langs, $conf, 'co_pr', 'fk_propale', 'propal', 'fk_commande', 'commande');
330
331 migrate_relationship_tables($db, $langs, $conf, 'fa_pr', 'fk_propal', 'propal', 'fk_facture', 'facture');
332
333 migrate_relationship_tables($db, $langs, $conf, 'co_fa', 'fk_commande', 'commande', 'fk_facture', 'facture');
334
335 migrate_project_user_resp($db, $langs, $conf);
336
337 migrate_project_task_actors($db, $langs, $conf);
338 }
339
340 // Script for 2.9
341 $afterversionarray = explode('.', '2.8.9');
342 $beforeversionarray = explode('.', '2.9.9');
343 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
344 migrate_element_time($db, $langs, $conf);
345
346 migrate_customerorder_shipping($db, $langs, $conf);
347
348 migrate_shipping_delivery($db, $langs, $conf);
349
350 migrate_shipping_delivery2($db, $langs, $conf);
351 }
352
353 // Script for 3.0
354 $afterversionarray = explode('.', '2.9.9');
355 $beforeversionarray = explode('.', '3.0.9');
356 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
357 // No particular code
358 }
359
360 // Script for 3.1
361 $afterversionarray = explode('.', '3.0.9');
362 $beforeversionarray = explode('.', '3.1.9');
363 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
364 migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss');
365
366 migrate_actioncomm_element($db, $langs, $conf);
367 }
368
369 // Script for 3.2
370 $afterversionarray = explode('.', '3.1.9');
371 $beforeversionarray = explode('.', '3.2.9');
372 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
373 migrate_price_contrat($db, $langs, $conf);
374
375 migrate_mode_reglement($db, $langs, $conf);
376
377 migrate_clean_association($db, $langs, $conf);
378 }
379
380 // Script for 3.3
381 $afterversionarray = explode('.', '3.2.9');
382 $beforeversionarray = explode('.', '3.3.9');
383 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
384 migrate_categorie_association($db, $langs, $conf);
385 }
386
387 // Script for 3.4
388 // No specific scripts
389
390 // Tasks to do always and only into last targeted version
391 $afterversionarray = explode('.', '3.6.9'); // target is after this
392 $beforeversionarray = explode('.', '3.7.9'); // target is before this
393 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
394 migrate_event_assignement($db, $langs, $conf);
395 }
396
397 // Scripts for 3.9
398 $afterversionarray = explode('.', '3.7.9');
399 $beforeversionarray = explode('.', '3.8.9');
400 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
401 // No particular code
402 }
403
404 // Scripts for 4.0
405 $afterversionarray = explode('.', '3.9.9');
406 $beforeversionarray = explode('.', '4.0.9');
407 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
408 migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias');
409 }
410
411 // Scripts for 5.0
412 $afterversionarray = explode('.', '4.0.9');
413 $beforeversionarray = explode('.', '5.0.9');
414 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
415 // Migrate to add entity value into llx_societe_remise
416 migrate_remise_entity($db, $langs, $conf);
417
418 // Migrate to add entity value into llx_societe_remise_except
419 migrate_remise_except_entity($db, $langs, $conf);
420 }
421
422 // Scripts for 6.0
423 $afterversionarray = explode('.', '5.0.9');
424 $beforeversionarray = explode('.', '6.0.9');
425 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
426 if (isModEnabled('multicompany')) {
427 global $multicompany_transverse_mode;
428
429 // Only if the transverse mode is not used
430 if (empty($multicompany_transverse_mode)) {
431 // Migrate to add entity value into llx_user_rights
432 migrate_user_rights_entity($db, $langs, $conf);
433
434 // Migrate to add entity value into llx_usergroup_rights
435 migrate_usergroup_rights_entity($db, $langs, $conf);
436 }
437 }
438 }
439
440 // Scripts for 7.0
441 $afterversionarray = explode('.', '6.0.9');
442 $beforeversionarray = explode('.', '7.0.9');
443 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
444 // Migrate contact association
445 migrate_event_assignement_contact($db, $langs, $conf);
446
447 migrate_reset_blocked_log($db, $langs, $conf);
448 }
449
450 // Scripts for 8.0
451 $afterversionarray = explode('.', '7.0.9');
452 $beforeversionarray = explode('.', '8.0.9');
453 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
454 migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract');
455 }
456
457 // Scripts for 9.0
458 $afterversionarray = explode('.', '8.0.9');
459 $beforeversionarray = explode('.', '9.0.9');
460 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
461 //migrate_user_photospath();
462 }
463
464 // Scripts for 11.0
465 $afterversionarray = explode('.', '10.0.9');
466 $beforeversionarray = explode('.', '11.0.9');
467 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
472 }
473
474 // Scripts for 14.0
475 $afterversionarray = explode('.', '13.0.9');
476 $beforeversionarray = explode('.', '14.0.9');
477 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
480 }
481
482 // Scripts for 16.0
483 $afterversionarray = explode('.', '15.0.9');
484 $beforeversionarray = explode('.', '16.0.9');
485 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
488 }
489
490 // Scripts for 17.0
491 $afterversionarray = explode('.', '16.0.9');
492 $beforeversionarray = explode('.', '17.0.9');
493 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
495 }
496
497 // Scripts for 18.0
498 $afterversionarray = explode('.', '17.0.9');
499 $beforeversionarray = explode('.', '18.0.9');
500 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
502 }
503
504 // Scripts for 19.0
505 /*
506 $afterversionarray = explode('.', '18.0.9');
507 $beforeversionarray = explode('.', '19.0.9');
508 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
509 migrate_contractdet_rank();
510 }
511 */
512 }
513
514
515 // Code executed only if migration is LAST ONE. Must always be done.
516 if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3) {
517 // 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)
518 $listofmodule = array(
519 'MAIN_MODULE_ACCOUNTING' => 'newboxdefonly',
520 'MAIN_MODULE_AGENDA' => 'newboxdefonly',
521 'MAIN_MODULE_BOM' => 'menuonly',
522 'MAIN_MODULE_BANQUE' => 'menuonly',
523 'MAIN_MODULE_BARCODE' => 'newboxdefonly',
524 'MAIN_MODULE_CRON' => 'newboxdefonly',
525 'MAIN_MODULE_COMMANDE' => 'newboxdefonly',
526 'MAIN_MODULE_BLOCKEDLOG' => 'noboxes',
527 'MAIN_MODULE_DEPLACEMENT' => 'newboxdefonly',
528 'MAIN_MODULE_DON' => 'newboxdefonly',
529 'MAIN_MODULE_ECM' => 'newboxdefonly',
530 'MAIN_MODULE_EXTERNALSITE' => 'newboxdefonly',
531 'MAIN_MODULE_EXPENSEREPORT' => 'newboxdefonly',
532 'MAIN_MODULE_FACTURE' => 'newboxdefonly',
533 'MAIN_MODULE_FOURNISSEUR' => 'newboxdefonly',
534 'MAIN_MODULE_FICHEINTER' => 'newboxdefonly',
535 'MAIN_MODULE_HOLIDAY' => 'newboxdefonly',
536 'MAIN_MODULE_LOAN' => 'newboxdefonly',
537 'MAIN_MODULE_MARGIN' => 'menuonly',
538 'MAIN_MODULE_MRP' => 'menuonly',
539 'MAIN_MODULE_OPENSURVEY' => 'newboxdefonly',
540 'MAIN_MODULE_PAYBOX' => 'newboxdefonly',
541 'MAIN_MODULE_PRINTING' => 'newboxdefonly',
542 'MAIN_MODULE_PRODUIT' => 'newboxdefonly',
543 'MAIN_MODULE_RECRUITMENT' => 'menuonly',
544 'MAIN_MODULE_RESOURCE' => 'noboxes',
545 'MAIN_MODULE_SALARIES' => 'newboxdefonly',
546 'MAIN_MODULE_SERVICE' => 'newboxdefonly',
547 'MAIN_MODULE_SYSLOG' => 'newboxdefonly',
548 'MAIN_MODULE_SOCIETE' => 'newboxdefonly',
549 'MAIN_MODULE_STRIPE' => 'menuonly',
550 'MAIN_MODULE_TICKET' => 'newboxdefonly',
551 'MAIN_MODULE_TAKEPOS' => 'newboxdefonly',
552 'MAIN_MODULE_USER' => 'newboxdefonly', //This one must be always done and only into last targeted version)
553 'MAIN_MODULE_VARIANTS' => 'newboxdefonly',
554 'MAIN_MODULE_WEBSITE' => 'newboxdefonly',
555 );
556
557 $result = migrate_reload_modules($db, $langs, $conf, $listofmodule);
558 if ($result < 0) {
559 $error++;
560 }
561 // Reload menus (this must be always and only into last targeted version)
562 $result = migrate_reload_menu($db, $langs, $conf);
563 if ($result < 0) {
564 $error++;
565 }
566 }
567
568 // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...'
569 // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line.
570 if (!$error && $enablemodules) {
571 // Reload modules (this must be always done and only into last targeted version)
572 $listofmodules = array();
573 $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules);
574 $tmplistofmodules = explode(',', $enablemodules);
575 foreach ($tmplistofmodules as $value) {
576 $listofmodules[$value] = 'forceactivate';
577 }
578
579 $resultreloadmodules = migrate_reload_modules($db, $langs, $conf, $listofmodules, 1);
580 if ($resultreloadmodules < 0) {
581 $error++;
582 }
583 }
584
585
586 // Can call a dedicated external upgrade process with hook doUpgradeAfterDB()
587 if (!$error) {
588 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
589 $object = new stdClass();
590 $action = "upgrade";
591 $reshook = $hookmanager->executeHooks('doUpgradeAfterDB', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
592 if ($hookmanager->resNbOfHooks > 0) {
593 if ($reshook < 0) {
594 print '<tr><td colspan="4">';
595 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
596 print $hookmanager->error;
597 print "<!-- (".$reshook.") -->";
598 print '</td></tr>';
599 } else {
600 print '<tr class="trforrunsql"><td colspan="4">';
601 print '<b>'.$langs->trans('UpgradeExternalModule').' (DB)</b>: <span class="ok">OK</span>';
602 print "<!-- (".$reshook.") -->";
603 print '</td></tr>';
604 }
605 } else {
606 //if (!empty($conf->modules))
607 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
608 print '<tr class="trforrunsql"><td colspan="4">';
609 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterDB");
610 print '</td></tr>';
611 }
612 }
613 }
614 }
615
616 print '</table>';
617
618 if (!$error) {
619 // Set constant to ask to remake a new ping to inform about upgrade (if first ping was done and OK)
620 $sql = 'UPDATE '.MAIN_DB_PREFIX."const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'";
621 $db->query($sql, 1);
622 }
623
624 // We always commit.
625 // Process is designed so we can run it several times whatever is situation.
626 $db->commit();
627
628
629 /***************************************************************************************
630 *
631 * Migration of files
632 *
633 ***************************************************************************************/
634
635 foreach ($listofentities as $entity) {
636 // Set $conf context for entity
637 $conf->setEntityValues($db, $entity);
638 // Reset forced setup after the setValues
639 if (defined('SYSLOG_FILE')) {
640 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
641 }
642 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
643
644
645 // Copy directory medias
646 $srcroot = DOL_DOCUMENT_ROOT.'/install/medias';
647 $destroot = DOL_DATA_ROOT.'/medias';
648 dolCopyDir($srcroot, $destroot, 0, 0);
649
650
651 // Actions for all versions (no database change but delete some files and directories)
652 migrate_delete_old_files($db, $langs, $conf);
653 migrate_delete_old_dir($db, $langs, $conf);
654 // Actions for all versions (no database change but create some directories)
655 dol_mkdir(DOL_DATA_ROOT.'/bank');
656 // Actions for all versions (no database change but rename some directories)
657 migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits');
658
659
660 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
661 $object = new stdClass();
662 $action = "upgrade";
663 $reshook = $hookmanager->executeHooks('doUpgradeAfterFiles', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
664 if ($hookmanager->resNbOfHooks > 0) {
665 if ($reshook < 0) {
666 print '<tr><td colspan="4">';
667 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
668 print $hookmanager->error;
669 print "<!-- (".$reshook.") -->";
670 print '</td></tr>';
671 } else {
672 print '<tr class="trforrunsql"><td colspan="4">';
673 print '<b>'.$langs->trans('UpgradeExternalModule').' (Files)</b>: <span class="ok">OK</span>';
674 print "<!-- (".$reshook.") -->";
675 print '</td></tr>';
676 }
677 } else {
678 //if (!empty($conf->modules))
679 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
680 print '<tr class="trforrunsql"><td colspan="4">';
681 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterFiles");
682 print '</td></tr>';
683 }
684 }
685 }
686
687 $db->close();
688
689 $silent = 0;
690 if (!$silent) {
691 print '<table width="100%">';
692 print '<tr><td style="width: 30%">'.$langs->trans("MigrationFinished").'</td>';
693 print '<td class="right">';
694 if ($error == 0) {
695 //print '<span class="ok">'.$langs->trans("OK").'</span> - '; // $error = 0 does not mean there is no error (error are not always trapped)
696 } else {
697 print '<span class="error">'.$langs->trans("Error").'</span> - ';
698 }
699
700 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
701 print '<script type="text/javascript">
702 jQuery(document).ready(function() {
703 function init_trrunsql()
704 {
705 console.log("toggle .trforrunsql");
706 jQuery(".trforrunsql").toggle();
707 }
708 init_trrunsql();
709 jQuery(".trforrunsqlshowhide").click(function() {
710 init_trrunsql();
711 });
712 });
713 </script>';
714 print '<a class="trforrunsqlshowhide" href="#">'.$langs->trans("ShowHideDetails").'</a>';
715 //}
716
717 print '</td></tr>'."\n";
718 print '</table>';
719 }
720
721 //print '<div><br>'.$langs->trans("MigrationFinished").'</div>';
722} else {
723 print '<div class="error">'.$langs->trans('ErrorWrongParameters').'</div>';
724 $error++;
725}
726
727$ret = 0;
728if ($error && isset($argv[1])) {
729 $ret = 1;
730}
731dolibarr_install_syslog("Exit ".$ret);
732
733dolibarr_install_syslog("--- upgrade2: end");
734pFooter($error ? 2 : 0, $setuplang);
735
736if ($db->connected) {
737 $db->close();
738}
739
740// Return code if ran from command line
741if ($ret) {
742 exit($ret);
743}
744
745
746
755function migrate_paiements($db, $langs, $conf)
756{
757 print '<tr><td colspan="4">';
758
759 print '<br>';
760 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
761
762 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
763 $obj = $db->fetch_object($result);
764 if ($obj) {
765 $sql = "SELECT p.rowid, p.fk_facture, p.amount";
766 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
767 $sql .= " WHERE p.fk_facture > 0";
768
769 $resql = $db->query($sql);
770
771 dolibarr_install_syslog("upgrade2::migrate_paiements");
772 if ($resql) {
773 $i = 0;
774 $row = array();
775 $num = $db->num_rows($resql);
776
777 while ($i < $num) {
778 $obj = $db->fetch_object($resql);
779 $row[$i][0] = $obj->rowid;
780 $row[$i][1] = $obj->fk_facture;
781 $row[$i][2] = $obj->amount;
782 $i++;
783 }
784 } else {
785 dol_print_error($db);
786 }
787
788 if ($num) {
789 print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."<br>\n";
790 if ($db->begin()) {
791 $res = 0;
792 $num = count($row);
793 for ($i = 0; $i < $num; $i++) {
794 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
795 $sql .= " VALUES (".((int) $row[$i][1]).",".((int) $row[$i][0]).",".((float) $row[$i][2]).")";
796
797 $res += $db->query($sql);
798
799 $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
800
801 $res += $db->query($sql);
802
803 print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."<br>\n";
804 }
805 }
806
807 if ($res == (2 * count($row))) {
808 $db->commit();
809 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
810 } else {
811 $db->rollback();
812 print $langs->trans('MigrationUpdateFailed').'<br>';
813 }
814 } else {
815 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
816 }
817 } else {
818 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
819 }
820
821 print '</td></tr>';
822}
823
834function migrate_paiements_orphelins_1($db, $langs, $conf)
835{
836 print '<tr><td colspan="4">';
837
838 print '<br>';
839 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
840
841 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
842 $obj = $db->fetch_object($result);
843 if ($obj) {
844 // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
845 $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
846 $sql .= " bu2.url_id as socid";
847 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
848 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
849 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
850 $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
851 $sql .= " AND b.rappro = 1";
852 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
853
854 $resql = $db->query($sql);
855
856 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1");
857 $row = array();
858 if ($resql) {
859 $i = $j = 0;
860 $num = $db->num_rows($resql);
861
862 while ($i < $num) {
863 $obj = $db->fetch_object($resql);
864 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
865 $row[$j]['paymentid'] = $obj->rowid; // paymentid
866 $row[$j]['pamount'] = $obj->pamount;
867 $row[$j]['fk_bank'] = $obj->fk_bank;
868 $row[$j]['bamount'] = $obj->bamount;
869 $row[$j]['socid'] = $obj->socid;
870 $row[$j]['datec'] = $obj->datec;
871 $j++;
872 }
873 $i++;
874 }
875 } else {
876 dol_print_error($db);
877 }
878
879 if (count($row)) {
880 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."<br>\n";
881 $db->begin();
882
883 $res = 0;
884 $num = count($row);
885 for ($i = 0; $i < $num; $i++) {
886 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
887 print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' bamount='.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'<br>';
888 }
889
890 // On cherche facture sans lien paiement et du meme montant et pour meme societe.
891 $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
892 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
893 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
894 $sql .= " AND pf.fk_facture IS NULL";
895 $sql .= " ORDER BY f.fk_statut";
896 //print $sql.'<br>';
897 $resql = $db->query($sql);
898 if ($resql) {
899 $num = $db->num_rows($resql);
900 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
901 if ($num >= 1) {
902 $obj = $db->fetch_object($resql);
903 $facid = $obj->rowid;
904
905 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
906 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
907
908 $res += $db->query($sql);
909
910 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
911 }
912 } else {
913 print 'ERROR';
914 }
915 }
916
917 if ($res > 0) {
918 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
919 } else {
920 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
921 }
922
923 $db->commit();
924 } else {
925 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
926 }
927 } else {
928 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
929 }
930
931 print '</td></tr>';
932}
933
944function migrate_paiements_orphelins_2($db, $langs, $conf)
945{
946 print '<tr><td colspan="4">';
947
948 print '<br>';
949 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
950
951 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
952 $obj = $db->fetch_object($result);
953 if ($obj) {
954 // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
955 $sql = "SELECT distinct p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
956 $sql .= " bu2.url_id as socid";
957 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
958 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
959 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
960 $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
961 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
962
963 $resql = $db->query($sql);
964
965 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2");
966 $row = array();
967 if ($resql) {
968 $i = $j = 0;
969 $num = $db->num_rows($resql);
970
971 while ($i < $num) {
972 $obj = $db->fetch_object($resql);
973 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
974 $row[$j]['paymentid'] = $obj->rowid; // paymentid
975 $row[$j]['pamount'] = $obj->pamount;
976 $row[$j]['fk_bank'] = $obj->fk_bank;
977 $row[$j]['bamount'] = $obj->bamount;
978 $row[$j]['socid'] = $obj->socid;
979 $row[$j]['datec'] = $obj->datec;
980 $j++;
981 }
982 $i++;
983 }
984 } else {
985 dol_print_error($db);
986 }
987
988 $nberr = 0;
989
990 $num = count($row);
991 if ($num) {
992 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."<br>\n";
993 $db->begin();
994
995 $res = 0;
996 for ($i = 0; $i < $num; $i++) {
997 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
998 print '* '.$row[$i]['datec'].' paymentid='.$row[$i]['paymentid'].' pamount='.$row[$i]['pamount'].' fk_bank='.$row[$i]['fk_bank'].' '.$row[$i]['bamount'].' socid='.$row[$i]['socid'].'<br>';
999 }
1000
1001 // On cherche facture sans lien paiement et du meme montant et pour meme societe.
1002 $sql = " SELECT distinct f.rowid from ".MAIN_DB_PREFIX."facture as f";
1003 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1004 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1005 $sql .= " AND pf.fk_facture IS NULL";
1006 $sql .= " ORDER BY f.fk_statut";
1007 //print $sql.'<br>';
1008 $resql = $db->query($sql);
1009 if ($resql) {
1010 $num = $db->num_rows($resql);
1011 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1012 if ($num >= 1) {
1013 $obj = $db->fetch_object($resql);
1014 $facid = $obj->rowid;
1015
1016 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1017 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1018
1019 $res += $db->query($sql);
1020
1021 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1022 }
1023 } else {
1024 print 'ERROR';
1025 $nberr++;
1026 }
1027 }
1028
1029 if ($res > 0) {
1030 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1031 } else {
1032 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1033 }
1034
1035 $db->commit();
1036 } else {
1037 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1038 }
1039
1040 // Delete obsolete fields fk_facture
1041 $db->begin();
1042
1043 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture";
1044 $db->query($sql);
1045
1046 if (!$nberr) {
1047 $db->commit();
1048 } else {
1049 print 'ERROR';
1050 $db->rollback();
1051 }
1052 } else {
1053 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1054 }
1055
1056 print '</td></tr>';
1057}
1058
1059
1068function migrate_contracts_det($db, $langs, $conf)
1069{
1070 print '<tr><td colspan="4">';
1071
1072 $nberr = 0;
1073
1074 print '<br>';
1075 print '<b>'.$langs->trans('MigrationContractsUpdate')."</b><br>\n";
1076
1077 $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1078 $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1079 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
1080 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p";
1081 $sql .= " ON c.fk_product = p.rowid";
1082 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd";
1083 $sql .= " ON c.rowid=cd.fk_contrat";
1084 $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1085 $resql = $db->query($sql);
1086
1087 dolibarr_install_syslog("upgrade2::migrate_contracts_det");
1088 if ($resql) {
1089 $i = 0;
1090 $row = array();
1091 $num = $db->num_rows($resql);
1092
1093 if ($num) {
1094 print $langs->trans('MigrationContractsNumberToUpdate', $num)."<br>\n";
1095 $db->begin();
1096
1097 while ($i < $num) {
1098 $obj = $db->fetch_object($resql);
1099
1100 $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet (";
1101 $sql .= "fk_contrat, fk_product, statut, label, description,";
1102 $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1103 $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)";
1104 $sql .= " VALUES (";
1105 $sql .= ((int) $obj->cref).", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).", ";
1106 $sql .= "0, ";
1107 $sql .= "'".$db->escape($obj->label)."', null, ";
1108 $sql .= ($obj->date_contrat ? "'".$db->idate($db->jdate($obj->date_contrat))."'" : "null").", ";
1109 $sql .= "null, ";
1110 $sql .= "null, ";
1111 $sql .= ((float) $obj->tva_tx).", 1, ";
1112 $sql .= ((float) $obj->price).", ".((float) $obj->price).", ".((int) $obj->fk_user_author).",";
1113 $sql .= "null";
1114 $sql .= ")";
1115
1116 if ($db->query($sql)) {
1117 print $langs->trans('MigrationContractsLineCreation', $obj->cref)."<br>\n";
1118 } else {
1119 dol_print_error($db);
1120 $nberr++;
1121 }
1122
1123 $i++;
1124 }
1125
1126 if (!$nberr) {
1127 // $db->rollback();
1128 $db->commit();
1129 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1130 } else {
1131 $db->rollback();
1132 print $langs->trans('MigrationUpdateFailed').'<br>';
1133 }
1134 } else {
1135 print $langs->trans('MigrationContractsNothingToUpdate')."<br>\n";
1136 }
1137 } else {
1138 print $langs->trans('MigrationContractsFieldDontExist')."<br>\n";
1139 // dol_print_error($db);
1140 }
1141
1142 print '</td></tr>';
1143}
1144
1153function migrate_links_transfert($db, $langs, $conf)
1154{
1155 print '<tr><td colspan="4">';
1156
1157 $nberr = 0;
1158
1159 print '<br>';
1160 print '<b>'.$langs->trans('MigrationBankTransfertsUpdate')."</b><br>\n";
1161
1162 $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1163 $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba";
1164 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid";
1165 $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1166 $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec";
1167 $sql .= " AND bu.fk_bank IS NULL";
1168 $resql = $db->query($sql);
1169
1170 dolibarr_install_syslog("upgrade2::migrate_links_transfert");
1171 if ($resql) {
1172 $i = 0;
1173 $row = array();
1174 $num = $db->num_rows($resql);
1175
1176 if ($num) {
1177 print $langs->trans('MigrationBankTransfertsToUpdate', $num)."<br>\n";
1178 $db->begin();
1179
1180 while ($i < $num) {
1181 $obj = $db->fetch_object($resql);
1182
1183 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
1184 $sql .= "fk_bank, url_id, url, label, type";
1185 $sql .= ")";
1186 $sql .= " VALUES (";
1187 $sql .= $obj->barowid.",".$obj->bbrowid.", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1188 $sql .= ")";
1189
1190 //print $sql.'<br>';
1191 dolibarr_install_syslog("migrate_links_transfert");
1192
1193 if (!$db->query($sql)) {
1194 dol_print_error($db);
1195 $nberr++;
1196 }
1197
1198 $i++;
1199 }
1200
1201 if (!$nberr) {
1202 // $db->rollback();
1203 $db->commit();
1204 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1205 } else {
1206 $db->rollback();
1207 print $langs->trans('MigrationUpdateFailed').'<br>';
1208 }
1209 } else {
1210 print $langs->trans('MigrationBankTransfertsNothingToUpdate')."<br>\n";
1211 }
1212 } else {
1213 dol_print_error($db);
1214 }
1215
1216 print '</td></tr>';
1217}
1218
1227function migrate_contracts_date1($db, $langs, $conf)
1228{
1229 print '<tr><td colspan="4">';
1230
1231 print '<br>';
1232 print '<b>'.$langs->trans('MigrationContractsEmptyDatesUpdate')."</b><br>\n";
1233
1234 $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null";
1235 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1236 $resql = $db->query($sql);
1237 if (!$resql) {
1238 dol_print_error($db);
1239 }
1240 if ($db->affected_rows($resql) > 0) {
1241 print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."<br>\n";
1242 } else {
1243 print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."<br>\n";
1244 }
1245
1246 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null";
1247 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1248 $resql = $db->query($sql);
1249 if (!$resql) {
1250 dol_print_error($db);
1251 }
1252 if ($db->affected_rows($resql) > 0) {
1253 print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."<br>\n";
1254 } else {
1255 print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."<br>\n";
1256 }
1257
1258 print '</td></tr>';
1259}
1260
1269function migrate_contracts_date2($db, $langs, $conf)
1270{
1271 print '<tr><td colspan="4">';
1272
1273 $nberr = 0;
1274
1275 print '<br>';
1276 print '<b>'.$langs->trans('MigrationContractsInvalidDatesUpdate')."</b><br>\n";
1277
1278 $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1279 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
1280 $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
1281 $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1282 $sql .= " GROUP BY c.rowid, c.date_contrat";
1283 $resql = $db->query($sql);
1284
1285 dolibarr_install_syslog("upgrade2::migrate_contracts_date2");
1286 if ($resql) {
1287 $i = 0;
1288 $row = array();
1289 $num = $db->num_rows($resql);
1290
1291 if ($num) {
1292 $nbcontratsmodifie = 0;
1293 $db->begin();
1294
1295 while ($i < $num) {
1296 $obj = $db->fetch_object($resql);
1297 if ($obj->date_contrat > $obj->datemin) {
1298 $datemin = $db->jdate($obj->datemin);
1299
1300 print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."<br>\n";
1301 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1302 $sql .= " SET date_contrat='".$db->idate($datemin)."'";
1303 $sql .= " WHERE rowid = ".((int) $obj->cref);
1304 $resql2 = $db->query($sql);
1305 if (!$resql2) {
1306 dol_print_error($db);
1307 }
1308
1309 $nbcontratsmodifie++;
1310 }
1311 $i++;
1312 }
1313
1314 $db->commit();
1315
1316 if ($nbcontratsmodifie) {
1317 print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."<br>\n";
1318 } else {
1319 print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."<br>\n";
1320 }
1321 }
1322 } else {
1323 dol_print_error($db);
1324 }
1325
1326 print '</td></tr>';
1327}
1328
1337function migrate_contracts_date3($db, $langs, $conf)
1338{
1339 print '<tr><td colspan="4">';
1340
1341 print '<br>';
1342 print '<b>'.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."</b><br>\n";
1343
1344 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat";
1345 dolibarr_install_syslog("upgrade2::migrate_contracts_date3");
1346 $resql = $db->query($sql);
1347 if (!$resql) {
1348 dol_print_error($db);
1349 }
1350 if ($db->affected_rows($resql) > 0) {
1351 print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."<br>\n";
1352 } else {
1353 print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."<br>\n";
1354 }
1355
1356 print '</td></tr>';
1357}
1358
1367function migrate_contracts_open($db, $langs, $conf)
1368{
1369 print '<tr><td colspan="4">';
1370
1371 print '<br>';
1372 print '<b>'.$langs->trans('MigrationReopeningContracts')."</b><br>\n";
1373
1374 $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd";
1375 $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1376 dolibarr_install_syslog("upgrade2::migrate_contracts_open");
1377 $resql = $db->query($sql);
1378 if (!$resql) {
1379 dol_print_error($db);
1380 }
1381 if ($db->affected_rows($resql) > 0) {
1382 $i = 0;
1383 $row = array();
1384 $num = $db->num_rows($resql);
1385
1386 if ($num) {
1387 $nbcontratsmodifie = 0;
1388 $db->begin();
1389
1390 while ($i < $num) {
1391 $obj = $db->fetch_object($resql);
1392
1393 print $langs->trans('MigrationReopenThisContract', $obj->cref)."<br>\n";
1394 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1395 $sql .= " SET statut = 1";
1396 $sql .= " WHERE rowid = ".((int) $obj->cref);
1397 $resql2 = $db->query($sql);
1398 if (!$resql2) {
1399 dol_print_error($db);
1400 }
1401
1402 $nbcontratsmodifie++;
1403
1404 $i++;
1405 }
1406
1407 $db->commit();
1408
1409 if ($nbcontratsmodifie) {
1410 print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."<br>\n";
1411 } else {
1412 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1413 }
1414 }
1415 } else {
1416 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1417 }
1418
1419 print '</td></tr>';
1420}
1421
1430function migrate_paiementfourn_facturefourn($db, $langs, $conf)
1431{
1432 global $bc;
1433
1434 print '<tr><td colspan="4">';
1435 print '<br>';
1436 print '<b>'.$langs->trans('SuppliersInvoices')."</b><br>\n";
1437 print '</td></tr>';
1438
1439 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn");
1440 $obj = $db->fetch_object($result);
1441 if ($obj) {
1442 $error = 0;
1443 $nb = 0;
1444
1445 $select_sql = 'SELECT rowid, fk_facture_fourn, amount';
1446 $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn';
1447 $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL';
1448
1449 dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn");
1450 $select_resql = $db->query($select_sql);
1451 if ($select_resql) {
1452 $select_num = $db->num_rows($select_resql);
1453 $i = 0;
1454
1455 // Pour chaque paiement fournisseur, on insere une ligne dans paiementfourn_facturefourn
1456 while (($i < $select_num) && (!$error)) {
1457 $select_obj = $db->fetch_object($select_resql);
1458
1459 // Verifier si la ligne est deja dans la nouvelle table. On ne veut pas inserer de doublons.
1460 $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn';
1461 $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
1462 $check_sql .= ' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1463 $check_resql = $db->query($check_sql);
1464 if ($check_resql) {
1465 $check_num = $db->num_rows($check_resql);
1466 if ($check_num == 0) {
1467 $db->begin();
1468
1469 if ($nb == 0) {
1470 print '<tr><td colspan="4" class="nowrap"><b>'.$langs->trans('SuppliersInvoices').'</b></td></tr>';
1471 print '<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans('Amount').'</td><td>&nbsp;</td></tr>';
1472 }
1473
1474 print '<tr class="oddeven">';
1475 print '<td>'.$select_obj->rowid.'</td><td>'.$select_obj->fk_facture_fourn.'</td><td>'.$select_obj->amount.'</td>';
1476
1477 $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET ';
1478 $insert_sql .= ' fk_paiementfourn = \''.$select_obj->rowid.'\',';
1479 $insert_sql .= ' fk_facturefourn = \''.$select_obj->fk_facture_fourn.'\',';
1480 $insert_sql .= ' amount = \''.$select_obj->amount.'\'';
1481 $insert_resql = $db->query($insert_sql);
1482
1483 if ($insert_resql) {
1484 $nb++;
1485 print '<td><span class="ok">'.$langs->trans("OK").'</span></td>';
1486 } else {
1487 print '<td><span class="error">Error on insert</span></td>';
1488 $error++;
1489 }
1490 print '</tr>';
1491 }
1492 } else {
1493 $error++;
1494 }
1495 $i++;
1496 }
1497 } else {
1498 $error++;
1499 }
1500
1501 if (!$error) {
1502 if (!$nb) {
1503 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1504 }
1505 $db->commit();
1506
1507 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn";
1508 $db->query($sql);
1509 } else {
1510 print '<tr><td>'.$langs->trans("Error").'</td></tr>';
1511 $db->rollback();
1512 }
1513 } else {
1514 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1515 }
1516}
1517
1526function migrate_price_facture($db, $langs, $conf)
1527{
1528 $err = 0;
1529
1530 $tmpmysoc = new Societe($db);
1531 $tmpmysoc->setMysoc($conf);
1532
1533 $db->begin();
1534
1535 print '<tr><td colspan="4">';
1536
1537 print '<br>';
1538 print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n";
1539
1540 // List of invoice lines not up to date
1541 $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1542 $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1543 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
1544 $sql .= " WHERE fd.fk_facture = f.rowid";
1545 $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1546 //print $sql;
1547
1548 dolibarr_install_syslog("upgrade2::migrate_price_facture");
1549 $resql = $db->query($sql);
1550 if ($resql) {
1551 $num = $db->num_rows($resql);
1552 $i = 0;
1553 if ($num) {
1554 while ($i < $num) {
1555 $obj = $db->fetch_object($resql);
1556
1557 $rowid = $obj->rowid;
1558 $qty = $obj->qty;
1559 $pu = $obj->subprice;
1560 $vatrate = $obj->vatrate;
1561 $remise_percent = $obj->remise_percent;
1562 $remise_percent_global = $obj->remise_percent_global;
1563 $total_ttc_f = $obj->total_ttc_f;
1564 $info_bits = $obj->info_bits;
1565
1566 // On met a jour les 3 nouveaux champs
1567 $facligne = new FactureLigne($db);
1568 $facligne->fetch($rowid);
1569
1570 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1571 $total_ht = $result[0];
1572 $total_tva = $result[1];
1573 $total_ttc = $result[2];
1574
1575 $facligne->total_ht = $total_ht;
1576 $facligne->total_tva = $total_tva;
1577 $facligne->total_ttc = $total_ttc;
1578
1579 dolibarr_install_syslog("upgrade2: line ".$rowid.": facid=".$obj->facid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc);
1580 print '. ';
1581 $facligne->update_total();
1582
1583
1584 /* On touche a facture mere uniquement si total_ttc = 0 */
1585 if (!$total_ttc_f) {
1586 $facture = new Facture($db);
1587 $facture->id = $obj->facid;
1588
1589 if ($facture->fetch($facture->id) >= 0) {
1590 if ($facture->update_price() > 0) {
1591 //print $facture->id;
1592 } else {
1593 print "Error id=".$facture->id;
1594 $err++;
1595 }
1596 } else {
1597 print "Error #3";
1598 $err++;
1599 }
1600 }
1601 print " ";
1602
1603 $i++;
1604 }
1605 } else {
1606 print $langs->trans("AlreadyDone");
1607 }
1608 $db->free($resql);
1609
1610 $db->commit();
1611 } else {
1612 print "Error #1 ".$db->error();
1613 $err++;
1614
1615 $db->rollback();
1616 }
1617
1618 print '<br>';
1619
1620 print '</td></tr>';
1621}
1622
1631function migrate_price_propal($db, $langs, $conf)
1632{
1633 $tmpmysoc = new Societe($db);
1634 $tmpmysoc->setMysoc($conf);
1635
1636 $db->begin();
1637
1638 print '<tr><td colspan="4">';
1639
1640 print '<br>';
1641 print '<b>'.$langs->trans('MigrationProposal')."</b><br>\n";
1642
1643 // List of proposal lines not up to date
1644 $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1645 $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global";
1646 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p";
1647 $sql .= " WHERE pd.fk_propal = p.rowid";
1648 $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1649
1650 dolibarr_install_syslog("upgrade2::migrate_price_propal");
1651 $resql = $db->query($sql);
1652 if ($resql) {
1653 $num = $db->num_rows($resql);
1654 $i = 0;
1655 if ($num) {
1656 while ($i < $num) {
1657 $obj = $db->fetch_object($resql);
1658
1659 $rowid = $obj->rowid;
1660 $qty = $obj->qty;
1661 $pu = $obj->subprice;
1662 $vatrate = $obj->vatrate;
1663 $remise_percent = $obj->remise_percent;
1664 $remise_percent_global = $obj->remise_percent_global;
1665 $info_bits = $obj->info_bits;
1666
1667 // On met a jour les 3 nouveaux champs
1668 $propalligne = new PropaleLigne($db);
1669 $propalligne->fetch($rowid);
1670
1671 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1672 $total_ht = $result[0];
1673 $total_tva = $result[1];
1674 $total_ttc = $result[2];
1675
1676 $propalligne->total_ht = $total_ht;
1677 $propalligne->total_tva = $total_tva;
1678 $propalligne->total_ttc = $total_ttc;
1679
1680 dolibarr_install_syslog("upgrade2: Line ".$rowid.": propalid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc);
1681 print '. ';
1682 $propalligne->update_total();
1683
1684 $i++;
1685 }
1686 } else {
1687 print $langs->trans("AlreadyDone");
1688 }
1689
1690 $db->free($resql);
1691
1692 $db->commit();
1693 } else {
1694 print "Error #1 ".$db->error();
1695
1696 $db->rollback();
1697 }
1698
1699 print '<br>';
1700
1701 print '</td></tr>';
1702}
1703
1712function migrate_price_contrat($db, $langs, $conf)
1713{
1714 $db->begin();
1715
1716 $tmpmysoc = new Societe($db);
1717 $tmpmysoc->setMysoc($conf);
1718 if (empty($tmpmysoc->country_id)) {
1719 $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
1720 }
1721
1722 print '<tr><td colspan="4">';
1723
1724 print '<br>';
1725 print '<b>'.$langs->trans('MigrationContract')."</b><br>\n";
1726
1727 // List of contract lines not up to date
1728 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1729 $sql .= " c.rowid as contratid";
1730 $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
1731 $sql .= " WHERE cd.fk_contrat = c.rowid";
1732 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1733
1734 dolibarr_install_syslog("upgrade2::migrate_price_contrat");
1735 $resql = $db->query($sql);
1736 if ($resql) {
1737 $num = $db->num_rows($resql);
1738 $i = 0;
1739 if ($num) {
1740 while ($i < $num) {
1741 $obj = $db->fetch_object($resql);
1742
1743 $rowid = $obj->rowid;
1744 $qty = $obj->qty;
1745 $pu = $obj->subprice;
1746 $vatrate = $obj->vatrate;
1747 $remise_percent = $obj->remise_percent;
1748 $info_bits = $obj->info_bits;
1749
1750 // On met a jour les 3 nouveaux champs
1751 $contratligne = new ContratLigne($db);
1752 //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis
1753 $contratligne->fetch($rowid);
1754
1755 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1756 $total_ht = $result[0];
1757 $total_tva = $result[1];
1758 $total_ttc = $result[2];
1759
1760 $contratligne->total_ht = $total_ht;
1761 $contratligne->total_tva = $total_tva;
1762 $contratligne->total_ttc = $total_ttc;
1763
1764 dolibarr_install_syslog("upgrade2: Line ".$rowid.": contratdetid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." -> ".$total_ht.", ".$total_tva." , ".$total_ttc);
1765 print '. ';
1766 $contratligne->update_total();
1767
1768 $i++;
1769 }
1770 } else {
1771 print $langs->trans("AlreadyDone");
1772 }
1773
1774 $db->free($resql);
1775
1776 $db->commit();
1777 } else {
1778 print "Error #1 ".$db->error();
1779
1780 $db->rollback();
1781 }
1782
1783 print '<br>';
1784
1785 print '</td></tr>';
1786}
1787
1796function migrate_price_commande($db, $langs, $conf)
1797{
1798 $db->begin();
1799
1800 $tmpmysoc = new Societe($db);
1801 $tmpmysoc->setMysoc($conf);
1802
1803 print '<tr><td colspan="4">';
1804
1805 print '<br>';
1806 print '<b>'.$langs->trans('MigrationOrder')."</b><br>\n";
1807
1808 // List of sales orders lines not up to date
1809 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1810 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
1811 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c";
1812 $sql .= " WHERE cd.fk_commande = c.rowid";
1813 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1814
1815 dolibarr_install_syslog("upgrade2::migrate_price_commande");
1816 $resql = $db->query($sql);
1817 if ($resql) {
1818 $num = $db->num_rows($resql);
1819 $i = 0;
1820 if ($num) {
1821 while ($i < $num) {
1822 $obj = $db->fetch_object($resql);
1823
1824 $rowid = $obj->rowid;
1825 $qty = $obj->qty;
1826 $pu = $obj->subprice;
1827 $vatrate = $obj->vatrate;
1828 $remise_percent = $obj->remise_percent;
1829 $remise_percent_global = $obj->remise_percent_global;
1830 $info_bits = $obj->info_bits;
1831
1832 // On met a jour les 3 nouveaux champs
1833 $commandeligne = new OrderLine($db);
1834 $commandeligne->fetch($rowid);
1835
1836 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
1837 $total_ht = $result[0];
1838 $total_tva = $result[1];
1839 $total_ttc = $result[2];
1840
1841 $commandeligne->total_ht = $total_ht;
1842 $commandeligne->total_tva = $total_tva;
1843 $commandeligne->total_ttc = $total_ttc;
1844
1845 dolibarr_install_syslog("upgrade2: Line ".$rowid." : commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc);
1846 print '. ';
1847 $commandeligne->update_total();
1848
1849 $i++;
1850 }
1851 } else {
1852 print $langs->trans("AlreadyDone");
1853 }
1854
1855 $db->free($resql);
1856
1857 /*
1858 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
1859 $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
1860 $resql=$db->query($sql);
1861 if (! $resql)
1862 {
1863 dol_print_error($db);
1864 }
1865 */
1866
1867 $db->commit();
1868 } else {
1869 print "Error #1 ".$db->error();
1870
1871 $db->rollback();
1872 }
1873
1874 print '<br>';
1875
1876 print '</td></tr>';
1877}
1878
1887function migrate_price_commande_fournisseur($db, $langs, $conf)
1888{
1889 global $mysoc;
1890
1891 $db->begin();
1892
1893 $tmpmysoc = new Societe($db);
1894 $tmpmysoc->setMysoc($conf);
1895
1896 print '<tr><td colspan="4">';
1897
1898 print '<br>';
1899 print '<b>'.$langs->trans('MigrationSupplierOrder')."</b><br>\n";
1900
1901 // List of purchase order lines not up to date
1902 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1903 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
1904 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c";
1905 $sql .= " WHERE cd.fk_commande = c.rowid";
1906 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1907
1908 dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur");
1909 $resql = $db->query($sql);
1910 if ($resql) {
1911 $num = $db->num_rows($resql);
1912 $i = 0;
1913 if ($num) {
1914 while ($i < $num) {
1915 $obj = $db->fetch_object($resql);
1916
1917 $rowid = $obj->rowid;
1918 $qty = $obj->qty;
1919 $pu = $obj->subprice;
1920 $vatrate = $obj->vatrate;
1921 $remise_percent = $obj->remise_percent;
1922 $remise_percent_global = $obj->remise_percent_global;
1923 $info_bits = $obj->info_bits;
1924
1925 // On met a jour les 3 nouveaux champs
1926 $commandeligne = new CommandeFournisseurLigne($db);
1927 $commandeligne->fetch($rowid);
1928
1929 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $mysoc);
1930 $total_ht = $result[0];
1931 $total_tva = $result[1];
1932 $total_ttc = $result[2];
1933
1934 $commandeligne->total_ht = $total_ht;
1935 $commandeligne->total_tva = $total_tva;
1936 $commandeligne->total_ttc = $total_ttc;
1937
1938 dolibarr_install_syslog("upgrade2: Line ".$rowid.": commandeid=".$obj->rowid." pu=".$pu." qty=".$qty." vatrate=".$vatrate." remise_percent=".$remise_percent." remise_global=".$remise_percent_global." -> ".$total_ht.", ".$total_tva.", ".$total_ttc);
1939 print '. ';
1940 $commandeligne->update_total();
1941
1942 $i++;
1943 }
1944 } else {
1945 print $langs->trans("AlreadyDone");
1946 }
1947
1948 $db->free($resql);
1949
1950 /*
1951 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
1952 $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
1953 $resql=$db->query($sql);
1954 if (! $resql)
1955 {
1956 dol_print_error($db);
1957 }
1958 */
1959
1960 $db->commit();
1961 } else {
1962 print "Error #1 ".$db->error();
1963
1964 $db->rollback();
1965 }
1966
1967 print '<br>';
1968
1969 print '</td></tr>';
1970}
1971
1980function migrate_modeles($db, $langs, $conf)
1981{
1982 //print '<br>';
1983 //print '<b>'.$langs->trans('UpdateModelsTable')."</b><br>\n";
1984
1985 dolibarr_install_syslog("upgrade2::migrate_modeles");
1986
1987 if (isModEnabled('invoice')) {
1988 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
1989 $modellist = ModelePDFFactures::liste_modeles($db);
1990 if (count($modellist) == 0) {
1991 // Aucun model par default.
1992 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')";
1993 $resql = $db->query($sql);
1994 if (!$resql) {
1995 dol_print_error($db);
1996 }
1997 }
1998 }
1999
2000 if (isModEnabled('order')) {
2001 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2002 $modellist = ModelePDFCommandes::liste_modeles($db);
2003 if (count($modellist) == 0) {
2004 // Aucun model par default.
2005 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')";
2006 $resql = $db->query($sql);
2007 if (!$resql) {
2008 dol_print_error($db);
2009 }
2010 }
2011 }
2012
2013 if (isModEnabled("shipping")) {
2014 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
2015 $modellist = ModelePdfExpedition::liste_modeles($db);
2016 if (count($modellist) == 0) {
2017 // Aucun model par default.
2018 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')";
2019 $resql = $db->query($sql);
2020 if (!$resql) {
2021 dol_print_error($db);
2022 }
2023 }
2024 }
2025
2026 //print $langs->trans("AlreadyDone");
2027}
2028
2029
2038function migrate_commande_expedition($db, $langs, $conf)
2039{
2040 dolibarr_install_syslog("upgrade2::migrate_commande_expedition");
2041
2042 print '<tr><td colspan="4">';
2043
2044 print '<br>';
2045 print '<b>'.$langs->trans('MigrationShipmentOrderMatching')."</b><br>\n";
2046
2047 $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande");
2048 $obj = $db->fetch_object($result);
2049 if ($obj) {
2050 $error = 0;
2051
2052 $db->begin();
2053
2054 $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
2055 $resql = $db->query($sql);
2056 if ($resql) {
2057 $i = 0;
2058 $num = $db->num_rows($resql);
2059
2060 if ($num) {
2061 while ($i < $num) {
2062 $obj = $db->fetch_object($resql);
2063
2064 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
2065 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2066 $resql2 = $db->query($sql);
2067
2068 if (!$resql2) {
2069 $error++;
2070 dol_print_error($db);
2071 }
2072 print '. ';
2073 $i++;
2074 }
2075 }
2076
2077 if ($error == 0) {
2078 $db->commit();
2079 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
2080 print $langs->trans('FieldRenamed')."<br>\n";
2081 $db->query($sql);
2082 } else {
2083 $db->rollback();
2084 }
2085 } else {
2086 dol_print_error($db);
2087 $db->rollback();
2088 }
2089 } else {
2090 print $langs->trans('AlreadyDone')."<br>\n";
2091 }
2092 print '</td></tr>';
2093}
2094
2103function migrate_commande_livraison($db, $langs, $conf)
2104{
2105 dolibarr_install_syslog("upgrade2::migrate_commande_livraison");
2106
2107 print '<tr><td colspan="4">';
2108
2109 print '<br>';
2110 print '<b>'.$langs->trans('MigrationDeliveryOrderMatching')."</b><br>\n";
2111
2112 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande");
2113 $obj = $db->fetch_object($result);
2114 if ($obj) {
2115 $error = 0;
2116
2117 $db->begin();
2118
2119 $sql = "SELECT l.rowid, l.fk_commande,";
2120 $sql .= " c.ref_client, c.date_livraison as delivery_date";
2121 $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
2122 $sql .= " WHERE c.rowid = l.fk_commande";
2123 $resql = $db->query($sql);
2124 if ($resql) {
2125 $i = 0;
2126 $num = $db->num_rows($resql);
2127
2128 if ($num) {
2129 while ($i < $num) {
2130 $obj = $db->fetch_object($resql);
2131
2132 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)";
2133 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2134 $resql2 = $db->query($sql);
2135
2136 if ($resql2) {
2137 $delivery_date = $db->jdate($obj->delivery_date);
2138
2139 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2140 $sqlu .= " ref_client = '".$db->escape($obj->ref_client)."'";
2141 $sqlu .= ", date_livraison = '".$db->idate($delivery_date)."'";
2142 $sqlu .= " WHERE rowid = ".((int) $obj->rowid);
2143 $resql3 = $db->query($sqlu);
2144 if (!$resql3) {
2145 $error++;
2146 dol_print_error($db);
2147 }
2148 } else {
2149 $error++;
2150 dol_print_error($db);
2151 }
2152 print '. ';
2153 $i++;
2154 }
2155 }
2156
2157 if ($error == 0) {
2158 $db->commit();
2159 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
2160 print $langs->trans('FieldRenamed')."<br>\n";
2161 $db->query($sql);
2162 } else {
2163 $db->rollback();
2164 }
2165 } else {
2166 dol_print_error($db);
2167 $db->rollback();
2168 }
2169 } else {
2170 print $langs->trans('AlreadyDone')."<br>\n";
2171 }
2172 print '</td></tr>';
2173}
2174
2183function migrate_detail_livraison($db, $langs, $conf)
2184{
2185 dolibarr_install_syslog("upgrade2::migrate_detail_livraison");
2186
2187 print '<tr><td colspan="4">';
2188
2189 print '<br>';
2190 print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n";
2191
2192 // This is done if field fk_commande_ligne exists.
2193 // If not this means migration was already done.
2194 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne");
2195 $obj = $db->fetch_object($result);
2196 if ($obj) {
2197 $error = 0;
2198
2199 $db->begin();
2200
2201 $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2202 $sql .= ", ld.fk_livraison";
2203 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
2204 $sql .= " WHERE ld.fk_commande_ligne = cd.rowid";
2205 $resql = $db->query($sql);
2206 if ($resql) {
2207 $i = 0;
2208 $num = $db->num_rows($resql);
2209
2210 if ($num) {
2211 while ($i < $num) {
2212 $obj = $db->fetch_object($resql);
2213
2214 $sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET";
2215 $sql .= " fk_product = ".((int) $obj->fk_product);
2216 $sql .= ",description = '".$db->escape($obj->description)."'";
2217 $sql .= ",subprice = ".price2num($obj->subprice);
2218 $sql .= ",total_ht = ".price2num($obj->total_ht);
2219 $sql .= " WHERE fk_commande_ligne = ".((int) $obj->rowid);
2220 $resql2 = $db->query($sql);
2221
2222 if ($resql2) {
2223 $sql = "SELECT total_ht";
2224 $sql .= " FROM ".MAIN_DB_PREFIX."livraison";
2225 $sql .= " WHERE rowid = ".((int) $obj->fk_livraison);
2226 $resql3 = $db->query($sql);
2227
2228 if ($resql3) {
2229 $obju = $db->fetch_object($resql3);
2230 $total_ht = $obju->total_ht + $obj->total_ht;
2231
2232 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2233 $sqlu .= " total_ht = ".price2num($total_ht, 'MT');
2234 $sqlu .= " WHERE rowid = ".((int) $obj->fk_livraison);
2235 $resql4 = $db->query($sqlu);
2236 if (!$resql4) {
2237 $error++;
2238 dol_print_error($db);
2239 }
2240 } else {
2241 $error++;
2242 dol_print_error($db);
2243 }
2244 } else {
2245 $error++;
2246 dol_print_error($db);
2247 }
2248 print '. ';
2249 $i++;
2250 }
2251 }
2252
2253 if ($error == 0) {
2254 $db->commit();
2255 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2256 print $langs->trans('FieldRenamed')."<br>\n";
2257 $db->query($sql);
2258 } else {
2259 $db->rollback();
2260 }
2261 } else {
2262 dol_print_error($db);
2263 $db->rollback();
2264 }
2265 } else {
2266 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line");
2267 $obj = $db->fetch_object($result);
2268 if (!$obj) {
2269 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2270 $db->query($sql);
2271 }
2272 print $langs->trans('AlreadyDone')."<br>\n";
2273 }
2274 print '</td></tr>';
2275}
2276
2285function migrate_stocks($db, $langs, $conf)
2286{
2287 dolibarr_install_syslog("upgrade2::migrate_stocks");
2288
2289 print '<tr><td colspan="4">';
2290
2291 print '<br>';
2292 print '<b>'.$langs->trans('MigrationStockDetail')."</b><br>\n";
2293
2294 $error = 0;
2295
2296 $db->begin();
2297
2298 $sql = "SELECT SUM(reel) as total, fk_product";
2299 $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
2300 $sql .= " GROUP BY fk_product";
2301 $resql = $db->query($sql);
2302 if ($resql) {
2303 $i = 0;
2304 $num = $db->num_rows($resql);
2305
2306 if ($num) {
2307 while ($i < $num) {
2308 $obj = $db->fetch_object($resql);
2309
2310 $sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
2311 $sql .= " stock = ".price2num($obj->total, 'MS');
2312 $sql .= " WHERE rowid = ".((int) $obj->fk_product);
2313
2314 $resql2 = $db->query($sql);
2315 if ($resql2) {
2316 } else {
2317 $error++;
2318 dol_print_error($db);
2319 }
2320 print '. ';
2321 $i++;
2322 }
2323 }
2324
2325 if ($error == 0) {
2326 $db->commit();
2327 } else {
2328 $db->rollback();
2329 }
2330 } else {
2331 dol_print_error($db);
2332 $db->rollback();
2333 }
2334
2335 print '</td></tr>';
2336}
2337
2347function migrate_menus($db, $langs, $conf)
2348{
2349 dolibarr_install_syslog("upgrade2::migrate_menus");
2350
2351 print '<tr><td colspan="4">';
2352
2353 print '<br>';
2354 print '<b>'.$langs->trans('MigrationMenusDetail')."</b><br>\n";
2355
2356 $error = 0;
2357
2358 if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) {
2359 $db->begin();
2360
2361 $sql = "SELECT m.rowid, mc.action";
2362 $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m";
2363 $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2364 $sql .= " AND m.enabled = '1'";
2365 $resql = $db->query($sql);
2366 if ($resql) {
2367 $i = 0;
2368 $num = $db->num_rows($resql);
2369 if ($num) {
2370 while ($i < $num) {
2371 $obj = $db->fetch_object($resql);
2372
2373 $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
2374 $sql .= " enabled = '".$db->escape($obj->action)."'";
2375 $sql .= " WHERE rowid = ".((int) $obj->rowid);
2376 $sql .= " AND enabled = '1'";
2377
2378 $resql2 = $db->query($sql);
2379 if ($resql2) {
2380 } else {
2381 $error++;
2382 dol_print_error($db);
2383 }
2384 print '. ';
2385 $i++;
2386 }
2387 }
2388
2389 if ($error == 0) {
2390 $db->commit();
2391 } else {
2392 $db->rollback();
2393 }
2394 } else {
2395 dol_print_error($db);
2396 $db->rollback();
2397 }
2398 } else {
2399 print $langs->trans('AlreadyDone')."<br>\n";
2400 }
2401
2402 print '</td></tr>';
2403}
2404
2414function migrate_commande_deliveryaddress($db, $langs, $conf)
2415{
2416 dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress");
2417
2418 print '<tr><td colspan="4">';
2419
2420 print '<br>';
2421 print '<b>'.$langs->trans('MigrationDeliveryAddress')."</b><br>\n";
2422
2423 $error = 0;
2424
2425 if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) {
2426 $db->begin();
2427
2428 $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition";
2429 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
2430 $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce";
2431 $sql .= " WHERE c.rowid = ce.fk_commande";
2432 $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2433
2434 $resql = $db->query($sql);
2435 if ($resql) {
2436 $i = 0;
2437 $num = $db->num_rows($resql);
2438
2439 if ($num) {
2440 while ($i < $num) {
2441 $obj = $db->fetch_object($resql);
2442
2443 $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
2444 $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'";
2445 $sql .= " WHERE rowid = ".((int) $obj->fk_expedition);
2446
2447 $resql2 = $db->query($sql);
2448 if (!$resql2) {
2449 $error++;
2450 dol_print_error($db);
2451 }
2452 print '. ';
2453 $i++;
2454 }
2455 } else {
2456 print $langs->trans('AlreadyDone')."<br>\n";
2457 }
2458
2459 if ($error == 0) {
2460 $db->commit();
2461 } else {
2462 $db->rollback();
2463 }
2464 } else {
2465 dol_print_error($db);
2466 $db->rollback();
2467 }
2468 } else {
2469 print $langs->trans('AlreadyDone')."<br>\n";
2470 }
2471
2472 print '</td></tr>';
2473}
2474
2484function migrate_restore_missing_links($db, $langs, $conf)
2485{
2486 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
2487
2488 if (($db->type == 'mysql' || $db->type == 'mysqli')) {
2489 if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
2490 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2491 return 0;
2492 }
2493 }
2494 print '<tr><td colspan="4">';
2495
2496 print '<br>';
2497 print '<b>'.$langs->trans('MigrationFixData')."</b> (1)<br>\n";
2498
2499 $error = 0;
2500
2501
2502 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1.
2503 $table1 = 'facturedet';
2504 $field1 = 'fk_remise_except';
2505 $table2 = 'societe_remise_except';
2506 $field2 = 'fk_facture_line';
2507
2508 $db->begin();
2509
2510 $sql = "SELECT t1.rowid, t1.".$field1." as field";
2511 $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1";
2512 $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN";
2513 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2";
2514 $sql .= " WHERE t1.rowid = t2.".$field2.")";
2515
2516 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1");
2517 $resql = $db->query($sql);
2518 if ($resql) {
2519 $i = 0;
2520 $num = $db->num_rows($resql);
2521
2522 if ($num) {
2523 while ($i < $num) {
2524 $obj = $db->fetch_object($resql);
2525
2526 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2527 $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET";
2528 $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'";
2529 $sql .= " WHERE rowid = ".((int) $obj->field);
2530
2531 $resql2 = $db->query($sql);
2532 if (!$resql2) {
2533 $error++;
2534 dol_print_error($db);
2535 }
2536 //print '. ';
2537 $i++;
2538 }
2539 } else {
2540 print $langs->trans('AlreadyDone')."<br>\n";
2541 }
2542
2543 if ($error == 0) {
2544 $db->commit();
2545 } else {
2546 $db->rollback();
2547 }
2548 } else {
2549 dol_print_error($db);
2550 $db->rollback();
2551 }
2552
2553 print '</td></tr>';
2554
2555
2556 print '<tr><td colspan="4">';
2557
2558 print '<br>';
2559 print '<b>'.$langs->trans('MigrationFixData')."</b> (2)<br>\n";
2560
2561 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2.
2562 $table2 = 'facturedet';
2563 $field2 = 'fk_remise_except';
2564 $table1 = 'societe_remise_except';
2565 $field1 = 'fk_facture_line';
2566
2567 $db->begin();
2568
2569 $sql = "SELECT t1.rowid, t1.".$field1." as field";
2570 $sql .= " FROM ".MAIN_DB_PREFIX.$table1." as t1";
2571 $sql .= " WHERE t1.".$field1." IS NOT NULL AND t1.".$field1." NOT IN";
2572 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$table2." as t2";
2573 $sql .= " WHERE t1.rowid = t2.".$field2.")";
2574
2575 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2");
2576 $resql = $db->query($sql);
2577 if ($resql) {
2578 $i = 0;
2579 $num = $db->num_rows($resql);
2580
2581 if ($num) {
2582 while ($i < $num) {
2583 $obj = $db->fetch_object($resql);
2584
2585 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2586 $sql = "UPDATE ".MAIN_DB_PREFIX.$table2." SET";
2587 $sql .= " ".$field2." = '".$db->escape($obj->rowid)."'";
2588 $sql .= " WHERE rowid = ".((int) $obj->field);
2589
2590 $resql2 = $db->query($sql);
2591 if (!$resql2) {
2592 $error++;
2593 dol_print_error($db);
2594 }
2595 //print '. ';
2596 $i++;
2597 }
2598 } else {
2599 print $langs->trans('AlreadyDone')."<br>\n";
2600 }
2601
2602 if ($error == 0) {
2603 $db->commit();
2604 } else {
2605 $db->rollback();
2606 }
2607 } else {
2608 dol_print_error($db);
2609 $db->rollback();
2610 }
2611
2612 print '</td></tr>';
2613
2614 return ($error ? -1 : 1);
2615}
2616
2625function migrate_project_user_resp($db, $langs, $conf)
2626{
2627 dolibarr_install_syslog("upgrade2::migrate_project_user_resp");
2628
2629 print '<tr><td colspan="4">';
2630
2631 print '<br>';
2632 print '<b>'.$langs->trans('MigrationProjectUserResp')."</b><br>\n";
2633
2634 $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp");
2635 $obj = $db->fetch_object($result);
2636 if ($obj) {
2637 $error = 0;
2638
2639 $db->begin();
2640
2641 $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet";
2642 $resql = $db->query($sql);
2643 if ($resql) {
2644 $i = 0;
2645 $num = $db->num_rows($resql);
2646
2647 if ($num) {
2648 while ($i < $num) {
2649 $obj = $db->fetch_object($resql);
2650
2651 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2652 $sql2 .= "datecreate";
2653 $sql2 .= ", statut";
2654 $sql2 .= ", element_id";
2655 $sql2 .= ", fk_c_type_contact";
2656 $sql2 .= ", fk_socpeople";
2657 $sql2 .= ") VALUES (";
2658 $sql2 .= "'".$db->idate(dol_now())."'";
2659 $sql2 .= ", '4'";
2660 $sql2 .= ", ".$obj->rowid;
2661 $sql2 .= ", '160'";
2662 $sql2 .= ", ".$obj->fk_user_resp;
2663 $sql2 .= ")";
2664
2665 if ($obj->fk_user_resp > 0) {
2666 $resql2 = $db->query($sql2);
2667 if (!$resql2) {
2668 $error++;
2669 dol_print_error($db);
2670 }
2671 }
2672 print '. ';
2673
2674 $i++;
2675 }
2676 }
2677
2678 if ($error == 0) {
2679 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp";
2680 if ($db->query($sqlDrop)) {
2681 $db->commit();
2682 } else {
2683 $db->rollback();
2684 }
2685 } else {
2686 $db->rollback();
2687 }
2688 } else {
2689 dol_print_error($db);
2690 $db->rollback();
2691 }
2692 } else {
2693 print $langs->trans('AlreadyDone')."<br>\n";
2694 }
2695 print '</td></tr>';
2696}
2697
2706function migrate_project_task_actors($db, $langs, $conf)
2707{
2708 dolibarr_install_syslog("upgrade2::migrate_project_task_actors");
2709
2710 print '<tr><td colspan="4">';
2711
2712 print '<br>';
2713 print '<b>'.$langs->trans('MigrationProjectTaskActors')."</b><br>\n";
2714
2715 if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) {
2716 $error = 0;
2717
2718 $db->begin();
2719
2720 $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors";
2721 $resql = $db->query($sql);
2722 if ($resql) {
2723 $i = 0;
2724 $num = $db->num_rows($resql);
2725
2726 if ($num) {
2727 while ($i < $num) {
2728 $obj = $db->fetch_object($resql);
2729
2730 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2731 $sql2 .= "datecreate";
2732 $sql2 .= ", statut";
2733 $sql2 .= ", element_id";
2734 $sql2 .= ", fk_c_type_contact";
2735 $sql2 .= ", fk_socpeople";
2736 $sql2 .= ") VALUES (";
2737 $sql2 .= "'".$db->idate(dol_now())."'";
2738 $sql2 .= ", '4'";
2739 $sql2 .= ", ".$obj->fk_project_task;
2740 $sql2 .= ", '180'";
2741 $sql2 .= ", ".$obj->fk_user;
2742 $sql2 .= ")";
2743
2744 $resql2 = $db->query($sql2);
2745
2746 if (!$resql2) {
2747 $error++;
2748 dol_print_error($db);
2749 }
2750 print '. ';
2751 $i++;
2752 }
2753 }
2754
2755 if ($error == 0) {
2756 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors";
2757 if ($db->query($sqlDrop)) {
2758 $db->commit();
2759 } else {
2760 $db->rollback();
2761 }
2762 } else {
2763 $db->rollback();
2764 }
2765 } else {
2766 dol_print_error($db);
2767 $db->rollback();
2768 }
2769 } else {
2770 print $langs->trans('AlreadyDone')."<br>\n";
2771 }
2772 print '</td></tr>';
2773}
2774
2788function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
2789{
2790 print '<tr><td colspan="4">';
2791
2792 print '<br>';
2793 print '<b>'.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."</b><br>\n";
2794
2795 $error = 0;
2796
2797 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2798 dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table);
2799
2800 $db->begin();
2801
2802 $sqlSelect = "SELECT ".$fk_source.", ".$fk_target;
2803 $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table;
2804
2805 $resql = $db->query($sqlSelect);
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 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
2815 $sqlInsert .= "fk_source";
2816 $sqlInsert .= ", sourcetype";
2817 $sqlInsert .= ", fk_target";
2818 $sqlInsert .= ", targettype";
2819 $sqlInsert .= ") VALUES (";
2820 $sqlInsert .= $obj->$fk_source;
2821 $sqlInsert .= ", '".$db->escape($sourcetype)."'";
2822 $sqlInsert .= ", ".$obj->$fk_target;
2823 $sqlInsert .= ", '".$db->escape($targettype)."'";
2824 $sqlInsert .= ")";
2825
2826 $result = $db->query($sqlInsert);
2827 if (!$result) {
2828 $error++;
2829 dol_print_error($db);
2830 }
2831 print '. ';
2832 $i++;
2833 }
2834 } else {
2835 print $langs->trans('AlreadyDone')."<br>\n";
2836 }
2837
2838 if ($error == 0) {
2839 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$table;
2840 if ($db->query($sqlDrop)) {
2841 $db->commit();
2842 } else {
2843 $db->rollback();
2844 }
2845 } else {
2846 $db->rollback();
2847 }
2848 } else {
2849 dol_print_error($db);
2850 $db->rollback();
2851 }
2852 } else {
2853 print $langs->trans('AlreadyDone')."<br>\n";
2854 }
2855
2856 print '</td></tr>';
2857}
2858
2867function migrate_element_time($db, $langs, $conf)
2868{
2869 dolibarr_install_syslog("upgrade2::migrate_element_time");
2870
2871 print '<tr><td colspan="4">';
2872
2873 print '<br>';
2874 print '<b>'.$langs->trans('MigrationProjectTaskTime')."</b><br>\n";
2875
2876 $error = 0;
2877
2878 $db->begin();
2879
2880 $sql = "SELECT rowid, fk_element, element_duration";
2881 $sql .= " FROM ".MAIN_DB_PREFIX."element_time";
2882 $resql = $db->query($sql);
2883 if ($resql) {
2884 $i = 0;
2885 $num = $db->num_rows($resql);
2886
2887 if ($num) {
2888 $totaltime = array();
2889 $oldtime = 0;
2890
2891 while ($i < $num) {
2892 $obj = $db->fetch_object($resql);
2893
2894 if ($obj->element_duration > 0) {
2895 // convert to second
2896 // only for int time and float time ex: 1,75 for 1h45
2897 list($hour, $min) = explode('.', $obj->element_duration);
2898 $hour = $hour * 60 * 60;
2899 $min = ($min / 100) * 60 * 60;
2900 $newtime = $hour + $min;
2901
2902 $sql2 = "UPDATE ".MAIN_DB_PREFIX."element_time SET";
2903 $sql2 .= " element_duration = ".((int) $newtime);
2904 $sql2 .= " WHERE rowid = ".((int) $obj->rowid);
2905
2906 $resql2 = $db->query($sql2);
2907 if (!$resql2) {
2908 $error++;
2909 dol_print_error($db);
2910 }
2911 print '. ';
2912 $oldtime++;
2913 if (!empty($totaltime[$obj->fk_element])) {
2914 $totaltime[$obj->fk_element] += $newtime;
2915 } else {
2916 $totaltime[$obj->fk_element] = $newtime;
2917 }
2918 } else {
2919 if (!empty($totaltime[$obj->fk_element])) {
2920 $totaltime[$obj->fk_element] += $obj->element_duration;
2921 } else {
2922 $totaltime[$obj->fk_element] = $obj->element_duration;
2923 }
2924 }
2925
2926 $i++;
2927 }
2928
2929 if ($error == 0) {
2930 if ($oldtime > 0) {
2931 foreach ($totaltime as $taskid => $total_duration) {
2932 $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
2933 $sql .= " duration_effective = ".((int) $total_duration);
2934 $sql .= " WHERE rowid = ".((int) $taskid);
2935
2936 $resql = $db->query($sql);
2937 if (!$resql) {
2938 $error++;
2939 dol_print_error($db);
2940 }
2941 }
2942 } else {
2943 print $langs->trans('AlreadyDone')."<br>\n";
2944 }
2945 } else {
2946 dol_print_error($db);
2947 }
2948 } else {
2949 print $langs->trans('AlreadyDone')."<br>\n";
2950 }
2951 } else {
2952 dol_print_error($db);
2953 }
2954
2955 if ($error == 0) {
2956 $db->commit();
2957 } else {
2958 $db->rollback();
2959 }
2960
2961 print '</td></tr>';
2962}
2963
2972function migrate_customerorder_shipping($db, $langs, $conf)
2973{
2974 print '<tr><td colspan="4">';
2975
2976 print '<br>';
2977 print '<b>'.$langs->trans('MigrationCustomerOrderShipping')."</b><br>\n";
2978
2979 $error = 0;
2980
2981 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer");
2982 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery");
2983 $obj1 = $db->fetch_object($result1);
2984 $obj2 = $db->fetch_object($result2);
2985 if (!$obj1 && !$obj2) {
2986 dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping");
2987
2988 $db->begin();
2989
2990 $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
2991 $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
2992
2993 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
2994 $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
2995 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e";
2996 $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el";
2997 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
2998 $sqlSelect .= " WHERE e.rowid = el.fk_target";
2999 $sqlSelect .= " AND el.targettype = 'shipping'";
3000
3001 $resql = $db->query($sqlSelect);
3002 if ($resql) {
3003 $i = 0;
3004 $num = $db->num_rows($resql);
3005
3006 if ($num) {
3007 while ($i < $num) {
3008 $obj = $db->fetch_object($resql);
3009
3010 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
3011 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'";
3012 $sqlUpdate .= ", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date : 'null')."'";
3013 $sqlUpdate .= " WHERE rowid = ".((int) $obj->shipping_id);
3014
3015 $result = $db->query($sqlUpdate);
3016 if (!$result) {
3017 $error++;
3018 dol_print_error($db);
3019 }
3020 print '. ';
3021 $i++;
3022 }
3023 } else {
3024 print $langs->trans('AlreadyDone')."<br>\n";
3025 }
3026
3027 if ($error == 0) {
3028 $db->commit();
3029 } else {
3030 dol_print_error($db);
3031 $db->rollback();
3032 }
3033 } else {
3034 dol_print_error($db);
3035 $db->rollback();
3036 }
3037 } else {
3038 dol_print_error($db);
3039 $db->rollback();
3040 }
3041 } else {
3042 print $langs->trans('AlreadyDone')."<br>\n";
3043 }
3044
3045 print '</td></tr>';
3046}
3047
3056function migrate_shipping_delivery($db, $langs, $conf)
3057{
3058 print '<tr><td colspan="4">';
3059
3060 print '<br>';
3061 print '<b>'.$langs->trans('MigrationShippingDelivery')."</b><br>\n";
3062
3063 $error = 0;
3064
3065 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition");
3066 $obj = $db->fetch_object($result);
3067 if ($obj) {
3068 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery");
3069
3070 $db->begin();
3071
3072 $sqlSelect = "SELECT rowid, fk_expedition";
3073 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison";
3074 $sqlSelect .= " WHERE fk_expedition is not null";
3075
3076 $resql = $db->query($sqlSelect);
3077 if ($resql) {
3078 $i = 0;
3079 $num = $db->num_rows($resql);
3080
3081 if ($num) {
3082 while ($i < $num) {
3083 $obj = $db->fetch_object($resql);
3084
3085 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
3086 $sqlInsert .= "fk_source";
3087 $sqlInsert .= ", sourcetype";
3088 $sqlInsert .= ", fk_target";
3089 $sqlInsert .= ", targettype";
3090 $sqlInsert .= ") VALUES (";
3091 $sqlInsert .= $obj->fk_expedition;
3092 $sqlInsert .= ", 'shipping'";
3093 $sqlInsert .= ", ".$obj->rowid;
3094 $sqlInsert .= ", 'delivery'";
3095 $sqlInsert .= ")";
3096
3097 $result = $db->query($sqlInsert);
3098 if ($result) {
3099 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL";
3100 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3101
3102 $result = $db->query($sqlUpdate);
3103 if (!$result) {
3104 $error++;
3105 dol_print_error($db);
3106 }
3107 print '. ';
3108 } else {
3109 $error++;
3110 dol_print_error($db);
3111 }
3112 $i++;
3113 }
3114 } else {
3115 print $langs->trans('AlreadyDone')."<br>\n";
3116 }
3117
3118 if ($error == 0) {
3119 $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3120 $db->query($sqlDelete);
3121
3122 $db->commit();
3123
3124 // DDL commands must not be inside a transaction
3125 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition";
3126 $db->query($sqlDrop);
3127 } else {
3128 dol_print_error($db);
3129 $db->rollback();
3130 }
3131 } else {
3132 dol_print_error($db);
3133 $db->rollback();
3134 }
3135 } else {
3136 print $langs->trans('AlreadyDone')."<br>\n";
3137 }
3138
3139 print '</td></tr>';
3140}
3141
3151function migrate_shipping_delivery2($db, $langs, $conf)
3152{
3153 print '<tr><td colspan="4">';
3154
3155 print '<br>';
3156 print '<b>'.$langs->trans('MigrationShippingDelivery2')."</b><br>\n";
3157
3158 $error = 0;
3159
3160 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2");
3161
3162 $db->begin();
3163
3164 $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3165 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,";
3166 $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,";
3167 $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e";
3168 $sqlSelect .= " WHERE l.rowid = el.fk_target";
3169 $sqlSelect .= " AND el.targettype = 'delivery'";
3170 $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3171 $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null
3172 // Add condition to know if we never migrate this record
3173 $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")";
3174 $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")";
3175
3176 $resql = $db->query($sqlSelect);
3177 if ($resql) {
3178 $i = 0;
3179 $num = $db->num_rows($resql);
3180
3181 if ($num) {
3182 while ($i < $num) {
3183 $obj = $db->fetch_object($resql);
3184
3185 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
3186 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',";
3187 $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null');
3188 $sqlUpdate .= " WHERE rowid = ".((int) $obj->delivery_id);
3189
3190 $result = $db->query($sqlUpdate);
3191 if (!$result) {
3192 $error++;
3193 dol_print_error($db);
3194 }
3195 print '. ';
3196 $i++;
3197 }
3198 } else {
3199 print $langs->trans('AlreadyDone')."<br>\n";
3200 }
3201
3202 if ($error == 0) {
3203 $db->commit();
3204 } else {
3205 dol_print_error($db);
3206 $db->rollback();
3207 }
3208 } else {
3209 dol_print_error($db);
3210 $db->rollback();
3211 }
3212
3213 print '</td></tr>';
3214}
3215
3224function migrate_actioncomm_element($db, $langs, $conf)
3225{
3226 print '<tr><td colspan="4">';
3227
3228 print '<br>';
3229 print '<b>'.$langs->trans('MigrationActioncommElement')."</b><br>\n";
3230
3231 $elements = array(
3232 'propal' => 'propalrowid',
3233 'order' => 'fk_commande',
3234 'invoice' => 'fk_facture',
3235 'contract' => 'fk_contract',
3236 'order_supplier' => 'fk_supplier_order',
3237 'invoice_supplier' => 'fk_supplier_invoice'
3238 );
3239
3240 foreach ($elements as $type => $field) {
3241 $result = $db->DDLDescTable(MAIN_DB_PREFIX."actioncomm", $field);
3242 $obj = $db->fetch_object($result);
3243 if ($obj) {
3244 dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=".$field);
3245
3246 $db->begin();
3247
3248 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ";
3249 $sql .= "fk_element = ".$field.", elementtype = '".$db->escape($type)."'";
3250 $sql .= " WHERE ".$field." IS NOT NULL";
3251 $sql .= " AND fk_element IS NULL";
3252 $sql .= " AND elementtype IS NULL";
3253
3254 $resql = $db->query($sql);
3255 if ($resql) {
3256 $db->commit();
3257
3258 // DDL commands must not be inside a transaction
3259 // We will drop at next version because a migrate should be runnable several times if it fails.
3260 //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
3261 //$db->query($sqlDrop);
3262 //print '. ';
3263 } else {
3264 dol_print_error($db);
3265 $db->rollback();
3266 }
3267 } else {
3268 print $langs->trans('AlreadyDone')."<br>\n";
3269 }
3270 }
3271
3272 print '</td></tr>';
3273}
3274
3283function migrate_mode_reglement($db, $langs, $conf)
3284{
3285 print '<tr><td colspan="4">';
3286
3287 print '<br>';
3288 print '<b>'.$langs->trans('MigrationPaymentMode')."</b><br>\n";
3289
3290 $elements = array(
3291 'old_id' => array(5, 8, 9, 10, 11),
3292 'new_id' => array(50, 51, 52, 53, 54),
3293 'code' => array('VAD', 'TRA', 'LCR', 'FAC', 'PRO'),
3294 'tables' => array('commande_fournisseur', 'commande', 'facture_rec', 'facture', 'propal')
3295 );
3296 $count = 0;
3297
3298 foreach ($elements['old_id'] as $key => $old_id) {
3299 $error = 0;
3300
3301 dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);
3302
3303 $sqlSelect = "SELECT id";
3304 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."c_paiement";
3305 $sqlSelect .= " WHERE id = ".((int) $old_id);
3306 $sqlSelect .= " AND code = '".$db->escape($elements['code'][$key])."'";
3307
3308 $resql = $db->query($sqlSelect);
3309 if ($resql) {
3310 $num = $db->num_rows($resql);
3311 if ($num) {
3312 $count++;
3313
3314 $db->begin();
3315
3316 $sqla = "UPDATE ".MAIN_DB_PREFIX."paiement SET";
3317 $sqla .= " fk_paiement = ".((int) $elements['new_id'][$key]);
3318 $sqla .= " WHERE fk_paiement = ".((int) $old_id);
3319 $sqla .= " AND fk_paiement IN (SELECT id FROM ".MAIN_DB_PREFIX."c_paiement WHERE id = ".((int) $old_id)." AND code = '".$db->escape($elements['code'][$key])."')";
3320 $resqla = $db->query($sqla);
3321
3322 $sql = "UPDATE ".MAIN_DB_PREFIX."c_paiement SET";
3323 $sql .= " id = ".((int) $elements['new_id'][$key]);
3324 $sql .= " WHERE id = ".((int) $old_id);
3325 $sql .= " AND code = '".$db->escape($elements['code'][$key])."'";
3326 $resql = $db->query($sql);
3327
3328 if ($resqla && $resql) {
3329 foreach ($elements['tables'] as $table) {
3330 $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET ";
3331 $sql .= "fk_mode_reglement = ".((int) $elements['new_id'][$key]);
3332 $sql .= " WHERE fk_mode_reglement = ".((int) $old_id);
3333
3334 $resql = $db->query($sql);
3335 if (!$resql) {
3336 dol_print_error($db);
3337 $error++;
3338 }
3339 print '. ';
3340 }
3341
3342 if (!$error) {
3343 $db->commit();
3344 } else {
3345 dol_print_error($db);
3346 $db->rollback();
3347 }
3348 } else {
3349 dol_print_error($db);
3350 $db->rollback();
3351 }
3352 }
3353 }
3354 }
3355
3356 if ($count == 0) {
3357 print $langs->trans('AlreadyDone')."<br>\n";
3358 }
3359
3360
3361 print '</td></tr>';
3362}
3363
3364
3373function migrate_clean_association($db, $langs, $conf)
3374{
3375 $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association");
3376 if ($result) { // result defined for version 3.2 or -
3377 $obj = $db->fetch_object($result);
3378 if ($obj) { // It table categorie_association exists
3379 $couples = array();
3380 $children = array();
3381 $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
3382 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3383 dolibarr_install_syslog("upgrade: search duplicate");
3384 $resql = $db->query($sql);
3385 if ($resql) {
3386 $num = $db->num_rows($resql);
3387 while ($obj = $db->fetch_object($resql)) {
3388 if (!isset($children[$obj->fk_categorie_fille])) { // Only one record as child (a child has only on parent).
3389 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3390 $children[$obj->fk_categorie_fille] = 1; // Set record for this child
3391 $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere' => $obj->fk_categorie_mere, 'fille' => $obj->fk_categorie_fille);
3392 }
3393 }
3394 }
3395
3396 dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
3397
3398 // If there is duplicates couples or child with two parents
3399 if (count($couples) > 0 && $num > count($couples)) {
3400 $error = 0;
3401
3402 $db->begin();
3403
3404 // We delete all
3405 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
3406 dolibarr_install_syslog("upgrade: delete association");
3407 $resqld = $db->query($sql);
3408 if ($resqld) {
3409 // And we insert only each record once
3410 foreach ($couples as $key => $val) {
3411 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
3412 $sql .= " VALUES(".((int) $val['mere']).", ".((int) $val['fille']).")";
3413 dolibarr_install_syslog("upgrade: insert association");
3414 $resqli = $db->query($sql);
3415 if (!$resqli) {
3416 $error++;
3417 }
3418 }
3419 }
3420
3421 if (!$error) {
3422 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3423 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
3424 $db->commit();
3425 } else {
3426 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3427 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").'</td></tr>';
3428 $db->rollback();
3429 }
3430 }
3431 } else {
3432 print '<tr><td>'.$langs->trans("Error").'</td>';
3433 print '<td class="right"><div class="error">'.$db->lasterror().'</div></td></tr>';
3434 }
3435 }
3436 }
3437}
3438
3439
3448function migrate_categorie_association($db, $langs, $conf)
3449{
3450 print '<tr><td colspan="4">';
3451
3452 print '<br>';
3453 print '<b>'.$langs->trans('MigrationCategorieAssociation')."</b><br>\n";
3454
3455 $error = 0;
3456
3457 if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association")) {
3458 dolibarr_install_syslog("upgrade2::migrate_categorie_association");
3459
3460 $db->begin();
3461
3462 $sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
3463 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3464
3465 $resql = $db->query($sqlSelect);
3466 if ($resql) {
3467 $i = 0;
3468 $num = $db->num_rows($resql);
3469
3470 if ($num) {
3471 while ($i < $num) {
3472 $obj = $db->fetch_object($resql);
3473
3474 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
3475 $sqlUpdate .= "fk_parent = ".((int) $obj->fk_categorie_mere);
3476 $sqlUpdate .= " WHERE rowid = ".((int) $obj->fk_categorie_fille);
3477
3478 $result = $db->query($sqlUpdate);
3479 if (!$result) {
3480 $error++;
3481 dol_print_error($db);
3482 }
3483 print '. ';
3484 $i++;
3485 }
3486 } else {
3487 print $langs->trans('AlreadyDone')."<br>\n";
3488 }
3489
3490 if (!$error) {
3491 $db->commit();
3492 } else {
3493 $db->rollback();
3494 }
3495 } else {
3496 dol_print_error($db);
3497 $db->rollback();
3498 }
3499 } else {
3500 print $langs->trans('AlreadyDone')."<br>\n";
3501 }
3502
3503 print '</td></tr>';
3504}
3505
3514function migrate_event_assignement($db, $langs, $conf)
3515{
3516 print '<tr><td colspan="4">';
3517
3518 print '<br>';
3519 print '<b>'.$langs->trans('MigrationEvents')."</b><br>\n";
3520
3521 $error = 0;
3522
3523 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3524
3525 $db->begin();
3526
3527 $sqlSelect = "SELECT a.id, a.fk_user_action";
3528 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3529 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'user' AND ar.fk_element = a.fk_user_action";
3530 $sqlSelect .= " WHERE fk_user_action > 0 AND fk_user_action NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'user')";
3531 $sqlSelect .= " ORDER BY a.id";
3532 //print $sqlSelect;
3533
3534 $resql = $db->query($sqlSelect);
3535 if ($resql) {
3536 $i = 0;
3537 $num = $db->num_rows($resql);
3538
3539 if ($num) {
3540 while ($i < $num) {
3541 $obj = $db->fetch_object($resql);
3542
3543 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3544 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'user', ".((int) $obj->fk_user_action).")";
3545
3546 $result = $db->query($sqlUpdate);
3547 if (!$result) {
3548 $error++;
3549 dol_print_error($db);
3550 }
3551 print '. ';
3552 $i++;
3553 }
3554 } else {
3555 print $langs->trans('AlreadyDone')."<br>\n";
3556 }
3557
3558 if (!$error) {
3559 $db->commit();
3560 } else {
3561 $db->rollback();
3562 }
3563 } else {
3564 dol_print_error($db);
3565 $db->rollback();
3566 }
3567
3568
3569 print '</td></tr>';
3570}
3571
3580function migrate_event_assignement_contact($db, $langs, $conf)
3581{
3582 print '<tr><td colspan="4">';
3583
3584 print '<br>';
3585 print '<b>'.$langs->trans('MigrationEventsContact')."</b><br>\n";
3586
3587 $error = 0;
3588
3589 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3590
3591 $db->begin();
3592
3593 $sqlSelect = "SELECT a.id, a.fk_contact";
3594 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3595 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople' AND ar.fk_element = a.fk_contact";
3596 $sqlSelect .= " WHERE fk_contact > 0 AND fk_contact NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople')";
3597 $sqlSelect .= " ORDER BY a.id";
3598 //print $sqlSelect;
3599
3600 $resql = $db->query($sqlSelect);
3601 if ($resql) {
3602 $i = 0;
3603 $num = $db->num_rows($resql);
3604
3605 if ($num) {
3606 while ($i < $num) {
3607 $obj = $db->fetch_object($resql);
3608
3609 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3610 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'socpeople', ".((int) $obj->fk_contact).")";
3611
3612 $result = $db->query($sqlUpdate);
3613 if (!$result) {
3614 $error++;
3615 dol_print_error($db);
3616 }
3617 print '. ';
3618 $i++;
3619 }
3620 } else {
3621 print $langs->trans('AlreadyDone')."<br>\n";
3622 }
3623
3624 if (!$error) {
3625 $db->commit();
3626 } else {
3627 $db->rollback();
3628 }
3629 } else {
3630 dol_print_error($db);
3631 $db->rollback();
3632 }
3633
3634
3635 print '</td></tr>';
3636}
3637
3638
3647function migrate_reset_blocked_log($db, $langs, $conf)
3648{
3649 global $user;
3650
3651 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
3652
3653 print '<tr><td colspan="4">';
3654
3655 print '<br>';
3656 print '<b>'.$langs->trans('MigrationResetBlockedLog')."</b><br>\n";
3657
3658 $error = 0;
3659
3660 dolibarr_install_syslog("upgrade2::migrate_reset_blocked_log");
3661
3662 $db->begin();
3663
3664 $sqlSelect = "SELECT DISTINCT entity";
3665 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."blockedlog";
3666
3667 //print $sqlSelect;
3668
3669 $resql = $db->query($sqlSelect);
3670 if ($resql) {
3671 $i = 0;
3672 $num = $db->num_rows($resql);
3673
3674 if ($num) {
3675 while ($i < $num) {
3676 $obj = $db->fetch_object($resql);
3677
3678 print 'Process entity '.$obj->entity;
3679
3680 $sqlSearch = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3681 $resqlSearch = $db->query($sqlSearch);
3682 if ($resqlSearch) {
3683 $objSearch = $db->fetch_object($resqlSearch);
3684 //var_dump($objSearch);
3685 if ($objSearch && $objSearch->nb == 0) {
3686 print ' - Record for entity must be reset...';
3687
3688 $sqlUpdate = "DELETE FROM ".MAIN_DB_PREFIX."blockedlog";
3689 $sqlUpdate .= " WHERE entity = ".((int) $obj->entity);
3690 $resqlUpdate = $db->query($sqlUpdate);
3691 if (!$resqlUpdate) {
3692 $error++;
3693 dol_print_error($db);
3694 } else {
3695 // Add set line
3696 $object = new stdClass();
3697 $object->id = 1;
3698 $object->element = 'module';
3699 $object->ref = 'systemevent';
3700 $object->entity = $obj->entity;
3701 $object->date = dol_now();
3702
3703 $b = new BlockedLog($db);
3704 $b->setObjectData($object, 'MODULE_SET', 0);
3705
3706 $res = $b->create($user);
3707 if ($res <= 0) {
3708 $error++;
3709 }
3710 }
3711 } else {
3712 print ' - '.$langs->trans('AlreadyInV7').'<br>';
3713 }
3714 } else {
3715 dol_print_error($db);
3716 }
3717
3718 $i++;
3719 }
3720 } else {
3721 print $langs->trans('NothingToDo')."<br>\n";
3722 }
3723
3724 if (!$error) {
3725 $db->commit();
3726 } else {
3727 $db->rollback();
3728 }
3729 } else {
3730 dol_print_error($db);
3731 $db->rollback();
3732 }
3733
3734 print '</td></tr>';
3735}
3736
3737
3746function migrate_remise_entity($db, $langs, $conf)
3747{
3748 print '<tr><td colspan="4">';
3749
3750 print '<br>';
3751 print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\n";
3752
3753 $error = 0;
3754
3755 dolibarr_install_syslog("upgrade2::migrate_remise_entity");
3756
3757 $db->begin();
3758
3759 $sqlSelect = "SELECT sr.rowid, s.entity";
3760 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s";
3761 $sqlSelect .= " WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3762
3763 //print $sqlSelect;
3764
3765 $resql = $db->query($sqlSelect);
3766 if ($resql) {
3767 $i = 0;
3768 $num = $db->num_rows($resql);
3769
3770 if ($num) {
3771 while ($i < $num) {
3772 $obj = $db->fetch_object($resql);
3773
3774 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
3775 $sqlUpdate .= " entity = ".$obj->entity;
3776 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3777
3778 $result = $db->query($sqlUpdate);
3779 if (!$result) {
3780 $error++;
3781 dol_print_error($db);
3782 }
3783
3784 print '. ';
3785 $i++;
3786 }
3787 } else {
3788 print $langs->trans('AlreadyDone')."<br>\n";
3789 }
3790
3791 if (!$error) {
3792 $db->commit();
3793 } else {
3794 $db->rollback();
3795 }
3796 } else {
3797 dol_print_error($db);
3798 $db->rollback();
3799 }
3800
3801 print '</td></tr>';
3802}
3803
3812function migrate_remise_except_entity($db, $langs, $conf)
3813{
3814 print '<tr><td colspan="4">';
3815
3816 print '<br>';
3817 print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\n";
3818
3819 $error = 0;
3820
3821 dolibarr_install_syslog("upgrade2::migrate_remise_except_entity");
3822
3823 $db->begin();
3824
3825 $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
3826 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
3827 //print $sqlSelect;
3828
3829 $resql = $db->query($sqlSelect);
3830 if ($resql) {
3831 $i = 0;
3832 $num = $db->num_rows($resql);
3833
3834 if ($num) {
3835 while ($i < $num) {
3836 $obj = $db->fetch_object($resql);
3837
3838 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
3839 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
3840
3841 $sqlSelect2 = "SELECT f.entity";
3842 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
3843 $sqlSelect2 .= " WHERE f.rowid = ".((int) $fk_facture);
3844 } elseif (!empty($obj->fk_facture_line)) {
3845 $sqlSelect2 = "SELECT f.entity";
3846 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
3847 $sqlSelect2 .= " WHERE fd.rowid = ".((int) $obj->fk_facture_line);
3848 $sqlSelect2 .= " AND fd.fk_facture = f.rowid";
3849 } else {
3850 $sqlSelect2 = "SELECT s.entity";
3851 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."societe as s";
3852 $sqlSelect2 .= " WHERE s.rowid = ".((int) $obj->fk_soc);
3853 }
3854
3855 $resql2 = $db->query($sqlSelect2);
3856 if ($resql2) {
3857 if ($db->num_rows($resql2) > 0) {
3858 $obj2 = $db->fetch_object($resql2);
3859
3860 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
3861 $sqlUpdate .= " entity = ".((int) $obj2->entity);
3862 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3863
3864 $result = $db->query($sqlUpdate);
3865 if (!$result) {
3866 $error++;
3867 dol_print_error($db);
3868 }
3869 }
3870 } else {
3871 $error++;
3872 dol_print_error($db);
3873 }
3874
3875 print '. ';
3876 $i++;
3877 }
3878 } else {
3879 print $langs->trans('AlreadyDone')."<br>\n";
3880 }
3881
3882 if (!$error) {
3883 $db->commit();
3884 } else {
3885 $db->rollback();
3886 }
3887 } else {
3888 dol_print_error($db);
3889 $db->rollback();
3890 }
3891
3892
3893 print '</td></tr>';
3894}
3895
3904function migrate_user_rights_entity($db, $langs, $conf)
3905{
3906 print '<tr><td colspan="4">';
3907
3908 print '<b>'.$langs->trans('MigrationUserRightsEntity')."</b><br>\n";
3909
3910 $error = 0;
3911
3912 dolibarr_install_syslog("upgrade2::migrate_user_rights_entity");
3913
3914 $db->begin();
3915
3916 $sqlSelect = "SELECT u.rowid, u.entity";
3917 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."user as u";
3918 $sqlSelect .= " WHERE u.entity > 1";
3919 //print $sqlSelect;
3920
3921 $resql = $db->query($sqlSelect);
3922 if ($resql) {
3923 $i = 0;
3924 $num = $db->num_rows($resql);
3925
3926 if ($num) {
3927 while ($i < $num) {
3928 $obj = $db->fetch_object($resql);
3929
3930 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
3931 $sqlUpdate .= " entity = ".((int) $obj->entity);
3932 $sqlUpdate .= " WHERE fk_user = ".((int) $obj->rowid);
3933
3934 $result = $db->query($sqlUpdate);
3935 if (!$result) {
3936 $error++;
3937 dol_print_error($db);
3938 }
3939
3940 print '. ';
3941 $i++;
3942 }
3943 } else {
3944 print $langs->trans('AlreadyDone')."<br>\n";
3945 }
3946
3947 if (!$error) {
3948 $db->commit();
3949 } else {
3950 $db->rollback();
3951 }
3952 } else {
3953 dol_print_error($db);
3954 $db->rollback();
3955 }
3956
3957
3958 print '</td></tr>';
3959}
3960
3969function migrate_usergroup_rights_entity($db, $langs, $conf)
3970{
3971 print '<tr><td colspan="4">';
3972
3973 print '<b>'.$langs->trans('MigrationUserGroupRightsEntity')."</b><br>\n";
3974
3975 $error = 0;
3976
3977 dolibarr_install_syslog("upgrade2::migrate_usergroup_rights_entity");
3978
3979 $db->begin();
3980
3981 $sqlSelect = "SELECT u.rowid, u.entity";
3982 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."usergroup as u";
3983 $sqlSelect .= " WHERE u.entity > 1";
3984 //print $sqlSelect;
3985
3986 $resql = $db->query($sqlSelect);
3987 if ($resql) {
3988 $i = 0;
3989 $num = $db->num_rows($resql);
3990
3991 if ($num) {
3992 while ($i < $num) {
3993 $obj = $db->fetch_object($resql);
3994
3995 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
3996 $sqlUpdate .= " entity = ".((int) $obj->entity);
3997 $sqlUpdate .= " WHERE fk_usergroup = ".((int) $obj->rowid);
3998
3999 $result = $db->query($sqlUpdate);
4000 if (!$result) {
4001 $error++;
4002 dol_print_error($db);
4003 }
4004
4005 print '. ';
4006 $i++;
4007 }
4008 } else {
4009 print $langs->trans('AlreadyDone')."<br>\n";
4010 }
4011
4012 if (!$error) {
4013 $db->commit();
4014 } else {
4015 $db->rollback();
4016 }
4017 } else {
4018 dol_print_error($db);
4019 $db->rollback();
4020 }
4021
4022
4023 print '</td></tr>';
4024}
4025
4036function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
4037{
4038 dolibarr_install_syslog("upgrade2::migrate_rename_directories");
4039
4040 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4041 dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname);
4042 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4043 }
4044}
4045
4046
4055function migrate_delete_old_files($db, $langs, $conf)
4056{
4057 $ret = true;
4058
4059 dolibarr_install_syslog("upgrade2::migrate_delete_old_files");
4060
4061 // List of files to delete
4062 $filetodeletearray = array(
4063 '/core/ajax/ajaxcompanies.php',
4064 '/core/triggers/interface_demo.class.php',
4065 '/core/menus/barre_left/default.php',
4066 '/core/menus/barre_top/default.php',
4067 '/core/modules/modComptabiliteExpert.class.php',
4068 '/core/modules/modCommercial.class.php',
4069 '/core/modules/modProduit.class.php',
4070 '/core/modules/modSkype.class.php',
4071 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4072 '/core/triggers/interface_modCommande_Ecotax.class.php',
4073 '/core/triggers/interface_modCommande_fraisport.class.php',
4074 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4075 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4076 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4077 '/core/menus/smartphone/iphone.lib.php',
4078 '/core/menus/smartphone/iphone_backoffice.php',
4079 '/core/menus/smartphone/iphone_frontoffice.php',
4080 '/core/menus/standard/auguria_backoffice.php',
4081 '/core/menus/standard/auguria_frontoffice.php',
4082 '/core/menus/standard/eldy_backoffice.php',
4083 '/core/menus/standard/eldy_frontoffice.php',
4084 '/core/modules/export/export_excel.modules.php',
4085 '/core/modules/export/export_csv.modules.php',
4086 '/core/modules/export/exportcsv.modules.php',
4087 '/core/modules/export/export_excel2007new.modules.php',
4088 '/core/modules/facture/pdf_crabe.modules.php',
4089 '/core/modules/facture/pdf_oursin.modules.php',
4090 '/core/modules/mailings/contacts2.modules.php',
4091 '/core/modules/mailings/contacts3.modules.php',
4092 '/core/modules/mailings/contacts4.modules.php',
4093 '/core/modules/mailings/framboise.modules.php',
4094 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4095 '/core/modules/mailings/peche.modules.php',
4096 '/core/modules/mailings/poire.modules.php',
4097 '/core/modules/mailings/kiwi.modules.php',
4098 '/core/boxes/box_members.php',
4099
4100 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4101 '/includes/nusoap/lib/class.*',
4102 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4103 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4104
4105 '/api/class/api_generic.class.php',
4106 '/asterisk/cidlookup.php',
4107 '/categories/class/api_category.class.php',
4108 '/categories/class/api_deprecated_category.class.php',
4109 '/compta/facture/class/api_invoice.class.php',
4110 '/commande/class/api_commande.class.php',
4111 '/partnership/class/api_partnership.class.php',
4112 '/product/class/api_product.class.php',
4113 '/recruitment/class/api_recruitment.class.php',
4114 '/societe/class/api_contact.class.php',
4115 '/societe/class/api_thirdparty.class.php',
4116 '/support/online.php',
4117 '/takepos/class/actions_takepos.class.php',
4118 '/user/class/api_user.class.php',
4119
4120 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4121 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4122 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4123 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4124 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4125 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4126 );
4127
4128 /*
4129 print '<tr><td colspan="4">';
4130 print '<b>'.$langs->trans('DeleteOldFiles')."</b><br>\n";
4131 print '</td></tr>';
4132 */
4133
4134 foreach ($filetodeletearray as $filetodelete) {
4135 //print '<b>'DOL_DOCUMENT_ROOT.$filetodelete."</b><br>\n";
4136 if (file_exists(DOL_DOCUMENT_ROOT.$filetodelete) || preg_match('/\*/', $filetodelete)) {
4137 //print "Process file ".$filetodelete."\n";
4138 $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, 0, 0, null, true, false);
4139 if (!$result) {
4140 $langs->load("errors");
4141 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4142 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4143 } else {
4144 //print $langs->trans("FileWasRemoved", $filetodelete).'<br>';
4145 }
4146 }
4147 }
4148
4149 return $ret;
4150}
4151
4160function migrate_delete_old_dir($db, $langs, $conf)
4161{
4162 $ret = true;
4163
4164 dolibarr_install_syslog("upgrade2::migrate_delete_old_dir");
4165
4166 // List of files to delete
4167 $filetodeletearray = array(
4168 DOL_DOCUMENT_ROOT.'/core/modules/facture/terre',
4169 DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure',
4170 );
4171
4172 // On linux, we can also removed old directory with a different case than new directory.
4173 if (!empty($_SERVER["WINDIR"])) {
4174 $filetodeletearray[] = DOL_DOCUMENT_ROOT.'/includes/phpoffice/PhpSpreadsheet';
4175 }
4176
4177 foreach ($filetodeletearray as $filetodelete) {
4178 $result = 1;
4179 if (file_exists($filetodelete)) {
4180 $result = dol_delete_dir_recursive($filetodelete);
4181 }
4182 if (!$result) {
4183 $langs->load("errors");
4184 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete);
4185 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4186 }
4187 }
4188
4189 return $ret;
4190}
4191
4192
4205function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $force = 0)
4206{
4207 global $user;
4208
4209 if (count($listofmodule) == 0) {
4210 return 0;
4211 }
4212
4213 if (!is_object($user)) {
4214 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4215 $user = new User($db); // To avoid error during migration
4216 }
4217
4218 dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".implode(',', array_keys($listofmodule)));
4219
4220 $reloadactionformodules = array(
4221 'MAIN_MODULE_AGENDA' => array('class' => 'modAgenda', 'remove' => 1),
4222 'MAIN_MODULE_API' => array('class' => 'modApi'),
4223 'MAIN_MODULE_BARCODE' => array('class' => 'modBarcode', 'remove' => 1),
4224 'MAIN_MODULE_BLOCKEDLOG' => array('class' => 'modBlockedLog', 'deleteinsertmenus' => 1),
4225 'MAIN_MODULE_CRON' => array('class' => 'modCron', 'remove' => 1),
4226 'MAIN_MODULE_EXTERNALSITE' => array('class' => 'modExternalSite', 'remove' => 1),
4227 'MAIN_MODULE_SOCIETE' => array('class' => 'modSociete', 'remove' => 1),
4228 'MAIN_MODULE_PRODUIT' => array('class' => 'modProduct'),
4229 'MAIN_MODULE_SERVICE' => array('class' => 'modService'),
4230 'MAIN_MODULE_COMMANDE' => array('class' => 'modCommande'),
4231 'MAIN_MODULE_DON' => array('class' => 'modDon'),
4232 'MAIN_MODULE_FACTURE' => array('class' => 'modFacture'),
4233 'MAIN_MODULE_FICHEINTER' => array('class' => 'modFicheinter'),
4234 'MAIN_MODULE_FOURNISSEUR' => array('class' => 'modFournisseur'),
4235 'MAIN_MODULE_EXPEDITION' => array('class' => 'modExpedition'),
4236 'MAIN_MODULE_EXPENSEREPORT' => array('class' => 'modExpenseReport'),
4237 'MAIN_MODULE_EVENTORGANIZATION' => array('class' => 'modEventOrganization', 'remove' => 1),
4238 'MAIN_MODULE_ECM' => array('class' => 'modECM', 'remove' => 1),
4239 'MAIN_MODULE_HOLIDAY' => array('class' => 'modHoliday', 'remove' => 1),
4240 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array('class' => 'modKnowledgeManagement', 'remove' => 1),
4241 'MAIN_MODULE_LOAN' => array('class' => 'modLoan', 'remove' => 1),
4242 'MAIN_MODULE_PAYBOX' => array('class' => 'modPaybox', 'remove' => 1),
4243 'MAIN_MODULE_PROPAL' => array('class' => 'modPropale'),
4244 'MAIN_MODULE_SUPPLIERPROPOSAL' => array('class' => 'modSupplierProposal', 'remove' => 1),
4245 'MAIN_MODULE_OPENSURVEY' => array('class' => 'modOpenSurvey', 'remove' => 1),
4246 'MAIN_MODULE_PRODUCTBATCH' => array('class' => 'modProductBatch', 'remove' => 1),
4247 'MAIN_MODULE_TAKEPOS' => array('class' => 'modTakePos', 'remove' => 1),
4248 'MAIN_MODULE_VARIANTS' => array('class' => 'modVariants', 'remove' => 1),
4249 'MAIN_MODULE_EMAILCOLLECTOR' => array('class' => 'modEmailCollector', 'remove' => 1),
4250 );
4251
4252 foreach ($listofmodule as $moduletoreload => $reloadmode) { // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
4253 if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && !$force)) {
4254 continue; // Discard reload if module not enabled
4255 }
4256
4257 $mod = null;
4258
4259 if (!empty($reloadactionformodules[$moduletoreload])) {
4260 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload." with mode ".$reloadmode);
4261
4262 $val = $reloadactionformodules[$moduletoreload];
4263 $classformodule = $val['class'];
4264 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/'.$classformodule.'.class.php';
4265 if ($res) {
4266 $mod = new $classformodule($db);
4267 if (!empty($val['remove'])) {
4268 $mod->remove('noboxes');
4269 }
4270 if (!empty($val['deleteinsertmenus'])) {
4271 // We only reload menus
4272 $mod->delete_menus();
4273 $mod->insert_menus();
4274 } else {
4275 $mod->init($reloadmode);
4276 }
4277 }
4278 } else { // Other generic cases/modules
4279 $reg = array();
4280 $tmp = preg_match('/MAIN_MODULE_([a-zA-Z0-9]+)/', $moduletoreload, $reg);
4281 if (!empty($reg[1])) {
4282 if (strtoupper($moduletoreload) == $moduletoreload) { // If key is un uppercase
4283 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4284 } else { // If key is a mix of up and low case
4285 $moduletoreloadshort = $reg[1];
4286 }
4287
4288 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort." with mode ".$reloadmode." (generic code)");
4289
4290 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php';
4291 if ($res) {
4292 $classname = 'mod'.$moduletoreloadshort;
4293 $mod = new $classname($db);
4294
4295 //$mod->remove('noboxes');
4296 $mod->delete_menus(); // We must delete to be sure it is inserted with new values
4297 $mod->init($reloadmode);
4298 } else {
4299 dolibarr_install_syslog('Failed to include '.DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php');
4300
4301 $res = @dol_include_once(strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
4302 if ($res) {
4303 $classname = 'mod'.$moduletoreloadshort;
4304 $mod = new $classname($db);
4305 $mod->init($reloadmode);
4306 } else {
4307 dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4308 print "Error, can't find module with name ".$moduletoreload."\n";
4309 return -1;
4310 }
4311 }
4312 } else {
4313 dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_ERR);
4314 print "Error, can't find module with name ".$moduletoreload."\n";
4315 return -1;
4316 }
4317 }
4318
4319 if (!empty($mod) && is_object($mod)) {
4320 print '<tr class="trforrunsql"><td colspan="4">';
4321 print '<b>'.$langs->trans('Upgrade').'</b>: ';
4322 print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
4323 print "<!-- (".$reloadmode.") -->";
4324 print "<br>\n";
4325 print '</td></tr>';
4326 }
4327 }
4328
4329 return 1;
4330}
4331
4332
4333
4342function migrate_reload_menu($db, $langs, $conf)
4343{
4344 global $conf;
4345 dolibarr_install_syslog("upgrade2::migrate_reload_menu");
4346
4347 // Define list of menu handlers to initialize
4348 $listofmenuhandler = array();
4349 if (getDolGlobalString('MAIN_MENU_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENU_SMARTPHONE') == 'auguria_menu'
4350 || getDolGlobalString('MAIN_MENUFRONT_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE') == 'auguria_menu') {
4351 $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers
4352 }
4353
4354 foreach ($listofmenuhandler as $key => $val) {
4355 print '<tr class="trforrunsql"><td colspan="4">';
4356
4357 //print "x".$key;
4358 print '<br>';
4359 print '<b>'.$langs->trans('Upgrade').'</b>: '.$langs->trans('MenuHandler')." ".$key."<br>\n";
4360
4361 // Load sql ini_menu_handler.sql file
4362 $dir = DOL_DOCUMENT_ROOT."/core/menus/";
4363 $file = 'init_menu_'.$key.'.sql';
4364 if (file_exists($dir.$file)) {
4365 $result = run_sql($dir.$file, 1, '', 1, $key);
4366 }
4367
4368 print '</td></tr>';
4369 }
4370
4371 return 1;
4372}
4373
4380{
4381 global $conf, $db, $langs, $user;
4382
4383 print '<tr><td colspan="4">';
4384
4385 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4386
4387 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4388 $fuser = new User($db);
4389 if (!is_object($user)) {
4390 $user = $fuser; // To avoid error during migration
4391 }
4392
4393 $sql = "SELECT rowid as uid, entity from ".MAIN_DB_PREFIX."user"; // Get list of all users
4394 $resql = $db->query($sql);
4395 if ($resql) {
4396 while ($obj = $db->fetch_object($resql)) {
4397 //$fuser->fetch($obj->uid);
4398 $fuser->id = $obj->uid;
4399 $fuser->entity = $obj->entity;
4400
4401 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4402 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4403 if ($entity > 1) {
4404 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4405 } else {
4406 $dir = $conf->user->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4407 }
4408
4409 if ($dir) {
4410 //print "Process user id ".$fuser->id."<br>\n";
4411 $origin = $dir.'/'.get_exdir($fuser->id, 2, 0, 1, $fuser, 'user'); // Use old behaviour to get x/y path
4412 $destin = $dir.'/'.$fuser->id;
4413
4414 $origin_osencoded = dol_osencode($origin);
4415
4416 dol_mkdir($destin);
4417
4418 //echo '<hr>'.$origin.' -> '.$destin;
4419 if (dol_is_dir($origin)) {
4420 $handle = opendir($origin_osencoded);
4421 if (is_resource($handle)) {
4422 while (($file = readdir($handle)) !== false) {
4423 if ($file == '.' || $file == '..') {
4424 continue;
4425 }
4426
4427 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4428 $thumbs = opendir($origin_osencoded.'/'.$file);
4429 if (is_resource($thumbs)) {
4430 dol_mkdir($destin.'/'.$file);
4431 while (($thumb = readdir($thumbs)) !== false) {
4432 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4433 if ($thumb == '.' || $thumb == '..') {
4434 continue;
4435 }
4436
4437 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4438 print '.';
4439 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, 0, 0);
4440 //var_dump('aaa');exit;
4441 }
4442 }
4443 // dol_delete_dir($origin.'/'.$file);
4444 }
4445 } else { // it is a file
4446 if (!dol_is_file($destin.'/'.$file)) {
4447 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4448 print '.';
4449 dol_copy($origin.'/'.$file, $destin.'/'.$file, 0, 0);
4450 //var_dump('eee');exit;
4451 }
4452 }
4453 }
4454 }
4455 }
4456 }
4457 }
4458 }
4459
4460 print '</td></tr>';
4461}
4462
4469{
4470 global $db, $langs, $user;
4471
4472 print '<tr><td colspan="4">';
4473
4474 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4475
4476 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4477 $fuser = new User($db);
4478 if (!is_object($user)) {
4479 $user = $fuser; // To avoid error during migration
4480 }
4481
4482 $sql = "SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX."user"; // Get list of all users
4483 $resql = $db->query($sql);
4484 if ($resql) {
4485 while ($obj = $db->fetch_object($resql)) {
4486 //$fuser->fetch($obj->uid);
4487 $fuser->id = $obj->uid;
4488 $fuser->entity = $obj->entity;
4489 $fuser->photo = $obj->photo;
4490
4491 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4492 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4493 if ($entity > 1) {
4494 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4495 } else {
4496 $dir = DOL_DATA_ROOT.'/users';
4497 }
4498
4499 if ($dir) {
4500 //print "Process user id ".$fuser->id."<br>\n";
4501 $origin = $dir.'/'.$fuser->id;
4502 $destin = $dir.'/'.$fuser->id.'/photos';
4503
4504 $origin_osencoded = dol_osencode($origin);
4505
4506 dol_mkdir($destin);
4507
4508 //echo '<hr>'.$origin.' -> '.$destin;
4509 if (dol_is_dir($origin)) {
4510 $handle = opendir($origin_osencoded);
4511 if (is_resource($handle)) {
4512 while (($file = readdir($handle)) !== false) {
4513 if ($file == '.' || $file == '..' || $file == 'photos') {
4514 continue;
4515 }
4516 if (!empty($fuser->photo) && ($file != $fuser->photo && $file != 'thumbs')) {
4517 continue;
4518 }
4519
4520 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4521 $thumbs = opendir($origin_osencoded.'/'.$file);
4522 if (is_resource($thumbs)) {
4523 dol_mkdir($destin.'/'.$file);
4524 while (($thumb = readdir($thumbs)) !== false) {
4525 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4526 if ($thumb == '.' || $thumb == '..') {
4527 continue;
4528 }
4529
4530 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4531 print '.';
4532 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, 0, 0);
4533 }
4534 }
4535 // dol_delete_dir($origin.'/'.$file);
4536 }
4537 } else { // it is a file
4538 if (!dol_is_file($destin.'/'.$file)) {
4539 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4540 print '.';
4541 dol_copy($origin.'/'.$file, $destin.'/'.$file, 0, 0);
4542 }
4543 }
4544 }
4545 }
4546 }
4547 }
4548 }
4549 }
4550
4551 print '</td></tr>';
4552}
4553
4554
4555/* A faire egalement: Modif statut paye et fk_facture des factures payes completement
4556
4557On recherche facture incorrecte:
4558select 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
4559having f.total_ttc = sum(pf.amount)
4560
4561On les corrige:
4562update llx_facture set paye=1, fk_statut=2 where close_code is null
4563and rowid in (...)
4564*/
4565
4573{
4574 global $db, $langs;
4575 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
4576 $error = 0;
4577 $db->begin();
4578 print '<tr><td colspan="4">';
4579 $sql = 'SELECT rowid, socialnetworks';
4580 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE';
4581 $sql .= " skype IS NOT NULL OR skype <> ''";
4582 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4583 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4584 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4585 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4586 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4587 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4588 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4589 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4590 //print $sql;
4591 $resql = $db->query($sql);
4592 if ($resql) {
4593 while ($obj = $db->fetch_object($resql)) {
4594 $arraysocialnetworks = array();
4595 if (!empty($obj->skype)) {
4596 $arraysocialnetworks['skype'] = $obj->skype;
4597 }
4598 if (!empty($obj->twitter)) {
4599 $arraysocialnetworks['twitter'] = $obj->twitter;
4600 }
4601 if (!empty($obj->facebook)) {
4602 $arraysocialnetworks['facebook'] = $obj->facebook;
4603 }
4604 if (!empty($obj->linkedin)) {
4605 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4606 }
4607 if (!empty($obj->instagram)) {
4608 $arraysocialnetworks['instagram'] = $obj->instagram;
4609 }
4610 if (!empty($obj->snapchat)) {
4611 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4612 }
4613 if (!empty($obj->googleplus)) {
4614 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4615 }
4616 if (!empty($obj->youtube)) {
4617 $arraysocialnetworks['youtube'] = $obj->youtube;
4618 }
4619 if (!empty($obj->whatsapp)) {
4620 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4621 }
4622 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4623 $obj->socialnetworks = '[]';
4624 }
4625 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4626 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4627 $sqlupd .= ', skype=null';
4628 $sqlupd .= ', twitter=null';
4629 $sqlupd .= ', facebook=null';
4630 $sqlupd .= ', linkedin=null';
4631 $sqlupd .= ', instagram=null';
4632 $sqlupd .= ', snapchat=null';
4633 $sqlupd .= ', googleplus=null';
4634 $sqlupd .= ', youtube=null';
4635 $sqlupd .= ', whatsapp=null';
4636 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4637 //print $sqlupd."<br>";
4638 $resqlupd = $db->query($sqlupd);
4639 if (!$resqlupd) {
4640 dol_print_error($db);
4641 $error++;
4642 }
4643 }
4644 } else {
4645 $error++;
4646 }
4647 if (!$error) {
4648 $db->commit();
4649 } else {
4650 dol_print_error($db);
4651 $db->rollback();
4652 }
4653 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."</b><br>\n";
4654 print '</td></tr>';
4655}
4656
4664{
4665 global $db, $langs;
4666
4667 print '<tr><td colspan="4">';
4668 $error = 0;
4669 $db->begin();
4670 print '<tr><td colspan="4">';
4671 $sql = 'SELECT rowid, socialnetworks';
4672 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE ';
4673 $sql .= " skype IS NOT NULL OR skype <> ''";
4674 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4675 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4676 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4677 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4678 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4679 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4680 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4681 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4682 //print $sql;
4683 $resql = $db->query($sql);
4684 if ($resql) {
4685 while ($obj = $db->fetch_object($resql)) {
4686 $arraysocialnetworks = array();
4687 if (!empty($obj->skype)) {
4688 $arraysocialnetworks['skype'] = $obj->skype;
4689 }
4690 if (!empty($obj->twitter)) {
4691 $arraysocialnetworks['twitter'] = $obj->twitter;
4692 }
4693 if (!empty($obj->facebook)) {
4694 $arraysocialnetworks['facebook'] = $obj->facebook;
4695 }
4696 if (!empty($obj->linkedin)) {
4697 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4698 }
4699 if (!empty($obj->instagram)) {
4700 $arraysocialnetworks['instagram'] = $obj->instagram;
4701 }
4702 if (!empty($obj->snapchat)) {
4703 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4704 }
4705 if (!empty($obj->googleplus)) {
4706 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4707 }
4708 if (!empty($obj->youtube)) {
4709 $arraysocialnetworks['youtube'] = $obj->youtube;
4710 }
4711 if (!empty($obj->whatsapp)) {
4712 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4713 }
4714 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4715 $obj->socialnetworks = '[]';
4716 }
4717 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4718 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4719 $sqlupd .= ', skype=null';
4720 $sqlupd .= ', twitter=null';
4721 $sqlupd .= ', facebook=null';
4722 $sqlupd .= ', linkedin=null';
4723 $sqlupd .= ', instagram=null';
4724 $sqlupd .= ', snapchat=null';
4725 $sqlupd .= ', googleplus=null';
4726 $sqlupd .= ', youtube=null';
4727 $sqlupd .= ', whatsapp=null';
4728 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4729 //print $sqlupd."<br>";
4730 $resqlupd = $db->query($sqlupd);
4731 if (!$resqlupd) {
4732 dol_print_error($db);
4733 $error++;
4734 }
4735 }
4736 } else {
4737 $error++;
4738 }
4739 if (!$error) {
4740 $db->commit();
4741 } else {
4742 dol_print_error($db);
4743 $db->rollback();
4744 }
4745 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."</b><br>\n";
4746 print '</td></tr>';
4747}
4748
4756{
4757 global $db, $langs;
4758 // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
4759 $error = 0;
4760 $db->begin();
4761 print '<tr><td colspan="4">';
4762 $sql = 'SELECT rowid, socialnetworks';
4763 $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE';
4764 $sql .= " jabberid IS NOT NULL OR jabberid <> ''";
4765 $sql .= " OR skype IS NOT NULL OR skype <> ''";
4766 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4767 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4768 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4769 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4770 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4771 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4772 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4773 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4774 //print $sql;
4775 $resql = $db->query($sql);
4776 if ($resql) {
4777 while ($obj = $db->fetch_object($resql)) {
4778 $arraysocialnetworks = array();
4779 if (!empty($obj->jabberid)) {
4780 $arraysocialnetworks['jabber'] = $obj->jabberid;
4781 }
4782 if (!empty($obj->skype)) {
4783 $arraysocialnetworks['skype'] = $obj->skype;
4784 }
4785 if (!empty($obj->twitter)) {
4786 $arraysocialnetworks['twitter'] = $obj->twitter;
4787 }
4788 if (!empty($obj->facebook)) {
4789 $arraysocialnetworks['facebook'] = $obj->facebook;
4790 }
4791 if (!empty($obj->linkedin)) {
4792 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4793 }
4794 if (!empty($obj->instagram)) {
4795 $arraysocialnetworks['instagram'] = $obj->instagram;
4796 }
4797 if (!empty($obj->snapchat)) {
4798 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4799 }
4800 if (!empty($obj->googleplus)) {
4801 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4802 }
4803 if (!empty($obj->youtube)) {
4804 $arraysocialnetworks['youtube'] = $obj->youtube;
4805 }
4806 if (!empty($obj->whatsapp)) {
4807 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4808 }
4809 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4810 $obj->socialnetworks = '[]';
4811 }
4812 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4813 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4814 $sqlupd .= ', jabberid=null';
4815 $sqlupd .= ', skype=null';
4816 $sqlupd .= ', twitter=null';
4817 $sqlupd .= ', facebook=null';
4818 $sqlupd .= ', linkedin=null';
4819 $sqlupd .= ', instagram=null';
4820 $sqlupd .= ', snapchat=null';
4821 $sqlupd .= ', googleplus=null';
4822 $sqlupd .= ', youtube=null';
4823 $sqlupd .= ', whatsapp=null';
4824 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4825 //print $sqlupd."<br>";
4826 $resqlupd = $db->query($sqlupd);
4827 if (!$resqlupd) {
4828 dol_print_error($db);
4829 $error++;
4830 }
4831 }
4832 } else {
4833 $error++;
4834 }
4835 if (!$error) {
4836 $db->commit();
4837 } else {
4838 dol_print_error($db);
4839 $db->rollback();
4840 }
4841 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."</b><br>\n";
4842 print '</td></tr>';
4843}
4844
4852{
4853 global $db, $langs;
4854 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
4855 $error = 0;
4856 $db->begin();
4857 print '<tr><td colspan="4">';
4858 $sql = 'SELECT rowid, socialnetworks';
4859 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE ';
4860 $sql .= " skype IS NOT NULL OR skype <> ''";
4861 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4862 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4863 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4864 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4865 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4866 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4867 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4868 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4869 //print $sql;
4870 $resql = $db->query($sql);
4871 if ($resql) {
4872 while ($obj = $db->fetch_object($resql)) {
4873 $arraysocialnetworks = array();
4874 if (!empty($obj->skype)) {
4875 $arraysocialnetworks['skype'] = $obj->skype;
4876 }
4877 if (!empty($obj->twitter)) {
4878 $arraysocialnetworks['twitter'] = $obj->twitter;
4879 }
4880 if (!empty($obj->facebook)) {
4881 $arraysocialnetworks['facebook'] = $obj->facebook;
4882 }
4883 if (!empty($obj->linkedin)) {
4884 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4885 }
4886 if (!empty($obj->instagram)) {
4887 $arraysocialnetworks['instagram'] = $obj->instagram;
4888 }
4889 if (!empty($obj->snapchat)) {
4890 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4891 }
4892 if (!empty($obj->googleplus)) {
4893 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4894 }
4895 if (!empty($obj->youtube)) {
4896 $arraysocialnetworks['youtube'] = $obj->youtube;
4897 }
4898 if (!empty($obj->whatsapp)) {
4899 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4900 }
4901 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4902 $obj->socialnetworks = '[]';
4903 }
4904 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4905 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4906 $sqlupd .= ', skype=null';
4907 $sqlupd .= ', twitter=null';
4908 $sqlupd .= ', facebook=null';
4909 $sqlupd .= ', linkedin=null';
4910 $sqlupd .= ', instagram=null';
4911 $sqlupd .= ', snapchat=null';
4912 $sqlupd .= ', googleplus=null';
4913 $sqlupd .= ', youtube=null';
4914 $sqlupd .= ', whatsapp=null';
4915 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4916 //print $sqlupd."<br>";
4917 $resqlupd = $db->query($sqlupd);
4918 if (!$resqlupd) {
4919 dol_print_error($db);
4920 $error++;
4921 }
4922 }
4923 } else {
4924 $error++;
4925 }
4926 if (!$error) {
4927 $db->commit();
4928 } else {
4929 dol_print_error($db);
4930 $db->rollback();
4931 }
4932 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."</b><br>\n";
4933 print '</td></tr>';
4934}
4935
4936
4943function migrate_export_import_profiles($mode = 'export')
4944{
4945 global $db, $langs;
4946
4947 $error = 0;
4948 $resultstring = '';
4949
4950 $db->begin();
4951
4952 print '<tr class="trforrunsql"><td colspan="4">';
4953 $sql = 'SELECT rowid, field';
4954 if ($mode == 'export') {
4955 $sql .= ', filter';
4956 }
4957 $sql .= ' FROM '.MAIN_DB_PREFIX.$mode.'_model WHERE';
4958 $sql .= " type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
4959 //print $sql;
4960 $resql = $db->query($sql);
4961 if ($resql) {
4962 while ($obj = $db->fetch_object($resql)) {
4963 $oldfield = $obj->field;
4964 $newfield = str_replace(array(',f.facnumber', 'f.facnumber,', 'f.total,', 'f.tva,'), array(',f.ref', 'f.ref,', 'f.total_ht,', 'f.total_tva,'), $oldfield);
4965
4966 if ($mode == 'export') {
4967 $oldfilter = $obj->filter;
4968 $newfilter = str_replace(array('f.facnumber=', 'f.total=', 'f.tva='), array('f.ref=', 'f.total_ht=', 'f.total_tva='), $oldfilter);
4969 } else {
4970 $oldfilter = '';
4971 $newfilter = '';
4972 }
4973
4974 if ($oldfield != $newfield || $oldfilter != $newfilter) {
4975 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX.$mode."_model SET field = '".$db->escape($newfield)."'";
4976 if ($mode == 'export') {
4977 $sqlupd .= ", filter = '".$db->escape($newfilter)."'";
4978 }
4979 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4980 $resultstring .= '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd."</td></tr>\n";
4981 $resqlupd = $db->query($sqlupd);
4982 if (!$resqlupd) {
4983 dol_print_error($db);
4984 $error++;
4985 }
4986 }
4987 }
4988 } else {
4989 $error++;
4990 }
4991 if (!$error) {
4992 $db->commit();
4993 } else {
4994 dol_print_error($db);
4995 $db->rollback();
4996 }
4997 print '<b>'.$langs->trans('MigrationImportOrExportProfiles', $mode)."</b><br>\n";
4998 print '</td></tr>';
4999
5000 if ($resultstring) {
5001 print $resultstring;
5002 } else {
5003 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5004 }
5005}
5006
5013{
5014 global $db, $langs;
5015
5016 $error = 0;
5017 $resultstring = '';
5018
5019 $db->begin();
5020 print '<tr class="trforrunsql"><td colspan="4">';
5021 print '<b>'.$langs->trans('MigrationContractLineRank')."</b><br>\n";
5022
5023 $sql = "SELECT c.rowid as cid ,cd.rowid as cdid,cd.rang FROM ".$db->prefix()."contratdet as cd INNER JOIN ".$db->prefix()."contrat as c ON c.rowid=cd.fk_contrat AND cd.rang=0";
5024 $sql .= " ORDER BY c.rowid,cd.rowid";
5025
5026 $resql = $db->query($sql);
5027 if ($resql) {
5028 $currentRank = 0;
5029 $current_contract = 0;
5030 while ($obj = $db->fetch_object($resql)) {
5031 if (empty($current_contract) || $current_contract == $obj->cid) {
5032 $currentRank++;
5033 } else {
5034 $currentRank = 1;
5035 }
5036
5037 $sqlUpd = "UPDATE ".$db->prefix()."contratdet SET rang=".(int) $currentRank." WHERE rowid=".(int) $obj->cdid;
5038 $resultstring = '.';
5039 print $resultstring;
5040 $resqlUpd = $db->query($sqlUpd);
5041 if (!$resqlUpd) {
5042 dol_print_error($db);
5043 $error++;
5044 }
5045
5046 $current_contract = $obj->cid;
5047 }
5048 } else {
5049 $error++;
5050 }
5051 if (!$error) {
5052 $db->commit();
5053 } else {
5054 $db->rollback();
5055 }
5056
5057 print '</td></tr>';
5058
5059 if (!$resultstring) {
5060 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5061 }
5062}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:68
Class to manage Blocked Log.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
Class to manage hooks.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation models.
Class to manage order lines.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:535
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:626
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:690
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:88
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
Definition upgrade2.php:834
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Re-enable features modules.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a lien dans llx_societe_rem...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
if($db->connected) if( $ret) migrate_paiements($db, $langs, $conf)
Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures)
Definition upgrade2.php:755
migrate_project_user_resp($db, $langs, $conf)
Migration du champ fk_user_resp de llx_projet vers llx_element_contact.
migrate_contracts_open($db, $langs, $conf)
Reouverture des contrats qui ont au moins une ligne non fermee.
migrate_shipping_delivery($db, $langs, $conf)
Migrate link stored into fk_expedition into llx_element_element.
migrate_delete_old_dir($db, $langs, $conf)
Remove deprecated directories.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration du champ stock dans produits.
migrate_paiementfourn_facturefourn($db, $langs, $conf)
Factures fournisseurs.
migrate_contacts_socialnetworks()
Migrate contacts fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_customerorder_shipping($db, $langs, $conf)
Migrate order ref_customer and date_delivery fields to llx_expedition.
migrate_detail_livraison($db, $langs, $conf)
Migration des details commandes dans les details livraisons.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Corrige paiement orphelins (liens paumes suite a bugs) Pour verifier s'il reste des orphelins: select...
Definition upgrade2.php:944
migrate_price_contrat($db, $langs, $conf)
Update total of contract lines.
migrate_users_socialnetworks()
Migrate users fields facebook and co to socialnetworks.
migrate_user_photospath2()
Migrate file from old path users/99/file.jpg into users/99/photos/file.jpg.
migrate_contracts_det($db, $langs, $conf)
Mise a jour des contrats (gestion du contrat + detail de contrat)
migrate_price_facture($db, $langs, $conf)
Update total of invoice lines.
migrate_usergroup_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_usergroup_rights.
migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
Migration des tables de relation.
migrate_modeles($db, $langs, $conf)
Mise a jour des modeles selectionnes.
migrate_reset_blocked_log($db, $langs, $conf)
Migrate to reset the blocked log for V7+ algorithm.
migrate_mode_reglement($db, $langs, $conf)
Migrate link stored into fk_mode_reglement.
migrate_export_import_profiles($mode='export')
Migrate export and import profiles to fix field name that was renamed.
migrate_contracts_date2($db, $langs, $conf)
Update contracts with date min real if service date is lower.
migrate_commande_expedition($db, $langs, $conf)
Correspondence des expeditions et des commandes clients dans la table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignment to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondence des livraisons et des commandes clients dans la table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment to owner.
migrate_contracts_date1($db, $langs, $conf)
Mise a jour des date de contrats non renseignees.
migrate_remise_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise.
migrate_contractdet_rank()
Migrate Rank into contract line.
migrate_menus($db, $langs, $conf)
Migration of menus (use only 1 table instead of 3) 2.6 -> 2.7.
migrate_categorie_association($db, $langs, $conf)
Migrate categorie association.
migrate_delete_old_files($db, $langs, $conf)
Delete deprecated files.
migrate_price_commande_fournisseur($db, $langs, $conf)
Update total of purchase order lines.
migrate_element_time($db, $langs, $conf)
Migrate duration in seconds.
migrate_members_socialnetworks()
Migrate members fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_reload_menu($db, $langs, $conf)
Reload SQL menu file (if dynamic menus, if modified by version)
migrate_price_commande($db, $langs, $conf)
Update total of sales order lines.
migrate_shipping_delivery2($db, $langs, $conf)
We try to complete field ref_customer and date_delivery that are empty into llx_livraison.