dolibarr 24.0.0-beta
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',
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 // Reload menus (this must be always done, and only into last targeted version)
739 // This reload the auguria menu.To reload a dynamic menu defined into module descriptor, see previours step
740 $result = migrate_reload_menu($db, $langs, $conf);
741 if ($result < 0) {
742 $error++;
743 }
744 }
745
746 // Can force activation of some module during migration with parameter 'enablemodules=MAIN_MODULE_XXX,MAIN_MODULE_YYY,...'
747 // In most cases (online install or upgrade) $enablemodules is empty. Can be forced when ran from command line.
748 if (!$error && $enablemodules) {
749 // Reload modules (this must be always done and only into last targeted version)
750 $listofmodules = array();
751 $enablemodules = preg_replace('/enablemodules=/', '', $enablemodules);
752 $tmplistofmodules = explode(',', $enablemodules);
753 foreach ($tmplistofmodules as $value) {
754 $listofmodules[$value] = 'forceactivate';
755 }
756
757 $resultreloadmodules = migrate_reload_modules($db, $langs, $conf, $listofmodules, 1);
758 if ($resultreloadmodules < 0) {
759 $error++;
760 }
761 }
762
763
764 // Can call a dedicated external upgrade process with hook doUpgradeAfterDB()
765 if (!$error) {
766 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
767 $object = new stdClass();
768 $action = "upgrade";
769 $reshook = $hookmanager->executeHooks('doUpgradeAfterDB', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
770 if ($hookmanager->resNbOfHooks > 0) {
771 if ($reshook < 0) {
772 print '<tr><td colspan="4">';
773 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
774 print $hookmanager->error;
775 print "<!-- (".$reshook.") -->";
776 print '</td></tr>';
777 } else {
778 print '<tr class="trforrunsql"><td colspan="4">';
779 print '<b>'.$langs->trans('UpgradeExternalModule').' (DB)</b>: <span class="ok">OK</span>';
780 print "<!-- (".$reshook.") -->";
781 print '</td></tr>';
782 }
783 } else {
784 //if (!empty($conf->modules))
785 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
786 print '<tr class="trforrunsql"><td colspan="4">';
787 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterDB");
788 print '</td></tr>';
789 }
790 }
791 }
792 }
793
794 print '</table>';
795
796 if (!$error) {
797 // Set constant to ask to remake a new ping to inform about upgrade (if ping was already done and OK)
798 $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
799 $db->query($sql, 1);
800 }
801
802 // We always commit.
803 // Process is designed so we can run it several times whatever is situation.
804 $db->commit();
805
806
807 /***************************************************************************************
808 *
809 * Migration of files
810 *
811 ***************************************************************************************/
812
813 foreach ($listofentities as $entity) {
814 // Set $conf context for entity
815 $conf->setEntityValues($db, $entity);
816 // Reset forced setup after the setValues
817 if (defined('SYSLOG_FILE')) {
818 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
819 }
820 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
821
822
823 // Copy directory medias
824 $srcroot = DOL_DOCUMENT_ROOT.'/install/medias';
825 $destroot = DOL_DATA_ROOT.'/medias';
826 dolCopyDir($srcroot, $destroot, '0', 0);
827
828
829 // Actions for all versions (no database change but delete some files and directories)
830 migrate_delete_old_files($db, $langs, $conf);
831 migrate_delete_old_dir($db, $langs, $conf);
832 // Actions for all versions (no database change but create some directories)
833 dol_mkdir(DOL_DATA_ROOT.'/bank');
834 // Actions for all versions (no database change but rename some directories)
835 migrate_rename_directories($db, $langs, $conf, '/banque/bordereau', '/bank/checkdeposits');
836
837
838 $parameters = array('versionfrom' => $versionfrom, 'versionto' => $versionto, 'conf' => $conf);
839 $object = new stdClass();
840 $action = "upgrade";
841 $reshook = $hookmanager->executeHooks('doUpgradeAfterFiles', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
842 if ($hookmanager->resNbOfHooks > 0) {
843 if ($reshook < 0) {
844 print '<tr><td colspan="4">';
845 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: ';
846 print $hookmanager->error;
847 print "<!-- (".$reshook.") -->";
848 print '</td></tr>';
849 } else {
850 print '<tr class="trforrunsql"><td colspan="4">';
851 print '<b>'.$langs->trans('UpgradeExternalModule').' (Files)</b>: <span class="ok">OK</span>';
852 print "<!-- (".$reshook.") -->";
853 print '</td></tr>';
854 }
855 } else {
856 //if (!empty($conf->modules))
857 if (!empty($conf->modules_parts['hooks'])) { // If there is at least one module with one hook, we show message to say nothing was done
858 print '<tr class="trforrunsql"><td colspan="4">';
859 print '<b>'.$langs->trans('UpgradeExternalModule').'</b>: '.$langs->trans("NodoUpgradeAfterFiles");
860 print '</td></tr>';
861 }
862 }
863 }
864
865 $db->close();
866
867 $silent = 0;
868 if (!$silent) {
869 print '<table width="100%">';
870 print '<tr><td style="width: 30%">'.$langs->trans("MigrationFinished").'</td>';
871 print '<td class="right">';
872 if ($error == 0) {
873 //print '<span class="ok">'.$langs->trans("OK").'</span> - '; // $error = 0 does not mean there is no error (error are not always trapped)
874 } else {
875 print '<span class="error">'.$langs->trans("Error").'</span> - ';
876 }
877
878 //if (!empty($conf->use_javascript_ajax)) { // use_javascript_ajax is not defined
879 print '<script type="text/javascript">
880 jQuery(document).ready(function() {
881 function init_trrunsql()
882 {
883 console.log("toggle .trforrunsql");
884 jQuery(".trforrunsql").toggle();
885 }
886 init_trrunsql();
887 jQuery(".trforrunsqlshowhide").click(function() {
888 init_trrunsql();
889 });
890 });
891 </script>';
892 print '<a class="reposition trforrunsqlshowhide" href="#">'.$langs->trans("ShowHideDetails").'</a>';
893 //}
894
895 print '</td></tr>'."\n";
896 print '</table>';
897 }
898
899 //print '<div><br>'.$langs->trans("MigrationFinished").'</div>';
900} else {
901 print '<div class="error">'.$langs->trans('ErrorWrongParameters').'</div>';
902 $error++;
903}
904
905$ret = 0;
906if ($error && isset($argv[1])) {
907 $ret = 1;
908}
909dolibarr_install_syslog("Exit ".$ret);
910
911dolibarr_install_syslog("--- upgrade2: end");
912pFooter($error ? 2 : 0, $setuplang);
913
914if ($db !== null && $db->connected) {
915 $db->close();
916}
917
918// Return code if ran from command line
919if ($ret) {
920 exit($ret);
921}
922
923
924
933function migrate_paiements($db, $langs, $conf)
934{
935 print '<tr><td colspan="4">';
936
937 print '<br>';
938 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
939
940 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
941 $obj = $db->fetch_object($result);
942 if ($obj) {
943 $sql = "SELECT p.rowid, p.fk_facture, p.amount";
944 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p";
945 $sql .= " WHERE p.fk_facture > 0";
946
947 $resql = $db->query($sql);
948 $row = array();
949 $num = 0;
950
951 dolibarr_install_syslog("upgrade2::migrate_paiements");
952 if ($resql) {
953 $i = 0;
954 $num = $db->num_rows($resql);
955
956 while ($i < $num) {
957 $obj = $db->fetch_object($resql);
958 $row[$i][0] = $obj->rowid;
959 $row[$i][1] = $obj->fk_facture;
960 $row[$i][2] = $obj->amount;
961 $i++;
962 }
963 } else {
965 }
966
967 if ($num) {
968 print $langs->trans('MigrationPaymentsNumberToUpdate', $num)."<br>\n";
969 $res = 0;
970 if ($db->begin()) {
971 $num = count($row);
972 for ($i = 0; $i < $num; $i++) {
973 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
974 $sql .= " VALUES (".((int) $row[$i][1]).",".((int) $row[$i][0]).",".((float) $row[$i][2]).")";
975
976 $res += $db->query($sql);
977
978 $sql = "UPDATE ".MAIN_DB_PREFIX."paiement SET fk_facture = 0 WHERE rowid = ".((int) $row[$i][0]);
979
980 $res += $db->query($sql);
981
982 print $langs->trans('MigrationProcessPaymentUpdate', $row[$i][0])."<br>\n";
983 }
984 }
985
986 if (is_array($row) && $res == (2 * count($row))) {
987 $db->commit();
988 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
989 } else {
990 $db->rollback();
991 print $langs->trans('MigrationUpdateFailed').'<br>';
992 }
993 } else {
994 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
995 }
996 } else {
997 print $langs->trans('MigrationPaymentsNothingToUpdate')."<br>\n";
998 }
999
1000 print '</td></tr>';
1001}
1002
1014{
1015 print '<tr><td colspan="4">';
1016
1017 print '<br>';
1018 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1019
1020 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1021 $obj = $db->fetch_object($result);
1022 if ($obj) {
1023 // All answer of this requests should have a parent into llx_paiement_facture
1024 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1025 $sql .= " bu2.url_id as socid";
1026 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1027 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1028 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank=bu2.fk_bank AND bu2.type = 'company')";
1029 $sql .= " WHERE pf.rowid IS NULL AND (p.rowid=bu.url_id AND bu.type='payment') AND bu.fk_bank = b.rowid";
1030 $sql .= " AND b.rappro = 1";
1031 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1032
1033 $resql = $db->query($sql);
1034
1035 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_1");
1036 $row = array();
1037 if ($resql) {
1038 $i = $j = 0;
1039 $num = $db->num_rows($resql);
1040
1041 while ($i < $num) {
1042 $obj = $db->fetch_object($resql);
1043 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1044 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1045 $row[$j]['pamount'] = $obj->pamount;
1046 $row[$j]['fk_bank'] = $obj->fk_bank;
1047 $row[$j]['bamount'] = $obj->bamount;
1048 $row[$j]['socid'] = $obj->socid;
1049 $row[$j]['datec'] = $obj->datec;
1050 $j++;
1051 }
1052 $i++;
1053 }
1054 } else {
1056 }
1057
1058 if (count($row)) {
1059 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 1).': '.count($row)."<br>\n";
1060 $db->begin();
1061
1062 $res = 0;
1063 $num = count($row);
1064 for ($i = 0; $i < $num; $i++) {
1065 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1066 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>';
1067 }
1068
1069 // Look for invoices without payment relations with the same amount and same comppany
1070 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1071 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1072 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1073 $sql .= " AND pf.fk_facture IS NULL";
1074 $sql .= " ORDER BY f.fk_statut";
1075 //print $sql.'<br>';
1076 $resql = $db->query($sql);
1077 if ($resql) {
1078 $num = $db->num_rows($resql);
1079 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1080 if ($num >= 1) {
1081 $obj = $db->fetch_object($resql);
1082 $facid = $obj->rowid;
1083
1084 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1085 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1086
1087 $res += $db->query($sql);
1088
1089 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1090 }
1091 } else {
1092 print 'ERROR';
1093 }
1094 }
1095
1096 if ($res > 0) {
1097 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1098 } else {
1099 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1100 }
1101
1102 $db->commit();
1103 } else {
1104 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1105 }
1106 } else {
1107 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1108 }
1109
1110 print '</td></tr>';
1111}
1112
1124{
1125 print '<tr><td colspan="4">';
1126
1127 print '<br>';
1128 print '<b>'.$langs->trans('MigrationPaymentsUpdate')."</b><br>\n";
1129
1130 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiement", "fk_facture");
1131 $obj = $db->fetch_object($result);
1132 if ($obj) {
1133 // Tous les enregistrements qui sortent de cette requete devrait avoir un pere dans llx_paiement_facture
1134 $sql = "SELECT DISTINCT p.rowid, p.datec, p.amount as pamount, bu.fk_bank, b.amount as bamount,";
1135 $sql .= " bu2.url_id as socid";
1136 $sql .= " FROM (".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."bank_url as bu, ".MAIN_DB_PREFIX."bank as b)";
1137 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON pf.fk_paiement = p.rowid";
1138 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu2 ON (bu.fk_bank = bu2.fk_bank AND bu2.type = 'company')";
1139 $sql .= " WHERE pf.rowid IS NULL AND (p.fk_bank = bu.fk_bank AND bu.type = 'payment') AND bu.fk_bank = b.rowid";
1140 $sql .= " AND (p.fk_facture = 0 OR p.fk_facture IS NULL)";
1141
1142 $resql = $db->query($sql);
1143
1144 dolibarr_install_syslog("upgrade2::migrate_paiements_orphelins_2");
1145 $row = array();
1146 if ($resql) {
1147 $i = $j = 0;
1148 $num = $db->num_rows($resql);
1149
1150 while ($i < $num) {
1151 $obj = $db->fetch_object($resql);
1152 if ($obj->pamount == $obj->bamount && $obj->socid) { // Pour etre sur d'avoir bon cas
1153 $row[$j]['paymentid'] = $obj->rowid; // paymentid
1154 $row[$j]['pamount'] = $obj->pamount;
1155 $row[$j]['fk_bank'] = $obj->fk_bank;
1156 $row[$j]['bamount'] = $obj->bamount;
1157 $row[$j]['socid'] = $obj->socid;
1158 $row[$j]['datec'] = $obj->datec;
1159 $j++;
1160 }
1161 $i++;
1162 }
1163 } else {
1165 }
1166
1167 $nberr = 0;
1168
1169 $num = count($row);
1170 if ($num) {
1171 print $langs->trans('OrphelinsPaymentsDetectedByMethod', 2).': '.count($row)."<br>\n";
1172 $db->begin();
1173
1174 $res = 0;
1175 for ($i = 0; $i < $num; $i++) {
1176 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') == 2) {
1177 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>';
1178 }
1179
1180 // Look for invoices without payment relations with the same amount and same comppany
1181 $sql = " SELECT DISTINCT f.rowid from ".MAIN_DB_PREFIX."facture as f";
1182 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
1183 $sql .= " WHERE f.fk_statut in (2,3) AND fk_soc = ".((int) $row[$i]['socid'])." AND total_ttc = ".((float) $row[$i]['pamount']);
1184 $sql .= " AND pf.fk_facture IS NULL";
1185 $sql .= " ORDER BY f.fk_statut";
1186 //print $sql.'<br>';
1187 $resql = $db->query($sql);
1188 if ($resql) {
1189 $num = $db->num_rows($resql);
1190 //print 'Nb of invoice found for this amount and company :'.$num.'<br>';
1191 if ($num >= 1) {
1192 $obj = $db->fetch_object($resql);
1193 $facid = $obj->rowid;
1194
1195 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount)";
1196 $sql .= " VALUES (".((int) $facid).",".((int) $row[$i]['paymentid']).", ".((float) $row[$i]['pamount']).")";
1197
1198 $res += $db->query($sql);
1199
1200 print $langs->trans('MigrationProcessPaymentUpdate', 'facid='.$facid.'-paymentid='.$row[$i]['paymentid'].'-amount='.$row[$i]['pamount'])."<br>\n";
1201 }
1202 } else {
1203 print 'ERROR';
1204 $nberr++;
1205 }
1206 }
1207
1208 if ($res > 0) {
1209 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1210 } else {
1211 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1212 }
1213
1214 $db->commit();
1215 } else {
1216 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1217 }
1218
1219 // Delete obsolete fields fk_facture
1220 $db->begin();
1221
1222 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiement DROP COLUMN fk_facture";
1223 $db->query($sql);
1224
1225 if (!$nberr) {
1226 $db->commit();
1227 } else {
1228 print 'ERROR';
1229 $db->rollback();
1230 }
1231 } else {
1232 print $langs->trans('MigrationPaymentsNothingUpdatable')."<br>\n";
1233 }
1234
1235 print '</td></tr>';
1236}
1237
1238
1247function migrate_contracts_det($db, $langs, $conf)
1248{
1249 print '<tr><td colspan="4">';
1250
1251 $nberr = 0;
1252
1253 print '<br>';
1254 print '<b>'.$langs->trans('MigrationContractsUpdate')."</b><br>\n";
1255
1256 $sql = "SELECT c.rowid as cref, c.date_contrat, c.statut, c.fk_product, c.fk_facture, c.fk_user_author,";
1257 $sql .= " p.ref, p.label, p.description, p.price, p.tva_tx, p.duration, cd.rowid";
1258 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c";
1259 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p";
1260 $sql .= " ON c.fk_product = p.rowid";
1261 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd";
1262 $sql .= " ON c.rowid=cd.fk_contrat";
1263 $sql .= " WHERE cd.rowid IS NULL AND p.rowid IS NOT NULL";
1264 $resql = $db->query($sql);
1265
1266 dolibarr_install_syslog("upgrade2::migrate_contracts_det");
1267 if ($resql) {
1268 $i = 0;
1269 $row = array();
1270 $num = $db->num_rows($resql);
1271
1272 if ($num) {
1273 print $langs->trans('MigrationContractsNumberToUpdate', $num)."<br>\n";
1274 $db->begin();
1275
1276 while ($i < $num) {
1277 $obj = $db->fetch_object($resql);
1278
1279 $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet (";
1280 $sql .= "fk_contrat, fk_product, statut, label, description,";
1281 $sql .= "date_ouverture_prevue, date_ouverture, date_fin_validite, tva_tx, qty,";
1282 $sql .= "subprice, price_ht, fk_user_author, fk_user_ouverture)";
1283 $sql .= " VALUES (";
1284 $sql .= ((int) $obj->cref).", ".($obj->fk_product ? ((int) $obj->fk_product) : 0).", ";
1285 $sql .= "0, ";
1286 $sql .= "'".$db->escape($obj->label)."', null, ";
1287 $sql .= ($obj->date_contrat ? "'".$db->idate($db->jdate($obj->date_contrat))."'" : "null").", ";
1288 $sql .= "null, ";
1289 $sql .= "null, ";
1290 $sql .= ((float) $obj->tva_tx).", 1, ";
1291 $sql .= ((float) $obj->price).", ".((float) $obj->price).", ".((int) $obj->fk_user_author).",";
1292 $sql .= "null";
1293 $sql .= ")";
1294
1295 if ($db->query($sql)) {
1296 print $langs->trans('MigrationContractsLineCreation', $obj->cref)."<br>\n";
1297 } else {
1299 $nberr++;
1300 }
1301
1302 $i++;
1303 }
1304
1305 if (!$nberr) {
1306 // $db->rollback();
1307 $db->commit();
1308 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1309 } else {
1310 $db->rollback();
1311 print $langs->trans('MigrationUpdateFailed').'<br>';
1312 }
1313 } else {
1314 print $langs->trans('MigrationContractsNothingToUpdate')."<br>\n";
1315 }
1316 } else {
1317 print $langs->trans('MigrationContractsFieldDontExist')."<br>\n";
1318 // dol_print_error($db);
1319 }
1320
1321 print '</td></tr>';
1322}
1323
1332function migrate_links_transfert($db, $langs, $conf)
1333{
1334 print '<tr><td colspan="4">';
1335
1336 $nberr = 0;
1337
1338 print '<br>';
1339 print '<b>'.$langs->trans('MigrationBankTransfertsUpdate')."</b><br>\n";
1340
1341 $sql = "SELECT ba.rowid as barowid, bb.rowid as bbrowid";
1342 $sql .= " FROM ".MAIN_DB_PREFIX."bank as bb, ".MAIN_DB_PREFIX."bank as ba";
1343 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = ba.rowid";
1344 $sql .= " WHERE ba.amount = -bb.amount AND ba.fk_account <> bb.fk_account";
1345 $sql .= " AND ba.datev = bb.datev AND ba.datec = bb.datec";
1346 $sql .= " AND bu.fk_bank IS NULL";
1347 $resql = $db->query($sql);
1348
1349 dolibarr_install_syslog("upgrade2::migrate_links_transfert");
1350 if ($resql) {
1351 $i = 0;
1352 $row = array();
1353 $num = $db->num_rows($resql);
1354
1355 if ($num) {
1356 print $langs->trans('MigrationBankTransfertsToUpdate', $num)."<br>\n";
1357 $db->begin();
1358
1359 while ($i < $num) {
1360 $obj = $db->fetch_object($resql);
1361
1362 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_url (";
1363 $sql .= "fk_bank, url_id, url, label, type";
1364 $sql .= ")";
1365 $sql .= " VALUES (";
1366 $sql .= $obj->barowid.",".$obj->bbrowid.", '/compta/bank/line.php?rowid=', '(banktransfert)', 'banktransfert'";
1367 $sql .= ")";
1368
1369 //print $sql.'<br>';
1370 dolibarr_install_syslog("migrate_links_transfert");
1371
1372 if (!$db->query($sql)) {
1374 $nberr++;
1375 }
1376
1377 $i++;
1378 }
1379
1380 if (!$nberr) {
1381 // $db->rollback();
1382 $db->commit();
1383 print $langs->trans('MigrationSuccessfullUpdate')."<br>";
1384 } else {
1385 $db->rollback();
1386 print $langs->trans('MigrationUpdateFailed').'<br>';
1387 }
1388 } else {
1389 print $langs->trans('MigrationBankTransfertsNothingToUpdate')."<br>\n";
1390 }
1391 } else {
1393 }
1394
1395 print '</td></tr>';
1396}
1397
1406function migrate_contracts_date1($db, $langs, $conf)
1407{
1408 print '<tr><td colspan="4">';
1409
1410 print '<br>';
1411 print '<b>'.$langs->trans('MigrationContractsEmptyDatesUpdate')."</b><br>\n";
1412
1413 $sql = "update ".MAIN_DB_PREFIX."contrat set date_contrat=tms where date_contrat is null";
1414 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1415 $resql = $db->query($sql);
1416 if (!$resql) {
1418 }
1419 if ($db->affected_rows($resql) > 0) {
1420 print $langs->trans('MigrationContractsEmptyDatesUpdateSuccess')."<br>\n";
1421 } else {
1422 print $langs->trans('MigrationContractsEmptyDatesNothingToUpdate')."<br>\n";
1423 }
1424
1425 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=tms where datec is null";
1426 dolibarr_install_syslog("upgrade2::migrate_contracts_date1");
1427 $resql = $db->query($sql);
1428 if (!$resql) {
1430 }
1431 if ($db->affected_rows($resql) > 0) {
1432 print $langs->trans('MigrationContractsEmptyCreationDatesUpdateSuccess')."<br>\n";
1433 } else {
1434 print $langs->trans('MigrationContractsEmptyCreationDatesNothingToUpdate')."<br>\n";
1435 }
1436
1437 print '</td></tr>';
1438}
1439
1448function migrate_contracts_date2($db, $langs, $conf)
1449{
1450 print '<tr><td colspan="4">';
1451
1452 $nberr = 0;
1453
1454 print '<br>';
1455 print '<b>'.$langs->trans('MigrationContractsInvalidDatesUpdate')."</b><br>\n";
1456
1457 $sql = "SELECT c.rowid as cref, c.datec, c.date_contrat, MIN(cd.date_ouverture) as datemin";
1458 $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c,";
1459 $sql .= " ".MAIN_DB_PREFIX."contratdet as cd";
1460 $sql .= " WHERE c.rowid=cd.fk_contrat AND cd.date_ouverture IS NOT NULL";
1461 $sql .= " GROUP BY c.rowid, c.date_contrat";
1462 $resql = $db->query($sql);
1463
1464 dolibarr_install_syslog("upgrade2::migrate_contracts_date2");
1465 if ($resql) {
1466 $i = 0;
1467 $row = array();
1468 $num = $db->num_rows($resql);
1469
1470 if ($num) {
1471 $nbcontratsmodifie = 0;
1472 $db->begin();
1473
1474 while ($i < $num) {
1475 $obj = $db->fetch_object($resql);
1476 if ($obj->date_contrat > $obj->datemin) {
1477 $datemin = $db->jdate($obj->datemin);
1478
1479 print $langs->trans('MigrationContractsInvalidDateFix', $obj->cref, $obj->date_contrat, $obj->datemin)."<br>\n";
1480 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1481 $sql .= " SET date_contrat='".$db->idate($datemin)."'";
1482 $sql .= " WHERE rowid = ".((int) $obj->cref);
1483 $resql2 = $db->query($sql);
1484 if (!$resql2) {
1486 }
1487
1488 $nbcontratsmodifie++;
1489 }
1490 $i++;
1491 }
1492
1493 $db->commit();
1494
1495 if ($nbcontratsmodifie) {
1496 print $langs->trans('MigrationContractsInvalidDatesNumber', $nbcontratsmodifie)."<br>\n";
1497 } else {
1498 print $langs->trans('MigrationContractsInvalidDatesNothingToUpdate')."<br>\n";
1499 }
1500 }
1501 } else {
1503 }
1504
1505 print '</td></tr>';
1506}
1507
1516function migrate_contracts_date3($db, $langs, $conf)
1517{
1518 print '<tr><td colspan="4">';
1519
1520 print '<br>';
1521 print '<b>'.$langs->trans('MigrationContractsIncoherentCreationDateUpdate')."</b><br>\n";
1522
1523 $sql = "update ".MAIN_DB_PREFIX."contrat set datec=date_contrat where datec is null or datec > date_contrat";
1524 dolibarr_install_syslog("upgrade2::migrate_contracts_date3");
1525 $resql = $db->query($sql);
1526 if (!$resql) {
1528 }
1529 if ($db->affected_rows($resql) > 0) {
1530 print $langs->trans('MigrationContractsIncoherentCreationDateUpdateSuccess')."<br>\n";
1531 } else {
1532 print $langs->trans('MigrationContractsIncoherentCreationDateNothingToUpdate')."<br>\n";
1533 }
1534
1535 print '</td></tr>';
1536}
1537
1546function migrate_contracts_open($db, $langs, $conf)
1547{
1548 print '<tr><td colspan="4">';
1549
1550 print '<br>';
1551 print '<b>'.$langs->trans('MigrationReopeningContracts')."</b><br>\n";
1552
1553 $sql = "SELECT c.rowid as cref FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."contratdet as cd";
1554 $sql .= " WHERE cd.statut = 4 AND c.statut=2 AND c.rowid=cd.fk_contrat";
1555 dolibarr_install_syslog("upgrade2::migrate_contracts_open");
1556 $resql = $db->query($sql);
1557 if (!$resql) {
1559 }
1560 if ($db->affected_rows($resql) > 0) {
1561 $i = 0;
1562 $row = array();
1563 $num = $db->num_rows($resql);
1564
1565 if ($num) {
1566 $nbcontratsmodifie = 0;
1567 $db->begin();
1568
1569 while ($i < $num) {
1570 $obj = $db->fetch_object($resql);
1571
1572 print $langs->trans('MigrationReopenThisContract', $obj->cref)."<br>\n";
1573 $sql = "UPDATE ".MAIN_DB_PREFIX."contrat";
1574 $sql .= " SET statut = 1";
1575 $sql .= " WHERE rowid = ".((int) $obj->cref);
1576 $resql2 = $db->query($sql);
1577 if (!$resql2) {
1579 }
1580
1581 $nbcontratsmodifie++;
1582
1583 $i++;
1584 }
1585
1586 $db->commit();
1587
1588 if ($nbcontratsmodifie) {
1589 print $langs->trans('MigrationReopenedContractsNumber', $nbcontratsmodifie)."<br>\n";
1590 } else {
1591 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1592 }
1593 }
1594 } else {
1595 print $langs->trans('MigrationReopeningContractsNothingToUpdate')."<br>\n";
1596 }
1597
1598 print '</td></tr>';
1599}
1600
1610{
1611 global $bc;
1612
1613 print '<tr><td colspan="4">';
1614 print '<br>';
1615 print '<b>'.$langs->trans('SuppliersInvoices')."</b><br>\n";
1616 print '</td></tr>';
1617
1618 $result = $db->DDLDescTable(MAIN_DB_PREFIX."paiementfourn", "fk_facture_fourn");
1619 $obj = $db->fetch_object($result);
1620 if ($obj) {
1621 $error = 0;
1622 $nb = 0;
1623
1624 $select_sql = 'SELECT rowid, fk_facture_fourn, amount';
1625 $select_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn';
1626 $select_sql .= ' WHERE fk_facture_fourn IS NOT NULL';
1627
1628 dolibarr_install_syslog("upgrade2::migrate_paiementfourn_facturefourn");
1629 $select_resql = $db->query($select_sql);
1630 if ($select_resql) {
1631 $select_num = $db->num_rows($select_resql);
1632 $i = 0;
1633
1634 // For every supplier payment, add a line to paiementfourn_facturefourn
1635 while (($i < $select_num) && (!$error)) {
1636 $select_obj = $db->fetch_object($select_resql);
1637
1638 // Verify if the row is already in the new table - avoid adding duplicates
1639 $check_sql = 'SELECT fk_paiementfourn, fk_facturefourn';
1640 $check_sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
1641 $check_sql .= ' WHERE fk_paiementfourn = '.((int) $select_obj->rowid).' AND fk_facturefourn = '.((int) $select_obj->fk_facture_fourn);
1642 $check_resql = $db->query($check_sql);
1643 if ($check_resql) {
1644 $check_num = $db->num_rows($check_resql);
1645 if ($check_num == 0) {
1646 $db->begin();
1647
1648 if ($nb == 0) {
1649 print '<tr><td colspan="4" class="nowrap"><b>'.$langs->trans('SuppliersInvoices').'</b></td></tr>';
1650 print '<tr><td>fk_paiementfourn</td><td>fk_facturefourn</td><td>'.$langs->trans('Amount').'</td><td>&nbsp;</td></tr>';
1651 }
1652
1653 print '<tr class="oddeven">';
1654 print '<td>'.$select_obj->rowid.'</td><td>'.$select_obj->fk_facture_fourn.'</td><td>'.$select_obj->amount.'</td>';
1655
1656 $insert_sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn SET ';
1657 $insert_sql .= ' fk_paiementfourn = \''.$select_obj->rowid.'\',';
1658 $insert_sql .= ' fk_facturefourn = \''.$select_obj->fk_facture_fourn.'\',';
1659 $insert_sql .= ' amount = \''.$select_obj->amount.'\'';
1660 $insert_resql = $db->query($insert_sql);
1661
1662 if ($insert_resql) {
1663 $nb++;
1664 print '<td><span class="ok">'.$langs->trans("OK").'</span></td>';
1665 } else {
1666 print '<td><span class="error">Error on insert</span></td>';
1667 $error++;
1668 }
1669 print '</tr>';
1670 }
1671 } else {
1672 $error++;
1673 }
1674 $i++;
1675 }
1676 } else {
1677 $error++;
1678 }
1679
1680 if (!$error) {
1681 if (!$nb) {
1682 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1683 }
1684 $db->commit();
1685
1686 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."paiementfourn DROP COLUMN fk_facture_fourn";
1687 $db->query($sql);
1688 } else {
1689 print '<tr><td>'.$langs->trans("Error").'</td></tr>';
1690 $db->rollback();
1691 }
1692 } else {
1693 print '<tr><td>'.$langs->trans("AlreadyDone").'</td></tr>';
1694 }
1695}
1696
1705function migrate_price_facture($db, $langs, $conf)
1706{
1707 $err = 0;
1708
1709 $tmpmysoc = new Societe($db);
1710 $tmpmysoc->setMysoc($conf);
1711
1712 $db->begin();
1713
1714 print '<tr><td colspan="4">';
1715
1716 print '<br>';
1717 print '<b>'.$langs->trans('MigrationInvoice')."</b><br>\n";
1718
1719 // List of invoice lines not up to date
1720 $sql = "SELECT fd.rowid, fd.qty, fd.subprice, fd.remise_percent, fd.tva_tx as vatrate, fd.total_ttc, fd.info_bits,";
1721 $sql .= " f.rowid as facid, f.remise_percent as remise_percent_global, f.total_ttc as total_ttc_f";
1722 $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
1723 $sql .= " WHERE fd.fk_facture = f.rowid";
1724 $sql .= " AND (((fd.total_ttc = 0 AND fd.remise_percent != 100) or fd.total_ttc IS NULL) or f.total_ttc IS NULL)";
1725 //print $sql;
1726
1727 dolibarr_install_syslog("upgrade2::migrate_price_facture");
1728 $resql = $db->query($sql);
1729 if ($resql) {
1730 $num = $db->num_rows($resql);
1731 $i = 0;
1732 if ($num) {
1733 while ($i < $num) {
1734 $obj = $db->fetch_object($resql);
1735
1736 $rowid = $obj->rowid;
1737 $qty = $obj->qty;
1738 $pu = $obj->subprice;
1739 $vatrate = $obj->vatrate;
1740 $remise_percent = $obj->remise_percent;
1741 $remise_percent_global = $obj->remise_percent_global;
1742 $total_ttc_f = $obj->total_ttc_f;
1743 $info_bits = $obj->info_bits;
1744
1745 // On met a jour les 3 nouveaux champs
1746 $facligne = new FactureLigne($db);
1747 $facligne->fetch($rowid);
1748
1749 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $facligne->product_type, $tmpmysoc);
1750 $total_ht = $result[0];
1751 $total_tva = $result[1];
1752 $total_ttc = $result[2];
1753
1754 $facligne->total_ht = (float) $total_ht;
1755 $facligne->total_tva = (float) $total_tva;
1756 $facligne->total_ttc = (float) $total_ttc;
1757
1758 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);
1759 print '. ';
1760 $facligne->update_total();
1761
1762
1763 /* On touche a facture mere uniquement si total_ttc = 0 */
1764 if (!$total_ttc_f) {
1765 $facture = new Facture($db);
1766 $facture->id = $obj->facid;
1767
1768 if ($facture->fetch($facture->id) >= 0) {
1769 if ($facture->update_price() > 0) {
1770 //print $facture->id;
1771 } else {
1772 print "Error id=".$facture->id;
1773 $err++;
1774 }
1775 } else {
1776 print "Error #3";
1777 $err++;
1778 }
1779 }
1780 print " ";
1781
1782 $i++;
1783 }
1784 } else {
1785 print $langs->trans("AlreadyDone");
1786 }
1787 $db->free($resql);
1788
1789 $db->commit();
1790 } else {
1791 print "Error #1 ".$db->error();
1792 $err++;
1793
1794 $db->rollback();
1795 }
1796
1797 print '<br>';
1798
1799 print '</td></tr>';
1800}
1801
1810function migrate_price_propal($db, $langs, $conf)
1811{
1812 $tmpmysoc = new Societe($db);
1813 $tmpmysoc->setMysoc($conf);
1814
1815 $db->begin();
1816
1817 print '<tr><td colspan="4">';
1818
1819 print '<br>';
1820 print '<b>'.$langs->trans('MigrationProposal')."</b><br>\n";
1821
1822 // List of proposal lines not up to date
1823 $sql = "SELECT pd.rowid, pd.qty, pd.subprice, pd.remise_percent, pd.tva_tx as vatrate, pd.info_bits,";
1824 $sql .= " p.rowid as propalid, p.remise_percent as remise_percent_global";
1825 $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd, ".MAIN_DB_PREFIX."propal as p";
1826 $sql .= " WHERE pd.fk_propal = p.rowid";
1827 $sql .= " AND ((pd.total_ttc = 0 AND pd.remise_percent != 100) or pd.total_ttc IS NULL)";
1828
1829 dolibarr_install_syslog("upgrade2::migrate_price_propal");
1830 $resql = $db->query($sql);
1831 if ($resql) {
1832 $num = $db->num_rows($resql);
1833 $i = 0;
1834 if ($num) {
1835 while ($i < $num) {
1836 $obj = $db->fetch_object($resql);
1837
1838 $rowid = $obj->rowid;
1839 $qty = $obj->qty;
1840 $pu = $obj->subprice;
1841 $vatrate = $obj->vatrate;
1842 $remise_percent = $obj->remise_percent;
1843 $remise_percent_global = $obj->remise_percent_global;
1844 $info_bits = $obj->info_bits;
1845
1846 // Update the 3 new fields
1847 $propalligne = new PropaleLigne($db);
1848 $propalligne->fetch($rowid);
1849
1850 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $propalligne->product_type, $tmpmysoc);
1851 $total_ht = $result[0];
1852 $total_tva = $result[1];
1853 $total_ttc = $result[2];
1854
1855 $propalligne->total_ht = (float) $total_ht;
1856 $propalligne->total_tva = (float) $total_tva;
1857 $propalligne->total_ttc = (float) $total_ttc;
1858
1859 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);
1860 print '. ';
1861 $propalligne->update_total();
1862
1863 $i++;
1864 }
1865 } else {
1866 print $langs->trans("AlreadyDone");
1867 }
1868
1869 $db->free($resql);
1870
1871 $db->commit();
1872 } else {
1873 print "Error #1 ".$db->error();
1874
1875 $db->rollback();
1876 }
1877
1878 print '<br>';
1879
1880 print '</td></tr>';
1881}
1882
1891function migrate_price_contrat($db, $langs, $conf)
1892{
1893 $db->begin();
1894
1895 $tmpmysoc = new Societe($db);
1896 $tmpmysoc->setMysoc($conf);
1897 if (empty($tmpmysoc->country_id)) {
1898 $tmpmysoc->country_id = 0; // Ti not have this set to '' or will make sql syntax error.
1899 }
1900
1901 print '<tr><td colspan="4">';
1902
1903 print '<br>';
1904 print '<b>'.$langs->trans('MigrationContract')."</b><br>\n";
1905
1906 // List of contract lines not up to date
1907 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1908 $sql .= " c.rowid as contratid";
1909 $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c";
1910 $sql .= " WHERE cd.fk_contrat = c.rowid";
1911 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100 AND cd.subprice > 0) or cd.total_ttc IS NULL)";
1912
1913 dolibarr_install_syslog("upgrade2::migrate_price_contrat");
1914 $resql = $db->query($sql);
1915 if ($resql) {
1916 $num = $db->num_rows($resql);
1917 $i = 0;
1918 if ($num) {
1919 while ($i < $num) {
1920 $obj = $db->fetch_object($resql);
1921
1922 $rowid = $obj->rowid;
1923 $qty = $obj->qty;
1924 $pu = $obj->subprice;
1925 $vatrate = $obj->vatrate;
1926 $remise_percent = $obj->remise_percent;
1927 $info_bits = $obj->info_bits;
1928
1929 // On met a jour les 3 nouveaux champs
1930 $contratligne = new ContratLigne($db);
1931 //$contratligne->fetch($rowid); Non requis car le update_total ne met a jour que chp redefinis
1932 $contratligne->fetch($rowid);
1933
1934 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, 0, 'HT', $info_bits, $contratligne->product_type, $tmpmysoc);
1935 $total_ht = $result[0];
1936 $total_tva = $result[1];
1937 $total_ttc = $result[2];
1938
1939 $contratligne->total_ht = (float) $total_ht;
1940 $contratligne->total_tva = (float) $total_tva;
1941 $contratligne->total_ttc = (float) $total_ttc;
1942
1943 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);
1944 print '. ';
1945 $contratligne->update_total();
1946
1947 $i++;
1948 }
1949 } else {
1950 print $langs->trans("AlreadyDone");
1951 }
1952
1953 $db->free($resql);
1954
1955 $db->commit();
1956 } else {
1957 print "Error #1 ".$db->error();
1958
1959 $db->rollback();
1960 }
1961
1962 print '<br>';
1963
1964 print '</td></tr>';
1965}
1966
1975function migrate_price_commande($db, $langs, $conf)
1976{
1977 $db->begin();
1978
1979 $tmpmysoc = new Societe($db);
1980 $tmpmysoc->setMysoc($conf);
1981
1982 print '<tr><td colspan="4">';
1983
1984 print '<br>';
1985 print '<b>'.$langs->trans('MigrationOrder')."</b><br>\n";
1986
1987 // List of sales orders lines not up to date
1988 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
1989 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
1990 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."commande as c";
1991 $sql .= " WHERE cd.fk_commande = c.rowid";
1992 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
1993
1994 dolibarr_install_syslog("upgrade2::migrate_price_commande");
1995 $resql = $db->query($sql);
1996 if ($resql) {
1997 $num = $db->num_rows($resql);
1998 $i = 0;
1999 if ($num) {
2000 while ($i < $num) {
2001 $obj = $db->fetch_object($resql);
2002
2003 $rowid = $obj->rowid;
2004 $qty = $obj->qty;
2005 $pu = $obj->subprice;
2006 $vatrate = $obj->vatrate;
2007 $remise_percent = $obj->remise_percent;
2008 $remise_percent_global = $obj->remise_percent_global;
2009 $info_bits = $obj->info_bits;
2010
2011 // On met a jour les 3 nouveaux champs
2012 $commandeligne = new OrderLine($db);
2013 $commandeligne->fetch($rowid);
2014
2015 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $tmpmysoc);
2016 $total_ht = $result[0];
2017 $total_tva = $result[1];
2018 $total_ttc = $result[2];
2019
2020 $commandeligne->total_ht = (float) $total_ht;
2021 $commandeligne->total_tva = (float) $total_tva;
2022 $commandeligne->total_ttc = (float) $total_ttc;
2023
2024 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);
2025 print '. ';
2026 $commandeligne->update_total();
2027
2028 $i++;
2029 }
2030 } else {
2031 print $langs->trans("AlreadyDone");
2032 }
2033
2034 $db->free($resql);
2035
2036 /*
2037 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
2038 $sql.= " WHERE price = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0 AND remise_percent = 0";
2039 $resql=$db->query($sql);
2040 if (! $resql)
2041 {
2042 dol_print_error($db);
2043 }
2044 */
2045
2046 $db->commit();
2047 } else {
2048 print "Error #1 ".$db->error();
2049
2050 $db->rollback();
2051 }
2052
2053 print '<br>';
2054
2055 print '</td></tr>';
2056}
2057
2067{
2068 global $mysoc;
2069
2070 $db->begin();
2071
2072 $tmpmysoc = new Societe($db);
2073 $tmpmysoc->setMysoc($conf);
2074
2075 print '<tr><td colspan="4">';
2076
2077 print '<br>';
2078 print '<b>'.$langs->trans('MigrationSupplierOrder')."</b><br>\n";
2079
2080 // List of purchase order lines not up to date
2081 $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as vatrate, cd.info_bits,";
2082 $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
2083 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd, ".MAIN_DB_PREFIX."commande_fournisseur as c";
2084 $sql .= " WHERE cd.fk_commande = c.rowid";
2085 $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
2086
2087 dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur");
2088 $resql = $db->query($sql);
2089 if ($resql) {
2090 $num = $db->num_rows($resql);
2091 $i = 0;
2092 if ($num) {
2093 while ($i < $num) {
2094 $obj = $db->fetch_object($resql);
2095
2096 $rowid = $obj->rowid;
2097 $qty = $obj->qty;
2098 $pu = $obj->subprice;
2099 $vatrate = $obj->vatrate;
2100 $remise_percent = $obj->remise_percent;
2101 $remise_percent_global = $obj->remise_percent_global;
2102 $info_bits = $obj->info_bits;
2103
2104 // On met a jour les 3 nouveaux champs
2105 $commandeligne = new CommandeFournisseurLigne($db);
2106 $commandeligne->fetch($rowid);
2107
2108 $result = calcul_price_total($qty, $pu, $remise_percent, $vatrate, 0, 0, $remise_percent_global, 'HT', $info_bits, $commandeligne->product_type, $mysoc);
2109 $total_ht = $result[0];
2110 $total_tva = $result[1];
2111 $total_ttc = $result[2];
2112
2113 $commandeligne->total_ht = (float) $total_ht;
2114 $commandeligne->total_tva = (float) $total_tva;
2115 $commandeligne->total_ttc = (float) $total_ttc;
2116
2117 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);
2118 print '. ';
2119 $commandeligne->update_total();
2120
2121 $i++;
2122 }
2123 } else {
2124 print $langs->trans("AlreadyDone");
2125 }
2126
2127 $db->free($resql);
2128
2129 /*
2130 $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
2131 $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
2132 $resql=$db->query($sql);
2133 if (! $resql)
2134 {
2135 dol_print_error($db);
2136 }
2137 */
2138
2139 $db->commit();
2140 } else {
2141 print "Error #1 ".$db->error();
2142
2143 $db->rollback();
2144 }
2145
2146 print '<br>';
2147
2148 print '</td></tr>';
2149}
2150
2159function migrate_modeles($db, $langs, $conf)
2160{
2161 //print '<br>';
2162 //print '<b>'.$langs->trans('UpdateModelsTable')."</b><br>\n";
2163
2164 dolibarr_install_syslog("upgrade2::migrate_modeles");
2165
2166 if (isModEnabled('invoice')) {
2167 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
2169 if (count($modellist) == 0) {
2170 // Aucun model par default.
2171 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('crabe','invoice')";
2172 $resql = $db->query($sql);
2173 if (!$resql) {
2175 }
2176 }
2177 }
2178
2179 if (isModEnabled('order')) {
2180 include_once DOL_DOCUMENT_ROOT.'/core/modules/commande/modules_commande.php';
2182 if (count($modellist) == 0) {
2183 // Aucun model par default.
2184 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('einstein','order')";
2185 $resql = $db->query($sql);
2186 if (!$resql) {
2188 }
2189 }
2190 }
2191
2192 if (isModEnabled("shipping")) {
2193 include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
2195 if (count($modellist) == 0) {
2196 // Aucun model par default.
2197 $sql = " insert into ".MAIN_DB_PREFIX."document_model(nom,type) values('rouget','shipping')";
2198 $resql = $db->query($sql);
2199 if (!$resql) {
2201 }
2202 }
2203 }
2204
2205 //print $langs->trans("AlreadyDone");
2206}
2207
2208
2218{
2219 dolibarr_install_syslog("upgrade2::migrate_commande_expedition");
2220
2221 print '<tr><td colspan="4">';
2222
2223 print '<br>';
2224 print '<b>'.$langs->trans('MigrationShipmentOrderMatching')."</b><br>\n";
2225
2226 $result = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "fk_commande");
2227 $obj = $db->fetch_object($result);
2228 if ($obj) {
2229 $error = 0;
2230
2231 $db->begin();
2232
2233 $sql = "SELECT e.rowid, e.fk_commande FROM ".MAIN_DB_PREFIX."expedition as e";
2234 $resql = $db->query($sql);
2235 if ($resql) {
2236 $i = 0;
2237 $num = $db->num_rows($resql);
2238
2239 if ($num) {
2240 while ($i < $num) {
2241 $obj = $db->fetch_object($resql);
2242
2243 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_exp (fk_expedition,fk_commande)";
2244 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2245 $resql2 = $db->query($sql);
2246
2247 if (!$resql2) {
2248 $error++;
2250 }
2251 print '. ';
2252 $i++;
2253 }
2254 }
2255
2256 if ($error == 0) {
2257 $db->commit();
2258 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."expedition DROP COLUMN fk_commande";
2259 print $langs->trans('FieldRenamed')."<br>\n";
2260 $db->query($sql);
2261 } else {
2262 $db->rollback();
2263 }
2264 } else {
2266 $db->rollback();
2267 }
2268 } else {
2269 print $langs->trans('AlreadyDone')."<br>\n";
2270 }
2271 print '</td></tr>';
2272}
2273
2282function migrate_commande_livraison($db, $langs, $conf)
2283{
2284 dolibarr_install_syslog("upgrade2::migrate_commande_livraison");
2285
2286 print '<tr><td colspan="4">';
2287
2288 print '<br>';
2289 print '<b>'.$langs->trans('MigrationDeliveryOrderMatching')."</b><br>\n";
2290
2291 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_commande");
2292 $obj = $db->fetch_object($result);
2293 if ($obj) {
2294 $error = 0;
2295
2296 $db->begin();
2297
2298 $sql = "SELECT l.rowid, l.fk_commande,";
2299 $sql .= " c.ref_client, c.date_livraison as delivery_date";
2300 $sql .= " FROM ".MAIN_DB_PREFIX."livraison as l, ".MAIN_DB_PREFIX."commande as c";
2301 $sql .= " WHERE c.rowid = l.fk_commande";
2302 $resql = $db->query($sql);
2303 if ($resql) {
2304 $i = 0;
2305 $num = $db->num_rows($resql);
2306
2307 if ($num) {
2308 while ($i < $num) {
2309 $obj = $db->fetch_object($resql);
2310
2311 $sql = "INSERT INTO ".MAIN_DB_PREFIX."co_liv (fk_livraison,fk_commande)";
2312 $sql .= " VALUES (".((int) $obj->rowid).", ".((int) $obj->fk_commande).")";
2313 $resql2 = $db->query($sql);
2314
2315 if ($resql2) {
2316 $delivery_date = $db->jdate($obj->delivery_date);
2317
2318 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2319 $sqlu .= " ref_client = '".$db->escape($obj->ref_client)."'";
2320 $sqlu .= ", date_livraison = '".$db->idate($delivery_date)."'";
2321 $sqlu .= " WHERE rowid = ".((int) $obj->rowid);
2322 $resql3 = $db->query($sqlu);
2323 if (!$resql3) {
2324 $error++;
2326 }
2327 } else {
2328 $error++;
2330 }
2331 print '. ';
2332 $i++;
2333 }
2334 }
2335
2336 if ($error == 0) {
2337 $db->commit();
2338 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_commande";
2339 print $langs->trans('FieldRenamed')."<br>\n";
2340 $db->query($sql);
2341 } else {
2342 $db->rollback();
2343 }
2344 } else {
2346 $db->rollback();
2347 }
2348 } else {
2349 print $langs->trans('AlreadyDone')."<br>\n";
2350 }
2351 print '</td></tr>';
2352}
2353
2362function migrate_detail_livraison($db, $langs, $conf)
2363{
2364 dolibarr_install_syslog("upgrade2::migrate_detail_livraison");
2365
2366 print '<tr><td colspan="4">';
2367
2368 print '<br>';
2369 print '<b>'.$langs->trans('MigrationDeliveryDetail')."</b><br>\n";
2370
2371 // This is done if field fk_commande_ligne exists.
2372 // If not this means migration was already done.
2373 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_commande_ligne");
2374 $obj = $db->fetch_object($result);
2375 if ($obj) {
2376 $error = 0;
2377
2378 $db->begin();
2379
2380 $sql = "SELECT cd.rowid, cd.fk_product, cd.description, cd.subprice, cd.total_ht";
2381 $sql .= ", ld.fk_livraison";
2382 $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd, ".MAIN_DB_PREFIX."livraisondet as ld";
2383 $sql .= " WHERE ld.fk_commande_ligne = cd.rowid";
2384 $resql = $db->query($sql);
2385 if ($resql) {
2386 $i = 0;
2387 $num = $db->num_rows($resql);
2388
2389 if ($num) {
2390 while ($i < $num) {
2391 $obj = $db->fetch_object($resql);
2392
2393 $sql = "UPDATE ".MAIN_DB_PREFIX."livraisondet SET";
2394 $sql .= " fk_product = ".((int) $obj->fk_product);
2395 $sql .= ",description = '".$db->escape($obj->description)."'";
2396 $sql .= ",subprice = ".price2num($obj->subprice);
2397 $sql .= ",total_ht = ".price2num($obj->total_ht);
2398 $sql .= " WHERE fk_commande_ligne = ".((int) $obj->rowid);
2399 $resql2 = $db->query($sql);
2400
2401 if ($resql2) {
2402 $sql = "SELECT total_ht";
2403 $sql .= " FROM ".MAIN_DB_PREFIX."livraison";
2404 $sql .= " WHERE rowid = ".((int) $obj->fk_livraison);
2405 $resql3 = $db->query($sql);
2406
2407 if ($resql3) {
2408 $obju = $db->fetch_object($resql3);
2409 $total_ht = $obju->total_ht + $obj->total_ht;
2410
2411 $sqlu = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
2412 $sqlu .= " total_ht = ".price2num($total_ht, 'MT');
2413 $sqlu .= " WHERE rowid = ".((int) $obj->fk_livraison);
2414 $resql4 = $db->query($sqlu);
2415 if (!$resql4) {
2416 $error++;
2418 }
2419 } else {
2420 $error++;
2422 }
2423 } else {
2424 $error++;
2426 }
2427 print '. ';
2428 $i++;
2429 }
2430 }
2431
2432 if ($error == 0) {
2433 $db->commit();
2434 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet CHANGE fk_commande_ligne fk_origin_line integer";
2435 print $langs->trans('FieldRenamed')."<br>\n";
2436 $db->query($sql);
2437 } else {
2438 $db->rollback();
2439 }
2440 } else {
2442 $db->rollback();
2443 }
2444 } else {
2445 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraisondet", "fk_origin_line");
2446 $obj = $db->fetch_object($result);
2447 if (!$obj) {
2448 $sql = "ALTER TABLE ".MAIN_DB_PREFIX."livraisondet ADD COLUMN fk_origin_line integer after fk_livraison";
2449 $db->query($sql);
2450 }
2451 print $langs->trans('AlreadyDone')."<br>\n";
2452 }
2453 print '</td></tr>';
2454}
2455
2464function migrate_stocks($db, $langs, $conf)
2465{
2466 dolibarr_install_syslog("upgrade2::migrate_stocks");
2467
2468 print '<tr><td colspan="4">';
2469
2470 print '<br>';
2471 print '<b>'.$langs->trans('MigrationStockDetail')."</b><br>\n";
2472
2473 $error = 0;
2474
2475 $db->begin();
2476
2477 $sql = "SELECT SUM(reel) as total, fk_product";
2478 $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
2479 $sql .= " GROUP BY fk_product";
2480 $resql = $db->query($sql);
2481 if ($resql) {
2482 $i = 0;
2483 $num = $db->num_rows($resql);
2484
2485 if ($num) {
2486 while ($i < $num) {
2487 $obj = $db->fetch_object($resql);
2488
2489 $sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
2490 $sql .= " stock = ".price2num($obj->total, 'MS');
2491 $sql .= " WHERE rowid = ".((int) $obj->fk_product);
2492
2493 $resql2 = $db->query($sql);
2494 if ($resql2) {
2495 } else {
2496 $error++;
2498 }
2499 print '. ';
2500 $i++;
2501 }
2502 }
2503
2504 if ($error == 0) {
2505 $db->commit();
2506 } else {
2507 $db->rollback();
2508 }
2509 } else {
2511 $db->rollback();
2512 }
2513
2514 print '</td></tr>';
2515}
2516
2526function migrate_menus($db, $langs, $conf)
2527{
2528 dolibarr_install_syslog("upgrade2::migrate_menus");
2529
2530 print '<tr><td colspan="4">';
2531
2532 print '<br>';
2533 print '<b>'.$langs->trans('MigrationMenusDetail')."</b><br>\n";
2534
2535 $error = 0;
2536
2537 if ($db->DDLInfoTable(MAIN_DB_PREFIX."menu_constraint")) {
2538 $db->begin();
2539
2540 $sql = "SELECT m.rowid, mc.action";
2541 $sql .= " FROM ".MAIN_DB_PREFIX."menu_constraint as mc, ".MAIN_DB_PREFIX."menu_const as md, ".MAIN_DB_PREFIX."menu as m";
2542 $sql .= " WHERE md.fk_menu = m.rowid AND md.fk_constraint = mc.rowid";
2543 $sql .= " AND m.enabled = '1'";
2544 $resql = $db->query($sql);
2545 if ($resql) {
2546 $i = 0;
2547 $num = $db->num_rows($resql);
2548 if ($num) {
2549 while ($i < $num) {
2550 $obj = $db->fetch_object($resql);
2551
2552 $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
2553 $sql .= " enabled = '".$db->escape($obj->action)."'";
2554 $sql .= " WHERE rowid = ".((int) $obj->rowid);
2555 $sql .= " AND enabled = '1'";
2556
2557 $resql2 = $db->query($sql);
2558 if ($resql2) {
2559 } else {
2560 $error++;
2562 }
2563 print '. ';
2564 $i++;
2565 }
2566 }
2567
2568 if ($error == 0) {
2569 $db->commit();
2570 } else {
2571 $db->rollback();
2572 }
2573 } else {
2575 $db->rollback();
2576 }
2577 } else {
2578 print $langs->trans('AlreadyDone')."<br>\n";
2579 }
2580
2581 print '</td></tr>';
2582}
2583
2594{
2595 dolibarr_install_syslog("upgrade2::migrate_commande_deliveryaddress");
2596
2597 print '<tr><td colspan="4">';
2598
2599 print '<br>';
2600 print '<b>'.$langs->trans('MigrationDeliveryAddress')."</b><br>\n";
2601
2602 $error = 0;
2603
2604 if ($db->DDLInfoTable(MAIN_DB_PREFIX."co_exp")) {
2605 $db->begin();
2606
2607 $sql = "SELECT c.fk_adresse_livraison, ce.fk_expedition";
2608 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
2609 $sql .= ", ".MAIN_DB_PREFIX."co_exp as ce";
2610 $sql .= " WHERE c.rowid = ce.fk_commande";
2611 $sql .= " AND c.fk_adresse_livraison IS NOT NULL AND c.fk_adresse_livraison != 0";
2612
2613 $resql = $db->query($sql);
2614 if ($resql) {
2615 $i = 0;
2616 $num = $db->num_rows($resql);
2617
2618 if ($num) {
2619 while ($i < $num) {
2620 $obj = $db->fetch_object($resql);
2621
2622 $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
2623 $sql .= " fk_adresse_livraison = '".$db->escape($obj->fk_adresse_livraison)."'";
2624 $sql .= " WHERE rowid = ".((int) $obj->fk_expedition);
2625
2626 $resql2 = $db->query($sql);
2627 if (!$resql2) {
2628 $error++;
2630 }
2631 print '. ';
2632 $i++;
2633 }
2634 } else {
2635 print $langs->trans('AlreadyDone')."<br>\n";
2636 }
2637
2638 if ($error == 0) {
2639 $db->commit();
2640 } else {
2641 $db->rollback();
2642 }
2643 } else {
2645 $db->rollback();
2646 }
2647 } else {
2648 print $langs->trans('AlreadyDone')."<br>\n";
2649 }
2650
2651 print '</td></tr>';
2652}
2653
2664{
2665 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links");
2666
2667 if (($db->type == 'mysql' || $db->type == 'mysqli')) {
2668 if (versioncompare($db->getVersionArray(), array(4, 0)) < 0) {
2669 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links Version of database too old to make this migrate action");
2670 return 0;
2671 }
2672 }
2673 print '<tr><td colspan="4">';
2674
2675 print '<br>';
2676 print '<b>'.$langs->trans('MigrationFixData')."</b> (1)<br>\n";
2677
2678 $error = 0;
2679
2680
2681 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 1.
2682 $table1 = 'facturedet';
2683 $field1 = 'fk_remise_except';
2684 $table2 = 'societe_remise_except';
2685 $field2 = 'fk_facture_line';
2686
2687 $db->begin();
2688
2689 $sql = "SELECT t1.rowid, t1.".$db->sanitize($field1)." as field";
2690 $sql .= " FROM ".MAIN_DB_PREFIX.$db->sanitize($table1)." as t1";
2691 $sql .= " WHERE t1.".$db->sanitize($field1)." IS NOT NULL AND t1.".$db->sanitize($field1)." NOT IN";
2692 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2)." as t2";
2693 $sql .= " WHERE t1.rowid = t2.".$db->sanitize($field2).")";
2694
2695 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 1");
2696 $resql = $db->query($sql);
2697 if ($resql) {
2698 $i = 0;
2699 $num = $db->num_rows($resql);
2700
2701 if ($num) {
2702 while ($i < $num) {
2703 $obj = $db->fetch_object($resql);
2704
2705 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2706
2707 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2708 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2709 $sql .= " WHERE rowid = ".((int) $obj->field);
2710
2711 $resql2 = $db->query($sql);
2712 if (!$resql2) {
2713 $error++;
2715 }
2716 //print '. ';
2717 $i++;
2718 }
2719 } else {
2720 print $langs->trans('AlreadyDone')."<br>\n";
2721 }
2722
2723 if ($error == 0) {
2724 $db->commit();
2725 } else {
2726 $db->rollback();
2727 }
2728 } else {
2730 $db->rollback();
2731 }
2732
2733 print '</td></tr>';
2734
2735
2736 print '<tr><td colspan="4">';
2737
2738 print '<br>';
2739 print '<b>'.$langs->trans('MigrationFixData')."</b> (2)<br>\n";
2740
2741 // Restore missing link for this cross foreign key (link 1 <=> 1). Direction 2.
2742 $table2 = 'facturedet';
2743 $field2 = 'fk_remise_except';
2744 $table1 = 'societe_remise_except';
2745 $field1 = 'fk_facture_line';
2746
2747 $db->begin();
2748
2749 $sql = "SELECT t1.rowid, t1.".$db->sanitize($field1)." as field";
2750 $sql .= " FROM ".MAIN_DB_PREFIX.$db->sanitize($table1)." as t1";
2751 $sql .= " WHERE t1.".$db->sanitize($field1)." IS NOT NULL AND t1.".$db->sanitize($field1)." NOT IN";
2752 $sql .= " (SELECT t2.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize($table2)." as t2";
2753 $sql .= " WHERE t1.rowid = t2.".$db->sanitize($field2).")";
2754
2755 dolibarr_install_syslog("upgrade2::migrate_restore_missing_links DIRECTION 2");
2756 $resql = $db->query($sql);
2757 if ($resql) {
2758 $i = 0;
2759 $num = $db->num_rows($resql);
2760
2761 if ($num) {
2762 while ($i < $num) {
2763 $obj = $db->fetch_object($resql);
2764
2765 print 'Line '.$obj->rowid.' in '.$table1.' is linked to record '.$obj->field.' in '.$table2.' that has no link to '.$table1.'. We fix this.<br>';
2766
2767 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table2)." SET";
2768 $sql .= " ".$db->sanitize($field2)." = '".$db->escape($obj->rowid)."'";
2769 $sql .= " WHERE rowid = ".((int) $obj->field);
2770
2771 $resql2 = $db->query($sql);
2772 if (!$resql2) {
2773 $error++;
2775 }
2776 //print '. ';
2777 $i++;
2778 }
2779 } else {
2780 print $langs->trans('AlreadyDone')."<br>\n";
2781 }
2782
2783 if ($error == 0) {
2784 $db->commit();
2785 } else {
2786 $db->rollback();
2787 }
2788 } else {
2790 $db->rollback();
2791 }
2792
2793 print '</td></tr>';
2794
2795 return ($error ? -1 : 1);
2796}
2797
2806function migrate_project_user_resp($db, $langs, $conf)
2807{
2808 dolibarr_install_syslog("upgrade2::migrate_project_user_resp");
2809
2810 print '<tr><td colspan="4">';
2811
2812 print '<br>';
2813 print '<b>'.$langs->trans('MigrationProjectUserResp')."</b><br>\n";
2814
2815 $result = $db->DDLDescTable(MAIN_DB_PREFIX."projet", "fk_user_resp");
2816 $obj = $db->fetch_object($result);
2817 if ($obj) {
2818 $error = 0;
2819
2820 $db->begin();
2821
2822 $sql = "SELECT rowid, fk_user_resp FROM ".MAIN_DB_PREFIX."projet";
2823 $resql = $db->query($sql);
2824 if ($resql) {
2825 $i = 0;
2826 $num = $db->num_rows($resql);
2827
2828 if ($num) {
2829 while ($i < $num) {
2830 $obj = $db->fetch_object($resql);
2831
2832 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2833 $sql2 .= "datecreate";
2834 $sql2 .= ", statut";
2835 $sql2 .= ", element_id";
2836 $sql2 .= ", fk_c_type_contact";
2837 $sql2 .= ", fk_socpeople";
2838 $sql2 .= ") VALUES (";
2839 $sql2 .= "'".$db->idate(dol_now())."'";
2840 $sql2 .= ", '4'";
2841 $sql2 .= ", ".$obj->rowid;
2842 $sql2 .= ", '160'";
2843 $sql2 .= ", ".$obj->fk_user_resp;
2844 $sql2 .= ")";
2845
2846 if ($obj->fk_user_resp > 0) {
2847 $resql2 = $db->query($sql2);
2848 if (!$resql2) {
2849 $error++;
2851 }
2852 }
2853 print '. ';
2854
2855 $i++;
2856 }
2857 }
2858
2859 if ($error == 0) {
2860 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."projet DROP COLUMN fk_user_resp";
2861 if ($db->query($sqlDrop)) {
2862 $db->commit();
2863 } else {
2864 $db->rollback();
2865 }
2866 } else {
2867 $db->rollback();
2868 }
2869 } else {
2871 $db->rollback();
2872 }
2873 } else {
2874 print $langs->trans('AlreadyDone')."<br>\n";
2875 }
2876 print '</td></tr>';
2877}
2878
2888{
2889 dolibarr_install_syslog("upgrade2::migrate_project_task_actors");
2890
2891 print '<tr><td colspan="4">';
2892
2893 print '<br>';
2894 print '<b>'.$langs->trans('MigrationProjectTaskActors')."</b><br>\n";
2895
2896 if ($db->DDLInfoTable(MAIN_DB_PREFIX."projet_task_actors")) {
2897 $error = 0;
2898
2899 $db->begin();
2900
2901 $sql = "SELECT fk_projet_task as fk_project_task, fk_user FROM ".MAIN_DB_PREFIX."projet_task_actors";
2902 $resql = $db->query($sql);
2903 if ($resql) {
2904 $i = 0;
2905 $num = $db->num_rows($resql);
2906
2907 if ($num) {
2908 while ($i < $num) {
2909 $obj = $db->fetch_object($resql);
2910
2911 $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."element_contact (";
2912 $sql2 .= "datecreate";
2913 $sql2 .= ", statut";
2914 $sql2 .= ", element_id";
2915 $sql2 .= ", fk_c_type_contact";
2916 $sql2 .= ", fk_socpeople";
2917 $sql2 .= ") VALUES (";
2918 $sql2 .= "'".$db->idate(dol_now())."'";
2919 $sql2 .= ", '4'";
2920 $sql2 .= ", ".$obj->fk_project_task;
2921 $sql2 .= ", '180'";
2922 $sql2 .= ", ".$obj->fk_user;
2923 $sql2 .= ")";
2924
2925 $resql2 = $db->query($sql2);
2926
2927 if (!$resql2) {
2928 $error++;
2930 }
2931 print '. ';
2932 $i++;
2933 }
2934 }
2935
2936 if ($error == 0) {
2937 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX."projet_task_actors";
2938 if ($db->query($sqlDrop)) {
2939 $db->commit();
2940 } else {
2941 $db->rollback();
2942 }
2943 } else {
2944 $db->rollback();
2945 }
2946 } else {
2948 $db->rollback();
2949 }
2950 } else {
2951 print $langs->trans('AlreadyDone')."<br>\n";
2952 }
2953 print '</td></tr>';
2954}
2955
2969function migrate_relationship_tables($db, $langs, $conf, $table, $fk_source, $sourcetype, $fk_target, $targettype)
2970{
2971 print '<tr><td colspan="4">';
2972
2973 print '<br>';
2974 print '<b>'.$langs->trans('MigrationRelationshipTables', MAIN_DB_PREFIX.$table)."</b><br>\n";
2975
2976 $error = 0;
2977
2978 if ($db->DDLInfoTable(MAIN_DB_PREFIX.$table)) {
2979 dolibarr_install_syslog("upgrade2::migrate_relationship_tables table = ".MAIN_DB_PREFIX.$table);
2980
2981 $db->begin();
2982
2983 $sqlSelect = "SELECT ".$db->sanitize($fk_source).", ".$db->sanitize($fk_target);
2984 $sqlSelect .= " FROM ".MAIN_DB_PREFIX.$table;
2985
2986 $resql = $db->query($sqlSelect);
2987 if ($resql) {
2988 $i = 0;
2989 $num = $db->num_rows($resql);
2990
2991 if ($num) {
2992 while ($i < $num) {
2993 $obj = $db->fetch_object($resql);
2994
2995 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
2996 $sqlInsert .= "fk_source";
2997 $sqlInsert .= ", sourcetype";
2998 $sqlInsert .= ", fk_target";
2999 $sqlInsert .= ", targettype";
3000 $sqlInsert .= ") VALUES (";
3001 $sqlInsert .= ((int) $obj->$fk_source);
3002 $sqlInsert .= ", '".$db->escape($sourcetype)."'";
3003 $sqlInsert .= ", ".((int) $obj->$fk_target);
3004 $sqlInsert .= ", '".$db->escape($targettype)."'";
3005 $sqlInsert .= ")";
3006
3007 $result = $db->query($sqlInsert);
3008 if (!$result) {
3009 $error++;
3011 }
3012 print '. ';
3013 $i++;
3014 }
3015 } else {
3016 print $langs->trans('AlreadyDone')."<br>\n";
3017 }
3018
3019 if ($error == 0) {
3020 $sqlDrop = "DROP TABLE ".MAIN_DB_PREFIX.$db->sanitize($table);
3021 if ($db->query($sqlDrop)) {
3022 $db->commit();
3023 } else {
3024 $db->rollback();
3025 }
3026 } else {
3027 $db->rollback();
3028 }
3029 } else {
3031 $db->rollback();
3032 }
3033 } else {
3034 print $langs->trans('AlreadyDone')."<br>\n";
3035 }
3036
3037 print '</td></tr>';
3038}
3039
3048function migrate_element_time($db, $langs, $conf)
3049{
3050 dolibarr_install_syslog("upgrade2::migrate_element_time");
3051
3052 print '<tr><td colspan="4">';
3053
3054 print '<br>';
3055 print '<b>'.$langs->trans('MigrationProjectTaskTime')."</b><br>\n";
3056
3057 $error = 0;
3058
3059 $db->begin();
3060
3061 $sql = "SELECT rowid, fk_element, element_duration";
3062 $sql .= " FROM ".MAIN_DB_PREFIX."element_time";
3063 $resql = $db->query($sql);
3064 if ($resql) {
3065 $i = 0;
3066 $num = $db->num_rows($resql);
3067
3068 if ($num) {
3069 $totaltime = array();
3070 $oldtime = 0;
3071
3072 while ($i < $num) {
3073 $obj = $db->fetch_object($resql);
3074
3075 if ($obj->element_duration > 0) {
3076 // convert to second
3077 // only for int time and float time ex: 1.75 for 1h45
3078 list($hour, $min) = explode('.', $obj->element_duration);
3079 $hour = (int) $hour * 60 * 60;
3080 $min = (int) ((float) ('.'.$min)) * 3600;
3081 $newtime = $hour + $min;
3082
3083 $sql2 = "UPDATE ".MAIN_DB_PREFIX."element_time SET";
3084 $sql2 .= " element_duration = ".((int) $newtime);
3085 $sql2 .= " WHERE rowid = ".((int) $obj->rowid);
3086
3087 $resql2 = $db->query($sql2);
3088 if (!$resql2) {
3089 $error++;
3091 }
3092 print '. ';
3093 $oldtime++;
3094 if (!empty($totaltime[$obj->fk_element])) {
3095 $totaltime[$obj->fk_element] += $newtime;
3096 } else {
3097 $totaltime[$obj->fk_element] = $newtime;
3098 }
3099 } else {
3100 if (!empty($totaltime[$obj->fk_element])) {
3101 $totaltime[$obj->fk_element] += $obj->element_duration;
3102 } else {
3103 $totaltime[$obj->fk_element] = $obj->element_duration;
3104 }
3105 }
3106
3107 $i++;
3108 }
3109
3110 if ($error == 0) {
3111 if ($oldtime > 0) {
3112 foreach ($totaltime as $taskid => $total_duration) {
3113 $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET";
3114 $sql .= " duration_effective = ".((int) $total_duration);
3115 $sql .= " WHERE rowid = ".((int) $taskid);
3116
3117 $resql = $db->query($sql);
3118 if (!$resql) {
3119 $error++;
3121 }
3122 }
3123 } else {
3124 print $langs->trans('AlreadyDone')."<br>\n";
3125 }
3126 } else {
3128 }
3129 } else {
3130 print $langs->trans('AlreadyDone')."<br>\n";
3131 }
3132 } else {
3134 }
3135
3136 if ($error == 0) {
3137 $db->commit();
3138 } else {
3139 $db->rollback();
3140 }
3141
3142 print '</td></tr>';
3143}
3144
3154{
3155 print '<tr><td colspan="4">';
3156
3157 print '<br>';
3158 print '<b>'.$langs->trans('MigrationCustomerOrderShipping')."</b><br>\n";
3159
3160 $error = 0;
3161
3162 $result1 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "ref_customer");
3163 $result2 = $db->DDLDescTable(MAIN_DB_PREFIX."expedition", "date_delivery");
3164 $obj1 = $db->fetch_object($result1);
3165 $obj2 = $db->fetch_object($result2);
3166 if (!$obj1 && !$obj2) {
3167 dolibarr_install_syslog("upgrade2::migrate_customerorder_shipping");
3168
3169 $db->begin();
3170
3171 $sqlAdd1 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN ref_customer varchar(30) AFTER entity";
3172 $sqlAdd2 = "ALTER TABLE ".MAIN_DB_PREFIX."expedition ADD COLUMN date_delivery date DEFAULT NULL AFTER date_expedition";
3173
3174 if ($db->query($sqlAdd1) && $db->query($sqlAdd2)) {
3175 $sqlSelect = "SELECT e.rowid as shipping_id, c.ref_client, c.date_livraison as delivery_date";
3176 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."expedition as e";
3177 $sqlSelect .= ", ".MAIN_DB_PREFIX."element_element as el";
3178 $sqlSelect .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON c.rowid = el.fk_source AND el.sourcetype = 'commande'";
3179 $sqlSelect .= " WHERE e.rowid = el.fk_target";
3180 $sqlSelect .= " AND el.targettype = 'shipping'";
3181
3182 $resql = $db->query($sqlSelect);
3183 if ($resql) {
3184 $i = 0;
3185 $num = $db->num_rows($resql);
3186
3187 if ($num) {
3188 while ($i < $num) {
3189 $obj = $db->fetch_object($resql);
3190
3191 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."expedition SET";
3192 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_client)."'";
3193 $sqlUpdate .= ", date_delivery = '".$db->escape($obj->delivery_date ? $obj->delivery_date : 'null')."'";
3194 $sqlUpdate .= " WHERE rowid = ".((int) $obj->shipping_id);
3195
3196 $result = $db->query($sqlUpdate);
3197 if (!$result) {
3198 $error++;
3200 }
3201 print '. ';
3202 $i++;
3203 }
3204 } else {
3205 print $langs->trans('AlreadyDone')."<br>\n";
3206 }
3207
3208 if ($error == 0) {
3209 $db->commit();
3210 } else {
3212 $db->rollback();
3213 }
3214 } else {
3216 $db->rollback();
3217 }
3218 } else {
3220 $db->rollback();
3221 }
3222 } else {
3223 print $langs->trans('AlreadyDone')."<br>\n";
3224 }
3225
3226 print '</td></tr>';
3227}
3228
3237function migrate_shipping_delivery($db, $langs, $conf)
3238{
3239 print '<tr><td colspan="4">';
3240
3241 print '<br>';
3242 print '<b>'.$langs->trans('MigrationShippingDelivery')."</b><br>\n";
3243
3244 $error = 0;
3245
3246 $result = $db->DDLDescTable(MAIN_DB_PREFIX."livraison", "fk_expedition");
3247 $obj = $db->fetch_object($result);
3248 if ($obj) {
3249 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery");
3250
3251 $db->begin();
3252
3253 $sqlSelect = "SELECT rowid, fk_expedition";
3254 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison";
3255 $sqlSelect .= " WHERE fk_expedition is not null";
3256
3257 $resql = $db->query($sqlSelect);
3258 if ($resql) {
3259 $i = 0;
3260 $num = $db->num_rows($resql);
3261
3262 if ($num) {
3263 while ($i < $num) {
3264 $obj = $db->fetch_object($resql);
3265
3266 $sqlInsert = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
3267 $sqlInsert .= "fk_source";
3268 $sqlInsert .= ", sourcetype";
3269 $sqlInsert .= ", fk_target";
3270 $sqlInsert .= ", targettype";
3271 $sqlInsert .= ") VALUES (";
3272 $sqlInsert .= $obj->fk_expedition;
3273 $sqlInsert .= ", 'shipping'";
3274 $sqlInsert .= ", ".$obj->rowid;
3275 $sqlInsert .= ", 'delivery'";
3276 $sqlInsert .= ")";
3277
3278 $result = $db->query($sqlInsert);
3279 if ($result) {
3280 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET fk_expedition = NULL";
3281 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3282
3283 $result = $db->query($sqlUpdate);
3284 if (!$result) {
3285 $error++;
3287 }
3288 print '. ';
3289 } else {
3290 $error++;
3292 }
3293 $i++;
3294 }
3295 } else {
3296 print $langs->trans('AlreadyDone')."<br>\n";
3297 }
3298
3299 if ($error == 0) {
3300 $sqlDelete = "DELETE FROM ".MAIN_DB_PREFIX."element_element WHERE sourcetype = 'commande' AND targettype = 'delivery'";
3301 $db->query($sqlDelete);
3302
3303 $db->commit();
3304
3305 // DDL commands must not be inside a transaction
3306 $sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."livraison DROP COLUMN fk_expedition";
3307 $db->query($sqlDrop);
3308 } else {
3310 $db->rollback();
3311 }
3312 } else {
3314 $db->rollback();
3315 }
3316 } else {
3317 print $langs->trans('AlreadyDone')."<br>\n";
3318 }
3319
3320 print '</td></tr>';
3321}
3322
3332function migrate_shipping_delivery2($db, $langs, $conf)
3333{
3334 print '<tr><td colspan="4">';
3335
3336 print '<br>';
3337 print '<b>'.$langs->trans('MigrationShippingDelivery2')."</b><br>\n";
3338
3339 $error = 0;
3340
3341 dolibarr_install_syslog("upgrade2::migrate_shipping_delivery2");
3342
3343 $db->begin();
3344
3345 $sqlSelect = "SELECT l.rowid as delivery_id, e.ref_customer, e.date_delivery";
3346 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."livraison as l,";
3347 $sqlSelect .= " ".MAIN_DB_PREFIX."element_element as el,";
3348 $sqlSelect .= " ".MAIN_DB_PREFIX."expedition as e";
3349 $sqlSelect .= " WHERE l.rowid = el.fk_target";
3350 $sqlSelect .= " AND el.targettype = 'delivery'";
3351 $sqlSelect .= " AND e.rowid = el.fk_source AND el.sourcetype = 'shipping'";
3352 $sqlSelect .= " AND (e.ref_customer IS NOT NULL OR e.date_delivery IS NOT NULL)"; // Useless to process this record if both are null
3353 // Add condition to know if we never migrate this record
3354 $sqlSelect .= " AND (l.ref_customer IS NULL".($db->type != 'pgsql' ? " or l.ref_customer = ''" : "").")";
3355 $sqlSelect .= " AND (l.date_delivery IS NULL".($db->type != 'pgsql' ? " or l.date_delivery = ''" : "").")";
3356
3357 $resql = $db->query($sqlSelect);
3358 if ($resql) {
3359 $i = 0;
3360 $num = $db->num_rows($resql);
3361
3362 if ($num) {
3363 while ($i < $num) {
3364 $obj = $db->fetch_object($resql);
3365
3366 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
3367 $sqlUpdate .= " ref_customer = '".$db->escape($obj->ref_customer)."',";
3368 $sqlUpdate .= " date_delivery = ".($obj->date_delivery ? "'".$db->escape($obj->date_delivery)."'" : 'null');
3369 $sqlUpdate .= " WHERE rowid = ".((int) $obj->delivery_id);
3370
3371 $result = $db->query($sqlUpdate);
3372 if (!$result) {
3373 $error++;
3375 }
3376 print '. ';
3377 $i++;
3378 }
3379 } else {
3380 print $langs->trans('AlreadyDone')."<br>\n";
3381 }
3382
3383 if ($error == 0) {
3384 $db->commit();
3385 } else {
3387 $db->rollback();
3388 }
3389 } else {
3391 $db->rollback();
3392 }
3393
3394 print '</td></tr>';
3395}
3396
3405function migrate_actioncomm_element($db, $langs, $conf)
3406{
3407 print '<tr><td colspan="4">';
3408
3409 print '<br>';
3410 print '<b>'.$langs->trans('MigrationActioncommElement')."</b><br>\n";
3411
3412 $elements = array(
3413 'propal' => 'propalrowid',
3414 'order' => 'fk_commande',
3415 'invoice' => 'fk_facture',
3416 'contract' => 'fk_contract',
3417 'order_supplier' => 'fk_supplier_order',
3418 'invoice_supplier' => 'fk_supplier_invoice'
3419 );
3420
3421 foreach ($elements as $type => $field) {
3422 $result = $db->DDLDescTable(MAIN_DB_PREFIX."actioncomm", $field);
3423 $obj = $db->fetch_object($result);
3424 if ($obj) {
3425 dolibarr_install_syslog("upgrade2::migrate_actioncomm_element field=".$field);
3426
3427 $db->begin();
3428
3429 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ";
3430 $sql .= "fk_element = ".$db->sanitize($field).", elementtype = '".$db->escape($type)."'";
3431 $sql .= " WHERE ".$db->sanitize($field)." IS NOT NULL";
3432 $sql .= " AND fk_element IS NULL";
3433 $sql .= " AND elementtype IS NULL";
3434
3435 $resql = $db->query($sql);
3436 if ($resql) {
3437 $db->commit();
3438
3439 // DDL commands must not be inside a transaction
3440 // We will drop at next version because a migrate should be runnable several times if it fails.
3441 //$sqlDrop = "ALTER TABLE ".MAIN_DB_PREFIX."actioncomm DROP COLUMN ".$field;
3442 //$db->query($sqlDrop);
3443 //print '. ';
3444 } else {
3446 $db->rollback();
3447 }
3448 } else {
3449 print $langs->trans('AlreadyDone')."<br>\n";
3450 }
3451 }
3452
3453 print '</td></tr>';
3454}
3455
3464function migrate_mode_reglement($db, $langs, $conf)
3465{
3466 print '<tr><td colspan="4">';
3467
3468 print '<br>';
3469 print '<b>'.$langs->trans('MigrationPaymentMode')."</b><br>\n";
3470
3471 $elements = array(
3472 'old_id' => array(5, 8, 9, 10, 11),
3473 'new_id' => array(50, 51, 52, 53, 54),
3474 'code' => array('VAD', 'TRA', 'LCR', 'FAC', 'PRO'),
3475 'tables' => array('commande_fournisseur', 'commande', 'facture_rec', 'facture', 'propal')
3476 );
3477 $count = 0;
3478
3479 foreach ($elements['old_id'] as $key => $old_id) {
3480 $error = 0;
3481
3482 dolibarr_install_syslog("upgrade2::migrate_mode_reglement code=".$elements['code'][$key]);
3483
3484 $sqlSelect = "SELECT id";
3485 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."c_paiement";
3486 $sqlSelect .= " WHERE id = ".((int) $old_id);
3487 $sqlSelect .= " AND code = '".$db->escape($elements['code'][$key])."'";
3488
3489 $resql = $db->query($sqlSelect);
3490 if ($resql) {
3491 $num = $db->num_rows($resql);
3492 if ($num) {
3493 $count++;
3494
3495 $db->begin();
3496
3497 $sqla = "UPDATE ".MAIN_DB_PREFIX."paiement SET";
3498 $sqla .= " fk_paiement = ".((int) $elements['new_id'][$key]);
3499 $sqla .= " WHERE fk_paiement = ".((int) $old_id);
3500 $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])."')";
3501 $resqla = $db->query($sqla);
3502
3503 $sql = "UPDATE ".MAIN_DB_PREFIX."c_paiement SET";
3504 $sql .= " id = ".((int) $elements['new_id'][$key]);
3505 $sql .= " WHERE id = ".((int) $old_id);
3506 $sql .= " AND code = '".$db->escape($elements['code'][$key])."'";
3507 $resql = $db->query($sql);
3508
3509 if ($resqla && $resql) {
3510 foreach ($elements['tables'] as $table) {
3511 $sql = "UPDATE ".MAIN_DB_PREFIX.$db->sanitize($table)." SET ";
3512 $sql .= "fk_mode_reglement = ".((int) $elements['new_id'][$key]);
3513 $sql .= " WHERE fk_mode_reglement = ".((int) $old_id);
3514
3515 $resql = $db->query($sql);
3516 if (!$resql) {
3518 $error++;
3519 }
3520 print '. ';
3521 }
3522
3523 if (!$error) {
3524 $db->commit();
3525 } else {
3527 $db->rollback();
3528 }
3529 } else {
3531 $db->rollback();
3532 }
3533 }
3534 }
3535 }
3536
3537 if ($count == 0) {
3538 print $langs->trans('AlreadyDone')."<br>\n";
3539 }
3540
3541
3542 print '</td></tr>';
3543}
3544
3545
3554function migrate_clean_association($db, $langs, $conf)
3555{
3556 $result = $db->DDLDescTable(MAIN_DB_PREFIX."categorie_association");
3557 if ($result) { // result defined for version 3.2 or -
3558 $obj = $db->fetch_object($result);
3559 if ($obj) { // It table categorie_association exists
3560 $couples = array();
3561 $children = array();
3562 $sql = "SELECT fk_categorie_mere, fk_categorie_fille";
3563 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3564 dolibarr_install_syslog("upgrade: search duplicate");
3565 $resql = $db->query($sql);
3566 if ($resql) {
3567 $num = $db->num_rows($resql);
3568 while ($obj = $db->fetch_object($resql)) {
3569 if (!isset($children[$obj->fk_categorie_fille])) { // Only one record as child (a child has only on parent).
3570 if ($obj->fk_categorie_mere != $obj->fk_categorie_fille) {
3571 $children[$obj->fk_categorie_fille] = 1; // Set record for this child
3572 $couples[$obj->fk_categorie_mere.'_'.$obj->fk_categorie_fille] = array('mere' => $obj->fk_categorie_mere, 'fille' => $obj->fk_categorie_fille);
3573 }
3574 }
3575 }
3576
3577 dolibarr_install_syslog("upgrade: result is num=".$num." count(couples)=".count($couples));
3578
3579 // If there is duplicates couples or child with two parents
3580 if (count($couples) > 0 && $num > count($couples)) {
3581 $error = 0;
3582
3583 $db->begin();
3584
3585 // We delete all
3586 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_association";
3587 dolibarr_install_syslog("upgrade: delete association");
3588 $resqld = $db->query($sql);
3589 if ($resqld) {
3590 // And we insert only each record once
3591 foreach ($couples as $key => $val) {
3592 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_association(fk_categorie_mere,fk_categorie_fille)";
3593 $sql .= " VALUES(".((int) $val['mere']).", ".((int) $val['fille']).")";
3594 dolibarr_install_syslog("upgrade: insert association");
3595 $resqli = $db->query($sql);
3596 if (!$resqli) {
3597 $error++;
3598 }
3599 }
3600 }
3601
3602 if (!$error) {
3603 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3604 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Success").' ('.$num.'=>'.count($couples).')</td></tr>';
3605 $db->commit();
3606 } else {
3607 print '<tr><td>'.$langs->trans("MigrationCategorieAssociation").'</td>';
3608 print '<td class="right">'.$langs->trans("RemoveDuplicates").' '.$langs->trans("Failed").'</td></tr>';
3609 $db->rollback();
3610 }
3611 }
3612 } else {
3613 print '<tr><td>'.$langs->trans("Error").'</td>';
3614 print '<td class="right"><div class="error">'.$db->lasterror().'</div></td></tr>';
3615 }
3616 }
3617 }
3618}
3619
3620
3630{
3631 print '<tr><td colspan="4">';
3632
3633 print '<br>';
3634 print '<b>'.$langs->trans('MigrationCategorieAssociation')."</b><br>\n";
3635
3636 $error = 0;
3637
3638 if ($db->DDLInfoTable(MAIN_DB_PREFIX."categorie_association")) {
3639 dolibarr_install_syslog("upgrade2::migrate_categorie_association");
3640
3641 $db->begin();
3642
3643 $sqlSelect = "SELECT fk_categorie_mere, fk_categorie_fille";
3644 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."categorie_association";
3645
3646 $resql = $db->query($sqlSelect);
3647 if ($resql) {
3648 $i = 0;
3649 $num = $db->num_rows($resql);
3650
3651 if ($num) {
3652 while ($i < $num) {
3653 $obj = $db->fetch_object($resql);
3654
3655 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."categorie SET ";
3656 $sqlUpdate .= "fk_parent = ".((int) $obj->fk_categorie_mere);
3657 $sqlUpdate .= " WHERE rowid = ".((int) $obj->fk_categorie_fille);
3658
3659 $result = $db->query($sqlUpdate);
3660 if (!$result) {
3661 $error++;
3663 }
3664 print '. ';
3665 $i++;
3666 }
3667 } else {
3668 print $langs->trans('AlreadyDone')."<br>\n";
3669 }
3670
3671 if (!$error) {
3672 $db->commit();
3673 } else {
3674 $db->rollback();
3675 }
3676 } else {
3678 $db->rollback();
3679 }
3680 } else {
3681 print $langs->trans('AlreadyDone')."<br>\n";
3682 }
3683
3684 print '</td></tr>';
3685}
3686
3695function migrate_event_assignement($db, $langs, $conf)
3696{
3697 print '<tr><td colspan="4">';
3698
3699 print '<br>';
3700 print '<b>'.$langs->trans('MigrationEvents')."</b><br>\n";
3701
3702 $error = 0;
3703
3704 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3705
3706 $db->begin();
3707
3708 $sqlSelect = "SELECT a.id, a.fk_user_action";
3709 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3710 $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";
3711 $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')";
3712 $sqlSelect .= " ORDER BY a.id";
3713 //print $sqlSelect;
3714
3715 $resql = $db->query($sqlSelect);
3716 if ($resql) {
3717 $i = 0;
3718 $num = $db->num_rows($resql);
3719
3720 if ($num) {
3721 while ($i < $num) {
3722 $obj = $db->fetch_object($resql);
3723
3724 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3725 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'user', ".((int) $obj->fk_user_action).")";
3726
3727 $result = $db->query($sqlUpdate);
3728 if (!$result) {
3729 $error++;
3731 }
3732 print '. ';
3733 $i++;
3734 }
3735 } else {
3736 print $langs->trans('AlreadyDone')."<br>\n";
3737 }
3738
3739 if (!$error) {
3740 $db->commit();
3741 } else {
3742 $db->rollback();
3743 }
3744 } else {
3746 $db->rollback();
3747 }
3748
3749
3750 print '</td></tr>';
3751}
3752
3762{
3763 print '<tr><td colspan="4">';
3764
3765 print '<br>';
3766 print '<b>'.$langs->trans('MigrationEventsContact')."</b><br>\n";
3767
3768 $error = 0;
3769
3770 dolibarr_install_syslog("upgrade2::migrate_event_assignement");
3771
3772 $db->begin();
3773
3774 $sqlSelect = "SELECT a.id, a.fk_contact";
3775 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
3776 $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";
3777 $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')";
3778 $sqlSelect .= " ORDER BY a.id";
3779 //print $sqlSelect;
3780
3781 $resql = $db->query($sqlSelect);
3782 if ($resql) {
3783 $i = 0;
3784 $num = $db->num_rows($resql);
3785
3786 if ($num) {
3787 while ($i < $num) {
3788 $obj = $db->fetch_object($resql);
3789
3790 $sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
3791 $sqlUpdate .= "VALUES(".((int) $obj->id).", 'socpeople', ".((int) $obj->fk_contact).")";
3792
3793 $result = $db->query($sqlUpdate);
3794 if (!$result) {
3795 $error++;
3797 }
3798 print '. ';
3799 $i++;
3800 }
3801 } else {
3802 print $langs->trans('AlreadyDone')."<br>\n";
3803 }
3804
3805 if (!$error) {
3806 $db->commit();
3807 } else {
3808 $db->rollback();
3809 }
3810 } else {
3812 $db->rollback();
3813 }
3814
3815
3816 print '</td></tr>';
3817}
3818
3819
3828function migrate_reset_blocked_log($db, $langs, $conf)
3829{
3830 global $user;
3831
3832 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
3833
3834 print '<tr><td colspan="4">';
3835
3836 print '<br>';
3837 print '<b>'.$langs->trans('MigrationResetBlockedLog')."</b><br>\n";
3838
3839 $error = 0;
3840
3841 dolibarr_install_syslog("upgrade2::migrate_reset_blocked_log");
3842
3843 $db->begin();
3844
3845 $sqlSelect = "SELECT DISTINCT entity";
3846 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."blockedlog";
3847
3848 //print $sqlSelect;
3849
3850 $resql = $db->query($sqlSelect);
3851 if ($resql) {
3852 $i = 0;
3853 $num = $db->num_rows($resql);
3854
3855 if ($num) {
3856 while ($i < $num) {
3857 $obj = $db->fetch_object($resql);
3858
3859 print 'Process entity '.$obj->entity;
3860
3861 $sqlSearch = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."blockedlog WHERE action = 'MODULE_SET' and entity = ".((int) $obj->entity);
3862 $resqlSearch = $db->query($sqlSearch);
3863 if ($resqlSearch) {
3864 $objSearch = $db->fetch_object($resqlSearch);
3865 //var_dump($objSearch);
3866 if ($objSearch && $objSearch->nb == 0) {
3867 print ' - Record for entity must be reset...';
3868
3869 $sqlUpdate = "DELETE FROM ".MAIN_DB_PREFIX."blockedlog";
3870 $sqlUpdate .= " WHERE entity = ".((int) $obj->entity);
3871 $resqlUpdate = $db->query($sqlUpdate);
3872 if (!$resqlUpdate) {
3873 $error++;
3875 } else {
3876 // Add set line
3877 $object = new stdClass();
3878 $object->id = 0;
3879 $object->element = 'module';
3880 $object->ref = 'systemevent';
3881 $object->entity = $obj->entity;
3882 $object->date = dol_now();
3883
3884 $b = new BlockedLog($db);
3885 $b->setObjectData($object, 'MODULE_SET', 0, $user, 0);
3886
3887 $res = $b->create($user);
3888 if ($res <= 0) {
3889 $error++;
3890 }
3891 }
3892 } else {
3893 print ' - '.$langs->trans('AlreadyDone').'<br>';
3894 }
3895 } else {
3897 }
3898
3899 $i++;
3900 }
3901 } else {
3902 print $langs->trans('NothingToDo')."<br>\n";
3903 }
3904
3905 if (!$error) {
3906 $db->commit();
3907 } else {
3908 $db->rollback();
3909 }
3910 } else {
3912 $db->rollback();
3913 }
3914
3915 print '</td></tr>';
3916}
3917
3918
3927function migrate_remise_entity($db, $langs, $conf)
3928{
3929 print '<tr><td colspan="4">';
3930
3931 print '<br>';
3932 print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\n";
3933
3934 $error = 0;
3935
3936 dolibarr_install_syslog("upgrade2::migrate_remise_entity");
3937
3938 $db->begin();
3939
3940 $sqlSelect = "SELECT sr.rowid, s.entity";
3941 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s";
3942 $sqlSelect .= " WHERE sr.fk_soc = s.rowid and sr.entity != s.entity";
3943
3944 //print $sqlSelect;
3945
3946 $resql = $db->query($sqlSelect);
3947 if ($resql) {
3948 $i = 0;
3949 $num = $db->num_rows($resql);
3950
3951 if ($num) {
3952 while ($i < $num) {
3953 $obj = $db->fetch_object($resql);
3954
3955 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET";
3956 $sqlUpdate .= " entity = ".$obj->entity;
3957 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
3958
3959 $result = $db->query($sqlUpdate);
3960 if (!$result) {
3961 $error++;
3963 }
3964
3965 print '. ';
3966 $i++;
3967 }
3968 } else {
3969 print $langs->trans('AlreadyDone')."<br>\n";
3970 }
3971
3972 if (!$error) {
3973 $db->commit();
3974 } else {
3975 $db->rollback();
3976 }
3977 } else {
3979 $db->rollback();
3980 }
3981
3982 print '</td></tr>';
3983}
3984
3994{
3995 print '<tr><td colspan="4">';
3996
3997 print '<br>';
3998 print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\n";
3999
4000 $error = 0;
4001
4002 dolibarr_install_syslog("upgrade2::migrate_remise_except_entity");
4003
4004 $db->begin();
4005
4006 $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line";
4007 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
4008 //print $sqlSelect;
4009
4010 $resql = $db->query($sqlSelect);
4011 if ($resql) {
4012 $i = 0;
4013 $num = $db->num_rows($resql);
4014
4015 if ($num) {
4016 while ($i < $num) {
4017 $obj = $db->fetch_object($resql);
4018
4019 if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) {
4020 $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture);
4021
4022 $sqlSelect2 = "SELECT f.entity";
4023 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
4024 $sqlSelect2 .= " WHERE f.rowid = ".((int) $fk_facture);
4025 } elseif (!empty($obj->fk_facture_line)) {
4026 $sqlSelect2 = "SELECT f.entity";
4027 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd";
4028 $sqlSelect2 .= " WHERE fd.rowid = ".((int) $obj->fk_facture_line);
4029 $sqlSelect2 .= " AND fd.fk_facture = f.rowid";
4030 } else {
4031 $sqlSelect2 = "SELECT s.entity";
4032 $sqlSelect2 .= " FROM ".MAIN_DB_PREFIX."societe as s";
4033 $sqlSelect2 .= " WHERE s.rowid = ".((int) $obj->fk_soc);
4034 }
4035
4036 $resql2 = $db->query($sqlSelect2);
4037 if ($resql2) {
4038 if ($db->num_rows($resql2) > 0) {
4039 $obj2 = $db->fetch_object($resql2);
4040
4041 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET";
4042 $sqlUpdate .= " entity = ".((int) $obj2->entity);
4043 $sqlUpdate .= " WHERE rowid = ".((int) $obj->rowid);
4044
4045 $result = $db->query($sqlUpdate);
4046 if (!$result) {
4047 $error++;
4049 }
4050 }
4051 } else {
4052 $error++;
4054 }
4055
4056 print '. ';
4057 $i++;
4058 }
4059 } else {
4060 print $langs->trans('AlreadyDone')."<br>\n";
4061 }
4062
4063 if (!$error) {
4064 $db->commit();
4065 } else {
4066 $db->rollback();
4067 }
4068 } else {
4070 $db->rollback();
4071 }
4072
4073
4074 print '</td></tr>';
4075}
4076
4085function migrate_user_rights_entity($db, $langs, $conf)
4086{
4087 print '<tr><td colspan="4">';
4088
4089 print '<b>'.$langs->trans('MigrationUserRightsEntity')."</b><br>\n";
4090
4091 $error = 0;
4092
4093 dolibarr_install_syslog("upgrade2::migrate_user_rights_entity");
4094
4095 $db->begin();
4096
4097 $sqlSelect = "SELECT u.rowid, u.entity";
4098 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."user as u";
4099 $sqlSelect .= " WHERE u.entity > 1";
4100 //print $sqlSelect;
4101
4102 $resql = $db->query($sqlSelect);
4103 if ($resql) {
4104 $i = 0;
4105 $num = $db->num_rows($resql);
4106
4107 if ($num) {
4108 while ($i < $num) {
4109 $obj = $db->fetch_object($resql);
4110
4111 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."user_rights SET";
4112 $sqlUpdate .= " entity = ".((int) $obj->entity);
4113 $sqlUpdate .= " WHERE fk_user = ".((int) $obj->rowid);
4114
4115 $result = $db->query($sqlUpdate);
4116 if (!$result) {
4117 $error++;
4119 }
4120
4121 print '. ';
4122 $i++;
4123 }
4124 } else {
4125 print $langs->trans('AlreadyDone')."<br>\n";
4126 }
4127
4128 if (!$error) {
4129 $db->commit();
4130 } else {
4131 $db->rollback();
4132 }
4133 } else {
4135 $db->rollback();
4136 }
4137
4138
4139 print '</td></tr>';
4140}
4141
4151{
4152 print '<tr><td colspan="4">';
4153
4154 print '<b>'.$langs->trans('MigrationUserGroupRightsEntity')."</b><br>\n";
4155
4156 $error = 0;
4157
4158 dolibarr_install_syslog("upgrade2::migrate_usergroup_rights_entity");
4159
4160 $db->begin();
4161
4162 $sqlSelect = "SELECT u.rowid, u.entity";
4163 $sqlSelect .= " FROM ".MAIN_DB_PREFIX."usergroup as u";
4164 $sqlSelect .= " WHERE u.entity > 1";
4165 //print $sqlSelect;
4166
4167 $resql = $db->query($sqlSelect);
4168 if ($resql) {
4169 $i = 0;
4170 $num = $db->num_rows($resql);
4171
4172 if ($num) {
4173 while ($i < $num) {
4174 $obj = $db->fetch_object($resql);
4175
4176 $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."usergroup_rights SET";
4177 $sqlUpdate .= " entity = ".((int) $obj->entity);
4178 $sqlUpdate .= " WHERE fk_usergroup = ".((int) $obj->rowid);
4179
4180 $result = $db->query($sqlUpdate);
4181 if (!$result) {
4182 $error++;
4184 }
4185
4186 print '. ';
4187 $i++;
4188 }
4189 } else {
4190 print $langs->trans('AlreadyDone')."<br>\n";
4191 }
4192
4193 if (!$error) {
4194 $db->commit();
4195 } else {
4196 $db->rollback();
4197 }
4198 } else {
4200 $db->rollback();
4201 }
4202
4203
4204 print '</td></tr>';
4205}
4206
4217function migrate_rename_directories($db, $langs, $conf, $oldname, $newname)
4218{
4219 dolibarr_install_syslog("upgrade2::migrate_rename_directories");
4220
4221 if (is_dir(DOL_DATA_ROOT.$oldname) && !file_exists(DOL_DATA_ROOT.$newname)) {
4222 dolibarr_install_syslog("upgrade2::migrate_rename_directories move ".DOL_DATA_ROOT.$oldname.' into '.DOL_DATA_ROOT.$newname);
4223 @rename(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname);
4224 } else {
4225 // If new directory already exists, we copy content of old one intotnew one
4226 dolCopyDir(DOL_DATA_ROOT.$oldname, DOL_DATA_ROOT.$newname, '0', 1);
4227 }
4228}
4229
4230
4239function migrate_delete_old_files($db, $langs, $conf)
4240{
4241 $ret = true;
4242
4243 dolibarr_install_syslog("upgrade2::migrate_delete_old_files");
4244
4245 // List of files to delete
4246 $filetodeletearray = array(
4247 '/core/ajax/ajaxcompanies.php',
4248 '/core/triggers/interface_demo.class.php',
4249 '/core/menus/barre_left/default.php',
4250 '/core/menus/barre_top/default.php',
4251 '/core/modules/modComptabiliteExpert.class.php',
4252 '/core/modules/modCommercial.class.php',
4253 '/core/modules/modPaybox.class.php',
4254 '/core/modules/modProduit.class.php',
4255 '/core/modules/modSkype.class.php',
4256 '/core/modules/modactivite.class.php', // A file from an external module that should not be here
4257 '/core/triggers/interface_modWebcalendar_Webcalsynchro.class.php',
4258 '/core/triggers/interface_modCommande_Ecotax.class.php',
4259 '/core/triggers/interface_modCommande_fraisport.class.php',
4260 '/core/triggers/interface_modPropale_PropalWorkflow.class.php',
4261 '/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php', // now has position 99
4262 '/core/triggers/interface_99_modWebhook_WebhookTriggers.class.php',
4263 '/core/triggers/interface_99_modZapier_ZapierTriggers.class.php',
4264 '/core/menus/smartphone/iphone.lib.php',
4265 '/core/menus/smartphone/iphone_backoffice.php',
4266 '/core/menus/smartphone/iphone_frontoffice.php',
4267 '/core/menus/standard/auguria_backoffice.php',
4268 '/core/menus/standard/auguria_frontoffice.php',
4269 '/core/menus/standard/eldy_backoffice.php',
4270 '/core/menus/standard/eldy_frontoffice.php',
4271 '/core/modules/export/export_excel.modules.php',
4272 '/core/modules/export/export_csv.modules.php',
4273 '/core/modules/export/exportcsv.modules.php',
4274 '/core/modules/export/export_excel2007new.modules.php',
4275 '/core/modules/facture/pdf_crabe.modules.php',
4276 '/core/modules/facture/pdf_oursin.modules.php',
4277 '/core/modules/mailings/contacts2.modules.php',
4278 '/core/modules/mailings/contacts3.modules.php',
4279 '/core/modules/mailings/contacts4.modules.php',
4280 '/core/modules/mailings/framboise.modules.php',
4281 '/core/modules/mailings/dolibarr_services_expired.modules.php',
4282 '/core/modules/mailings/peche.modules.php',
4283 '/core/modules/mailings/poire.modules.php',
4284 '/core/modules/mailings/kiwi.modules.php',
4285 '/core/modules/syslog/mod_syslog_chromephp.php',
4286 '/core/modules/syslog/mod_syslog_firephp.php',
4287 '/core/modules/syslog/logHandlerInterface.php',
4288 '/core/boxes/box_members.php',
4289
4290 '/includes/restler/framework/Luracast/Restler/Data/Object.php',
4291 '/includes/nusoap/lib/class.*',
4292 '/phenix/inc/triggers/interface_modPhenix_Phenixsynchro.class.php',
4293 '/webcalendar/inc/triggers/interface_modWebcalendar_webcalsynchro.class.php',
4294
4295 '/api/class/api_generic.class.php',
4296 '/asterisk/cidlookup.php',
4297 '/categories/class/api_category.class.php',
4298 '/categories/class/api_deprecated_category.class.php',
4299 '/compta/facture/class/api_invoice.class.php',
4300 '/commande/class/api_commande.class.php',
4301 '/partnership/class/api_partnership.class.php',
4302 '/product/class/api_product.class.php',
4303 '/recruitment/class/api_recruitment.class.php',
4304 '/societe/class/api_contact.class.php',
4305 '/societe/class/api_thirdparty.class.php',
4306 '/support/online.php',
4307 '/takepos/class/actions_takepos.class.php',
4308 '/user/class/api_user.class.php',
4309
4310 '/install/mysql/tables/llx_c_ticketsup_category.key.sql',
4311 '/install/mysql/tables/llx_c_ticketsup_category.sql',
4312 '/install/mysql/tables/llx_c_ticketsup_severity.key.sql',
4313 '/install/mysql/tables/llx_c_ticketsup_severity.sql',
4314 '/install/mysql/tables/llx_c_ticketsup_type.key.sql',
4315 '/install/mysql/tables/llx_c_ticketsup_type.sql'
4316 );
4317
4318 /*
4319 print '<tr><td colspan="4">';
4320 print '<b>'.$langs->trans('DeleteOldFiles')."</b><br>\n";
4321 print '</td></tr>';
4322 */
4323
4324 foreach ($filetodeletearray as $filetodelete) {
4325 //print '<b>'DOL_DOCUMENT_ROOT.$filetodelete."</b><br>\n";
4326 if (preg_match('/\*/', $filetodelete) || file_exists(DOL_DOCUMENT_ROOT.$filetodelete)) {
4327 //print "Process file ".$filetodelete."\n";
4328 $result = dol_delete_file(DOL_DOCUMENT_ROOT.$filetodelete, 0, (preg_match('/\*/', $filetodelete) ? 1 : 0), 0, null, true, 0);
4329 if (!$result) {
4330 $langs->load("errors");
4331 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteFile", DOL_DOCUMENT_ROOT.$filetodelete);
4332 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4333 } else {
4334 //print $langs->trans("FileWasRemoved", $filetodelete).'<br>';
4335 }
4336 }
4337 }
4338
4339 return $ret;
4340}
4341
4350function migrate_delete_old_dir($db, $langs, $conf)
4351{
4352 $ret = true;
4353
4354 dolibarr_install_syslog("upgrade2::migrate_delete_old_dir");
4355
4356 // List of files to delete
4357 $filetodeletearray = array(
4358 DOL_DOCUMENT_ROOT.'/core/modules/facture/terre',
4359 DOL_DOCUMENT_ROOT.'/core/modules/facture/mercure',
4360 );
4361
4362 // On linux, we can also removed old directory with a different case than new directory.
4363 if (!empty($_SERVER["WINDIR"])) {
4364 $filetodeletearray[] = DOL_DOCUMENT_ROOT.'/includes/phpoffice/PhpSpreadsheet';
4365 }
4366
4367 foreach ($filetodeletearray as $filetodelete) {
4368 $result = 1;
4369 if (file_exists($filetodelete)) {
4370 $result = dol_delete_dir_recursive($filetodelete);
4371 }
4372 if (!$result) {
4373 $langs->load("errors");
4374 print '<div class="error">'.$langs->trans("Error").': '.$langs->trans("ErrorFailToDeleteDir", $filetodelete);
4375 print ' '.$langs->trans("RemoveItManuallyAndPressF5ToContinue").'</div>';
4376 }
4377 }
4378
4379 return $ret;
4380}
4381
4382
4395function migrate_reload_modules($db, $langs, $conf, $listofmodule = array(), $force = 0)
4396{
4397 global $user;
4398
4399 if (count($listofmodule) == 0) {
4400 return 0;
4401 }
4402
4403 if (!is_object($user)) {
4404 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4405 $user = new User($db); // To avoid error during migration
4406 }
4407
4408 dolibarr_install_syslog("upgrade2::migrate_reload_modules force=".$force.", listofmodule=".implode(',', array_keys($listofmodule)), LOG_NOTICE);
4409
4410 $reloadactionformodules = array(
4411 'MAIN_MODULE_AGENDA' => array('class' => 'modAgenda', 'remove' => 1),
4412 'MAIN_MODULE_API' => array('class' => 'modApi'),
4413 'MAIN_MODULE_BARCODE' => array('class' => 'modBarcode', 'remove' => 1),
4414 'MAIN_MODULE_BLOCKEDLOG' => array('class' => 'modBlockedLog', 'deleteinsertmenus' => 1),
4415 'MAIN_MODULE_CRON' => array('class' => 'modCron', 'remove' => 1),
4416 'MAIN_MODULE_SOCIETE' => array('class' => 'modSociete', 'remove' => 1),
4417 'MAIN_MODULE_PRODUIT' => array('class' => 'modProduct'),
4418 'MAIN_MODULE_SERVICE' => array('class' => 'modService'),
4419 'MAIN_MODULE_COMMANDE' => array('class' => 'modCommande'),
4420 'MAIN_MODULE_DON' => array('class' => 'modDon'),
4421 'MAIN_MODULE_FACTURE' => array('class' => 'modFacture'),
4422 'MAIN_MODULE_FICHEINTER' => array('class' => 'modFicheinter'),
4423 'MAIN_MODULE_FOURNISSEUR' => array('class' => 'modFournisseur'),
4424 'MAIN_MODULE_EXPEDITION' => array('class' => 'modExpedition'),
4425 'MAIN_MODULE_EXPENSEREPORT' => array('class' => 'modExpenseReport'),
4426 'MAIN_MODULE_EVENTORGANIZATION' => array('class' => 'modEventOrganization', 'remove' => 1),
4427 'MAIN_MODULE_ECM' => array('class' => 'modECM', 'remove' => 1),
4428 'MAIN_MODULE_HOLIDAY' => array('class' => 'modHoliday', 'remove' => 1),
4429 'MAIN_MODULE_KNOWLEDGEMANAGEMENT' => array('class' => 'modKnowledgeManagement', 'remove' => 1),
4430 'MAIN_MODULE_LOAN' => array('class' => 'modLoan', 'remove' => 1),
4431 'MAIN_MODULE_PROPAL' => array('class' => 'modPropale'),
4432 'MAIN_MODULE_SUPPLIERPROPOSAL' => array('class' => 'modSupplierProposal', 'remove' => 1),
4433 'MAIN_MODULE_OPENSURVEY' => array('class' => 'modOpenSurvey', 'remove' => 1),
4434 'MAIN_MODULE_PRODUCTBATCH' => array('class' => 'modProductBatch', 'remove' => 1),
4435 'MAIN_MODULE_TAKEPOS' => array('class' => 'modTakePos', 'remove' => 1),
4436 'MAIN_MODULE_VARIANTS' => array('class' => 'modVariants', 'remove' => 1),
4437 'MAIN_MODULE_EMAILCOLLECTOR' => array('class' => 'modEmailCollector', 'remove' => 1),
4438 );
4439
4440 foreach ($listofmodule as $moduletoreload => $reloadmode) { // reloadmodule can be 'noboxes', 'newboxdefonly', 'forceactivate'
4441 $modulekey = preg_replace('/^MAIN_MODULE_/', '', $moduletoreload);
4442
4443 if (empty($moduletoreload) || (!isModEnabled(strtolower($modulekey)) && !$force)) {
4444 continue; // Discard reload if module not enabled
4445 }
4446
4447 $mod = null;
4448
4449 if (!empty($reloadactionformodules[$moduletoreload])) {
4450 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreload." with mode ".$reloadmode);
4451
4452 $val = $reloadactionformodules[$moduletoreload];
4453 $classformodule = $val['class'];
4454 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/'.$classformodule.'.class.php';
4455 if ($res) {
4456 $mod = new $classformodule($db);
4457 if (!empty($val['remove'])) {
4458 $mod->remove('noboxes');
4459 }
4460 if (!empty($val['deleteinsertmenus'])) {
4461 // We only reload menus
4462 $mod->delete_menus();
4463 $mod->insert_menus();
4464 } else {
4465 $mod->init($reloadmode);
4466 }
4467 }
4468 } else { // Other generic cases/modules
4469 $reg = array();
4470 preg_match('/([a-zA-Z0-9]+)/', $modulekey, $reg);
4471 if (!empty($reg[1])) {
4472 if (strtoupper($moduletoreload) == $moduletoreload) { // If key has at least one uppercase
4473 $moduletoreloadshort = ucfirst(strtolower($reg[1]));
4474 } else { // If key is a mix of up and low case
4475 $moduletoreloadshort = $reg[1];
4476 }
4477
4478 dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate module ".$moduletoreloadshort." with mode ".$reloadmode." (generic code)", LOG_NOTICE);
4479
4480 $res = @include_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php';
4481 if ($res) {
4482 $classname = 'mod'.$moduletoreloadshort;
4483 $mod = new $classname($db);
4484 '@phan-var-force DolibarrModules $mod';
4485
4486 //$mod->remove('noboxes');
4487 $mod->delete_menus(); // We must delete to be sure it is inserted with new values
4488 $mod->init($reloadmode);
4489 } else {
4490 dolibarr_install_syslog('Failed to include '.DOL_DOCUMENT_ROOT.'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4491
4492 $res = @dol_include_once(strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php');
4493 if ($res) {
4494 $classname = 'mod'.$moduletoreloadshort;
4495 $mod = new $classname($db);
4496 '@phan-var-force DolibarrModules $mod';
4497 $mod->init($reloadmode);
4498 } else {
4499 dolibarr_install_syslog('Failed to include '.strtolower($moduletoreloadshort).'/core/modules/mod'.$moduletoreloadshort.'.class.php', LOG_ERR);
4500 print "Error, can't find module with name ".$moduletoreload."\n";
4501 return -1;
4502 }
4503 }
4504 } else {
4505 dolibarr_install_syslog("Error, can't find module with name ".$moduletoreload, LOG_ERR);
4506 print "Error, can't find module with name ".$moduletoreload."\n";
4507 return -1;
4508 }
4509 }
4510
4511 if (!empty($mod) && is_object($mod)) {
4512 print '<tr class="trforrunsql"><td colspan="4">';
4513 print '<b>'.$langs->trans('Upgrade').'</b>: ';
4514 print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated
4515 print "<!-- (".$reloadmode.") -->";
4516 print "<br>\n";
4517 print '</td></tr>';
4518 }
4519 }
4520
4521 return 1;
4522}
4523
4524
4525
4534function migrate_reload_menu($db, $langs, $conf)
4535{
4536 global $conf;
4537 dolibarr_install_syslog("upgrade2::migrate_reload_menu");
4538
4539 // Define list of menu handlers to initialize
4540 $listofmenuhandler = array();
4541 if (getDolGlobalString('MAIN_MENU_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENU_SMARTPHONE') == 'auguria_menu'
4542 || getDolGlobalString('MAIN_MENUFRONT_STANDARD') == 'auguria_menu' || getDolGlobalString('MAIN_MENUFRONT_SMARTPHONE') == 'auguria_menu') {
4543 $listofmenuhandler['auguria'] = 1; // We set here only dynamic menu handlers
4544 }
4545
4546 foreach ($listofmenuhandler as $key => $val) {
4547 print '<tr class="trforrunsql"><td colspan="4">';
4548
4549 //print "x".$key;
4550 print '<br>';
4551 print '<b>'.$langs->trans('Upgrade').'</b>: '.$langs->trans('MenuHandler')." ".$key."<br>\n";
4552
4553 // Load sql ini_menu_handler.sql file
4554 $dir = DOL_DOCUMENT_ROOT."/core/menus/";
4555 $file = 'init_menu_'.$key.'.sql';
4556 if (file_exists($dir.$file)) {
4557 $result = run_sql($dir.$file, 1, 0, 1, $key);
4558 }
4559
4560 print '</td></tr>';
4561 }
4562
4563 return 1;
4564}
4565
4572{
4573 global $conf, $db, $langs, $user;
4574
4575 if (!is_object($user)) {
4576 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4577 $user = new User($db); // To avoid error during migration
4578 }
4579
4580 print '<tr><td colspan="4">';
4581
4582 print '<b>'.$langs->trans('MigrationProductLotPath')."</b><br>\n";
4583
4584 $sql = "SELECT rowid, entity, batch, fk_product from ".MAIN_DB_PREFIX."product_lot";
4585 $resql = $db->query($sql);
4586
4587 if ($resql) {
4588 $modulepart = "product_batch";
4589
4590 $lot = new Productlot($db);
4591
4592 while ($obj = $db->fetch_object($resql)) {
4593 $entity = (empty($obj->entity) ? 1 : $obj->entity);
4594 if ($entity > 1) {
4595 $dir = DOL_DATA_ROOT.'/'.$entity.'/'.$conf->productbatch->multidir_output[$entity];
4596 } else {
4597 $dir = $conf->productbatch->multidir_output[$entity];
4598 }
4599
4600 if ($dir) {
4601 $lot->id = (int) $obj->rowid;
4602 $lot->ref = (string) $obj->rowid; // No ref for the moment
4603 $lot->batch = $obj->batch;
4604 $lot->entity = $obj->entity;
4605 $lot->fk_product = $obj->fk_product;
4606
4607 $savref = $lot->ref;
4608
4609 $lot->ref = $obj->batch;
4610 $origin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4611
4612 $lot->ref = $savref; // So restore the id
4613 $destin = $dir . '/' . get_exdir(0, 0, 0, 1, $lot, $modulepart);
4614
4615 //var_dump($origin.' -> '.$destin.' '.$lot->batch.' dir origin is '.dol_is_dir($origin));exit;
4616
4617 if (dol_is_dir($origin) && !dol_is_dir($destin)) {
4618 dol_move_dir($origin, $destin, 0);
4619 }
4620 }
4621 }
4622 }
4623 print '</td></tr>';
4624
4625 return 1;
4626}
4627
4634{
4635 global $conf, $db, $langs, $user;
4636
4637 print '<tr><td colspan="4">';
4638
4639 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4640
4641 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4642 $fuser = new User($db);
4643 if (!is_object($user)) {
4644 $user = $fuser; // To avoid error during migration
4645 }
4646
4647 $sql = "SELECT rowid as uid, entity from ".MAIN_DB_PREFIX."user"; // Get list of all users
4648 $resql = $db->query($sql);
4649 if ($resql) {
4650 while ($obj = $db->fetch_object($resql)) {
4651 //$fuser->fetch($obj->uid);
4652 $fuser->id = $obj->uid;
4653 $fuser->entity = $obj->entity;
4654
4655 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4656 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4657 if ($entity > 1) {
4658 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4659 } else {
4660 $dir = $conf->user->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4661 }
4662
4663 if ($dir) {
4664 //print "Process user id ".$fuser->id."<br>\n";
4665 $origin = $dir.'/'.get_exdir($fuser->id, 2, 0, 1, $fuser, 'user'); // Use old behaviour to get x/y path
4666 $destin = $dir.'/'.$fuser->id;
4667
4668 $origin_osencoded = dol_osencode($origin);
4669
4670 dol_mkdir($destin);
4671
4672 //echo '<hr>'.$origin.' -> '.$destin;
4673 if (dol_is_dir($origin)) {
4674 $handle = opendir($origin_osencoded);
4675 if (is_resource($handle)) {
4676 while (($file = readdir($handle)) !== false) {
4677 if ($file == '.' || $file == '..') {
4678 continue;
4679 }
4680
4681 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4682 $thumbs = opendir($origin_osencoded.'/'.$file);
4683 if (is_resource($thumbs)) {
4684 dol_mkdir($destin.'/'.$file);
4685 while (($thumb = readdir($thumbs)) !== false) {
4686 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4687 if ($thumb == '.' || $thumb == '..') {
4688 continue;
4689 }
4690
4691 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4692 print '.';
4693 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4694 //var_dump('aaa');exit;
4695 }
4696 }
4697 // dol_delete_dir($origin.'/'.$file);
4698 }
4699 } else { // it is a file
4700 if (!dol_is_file($destin.'/'.$file)) {
4701 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4702 print '.';
4703 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4704 //var_dump('eee');exit;
4705 }
4706 }
4707 }
4708 }
4709 }
4710 }
4711 }
4712 }
4713
4714 print '</td></tr>';
4715}
4716
4723{
4724 global $db, $langs, $user;
4725
4726 print '<tr><td colspan="4">';
4727
4728 print '<b>'.$langs->trans('MigrationUserPhotoPath')."</b><br>\n";
4729
4730 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
4731 $fuser = new User($db);
4732 if (!is_object($user)) {
4733 $user = $fuser; // To avoid error during migration
4734 }
4735
4736 $sql = "SELECT rowid as uid, entity, photo from ".MAIN_DB_PREFIX."user"; // Get list of all users
4737 $resql = $db->query($sql);
4738 if ($resql) {
4739 while ($obj = $db->fetch_object($resql)) {
4740 //$fuser->fetch($obj->uid);
4741 $fuser->id = $obj->uid;
4742 $fuser->entity = $obj->entity;
4743 $fuser->photo = $obj->photo;
4744
4745 //echo '<hr>'.$fuser->id.' -> '.$fuser->entity;
4746 $entity = (empty($fuser->entity) ? 1 : $fuser->entity);
4747 if ($entity > 1) {
4748 $dir = DOL_DATA_ROOT.'/'.$entity.'/users';
4749 } else {
4750 $dir = DOL_DATA_ROOT.'/users';
4751 }
4752
4753 if ($dir) {
4754 //print "Process user id ".$fuser->id."<br>\n";
4755 $origin = $dir.'/'.$fuser->id;
4756 $destin = $dir.'/'.$fuser->id.'/photos';
4757
4758 $origin_osencoded = dol_osencode($origin);
4759
4760 dol_mkdir($destin);
4761
4762 //echo '<hr>'.$origin.' -> '.$destin;
4763 if (dol_is_dir($origin)) {
4764 $handle = opendir($origin_osencoded);
4765 if (is_resource($handle)) {
4766 while (($file = readdir($handle)) !== false) {
4767 if ($file == '.' || $file == '..' || $file == 'photos') {
4768 continue;
4769 }
4770 if (!empty($fuser->photo) && ($file != $fuser->photo && $file != 'thumbs')) {
4771 continue;
4772 }
4773
4774 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4775 $thumbs = opendir($origin_osencoded.'/'.$file);
4776 if (is_resource($thumbs)) {
4777 dol_mkdir($destin.'/'.$file);
4778 while (($thumb = readdir($thumbs)) !== false) {
4779 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4780 if ($thumb == '.' || $thumb == '..') {
4781 continue;
4782 }
4783
4784 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4785 print '.';
4786 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4787 }
4788 }
4789 // dol_delete_dir($origin.'/'.$file);
4790 }
4791 } else { // it is a file
4792 if (!dol_is_file($destin.'/'.$file)) {
4793 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4794 print '.';
4795 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4796 }
4797 }
4798 }
4799 }
4800 }
4801 }
4802 }
4803 }
4804
4805 print '</td></tr>';
4806}
4807
4808
4809
4816{
4817 global $conf, $db, $langs;
4818
4819 print '<tr class="trforrunsql"><td>';
4820
4821 print '<b>'.$langs->trans('MigrationHolidayPath')."</b><br>\n";
4822
4823 include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
4824 $holiday = new Holiday($db);
4825
4826 $sql = "SELECT rowid as uid, ref, entity from ".MAIN_DB_PREFIX."holiday"; // Get list of all holiday
4827
4828 $resql = $db->query($sql);
4829 if ($resql) {
4830 while ($obj = $db->fetch_object($resql)) {
4831 //$holiday->fetch($obj->uid);
4832 $holiday->id = $obj->uid;
4833 $holiday->ref = $obj->ref;
4834 $holiday->entity = $obj->entity;
4835
4836 //echo '<hr>'.$holiday->id.' -> '.$holiday->entity;
4837 $entity = (empty($holiday->entity) ? 1 : $holiday->entity);
4838 if ($entity > 1) {
4839 $dir = DOL_DATA_ROOT.'/'.$entity.'/holiday';
4840 } else {
4841 $dir = $conf->holiday->multidir_output[$entity]; // $conf->user->multidir_output[] for each entity is construct by the multicompany module
4842 }
4843
4844 if ($dir) {
4845 //print "Process holiday id ".$holiday->id."<br>\n";
4846 $origin = $dir.'/'.get_exdir($holiday->id, 2, 0, 1, $holiday, 'holiday'); // Use old behaviour to get x/y path
4847 $destin = $dir.'/'.$holiday->ref;
4848
4849 $origin_osencoded = dol_osencode($origin);
4850
4851 dol_mkdir($destin);
4852
4853 //echo $origin.' -> '.$destin."<br>\n";
4854 if (dol_is_dir($origin)) {
4855 $handle = opendir($origin_osencoded);
4856 if (is_resource($handle)) {
4857 while (($file = readdir($handle)) !== false) {
4858 if ($file == '.' || $file == '..') {
4859 continue;
4860 }
4861
4862 if (dol_is_dir($origin.'/'.$file)) { // it is a dir (like 'thumbs')
4863 $thumbs = opendir($origin_osencoded.'/'.$file);
4864 if (is_resource($thumbs)) {
4865 dol_mkdir($destin.'/'.$file);
4866 while (($thumb = readdir($thumbs)) !== false) {
4867 if (!dol_is_file($destin.'/'.$file.'/'.$thumb)) {
4868 if ($thumb == '.' || $thumb == '..') {
4869 continue;
4870 }
4871
4872 //print $origin.'/'.$file.'/'.$thumb.' -> '.$destin.'/'.$file.'/'.$thumb.'<br>'."\n";
4873 print '.';
4874 dol_copy($origin.'/'.$file.'/'.$thumb, $destin.'/'.$file.'/'.$thumb, '0', 0);
4875 //var_dump('aaa');exit;
4876 }
4877 }
4878 // dol_delete_dir($origin.'/'.$file);
4879 }
4880 } else { // it is a file
4881 if (!dol_is_file($destin.'/'.$file)) {
4882 //print $origin.'/'.$file.' -> '.$destin.'/'.$file.'<br>'."\n";
4883 print '.';
4884 dol_copy($origin.'/'.$file, $destin.'/'.$file, '0', 0);
4885 }
4886 }
4887 }
4888 }
4889 }
4890 }
4891 }
4892 }
4893
4894 print '</td></tr>';
4895}
4896
4897
4898/* TODO: Modify the Paid status and `fk_facture` of the invoices paid in full
4899
4900Lookup incorrect invoices:
4901select 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
4902having f.total_ttc = sum(pf.amount)
4903
4904Correct the incorrect invoices:
4905update llx_facture set paye=1, fk_statut=2 where close_code is null
4906and rowid in (...)
4907*/
4908
4916{
4917 global $db, $langs;
4918 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
4919 $error = 0;
4920 $db->begin();
4921 print '<tr><td colspan="4">';
4922 $sql = 'SELECT rowid, socialnetworks';
4923 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'user WHERE';
4924 $sql .= " skype IS NOT NULL OR skype <> ''";
4925 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
4926 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
4927 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
4928 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
4929 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
4930 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
4931 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
4932 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
4933
4934 $resql = $db->query($sql);
4935 if ($resql) {
4936 while ($obj = $db->fetch_object($resql)) {
4937 $arraysocialnetworks = array();
4938 if (!empty($obj->skype)) {
4939 $arraysocialnetworks['skype'] = $obj->skype;
4940 }
4941 if (!empty($obj->twitter)) {
4942 $arraysocialnetworks['twitter'] = $obj->twitter;
4943 }
4944 if (!empty($obj->facebook)) {
4945 $arraysocialnetworks['facebook'] = $obj->facebook;
4946 }
4947 if (!empty($obj->linkedin)) {
4948 $arraysocialnetworks['linkedin'] = $obj->linkedin;
4949 }
4950 if (!empty($obj->instagram)) {
4951 $arraysocialnetworks['instagram'] = $obj->instagram;
4952 }
4953 if (!empty($obj->snapchat)) {
4954 $arraysocialnetworks['snapchat'] = $obj->snapchat;
4955 }
4956 if (!empty($obj->googleplus)) {
4957 $arraysocialnetworks['googleplus'] = $obj->googleplus;
4958 }
4959 if (!empty($obj->youtube)) {
4960 $arraysocialnetworks['youtube'] = $obj->youtube;
4961 }
4962 if (!empty($obj->whatsapp)) {
4963 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
4964 }
4965 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
4966 $obj->socialnetworks = '[]';
4967 }
4968 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
4969 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."user SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
4970 $sqlupd .= ', skype=null';
4971 $sqlupd .= ', twitter=null';
4972 $sqlupd .= ', facebook=null';
4973 $sqlupd .= ', linkedin=null';
4974 $sqlupd .= ', instagram=null';
4975 $sqlupd .= ', snapchat=null';
4976 $sqlupd .= ', googleplus=null';
4977 $sqlupd .= ', youtube=null';
4978 $sqlupd .= ', whatsapp=null';
4979 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
4980
4981 $resqlupd = $db->query($sqlupd);
4982 if (!$resqlupd) {
4984 $error++;
4985 }
4986 }
4987 } else {
4988 $error++;
4989 }
4990 if (!$error) {
4991 $db->commit();
4992 } else {
4994 $db->rollback();
4995 }
4996 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Users')."</b><br>\n";
4997 print '</td></tr>';
4998}
4999
5007{
5008 global $db, $langs;
5009
5010 print '<tr><td colspan="4">';
5011 $error = 0;
5012 $db->begin();
5013 print '<tr><td colspan="4">';
5014 $sql = 'SELECT rowid, socialnetworks';
5015 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'adherent WHERE ';
5016 $sql .= " skype IS NOT NULL OR skype <> ''";
5017 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5018 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5019 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5020 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5021 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5022 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5023 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5024 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5025 //print $sql;
5026 $resql = $db->query($sql);
5027 if ($resql) {
5028 while ($obj = $db->fetch_object($resql)) {
5029 $arraysocialnetworks = array();
5030 if (!empty($obj->skype)) {
5031 $arraysocialnetworks['skype'] = $obj->skype;
5032 }
5033 if (!empty($obj->twitter)) {
5034 $arraysocialnetworks['twitter'] = $obj->twitter;
5035 }
5036 if (!empty($obj->facebook)) {
5037 $arraysocialnetworks['facebook'] = $obj->facebook;
5038 }
5039 if (!empty($obj->linkedin)) {
5040 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5041 }
5042 if (!empty($obj->instagram)) {
5043 $arraysocialnetworks['instagram'] = $obj->instagram;
5044 }
5045 if (!empty($obj->snapchat)) {
5046 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5047 }
5048 if (!empty($obj->googleplus)) {
5049 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5050 }
5051 if (!empty($obj->youtube)) {
5052 $arraysocialnetworks['youtube'] = $obj->youtube;
5053 }
5054 if (!empty($obj->whatsapp)) {
5055 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5056 }
5057 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5058 $obj->socialnetworks = '[]';
5059 }
5060 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5061 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."adherent SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5062 $sqlupd .= ', skype=null';
5063 $sqlupd .= ', twitter=null';
5064 $sqlupd .= ', facebook=null';
5065 $sqlupd .= ', linkedin=null';
5066 $sqlupd .= ', instagram=null';
5067 $sqlupd .= ', snapchat=null';
5068 $sqlupd .= ', googleplus=null';
5069 $sqlupd .= ', youtube=null';
5070 $sqlupd .= ', whatsapp=null';
5071 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5072 //print $sqlupd."<br>";
5073 $resqlupd = $db->query($sqlupd);
5074 if (!$resqlupd) {
5076 $error++;
5077 }
5078 }
5079 } else {
5080 $error++;
5081 }
5082 if (!$error) {
5083 $db->commit();
5084 } else {
5086 $db->rollback();
5087 }
5088 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Members')."</b><br>\n";
5089 print '</td></tr>';
5090}
5091
5099{
5100 global $db, $langs;
5101 // jabberid,skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5102 $error = 0;
5103 $db->begin();
5104 print '<tr><td colspan="4">';
5105 $sql = 'SELECT rowid, socialnetworks';
5106 $sql .= ', jabberid, skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'socpeople WHERE';
5107 $sql .= " jabberid IS NOT NULL OR jabberid <> ''";
5108 $sql .= " OR skype IS NOT NULL OR skype <> ''";
5109 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5110 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5111 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5112 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5113 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5114 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5115 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5116 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5117 //print $sql;
5118 $resql = $db->query($sql);
5119 if ($resql) {
5120 while ($obj = $db->fetch_object($resql)) {
5121 $arraysocialnetworks = array();
5122 if (!empty($obj->jabberid)) {
5123 $arraysocialnetworks['jabber'] = $obj->jabberid;
5124 }
5125 if (!empty($obj->skype)) {
5126 $arraysocialnetworks['skype'] = $obj->skype;
5127 }
5128 if (!empty($obj->twitter)) {
5129 $arraysocialnetworks['twitter'] = $obj->twitter;
5130 }
5131 if (!empty($obj->facebook)) {
5132 $arraysocialnetworks['facebook'] = $obj->facebook;
5133 }
5134 if (!empty($obj->linkedin)) {
5135 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5136 }
5137 if (!empty($obj->instagram)) {
5138 $arraysocialnetworks['instagram'] = $obj->instagram;
5139 }
5140 if (!empty($obj->snapchat)) {
5141 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5142 }
5143 if (!empty($obj->googleplus)) {
5144 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5145 }
5146 if (!empty($obj->youtube)) {
5147 $arraysocialnetworks['youtube'] = $obj->youtube;
5148 }
5149 if (!empty($obj->whatsapp)) {
5150 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5151 }
5152 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5153 $obj->socialnetworks = '[]';
5154 }
5155 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5156 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."socpeople SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5157 $sqlupd .= ', jabberid=null';
5158 $sqlupd .= ', skype=null';
5159 $sqlupd .= ', twitter=null';
5160 $sqlupd .= ', facebook=null';
5161 $sqlupd .= ', linkedin=null';
5162 $sqlupd .= ', instagram=null';
5163 $sqlupd .= ', snapchat=null';
5164 $sqlupd .= ', googleplus=null';
5165 $sqlupd .= ', youtube=null';
5166 $sqlupd .= ', whatsapp=null';
5167 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5168 //print $sqlupd."<br>";
5169 $resqlupd = $db->query($sqlupd);
5170 if (!$resqlupd) {
5172 $error++;
5173 }
5174 }
5175 } else {
5176 $error++;
5177 }
5178 if (!$error) {
5179 $db->commit();
5180 } else {
5182 $db->rollback();
5183 }
5184 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Contacts')."</b><br>\n";
5185 print '</td></tr>';
5186}
5187
5195{
5196 global $db, $langs;
5197 // skype,twitter,facebook,linkedin,instagram,snapchat,googleplus,youtube,whatsapp
5198 $error = 0;
5199 $db->begin();
5200 print '<tr><td colspan="4">';
5201 $sql = 'SELECT rowid, socialnetworks';
5202 $sql .= ', skype, twitter, facebook, linkedin, instagram, snapchat, googleplus, youtube, whatsapp FROM '.MAIN_DB_PREFIX.'societe WHERE ';
5203 $sql .= " skype IS NOT NULL OR skype <> ''";
5204 $sql .= " OR twitter IS NOT NULL OR twitter <> ''";
5205 $sql .= " OR facebook IS NOT NULL OR facebook <> ''";
5206 $sql .= " OR linkedin IS NOT NULL OR linkedin <> ''";
5207 $sql .= " OR instagram IS NOT NULL OR instagram <> ''";
5208 $sql .= " OR snapchat IS NOT NULL OR snapchat <> ''";
5209 $sql .= " OR googleplus IS NOT NULL OR googleplus <> ''";
5210 $sql .= " OR youtube IS NOT NULL OR youtube <> ''";
5211 $sql .= " OR whatsapp IS NOT NULL OR whatsapp <> ''";
5212
5213 $resql = $db->query($sql);
5214 if ($resql) {
5215 while ($obj = $db->fetch_object($resql)) {
5216 $arraysocialnetworks = array();
5217 if (!empty($obj->skype)) {
5218 $arraysocialnetworks['skype'] = $obj->skype;
5219 }
5220 if (!empty($obj->twitter)) {
5221 $arraysocialnetworks['twitter'] = $obj->twitter;
5222 }
5223 if (!empty($obj->facebook)) {
5224 $arraysocialnetworks['facebook'] = $obj->facebook;
5225 }
5226 if (!empty($obj->linkedin)) {
5227 $arraysocialnetworks['linkedin'] = $obj->linkedin;
5228 }
5229 if (!empty($obj->instagram)) {
5230 $arraysocialnetworks['instagram'] = $obj->instagram;
5231 }
5232 if (!empty($obj->snapchat)) {
5233 $arraysocialnetworks['snapchat'] = $obj->snapchat;
5234 }
5235 if (!empty($obj->googleplus)) {
5236 $arraysocialnetworks['googleplus'] = $obj->googleplus;
5237 }
5238 if (!empty($obj->youtube)) {
5239 $arraysocialnetworks['youtube'] = $obj->youtube;
5240 }
5241 if (!empty($obj->whatsapp)) {
5242 $arraysocialnetworks['whatsapp'] = $obj->whatsapp;
5243 }
5244 if ($obj->socialnetworks == '' || is_null($obj->socialnetworks)) {
5245 $obj->socialnetworks = '[]';
5246 }
5247 $socialnetworks = array_merge($arraysocialnetworks, json_decode($obj->socialnetworks, true));
5248 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX."societe SET socialnetworks='".$db->escape(json_encode($socialnetworks))."'";
5249 $sqlupd .= ', skype=null';
5250 $sqlupd .= ', twitter=null';
5251 $sqlupd .= ', facebook=null';
5252 $sqlupd .= ', linkedin=null';
5253 $sqlupd .= ', instagram=null';
5254 $sqlupd .= ', snapchat=null';
5255 $sqlupd .= ', googleplus=null';
5256 $sqlupd .= ', youtube=null';
5257 $sqlupd .= ', whatsapp=null';
5258 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5259 //print $sqlupd."<br>";
5260 $resqlupd = $db->query($sqlupd);
5261 if (!$resqlupd) {
5263 $error++;
5264 }
5265 }
5266 } else {
5267 $error++;
5268 }
5269 if (!$error) {
5270 $db->commit();
5271 } else {
5273 $db->rollback();
5274 }
5275 print '<b>'.$langs->trans('MigrationFieldsSocialNetworks', 'Thirdparties')."</b><br>\n";
5276 print '</td></tr>';
5277}
5278
5279
5286function migrate_export_import_profiles($mode = 'export')
5287{
5288 global $db, $langs;
5289
5290 $error = 0;
5291 $resultstring = '';
5292
5293 $db->begin();
5294
5295 print '<tr class="trforrunsql"><td colspan="4">';
5296 $sql = 'SELECT rowid, field';
5297 if ($mode == 'export') {
5298 $sql .= ', filter';
5299 }
5300 $sql .= ' FROM '.MAIN_DB_PREFIX.$mode.'_model WHERE';
5301 $sql .= " type LIKE 'propale_%' OR type LIKE 'commande_%' OR type LIKE 'facture_%'";
5302 //print $sql;
5303 $resql = $db->query($sql);
5304 if ($resql) {
5305 while ($obj = $db->fetch_object($resql)) {
5306 $oldfield = $obj->field;
5307 $newfield = str_replace(array(',f.facnumber', 'f.facnumber,', 'f.total,', 'f.tva,'), array(',f.ref', 'f.ref,', 'f.total_ht,', 'f.total_tva,'), $oldfield);
5308
5309 if ($mode == 'export') {
5310 $oldfilter = $obj->filter;
5311 $newfilter = str_replace(array('f.facnumber=', 'f.total=', 'f.tva='), array('f.ref=', 'f.total_ht=', 'f.total_tva='), $oldfilter);
5312 } else {
5313 $oldfilter = '';
5314 $newfilter = '';
5315 }
5316
5317 if ($oldfield != $newfield || $oldfilter != $newfilter) {
5318 $sqlupd = 'UPDATE '.MAIN_DB_PREFIX.$mode."_model SET field = '".$db->escape($newfield)."'";
5319 if ($mode == 'export') {
5320 $sqlupd .= ", filter = '".$db->escape($newfilter)."'";
5321 }
5322 $sqlupd .= ' WHERE rowid = '.((int) $obj->rowid);
5323 $resultstring .= '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$sqlupd."</td></tr>\n";
5324 $resqlupd = $db->query($sqlupd);
5325 if (!$resqlupd) {
5327 $error++;
5328 }
5329 }
5330 }
5331 } else {
5332 $error++;
5333 }
5334 if (!$error) {
5335 $db->commit();
5336 } else {
5338 $db->rollback();
5339 }
5340 print '<b>'.$langs->trans('MigrationImportOrExportProfiles', $mode)."</b><br>\n";
5341 print '</td></tr>';
5342
5343 if ($resultstring) {
5344 print $resultstring;
5345 } else {
5346 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5347 }
5348}
5349
5356{
5357 global $db, $langs;
5358
5359 $error = 0;
5360 $resultstring = '';
5361
5362 $db->begin();
5363 print '<tr class="trforrunsql"><td colspan="4">';
5364 print '<b>'.$langs->trans('MigrationContractLineRank')."</b><br>\n";
5365
5366 $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";
5367 $sql .= " ORDER BY c.rowid,cd.rowid";
5368
5369 $resql = $db->query($sql);
5370 if ($resql) {
5371 $currentRank = 0;
5372 $current_contract = 0;
5373 while ($obj = $db->fetch_object($resql)) {
5374 if (empty($current_contract) || $current_contract == $obj->cid) {
5375 $currentRank++;
5376 } else {
5377 $currentRank = 1;
5378 }
5379
5380 $sqlUpd = "UPDATE ".$db->prefix()."contratdet SET rang=".(int) $currentRank." WHERE rowid=".(int) $obj->cdid;
5381 $resultstring = '.';
5382 print $resultstring;
5383 $resqlUpd = $db->query($sqlUpd);
5384 if (!$resqlUpd) {
5386 $error++;
5387 }
5388
5389 $current_contract = $obj->cid;
5390 }
5391 } else {
5392 $error++;
5393 }
5394 if (!$error) {
5395 $db->commit();
5396 } else {
5397 $db->rollback();
5398 }
5399
5400 print '</td></tr>';
5401
5402 if (!$resultstring) {
5403 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5404 }
5405}
5406
5413{
5414 global $db, $langs;
5415
5416 $lock = getDolGlobalInt('MIGRATION_FLAG_INVOICE_MODELS_V20');
5417
5418 $firstInstallVersion = getDolGlobalString('MAIN_VERSION_FIRST_INSTALL', DOL_VERSION);
5419 $migrationNeeded = (versioncompare(explode('.', $firstInstallVersion, 3), array(20, 0, -5)) < 0 && !$lock);
5420
5421 print '<tr class="trforrunsql"><td colspan="4">';
5422 print '<b>'.$langs->trans('InvoiceExportModelsMigration')."</b>: \n";
5423
5424 if (! $migrationNeeded) {
5425 print $langs->trans("AlreadyDone");
5426 print '</td></tr>';
5427 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5428 return;
5429 }
5430
5431
5432 $db->begin();
5433
5434 $sql1 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_0' WHERE type = 'facture_1'";
5435
5436 $resql1 = $db->query($sql1);
5437
5438 if (! $resql1) {
5440 $db->rollback();
5441 print '</td></tr>';
5442 return;
5443 }
5444
5445 $modified1 = $db->affected_rows($resql1);
5446
5447 print str_repeat('.', $modified1);
5448
5449 $db->free($resql1);
5450
5451 $sql2 = "UPDATE ".$db->prefix()."export_model SET type = 'facture_1' WHERE type = 'facture_2'";
5452
5453 $resql2 = $db->query($sql2);
5454
5455 if (! $resql2) {
5457 $db->rollback();
5458 print '</td></tr>';
5459 return;
5460 }
5461
5462 $modified2 = $db->affected_rows($resql2);
5463
5464 print str_repeat('.', $modified2);
5465
5466 $db->free($resql2);
5467
5468 if (empty($modified1 + $modified2)) {
5469 print $langs->trans('NothingToDo');
5470 }
5471
5472 $db->commit();
5473
5474 dolibarr_set_const($db, 'MIGRATION_FLAG_INVOICE_MODELS_V20', 1, 'chaine', 0, 'To flag the upgrade of invoice template has been set', 0);
5475
5476 echo '</td></tr>';
5477}
5478
5486{
5487 global $db, $langs;
5488
5489 $error = 0;
5490 $resultstring = '';
5491 $bookKeepingAddon = '';
5492
5493 // For the moment we set the numbering rule to neon (the rule argon has a lot of critical bugs to fix first).
5494 if (getDolGlobalString('BOOKKEEPING_ADDON') == '') {
5495 dolibarr_set_const($db, 'BOOKKEEPING_ADDON', 'mod_bookkeeping_neon', 'chaine', 0, '', $entity);
5496 $bookKeepingAddon = 'mod_bookkeeping_neon';
5497 }
5498
5499 print '<tr class="trforrunsql"><td colspan="4">';
5500 print '<b>'.$langs->trans('MigrationAccountancyBookkeeping')."</b><br>\n";
5501
5502 // TODO
5503 if ($bookKeepingAddon === 'mod_bookkeeping_argon') {
5504 $db->begin();
5505
5506 $sql = "SELECT DISTINCT YEAR(doc_date) as doc_year, MONTH(doc_date) as doc_month, code_journal, piece_num FROM ".$db->prefix()."accounting_bookkeeping";
5507 $sql .= " WHERE ref IS NULL AND entity = ".((int) $entity);
5508 $sql .= " ORDER BY doc_year, doc_month, code_journal, piece_num";
5509
5510 $resql = $db->query($sql);
5511
5512 require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php';
5513 $bookkeeping = new BookKeeping($db);
5514 if ($resql) {
5515 while ($obj = $db->fetch_object($resql)) {
5516 $bookkeeping->doc_date = dol_mktime(0, 0, 0, $obj->doc_month, 1, $obj->doc_year);
5517 $bookkeeping->code_journal = $obj->code_journal;
5518 $ref = $bookkeeping->getNextNumRef();
5519
5520 $sqlUpd = "UPDATE ".$db->prefix()."accounting_bookkeeping SET ref = '".$db->escape($ref)."' WHERE piece_num = '".$db->escape($obj->piece_num)."' AND entity = ".((int) $entity);
5521 $resultstring = '.';
5522 print $resultstring;
5523 $resqlUpd = $db->query($sqlUpd);
5524 if (!$resqlUpd) {
5526 $error++;
5527 }
5528 }
5529 } else {
5530 $error++;
5531 }
5532
5533 if (!$error) {
5534 $db->commit();
5535 } else {
5536 $db->rollback();
5537 }
5538 }
5539
5540 print '</td></tr>';
5541
5542 if (!$resultstring) {
5543 print '<tr class="trforrunsql" style=""><td class="wordbreak" colspan="4">'.$langs->trans("NothingToDo")."</td></tr>\n";
5544 }
5545}
5546
5553{
5554 global $conf, $db, $langs;
5555
5556 print '<tr class="trforrunsql"><td colspan="4">';
5557 print '<b>'.$langs->trans('MigrationApiRestTokens')."</b>:\n";
5558
5559 $error = 0;
5560 $nbofmigration = 0;
5561 $allexistingtokens = array();
5562
5563 $db->begin();
5564
5565 $sqlforalltokens = "SELECT oat.tokenstring";
5566 $sqlforalltokens .= " FROM ".$db->prefix()."oauth_token AS oat";
5567 $sqlforalltokens .= " WHERE oat.service = 'dolibarr_rest_api'";
5568
5569 $resalltoken = $db->query($sqlforalltokens);
5570
5571 if ($resalltoken) {
5572 while ($tokenobj = $db->fetch_object($resalltoken)) {
5573 $allexistingtokens[] = dolDecrypt($tokenobj->tokenstring);
5574 }
5575 } else {
5576 $error++;
5578 $db->rollback();
5579 }
5580
5581 if (!$error) {
5582 $sql = "SELECT 'dolibarr_rest_api' AS service, u.api_key AS tokenstring, u.rowid AS fk_user, u.entity";
5583 $sql .= " FROM llx_user AS u";
5584 $sql .= " WHERE u.api_key IS NOT NULL AND u.api_key <> ''";
5585
5586 $result = $db->query($sql);
5587
5588 if ($result) {
5589 $tmpuser = new User($db);
5590
5591 while ($obj = $db->fetch_object($result)) {
5592 if (!in_array(dolDecrypt($obj->tokenstring), $allexistingtokens)) {
5593 // Load the object of the user of token so we can get the API_COUNT_CALL
5594 unset($tmpuser->conf);
5595 $tmpuser->conf = new stdClass();
5596 $tmpuser->fetch((int) $obj->fk_user, '', '', 1, ($obj->entity ? $obj->entity : $conf->entity));
5597
5598 $sqlforinsert = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token (service, tokenstring, fk_user, datec, entity, apicount_total)";
5599 $sqlforinsert .= " VALUES ('".$db->escape($obj->service)."', '".$db->escape(dolEncrypt(dolDecrypt($obj->tokenstring)))."', ";
5600 $sqlforinsert .= ((int) $obj->fk_user).", '".$db->idate(dol_now())."', ".((int) $obj->entity).", ";
5601 $sqlforinsert .= getDolUserInt('API_COUNT_CALL', 0, $tmpuser);
5602 $sqlforinsert .= ")";
5603
5604 $insertresult = $db->query($sqlforinsert);
5605 if (!$insertresult) {
5606 $error++;
5608 } else {
5609 $nbofmigration++;
5610 }
5611 }
5612 }
5613
5614 if (!$error) {
5615 $db->commit();
5616 } else {
5617 $db->rollback();
5618 }
5619 } else {
5621 $db->rollback();
5622 }
5623 }
5624
5625 if (!$nbofmigration) {
5626 print $langs->trans("NothingToDo")."\n";
5627 } else {
5628 print $langs->trans('MigratedTokens', $nbofmigration);
5629 }
5630 print '</td></tr>';
5631}
5632
5633
5642{
5643 global $conf, $db, $langs;
5644
5645 include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
5646 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
5647
5648 print '<tr class="trforrunsql"><td colspan="4">';
5649 print '<b>'.$langs->trans('InitAHMACKeyForBlockedLog')."</b>:\n";
5650
5651 $db->begin();
5652
5653 // Create HMAC if it does not exists yet
5654 $hmac_encoded_secret_key = getDolGlobalString('BLOCKEDLOG_HMAC_KEY');
5655 if (empty($hmac_encoded_secret_key)) {
5656 // Add key
5657 $randomsecret = bin2hex(random_bytes(32)); // 64 char hex - 256 bits
5658
5659 $hmac_secret_key = 'BLOCKEDLOGHMAC'.$randomsecret; // Example: 'BLOCKEDLOGHMACY3Ewx37RXbSd8gL9JV8p7Wqw7qvq2K2A'
5660
5661 $result = dolibarr_set_const($db, 'BLOCKEDLOG_HMAC_KEY', $hmac_secret_key, 'chaine', 0, 'The secret key for HMAC used for blockedlog record', 0); // Will encrypt the value using dolCrypt and store it.
5662
5663 if ($result < 0) {
5665 $db->rollback();
5666
5667 print '</td></tr>';
5668 return -1;
5669 }
5670
5671 print $langs->trans('Done');
5672 } else {
5673 // Decode the HMAC key
5674 $hmac_secret_key = dolDecrypt($hmac_encoded_secret_key);
5675
5676 if (! preg_match('/^BLOCKEDLOGHMAC/', $hmac_secret_key)) {
5677 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.';
5678 print 'Restore the value of $dolibarr_main_crypt_key that was used for encryption in database and restart the migration.';
5679 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.';
5680 $db->rollback();
5681
5682 print '</td></tr>';
5683 return -1;
5684 }
5685
5686 print $langs->trans("NothingToDo")."\n";
5687 }
5688
5689 $db->commit();
5690
5691 print '</td></tr>';
5692 return 1;
5693}
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)
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:541
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:635
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:699
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, $remise_percent_global, $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.
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:933
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_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.