dolibarr 25.0.0-alpha
upgrade2.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
3 * Copyright (C) 2005-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 *
24 * Upgrade2 scripts can be ran from command line with syntax:
25 *
26 * cd htdocs/install
27 * php upgrade.php 3.4.0 3.5.0 [dirmodule|ignoredbversion]
28 * php upgrade2.php 3.4.0 3.5.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
29 *
30 * And for final step:
31 * php step5.php 3.4.0 3.5.0
32 *
33 * Return code is 0 if OK, >0 if error
34 *
35 * Note: To just enable a module from command line, use this syntax:
36 * php upgrade2.php 0.0.0 0.0.0 [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE]
37 */
38
44define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
45include_once 'inc.php';
46
51if (!file_exists($conffile)) {
52 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").';
53}
54require_once $conffile;
70'
71@phan-var-force string $dolibarr_main_db_type
72';
73
74require_once $dolibarr_main_document_root.'/compta/facture/class/facture.class.php';
75require_once $dolibarr_main_document_root.'/comm/propal/class/propal.class.php';
76require_once $dolibarr_main_document_root.'/contrat/class/contrat.class.php';
77require_once $dolibarr_main_document_root.'/commande/class/commande.class.php';
78require_once $dolibarr_main_document_root.'/fourn/class/fournisseur.commande.class.php';
79require_once $dolibarr_main_document_root.'/core/lib/price.lib.php';
80require_once $dolibarr_main_document_root.'/core/class/menubase.class.php';
81require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
82require_once $dolibarr_main_document_root.'/core/lib/files.lib.php';
83require_once $dolibarr_main_document_root.'/user/class/user.class.php';
84require_once $dolibarr_main_document_root.'/blockedlog/lib/blockedlog.lib.php';
85
86global $langs;
87
88
89$error = 0;
90
91
92// This page can be long. We increase the allowed delay, but this does not work when we are in safe_mode.
93$err = error_reporting();
94error_reporting(0);
95if (getDolGlobalInt('MAIN_OVERRIDE_TIME_LIMIT')) {
96 @set_time_limit(getDolGlobalInt('MAIN_OVERRIDE_TIME_LIMIT'));
97} else {
98 @set_time_limit(600);
99}
100error_reporting($err);
101
102$setuplang = GETPOST("selectlang", 'aZ09', 3) ? GETPOST("selectlang", 'aZ09', 3) : 'auto';
103$langs->setDefaultLang($setuplang);
104$versionfrom = GETPOST("versionfrom", 'alpha', 3) ? GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
105$versionto = GETPOST("versionto", 'alpha', 3) ? GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
106$enablemodules = GETPOST("enablemodules", 'alpha', 3) ? GETPOST("enablemodules", 'alpha', 3) : (empty($argv[3]) ? '' : $argv[3]);
107
108$langs->loadLangs(array("admin", "install", "bills", "suppliers"));
109
110if ($dolibarr_main_db_type == 'mysqli') {
111 $choix = 1;
112}
113if ($dolibarr_main_db_type == 'pgsql') {
114 $choix = 2;
115}
116if ($dolibarr_main_db_type == 'mssql') {
117 $choix = 3;
118}
119
120
121dolibarr_install_syslog("--- upgrade2: entering upgrade2.php page ".$versionfrom." ".$versionto." ".$enablemodules);
122if (!is_object($conf)) {
123 dolibarr_install_syslog("upgrade2: conf file not initialized", LOG_ERR);
124}
125
126
127
128/*
129 * View
130 */
131
132if ((!$versionfrom || preg_match('/version/', $versionfrom)) && (!$versionto || preg_match('/version/', $versionto))) {
133 print 'Error: Parameter versionfrom or versionto missing or having a bad format.'."\n";
134 print 'Upgrade must be ran from command line with parameters or called from page install/index.php (like a first install)'."\n";
135 // Test if batch mode
136 $sapi_type = php_sapi_name();
137 $script_file = basename(__FILE__);
138 if (substr($sapi_type, 0, 3) == 'cli') {
139 print 'Syntax from command line: '.$script_file." x.y.z a.b.c [MAIN_MODULE_NAME1_TO_ENABLE,MAIN_MODULE_NAME2_TO_ENABLE...]\n";
140 print 'Example, upgrade from 19 to 20: '.$script_file." 19.0.0 20.0.0\n";
141 print 'Example, enable a module only: '.$script_file." 0.0.0 0.0.0 MAIN_MODULE_Adherent\n";
142 print "\n";
143 }
144 exit;
145}
146
147pHeader('', 'step5', GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'upgrade', 'versionfrom='.$versionfrom.'&versionto='.$versionto, '', 'main-inside main-inside-borderbottom');
148
149
150$db = null;
151
152if (!GETPOST('action', 'aZ09') || preg_match('/upgrade/i', GETPOST('action', 'aZ09'))) {
153 print '<h3><img class="valignmiddle inline-block paddingright" src="../public/theme/common/database.svg" width="20" alt="Database"> ';
154 print '<span class="inline-block valignmiddle">'.$langs->trans('DataMigration').'</span></h3>';
155
156 print '<table class="centpercent">';
157
158 // If password is encoded, we decode it
159 if ((!empty($dolibarr_main_db_pass) && preg_match('/(crypted|dolcrypt):/i', (string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
160 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
161 if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
162 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', (string) $dolibarr_main_db_pass);
163 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
164 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_pass);
165 } elseif (preg_match('/dolcrypt:/i', (string) $dolibarr_main_db_pass)) {
166 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
167 $dolibarr_main_db_pass = dolDecrypt((string) $dolibarr_main_db_pass);
168 } else {
169 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_encrypted_pass);
170 }
171 }
172
173 // $conf is already instantiated inside inc.php
174 $conf->db->type = $dolibarr_main_db_type;
175 $conf->db->host = $dolibarr_main_db_host;
176 $conf->db->port = $dolibarr_main_db_port;
177 $conf->db->name = $dolibarr_main_db_name;
178 $conf->db->user = $dolibarr_main_db_user;
179 $conf->db->pass = $dolibarr_main_db_pass;
180
181 $db = getDoliDBInstance($conf->db->type, $conf->db->host, (string) $conf->db->user, (string) $conf->db->pass, (string) $conf->db->name, (int) $conf->db->port);
182
183 if (!$db->connected) {
184 print '<tr><td colspan="4">'.$langs->trans("ErrorFailedToConnectToDatabase", $conf->db->name).'</td><td class="right">'.$langs->trans('Error').'</td></tr>';
185 dolibarr_install_syslog('upgrade2: failed to connect to database :'.(string) $conf->db->name.' on '.(string) $conf->db->host.' for user '.(string) $conf->db->user, LOG_ERR);
186 $error++;
187 }
188
189 if (!$error) {
190 if ($db->database_selected) {
191 dolibarr_install_syslog('upgrade2: database connection successful :'.$dolibarr_main_db_name);
192 } else {
193 $error++;
194 }
195 }
196
197 if (empty($dolibarr_main_db_encryption)) {
198 $dolibarr_main_db_encryption = 0;
199 }
200 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
201 if (empty($dolibarr_main_db_cryptkey)) {
202 $dolibarr_main_db_cryptkey = '';
203 }
204 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
205
206 // Load global conf
207 $conf->setValues($db);
208
209
210 // Reforce log activation (samecode than into the inc.php)
211 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
212 $conf->modules['syslog'] = 'syslog';
213 $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
214 if (!defined('SYSLOG_HANDLERS')) {
215 define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
216 }
217 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
218 if (@is_writable('/tmp')) {
219 define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
220 } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
221 define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
222 } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
223 define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
224 } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
225 define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
226 } elseif (@is_writable('../../')) {
227 define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
228 }
229 //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
230 }
231 if (defined('SYSLOG_FILE')) {
232 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
233 }
234 if (!defined('SYSLOG_FILE_NO_ERROR')) {
235 define('SYSLOG_FILE_NO_ERROR', 1);
236 }
237 // We init log handler for install
238 $handlers = array('mod_syslog_file');
239 foreach ($handlers as $handler) {
240 $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
241 if (!file_exists($file)) {
242 throw new Exception('Missing log handler file '.$handler.'.php');
243 }
244
245 require_once $file;
246 $loghandlerinstance = new $handler();
247 if (!$loghandlerinstance instanceof LogHandler) {
248 throw new Exception('Log handler does not extend LogHandler');
249 }
250
251 if (empty($conf->loghandlers[$handler])) {
252 $conf->loghandlers[$handler] = $loghandlerinstance;
253 }
254 }
255
256
257 $listofentities = array(1);
258
259 // Create the global $hookmanager object
260 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
261 $hookmanager = new HookManager($db);
262 $hookmanager->initHooks(array('upgrade2'));
263
264 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto);
265 $object = new stdClass();
266 $action = "upgrade";
267 $reshook = $hookmanager->executeHooks('doUpgradeBefore', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
268 if ($reshook >= 0 && is_array($hookmanager->resArray)) {
269 // Example: $hookmanager->resArray = array(2, 3, 10);
270 $listofentities = array_unique(array_merge($listofentities, $hookmanager->resArray));
271 }
272
273
274 /***************************************************************************************
275 *
276 * Migration of data
277 *
278 ***************************************************************************************/
279
280 dol_syslog("Process upgrade2 (step common to all entities)");
281
282 // Force to execute this at begin to avoid the new core code into Dolibarr to be broken.
283 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN birth date';
284 $db->query($sql, 1);
285 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemployment date';
286 $db->query($sql, 1);
287 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN dateemploymentend date';
288 $db->query($sql, 1);
289 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_range integer';
290 $db->query($sql, 1);
291 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user ADD COLUMN default_c_exp_tax_cat integer';
292 $db->query($sql, 1);
293 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN langs varchar(24)';
294 $db->query($sql, 1);
295 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fieldcomputed text';
296 $db->query($sql, 1);
297 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN fielddefault varchar(255)';
298 $db->query($sql, 1);
299 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX."extrafields ADD COLUMN enabled varchar(255) DEFAULT '1'";
300 $db->query($sql, 1);
301 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'extrafields ADD COLUMN help text';
302 $db->query($sql, 1);
303 $sql = 'ALTER TABLE '.MAIN_DB_PREFIX.'user_rights ADD COLUMN entity integer DEFAULT 1 NOT NULL';
304 $db->query($sql, 1);
305
306
307 $db->begin();
308
309 foreach ($listofentities as $entity) {
310 dol_syslog("Process upgrade2 (step a) for entity ".$entity);
311
312 // Set $conf context for entity
313 $conf->setEntityValues($db, $entity);
314
315 // Reset forced setup after the setValues
316 if (defined('SYSLOG_FILE')) {
317 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
318 }
319
320 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1; // Add also log into conf->logbuffer.
321
322 $versiontoarray = array();
323 $versionranarray = array();
324
325 dol_syslog("Process upgrade2 (step b) for entity ".$entity);
326
327 if (!$error) {
328 if (count($listofentities) > 1) {
329 print '<tr><td colspan="4">*** '.$langs->trans("Entity").' '.$entity.'</td></tr>'."\n";
330 }
331
332 // Current version is $conf->global->MAIN_VERSION_LAST_UPGRADE
333 // Version to install is DOL_VERSION
334 $dolibarrlastupgradeversionarray = preg_split('/[\.-]/', getDolGlobalString('MAIN_VERSION_LAST_UPGRADE', getDolGlobalString('MAIN_VERSION_LAST_INSTALL')));
335
336 // Every migration action must return a 4 column line with:
337 // - in the 1st column: the description of the action to do,
338 // - in the 4th column: the text 'OK' if done, or 'AlreadyDone' si nothing is done, or 'Error'
339
340 $versiontoarray = explode('.', $versionto);
341 $versionranarray = explode('.', DOL_VERSION);
342
343 $afterversionarray = explode('.', '2.0.0');
344 $beforeversionarray = explode('.', '2.7.9');
345 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
346 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
347
348 // Script pour V2 -> V2.1
349 migrate_paiements($db, $langs, $conf);
350
351 migrate_contracts_det($db, $langs, $conf);
352
353 migrate_contracts_date1($db, $langs, $conf);
354
355 migrate_contracts_date2($db, $langs, $conf);
356
357 migrate_contracts_date3($db, $langs, $conf);
358
359 migrate_contracts_open($db, $langs, $conf);
360
361 migrate_modeles($db, $langs, $conf);
362
363 migrate_price_propal($db, $langs, $conf);
364
365 migrate_price_commande($db, $langs, $conf);
366
368
369 migrate_price_contrat($db, $langs, $conf);
370
372
373
374 // Script pour V2.1 -> V2.2
376
378
379 migrate_links_transfert($db, $langs, $conf);
380
381
382 // Script pour V2.2 -> V2.4
384
385 migrate_commande_livraison($db, $langs, $conf);
386
387 migrate_detail_livraison($db, $langs, $conf);
388
389
390 // Script pour V2.5 -> V2.6
391 migrate_stocks($db, $langs, $conf);
392
393
394 // Script pour V2.6 -> V2.7
395 migrate_menus($db, $langs, $conf);
396
398
400
401 migrate_rename_directories($db, $langs, $conf, '/compta', '/banque');
402
403 migrate_rename_directories($db, $langs, $conf, '/societe', '/mycompany');
404 }
405
406 // Script for 2.8
407 $afterversionarray = explode('.', '2.7.9');
408 $beforeversionarray = explode('.', '2.8.9');
409 //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
410 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
411 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
412
413 migrate_price_facture($db, $langs, $conf); // Code of this function works for 2.8+ because need a field tva_tx
414
415 migrate_relationship_tables($db, $langs, $conf, 'co_exp', 'fk_commande', 'commande', 'fk_expedition', 'shipping');
416
417 migrate_relationship_tables($db, $langs, $conf, 'pr_exp', 'fk_propal', 'propal', 'fk_expedition', 'shipping');
418
419 migrate_relationship_tables($db, $langs, $conf, 'pr_liv', 'fk_propal', 'propal', 'fk_livraison', 'delivery');
420
421 migrate_relationship_tables($db, $langs, $conf, 'co_liv', 'fk_commande', 'commande', 'fk_livraison', 'delivery');
422
423 migrate_relationship_tables($db, $langs, $conf, 'co_pr', 'fk_propale', 'propal', 'fk_commande', 'commande');
424
425 migrate_relationship_tables($db, $langs, $conf, 'fa_pr', 'fk_propal', 'propal', 'fk_facture', 'facture');
426
427 migrate_relationship_tables($db, $langs, $conf, 'co_fa', 'fk_commande', 'commande', 'fk_facture', 'facture');
428
429 migrate_project_user_resp($db, $langs, $conf);
430
432 }
433
434 // Script for 2.9
435 $afterversionarray = explode('.', '2.8.9');
436 $beforeversionarray = explode('.', '2.9.9');
437 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
438 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
439
440 migrate_element_time($db, $langs, $conf);
441
443
444 migrate_shipping_delivery($db, $langs, $conf);
445
446 migrate_shipping_delivery2($db, $langs, $conf);
447 }
448
449 // Script for 3.0
450 $afterversionarray = explode('.', '2.9.9');
451 $beforeversionarray = explode('.', '3.0.9');
452 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
453 // No particular code
454 //}
455
456 // Script for 3.1
457 $afterversionarray = explode('.', '3.0.9');
458 $beforeversionarray = explode('.', '3.1.9');
459 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
460 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
461
462 migrate_rename_directories($db, $langs, $conf, '/rss', '/externalrss');
463
464 migrate_actioncomm_element($db, $langs, $conf);
465 }
466
467 // Script for 3.2
468 $afterversionarray = explode('.', '3.1.9');
469 $beforeversionarray = explode('.', '3.2.9');
470 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
471 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
472
473 migrate_price_contrat($db, $langs, $conf);
474
475 migrate_mode_reglement($db, $langs, $conf);
476
477 migrate_clean_association($db, $langs, $conf);
478 }
479
480 // Script for 3.3
481 $afterversionarray = explode('.', '3.2.9');
482 $beforeversionarray = explode('.', '3.3.9');
483 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
484 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
485
487 }
488
489 // Script for 3.4
490 // No specific scripts
491
492 // Tasks to do always and only into last targeted version
493 $afterversionarray = explode('.', '3.6.9'); // target is after this
494 $beforeversionarray = explode('.', '3.7.9'); // target is before this
495 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
496 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
497
498 migrate_event_assignement($db, $langs, $conf);
499 }
500
501 // Scripts for 3.9
502 $afterversionarray = explode('.', '3.7.9');
503 $beforeversionarray = explode('.', '3.8.9');
504 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
505 // No particular code
506 //}
507
508 // Scripts for 4.0
509 $afterversionarray = explode('.', '3.9.9');
510 $beforeversionarray = explode('.', '4.0.9');
511 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
512 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
513
514 migrate_rename_directories($db, $langs, $conf, '/fckeditor', '/medias');
515 }
516
517 // Scripts for 5.0
518 $afterversionarray = explode('.', '4.0.9');
519 $beforeversionarray = explode('.', '5.0.9');
520 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
521 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
522
523 // Migrate to add entity value into llx_societe_remise
524 migrate_remise_entity($db, $langs, $conf);
525
526 // Migrate to add entity value into llx_societe_remise_except
528 }
529
530 // Scripts for 6.0
531 $afterversionarray = explode('.', '5.0.9');
532 $beforeversionarray = explode('.', '6.0.9');
533 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
534 if (isModEnabled('multicompany')) {
535 global $multicompany_transverse_mode;
536
537 // Only if the transverse mode is not used
538 if (empty($multicompany_transverse_mode)) {
539 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
540
541 // Migrate to add entity value into llx_user_rights
542 migrate_user_rights_entity($db, $langs, $conf);
543
544 // Migrate to add entity value into llx_usergroup_rights
546 }
547 }
548 }
549
550 // Scripts for 7.0
551 $afterversionarray = explode('.', '6.0.9');
552 $beforeversionarray = explode('.', '7.0.9');
553 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
554 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
555
556 // Migrate contact association
558
559 migrate_reset_blocked_log($db, $langs, $conf);
560 }
561
562 // Scripts for 8.0
563 $afterversionarray = explode('.', '7.0.9');
564 $beforeversionarray = explode('.', '8.0.9');
565 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
566 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
567
568 migrate_rename_directories($db, $langs, $conf, '/contracts', '/contract');
569 }
570
571 // Scripts for 9.0
572 $afterversionarray = explode('.', '8.0.9');
573 $beforeversionarray = explode('.', '9.0.9');
574 //if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
575 //migrate_user_photospath();
576 //}
577
578 // Scripts for 11.0
579 $afterversionarray = explode('.', '10.0.9');
580 $beforeversionarray = explode('.', '11.0.9');
581 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
582 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
583
588 }
589
590 // Scripts for 14.0
591 $afterversionarray = explode('.', '13.0.9');
592 $beforeversionarray = explode('.', '14.0.9');
593 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
594 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
595
598 }
599
600 // Scripts for 16.0
601 $afterversionarray = explode('.', '15.0.9');
602 $beforeversionarray = explode('.', '16.0.9');
603 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
604 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
605
608 }
609
610 // Scripts for 17.0
611 $afterversionarray = explode('.', '16.0.9');
612 $beforeversionarray = explode('.', '17.0.9');
613 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
614 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
615
617 }
618
619 // Scripts for 18.0
620 $afterversionarray = explode('.', '17.0.9');
621 $beforeversionarray = explode('.', '18.0.9');
622 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
623 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
624
626 }
627
628 // Scripts for 19.0
629 /*
630 $afterversionarray = explode('.', '18.0.9');
631 $beforeversionarray = explode('.', '19.0.9');
632 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
633 }
634 */
635
636 // Scripts for 20.0
637 $afterversionarray = explode('.', '19.0.9');
638 $beforeversionarray = explode('.', '20.0.9');
639 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
640 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
641
643 }
644
645 // Scripts for 21.0
646 $afterversionarray = explode('.', '20.0.9');
647 $beforeversionarray = explode('.', '21.0.9');
648
649
650 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
651 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
652
654 }
655
656 // Scripts for 22.0
657 $afterversionarray = explode('.', '21.0.9');
658 $beforeversionarray = explode('.', '22.0.9');
659 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
660 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
661
663 }
664
665 // Scripts for 23.0
666 $afterversionarray = explode('.', '22.0.9');
667 $beforeversionarray = explode('.', '23.0.9');
668 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
669 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
670
672
674
676 }
677
678 // Scripts for 23.0
679 $afterversionarray = explode('.', '23.0.9');
680 $beforeversionarray = explode('.', '24.0.9');
681 if (versioncompare($versiontoarray, $afterversionarray) >= 0 && versioncompare($versiontoarray, $beforeversionarray) <= 0) {
682 dol_syslog("Run migrate_... versionto is between ".json_encode($afterversionarray)." and ".json_encode($beforeversionarray));
683
684 migrate_rename_directories($db, $langs, $conf, '/banque', '/bank');
685
687 }
688 }
689
690 // Code executed only if migration is LAST ONE. Must always be done.
691 if (versioncompare($versiontoarray, $versionranarray) >= 0 || versioncompare($versiontoarray, $versionranarray) <= -3) {
692 dol_syslog("Run migrate_... if migration is LAST ONE");
693
694 // 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)
695 $listofmodule = array(
696 'MAIN_MODULE_ACCOUNTING' => 'newboxdefonly',
697 'MAIN_MODULE_AGENDA' => 'newboxdefonly',
698 'MAIN_MODULE_BOM' => 'menuonly',
699 'MAIN_MODULE_BANQUE' => 'menuonly',
700 'MAIN_MODULE_BARCODE' => 'newboxdefonly',
701 'MAIN_MODULE_CRON' => 'newboxdefonly',
702 'MAIN_MODULE_COMMANDE' => 'newboxdefonly',
703 'MAIN_MODULE_BLOCKEDLOG' => 'noboxes',
704 'MAIN_MODULE_DON' => 'newboxdefonly',
705 'MAIN_MODULE_ECM' => 'newboxdefonly',
706 'MAIN_MODULE_EVENTORGANIZATION' => 'newboxdefonly',
707 'MAIN_MODULE_EXPENSEREPORT' => 'newboxdefonly',
708 'MAIN_MODULE_FACTURE' => 'newboxdefonly',
709 'MAIN_MODULE_FOURNISSEUR' => 'newboxdefonly',
710 'MAIN_MODULE_FICHEINTER' => 'newboxdefonly',
711 'MAIN_MODULE_HOLIDAY' => 'newboxdefonly',
712 'MAIN_MODULE_LOAN' => 'newboxdefonly',
713 'MAIN_MODULE_MARGIN' => 'menuonly',
714 'MAIN_MODULE_MRP' => 'menuonly',
715 'MAIN_MODULE_OPENSURVEY' => 'newboxdefonly',
716 'MAIN_MODULE_PARTNERSHIP' => 'newboxdefonly',
717 'MAIN_MODULE_PRINTING' => 'newboxdefonly',
718 'MAIN_MODULE_PRODUIT' => 'newboxdefonly',
719 'MAIN_MODULE_RECRUITMENT' => 'menuonly',
720 'MAIN_MODULE_RESOURCE' => 'noboxes',
721 'MAIN_MODULE_SALARIES' => 'newboxdefonly',
722 'MAIN_MODULE_SERVICE' => 'newboxdefonly',
723 //'MAIN_MODULE_SYSLOG' => 'newboxdefonly', This enabled the module syslog, but we don't want to do that.
724 'MAIN_MODULE_SOCIETE' => 'newboxdefonly',
725 'MAIN_MODULE_STRIPE' => 'menuonly',
726 'MAIN_MODULE_TICKET' => 'newboxdefonly',
727 'MAIN_MODULE_TAKEPOS' => 'newboxdefonly',
728 'MAIN_MODULE_USER' => 'newboxdefonly', //This one must be always done and only into last targeted version)
729 'MAIN_MODULE_VARIANTS' => 'newboxdefonly',
730 'MAIN_MODULE_WEBSITE' => 'newboxdefonly',
731 );
732
733 $result = migrate_reload_modules($db, $langs, $conf, $listofmodule);
734 if ($result < 0) {
735 $error++;
736 }
737
738 // Grant the supplier prices permissions added in 23.0 to users/groups that already have
739 // the matching product/service rights (ids resolved by name from the rights_def reloaded
740 // just above), so nobody loses access to supplier prices on upgrade. Idempotent.
741 $result = migrate_supplier_prices_permissions($db, $langs, $conf);
742 if ($result < 0) {
743 $error++;
744 }
745
746 // Reload menus (this must be always done, and only into last targeted version)
747 // This reload the auguria menu.To reload a dynamic menu defined into module descriptor, see previours step
748 $result = migrate_reload_menu($db, $langs, $conf);
749 if ($result < 0) {
750 $error++;
751 }
752 }
753
754 // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...'
755 // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line.
756 if (!$error && $enablemodules) {
757 // Reload modules (this must be always done and only into last targeted version)
758 $listofmodules = array();
759 $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules);
760 $tmplistofmodules = explode(',', $enablemodules);
761 foreach ($tmplistofmodules as $value) {
762 $listofmodules[$value] = 'forceactivate';
763 }
764
765 $resultreloadmodules = migrate_reload_modules($db, $langs, $conf, $listofmodules, 1);
766 if ($resultreloadmodules < 0) {
767 $error++;
768 }
769 }
770
771
772 // Can call a dedicated external upgrade process with hook doUpgradeAfterDB()
773 if (!$error) {
774 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
775 $object = new stdClass();
776 $action = "upgrade";
777 $reshook = $hookmanager->executeHooks('doUpgradeAfterDB', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
778 if ($hookmanager->resNbOfHooks > 0) {
779 if ($reshook < 0) {
780 print '<tr><td colspan="4">';
781 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
782 print $hookmanager->error;
783 print "<!-- (".$reshook.") -->";
784 print '</td></tr>';
785 } else {
786 print '<tr class="trforrunsql"><td colspan="4">';
787 print '<b>'.$langs->trans('UpgradeExternalModule').' (DB)</b>: <span class="ok">OK</span>';
788 print "<!-- (".$reshook.") -->";
789 print '</td></tr>';
790 }
791 } else {
792 //if (!empty($conf->modules))
793 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
794 print '<tr class="trforrunsql"><td colspan="4">';
795 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterDB");
796 print '</td></tr>';
797 }
798 }
799 }
800 }
801
802 print '</table>';
803
804 if (!$error) {
805 // Set constant to ask to remake a new ping to inform about upgrade (if ping was already done and OK)
806 $sql = 'UPDATE '.MAIN_DB_PREFIX."const SET VALUE = 'torefresh' WHERE name = 'MAIN_FIRST_PING_OK_ID'"; // This should be useless now because constant is uniqueid+' v'+version
807 $db->query($sql, 1);
808 }
809
810 // We always commit.
811 // Process is designed so we can run it several times whatever is situation.
812 $db->commit();
813
814
815 /***************************************************************************************
816 *
817 * Migration of files
818 *
819 ***************************************************************************************/
820
821 foreach ($listofentities as $entity) {
822 // Set $conf context for entity
823 $conf->setEntityValues($db, $entity);
824 // Reset forced setup after the setValues
825 if (defined('SYSLOG_FILE')) {
826 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
827 }
828 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
829
830
831 // Copy directory medias
832 $srcroot = DOL_DOCUMENT_ROOT.'/install/medias';
833 $destroot = DOL_DATA_ROOT.'/medias';
834 dolCopyDir($srcroot, $destroot, '0', 0);
835
836
837 // Actions for all versions (no database change but delete some files and directories)
838 migrate_delete_old_files($db, $langs, $conf);
839 migrate_delete_old_dir($db, $langs, $conf);
840 // Actions for all versions (no database change but create some directories)
841 dol_mkdir(DOL_DATA_ROOT.'/bank');
842 // Actions for all versions (no database change but rename some directories)
843 migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits');
844
845
846 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
847 $object = new stdClass();
848 $action = "upgrade";
849 $reshook = $hookmanager->executeHooks('doUpgradeAfterFiles', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
850 if ($hookmanager->resNbOfHooks > 0) {
851 if ($reshook < 0) {
852 print '<tr><td colspan="4">';
853 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
854 print $hookmanager->error;
855 print "<!-- (".$reshook.") -->";
856 print '</td></tr>';
857 } else {
858 print '<tr class="trforrunsql"><td colspan="4">';
859 print '<b>'.$langs->trans('UpgradeExternalModule').' (Files)</b>: <span class="ok">OK</span>';
860 print "<!-- (".$reshook.") -->";
861 print '</td></tr>';
862 }
863 } else {
864 //if (!empty($conf->modules))
865 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
866 print '<tr class="trforrunsql"><td colspan="4">';
867 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterFiles");
868 print '</td></tr>';
869 }
870 }
871 }
872
873 $db->close();
874
875 $silent = 0;
876 if (!$silent) {
877 print '<table width="100%">';
878 print '<tr><td style="width: 30%">'.$langs->trans("MigrationFinished").'</td>';
879 print '<td class="right">';
880 if ($error == 0) {
881 //print '<span class="ok">'.$langs->trans("OK").'</span> - '; // $error = 0 does not mean there is no error (error are not always trapped)
882 } else {
883 print '<span class="error">'.$langs->trans("Error").'</span> - ';
884 }
885
886 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
887 print '<script type="text/javascript">
888 jQuery(document).ready(function() {
889 function init_trrunsql()
890 {
891 console.log("toggle .trforrunsql");
892 jQuery(".trforrunsql").toggle();
893 }
894 init_trrunsql();
895 jQuery(".trforrunsqlshowhide").click(function() {
896 init_trrunsql();
897 });
898 });
899 </script>';
900 print '<a class="reposition trforrunsqlshowhide" href="#">'.$langs->trans("ShowHideDetails").'</a>';
901 //}
902
903 print '</td></tr>'."\n";
904 print '</table>';
905 }
906
907 //print '<div><br>'.$langs->trans("MigrationFinished").'</div>';
908} else {
909 print '<div class="error">'.$langs->trans('ErrorWrongParameters').'</div>';
910 $error++;
911}
912
913$ret = 0;
914if ($error && isset($argv[1])) {
915 $ret = 1;
916}
917dolibarr_install_syslog("Exit ".$ret);
918
919dolibarr_install_syslog("--- upgrade2: end");
920pFooter($error ? 2 : 0, $setuplang);
921
922if ($db !== null && $db->connected) {
923 $db->close();
924}
925
926// Return code if ran from command line
927if ($ret) {
928 exit($ret);
929}
930
931
932
941function migrate_paiements($db, $langs, $conf)
942{
943 print '<tr><td colspan="4">';
944
945 print '<br>';
946 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
947
948 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
949 $obj = $db->fetch_object($result);
950 if ($obj) {
951 $sql = "SELECT p.rowid, p.fk_facture, p.amount";
952 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
953 $sql .= " WHERE p.fk_facture > 0";
954
955 $resql = $db->query($sql);
956 $row = array();
957 $num = 0;
958
959 dolibarr_install_syslog("upgrade2::migrate_paiements");
960 if ($resql) {
961 $i = 0;
962 $num = $db->num_rows($resql);
963
964 while ($i < $num) {
965 $obj = $db->fetch_object($resql);
966 $row[$i][0] = $obj->rowid;
967 $row[$i][1] = $obj->fk_facture;
968 $row[$i][2] = $obj->amount;
969 $i++;
970 }
971 } else {
973 }
974
975 if ($num) {
976 print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."<br>\n";
977 $res = 0;
978 if ($db->begin()) {
979 $num = count($row);
980 for ($i = 0; $i < $num; $i++) {
981 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
982 $sql .= " VALUES (".((int) $row[$i][1]).",".((int) $row[$i][0]).",".((float) $row[$i][2]).")";
983
984 $res += $db->query($sql);
985
986 $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
987
988 $res += $db->query($sql);
989
990 print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."<br>\n";
991 }
992 }
993
994 if (is_array($row) && $res == (2 * count($row))) {
995 $db->commit();
996 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
997 } else {
998 $db->rollback();
999 print $langs->trans('MigrationUpdateFailed').'<br>';
1000 }
1001 } else {
1002 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
1003 }
1004 } else {
1005 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
1006 }
1007
1008 print '</td></tr>';
1009}
1010
1022{
1023 print '<tr><td colspan="4">';
1024
1025 print '<br>';
1026 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1027
1028 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1029 $obj = $db->fetch_object($result);
1030 if ($obj) {
1031 // All answer of this requests should have a parent into llx_paiement_facture
1032 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1033 $sql .= " bu2.url_id as socid";
1034 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1035 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1036 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
1037 $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
1038 $sql .= " AND b.rappro = 1";
1039 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1040
1041 $resql = $db->query($sql);
1042
1043 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1");
1044 $row = array();
1045 if ($resql) {
1046 $i = $j = 0;
1047 $num = $db->num_rows($resql);
1048
1049 while ($i < $num) {
1050 $obj = $db->fetch_object($resql);
1051 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1052 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1053 $row[$j]['pamount'] = $obj->pamount;
1054 $row[$j]['fk_bank'] = $obj->fk_bank;
1055 $row[$j]['bamount'] = $obj->bamount;
1056 $row[$j]['socid'] = $obj->socid;
1057 $row[$j]['datec'] = $obj->datec;
1058 $j++;
1059 }
1060 $i++;
1061 }
1062 } else {
1064 }
1065
1066 if (count($row)) {
1067 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."<br>\n";
1068 $db->begin();
1069
1070 $res = 0;
1071 $num = count($row);
1072 for ($i = 0; $i < $num; $i++) {
1073 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1074 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>';
1075 }
1076
1077 // Look for invoices without payment relations with the same amount and same comppany
1078 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1079 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1080 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1081 $sql .= " AND pf.fk_facture IS NULL";
1082 $sql .= " ORDER BY f.fk_statut";
1083 //print $sql.'<br>';
1084 $resql = $db->query($sql);
1085 if ($resql) {
1086 $num = $db->num_rows($resql);
1087 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1088 if ($num >= 1) {
1089 $obj = $db->fetch_object($resql);
1090 $facid = $obj->rowid;
1091
1092 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1093 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1094
1095 $res += $db->query($sql);
1096
1097 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1098 }
1099 } else {
1100 print 'ERROR';
1101 }
1102 }
1103
1104 if ($res > 0) {
1105 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1106 } else {
1107 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1108 }
1109
1110 $db->commit();
1111 } else {
1112 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1113 }
1114 } else {
1115 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1116 }
1117
1118 print '</td></tr>';
1119}
1120
1132{
1133 print '<tr><td colspan="4">';
1134
1135 print '<br>';
1136 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1137
1138 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1139 $obj = $db->fetch_object($result);
1140 if ($obj) {
1141 // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
1142 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1143 $sql .= " bu2.url_id as socid";
1144 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1145 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1146 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
1147 $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
1148 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1149
1150 $resql = $db->query($sql);
1151
1152 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2");
1153 $row = array();
1154 if ($resql) {
1155 $i = $j = 0;
1156 $num = $db->num_rows($resql);
1157
1158 while ($i < $num) {
1159 $obj = $db->fetch_object($resql);
1160 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1161 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1162 $row[$j]['pamount'] = $obj->pamount;
1163 $row[$j]['fk_bank'] = $obj->fk_bank;
1164 $row[$j]['bamount'] = $obj->bamount;
1165 $row[$j]['socid'] = $obj->socid;
1166 $row[$j]['datec'] = $obj->datec;
1167 $j++;
1168 }
1169 $i++;
1170 }
1171 } else {
1173 }
1174
1175 $nberr = 0;
1176
1177 $num = count($row);
1178 if ($num) {
1179 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."<br>\n";
1180 $db->begin();
1181
1182 $res = 0;
1183 for ($i = 0; $i < $num; $i++) {
1184 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1185 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>';
1186 }
1187
1188 // Look for invoices without payment relations with the same amount and same comppany
1189 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1190 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1191 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1192 $sql .= " AND pf.fk_facture IS NULL";
1193 $sql .= " ORDER BY f.fk_statut";
1194 //print $sql.'<br>';
1195 $resql = $db->query($sql);
1196 if ($resql) {
1197 $num = $db->num_rows($resql);
1198 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1199 if ($num >= 1) {
1200 $obj = $db->fetch_object($resql);
1201 $facid = $obj->rowid;
1202
1203 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1204 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1205
1206 $res += $db->query($sql);
1207
1208 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1209 }
1210 } else {
1211 print 'ERROR';
1212 $nberr++;
1213 }
1214 }
1215
1216 if ($res > 0) {
1217 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1218 } else {
1219 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1220 }
1221
1222 $db->commit();
1223 } else {
1224 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1225 }
1226
1227 // Delete obsolete fields fk_facture
1228 $db->begin();
1229
1230 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture";
1231 $db->query($sql);
1232
1233 if (!$nberr) {
1234 $db->commit();
1235 } else {
1236 print 'ERROR';
1237 $db->rollback();
1238 }
1239 } else {
1240 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1241 }
1242
1243 print '</td></tr>';
1244}
1245
1246
1255function migrate_contracts_det($db, $langs, $conf)
1256{
1257 print '<tr><td colspan="4">';
1258
1259 $nberr = 0;
1260
1261 print '<br>';
1262 print '<b>'.$langs->trans('MigrationContractsUpdate')."</b><br>\n";
1263
1264 $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1265 $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1266 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
1267 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p";
1268 $sql .= " ON c.fk_product = p.rowid";
1269 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd";
1270 $sql .= " ON c.rowid=cd.fk_contrat";
1271 $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1272 $resql = $db->query($sql);
1273
1274 dolibarr_install_syslog("upgrade2::migrate_contracts_det");
1275 if ($resql) {
1276 $i = 0;
1277 $row = array();
1278 $num = $db->num_rows($resql);
1279
1280 if ($num) {
1281 print $langs->trans('MigrationContractsNumberToUpdate', $num)."<br>\n";
1282 $db->begin();
1283
1284 while ($i < $num) {
1285 $obj = $db->fetch_object($resql);
1286
1287 $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet (";
1288 $sql .= "fk_contrat, fk_product, statut, label, description,";
1289 $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1290 $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)";
1291 $sql .= " VALUES (";
1292 $sql .= ((int) $obj->cref).", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).", ";
1293 $sql .= "0, ";
1294 $sql .= "'".$db->escape($obj->label)."', null, ";
1295 $sql .= ($obj->date_contrat ? "'".$db->idate($db->jdate($obj->date_contrat))."'" : "null").", ";
1296 $sql .= "null, ";
1297 $sql .= "null, ";
1298 $sql .= ((float) $obj->tva_tx).", 1, ";
1299 $sql .= ((float) $obj->price).", ".((float) $obj->price).", ".((int) $obj->fk_user_author).",";
1300 $sql .= "null";
1301 $sql .= ")";
1302
1303 if ($db->query($sql)) {
1304 print $langs->trans('MigrationContractsLineCreation', $obj->cref)."<br>\n";
1305 } else {
1307 $nberr++;
1308 }
1309
1310 $i++;
1311 }
1312
1313 if (!$nberr) {
1314 // $db->rollback();
1315 $db->commit();
1316 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1317 } else {
1318 $db->rollback();
1319 print $langs->trans('MigrationUpdateFailed').'<br>';
1320 }
1321 } else {
1322 print $langs->trans('MigrationContractsNothingToUpdate')."<br>\n";
1323 }
1324 } else {
1325 print $langs->trans('MigrationContractsFieldDontExist')."<br>\n";
1326 // dol_print_error($db);
1327 }
1328
1329 print '</td></tr>';
1330}
1331
1340function migrate_links_transfert($db, $langs, $conf)
1341{
1342 print '<tr><td colspan="4">';
1343
1344 $nberr = 0;
1345
1346 print '<br>';
1347 print '<b>'.$langs->trans('MigrationBankTransfertsUpdate')."</b><br>\n";
1348
1349 $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1350 $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba";
1351 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid";
1352 $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1353 $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec";
1354 $sql .= " AND bu.fk_bank IS NULL";
1355 $resql = $db->query($sql);
1356
1357 dolibarr_install_syslog("upgrade2::migrate_links_transfert");
1358 if ($resql) {
1359 $i = 0;
1360 $row = array();
1361 $num = $db->num_rows($resql);
1362
1363 if ($num) {
1364 print $langs->trans('MigrationBankTransfertsToUpdate', $num)."<br>\n";
1365 $db->begin();
1366
1367 while ($i < $num) {
1368 $obj = $db->fetch_object($resql);
1369
1370 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
1371 $sql .= "fk_bank, url_id, url, label, type";
1372 $sql .= ")";
1373 $sql .= " VALUES (";
1374 $sql .= ((int) $obj->barowid).",".((int) $obj->bbrowid).", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1375 $sql .= ")";
1376
1377 //print $sql.'<br>';
1378 dolibarr_install_syslog("migrate_links_transfert");
1379
1380 if (!$db->query($sql)) {
1382 $nberr++;
1383 }
1384
1385 $i++;
1386 }
1387
1388 if (!$nberr) {
1389 // $db->rollback();
1390 $db->commit();
1391 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1392 } else {
1393 $db->rollback();
1394 print $langs->trans('MigrationUpdateFailed').'<br>';
1395 }
1396 } else {
1397 print $langs->trans('MigrationBankTransfertsNothingToUpdate')."<br>\n";
1398 }
1399 } else {
1401 }
1402
1403 print '</td></tr>';
1404}
1405
1414function migrate_contracts_date1($db, $langs, $conf)
1415{
1416 print '<tr><td colspan="4">';
1417
1418 print '<br>';
1419 print '<b>'.$langs->trans('MigrationContractsEmptyDatesUpdate')."</b><br>\n";
1420
1421 $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null";
1422 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1423 $resql = $db->query($sql);
1424 if (!$resql) {
1426 }
1427 if ($db->affected_rows($resql) > 0) {
1428 print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."<br>\n";
1429 } else {
1430 print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."<br>\n";
1431 }
1432
1433 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null";
1434 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1435 $resql = $db->query($sql);
1436 if (!$resql) {
1438 }
1439 if ($db->affected_rows($resql) > 0) {
1440 print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."<br>\n";
1441 } else {
1442 print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."<br>\n";
1443 }
1444
1445 print '</td></tr>';
1446}
1447
1456function migrate_contracts_date2($db, $langs, $conf)
1457{
1458 print '<tr><td colspan="4">';
1459
1460 $nberr = 0;
1461
1462 print '<br>';
1463 print '<b>'.$langs->trans('MigrationContractsInvalidDatesUpdate')."</b><br>\n";
1464
1465 $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1466 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
1467 $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
1468 $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1469 $sql .= " GROUP BY c.rowid, c.date_contrat";
1470 $resql = $db->query($sql);
1471
1472 dolibarr_install_syslog("upgrade2::migrate_contracts_date2");
1473 if ($resql) {
1474 $i = 0;
1475 $row = array();
1476 $num = $db->num_rows($resql);
1477
1478 if ($num) {
1479 $nbcontratsmodifie = 0;
1480 $db->begin();
1481
1482 while ($i < $num) {
1483 $obj = $db->fetch_object($resql);
1484 if ($obj->date_contrat > $obj->datemin) {
1485 $datemin = $db->jdate($obj->datemin);
1486
1487 print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."<br>\n";
1488 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1489 $sql .= " SET date_contrat='".$db->idate($datemin)."'";
1490 $sql .= " WHERE rowid = ".((int) $obj->cref);
1491 $resql2 = $db->query($sql);
1492 if (!$resql2) {
1494 }
1495
1496 $nbcontratsmodifie++;
1497 }
1498 $i++;
1499 }
1500
1501 $db->commit();
1502
1503 if ($nbcontratsmodifie) {
1504 print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."<br>\n";
1505 } else {
1506 print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."<br>\n";
1507 }
1508 }
1509 } else {
1511 }
1512
1513 print '</td></tr>';
1514}
1515
1524function migrate_contracts_date3($db, $langs, $conf)
1525{
1526 print '<tr><td colspan="4">';
1527
1528 print '<br>';
1529 print '<b>'.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."</b><br>\n";
1530
1531 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat";
1532 dolibarr_install_syslog("upgrade2::migrate_contracts_date3");
1533 $resql = $db->query($sql);
1534 if (!$resql) {
1536 }
1537 if ($db->affected_rows($resql) > 0) {
1538 print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."<br>\n";
1539 } else {
1540 print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."<br>\n";
1541 }
1542
1543 print '</td></tr>';
1544}
1545
1554function migrate_contracts_open($db, $langs, $conf)
1555{
1556 print '<tr><td colspan="4">';
1557
1558 print '<br>';
1559 print '<b>'.$langs->trans('MigrationReopeningContracts')."</b><br>\n";
1560
1561 $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd";
1562 $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1563 dolibarr_install_syslog("upgrade2::migrate_contracts_open");
1564 $resql = $db->query($sql);
1565 if (!$resql) {
1567 }
1568 if ($db->affected_rows($resql) > 0) {
1569 $i = 0;
1570 $row = array();
1571 $num = $db->num_rows($resql);
1572
1573 if ($num) {
1574 $nbcontratsmodifie = 0;
1575 $db->begin();
1576
1577 while ($i < $num) {
1578 $obj = $db->fetch_object($resql);
1579
1580 print $langs->trans('MigrationReopenThisContract', $obj->cref)."<br>\n";
1581 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1582 $sql .= " SET statut = 1";
1583 $sql .= " WHERE rowid = ".((int) $obj->cref);
1584 $resql2 = $db->query($sql);
1585 if (!$resql2) {
1587 }
1588
1589 $nbcontratsmodifie++;
1590
1591 $i++;
1592 }
1593
1594 $db->commit();
1595
1596 if ($nbcontratsmodifie) {
1597 print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."<br>\n";
1598 } else {
1599 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1600 }
1601 }
1602 } else {
1603 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1604 }
1605
1606 print '</td></tr>';
1607}
1608
1618{
1619 global $bc;
1620
1621 print '<tr><td colspan="4">';
1622 print '<br>';
1623 print '<b>'.$langs->trans('SuppliersInvoices')."</b><br>\n";
1624 print '</td></tr>';
1625
1626 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn");
1627 $obj = $db->fetch_object($result);
1628 if ($obj) {
1629 $error = 0;
1630 $nb = 0;
1631
1632 $select_sql = 'SELECT rowid, fk_facture_fourn, amount';
1633 $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn';
1634 $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL';
1635
1636 dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn");
1637 $select_resql = $db->query($select_sql);
1638 if ($select_resql) {
1639 $select_num = $db->num_rows($select_resql);
1640 $i = 0;
1641
1642 // For every supplier payment, add a line to paiementfourn_facturefourn
1643 while (($i < $select_num) && (!$error)) {
1644 $select_obj = $db->fetch_object($select_resql);
1645
1646 // Verify if the row is already in the new table - avoid adding duplicates
1647 $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn';
1648 $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
1649 $check_sql .= ' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1650 $check_resql = $db->query($check_sql);
1651 if ($check_resql) {
1652 $check_num = $db->num_rows($check_resql);
1653 if ($check_num == 0) {
1654 $db->begin();
1655
1656 if ($nb == 0) {
1657 print '<tr><td colspan="4" class="nowrap"><b>'.$langs->trans('SuppliersInvoices').'</b></td></tr>';
1658 print '<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans('Amount').'</td><td>&nbsp;</td></tr>';
1659 }
1660
1661 print '<tr class="oddeven">';
1662 print '<td>'.$select_obj->rowid.'</td><td>'.$select_obj->fk_facture_fourn.'</td><td>'.$select_obj->amount.'</td>';
1663
1664 $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET ';
1665 $insert_sql .= ' fk_paiementfourn = \''.((int) $select_obj->rowid).'\',';
1666 $insert_sql .= ' fk_facturefourn = \''.((int) $select_obj->fk_facture_fourn).'\',';
1667 $insert_sql .= ' amount = \''.((float) $select_obj->amount).'\'';
1668 $insert_resql = $db->query($insert_sql);
1669
1670 if ($insert_resql) {
1671 $nb++;
1672 print '<td><span class="ok">'.$langs->trans("OK").'</span></td>';
1673 } else {
1674 print '<td><span class="error">Error on insert</span></td>';
1675 $error++;
1676 }
1677 print '</tr>';
1678 }
1679 } else {
1680 $error++;
1681 }
1682 $i++;
1683 }
1684 } else {
1685 $error++;
1686 }
1687
1688 if (!$error) {
1689 if (!$nb) {
1690 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1691 }
1692 $db->commit();
1693
1694 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn";
1695 $db->query($sql);
1696 } else {
1697 print '<tr><td>'.$langs->trans("Error").'</td></tr>';
1698 $db->rollback();
1699 }
1700 } else {
1701 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1702 }
1703}
1704
1713function migrate_price_facture($db, $langs, $conf)
1714{
1715 $err = 0;
1716
1717 $tmpmysoc = new Societe($db);
1718 $tmpmysoc->setMysoc($conf);
1719
1720 $db->begin();
1721
1722 print '<tr><td colspan="4">';
1723
1724 print '<br>';
1725 print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n";
1726
1727 // List of invoice lines not up to date
1728 $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1729 $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1730 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
1731 $sql .= " WHERE fd.fk_facture = f.rowid";
1732 $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1733 //print $sql;
1734
1735 dolibarr_install_syslog("upgrade2::migrate_price_facture");
1736 $resql = $db->query($sql);
1737 if ($resql) {
1738 $num = $db->num_rows($resql);
1739 $i = 0;
1740 if ($num) {
1741 while ($i < $num) {
1742 $obj = $db->fetch_object($resql);
1743
1744 $rowid = $obj->rowid;
1745 $qty = $obj->qty;
1746 $pu = $obj->subprice;
1747 $vatrate = $obj->vatrate;
1748 $remise_percent = $obj->remise_percent;
1749 $remise_percent_global = $obj->remise_percent_global;
1750 $total_ttc_f = $obj->total_ttc_f;
1751 $info_bits = $obj->info_bits;
1752
1753 // On met a jour les 3 nouveaux champs
1754 $facligne = new FactureLigne($db);
1755 $facligne->fetch($rowid);
1756
1757 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1758 $total_ht = $result[0];
1759 $total_tva = $result[1];
1760 $total_ttc = $result[2];
1761
1762 $facligne->total_ht = (float) $total_ht;
1763 $facligne->total_tva = (float) $total_tva;
1764 $facligne->total_ttc = (float) $total_ttc;
1765
1766 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);
1767 print '. ';
1768 $facligne->update_total();
1769
1770
1771 /* On touche a facture mere uniquement si total_ttc = 0 */
1772 if (!$total_ttc_f) {
1773 $facture = new Facture($db);
1774 $facture->id = $obj->facid;
1775
1776 if ($facture->fetch($facture->id) >= 0) {
1777 if ($facture->update_price() > 0) {
1778 //print $facture->id;
1779 } else {
1780 print "Error id=".$facture->id;
1781 $err++;
1782 }
1783 } else {
1784 print "Error #3";
1785 $err++;
1786 }
1787 }
1788 print " ";
1789
1790 $i++;
1791 }
1792 } else {
1793 print $langs->trans("AlreadyDone");
1794 }
1795 $db->free($resql);
1796
1797 $db->commit();
1798 } else {
1799 print "Error #1 ".$db->error();
1800 $err++;
1801
1802 $db->rollback();
1803 }
1804
1805 print '<br>';
1806
1807 print '</td></tr>';
1808}
1809
1818function migrate_price_propal($db, $langs, $conf)
1819{
1820 $tmpmysoc = new Societe($db);
1821 $tmpmysoc->setMysoc($conf);
1822
1823 $db->begin();
1824
1825 print '<tr><td colspan="4">';
1826
1827 print '<br>';
1828 print '<b>'.$langs->trans('MigrationProposal')."</b><br>\n";
1829
1830 // List of proposal lines not up to date
1831 $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1832 $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global";
1833 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p";
1834 $sql .= " WHERE pd.fk_propal = p.rowid";
1835 $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1836
1837 dolibarr_install_syslog("upgrade2::migrate_price_propal");
1838 $resql = $db->query($sql);
1839 if ($resql) {
1840 $num = $db->num_rows($resql);
1841 $i = 0;
1842 if ($num) {
1843 while ($i < $num) {
1844 $obj = $db->fetch_object($resql);
1845
1846 $rowid = $obj->rowid;
1847 $qty = $obj->qty;
1848 $pu = $obj->subprice;
1849 $vatrate = $obj->vatrate;
1850 $remise_percent = $obj->remise_percent;
1851 $remise_percent_global = $obj->remise_percent_global;
1852 $info_bits = $obj->info_bits;
1853
1854 // Update the 3 new fields
1855 $propalligne = new PropaleLigne($db);
1856 $propalligne->fetch($rowid);
1857
1858 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1859 $total_ht = $result[0];
1860 $total_tva = $result[1];
1861 $total_ttc = $result[2];
1862
1863 $propalligne->total_ht = (float) $total_ht;
1864 $propalligne->total_tva = (float) $total_tva;
1865 $propalligne->total_ttc = (float) $total_ttc;
1866
1867 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);
1868 print '. ';
1869 $propalligne->update_total();
1870
1871 $i++;
1872 }
1873 } else {
1874 print $langs->trans("AlreadyDone");
1875 }
1876
1877 $db->free($resql);
1878
1879 $db->commit();
1880 } else {
1881 print "Error #1 ".$db->error();
1882
1883 $db->rollback();
1884 }
1885
1886 print '<br>';
1887
1888 print '</td></tr>';
1889}
1890
1899function migrate_price_contrat($db, $langs, $conf)
1900{
1901 $db->begin();
1902
1903 $tmpmysoc = new Societe($db);
1904 $tmpmysoc->setMysoc($conf);
1905 if (empty($tmpmysoc->country_id)) {
1906 $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
1907 }
1908
1909 print '<tr><td colspan="4">';
1910
1911 print '<br>';
1912 print '<b>'.$langs->trans('MigrationContract')."</b><br>\n";
1913
1914 // List of contract lines not up to date
1915 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1916 $sql .= " c.rowid as contratid";
1917 $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
1918 $sql .= " WHERE cd.fk_contrat = c.rowid";
1919 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1920
1921 dolibarr_install_syslog("upgrade2::migrate_price_contrat");
1922 $resql = $db->query($sql);
1923 if ($resql) {
1924 $num = $db->num_rows($resql);
1925 $i = 0;
1926 if ($num) {
1927 while ($i < $num) {
1928 $obj = $db->fetch_object($resql);
1929
1930 $rowid = $obj->rowid;
1931 $qty = $obj->qty;
1932 $pu = $obj->subprice;
1933 $vatrate = $obj->vatrate;
1934 $remise_percent = $obj->remise_percent;
1935 $info_bits = $obj->info_bits;
1936
1937 // On met a jour les 3 nouveaux champs
1938 $contratligne = new ContratLigne($db);
1939 //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis
1940 $contratligne->fetch($rowid);
1941
1942 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1943 $total_ht = $result[0];
1944 $total_tva = $result[1];
1945 $total_ttc = $result[2];
1946
1947 $contratligne->total_ht = (float) $total_ht;
1948 $contratligne->total_tva = (float) $total_tva;
1949 $contratligne->total_ttc = (float) $total_ttc;
1950
1951 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);
1952 print '. ';
1953 $contratligne->update_total();
1954
1955 $i++;
1956 }
1957 } else {
1958 print $langs->trans("AlreadyDone");
1959 }
1960
1961 $db->free($resql);
1962
1963 $db->commit();
1964 } else {
1965 print "Error #1 ".$db->error();
1966
1967 $db->rollback();
1968 }
1969
1970 print '<br>';
1971
1972 print '</td></tr>';
1973}
1974
1983function migrate_price_commande($db, $langs, $conf)
1984{
1985 $db->begin();
1986
1987 $tmpmysoc = new Societe($db);
1988 $tmpmysoc->setMysoc($conf);
1989
1990 print '<tr><td colspan="4">';
1991
1992 print '<br>';
1993 print '<b>'.$langs->trans('MigrationOrder')."</b><br>\n";
1994
1995 // List of sales orders lines not up to date
1996 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1997 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
1998 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c";
1999 $sql .= " WHERE cd.fk_commande = c.rowid";
2000 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2001
2002 dolibarr_install_syslog("upgrade2::migrate_price_commande");
2003 $resql = $db->query($sql);
2004 if ($resql) {
2005 $num = $db->num_rows($resql);
2006 $i = 0;
2007 if ($num) {
2008 while ($i < $num) {
2009 $obj = $db->fetch_object($resql);
2010
2011 $rowid = $obj->rowid;
2012 $qty = $obj->qty;
2013 $pu = $obj->subprice;
2014 $vatrate = $obj->vatrate;
2015 $remise_percent = $obj->remise_percent;
2016 $remise_percent_global = $obj->remise_percent_global;
2017 $info_bits = $obj->info_bits;
2018
2019 // On met a jour les 3 nouveaux champs
2020 $commandeligne = new OrderLine($db);
2021 $commandeligne->fetch($rowid);
2022
2023 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
2024 $total_ht = $result[0];
2025 $total_tva = $result[1];
2026 $total_ttc = $result[2];
2027
2028 $commandeligne->total_ht = (float) $total_ht;
2029 $commandeligne->total_tva = (float) $total_tva;
2030 $commandeligne->total_ttc = (float) $total_ttc;
2031
2032 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);
2033 print '. ';
2034 $commandeligne->update_total();
2035
2036 $i++;
2037 }
2038 } else {
2039 print $langs->trans("AlreadyDone");
2040 }
2041
2042 $db->free($resql);
2043
2044 /*
2045 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
2046 $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
2047 $resql=$db->query($sql);
2048 if (! $resql)
2049 {
2050 dol_print_error($db);
2051 }
2052 */
2053
2054 $db->commit();
2055 } else {
2056 print "Error #1 ".$db->error();
2057
2058 $db->rollback();
2059 }
2060
2061 print '<br>';
2062
2063 print '</td></tr>';
2064}
2065
2075{
2076 global $mysoc;
2077
2078 $db->begin();
2079
2080 $tmpmysoc = new Societe($db);
2081 $tmpmysoc->setMysoc($conf);
2082
2083 print '<tr><td colspan="4">';
2084
2085 print '<br>';
2086 print '<b>'.$langs->trans('MigrationSupplierOrder')."</b><br>\n";
2087
2088 // List of purchase order lines not up to date
2089 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2090 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
2091 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c";
2092 $sql .= " WHERE cd.fk_commande = c.rowid";
2093 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2094
2095 dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur");
2096 $resql = $db->query($sql);
2097 if ($resql) {
2098 $num = $db->num_rows($resql);
2099 $i = 0;
2100 if ($num) {
2101 while ($i < $num) {
2102 $obj = $db->fetch_object($resql);
2103
2104 $rowid = $obj->rowid;
2105 $qty = $obj->qty;
2106 $pu = $obj->subprice;
2107 $vatrate = $obj->vatrate;
2108 $remise_percent = $obj->remise_percent;
2109 $remise_percent_global = $obj->remise_percent_global;
2110 $info_bits = $obj->info_bits;
2111
2112 // On met a jour les 3 nouveaux champs
2113 $commandeligne = new CommandeFournisseurLigne($db);
2114 $commandeligne->fetch($rowid);
2115
2116 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $mysoc);
2117 $total_ht = $result[0];
2118 $total_tva = $result[1];
2119 $total_ttc = $result[2];
2120
2121 $commandeligne->total_ht = (float) $total_ht;
2122 $commandeligne->total_tva = (float) $total_tva;
2123 $commandeligne->total_ttc = (float) $total_ttc;
2124
2125 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);
2126 print '. ';
2127 $commandeligne->update_total();
2128
2129 $i++;
2130 }
2131 } else {
2132 print $langs->trans("AlreadyDone");
2133 }
2134
2135 $db->free($resql);
2136
2137 /*
2138 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
2139 $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
2140 $resql=$db->query($sql);
2141 if (! $resql)
2142 {
2143 dol_print_error($db);
2144 }
2145 */
2146
2147 $db->commit();
2148 } else {
2149 print "Error #1 ".$db->error();
2150
2151 $db->rollback();
2152 }
2153
2154 print '<br>';
2155
2156 print '</td></tr>';
2157}
2158
2167function migrate_modeles($db, $langs, $conf)
2168{
2169 //print '<br>';
2170 //print '<b>'.$langs->trans('UpdateModelsTable')."</b><br>\n";
2171
2172 dolibarr_install_syslog("upgrade2::migrate_modeles");
2173
2174 if (isModEnabled('invoice')) {
2175 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
2177 if (count($modellist) == 0) {
2178 // Aucun model par default.
2179 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')";
2180 $resql = $db->query($sql);
2181 if (!$resql) {
2183 }
2184 }
2185 }
2186
2187 if (isModEnabled('order')) {
2188 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2190 if (count($modellist) == 0) {
2191 // Aucun model par default.
2192 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')";
2193 $resql = $db->query($sql);
2194 if (!$resql) {
2196 }
2197 }
2198 }
2199
2200 if (isModEnabled("shipping")) {
2201 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
2203 if (count($modellist) == 0) {
2204 // Aucun model par default.
2205 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')";
2206 $resql = $db->query($sql);
2207 if (!$resql) {
2209 }
2210 }
2211 }
2212
2213 //print $langs->trans("AlreadyDone");
2214}
2215
2216
2226{
2227 dolibarr_install_syslog("upgrade2::migrate_commande_expedition");
2228
2229 print '<tr><td colspan="4">';
2230
2231 print '<br>';
2232 print '<b>'.$langs->trans('MigrationShipmentOrderMatching')."</b><br>\n";
2233
2234 $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande");
2235 $obj = $db->fetch_object($result);
2236 if ($obj) {
2237 $error = 0;
2238
2239 $db->begin();
2240
2241 $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
2242 $resql = $db->query($sql);
2243 if ($resql) {
2244 $i = 0;
2245 $num = $db->num_rows($resql);
2246
2247 if ($num) {
2248 while ($i < $num) {
2249 $obj = $db->fetch_object($resql);
2250
2251 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
2252 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2253 $resql2 = $db->query($sql);
2254
2255 if (!$resql2) {
2256 $error++;
2258 }
2259 print '. ';
2260 $i++;
2261 }
2262 }
2263
2264 if ($error == 0) {
2265 $db->commit();
2266 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
2267 print $langs->trans('FieldRenamed')."<br>\n";
2268 $db->query($sql);
2269 } else {
2270 $db->rollback();
2271 }
2272 } else {
2274 $db->rollback();
2275 }
2276 } else {
2277 print $langs->trans('AlreadyDone')."<br>\n";
2278 }
2279 print '</td></tr>';
2280}
2281
2290function migrate_commande_livraison($db, $langs, $conf)
2291{
2292 dolibarr_install_syslog("upgrade2::migrate_commande_livraison");
2293
2294 print '<tr><td colspan="4">';
2295
2296 print '<br>';
2297 print '<b>'.$langs->trans('MigrationDeliveryOrderMatching')."</b><br>\n";
2298
2299 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande");
2300 $obj = $db->fetch_object($result);
2301 if ($obj) {
2302 $error = 0;
2303
2304 $db->begin();
2305
2306 $sql = "SELECT l.rowid, l.fk_commande,";
2307 $sql .= " c.ref_client, c.date_livraison as delivery_date";
2308 $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
2309 $sql .= " WHERE c.rowid = l.fk_commande";
2310 $resql = $db->query($sql);
2311 if ($resql) {
2312 $i = 0;
2313 $num = $db->num_rows($resql);
2314
2315 if ($num) {
2316 while ($i < $num) {
2317 $obj = $db->fetch_object($resql);
2318
2319 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)";
2320 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2321 $resql2 = $db->query($sql);
2322
2323 if ($resql2) {
2324 $delivery_date = $db->jdate($obj->delivery_date);
2325
2326 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2327 $sqlu .= " ref_client = '".$db->escape($obj->ref_client)."'";
2328 $sqlu .= ", date_livraison = '".$db->idate($delivery_date)."'";
2329 $sqlu .= " WHERE rowid = ".((int) $obj->rowid);
2330 $resql3 = $db->query($sqlu);
2331 if (!$resql3) {
2332 $error++;
2334 }
2335 } else {
2336 $error++;
2338 }
2339 print '. ';
2340 $i++;
2341 }
2342 }
2343
2344 if ($error == 0) {
2345 $db->commit();
2346 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
2347 print $langs->trans('FieldRenamed')."<br>\n";
2348 $db->query($sql);
2349 } else {
2350 $db->rollback();
2351 }
2352 } else {
2354 $db->rollback();
2355 }
2356 } else {
2357 print $langs->trans('AlreadyDone')."<br>\n";
2358 }
2359 print '</td></tr>';
2360}
2361
2370function migrate_detail_livraison($db, $langs, $conf)
2371{
2372 dolibarr_install_syslog("upgrade2::migrate_detail_livraison");
2373
2374 print '<tr><td colspan="4">';
2375
2376 print '<br>';
2377 print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n";
2378
2379 // This is done if field fk_commande_ligne exists.
2380 // If not this means migration was already done.
2381 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne");
2382 $obj = $db->fetch_object($result);
2383 if ($obj) {
2384 $error = 0;
2385
2386 $db->begin();
2387
2388 $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2389 $sql .= ", ld.fk_livraison";
2390 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
2391 $sql .= " WHERE ld.fk_commande_ligne = cd.rowid";
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."livraisondet SET";
2402 $sql .= " fk_product = ".((int) $obj->fk_product);
2403 $sql .= ",description = '".$db->escape($obj->description)."'";
2404 $sql .= ",subprice = ".price2num($obj->subprice);
2405 $sql .= ",total_ht = ".price2num($obj->total_ht);
2406 $sql .= " WHERE fk_commande_ligne = ".((int) $obj->rowid);
2407 $resql2 = $db->query($sql);
2408
2409 if ($resql2) {
2410 $sql = "SELECT total_ht";
2411 $sql .= " FROM ".MAIN_DB_PREFIX."livraison";
2412 $sql .= " WHERE rowid = ".((int) $obj->fk_livraison);
2413 $resql3 = $db->query($sql);
2414
2415 if ($resql3) {
2416 $obju = $db->fetch_object($resql3);
2417 $total_ht = $obju->total_ht + $obj->total_ht;
2418
2419 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2420 $sqlu .= " total_ht = ".price2num($total_ht, 'MT');
2421 $sqlu .= " WHERE rowid = ".((int) $obj->fk_livraison);
2422 $resql4 = $db->query($sqlu);
2423 if (!$resql4) {
2424 $error++;
2426 }
2427 } else {
2428 $error++;
2430 }
2431 } else {
2432 $error++;
2434 }
2435 print '. ';
2436 $i++;
2437 }
2438 }
2439
2440 if ($error == 0) {
2441 $db->commit();
2442 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2443 print $langs->trans('FieldRenamed')."<br>\n";
2444 $db->query($sql);
2445 } else {
2446 $db->rollback();
2447 }
2448 } else {
2450 $db->rollback();
2451 }
2452 } else {
2453 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line");
2454 $obj = $db->fetch_object($result);
2455 if (!$obj) {
2456 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2457 $db->query($sql);
2458 }
2459 print $langs->trans('AlreadyDone')."<br>\n";
2460 }
2461 print '</td></tr>';
2462}
2463
2472function migrate_stocks($db, $langs, $conf)
2473{
2474 dolibarr_install_syslog("upgrade2::migrate_stocks");
2475
2476 print '<tr><td colspan="4">';
2477
2478 print '<br>';
2479 print '<b>'.$langs->trans('MigrationStockDetail')."</b><br>\n";
2480
2481 $error = 0;
2482
2483 $db->begin();
2484
2485 $sql = "SELECT SUM(reel) as total, fk_product";
2486 $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
2487 $sql .= " GROUP BY fk_product";
2488 $resql = $db->query($sql);
2489 if ($resql) {
2490 $i = 0;
2491 $num = $db->num_rows($resql);
2492
2493 if ($num) {
2494 while ($i < $num) {
2495 $obj = $db->fetch_object($resql);
2496
2497 $sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
2498 $sql .= " stock = ".price2num($obj->total, 'MS');
2499 $sql .= " WHERE rowid = ".((int) $obj->fk_product);
2500
2501 $resql2 = $db->query($sql);
2502 if ($resql2) {
2503 } else {
2504 $error++;
2506 }
2507 print '. ';
2508 $i++;
2509 }
2510 }
2511
2512 if ($error == 0) {
2513 $db->commit();
2514 } else {
2515 $db->rollback();
2516 }
2517 } else {
2519 $db->rollback();
2520 }
2521
2522 print '</td></tr>';
2523}
2524
2534function migrate_menus($db, $langs, $conf)
2535{
2536 dolibarr_install_syslog("upgrade2::migrate_menus");
2537
2538 print '<tr><td colspan="4">';
2539
2540 print '<br>';
2541 print '<b>'.$langs->trans('MigrationMenusDetail')."</b><br>\n";
2542
2543 $error = 0;
2544
2545 if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) {
2546 $db->begin();
2547
2548 $sql = "SELECT m.rowid, mc.action";
2549 $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m";
2550 $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2551 $sql .= " AND m.enabled = '1'";
2552 $resql = $db->query($sql);
2553 if ($resql) {
2554 $i = 0;
2555 $num = $db->num_rows($resql);
2556 if ($num) {
2557 while ($i < $num) {
2558 $obj = $db->fetch_object($resql);
2559
2560 $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
2561 $sql .= " enabled = '".$db->escape($obj->action)."'";
2562 $sql .= " WHERE rowid = ".((int) $obj->rowid);
2563 $sql .= " AND enabled = '1'";
2564
2565 $resql2 = $db->query($sql);
2566 if ($resql2) {
2567 } else {
2568 $error++;
2570 }
2571 print '. ';
2572 $i++;
2573 }
2574 }
2575
2576 if ($error == 0) {
2577 $db->commit();
2578 } else {
2579 $db->rollback();
2580 }
2581 } else {
2583 $db->rollback();
2584 }
2585 } else {
2586 print $langs->trans('AlreadyDone')."<br>\n";
2587 }
2588
2589 print '</td></tr>';
2590}
2591
2602{
2603 dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress");
2604
2605 print '<tr><td colspan="4">';
2606
2607 print '<br>';
2608 print '<b>'.$langs->trans('MigrationDeliveryAddress')."</b><br>\n";
2609
2610 $error = 0;
2611
2612 if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) {
2613 $db->begin();
2614
2615 $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition";
2616 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
2617 $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce";
2618 $sql .= " WHERE c.rowid = ce.fk_commande";
2619 $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2620
2621 $resql = $db->query($sql);
2622 if ($resql) {
2623 $i = 0;
2624 $num = $db->num_rows($resql);
2625
2626 if ($num) {
2627 while ($i < $num) {
2628 $obj = $db->fetch_object($resql);
2629
2630 $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
2631 $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'";
2632 $sql .= " WHERE rowid = ".((int) $obj->fk_expedition);
2633
2634 $resql2 = $db->query($sql);
2635 if (!$resql2) {
2636 $error++;
2638 }
2639 print '. ';
2640 $i++;
2641 }
2642 } else {
2643 print $langs->trans('AlreadyDone')."<br>\n";
2644 }
2645
2646 if ($error == 0) {
2647 $db->commit();
2648 } else {
2649 $db->rollback();
2650 }
2651 } else {
2653 $db->rollback();
2654 }
2655 } else {
2656 print $langs->trans('AlreadyDone')."<br>\n";
2657 }
2658
2659 print '</td></tr>';
2660}
2661
2672{
2673 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
2674
2675 if (($db->type == 'mysql' || $db->type == 'mysqli')) {
2676 if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
2677 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2678 return 0;
2679 }
2680 }
2681 print '<tr><td colspan="4">';
2682
2683 print '<br>';
2684 print '<b>'.$langs->trans('MigrationFixData')."</b> (1)<br>\n";
2685
2686 $error = 0;
2687
2688
2689 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1.
2690 $table1 = 'facturedet';
2691 $field1 = 'fk_remise_except';
2692 $table2 = 'societe_remise_except';
2693 $field2 = 'fk_facture_line';
2694
2695 $db->begin();
2696
2697 $sql = "SELECT t1.rowid, t1.".$db->sanitize($field1)." as field";
2698 $sql .= " FROM ".MAIN_DB_PREFIX.$db->sanitize($table1)." as t1";
2699 $sql .= " WHERE t1.".$db->sanitize($field1)." IS NOT NULL AND t1.".$db->sanitize($field1)." NOT IN";
2700 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2)." as t2";
2701 $sql .= " WHERE t1.rowid = t2.".$db->sanitize($field2).")";
2702
2703 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1");
2704 $resql = $db->query($sql);
2705 if ($resql) {
2706 $i = 0;
2707 $num = $db->num_rows($resql);
2708
2709 if ($num) {
2710 while ($i < $num) {
2711 $obj = $db->fetch_object($resql);
2712
2713 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2714
2715 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2716 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2717 $sql .= " WHERE rowid = ".((int) $obj->field);
2718
2719 $resql2 = $db->query($sql);
2720 if (!$resql2) {
2721 $error++;
2723 }
2724 //print '. ';
2725 $i++;
2726 }
2727 } else {
2728 print $langs->trans('AlreadyDone')."<br>\n";
2729 }
2730
2731 if ($error == 0) {
2732 $db->commit();
2733 } else {
2734 $db->rollback();
2735 }
2736 } else {
2738 $db->rollback();
2739 }
2740
2741 print '</td></tr>';
2742
2743
2744 print '<tr><td colspan="4">';
2745
2746 print '<br>';
2747 print '<b>'.$langs->trans('MigrationFixData')."</b> (2)<br>\n";
2748
2749 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2.
2750 $table2 = 'facturedet';
2751 $field2 = 'fk_remise_except';
2752 $table1 = 'societe_remise_except';
2753 $field1 = 'fk_facture_line';
2754
2755 $db->begin();
2756
2757 $sql = "SELECT t1.rowid, t1.".$db->sanitize($field1)." as field";
2758 $sql .= " FROM ".MAIN_DB_PREFIX.$db->sanitize($table1)." as t1";
2759 $sql .= " WHERE t1.".$db->sanitize($field1)." IS NOT NULL AND t1.".$db->sanitize($field1)." NOT IN";
2760 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2)." as t2";
2761 $sql .= " WHERE t1.rowid = t2.".$db->sanitize($field2).")";
2762
2763 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2");
2764 $resql = $db->query($sql);
2765 if ($resql) {
2766 $i = 0;
2767 $num = $db->num_rows($resql);
2768
2769 if ($num) {
2770 while ($i < $num) {
2771 $obj = $db->fetch_object($resql);
2772
2773 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2774
2775 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2776 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2777 $sql .= " WHERE rowid = ".((int) $obj->field);
2778
2779 $resql2 = $db->query($sql);
2780 if (!$resql2) {
2781 $error++;
2783 }
2784 //print '. ';
2785 $i++;
2786 }
2787 } else {
2788 print $langs->trans('AlreadyDone')."<br>\n";
2789 }
2790
2791 if ($error == 0) {
2792 $db->commit();
2793 } else {
2794 $db->rollback();
2795 }
2796 } else {
2798 $db->rollback();
2799 }
2800
2801 print '</td></tr>';
2802
2803 return ($error ? -1 : 1);
2804}
2805
2814function migrate_project_user_resp($db, $langs, $conf)
2815{
2816 dolibarr_install_syslog("upgrade2::migrate_project_user_resp");
2817
2818 print '<tr><td colspan="4">';
2819
2820 print '<br>';
2821 print '<b>'.$langs->trans('MigrationProjectUserResp')."</b><br>\n";
2822
2823 $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp");
2824 $obj = $db->fetch_object($result);
2825 if ($obj) {
2826 $error = 0;
2827
2828 $db->begin();
2829
2830 $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet";
2831 $resql = $db->query($sql);
2832 if ($resql) {
2833 $i = 0;
2834 $num = $db->num_rows($resql);
2835
2836 if ($num) {
2837 while ($i < $num) {
2838 $obj = $db->fetch_object($resql);
2839
2840 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2841 $sql2 .= "datecreate";
2842 $sql2 .= ", statut";
2843 $sql2 .= ", element_id";
2844 $sql2 .= ", fk_c_type_contact";
2845 $sql2 .= ", fk_socpeople";
2846 $sql2 .= ") VALUES (";
2847 $sql2 .= "'".$db->idate(dol_now())."'";
2848 $sql2 .= ", '4'";
2849 $sql2 .= ", ".((int) $obj->rowid);
2850 $sql2 .= ", '160'";
2851 $sql2 .= ", ".((int) $obj->fk_user_resp);
2852 $sql2 .= ")";
2853
2854 if ($obj->fk_user_resp > 0) {
2855 $resql2 = $db->query($sql2);
2856 if (!$resql2) {
2857 $error++;
2859 }
2860 }
2861 print '. ';
2862
2863 $i++;
2864 }
2865 }
2866
2867 if ($error == 0) {
2868 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp";
2869 if ($db->query($sqlDrop)) {
2870 $db->commit();
2871 } else {
2872 $db->rollback();
2873 }
2874 } else {
2875 $db->rollback();
2876 }
2877 } else {
2879 $db->rollback();
2880 }
2881 } else {
2882 print $langs->trans('AlreadyDone')."<br>\n";
2883 }
2884 print '</td></tr>';
2885}
2886
2896{
2897 dolibarr_install_syslog("upgrade2::migrate_project_task_actors");
2898
2899 print '<tr><td colspan="4">';
2900
2901 print '<br>';
2902 print '<b>'.$langs->trans('MigrationProjectTaskActors')."</b><br>\n";
2903
2904 if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) {
2905 $error = 0;
2906
2907 $db->begin();
2908
2909 $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors";
2910 $resql = $db->query($sql);
2911 if ($resql) {
2912 $i = 0;
2913 $num = $db->num_rows($resql);
2914
2915 if ($num) {
2916 while ($i < $num) {
2917 $obj = $db->fetch_object($resql);
2918
2919 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2920 $sql2 .= "datecreate";
2921 $sql2 .= ", statut";
2922 $sql2 .= ", element_id";
2923 $sql2 .= ", fk_c_type_contact";
2924 $sql2 .= ", fk_socpeople";
2925 $sql2 .= ") VALUES (";
2926 $sql2 .= "'".$db->idate(dol_now())."'";
2927 $sql2 .= ", '4'";
2928 $sql2 .= ", ".((int) $obj->fk_project_task);
2929 $sql2 .= ", '180'";
2930 $sql2 .= ", ".((int) $obj->fk_user);
2931 $sql2 .= ")";
2932
2933 $resql2 = $db->query($sql2);
2934
2935 if (!$resql2) {
2936 $error++;
2938 }
2939 print '. ';
2940 $i++;
2941 }
2942 }
2943
2944 if ($error == 0) {
2945 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors";
2946 if ($db->query($sqlDrop)) {
2947 $db->commit();
2948 } else {
2949 $db->rollback();
2950 }
2951 } else {
2952 $db->rollback();
2953 }
2954 } else {
2956 $db->rollback();
2957 }
2958 } else {
2959 print $langs->trans('AlreadyDone')."<br>\n";
2960 }
2961 print '</td></tr>';
2962}
2963
2977function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
2978{
2979 print '<tr><td colspan="4">';
2980
2981 print '<br>';
2982 print '<b>'.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."</b><br>\n";
2983
2984 $error = 0;
2985
2986 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2987 dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table);
2988
2989 $db->begin();
2990
2991 $sqlSelect = "SELECT ".$db->sanitize($fk_source).", ".$db->sanitize($fk_target);
2992 $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table;
2993
2994 $resql = $db->query($sqlSelect);
2995 if ($resql) {
2996 $i = 0;
2997 $num = $db->num_rows($resql);
2998
2999 if ($num) {
3000 while ($i < $num) {
3001 $obj = $db->fetch_object($resql);
3002
3003 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
3004 $sqlInsert .= "fk_source";
3005 $sqlInsert .= ", sourcetype";
3006 $sqlInsert .= ", fk_target";
3007 $sqlInsert .= ", targettype";
3008 $sqlInsert .= ") VALUES (";
3009 $sqlInsert .= ((int) $obj->$fk_source);
3010 $sqlInsert .= ", '".$db->escape($sourcetype)."'";
3011 $sqlInsert .= ", ".((int) $obj->$fk_target);
3012 $sqlInsert .= ", '".$db->escape($targettype)."'";
3013 $sqlInsert .= ")";
3014
3015 $result = $db->query($sqlInsert);
3016 if (!$result) {
3017 $error++;
3019 }
3020 print '. ';
3021 $i++;
3022 }
3023 } else {
3024 print $langs->trans('AlreadyDone')."<br>\n";
3025 }
3026
3027 if ($error == 0) {
3028 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$db->sanitize($table);
3029 if ($db->query($sqlDrop)) {
3030 $db->commit();
3031 } else {
3032 $db->rollback();
3033 }
3034 } else {
3035 $db->rollback();
3036 }
3037 } else {
3039 $db->rollback();
3040 }
3041 } else {
3042 print $langs->trans('AlreadyDone')."<br>\n";
3043 }
3044
3045 print '</td></tr>';
3046}
3047
3056function migrate_element_time($db, $langs, $conf)
3057{
3058 dolibarr_install_syslog("upgrade2::migrate_element_time");
3059
3060 print '<tr><td colspan="4">';
3061
3062 print '<br>';
3063 print '<b>'.$langs->trans('MigrationProjectTaskTime')."</b><br>\n";
3064
3065 $error = 0;
3066
3067 $db->begin();
3068
3069 $sql = "SELECT rowid, fk_element, element_duration";
3070 $sql .= " FROM ".MAIN_DB_PREFIX."element_time";
3071 $resql = $db->query($sql);
3072 if ($resql) {
3073 $i = 0;
3074 $num = $db->num_rows($resql);
3075
3076 if ($num) {
3077 $totaltime = array();
3078 $oldtime = 0;
3079
3080 while ($i < $num) {
3081 $obj = $db->fetch_object($resql);
3082
3083 if ($obj->element_duration > 0) {
3084 // convert to second
3085 // only for int time and float time ex: 1.75 for 1h45
3086 list($hour, $min) = explode('.', $obj->element_duration);
3087 $hour = (int) $hour * 60 * 60;
3088 $min = (int) ((float) ('.'.$min)) * 3600;
3089 $newtime = $hour + $min;
3090
3091 $sql2 = "UPDATE ".MAIN_DB_PREFIX."element_time SET";
3092 $sql2 .= " element_duration = ".((int) $newtime);
3093 $sql2 .= " WHERE rowid = ".((int) $obj->rowid);
3094
3095 $resql2 = $db->query($sql2);
3096 if (!$resql2) {
3097 $error++;
3099 }
3100 print '. ';
3101 $oldtime++;
3102 if (!empty($totaltime[$obj->fk_element])) {
3103 $totaltime[$obj->fk_element] += $newtime;
3104 } else {
3105 $totaltime[$obj->fk_element] = $newtime;
3106 }
3107 } else {
3108 if (!empty($totaltime[$obj->fk_element])) {
3109 $totaltime[$obj->fk_element] += $obj->element_duration;
3110 } else {
3111 $totaltime[$obj->fk_element] = $obj->element_duration;
3112 }
3113 }
3114
3115 $i++;
3116 }
3117
3118 if ($error == 0) {
3119 if ($oldtime > 0) {
3120 foreach ($totaltime as $taskid => $total_duration) {
3121 $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
3122 $sql .= " duration_effective = ".((int) $total_duration);
3123 $sql .= " WHERE rowid = ".((int) $taskid);
3124
3125 $resql = $db->query($sql);
3126 if (!$resql) {
3127 $error++;
3129 }
3130 }
3131 } else {
3132 print $langs->trans('AlreadyDone')."<br>\n";
3133 }
3134 } else {
3136 }
3137 } else {
3138 print $langs->trans('AlreadyDone')."<br>\n";
3139 }
3140 } else {
3142 }
3143
3144 if ($error == 0) {
3145 $db->commit();
3146 } else {
3147 $db->rollback();
3148 }
3149
3150 print '</td></tr>';
3151}
3152
3162{
3163 print '<tr><td colspan="4">';
3164
3165 print '<br>';
3166 print '<b>'.$langs->trans('MigrationCustomerOrderShipping')."</b><br>\n";
3167
3168 $error = 0;
3169
3170 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer");
3171 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery");
3172 $obj1 = $db->fetch_object($result1);
3173 $obj2 = $db->fetch_object($result2);
3174 if (!$obj1 && !$obj2) {
3175 dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping");
3176
3177 $db->begin();
3178
3179 $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3180 $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3181
3182 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3183 $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3184 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e";
3185 $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el";
3186 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3187 $sqlSelect .= " WHERE e.rowid = el.fk_target";
3188 $sqlSelect .= " AND el.targettype = 'shipping'";
3189
3190 $resql = $db->query($sqlSelect);
3191 if ($resql) {
3192 $i = 0;
3193 $num = $db->num_rows($resql);
3194
3195 if ($num) {
3196 while ($i < $num) {
3197 $obj = $db->fetch_object($resql);
3198
3199 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
3200 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'";
3201 $sqlUpdate .= ", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date : 'null')."'";
3202 $sqlUpdate .= " WHERE rowid = ".((int) $obj->shipping_id);
3203
3204 $result = $db->query($sqlUpdate);
3205 if (!$result) {
3206 $error++;
3208 }
3209 print '. ';
3210 $i++;
3211 }
3212 } else {
3213 print $langs->trans('AlreadyDone')."<br>\n";
3214 }
3215
3216 if ($error == 0) {
3217 $db->commit();
3218 } else {
3220 $db->rollback();
3221 }
3222 } else {
3224 $db->rollback();
3225 }
3226 } else {
3228 $db->rollback();
3229 }
3230 } else {
3231 print $langs->trans('AlreadyDone')."<br>\n";
3232 }
3233
3234 print '</td></tr>';
3235}
3236
3245function migrate_shipping_delivery($db, $langs, $conf)
3246{
3247 print '<tr><td colspan="4">';
3248
3249 print '<br>';
3250 print '<b>'.$langs->trans('MigrationShippingDelivery')."</b><br>\n";
3251
3252 $error = 0;
3253
3254 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition");
3255 $obj = $db->fetch_object($result);
3256 if ($obj) {
3257 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery");
3258
3259 $db->begin();
3260
3261 $sqlSelect = "SELECT rowid, fk_expedition";
3262 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison";
3263 $sqlSelect .= " WHERE fk_expedition is not null";
3264
3265 $resql = $db->query($sqlSelect);
3266 if ($resql) {
3267 $i = 0;
3268 $num = $db->num_rows($resql);
3269
3270 if ($num) {
3271 while ($i < $num) {
3272 $obj = $db->fetch_object($resql);
3273
3274 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
3275 $sqlInsert .= "fk_source";
3276 $sqlInsert .= ", sourcetype";
3277 $sqlInsert .= ", fk_target";
3278 $sqlInsert .= ", targettype";
3279 $sqlInsert .= ") VALUES (";
3280 $sqlInsert .= ((int) $obj->fk_expedition);
3281 $sqlInsert .= ", 'shipping'";
3282 $sqlInsert .= ", ".((int) $obj->rowid);
3283 $sqlInsert .= ", 'delivery'";
3284 $sqlInsert .= ")";
3285
3286 $result = $db->query($sqlInsert);
3287 if ($result) {
3288 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL";
3289 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3290
3291 $result = $db->query($sqlUpdate);
3292 if (!$result) {
3293 $error++;
3295 }
3296 print '. ';
3297 } else {
3298 $error++;
3300 }
3301 $i++;
3302 }
3303 } else {
3304 print $langs->trans('AlreadyDone')."<br>\n";
3305 }
3306
3307 if ($error == 0) {
3308 $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3309 $db->query($sqlDelete);
3310
3311 $db->commit();
3312
3313 // DDL commands must not be inside a transaction
3314 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition";
3315 $db->query($sqlDrop);
3316 } else {
3318 $db->rollback();
3319 }
3320 } else {
3322 $db->rollback();
3323 }
3324 } else {
3325 print $langs->trans('AlreadyDone')."<br>\n";
3326 }
3327
3328 print '</td></tr>';
3329}
3330
3340function migrate_shipping_delivery2($db, $langs, $conf)
3341{
3342 print '<tr><td colspan="4">';
3343
3344 print '<br>';
3345 print '<b>'.$langs->trans('MigrationShippingDelivery2')."</b><br>\n";
3346
3347 $error = 0;
3348
3349 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2");
3350
3351 $db->begin();
3352
3353 $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3354 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,";
3355 $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,";
3356 $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e";
3357 $sqlSelect .= " WHERE l.rowid = el.fk_target";
3358 $sqlSelect .= " AND el.targettype = 'delivery'";
3359 $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3360 $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null
3361 // Add condition to know if we never migrate this record
3362 $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")";
3363 $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")";
3364
3365 $resql = $db->query($sqlSelect);
3366 if ($resql) {
3367 $i = 0;
3368 $num = $db->num_rows($resql);
3369
3370 if ($num) {
3371 while ($i < $num) {
3372 $obj = $db->fetch_object($resql);
3373
3374 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
3375 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',";
3376 $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null');
3377 $sqlUpdate .= " WHERE rowid = ".((int) $obj->delivery_id);
3378
3379 $result = $db->query($sqlUpdate);
3380 if (!$result) {
3381 $error++;
3383 }
3384 print '. ';
3385 $i++;
3386 }
3387 } else {
3388 print $langs->trans('AlreadyDone')."<br>\n";
3389 }
3390
3391 if ($error == 0) {
3392 $db->commit();
3393 } else {
3395 $db->rollback();
3396 }
3397 } else {
3399 $db->rollback();
3400 }
3401
3402 print '</td></tr>';
3403}
3404
3413function migrate_actioncomm_element($db, $langs, $conf)
3414{
3415 print '<tr><td colspan="4">';
3416
3417 print '<br>';
3418 print '<b>'.$langs->trans('MigrationActioncommElement')."</b><br>\n";
3419
3420 $elements = array(
3421 'propal' => 'propalrowid',
3422 'order' => 'fk_commande',
3423 'invoice' => 'fk_facture',
3424 'contract' => 'fk_contract',
3425 'order_supplier' => 'fk_supplier_order',
3426 'invoice_supplier' => 'fk_supplier_invoice'
3427 );
3428
3429 foreach ($elements as $type => $field) {
3430 $result = $db->DDLDescTable(MAIN_DB_PREFIX."actioncomm", $field);
3431 $obj = $db->fetch_object($result);
3432 if ($obj) {
3433 dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=".$field);
3434
3435 $db->begin();
3436
3437 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ";
3438 $sql .= "fk_element = ".$db->sanitize($field).", elementtype = '".$db->escape($type)."'";
3439 $sql .= " WHERE ".$db->sanitize($field)." IS NOT NULL";
3440 $sql .= " AND fk_element IS NULL";
3441 $sql .= " AND elementtype IS NULL";
3442
3443 $resql = $db->query($sql);
3444 if ($resql) {
3445 $db->commit();
3446
3447 // DDL commands must not be inside a transaction
3448 // We will drop at next version because a migrate should be runnable several times if it fails.
3449 //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
3450 //$db->query($sqlDrop);
3451 //print '. ';
3452 } else {
3454 $db->rollback();
3455 }
3456 } else {
3457 print $langs->trans('AlreadyDone')."<br>\n";
3458 }
3459 }
3460
3461 print '</td></tr>';
3462}
3463
3472function migrate_mode_reglement($db, $langs, $conf)
3473{
3474 print '<tr><td colspan="4">';
3475
3476 print '<br>';
3477 print '<b>'.$langs->trans('MigrationPaymentMode')."</b><br>\n";
3478
3479 $elements = array(
3480 'old_id' => array(5, 8, 9, 10, 11),
3481 'new_id' => array(50, 51, 52, 53, 54),
3482 'code' => array('VAD', 'TRA', 'LCR', 'FAC', 'PRO'),
3483 'tables' => array('commande_fournisseur', 'commande', 'facture_rec', 'facture', 'propal')
3484 );
3485 $count = 0;
3486
3487 foreach ($elements['old_id'] as $key => $old_id) {
3488 $error = 0;
3489
3490 dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);
3491
3492 $sqlSelect = "SELECT id";
3493 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."c_paiement";
3494 $sqlSelect .= " WHERE id = ".((int) $old_id);
3495 $sqlSelect .= " AND code = '".$db->escape($elements['code'][$key])."'";
3496
3497 $resql = $db->query($sqlSelect);
3498 if ($resql) {
3499 $num = $db->num_rows($resql);
3500 if ($num) {
3501 $count++;
3502
3503 $db->begin();
3504
3505 $sqla = "UPDATE ".MAIN_DB_PREFIX."paiement SET";
3506 $sqla .= " fk_paiement = ".((int) $elements['new_id'][$key]);
3507 $sqla .= " WHERE fk_paiement = ".((int) $old_id);
3508 $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])."')";
3509 $resqla = $db->query($sqla);
3510
3511 $sql = "UPDATE ".MAIN_DB_PREFIX."c_paiement SET";
3512 $sql .= " id = ".((int) $elements['new_id'][$key]);
3513 $sql .= " WHERE id = ".((int) $old_id);
3514 $sql .= " AND code = '".$db->escape($elements['code'][$key])."'";
3515 $resql = $db->query($sql);
3516
3517 if ($resqla && $resql) {
3518 foreach ($elements['tables'] as $table) {
3519 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table)." SET ";
3520 $sql .= "fk_mode_reglement = ".((int) $elements['new_id'][$key]);
3521 $sql .= " WHERE fk_mode_reglement = ".((int) $old_id);
3522
3523 $resql = $db->query($sql);
3524 if (!$resql) {
3526 $error++;
3527 }
3528 print '. ';
3529 }
3530
3531 if (!$error) {
3532 $db->commit();
3533 } else {
3535 $db->rollback();
3536 }
3537 } else {
3539 $db->rollback();
3540 }
3541 }
3542 }
3543 }
3544
3545 if ($count == 0) {
3546 print $langs->trans('AlreadyDone')."<br>\n";
3547 }
3548
3549
3550 print '</td></tr>';
3551}
3552
3553
3562function migrate_clean_association($db, $langs, $conf)
3563{
3564 $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association");
3565 if ($result) { // result defined for version 3.2 or -
3566 $obj = $db->fetch_object($result);
3567 if ($obj) { // It table categorie_association exists
3568 $couples = array();
3569 $children = array();
3570 $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
3571 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3572 dolibarr_install_syslog("upgrade: search duplicate");
3573 $resql = $db->query($sql);
3574 if ($resql) {
3575 $num = $db->num_rows($resql);
3576 while ($obj = $db->fetch_object($resql)) {
3577 if (!isset($children[$obj->fk_categorie_fille])) { // Only one record as child (a child has only on parent).
3578 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3579 $children[$obj->fk_categorie_fille] = 1; // Set record for this child
3580 $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere' => $obj->fk_categorie_mere, 'fille' => $obj->fk_categorie_fille);
3581 }
3582 }
3583 }
3584
3585 dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
3586
3587 // If there is duplicates couples or child with two parents
3588 if (count($couples) > 0 && $num > count($couples)) {
3589 $error = 0;
3590
3591 $db->begin();
3592
3593 // We delete all
3594 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
3595 dolibarr_install_syslog("upgrade: delete association");
3596 $resqld = $db->query($sql);
3597 if ($resqld) {
3598 // And we insert only each record once
3599 foreach ($couples as $key => $val) {
3600 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
3601 $sql .= " VALUES(".((int) $val['mere']).", ".((int) $val['fille']).")";
3602 dolibarr_install_syslog("upgrade: insert association");
3603 $resqli = $db->query($sql);
3604 if (!$resqli) {
3605 $error++;
3606 }
3607 }
3608 }
3609
3610 if (!$error) {
3611 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3612 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
3613 $db->commit();
3614 } else {
3615 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3616 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").'</td></tr>';
3617 $db->rollback();
3618 }
3619 }
3620 } else {
3621 print '<tr><td>'.$langs->trans("Error").'</td>';
3622 print '<td class="right"><div class="error">'.$db->lasterror().'</div></td></tr>';
3623 }
3624 }
3625 }
3626}
3627
3628
3638{
3639 print '<tr><td colspan="4">';
3640
3641 print '<br>';
3642 print '<b>'.$langs->trans('MigrationCategorieAssociation')."</b><br>\n";
3643
3644 $error = 0;
3645
3646 if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association")) {
3647 dolibarr_install_syslog("upgrade2::migrate_categorie_association");
3648
3649 $db->begin();
3650
3651 $sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
3652 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3653
3654 $resql = $db->query($sqlSelect);
3655 if ($resql) {
3656 $i = 0;
3657 $num = $db->num_rows($resql);
3658
3659 if ($num) {
3660 while ($i < $num) {
3661 $obj = $db->fetch_object($resql);
3662
3663 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
3664 $sqlUpdate .= "fk_parent = ".((int) $obj->fk_categorie_mere);
3665 $sqlUpdate .= " WHERE rowid = ".((int) $obj->fk_categorie_fille);
3666
3667 $result = $db->query($sqlUpdate);
3668 if (!$result) {
3669 $error++;
3671 }
3672 print '. ';
3673 $i++;
3674 }
3675 } else {
3676 print $langs->trans('AlreadyDone')."<br>\n";
3677 }
3678
3679 if (!$error) {
3680 $db->commit();
3681 } else {
3682 $db->rollback();
3683 }
3684 } else {
3686 $db->rollback();
3687 }
3688 } else {
3689 print $langs->trans('AlreadyDone')."<br>\n";
3690 }
3691
3692 print '</td></tr>';
3693}
3694
3703function migrate_event_assignement($db, $langs, $conf)
3704{
3705 print '<tr><td colspan="4">';
3706
3707 print '<br>';
3708 print '<b>'.$langs->trans('MigrationEvents')."</b><br>\n";
3709
3710 $error = 0;
3711
3712 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3713
3714 $db->begin();
3715
3716 $sqlSelect = "SELECT a.id, a.fk_user_action";
3717 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3718 $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";
3719 $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')";
3720 $sqlSelect .= " ORDER BY a.id";
3721 //print $sqlSelect;
3722
3723 $resql = $db->query($sqlSelect);
3724 if ($resql) {
3725 $i = 0;
3726 $num = $db->num_rows($resql);
3727
3728 if ($num) {
3729 while ($i < $num) {
3730 $obj = $db->fetch_object($resql);
3731
3732 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3733 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'user', ".((int) $obj->fk_user_action).")";
3734
3735 $result = $db->query($sqlUpdate);
3736 if (!$result) {
3737 $error++;
3739 }
3740 print '. ';
3741 $i++;
3742 }
3743 } else {
3744 print $langs->trans('AlreadyDone')."<br>\n";
3745 }
3746
3747 if (!$error) {
3748 $db->commit();
3749 } else {
3750 $db->rollback();
3751 }
3752 } else {
3754 $db->rollback();
3755 }
3756
3757
3758 print '</td></tr>';
3759}
3760
3770{
3771 print '<tr><td colspan="4">';
3772
3773 print '<br>';
3774 print '<b>'.$langs->trans('MigrationEventsContact')."</b><br>\n";
3775
3776 $error = 0;
3777
3778 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3779
3780 $db->begin();
3781
3782 $sqlSelect = "SELECT a.id, a.fk_contact";
3783 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3784 $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";
3785 $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')";
3786 $sqlSelect .= " ORDER BY a.id";
3787 //print $sqlSelect;
3788
3789 $resql = $db->query($sqlSelect);
3790 if ($resql) {
3791 $i = 0;
3792 $num = $db->num_rows($resql);
3793
3794 if ($num) {
3795 while ($i < $num) {
3796 $obj = $db->fetch_object($resql);
3797
3798 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3799 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'socpeople', ".((int) $obj->fk_contact).")";
3800
3801 $result = $db->query($sqlUpdate);
3802 if (!$result) {
3803 $error++;
3805 }
3806 print '. ';
3807 $i++;
3808 }
3809 } else {
3810 print $langs->trans('AlreadyDone')."<br>\n";
3811 }
3812
3813 if (!$error) {
3814 $db->commit();
3815 } else {
3816 $db->rollback();
3817 }
3818 } else {
3820 $db->rollback();
3821 }
3822
3823
3824 print '</td></tr>';
3825}
3826
3827
3836function migrate_reset_blocked_log($db, $langs, $conf)
3837{
3838 global $user;
3839
3840 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
3841
3842 print '<tr><td colspan="4">';
3843
3844 print '<br>';
3845 print '<b>'.$langs->trans('MigrationResetBlockedLog')."</b><br>\n";
3846
3847 $error = 0;
3848
3849 dolibarr_install_syslog("upgrade2::migrate_reset_blocked_log");
3850
3851 $db->begin();
3852
3853 $sqlSelect = "SELECT DISTINCT entity";
3854 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."blockedlog";
3855
3856 //print $sqlSelect;
3857
3858 $resql = $db->query($sqlSelect);
3859 if ($resql) {
3860 $i = 0;
3861 $num = $db->num_rows($resql);
3862
3863 if ($num) {
3864 while ($i < $num) {
3865 $obj = $db->fetch_object($resql);
3866
3867 print 'Process entity '.$obj->entity;
3868
3869 $sqlSearch = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3870 $resqlSearch = $db->query($sqlSearch);
3871 if ($resqlSearch) {
3872 $objSearch = $db->fetch_object($resqlSearch);
3873 //var_dump($objSearch);
3874 if ($objSearch && $objSearch->nb == 0) {
3875 print ' - Record for entity must be reset...';
3876
3877 $sqlUpdate = "DELETE FROM ".MAIN_DB_PREFIX."blockedlog";
3878 $sqlUpdate .= " WHERE entity = ".((int) $obj->entity);
3879 $resqlUpdate = $db->query($sqlUpdate);
3880 if (!$resqlUpdate) {
3881 $error++;
3883 } else {
3884 // Add set line
3885 $object = new stdClass();
3886 $object->id = 0;
3887 $object->element = 'module';
3888 $object->ref = 'systemevent';
3889 $object->entity = $obj->entity;
3890 $object->date = dol_now();
3891
3892 $b = new BlockedLog($db);
3893 $b->setObjectData($object, 'MODULE_SET', 0, $user, 0);
3894
3895 $res = $b->create($user);
3896 if ($res <= 0) {
3897 $error++;
3898 }
3899 }
3900 } else {
3901 print ' - '.$langs->trans('AlreadyDone').'<br>';
3902 }
3903 } else {
3905 }
3906
3907 $i++;
3908 }
3909 } else {
3910 print $langs->trans('NothingToDo')."<br>\n";
3911 }
3912
3913 if (!$error) {
3914 $db->commit();
3915 } else {
3916 $db->rollback();
3917 }
3918 } else {
3920 $db->rollback();
3921 }
3922
3923 print '</td></tr>';
3924}
3925
3926
3935function migrate_remise_entity($db, $langs, $conf)
3936{
3937 print '<tr><td colspan="4">';
3938
3939 print '<br>';
3940 print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\n";
3941
3942 $error = 0;
3943
3944 dolibarr_install_syslog("upgrade2::migrate_remise_entity");
3945
3946 $db->begin();
3947
3948 $sqlSelect = "SELECT sr.rowid, s.entity";
3949 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s";
3950 $sqlSelect .= " WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3951
3952 //print $sqlSelect;
3953
3954 $resql = $db->query($sqlSelect);
3955 if ($resql) {
3956 $i = 0;
3957 $num = $db->num_rows($resql);
3958
3959 if ($num) {
3960 while ($i < $num) {
3961 $obj = $db->fetch_object($resql);
3962
3963 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
3964 $sqlUpdate .= " entity = ".((int) $obj->entity);
3965 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3966
3967 $result = $db->query($sqlUpdate);
3968 if (!$result) {
3969 $error++;
3971 }
3972
3973 print '. ';
3974 $i++;
3975 }
3976 } else {
3977 print $langs->trans('AlreadyDone')."<br>\n";
3978 }
3979
3980 if (!$error) {
3981 $db->commit();
3982 } else {
3983 $db->rollback();
3984 }
3985 } else {
3987 $db->rollback();
3988 }
3989
3990 print '</td></tr>';
3991}
3992
4002{
4003 print '<tr><td colspan="4">';
4004
4005 print '<br>';
4006 print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\n";
4007
4008 $error = 0;
4009
4010 dolibarr_install_syslog("upgrade2::migrate_remise_except_entity");
4011
4012 $db->begin();
4013
4014 $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
4015 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
4016 //print $sqlSelect;
4017
4018 $resql = $db->query($sqlSelect);
4019 if ($resql) {
4020 $i = 0;
4021 $num = $db->num_rows($resql);
4022
4023 if ($num) {
4024 while ($i < $num) {
4025 $obj = $db->fetch_object($resql);
4026
4027 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
4028 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
4029
4030 $sqlSelect2 = "SELECT f.entity";
4031 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
4032 $sqlSelect2 .= " WHERE f.rowid = ".((int) $fk_facture);
4033 } elseif (!empty($obj->fk_facture_line)) {
4034 $sqlSelect2 = "SELECT f.entity";
4035 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
4036 $sqlSelect2 .= " WHERE fd.rowid = ".((int) $obj->fk_facture_line);
4037 $sqlSelect2 .= " AND fd.fk_facture = f.rowid";
4038 } else {
4039 $sqlSelect2 = "SELECT s.entity";
4040 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."societe as s";
4041 $sqlSelect2 .= " WHERE s.rowid = ".((int) $obj->fk_soc);
4042 }
4043
4044 $resql2 = $db->query($sqlSelect2);
4045 if ($resql2) {
4046 if ($db->num_rows($resql2) > 0) {
4047 $obj2 = $db->fetch_object($resql2);
4048
4049 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
4050 $sqlUpdate .= " entity = ".((int) $obj2->entity);
4051 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
4052
4053 $result = $db->query($sqlUpdate);
4054 if (!$result) {
4055 $error++;
4057 }
4058 }
4059 } else {
4060 $error++;
4062 }
4063
4064 print '. ';
4065 $i++;
4066 }
4067 } else {
4068 print $langs->trans('AlreadyDone')."<br>\n";
4069 }
4070
4071 if (!$error) {
4072 $db->commit();
4073 } else {
4074 $db->rollback();
4075 }
4076 } else {
4078 $db->rollback();
4079 }
4080
4081
4082 print '</td></tr>';
4083}
4084
4102{
4103 dolibarr_install_syslog("upgrade2::migrate_supplier_prices_permissions");
4104
4105 // Grant each target permission to holders of any of its source permissions.
4106 // Format: array('to' => array(module, perms, subperms), 'from' => array(array(module, perms, subperms), ...))
4107 $rules = array(
4108 array('to' => array('produit', 'product_advance', 'read_supplier_prices'), 'from' => array(array('produit', 'lire', ''), array('produit', 'creer', ''))),
4109 array('to' => array('produit', 'product_advance', 'write_supplier_prices'), 'from' => array(array('produit', 'creer', ''))),
4110 array('to' => array('service', 'service_advance', 'read_supplier_prices'), 'from' => array(array('service', 'lire', ''))),
4111 );
4112
4113 $error = 0;
4114 $db->begin();
4115
4116 foreach ($rules as $rule) {
4117 // Resolve the target permission id by name (skip if the module/permission is not present)
4118 $targetid = migrate_get_rights_def_id($db, $rule['to'][0], $rule['to'][1], $rule['to'][2]);
4119 if ($targetid <= 0) {
4120 continue;
4121 }
4122
4123 // Resolve the source permission ids by name
4124 $sourceids = array();
4125 foreach ($rule['from'] as $from) {
4126 $id = migrate_get_rights_def_id($db, $from[0], $from[1], $from[2]);
4127 if ($id > 0) {
4128 $sourceids[] = $id;
4129 }
4130 }
4131 if (empty($sourceids)) {
4132 continue;
4133 }
4134 $sourcelist = implode(',', $sourceids);
4135
4136 // Grant to groups that hold a source permission but not yet the target
4137 $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_rights (entity, fk_usergroup, fk_id)";
4138 $sql .= " SELECT DISTINCT gr.entity, gr.fk_usergroup, ".((int) $targetid);
4139 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr";
4140 $sql .= " WHERE gr.fk_id IN (".$db->sanitize($sourcelist).")";
4141 $sql .= " AND NOT EXISTS (SELECT 1 FROM ".MAIN_DB_PREFIX."usergroup_rights as ex WHERE ex.fk_usergroup = gr.fk_usergroup AND ex.entity = gr.entity AND ex.fk_id = ".((int) $targetid).")";
4142 if (!$db->query($sql)) {
4143 $error++;
4144 break;
4145 }
4146
4147 // Grant to users that hold a source permission but not yet the target
4148 $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (entity, fk_user, fk_id)";
4149 $sql .= " SELECT DISTINCT ur.entity, ur.fk_user, ".((int) $targetid);
4150 $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur";
4151 $sql .= " WHERE ur.fk_id IN (".$db->sanitize($sourcelist).")";
4152 $sql .= " AND NOT EXISTS (SELECT 1 FROM ".MAIN_DB_PREFIX."user_rights as ex WHERE ex.fk_user = ur.fk_user AND ex.entity = ur.entity AND ex.fk_id = ".((int) $targetid).")";
4153 if (!$db->query($sql)) {
4154 $error++;
4155 break;
4156 }
4157 }
4158
4159 if ($error) {
4160 $db->rollback();
4161 return -1;
4162 }
4163 $db->commit();
4164 return 0;
4165}
4166
4176function migrate_get_rights_def_id($db, $module, $perms, $subperms)
4177{
4178 $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def";
4179 $sql .= " WHERE module = '".$db->escape($module)."'";
4180 $sql .= " AND perms = '".$db->escape($perms)."'";
4181 if ($subperms === '') {
4182 $sql .= " AND (subperms IS NULL OR subperms = '')";
4183 } else {
4184 $sql .= " AND subperms = '".$db->escape($subperms)."'";
4185 }
4186 $resql = $db->query($sql);
4187 if (!$resql) {
4188 return 0;
4189 }
4190 $obj = $db->fetch_object($resql);
4191 return $obj ? (int) $obj->id : 0;
4192}
4193
4202function migrate_user_rights_entity($db, $langs, $conf)
4203{
4204 print '<tr><td colspan="4">';
4205
4206 print '<b>'.$langs->trans('MigrationUserRightsEntity')."</b><br>\n";
4207
4208 $error = 0;
4209
4210 dolibarr_install_syslog("upgrade2::migrate_user_rights_entity");
4211
4212 $db->begin();
4213
4214 $sqlSelect = "SELECT u.rowid, u.entity";
4215 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."user as u";
4216 $sqlSelect .= " WHERE u.entity > 1";
4217 //print $sqlSelect;
4218
4219 $resql = $db->query($sqlSelect);
4220 if ($resql) {
4221 $i = 0;
4222 $num = $db->num_rows($resql);
4223
4224 if ($num) {
4225 while ($i < $num) {
4226 $obj = $db->fetch_object($resql);
4227
4228 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
4229 $sqlUpdate .= " entity = ".((int) $obj->entity);
4230 $sqlUpdate .= " WHERE fk_user = ".((int) $obj->rowid);
4231
4232 $result = $db->query($sqlUpdate);
4233 if (!$result) {
4234 $error++;
4236 }
4237
4238 print '. ';
4239 $i++;
4240 }
4241 } else {
4242 print $langs->trans('AlreadyDone')."<br>\n";
4243 }
4244
4245 if (!$error) {
4246 $db->commit();
4247 } else {
4248 $db->rollback();
4249 }
4250 } else {
4252 $db->rollback();
4253 }
4254
4255
4256 print '</td></tr>';
4257}
4258
4268{
4269 print '<tr><td colspan="4">';
4270
4271 print '<b>'.$langs->trans('MigrationUserGroupRightsEntity')."</b><br>\n";
4272
4273 $error = 0;
4274
4275 dolibarr_install_syslog("upgrade2::migrate_usergroup_rights_entity");
4276
4277 $db->begin();
4278
4279 $sqlSelect = "SELECT u.rowid, u.entity";
4280 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."usergroup as u";
4281 $sqlSelect .= " WHERE u.entity > 1";
4282 //print $sqlSelect;
4283
4284 $resql = $db->query($sqlSelect);
4285 if ($resql) {
4286 $i = 0;
4287 $num = $db->num_rows($resql);
4288
4289 if ($num) {
4290 while ($i < $num) {
4291 $obj = $db->fetch_object($resql);
4292
4293 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
4294 $sqlUpdate .= " entity = ".((int) $obj->entity);
4295 $sqlUpdate .= " WHERE fk_usergroup = ".((int) $obj->rowid);
4296
4297 $result = $db->query($sqlUpdate);
4298 if (!$result) {
4299 $error++;
4301 }
4302
4303 print '. ';
4304 $i++;
4305 }
4306 } else {
4307 print $langs->trans('AlreadyDone')."<br>\n";
4308 }
4309
4310 if (!$error) {
4311 $db->commit();
4312 } else {
4313 $db->rollback();
4314 }
4315 } else {
4317 $db->rollback();
4318 }
4319
4320
4321 print '</td></tr>';
4322}
4323
4334function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
4335{
4336 dolibarr_install_syslog("upgrade2::migrate_rename_directories");
4337
4338 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4339 dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname);
4340 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4341 } else {
4342 // If new directory already exists, we copy content of old one intotnew one
4343 dolCopyDir(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname, '0', 1);
4344 }
4345}
4346
4347
4356function migrate_delete_old_files($db, $langs, $conf)
4357{
4358 $ret = true;
4359
4360 dolibarr_install_syslog("upgrade2::migrate_delete_old_files");
4361
4362 // List of files to delete
4363 $filetodeletearray = array(
4364 '/core/ajax/ajaxcompanies.php',
4365 '/core/triggers/interface_demo.class.php',
4366 '/core/menus/barre_left/default.php',
4367 '/core/menus/barre_top/default.php',
4368 '/core/modules/modComptabiliteExpert.class.php',
4369 '/core/modules/modCommercial.class.php',
4370 '/core/modules/modPaybox.class.php',
4371 '/core/modules/modProduit.class.php',
4372 '/core/modules/modSkype.class.php',
4373 '/core/modules/modactivite.class.php', // A file from an external module that should not be here
4374 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4375 '/core/triggers/interface_modCommande_Ecotax.class.php',
4376 '/core/triggers/interface_modCommande_fraisport.class.php',
4377 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4378 '/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php', // now has position 99
4379 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4380 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4381 '/core/menus/smartphone/iphone.lib.php',
4382 '/core/menus/smartphone/iphone_backoffice.php',
4383 '/core/menus/smartphone/iphone_frontoffice.php',
4384 '/core/menus/standard/auguria_backoffice.php',
4385 '/core/menus/standard/auguria_frontoffice.php',
4386 '/core/menus/standard/eldy_backoffice.php',
4387 '/core/menus/standard/eldy_frontoffice.php',
4388 '/core/modules/export/export_excel.modules.php',
4389 '/core/modules/export/export_csv.modules.php',
4390 '/core/modules/export/exportcsv.modules.php',
4391 '/core/modules/export/export_excel2007new.modules.php',
4392 '/core/modules/facture/pdf_crabe.modules.php',
4393 '/core/modules/facture/pdf_oursin.modules.php',
4394 '/core/modules/mailings/contacts2.modules.php',
4395 '/core/modules/mailings/contacts3.modules.php',
4396 '/core/modules/mailings/contacts4.modules.php',
4397 '/core/modules/mailings/framboise.modules.php',
4398 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4399 '/core/modules/mailings/peche.modules.php',
4400 '/core/modules/mailings/poire.modules.php',
4401 '/core/modules/mailings/kiwi.modules.php',
4402 '/core/modules/syslog/mod_syslog_chromephp.php',
4403 '/core/modules/syslog/mod_syslog_firephp.php',
4404 '/core/modules/syslog/logHandlerInterface.php',
4405 '/core/boxes/box_members.php',
4406
4407 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4408 '/includes/nusoap/lib/class.*',
4409 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4410 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4411
4412 '/api/class/api_generic.class.php',
4413 '/asterisk/cidlookup.php',
4414 '/categories/class/api_category.class.php',
4415 '/categories/class/api_deprecated_category.class.php',
4416 '/compta/facture/class/api_invoice.class.php',
4417 '/commande/class/api_commande.class.php',
4418 '/partnership/class/api_partnership.class.php',
4419 '/product/class/api_product.class.php',
4420 '/recruitment/class/api_recruitment.class.php',
4421 '/societe/class/api_contact.class.php',
4422 '/societe/class/api_thirdparty.class.php',
4423 '/support/online.php',
4424 '/takepos/class/actions_takepos.class.php',
4425 '/user/class/api_user.class.php',
4426
4427 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4428 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4429 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4430 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4431 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4432 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4433 );
4434
4435 /*
4436 print '<tr><td colspan="4">';
4437 print '<b>'.$langs->trans('DeleteOldFiles')."</b><br>\n";
4438 print '</td></tr>';
4439 */
4440
4441 foreach ($filetodeletearray as $filetodelete) {
4442 //print '<b>'DOL_DOCUMENT_ROOT.$filetodelete."</b><br>\n";
4443 if (preg_match('/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4444 //print "Process file ".$filetodelete."\n";
4445 $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match('/\*/', $filetodelete) ? 1 : 0), 0, null, true, 0);
4446 if (!$result) {
4447 $langs->load("errors");
4448 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4449 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4450 } else {
4451 //print $langs->trans("FileWasRemoved", $filetodelete).'<br>';
4452 }
4453 }
4454 }
4455
4456 return $ret;
4457}
4458
4467function migrate_delete_old_dir($db, $langs, $conf)
4468{
4469 $ret = true;
4470
4471 dolibarr_install_syslog("upgrade2::migrate_delete_old_dir");
4472
4473 // List of files to delete
4474 $filetodeletearray = array(
4475 DOL_DOCUMENT_ROOT.'/core/modules/facture/terre',
4476 DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure',
4477 );
4478
4479 // On linux, we can also removed old directory with a different case than new directory.
4480 if (!empty($_SERVER["WINDIR"])) {
4481 $filetodeletearray[] = DOL_DOCUMENT_ROOT.'/includes/phpoffice/PhpSpreadsheet';
4482 }
4483
4484 foreach ($filetodeletearray as $filetodelete) {
4485 $result = 1;
4486 if (file_exists($filetodelete)) {
4487 $result = dol_delete_dir_recursive($filetodelete);
4488 }
4489 if (!$result) {
4490 $langs->load("errors");
4491 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete);
4492 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4493 }
4494 }
4495
4496 return $ret;
4497}
4498
4499
4512function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $force = 0)
4513{
4514 global $user;
4515
4516 if (count($listofmodule) == 0) {
4517 return 0;
4518 }
4519
4520 if (!is_object($user)) {
4521 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4522 $user = new User($db); // To avoid error during migration
4523 }
4524
4525 dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".implode(',', array_keys($listofmodule)), LOG_NOTICE);
4526
4527 $reloadactionformodules = array(
4528 'MAIN_MODULE_AGENDA' => array('class' => 'modAgenda', 'remove' => 1),
4529 'MAIN_MODULE_API' => array('class' => 'modApi'),
4530 'MAIN_MODULE_BARCODE' => array('class' => 'modBarcode', 'remove' => 1),
4531 'MAIN_MODULE_BLOCKEDLOG' => array('class' => 'modBlockedLog', 'deleteinsertmenus' => 1),
4532 'MAIN_MODULE_CRON' => array('class' => 'modCron', 'remove' => 1),
4533 'MAIN_MODULE_SOCIETE' => array('class' => 'modSociete', 'remove' => 1),
4534 'MAIN_MODULE_PRODUIT' => array('class' => 'modProduct'),
4535 'MAIN_MODULE_SERVICE' => array('class' => 'modService'),
4536 'MAIN_MODULE_COMMANDE' => array('class' => 'modCommande'),
4537 'MAIN_MODULE_DON' => array('class' => 'modDon'),
4538 'MAIN_MODULE_FACTURE' => array('class' => 'modFacture'),
4539 'MAIN_MODULE_FICHEINTER' => array('class' => 'modFicheinter'),
4540 'MAIN_MODULE_FOURNISSEUR' => array('class' => 'modFournisseur'),
4541 'MAIN_MODULE_EXPEDITION' => array('class' => 'modExpedition'),
4542 'MAIN_MODULE_EXPENSEREPORT' => array('class' => 'modExpenseReport'),
4543 'MAIN_MODULE_EVENTORGANIZATION' => array('class' => 'modEventOrganization', 'remove' => 1),
4544 'MAIN_MODULE_ECM' => array('class' => 'modECM', 'remove' => 1),
4545 'MAIN_MODULE_HOLIDAY' => array('class' => 'modHoliday', 'remove' => 1),
4546 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array('class' => 'modKnowledgeManagement', 'remove' => 1),
4547 'MAIN_MODULE_LOAN' => array('class' => 'modLoan', 'remove' => 1),
4548 'MAIN_MODULE_PROPAL' => array('class' => 'modPropale'),
4549 'MAIN_MODULE_SUPPLIERPROPOSAL' => array('class' => 'modSupplierProposal', 'remove' => 1),
4550 'MAIN_MODULE_OPENSURVEY' => array('class' => 'modOpenSurvey', 'remove' => 1),
4551 'MAIN_MODULE_PRODUCTBATCH' => array('class' => 'modProductBatch', 'remove' => 1),
4552 'MAIN_MODULE_TAKEPOS' => array('class' => 'modTakePos', 'remove' => 1),
4553 'MAIN_MODULE_VARIANTS' => array('class' => 'modVariants', 'remove' => 1),
4554 'MAIN_MODULE_EMAILCOLLECTOR' => array('class' => 'modEmailCollector', 'remove' => 1),
4555 );
4556
4557 foreach ($listofmodule as $moduletoreload => $reloadmode) { // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
4558 $modulekey = preg_replace('/^MAIN_MODULE_/', '', $moduletoreload);
4559
4560 if (empty($moduletoreload) || (!isModEnabled(strtolower($modulekey)) && !$force)) {
4561 continue; // Discard reload if module not enabled
4562 }
4563
4564 $mod = null;
4565
4566 if (!empty($reloadactionformodules[$moduletoreload])) {
4567 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload." with mode ".$reloadmode);
4568
4569 $val = $reloadactionformodules[$moduletoreload];
4570 $classformodule = $val['class'];
4571 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/'.$classformodule.'.class.php';
4572 if ($res) {
4573 $mod = new $classformodule($db);
4574 if (!empty($val['remove'])) {
4575 $mod->remove('noboxes');
4576 }
4577 if (!empty($val['deleteinsertmenus'])) {
4578 // We only reload menus
4579 $mod->delete_menus();
4580 $mod->insert_menus();
4581 } else {
4582 $mod->init($reloadmode);
4583 }
4584 }
4585 } else { // Other generic cases/modules
4586 $reg = array();
4587 preg_match('/([a-zA-Z0-9]+)/', $modulekey, $reg);
4588 if (!empty($reg[1])) {
4589 if (strtoupper($moduletoreload) == $moduletoreload) { // If key has at least one uppercase
4590 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4591 } else { // If key is a mix of up and low case
4592 $moduletoreloadshort = $reg[1];
4593 }
4594
4595 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort." with mode ".$reloadmode." (generic code)", LOG_NOTICE);
4596
4597 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php';
4598 if ($res) {
4599 $classname = 'mod'.$moduletoreloadshort;
4600 $mod = new $classname($db);
4601 '@phan-var-force DolibarrModules $mod';
4602
4603 //$mod->remove('noboxes');
4604 $mod->delete_menus(); // We must delete to be sure it is inserted with new values
4605 $mod->init($reloadmode);
4606 } else {
4607 dolibarr_install_syslog('Failed to include '.DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4608
4609 $res = @dol_include_once(strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
4610 if ($res) {
4611 $classname = 'mod'.$moduletoreloadshort;
4612 $mod = new $classname($db);
4613 '@phan-var-force DolibarrModules $mod';
4614 $mod->init($reloadmode);
4615 } else {
4616 dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4617 print "Error, can't find module with name ".$moduletoreload."\n";
4618 return -1;
4619 }
4620 }
4621 } else {
4622 dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_ERR);
4623 print "Error, can't find module with name ".$moduletoreload."\n";
4624 return -1;
4625 }
4626 }
4627
4628 if (!empty($mod) && is_object($mod)) {
4629 print '<tr class="trforrunsql"><td colspan="4">';
4630 print '<b>'.$langs->trans('Upgrade').'</b>: ';
4631 print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
4632 print "<!-- (".$reloadmode.") -->";
4633 print "<br>\n";
4634 print '</td></tr>';
4635 }
4636 }
4637
4638 return 1;
4639}
4640
4641
4642
4651function migrate_reload_menu($db, $langs, $conf)
4652{
4653 global $conf;
4654 dolibarr_install_syslog("upgrade2::migrate_reload_menu");
4655
4656 // Define list of menu handlers to initialize
4657 $listofmenuhandler = array();
4658 if (getDolGlobalString('MAIN_MENU_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENU_SMARTPHONE') == 'auguria_menu'
4659 || getDolGlobalString('MAIN_MENUFRONT_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE') == 'auguria_menu') {
4660 $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers
4661 }
4662
4663 foreach ($listofmenuhandler as $key => $val) {
4664 print '<tr class="trforrunsql"><td colspan="4">';
4665
4666 //print "x".$key;
4667 print '<br>';
4668 print '<b>'.$langs->trans('Upgrade').'</b>: '.$langs->trans('MenuHandler')." ".$key."<br>\n";
4669
4670 // Load sql ini_menu_handler.sql file
4671 $dir = DOL_DOCUMENT_ROOT."/core/menus/";
4672 $file = 'init_menu_'.$key.'.sql';
4673 if (file_exists($dir.$file)) {
4674 $result = run_sql($dir.$file, 1, 0, 1, $key);
4675 }
4676
4677 print '</td></tr>';
4678 }
4679
4680 return 1;
4681}
4682
4689{
4690 global $conf, $db, $langs, $user;
4691
4692 if (!is_object($user)) {
4693 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4694 $user = new User($db); // To avoid error during migration
4695 }
4696
4697 print '<tr><td colspan="4">';
4698
4699 print '<b>'.$langs->trans('MigrationProductLotPath')."</b><br>\n";
4700
4701 $sql = "SELECT rowid, entity, batch, fk_product from ".MAIN_DB_PREFIX."product_lot";
4702 $resql = $db->query($sql);
4703
4704 if ($resql) {
4705 $modulepart = "product_batch";
4706
4707 $lot = new Productlot($db);
4708
4709 while ($obj = $db->fetch_object($resql)) {
4710 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4711 if ($entity > 1) {
4712 $dir = DOL_DATA_ROOT.'/'.$entity.'/'.$conf->productbatch->multidir_output[$entity];
4713 } else {
4714 $dir = $conf->productbatch->multidir_output[$entity];
4715 }
4716
4717 if ($dir) {
4718 $lot->id = (int) $obj->rowid;
4719 $lot->ref = (string) $obj->rowid; // No ref for the moment
4720 $lot->batch = $obj->batch;
4721 $lot->entity = $obj->entity;
4722 $lot->fk_product = $obj->fk_product;
4723
4724 $savref = $lot->ref;
4725
4726 $lot->ref = $obj->batch;
4727 $origin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4728
4729 $lot->ref = $savref; // So restore the id
4730 $destin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4731
4732 //var_dump($origin.' -> '.$destin.' '.$lot->batch.' dir origin is '.dol_is_dir($origin));exit;
4733
4734 if (dol_is_dir($origin) && !dol_is_dir($destin)) {
4735 dol_move_dir($origin, $destin, 0);
4736 }
4737 }
4738 }
4739 }
4740 print '</td></tr>';
4741
4742 return 1;
4743}
4744
4751{
4752 global $conf, $db, $langs, $user;
4753
4754 print '<tr><td colspan="4">';
4755
4756 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4757
4758 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4759 $fuser = new User($db);
4760 if (!is_object($user)) {
4761 $user = $fuser; // To avoid error during migration
4762 }
4763
4764 $sql = "SELECT rowid as uid, entity from ".MAIN_DB_PREFIX."user"; // Get list of all users
4765 $resql = $db->query($sql);
4766 if ($resql) {
4767 while ($obj = $db->fetch_object($resql)) {
4768 //$fuser->fetch($obj->uid);
4769 $fuser->id = $obj->uid;
4770 $fuser->entity = $obj->entity;
4771
4772 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4773 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4774 if ($entity > 1) {
4775 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4776 } else {
4777 $dir = $conf->user->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4778 }
4779
4780 if ($dir) {
4781 //print "Process user id ".$fuser->id."<br>\n";
4782 $origin = $dir.'/'.get_exdir($fuser->id, 2, 0, 1, $fuser, 'user'); // Use old behaviour to get x/y path
4783 $destin = $dir.'/'.$fuser->id;
4784
4785 $origin_osencoded = dol_osencode($origin);
4786
4787 dol_mkdir($destin);
4788
4789 //echo '<hr>'.$origin.' -> '.$destin;
4790 if (dol_is_dir($origin)) {
4791 $handle = opendir($origin_osencoded);
4792 if (is_resource($handle)) {
4793 while (($file = readdir($handle)) !== false) {
4794 if ($file == '.' || $file == '..') {
4795 continue;
4796 }
4797
4798 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4799 $thumbs = opendir($origin_osencoded.'/'.$file);
4800 if (is_resource($thumbs)) {
4801 dol_mkdir($destin.'/'.$file);
4802 while (($thumb = readdir($thumbs)) !== false) {
4803 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4804 if ($thumb == '.' || $thumb == '..') {
4805 continue;
4806 }
4807
4808 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4809 print '.';
4810 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4811 //var_dump('aaa');exit;
4812 }
4813 }
4814 // dol_delete_dir($origin.'/'.$file);
4815 }
4816 } else { // it is a file
4817 if (!dol_is_file($destin.'/'.$file)) {
4818 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4819 print '.';
4820 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4821 //var_dump('eee');exit;
4822 }
4823 }
4824 }
4825 }
4826 }
4827 }
4828 }
4829 }
4830
4831 print '</td></tr>';
4832}
4833
4840{
4841 global $db, $langs, $user;
4842
4843 print '<tr><td colspan="4">';
4844
4845 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4846
4847 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4848 $fuser = new User($db);
4849 if (!is_object($user)) {
4850 $user = $fuser; // To avoid error during migration
4851 }
4852
4853 $sql = "SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX."user"; // Get list of all users
4854 $resql = $db->query($sql);
4855 if ($resql) {
4856 while ($obj = $db->fetch_object($resql)) {
4857 //$fuser->fetch($obj->uid);
4858 $fuser->id = $obj->uid;
4859 $fuser->entity = $obj->entity;
4860 $fuser->photo = $obj->photo;
4861
4862 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4863 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4864 if ($entity > 1) {
4865 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4866 } else {
4867 $dir = DOL_DATA_ROOT.'/users';
4868 }
4869
4870 if ($dir) {
4871 //print "Process user id ".$fuser->id."<br>\n";
4872 $origin = $dir.'/'.$fuser->id;
4873 $destin = $dir.'/'.$fuser->id.'/photos';
4874
4875 $origin_osencoded = dol_osencode($origin);
4876
4877 dol_mkdir($destin);
4878
4879 //echo '<hr>'.$origin.' -> '.$destin;
4880 if (dol_is_dir($origin)) {
4881 $handle = opendir($origin_osencoded);
4882 if (is_resource($handle)) {
4883 while (($file = readdir($handle)) !== false) {
4884 if ($file == '.' || $file == '..' || $file == 'photos') {
4885 continue;
4886 }
4887 if (!empty($fuser->photo) && ($file != $fuser->photo && $file != 'thumbs')) {
4888 continue;
4889 }
4890
4891 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4892 $thumbs = opendir($origin_osencoded.'/'.$file);
4893 if (is_resource($thumbs)) {
4894 dol_mkdir($destin.'/'.$file);
4895 while (($thumb = readdir($thumbs)) !== false) {
4896 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4897 if ($thumb == '.' || $thumb == '..') {
4898 continue;
4899 }
4900
4901 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4902 print '.';
4903 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4904 }
4905 }
4906 // dol_delete_dir($origin.'/'.$file);
4907 }
4908 } else { // it is a file
4909 if (!dol_is_file($destin.'/'.$file)) {
4910 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4911 print '.';
4912 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4913 }
4914 }
4915 }
4916 }
4917 }
4918 }
4919 }
4920 }
4921
4922 print '</td></tr>';
4923}
4924
4925
4926
4933{
4934 global $conf, $db, $langs;
4935
4936 print '<tr class="trforrunsql"><td>';
4937
4938 print '<b>'.$langs->trans('MigrationHolidayPath')."</b><br>\n";
4939
4940 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
4941 $holiday = new Holiday($db);
4942
4943 $sql = "SELECT rowid as uid, ref, entity from ".MAIN_DB_PREFIX."holiday"; // Get list of all holiday
4944
4945 $resql = $db->query($sql);
4946 if ($resql) {
4947 while ($obj = $db->fetch_object($resql)) {
4948 //$holiday->fetch($obj->uid);
4949 $holiday->id = $obj->uid;
4950 $holiday->ref = $obj->ref;
4951 $holiday->entity = $obj->entity;
4952
4953 //echo '<hr>'.$holiday->id.' -> '.$holiday->entity;
4954 $entity = (empty($holiday->entity) ? 1 : $holiday->entity);
4955 if ($entity > 1) {
4956 $dir = DOL_DATA_ROOT.'/'.$entity.'/holiday';
4957 } else {
4958 $dir = $conf->holiday->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4959 }
4960
4961 if ($dir) {
4962 //print "Process holiday id ".$holiday->id."<br>\n";
4963 $origin = $dir.'/'.get_exdir($holiday->id, 2, 0, 1, $holiday, 'holiday'); // Use old behaviour to get x/y path
4964 $destin = $dir.'/'.$holiday->ref;
4965
4966 $origin_osencoded = dol_osencode($origin);
4967
4968 dol_mkdir($destin);
4969
4970 //echo $origin.' -> '.$destin."<br>\n";
4971 if (dol_is_dir($origin)) {
4972 $handle = opendir($origin_osencoded);
4973 if (is_resource($handle)) {
4974 while (($file = readdir($handle)) !== false) {
4975 if ($file == '.' || $file == '..') {
4976 continue;
4977 }
4978
4979 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4980 $thumbs = opendir($origin_osencoded.'/'.$file);
4981 if (is_resource($thumbs)) {
4982 dol_mkdir($destin.'/'.$file);
4983 while (($thumb = readdir($thumbs)) !== false) {
4984 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4985 if ($thumb == '.' || $thumb == '..') {
4986 continue;
4987 }
4988
4989 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4990 print '.';
4991 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4992 //var_dump('aaa');exit;
4993 }
4994 }
4995 // dol_delete_dir($origin.'/'.$file);
4996 }
4997 } else { // it is a file
4998 if (!dol_is_file($destin.'/'.$file)) {
4999 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
5000 print '.';
5001 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
5002 }
5003 }
5004 }
5005 }
5006 }
5007 }
5008 }
5009 }
5010
5011 print '</td></tr>';
5012}
5013
5014
5015/* TODO: Modify the Paid status and `fk_facture` of the invoices paid in full
5016
5017Lookup incorrect invoices:
5018select 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
5019having f.total_ttc = sum(pf.amount)
5020
5021Correct the incorrect invoices:
5022update llx_facture set paye=1, fk_statut=2 where close_code is null
5023and rowid in (...)
5024*/
5025
5033{
5034 global $db, $langs;
5035 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5036 $error = 0;
5037 $db->begin();
5038 print '<tr><td colspan="4">';
5039 $sql = 'SELECT rowid, socialnetworks';
5040 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE';
5041 $sql .= " skype IS NOT NULL OR skype <> ''";
5042 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5043 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5044 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5045 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5046 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5047 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5048 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5049 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5050
5051 $resql = $db->query($sql);
5052 if ($resql) {
5053 while ($obj = $db->fetch_object($resql)) {
5054 $arraysocialnetworks = array();
5055 if (!empty($obj->skype)) {
5056 $arraysocialnetworks['skype'] = $obj->skype;
5057 }
5058 if (!empty($obj->twitter)) {
5059 $arraysocialnetworks['twitter'] = $obj->twitter;
5060 }
5061 if (!empty($obj->facebook)) {
5062 $arraysocialnetworks['facebook'] = $obj->facebook;
5063 }
5064 if (!empty($obj->linkedin)) {
5065 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5066 }
5067 if (!empty($obj->instagram)) {
5068 $arraysocialnetworks['instagram'] = $obj->instagram;
5069 }
5070 if (!empty($obj->snapchat)) {
5071 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5072 }
5073 if (!empty($obj->googleplus)) {
5074 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5075 }
5076 if (!empty($obj->youtube)) {
5077 $arraysocialnetworks['youtube'] = $obj->youtube;
5078 }
5079 if (!empty($obj->whatsapp)) {
5080 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5081 }
5082 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5083 $obj->socialnetworks = '[]';
5084 }
5085 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5086 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5087 $sqlupd .= ', skype=null';
5088 $sqlupd .= ', twitter=null';
5089 $sqlupd .= ', facebook=null';
5090 $sqlupd .= ', linkedin=null';
5091 $sqlupd .= ', instagram=null';
5092 $sqlupd .= ', snapchat=null';
5093 $sqlupd .= ', googleplus=null';
5094 $sqlupd .= ', youtube=null';
5095 $sqlupd .= ', whatsapp=null';
5096 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5097
5098 $resqlupd = $db->query($sqlupd);
5099 if (!$resqlupd) {
5101 $error++;
5102 }
5103 }
5104 } else {
5105 $error++;
5106 }
5107 if (!$error) {
5108 $db->commit();
5109 } else {
5111 $db->rollback();
5112 }
5113 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."</b><br>\n";
5114 print '</td></tr>';
5115}
5116
5124{
5125 global $db, $langs;
5126
5127 print '<tr><td colspan="4">';
5128 $error = 0;
5129 $db->begin();
5130 print '<tr><td colspan="4">';
5131 $sql = 'SELECT rowid, socialnetworks';
5132 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE ';
5133 $sql .= " skype IS NOT NULL OR skype <> ''";
5134 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5135 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5136 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5137 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5138 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5139 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5140 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5141 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5142 //print $sql;
5143 $resql = $db->query($sql);
5144 if ($resql) {
5145 while ($obj = $db->fetch_object($resql)) {
5146 $arraysocialnetworks = array();
5147 if (!empty($obj->skype)) {
5148 $arraysocialnetworks['skype'] = $obj->skype;
5149 }
5150 if (!empty($obj->twitter)) {
5151 $arraysocialnetworks['twitter'] = $obj->twitter;
5152 }
5153 if (!empty($obj->facebook)) {
5154 $arraysocialnetworks['facebook'] = $obj->facebook;
5155 }
5156 if (!empty($obj->linkedin)) {
5157 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5158 }
5159 if (!empty($obj->instagram)) {
5160 $arraysocialnetworks['instagram'] = $obj->instagram;
5161 }
5162 if (!empty($obj->snapchat)) {
5163 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5164 }
5165 if (!empty($obj->googleplus)) {
5166 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5167 }
5168 if (!empty($obj->youtube)) {
5169 $arraysocialnetworks['youtube'] = $obj->youtube;
5170 }
5171 if (!empty($obj->whatsapp)) {
5172 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5173 }
5174 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5175 $obj->socialnetworks = '[]';
5176 }
5177 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5178 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5179 $sqlupd .= ', skype=null';
5180 $sqlupd .= ', twitter=null';
5181 $sqlupd .= ', facebook=null';
5182 $sqlupd .= ', linkedin=null';
5183 $sqlupd .= ', instagram=null';
5184 $sqlupd .= ', snapchat=null';
5185 $sqlupd .= ', googleplus=null';
5186 $sqlupd .= ', youtube=null';
5187 $sqlupd .= ', whatsapp=null';
5188 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5189 //print $sqlupd."<br>";
5190 $resqlupd = $db->query($sqlupd);
5191 if (!$resqlupd) {
5193 $error++;
5194 }
5195 }
5196 } else {
5197 $error++;
5198 }
5199 if (!$error) {
5200 $db->commit();
5201 } else {
5203 $db->rollback();
5204 }
5205 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."</b><br>\n";
5206 print '</td></tr>';
5207}
5208
5216{
5217 global $db, $langs;
5218 // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5219 $error = 0;
5220 $db->begin();
5221 print '<tr><td colspan="4">';
5222 $sql = 'SELECT rowid, socialnetworks';
5223 $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE';
5224 $sql .= " jabberid IS NOT NULL OR jabberid <> ''";
5225 $sql .= " OR skype IS NOT NULL OR skype <> ''";
5226 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5227 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5228 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5229 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5230 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5231 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5232 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5233 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5234 //print $sql;
5235 $resql = $db->query($sql);
5236 if ($resql) {
5237 while ($obj = $db->fetch_object($resql)) {
5238 $arraysocialnetworks = array();
5239 if (!empty($obj->jabberid)) {
5240 $arraysocialnetworks['jabber'] = $obj->jabberid;
5241 }
5242 if (!empty($obj->skype)) {
5243 $arraysocialnetworks['skype'] = $obj->skype;
5244 }
5245 if (!empty($obj->twitter)) {
5246 $arraysocialnetworks['twitter'] = $obj->twitter;
5247 }
5248 if (!empty($obj->facebook)) {
5249 $arraysocialnetworks['facebook'] = $obj->facebook;
5250 }
5251 if (!empty($obj->linkedin)) {
5252 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5253 }
5254 if (!empty($obj->instagram)) {
5255 $arraysocialnetworks['instagram'] = $obj->instagram;
5256 }
5257 if (!empty($obj->snapchat)) {
5258 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5259 }
5260 if (!empty($obj->googleplus)) {
5261 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5262 }
5263 if (!empty($obj->youtube)) {
5264 $arraysocialnetworks['youtube'] = $obj->youtube;
5265 }
5266 if (!empty($obj->whatsapp)) {
5267 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5268 }
5269 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5270 $obj->socialnetworks = '[]';
5271 }
5272 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5273 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5274 $sqlupd .= ', jabberid=null';
5275 $sqlupd .= ', skype=null';
5276 $sqlupd .= ', twitter=null';
5277 $sqlupd .= ', facebook=null';
5278 $sqlupd .= ', linkedin=null';
5279 $sqlupd .= ', instagram=null';
5280 $sqlupd .= ', snapchat=null';
5281 $sqlupd .= ', googleplus=null';
5282 $sqlupd .= ', youtube=null';
5283 $sqlupd .= ', whatsapp=null';
5284 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5285 //print $sqlupd."<br>";
5286 $resqlupd = $db->query($sqlupd);
5287 if (!$resqlupd) {
5289 $error++;
5290 }
5291 }
5292 } else {
5293 $error++;
5294 }
5295 if (!$error) {
5296 $db->commit();
5297 } else {
5299 $db->rollback();
5300 }
5301 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."</b><br>\n";
5302 print '</td></tr>';
5303}
5304
5312{
5313 global $db, $langs;
5314 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5315 $error = 0;
5316 $db->begin();
5317 print '<tr><td colspan="4">';
5318 $sql = 'SELECT rowid, socialnetworks';
5319 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE ';
5320 $sql .= " skype IS NOT NULL OR skype <> ''";
5321 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5322 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5323 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5324 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5325 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5326 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5327 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5328 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5329
5330 $resql = $db->query($sql);
5331 if ($resql) {
5332 while ($obj = $db->fetch_object($resql)) {
5333 $arraysocialnetworks = array();
5334 if (!empty($obj->skype)) {
5335 $arraysocialnetworks['skype'] = $obj->skype;
5336 }
5337 if (!empty($obj->twitter)) {
5338 $arraysocialnetworks['twitter'] = $obj->twitter;
5339 }
5340 if (!empty($obj->facebook)) {
5341 $arraysocialnetworks['facebook'] = $obj->facebook;
5342 }
5343 if (!empty($obj->linkedin)) {
5344 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5345 }
5346 if (!empty($obj->instagram)) {
5347 $arraysocialnetworks['instagram'] = $obj->instagram;
5348 }
5349 if (!empty($obj->snapchat)) {
5350 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5351 }
5352 if (!empty($obj->googleplus)) {
5353 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5354 }
5355 if (!empty($obj->youtube)) {
5356 $arraysocialnetworks['youtube'] = $obj->youtube;
5357 }
5358 if (!empty($obj->whatsapp)) {
5359 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5360 }
5361 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5362 $obj->socialnetworks = '[]';
5363 }
5364 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5365 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5366 $sqlupd .= ', skype=null';
5367 $sqlupd .= ', twitter=null';
5368 $sqlupd .= ', facebook=null';
5369 $sqlupd .= ', linkedin=null';
5370 $sqlupd .= ', instagram=null';
5371 $sqlupd .= ', snapchat=null';
5372 $sqlupd .= ', googleplus=null';
5373 $sqlupd .= ', youtube=null';
5374 $sqlupd .= ', whatsapp=null';
5375 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5376 //print $sqlupd."<br>";
5377 $resqlupd = $db->query($sqlupd);
5378 if (!$resqlupd) {
5380 $error++;
5381 }
5382 }
5383 } else {
5384 $error++;
5385 }
5386 if (!$error) {
5387 $db->commit();
5388 } else {
5390 $db->rollback();
5391 }
5392 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."</b><br>\n";
5393 print '</td></tr>';
5394}
5395
5396
5403function migrate_export_import_profiles($mode = 'export')
5404{
5405 global $db, $langs;
5406
5407 $error = 0;
5408 $resultstring = '';
5409
5410 $db->begin();
5411
5412 print '<tr class="trforrunsql"><td colspan="4">';
5413 $sql = 'SELECT rowid, field';
5414 if ($mode == 'export') {
5415 $sql .= ', filter';
5416 }
5417 $sql .= ' FROM '.MAIN_DB_PREFIX.$mode.'_model WHERE';
5418 $sql .= " type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5419 //print $sql;
5420 $resql = $db->query($sql);
5421 if ($resql) {
5422 while ($obj = $db->fetch_object($resql)) {
5423 $oldfield = $obj->field;
5424 $newfield = str_replace(array(',f.facnumber', 'f.facnumber,', 'f.total,', 'f.tva,'), array(',f.ref', 'f.ref,', 'f.total_ht,', 'f.total_tva,'), $oldfield);
5425
5426 if ($mode == 'export') {
5427 $oldfilter = $obj->filter;
5428 $newfilter = str_replace(array('f.facnumber=', 'f.total=', 'f.tva='), array('f.ref=', 'f.total_ht=', 'f.total_tva='), $oldfilter);
5429 } else {
5430 $oldfilter = '';
5431 $newfilter = '';
5432 }
5433
5434 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5435 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX.$mode."_model SET field = '".$db->escape($newfield)."'";
5436 if ($mode == 'export') {
5437 $sqlupd .= ", filter = '".$db->escape($newfilter)."'";
5438 }
5439 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5440 $resultstring .= '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd."</td></tr>\n";
5441 $resqlupd = $db->query($sqlupd);
5442 if (!$resqlupd) {
5444 $error++;
5445 }
5446 }
5447 }
5448 } else {
5449 $error++;
5450 }
5451 if (!$error) {
5452 $db->commit();
5453 } else {
5455 $db->rollback();
5456 }
5457 print '<b>'.$langs->trans('MigrationImportOrExportProfiles', $mode)."</b><br>\n";
5458 print '</td></tr>';
5459
5460 if ($resultstring) {
5461 print $resultstring;
5462 } else {
5463 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5464 }
5465}
5466
5473{
5474 global $db, $langs;
5475
5476 $error = 0;
5477 $resultstring = '';
5478
5479 $db->begin();
5480 print '<tr class="trforrunsql"><td colspan="4">';
5481 print '<b>'.$langs->trans('MigrationContractLineRank')."</b><br>\n";
5482
5483 $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";
5484 $sql .= " ORDER BY c.rowid,cd.rowid";
5485
5486 $resql = $db->query($sql);
5487 if ($resql) {
5488 $currentRank = 0;
5489 $current_contract = 0;
5490 while ($obj = $db->fetch_object($resql)) {
5491 if (empty($current_contract) || $current_contract == $obj->cid) {
5492 $currentRank++;
5493 } else {
5494 $currentRank = 1;
5495 }
5496
5497 $sqlUpd = "UPDATE ".$db->prefix()."contratdet SET rang=".(int) $currentRank." WHERE rowid=".(int) $obj->cdid;
5498 $resultstring = '.';
5499 print $resultstring;
5500 $resqlUpd = $db->query($sqlUpd);
5501 if (!$resqlUpd) {
5503 $error++;
5504 }
5505
5506 $current_contract = $obj->cid;
5507 }
5508 } else {
5509 $error++;
5510 }
5511 if (!$error) {
5512 $db->commit();
5513 } else {
5514 $db->rollback();
5515 }
5516
5517 print '</td></tr>';
5518
5519 if (!$resultstring) {
5520 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5521 }
5522}
5523
5530{
5531 global $db, $langs;
5532
5533 $lock = getDolGlobalInt('MIGRATION_FLAG_INVOICE_MODELS_V20');
5534
5535 $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5536 $migrationNeeded = (versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5537
5538 print '<tr class="trforrunsql"><td colspan="4">';
5539 print '<b>'.$langs->trans('InvoiceExportModelsMigration')."</b>: \n";
5540
5541 if (! $migrationNeeded) {
5542 print $langs->trans("AlreadyDone");
5543 print '</td></tr>';
5544 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5545 return;
5546 }
5547
5548
5549 $db->begin();
5550
5551 $sql1 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5552
5553 $resql1 = $db->query($sql1);
5554
5555 if (! $resql1) {
5557 $db->rollback();
5558 print '</td></tr>';
5559 return;
5560 }
5561
5562 $modified1 = $db->affected_rows($resql1);
5563
5564 print str_repeat('.', $modified1);
5565
5566 $db->free($resql1);
5567
5568 $sql2 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5569
5570 $resql2 = $db->query($sql2);
5571
5572 if (! $resql2) {
5574 $db->rollback();
5575 print '</td></tr>';
5576 return;
5577 }
5578
5579 $modified2 = $db->affected_rows($resql2);
5580
5581 print str_repeat('.', $modified2);
5582
5583 $db->free($resql2);
5584
5585 if (empty($modified1 + $modified2)) {
5586 print $langs->trans('NothingToDo');
5587 }
5588
5589 $db->commit();
5590
5591 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5592
5593 echo '</td></tr>';
5594}
5595
5603{
5604 global $db, $langs;
5605
5606 $error = 0;
5607 $resultstring = '';
5608 $bookKeepingAddon = '';
5609
5610 // For the moment we set the numbering rule to neon (the rule argon has a lot of critical bugs to fix first).
5611 if (getDolGlobalString('BOOKKEEPING_ADDON') == '') {
5612 dolibarr_set_const($db, 'BOOKKEEPING_ADDON', 'mod_bookkeeping_neon', 'chaine', 0, '', $entity);
5613 $bookKeepingAddon = 'mod_bookkeeping_neon';
5614 }
5615
5616 print '<tr class="trforrunsql"><td colspan="4">';
5617 print '<b>'.$langs->trans('MigrationAccountancyBookkeeping')."</b><br>\n";
5618
5619 // TODO
5620 if ($bookKeepingAddon === 'mod_bookkeeping_argon') {
5621 $db->begin();
5622
5623 $sql = "SELECT DISTINCT YEAR(doc_date) as doc_year, MONTH(doc_date) as doc_month, code_journal, piece_num FROM ".$db->prefix()."accounting_bookkeeping";
5624 $sql .= " WHERE ref IS NULL AND entity = ".((int) $entity);
5625 $sql .= " ORDER BY doc_year, doc_month, code_journal, piece_num";
5626
5627 $resql = $db->query($sql);
5628
5629 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
5630 $bookkeeping = new BookKeeping($db);
5631 if ($resql) {
5632 while ($obj = $db->fetch_object($resql)) {
5633 $bookkeeping->doc_date = dol_mktime(0, 0, 0, $obj->doc_month, 1, $obj->doc_year);
5634 $bookkeeping->code_journal = $obj->code_journal;
5635 $ref = $bookkeeping->getNextNumRef();
5636
5637 $sqlUpd = "UPDATE ".$db->prefix()."accounting_bookkeeping SET ref = '".$db->escape($ref)."' WHERE piece_num = '".$db->escape($obj->piece_num)."' AND entity = ".((int) $entity);
5638 $resultstring = '.';
5639 print $resultstring;
5640 $resqlUpd = $db->query($sqlUpd);
5641 if (!$resqlUpd) {
5643 $error++;
5644 }
5645 }
5646 } else {
5647 $error++;
5648 }
5649
5650 if (!$error) {
5651 $db->commit();
5652 } else {
5653 $db->rollback();
5654 }
5655 }
5656
5657 print '</td></tr>';
5658
5659 if (!$resultstring) {
5660 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5661 }
5662}
5663
5670{
5671 global $conf, $db, $langs;
5672
5673 print '<tr class="trforrunsql"><td colspan="4">';
5674 print '<b>'.$langs->trans('MigrationApiRestTokens')."</b>:\n";
5675
5676 $error = 0;
5677 $nbofmigration = 0;
5678 $allexistingtokens = array();
5679
5680 $db->begin();
5681
5682 $sqlforalltokens = "SELECT oat.tokenstring";
5683 $sqlforalltokens .= " FROM ".$db->prefix()."oauth_token AS oat";
5684 $sqlforalltokens .= " WHERE oat.service = 'dolibarr_rest_api'";
5685
5686 $resalltoken = $db->query($sqlforalltokens);
5687
5688 if ($resalltoken) {
5689 while ($tokenobj = $db->fetch_object($resalltoken)) {
5690 $allexistingtokens[] = dolDecrypt($tokenobj->tokenstring);
5691 }
5692 } else {
5693 $error++;
5695 $db->rollback();
5696 }
5697
5698 if (!$error) {
5699 $sql = "SELECT 'dolibarr_rest_api' AS service, u.api_key AS tokenstring, u.rowid AS fk_user, u.entity";
5700 $sql .= " FROM llx_user AS u";
5701 $sql .= " WHERE u.api_key IS NOT NULL AND u.api_key <> ''";
5702
5703 $result = $db->query($sql);
5704
5705 if ($result) {
5706 $tmpuser = new User($db);
5707
5708 while ($obj = $db->fetch_object($result)) {
5709 if (!in_array(dolDecrypt($obj->tokenstring), $allexistingtokens)) {
5710 // Load the object of the user of token so we can get the API_COUNT_CALL
5711 unset($tmpuser->conf);
5712 $tmpuser->conf = new stdClass();
5713 $tmpuser->fetch((int) $obj->fk_user, '', '', 1, ($obj->entity ? $obj->entity : $conf->entity));
5714
5715 $sqlforinsert = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, tokenstring, fk_user, datec, entity, apicount_total)";
5716 $sqlforinsert .= " VALUES ('".$db->escape($obj->service)."', '".$db->escape(dolEncrypt(dolDecrypt($obj->tokenstring)))."', ";
5717 $sqlforinsert .= ((int) $obj->fk_user).", '".$db->idate(dol_now())."', ".((int) $obj->entity).", ";
5718 $sqlforinsert .= getDolUserInt('API_COUNT_CALL', 0, $tmpuser);
5719 $sqlforinsert .= ")";
5720
5721 $insertresult = $db->query($sqlforinsert);
5722 if (!$insertresult) {
5723 $error++;
5725 } else {
5726 $nbofmigration++;
5727 }
5728 }
5729 }
5730
5731 if (!$error) {
5732 $db->commit();
5733 } else {
5734 $db->rollback();
5735 }
5736 } else {
5738 $db->rollback();
5739 }
5740 }
5741
5742 if (!$nbofmigration) {
5743 print $langs->trans("NothingToDo")."\n";
5744 } else {
5745 print $langs->trans('MigratedTokens', $nbofmigration);
5746 }
5747 print '</td></tr>';
5748}
5749
5750
5759{
5760 global $conf, $db, $langs;
5761
5762 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
5763 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
5764
5765 print '<tr class="trforrunsql"><td colspan="4">';
5766 print '<b>'.$langs->trans('InitAHMACKeyForBlockedLog')."</b>:\n";
5767
5768 $db->begin();
5769
5770 // Create HMAC if it does not exists yet
5771 $hmac_encoded_secret_key = getDolGlobalString('BLOCKEDLOG_HMAC_KEY');
5772 if (empty($hmac_encoded_secret_key)) {
5773 // Add key
5774 $randomsecret = bin2hex(random_bytes(32)); // 64 char hex - 256 bits
5775
5776 $hmac_secret_key = 'BLOCKEDLOGHMAC'.$randomsecret; // Example: 'BLOCKEDLOGHMACY3Ewx37RXbSd8gL9JV8p7Wqw7qvq2K2A'
5777
5778 $result = dolibarr_set_const($db, 'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key, 'chaine', 0, 'The secret key for HMAC used for blockedlog record', $conf->entity); // Will encrypt the value using dolCrypt and store it.
5779
5780 if ($result < 0) {
5782 $db->rollback();
5783
5784 print '</td></tr>';
5785 return -1;
5786 }
5787
5788 print $langs->trans('Done');
5789 } else {
5790 // Decode the HMAC key
5791 $hmac_secret_key = dolDecrypt($hmac_encoded_secret_key);
5792
5793 if (! preg_match('/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
5794 print 'Error: Failed to decode the crypted value of the parameter BLOCKEDLOG_HMAC_KEY using the $dolibarr_main_crypt_key. A value was found in config parameters in database but decoding failed. May be the database data were restored onto another environment and the coding/decoding key $dolibarr_main_dolcrypt_key was not restored with the same value in conf.php file.';
5795 print 'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.';
5796 print 'If you don\'t use the Unalterable Log module, you can also remove the BLOCKEDLOG_HMAC_KEY entry from llx_const table. If you use the Unalterable Log, this is not possible because this will invalidate all past record.';
5797 $db->rollback();
5798
5799 print '</td></tr>';
5800 return -1;
5801 }
5802
5803 print $langs->trans("NothingToDo")."\n";
5804 }
5805
5806 $db->commit();
5807
5808 print '</td></tr>';
5809 return 1;
5810}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:72
migrate_blockedlog_add_end_file()
Migrate an old database to add the .end flag.
Class to manage Blocked Log.
Class to manage Ledger (General Ledger and Subledger)
Class to manage line orders.
Class to manage lines of contracts.
Class to manage invoices.
Class to manage invoice lines.
Class of the module paid holiday.
Class to manage hooks.
Parent class for log handlers.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage order lines.
Class with list of lots and properties.
Class to manage commercial proposal lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$conffile
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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:551
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:645
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:709
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:90
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:489
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.
migrate_supplier_prices_permissions($db, $langs, $conf)
Grant the "supplier prices" advanced permissions introduced in 23.0 (product/service read_supplier_pr...
if($db !==null && $db->connected) if( $ret migrate_paiements)($db, $langs, $conf)
Records payment links for an invoice in a join table (link n<-->n for payments<-->invoices)
Definition upgrade2.php:941
migrate_links_transfert($db, $langs, $conf)
Function to migrate links into llx_bank_url.
migrate_paiements_orphelins_1($db, $langs, $conf)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: select...
migrate_user_rights_entity($db, $langs, $conf)
Migrate to add entity value into llx_user_rights.
migrate_reload_modules($db, $langs, $conf, $listofmodule=array(), $force=0)
Disable/Re-enable features modules.
migrate_contracts_date3($db, $langs, $conf)
Mise a jour des dates de creation de contrat.
migrate_restore_missing_links($db, $langs, $conf)
Migration du champ fk_remise_except dans llx_facturedet doit correspondre a Link in llx_societe_remis...
migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
Migration directory.
migrate_project_task_actors($db, $langs, $conf)
Migration de la table llx_projet_task_actors vers llx_element_contact.
migrate_holiday_path()
Migrate file from old path to new one for users.
migrate_commande_deliveryaddress($db, $langs, $conf)
Migration du champ fk_adresse_livraison dans expedition 2.6 -> 2.7.
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)
Reopen the contracts that have at least one line that is not closed (/completed).
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_accountingbookkeeping(int $entity)
Migrate Ref in bookkeeping lines.
migrate_price_propal($db, $langs, $conf)
Update total of proposal lines.
migrate_stocks($db, $langs, $conf)
Migration of the stock field in the Products table.
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)
Migrate the Order Details in the Delivery Details.
migrate_remise_except_entity($db, $langs, $conf)
Migrate to add entity value into llx_societe_remise_except.
migrate_paiements_orphelins_2($db, $langs, $conf)
Repair orphan payments (lost relations due to bugs) Query to check if there are still orphans: select...
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)
Update the contracts (Contract Management + Contract Detail)
migrate_get_rights_def_id($db, $module, $perms, $subperms)
Return the permission id (llx_rights_def.id) matching a module/perms/subperms triplet,...
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)
Relations between the Shipping and Client Order in the table llx_co_exp.
migrate_actioncomm_element($db, $langs, $conf)
Migrate link stored into fk_xxxx into fk_element and elementtype.
migrate_blockedlog_add_hmac_key()
Add the HMAC key for blockedlog v2+ Note that this is used on old version only.
migrate_productlot_path()
Migrate file from old path to new one for lot path.
migrate_user_photospath()
Migrate file from old path to new one for users.
migrate_invoice_export_models()
Invoice exports been shifted (facture_1 => facture_0, facture_2 => facture_1) in version 20,...
migrate_thirdparties_socialnetworks()
Migrate thirdparties fields facebook and co to socialnetworks Can be called only when version is 10....
migrate_event_assignement($db, $langs, $conf)
Migrate event assignment to owner.
migrate_clean_association($db, $langs, $conf)
Delete duplicates in table categorie_association.
migrate_commande_livraison($db, $langs, $conf)
Correspondence of the deliveries and the Customer Orders in the table llx_co_liv.
migrate_event_assignement_contact($db, $langs, $conf)
Migrate event assignment to owner.
migrate_contracts_date1($db, $langs, $conf)
Update missing Contract Dates.
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.
migrate_apiresttokens()
Migrate API key in oauth_token table.