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