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

@@ -82,25 +82,45 @@ class System {
}
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() {
if (! defined ( 'PM_VERSION' )) {
if (file_exists ( PATH_METHODS . 'login/version-pmos.php' )) {
include (PATH_METHODS . 'login/version-pmos.php');
}
else {
$cmd = sprintf ("cd %s && git status | grep 'On branch' | awk '{print \"Branch: \" $4} '", PATH_TRUNK);
if ( exec ( $cmd , $target) ) {
$cmd = sprintf ("cd %s && git describe ", PATH_TRUNK);
$commit = exec ( $cmd , $target);
define ( 'PM_VERSION', implode(' ', $target) );
}
else
define ( 'PM_VERSION', 'Development Version' );
} else {
$version = self::getVersionFromGit();
if ($version === false)
$version = 'Development Version';
define ( 'PM_VERSION', $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
@@ -109,12 +129,6 @@ class System {
* @return array with system information
*/
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']);
if( getenv('HTTP_CLIENT_IP') ) {
@@ -157,7 +171,7 @@ class System {
$Fields = array();
$Fields['SYSTEM'] = $distro;
$Fields['PHP'] = phpversion();
$Fields['PM_VERSION'] = PM_VERSION;
$Fields['PM_VERSION'] = self::getVersion();
$Fields['SERVER_ADDR'] = $ipe[2]; //lookup($ipe[2]);
$Fields['IP'] = $ipe[0]; //lookup($ipe[0]);
@@ -328,14 +342,7 @@ class System {
}
}
//now getting the current version of PM
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);
$pmVersion = explode('-', self::getVersion());
array_shift($pmVersion);
$patchVersion = explode('-', $this->sRevision);

View File

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

View File

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

View File

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

View File

@@ -116,4 +116,4 @@ if (! defined ( 'SKIP_RENDER_SYSTEM_INFORMATION' )) {
$G_PUBLISH = new Publisher ( );
$G_PUBLISH->AddContent ( 'xmlform', 'xmlform', 'login/dbInfo', '', $Fields, 'appNew2' );
G::RenderPage ( 'publish', 'raw' );
}
}

View File

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

View File

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

View File

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

View File

@@ -89,11 +89,9 @@ try {
$oClass->iPMVersion = 0;
}
if ($oClass->iPMVersion > 0) {
if (!defined('PM_VERSION')) {
define('PM_VERSION', 0);
}
if (PM_VERSION > 0) {
if ($oClass->iPMVersion > PM_VERSION) {
G::LoadClass("system");
if (System::getVersion() > 0) {
if ($oClass->iPMVersion > System::getVersion()) {
//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;
}
//get the current process
if (file_exists(PATH_METHODS . 'login/version-pmos.php'))
{
include(PATH_METHODS . 'login/version-pmos.php');
}
else {
define('PM_VERSION', '1.2.2740');
}
G::LoadClass("system");
$id = $_GET['id'];
@@ -156,7 +149,7 @@ switch ($RBAC->userCanAccess('PM_SETUP'))
$fields['className'] = $id;
$fields['version'] = $oConf->version;
$fields['description'] = $oConf->description;
$fields['PMversion'] = PM_VERSION;
$fields['PMversion'] = System::getVersion();
savePluginFile ( 'skinPluginMainClass' , $pathHome . $id . '.php', $fields );
savePluginFile ( 'skinPluginClass' , $pathBase . 'class.' . $id . '.php', $fields );

View File

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

View File

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