From e084dc306ed4637521d143b297f73879fa8d45ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Wed, 4 Apr 2012 20:37:16 +0200 Subject: [PATCH] Fix: When run from command line, script must return return code --- htdocs/install/repair.php | 25 +++++++++++-------------- htdocs/install/upgrade.php | 20 ++++++++++++-------- htdocs/install/upgrade2.php | 16 +++++++++++----- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index b4ce4b4e78a..73557601813 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -39,10 +39,10 @@ error_reporting(0); @set_time_limit(120); error_reporting($err); -$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); +$setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):'auto'; $langs->setDefaultLang($setuplang); -$versionfrom=isset($_GET["versionfrom"])?$_GET["versionfrom"]:''; -$versionto=isset($_GET["versionto"])?$_GET["versionto"]:''; +$versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); +$versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); $langs->load("admin"); $langs->load("install"); @@ -147,9 +147,7 @@ print '<tr><td colspan="2">'.$langs->trans("PleaseBePatient").'</td></tr>'; flush(); -/* - * Load sql files -*/ +// Run repair SQL file if ($ok) { $dir = "mysql/migration/"; @@ -178,7 +176,7 @@ if ($ok) } } - // Boucle sur chaque fichier + // Loop on each file foreach($filelist as $file) { print '<tr><td nowrap>'; @@ -191,7 +189,7 @@ if ($ok) } } - +// Run purge of directory if (GETPOST('purge')) { $conf->setValues($db); @@ -317,11 +315,6 @@ print '</table>'; - -if ($db->connected) $db->close(); - - - if (empty($actiondone)) { print '<div class="error">'.$langs->trans("ErrorWrongParameters").'</div>'; @@ -334,4 +327,8 @@ print '</a></center>'; pFooter(1,$setuplang); -?> +if ($db->connected) $db->close(); + +// Return code if ran from command line +if (! $ok && isset($argv[1])) exit(1); +?> \ No newline at end of file diff --git a/htdocs/install/upgrade.php b/htdocs/install/upgrade.php index 98a97dc3506..22c69ac4f99 100644 --- a/htdocs/install/upgrade.php +++ b/htdocs/install/upgrade.php @@ -42,10 +42,10 @@ error_reporting(0); @set_time_limit(120); error_reporting($err); -$setuplang=isset($_POST["selectlang"])?$_POST["selectlang"]:(isset($_GET["selectlang"])?$_GET["selectlang"]:'auto'); +$setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):'auto'; $langs->setDefaultLang($setuplang); -$versionfrom=isset($_POST["versionfrom"])?$_POST["versionfrom"]:(isset($_GET["versionfrom"])?$_GET["versionfrom"]:''); -$versionto=isset($_POST["versionto"])?$_POST["versionto"]:(isset($_GET["versionto"])?$_GET["versionto"]:''); +$versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); +$versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); $langs->load("admin"); $langs->load("install"); @@ -64,11 +64,11 @@ if (! is_object($conf)) dolibarr_install_syslog("upgrade2: conf file not initial * View */ -pHeader('',"upgrade2",isset($_REQUEST['action'])?$_REQUEST['action']:'','versionfrom='.$versionfrom.'&versionto='.$versionto); +pHeader('',"upgrade2",GETPOST('action'),'versionfrom='.$versionfrom.'&versionto='.$versionto); $actiondone=0; -// Action to launch the repair or migrate script +// Action to launch the migrate script if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) { $actiondone=1; @@ -77,7 +77,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) if (! $versionfrom && ! $versionto) { - print '<div class="error">Parameter versionfrom or version to missing. Upgrade is launched from page install/index.php (like a first install) instead of install/upgrade.php</div>'; + print '<div class="error">Parameter versionfrom or versionto missing. Upgrade is launched from page install/index.php (like a first install) instead of install/upgrade.php</div>'; exit; } @@ -245,7 +245,7 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) MAIN_DB_PREFIX.'c_methode_commande_fournisseur', // table renamed MAIN_DB_PREFIX.'c_input_method' ); - + $listtables = $db->DDLListTables($conf->db->name,''); foreach ($listtables as $val) { @@ -353,4 +353,8 @@ if (empty($actiondone)) pFooter(! $ok && empty($_GET["ignoreerrors"]),$setuplang); -?> +if ($db->connected) $db->close(); + +// Return code if ran from command line +if (! $ok && isset($argv[1])) exit(1); +?> \ No newline at end of file diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index bb4d872f75b..6c4ab5bac1b 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -1,6 +1,6 @@ <?php /* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> - * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net> + * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * @@ -50,10 +50,10 @@ error_reporting(0); @set_time_limit(120); error_reporting($err); -$setuplang=isset($_POST['selectlang'])?$_POST['selectlang']:(isset($_GET['selectlang'])?$_GET['selectlang']:'auto'); +$setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):'auto'; $langs->setDefaultLang($setuplang); -$versionfrom=isset($_POST["versionfrom"])?$_POST["versionfrom"]:(isset($_GET["versionfrom"])?$_GET["versionfrom"]:''); -$versionto=isset($_POST["versionto"])?$_POST["versionto"]:(isset($_GET["versionto"])?$_GET["versionto"]:''); +$versionfrom=GETPOST("versionfrom",'',3)?GETPOST("versionfrom",'',3):(empty($argv[1])?'':$argv[1]); +$versionto=GETPOST("versionto",'',3)?GETPOST("versionto",'',3):(empty($argv[2])?'':$argv[2]); $langs->load('admin'); $langs->load('install'); @@ -342,6 +342,12 @@ else pFooter($error,$setuplang); +if ($db->connected) $db->close(); + +// Return code if ran from command line +if ($error && isset($argv[1])) exit(1); + + /** * Reporte liens vers une facture de paiements sur table de jointure (lien n-n paiements factures) @@ -3691,4 +3697,4 @@ update llx_facture set paye=1, fk_statut=2 where close_code is null and rowid in (...) */ -?> +?> \ No newline at end of file -- GitLab