BUG 5978 Add getVersion to System class and use it instead of PM_VERSION

Instead of every page defining it's own PM_VERSION interpretation,
there is now a single getVersion function in the System class to
always get the right version.
This commit is contained in:
Alexandre Rosenfeld
2011-04-13 16:04:36 -04:00
parent 721a87f6c0
commit f0277f02fb
12 changed files with 62 additions and 101 deletions

View File

@@ -83,25 +83,45 @@ class System {
return $aWorkspaces; return $aWorkspaces;
} }
/**
* Get the ProcessMaker version. If version-pmos.php is not found, try to
* retrieve the version from git.
*
* @author Alexandre Rosenfeld <alexandre@colosa.com>
* @return string system
*/
public static function getVersion() { public static function getVersion() {
if (! defined ( 'PM_VERSION' )) { if (! defined ( 'PM_VERSION' )) {
if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) { if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) {
include (PATH_METHODS . 'login/version-pmos.php'); include (PATH_METHODS . 'login/version-pmos.php');
} } else {
else { $version = self::getVersionFromGit();
$cmd = sprintf ("cd %s && git status | grep 'On branch' | awk '{print \"Branch: \" $4} '", PATH_TRUNK); if ($version === false)
if ( exec ( $cmd , $target) ) { $version = 'Development Version';
$cmd = sprintf ("cd %s && git describe ", PATH_TRUNK); define ( 'PM_VERSION', $version );
$commit = exec ( $cmd , $target);
define ( 'PM_VERSION', implode(' ', $target) );
}
else
define ( 'PM_VERSION', 'Development Version' );
} }
} }
return PM_VERSION; return PM_VERSION;
} }
/**
* Get the branch and tag information from a git repository.
*
* @author Alexandre Rosenfeld <alexandre@colosa.com>
* @return string branch and tag information
*/
public static function getVersionFromGit($dir = NULL) {
if ($dir == NULL)
$dir = PATH_TRUNK;
if (!file_exists("$dir/.git"))
return false;
if (exec("cd $dir && git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* \(.*\)$/(Branch \\1)/'", $target)) {
exec("cd $dir && git describe", $target);
return implode(' ', $target);
}
return false;
}
/** /**
* Get system information * Get system information
* *
@@ -109,12 +129,6 @@ class System {
* @return array with system information * @return array with system information
*/ */
public static function getSysInfo() { public static function getSysInfo() {
if( file_exists(PATH_METHODS . 'login/version-pmos.php') ) {
require_once (PATH_METHODS . 'login/version-pmos.php');
} else {
define('PM_VERSION', 'Development Version');
}
$ipe = explode(" ", $_SERVER['SSH_CONNECTION']); $ipe = explode(" ", $_SERVER['SSH_CONNECTION']);
if( getenv('HTTP_CLIENT_IP') ) { if( getenv('HTTP_CLIENT_IP') ) {
@@ -157,7 +171,7 @@ class System {
$Fields = array(); $Fields = array();
$Fields['SYSTEM'] = $distro; $Fields['SYSTEM'] = $distro;
$Fields['PHP'] = phpversion(); $Fields['PHP'] = phpversion();
$Fields['PM_VERSION'] = PM_VERSION; $Fields['PM_VERSION'] = self::getVersion();
$Fields['SERVER_ADDR'] = $ipe[2]; //lookup($ipe[2]); $Fields['SERVER_ADDR'] = $ipe[2]; //lookup($ipe[2]);
$Fields['IP'] = $ipe[0]; //lookup($ipe[0]); $Fields['IP'] = $ipe[0]; //lookup($ipe[0]);
@@ -328,14 +342,7 @@ class System {
} }
} }
//now getting the current version of PM $pmVersion = explode('-', self::getVersion());
if( file_exists(PATH_METHODS . 'login/version-pmos.php') ) {
include (PATH_METHODS . 'login/version-pmos.php');
} else {
define('PM_VERSION', '1.6-0-development');
}
$pmVersion = explode('-', PM_VERSION);
array_shift($pmVersion); array_shift($pmVersion);
$patchVersion = explode('-', $this->sRevision); $patchVersion = explode('-', $this->sRevision);

View File

@@ -1931,7 +1931,8 @@ class wsBase
$result->status_code = 0; $result->status_code = 0;
$result->message = 'Sucessful'; $result->message = 'Sucessful';
$result->timestamp = date ( 'Y-m-d H:i:s'); $result->timestamp = date ( 'Y-m-d H:i:s');
$result->version = PM_VERSION; G::LoadClass("system");
$result->version = System::getVersion();
$result->operatingSystem = $redhat; $result->operatingSystem = $redhat;
$result->webServer = getenv('SERVER_SOFTWARE'); $result->webServer = getenv('SERVER_SOFTWARE');
$result->serverName = getenv('SERVER_NAME'); $result->serverName = getenv('SERVER_NAME');

View File

@@ -130,11 +130,7 @@ class webEntryProxy extends HttpProxyController
//return $params; //return $params;
if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) { G::LoadClass("system");
include_once (PATH_METHODS . 'login/version-pmos.php');
} else {
define ( 'PM_VERSION', 'Dev.' );
}
$pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP; $pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP;
G::mk_dir ( $pathProcess, 0777 ); G::mk_dir ( $pathProcess, 0777 );
@@ -193,7 +189,7 @@ class webEntryProxy extends HttpProxyController
$template->assign ( 'dynaform', $dynTitle ); $template->assign ( 'dynaform', $dynTitle );
$template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) ); $template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) );
$template->assign ( 'ws', SYS_SYS ); $template->assign ( 'ws', SYS_SYS );
$template->assign ( 'version', PM_VERSION ); $template->assign ( 'version', System::getVersion() );
$fileName = $pathProcess . $dynTitle . 'Post.php'; $fileName = $pathProcess . $dynTitle . 'Post.php';
file_put_contents ( $fileName, $template->getOutputContent () ); file_put_contents ( $fileName, $template->getOutputContent () );

View File

@@ -97,13 +97,11 @@ if(isset($_POST['action'])) {
G::LoadCLass('net'); G::LoadCLass('net');
$net = new NET(G::getIpAddress()); $net = new NET(G::getIpAddress());
if( !defined("PM_VERSION")){ G::LoadClass("system");
define('PM_VERSION', 'development');
}
$META = " \n-----== ProcessMaker Open Source Private Tables ==-----\n". $META = " \n-----== ProcessMaker Open Source Private Tables ==-----\n".
" @Ver: 1.0 Oct-2009\n". " @Ver: 1.0 Oct-2009\n".
" @Processmaker version: ".PM_VERSION."\n". " @Processmaker version: ".System::getVersion()."\n".
" -------------------------------------------------------\n". " -------------------------------------------------------\n".
" @Export Date: ".date("l jS \of F Y h:i:s A")."\n". " @Export Date: ".date("l jS \of F Y h:i:s A")."\n".
" @Server address: ".getenv('SERVER_NAME')." (".getenv('SERVER_ADDR').")\n". " @Server address: ".getenv('SERVER_NAME')." (".getenv('SERVER_ADDR').")\n".
@@ -237,9 +235,7 @@ if(isset($_POST['function'])) {
G::LoadCLass('net'); G::LoadCLass('net');
$net = new NET(G::getIpAddress()); $net = new NET(G::getIpAddress());
if( !defined("PM_VERSION")){ G::LoadClass("system");
define('PM_VERSION', 'development');
}
$EXPORT_TRACEBACK = Array(); $EXPORT_TRACEBACK = Array();
foreach ($tables as $uid) { foreach ($tables as $uid) {
$aTable = new additionalTables(); $aTable = new additionalTables();

View File

@@ -11,11 +11,7 @@ $sWE_USR = $oData->WE_USR;
$withWS = $sWE_TYPE == 'WS'; $withWS = $sWE_TYPE == 'WS';
if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) { G::LoadClass("system");
include_once (PATH_METHODS . 'login/version-pmos.php');
} else {
define ( 'PM_VERSION', 'Dev.' );
}
try { try {
$pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP; $pathProcess = PATH_DATA_SITE . 'public' . PATH_SEP . $sPRO_UID . PATH_SEP;
@@ -87,7 +83,7 @@ try {
$template->assign ( 'dynaform', $dynTitle ); $template->assign ( 'dynaform', $dynTitle );
$template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) ); $template->assign ( 'timestamp', date ( 'l jS \of F Y h:i:s A' ) );
$template->assign ( 'ws', SYS_SYS ); $template->assign ( 'ws', SYS_SYS );
$template->assign ( 'version', PM_VERSION ); $template->assign ( 'version', System::getVersion() );
$fileName = $pathProcess . $dynTitle . 'Post.php'; $fileName = $pathProcess . $dynTitle . 'Post.php';
file_put_contents ( $fileName, $template->getOutputContent () ); file_put_contents ( $fileName, $template->getOutputContent () );

View File

@@ -75,13 +75,7 @@ function file_get_conditional_contents($szURL){
function buildData(){ function buildData(){
G::LoadClass ( 'serverConfiguration' ); G::LoadClass ( 'serverConfiguration' );
$oServerConf = & serverConf::getSingleton (); $oServerConf = & serverConf::getSingleton ();
if (! defined ( 'PM_VERSION' )) { G::LoadClass("system");
if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) {
require_once (PATH_METHODS . 'login/version-pmos.php');
} else {
define ( 'PM_VERSION', 'Development Version' );
}
}
$os = ''; $os = '';
if (file_exists ( '/etc/redhat-release' )) { if (file_exists ( '/etc/redhat-release' )) {
@@ -106,7 +100,7 @@ $oServerConf = & serverConf::getSingleton ();
$params ['os'] = $os; $params ['os'] = $os;
$params ['webserver'] = getenv ( 'SERVER_SOFTWARE' ); $params ['webserver'] = getenv ( 'SERVER_SOFTWARE' );
$params ['php'] = phpversion (); $params ['php'] = phpversion ();
$params ['pmVersion'] = PM_VERSION; $params ['pmVersion'] = System::getVersion();
if(class_exists('pmLicenseManager')){ if(class_exists('pmLicenseManager')){
$params ['pmProduct'] = 'PMEE'; $params ['pmProduct'] = 'PMEE';
}else{ }else{

View File

@@ -35,13 +35,7 @@ G::LoadSystem('i18n_po');
//$timer = new Benchmark_Timer(); //$timer = new Benchmark_Timer();
//$timer->start(); //$timer->start();
if (!defined('PM_VERSION')) { G::LoadClass("system");
if (file_exists ( PATH_METHODS . 'login/version-pmos.php')) {
include (PATH_METHODS . 'login/version-pmos.php');
} else {
define('PM_VERSION', 'Development Version');
}
}
//creating the .po file //creating the .po file
if( ! isset($_GET['LOCALE']) ) if( ! isset($_GET['LOCALE']) )
@@ -79,7 +73,7 @@ if( ! isset($langRecord['LAN_NAME']) )
$sLanguage = $langRecord['LAN_NAME']; $sLanguage = $langRecord['LAN_NAME'];
//setting headers //setting headers
$poFile->addHeader('Project-Id-Version' , 'ProcessMaker ' . PM_VERSION); $poFile->addHeader('Project-Id-Version' , 'ProcessMaker ' . System::getVersion());
$poFile->addHeader('POT-Creation-Date' , ''); $poFile->addHeader('POT-Creation-Date' , '');
$poFile->addHeader('PO-Revision-Date' , date('Y-m-d H:i:s')); $poFile->addHeader('PO-Revision-Date' , date('Y-m-d H:i:s'));
$poFile->addHeader('Last-Translator' , ''); $poFile->addHeader('Last-Translator' , '');

View File

@@ -89,11 +89,9 @@ try {
$oClass->iPMVersion = 0; $oClass->iPMVersion = 0;
} }
if ($oClass->iPMVersion > 0) { if ($oClass->iPMVersion > 0) {
if (!defined('PM_VERSION')) { G::LoadClass("system");
define('PM_VERSION', 0); if (System::getVersion() > 0) {
} if ($oClass->iPMVersion > System::getVersion()) {
if (PM_VERSION > 0) {
if ($oClass->iPMVersion > PM_VERSION) {
//throw new Exception('This plugin needs version ' . $oClass->iPMVersion . ' or higher of ProcessMaker'); //throw new Exception('This plugin needs version ' . $oClass->iPMVersion . ' or higher of ProcessMaker');
} }
} }

View File

@@ -117,14 +117,7 @@ switch ($RBAC->userCanAccess('PM_SETUP'))
break; break;
} }
//get the current process G::LoadClass("system");
if (file_exists(PATH_METHODS . 'login/version-pmos.php'))
{
include(PATH_METHODS . 'login/version-pmos.php');
}
else {
define('PM_VERSION', '1.2.2740');
}
$id = $_GET['id']; $id = $_GET['id'];
@@ -156,7 +149,7 @@ switch ($RBAC->userCanAccess('PM_SETUP'))
$fields['className'] = $id; $fields['className'] = $id;
$fields['version'] = $oConf->version; $fields['version'] = $oConf->version;
$fields['description'] = $oConf->description; $fields['description'] = $oConf->description;
$fields['PMversion'] = PM_VERSION; $fields['PMversion'] = System::getVersion();
savePluginFile ( 'skinPluginMainClass' , $pathHome . $id . '.php', $fields ); savePluginFile ( 'skinPluginMainClass' , $pathHome . $id . '.php', $fields );
savePluginFile ( 'skinPluginClass' , $pathBase . 'class.' . $id . '.php', $fields ); savePluginFile ( 'skinPluginClass' , $pathBase . 'class.' . $id . '.php', $fields );

View File

@@ -54,14 +54,7 @@ switch ($RBAC->userCanAccess('PM_SETUP'))
break; break;
} }
//get the current process G::LoadClass("system");
if (file_exists(PATH_METHODS . 'login/version-pmos.php'))
{
include('version-pmos.php');
}
else {
define('PM_VERSION', '1.8.320');
}
$id = strip_tags ( str_replace ( ' ', '_', trim ($_POST['form']['NAME']) ) ); $id = strip_tags ( str_replace ( ' ', '_', trim ($_POST['form']['NAME']) ) );
$desc = $_POST['form']['DESCRIPTION']; $desc = $_POST['form']['DESCRIPTION'];

View File

@@ -63,16 +63,9 @@ if( $access != 1 ){
$G_ID_MENU_SELECTED = 'SETUP'; $G_ID_MENU_SELECTED = 'SETUP';
$G_ID_SUB_MENU_SELECTED = 'UPGRADE'; $G_ID_SUB_MENU_SELECTED = 'UPGRADE';
if ( !defined ( 'PM_VERSION' ) ) { G::LoadClass("system");
if (file_exists(PATH_METHODS . 'login/version-pmos.php')) {
include(PATH_METHODS . 'login/version-pmos.php');
}
else {
define('PM_VERSION', 'Development Version');
}
}
$Fields['PM_VERSION'] = PM_VERSION; $Fields['PM_VERSION'] = System::getVersion();
$Fields['MAX_FILE_SIZE'] = $uploadMaxSize . " (" . $UPLOAD_MAX_SIZE . ") "; $Fields['MAX_FILE_SIZE'] = $uploadMaxSize . " (" . $UPLOAD_MAX_SIZE . ") ";
$G_PUBLISH = new Publisher; $G_PUBLISH = new Publisher;