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