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