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