CODE STYLE class.system.php

This commit is contained in:
Fernando Ontiveros
2012-10-09 13:25:03 -04:00
parent f926ac68e9
commit 1028fb9788

View File

@@ -1,6 +1,8 @@
<?php
/**
* upgrade_System.php
*
* @package workflow.engine.classes
*
* ProcessMaker Open Source Edition
@@ -29,11 +31,13 @@
*
* author Erik A.O.<erik@colosa.com>
* date May 12th, 2010
*
* @package workflow.engine.classes
*
*/
class System {
class System
{
var $sFilename;
var $sFilesList;
@@ -48,9 +52,11 @@ class System {
* List currently installed plugins
*
* param
*
* @return array with the names of the plugins
*/
public static function getPlugins() {
public static function getPlugins ()
{
$plugins = array ();
foreach (glob( PATH_PLUGINS . "*" ) as $filename) {
@@ -73,7 +79,8 @@ class System {
* @access public
* @return array of workspace tools objects
*/
public static function listWorkspaces() {
public static function listWorkspaces ()
{
$oDirectory = dir( PATH_DB );
$aWorkspaces = array ();
foreach (glob( PATH_DB . "*" ) as $filename) {
@@ -84,13 +91,15 @@ class System {
}
/**
* Get the ProcessMaker version. If version-pmos.php is not found, try to
* 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 (file_exists( PATH_METHODS . 'login/version-pmos.php' )) {
include (PATH_METHODS . 'login/version-pmos.php');
@@ -110,7 +119,8 @@ class System {
* @author Alexandre Rosenfeld <alexandre@colosa.com>
* @return string branch and tag information
*/
public static function getVersionFromGit($dir = NULL) {
public static function getVersionFromGit ($dir = NULL)
{
if ($dir == NULL)
$dir = PATH_TRUNK;
if (! file_exists( "$dir/.git" ))
@@ -126,9 +136,11 @@ class System {
* Get system information
*
* param
*
* @return array with system information
*/
public static function getSysInfo() {
public static function getSysInfo ()
{
$ipe = explode( " ", $_SERVER['SSH_CONNECTION'] );
if (getenv( 'HTTP_CLIENT_IP' )) {
@@ -175,12 +187,14 @@ class System {
$Fields['SERVER_ADDR'] = $ipe[2]; //lookup($ipe[2]);
$Fields['IP'] = $ipe[0]; //lookup($ipe[0]);
$Fields['PLUGINS_LIST'] = System::getPlugins();
return $Fields;
}
public static function listPoFiles() {
public static function listPoFiles ()
{
$folders = glob( PATH_CORE . '/content/translations/*' );
$items = glob( PATH_CORE . '/content/translations/*.po' );
@@ -194,11 +208,13 @@ class System {
return $items;
}
public static function verifyChecksum() {
public static function verifyChecksum ()
{
if (! file_exists( PATH_TRUNK . "checksum.txt" ))
return false;
$lines = explode( "\n", file_get_contents( PATH_TRUNK . "checksum.txt" ) );
$result = array("diff" => array(), "missing" => array());
$result = array ("diff" => array (),"missing" => array ()
);
foreach ($lines as $line) {
if (empty( $line ))
continue;
@@ -254,9 +270,7 @@ class System {
{
G::LoadClass( 'archive' );
$this->sFilesList = new gzip_file( $this->sFilename );
$this->sFilesList->set_options(array (
'basedir' => dirname($this->sFilename),
'overwrite' => 1
$this->sFilesList->set_options( array ('basedir' => dirname( $this->sFilename ),'overwrite' => 1
) );
$this->sFilesList->extract_files();
if (count( $this->sFilesList->error ) > 0) {
@@ -653,7 +667,8 @@ class System {
*
* @return schema content in an array
*/
public static function getSystemSchema() {
public static function getSystemSchema ()
{
return System::getSchema( PATH_TRUNK . "workflow/engine/config/schema.xml" );
}
@@ -663,7 +678,8 @@ class System {
* @param string $pluginName name of the plugin
* @return $sContent
*/
public static function getPluginSchema($pluginName) {
public static function getPluginSchema ($pluginName)
{
if (file_exists( PATH_PLUGINS . $pluginName . "/config/schema.xml" ))
return System::getSchema( PATH_PLUGINS . $pluginName . "/config/schema.xml" );
else
@@ -676,20 +692,13 @@ class System {
* @param string $sSchemaFile schema filename
* @return $sContent
*/
public static function getSchema($sSchemaFile) {
public static function getSchema ($sSchemaFile)
{
/* This is the MySQL mapping that Propel uses (from MysqlPlatform.php) */
$mysqlTypes = array(
'NUMERIC' => "DECIMAL",
'LONGVARCHAR' => "MEDIUMTEXT",
'TIMESTAMP' => "DATETIME",
'BU_TIMESTAMP' => "DATETIME",
'BINARY' => "BLOB",
'VARBINARY' => "MEDIUMBLOB",
'LONGVARBINARY' => "LONGBLOB",
'BLOB' => "LONGBLOB",
'CLOB' => "LONGTEXT",
$mysqlTypes = array ('NUMERIC' => "DECIMAL",'LONGVARCHAR' => "MEDIUMTEXT",'TIMESTAMP' => "DATETIME",'BU_TIMESTAMP' => "DATETIME",'BINARY' => "BLOB",'VARBINARY' => "MEDIUMBLOB",'LONGVARBINARY' => "LONGBLOB",'BLOB' => "LONGBLOB",'CLOB' => "LONGTEXT",
/* This is not from Propel, but is required to get INT right */
'INTEGER' => "INT");
'INTEGER' => "INT"
);
$aSchema = array ();
$oXml = new DomDocument();
@@ -722,21 +731,19 @@ class System {
$required = $oColumn->hasAttribute( 'required' ) ? $oColumn->getAttribute( 'required' ) : NULL;
/* Convert $required to a bool */
$required = (in_array (strtolower ($required), array('1', 'true')));
$required = (in_array( strtolower( $required ), array ('1','true'
) ));
$default = $oColumn->hasAttribute( 'default' ) ? $oColumn->getAttribute( 'default' ) : NULL;
$primaryKey = $oColumn->hasAttribute( 'primaryKey' ) ? $oColumn->getAttribute( 'primaryKey' ) : NULL;
/* Convert $primaryKey to a bool */
$primaryKey = (in_array (strtolower ($primaryKey), array('1', 'true')));
$primaryKey = (in_array( strtolower( $primaryKey ), array ('1','true'
) ));
if ($primaryKey)
$aPrimaryKeys[] = $sColumName;
$aSchema[$sTableName][$sColumName] = array(
'Field' => $sColumName,
'Type' => $type,
'Null' => $required ? "NO" : "YES",
'Default' => $default
$aSchema[$sTableName][$sColumName] = array ('Field' => $sColumName,'Type' => $type,'Null' => $required ? "NO" : "YES",'Default' => $default
);
}
@@ -763,7 +770,8 @@ class System {
* @param array $aNewSchema new schema array
* @return array with tablesToAdd, tablesToAlter, tablesWithNewIndex and tablesToAlterIndex
*/
public static function compareSchema($aOldSchema, $aNewSchema) {
public static function compareSchema ($aOldSchema, $aNewSchema)
{
//$aChanges = array('tablesToDelete' => array(), 'tablesToAdd' => array(), 'tablesToAlter' => array());
//Tables to delete, but this is disabled
//foreach ($aOldSchema as $sTableName => $aColumns) {
@@ -774,19 +782,21 @@ class System {
// }
//}
$aChanges = array('tablesToAdd' => array(), 'tablesToAlter' => array(), 'tablesWithNewIndex' => array(), 'tablesToAlterIndex'=> array());
$aChanges = array ('tablesToAdd' => array (),'tablesToAlter' => array (),'tablesWithNewIndex' => array (),'tablesToAlterIndex' => array ()
);
//new tables to create and alter
foreach ($aNewSchema as $sTableName => $aColumns) {
if (! isset( $aOldSchema[$sTableName] )) {
$aChanges['tablesToAdd'][$sTableName] = $aColumns;
}
else {
} else {
//drop old columns
foreach ($aOldSchema[$sTableName] as $sColumName => $aParameters) {
if (! isset( $aNewSchema[$sTableName][$sColumName] )) {
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
$aChanges['tablesToAlter'][$sTableName] = array('DROP' => array(), 'ADD' => array(), 'CHANGE' => array());
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
);
}
$aChanges['tablesToAlter'][$sTableName]['DROP'][$sColumName] = $sColumName;
}
@@ -798,18 +808,21 @@ class System {
if ($sColumName != 'INDEXES') {
if (! isset( $aOldSchema[$sTableName][$sColumName] )) { //this column doesnt exist in oldschema
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
$aChanges['tablesToAlter'][$sTableName] = array('DROP' => array(), 'ADD' => array(), 'CHANGE' => array());
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
);
}
$aChanges['tablesToAlter'][$sTableName]['ADD'][$sColumName] = $aParameters;
}
else { //the column exists
} else { //the column exists
$newField = $aNewSchema[$sTableName][$sColumName];
$oldField = $aOldSchema[$sTableName][$sColumName];
//both are null, no change is required
if ( !isset($newField['Default']) && !isset($oldField['Default'])) $changeDefaultAttr = false;
if (! isset( $newField['Default'] ) && ! isset( $oldField['Default'] ))
$changeDefaultAttr = false;
//one of them is null, change IS required
if ( !isset($newField['Default']) && isset($oldField['Default']) && $oldField['Default']!= '') $changeDefaultAttr = true;
if ( isset($newField['Default']) && !isset($oldField['Default'])) $changeDefaultAttr = true;
if (! isset( $newField['Default'] ) && isset( $oldField['Default'] ) && $oldField['Default'] != '')
$changeDefaultAttr = true;
if (isset( $newField['Default'] ) && ! isset( $oldField['Default'] ))
$changeDefaultAttr = true;
//both are defined and they are different.
if (isset( $newField['Default'] ) && isset( $oldField['Default'] )) {
if ($newField['Default'] != $oldField['Default'])
@@ -819,11 +832,13 @@ class System {
}
//special cases
// BLOB and TEXT columns cannot have DEFAULT values. http://dev.mysql.com/doc/refman/5.0/en/blob.html
if ( in_array(strtolower($newField['Type']), array('text','mediumtext') ) )
if (in_array( strtolower( $newField['Type'] ), array ('text','mediumtext'
) ))
$changeDefaultAttr = false;
//#1067 - Invalid default value for datetime field
if ( in_array($newField['Type'], array('datetime')) && isset($newField['Default']) && $newField['Default']== '' )
if (in_array( $newField['Type'], array ('datetime'
) ) && isset( $newField['Default'] ) && $newField['Default'] == '')
$changeDefaultAttr = false;
//#1067 - Invalid default value for int field
@@ -831,12 +846,10 @@ class System {
$changeDefaultAttr = false;
//if any difference exists, then insert the difference in aChanges
if ( strcasecmp($newField['Field'], $oldField['Field']) !== 0 ||
strcasecmp($newField['Type'], $oldField['Type']) !== 0 ||
strcasecmp($newField['Null'], $oldField['Null']) !== 0 ||
$changeDefaultAttr ) {
if (strcasecmp( $newField['Field'], $oldField['Field'] ) !== 0 || strcasecmp( $newField['Type'], $oldField['Type'] ) !== 0 || strcasecmp( $newField['Null'], $oldField['Null'] ) !== 0 || $changeDefaultAttr) {
if (! isset( $aChanges['tablesToAlter'][$sTableName] )) {
$aChanges['tablesToAlter'][$sTableName] = array('DROP' => array(), 'ADD' => array(), 'CHANGE' => array());
$aChanges['tablesToAlter'][$sTableName] = array ('DROP' => array (),'ADD' => array (),'CHANGE' => array ()
);
}
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Field'] = $newField['Field'];
$aChanges['tablesToAlter'][$sTableName]['CHANGE'][$sColumName]['Type'] = $newField['Type'];
@@ -851,6 +864,7 @@ class System {
} //only columns, no the indexes column
} //foreach $aColumns
//now check the indexes of table
if (isset( $aNewSchema[$sTableName]['INDEXES'] )) {
foreach ($aNewSchema[$sTableName]['INDEXES'] as $indexName => $indexFields) {
@@ -859,8 +873,7 @@ class System {
$aChanges['tablesWithNewIndex'][$sTableName] = array ();
}
$aChanges['tablesWithNewIndex'][$sTableName][$indexName] = $indexFields;
}
else {
} else {
if ($aOldSchema[$sTableName]['INDEXES'][$indexName] != $indexFields) {
if (! isset( $aChanges['tablesToAlterIndex'][$sTableName] )) {
$aChanges['tablesToAlterIndex'][$sTableName] = array ();
@@ -875,7 +888,6 @@ class System {
return $aChanges;
}
function getEmailConfiguration ()
{
G::LoadClass( 'configuration' );
@@ -942,16 +954,14 @@ class System {
$timezones = DateTimeZone::listAbbreviations();
$cities = array ();
foreach( $timezones as $key => $zones )
{
foreach( $zones as $id => $zone )
{
foreach ($timezones as $key => $zones) {
foreach ($zones as $id => $zone) {
/**
* Only get timezones explicitely not part of "Others".
*
* @see http://www.php.net/manual/en/timezones.others.php
*/
if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Africa|Europe|Indian|Pacific)\//', $zone['timezone_id'] )
&& $zone['timezone_id']) {
if (preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Africa|Europe|Indian|Pacific)\//', $zone['timezone_id'] ) && $zone['timezone_id']) {
$cities[$zone['timezone_id']][] = $key;
}
}
@@ -1015,22 +1025,7 @@ class System {
}
// default configuration
$config = array(
'debug' => 0,
'debug_sql' => 0,
'debug_time' => 0,
'debug_calendar' => 0,
'wsdl_cache' => 1,
'memory_limit' => '128M',
'time_zone' => 'America/New_York',
'memcached' => 0,
'memcached_server' => '',
'default_skin' => 'classic',
'default_lang' => 'en',
'proxy_host' => '',
'proxy_port' => '',
'proxy_user' => '',
'proxy_pass' => ''
$config = array ('debug' => 0,'debug_sql' => 0,'debug_time' => 0,'debug_calendar' => 0,'wsdl_cache' => 1,'memory_limit' => '128M','time_zone' => 'America/New_York','memcached' => 0,'memcached_server' => '','default_skin' => 'classic','default_lang' => 'en','proxy_host' => '','proxy_port' => '','proxy_user' => '','proxy_pass' => ''
);
// read the global env.ini configuration file
@@ -1069,8 +1064,7 @@ class System {
{
if (! file_exists( PATH_HTML . 'index.html' )) {
throw new Exception( 'The public index file "' . PATH_HTML . 'index.html" does not exist!' );
}
else {
} else {
if (! is_writable( PATH_HTML . 'index.html' )) {
throw new Exception( 'The index.html file is not writable on workflow/public_html directory.' );
}
@@ -1099,8 +1093,7 @@ class System {
{
if (empty( $sysName )) {
$conf = System::getSystemConfiguration();
}
else {
} else {
$conf = System::getSystemConfiguration( '', '', $sysName );
}
@@ -1109,10 +1102,7 @@ class System {
}
if ($conf['solr_enabled']) {
return array(
'solr_enabled' => $conf['solr_enabled'],
'solr_host' => $conf['solr_host'],
'solr_instance' => $conf['solr_instance']
return array ('solr_enabled' => $conf['solr_enabled'],'solr_host' => $conf['solr_host'],'solr_instance' => $conf['solr_instance']
);
}