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