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