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