From eabc43bc92308c41446d1c98eb290e567b18adad Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 23 Dec 2009 16:52:39 +0100 Subject: [PATCH] fixed command line report generator, can now run from any location --- src/admin/reports.php | 2 +- src/cron/cmdreportgen.php | 27 ++++++++++++++++++++++++++- src/lang/en/main.php | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/admin/reports.php b/src/admin/reports.php index 283491f..87fcef2 100644 --- a/src/admin/reports.php +++ b/src/admin/reports.php @@ -1184,7 +1184,7 @@ function CreateCronCommand( $myReportID, $mySavedReportID = null ) if ( isset($mySavedReportID) ) { - $pos = strpos( strtoupper($_SERVER['SERVER_SOFTWARE']), "WIN32"); + $pos = strpos( strtoupper(PHP_OS), "WIN"); if ($pos !== false) { // Running on Windows diff --git a/src/cron/cmdreportgen.php b/src/cron/cmdreportgen.php index 7231dc9..28296cd 100644 --- a/src/cron/cmdreportgen.php +++ b/src/cron/cmdreportgen.php @@ -35,6 +35,31 @@ define('IN_PHPLOGCON', true); $gl_root_path = './../'; +// --- IMPORTANT, read the script filename from argv! +// Operation argv +if ( isset($_SERVER["argv"][0]) ) + $myscriptname = $_SERVER["argv"][0]; +else + die( "Error, this script can only be run from the command prompt." ); + +// Extract OS! +$pos = strpos( strtoupper(PHP_OS), "WIN"); +if ($pos !== false) // Running on Windows +{ + // Extract Global root path from scriptname + $gl_root_path = substr( $myscriptname, 0, strrpos($myscriptname, "\\")+1 ); + $gl_root_path = str_replace("\\", "/", $gl_root_path); +} +else // Running on LINUX +{ + // Extract Global root path from scriptname + $gl_root_path = substr( $myscriptname, 0, strrpos($myscriptname, "/")+1 ); +} + +// Remove cron folder as well! +$gl_root_path = str_replace("cron/", "", $gl_root_path); +// --- + // Now include necessary include files! include_once($gl_root_path . 'include/functions_common.php'); include_once($gl_root_path . 'include/functions_frontendhelpers.php'); @@ -92,7 +117,7 @@ function RunReport() // Call processing part now! $res = $myReportObj->startDataProcessing(); if ( $res != SUCCESS ) - DieWithErrorMsg( GetAndReplaceLangStr( $content['LN_GEN_ERROR_REPORTGENFAILED'], $mySavedReport['customTitle'], GetErrorMessage($res) ); + DieWithErrorMsg( GetAndReplaceLangStr($content['LN_GEN_ERROR_REPORTGENFAILED'], $mySavedReport['customTitle'], GetErrorMessage($res)) ); else { // --- Perform report output diff --git a/src/lang/en/main.php b/src/lang/en/main.php index 9339ee2..12866cf 100644 --- a/src/lang/en/main.php +++ b/src/lang/en/main.php @@ -357,6 +357,7 @@ $content['LN_ORACLE_WHOIS'] = "WHOIS Lookup for '%1' value '%2'"; $content['LN_CMD_SAVEDREPORTIDNOTFOUND'] = "Invalid SavedReport ID '%1'"; $content['LN_CMD_NOREPORTID'] = "Missing Report ID"; $content['LN_CMD_NOSAVEDREPORTID'] = "Missing SavedReport ID"; + $content['LN_CMD_NOCMDPROMPT'] = "Error, this script can only be run from the command prompt."; ?> \ No newline at end of file