From 920d4908bf0f52cb8a48548a923f0549c01b3d77 Mon Sep 17 00:00:00 2001 From: Herbert Saal Gutierrez Date: Wed, 16 May 2012 11:59:47 -0400 Subject: [PATCH] BUG 0000 Support for php 5.2 in Solr implementation Add support for php 5.2 in Solr implementation: - Exception function has two parameters - use of function call_user_func --- workflow/engine/bin/reindex_solr.php | 7 +-- workflow/engine/classes/class.AppSolr.php | 37 ++++++++++----- workflow/engine/classes/class.searchIndex.php | 2 +- workflow/engine/classes/class.solr.php | 45 +++++++++---------- workflow/engine/classes/class.system.php | 24 ++++++---- workflow/engine/classes/entities/Base.php | 10 +++-- 6 files changed, 76 insertions(+), 49 deletions(-) diff --git a/workflow/engine/bin/reindex_solr.php b/workflow/engine/bin/reindex_solr.php index 9f3a355bb..ed51690b3 100644 --- a/workflow/engine/bin/reindex_solr.php +++ b/workflow/engine/bin/reindex_solr.php @@ -53,7 +53,7 @@ if (! defined ( 'PATH_HOME' )) { G::LoadSystem ( 'dvEditor' ); G::LoadSystem ( 'table' ); G::LoadSystem ( 'pagedTable' ); - G::LoadSystem ( 'system' ); + G::LoadClass ( 'system' ); require_once ("propel/Propel.php"); require_once ("creole/Creole.php"); } @@ -103,7 +103,7 @@ if (! defined ( 'SYS_SYS' )) { // **************************************** // read initialize file require_once PATH_HOME . 'engine' . PATH_SEP . 'classes' . PATH_SEP . 'class.system.php'; - $config = System::getSystemConfiguration ( PATH_HOME . 'engine' . PATH_SEP . 'config' . PATH_SEP . 'env.ini' ); + $config = System::getSystemConfiguration ('', '', SYS_SYS); define ( 'MEMCACHED_ENABLED', $config ['memcached'] ); define ( 'MEMCACHED_SERVER', $config ['memcached_server'] ); define ( 'TIME_ZONE', $config ['time_zone'] ); @@ -208,7 +208,8 @@ function processWorkspace() { global $sLastExecution; try { - if ($solrConf = System::solrEnv () !== false) { + + if (($solrConf = System::solrEnv (SYS_SYS)) !== false) { G::LoadClass ( 'AppSolr' ); $oAppSolr = new AppSolr ( $solrConf ['solr_enabled'], $solrConf ['solr_host'], $solrConf ['solr_instance'] ); $oAppSolr->reindexAllApplications (); diff --git a/workflow/engine/classes/class.AppSolr.php b/workflow/engine/classes/class.AppSolr.php index 3819173d7..69ad04c2e 100644 --- a/workflow/engine/classes/class.AppSolr.php +++ b/workflow/engine/classes/class.AppSolr.php @@ -15,10 +15,10 @@ require_once "classes/model/AppSolrQueue.php"; class InvalidIndexSearchTextException extends Exception { // Redefine the exception so message isn't optional - public function __construct($message, $code = 0, Exception $previous = null) { + public function __construct($message, $code = 0) { // some code // make sure everything is assigned properly - parent::__construct ( $message, $code, $previous ); + parent::__construct ( $message, $code); } // custom string representation of object @@ -27,6 +27,20 @@ class InvalidIndexSearchTextException extends Exception { } } +class ApplicationWithoutDelegationRecordsException extends Exception { + // Redefine the exception so message isn't optional + public function __construct($message, $code = 0) { + // some code + // make sure everything is assigned properly + parent::__construct ( $message, $code); + } + + // custom string representation of object + public function __toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; + } +} + class AppSolr { private $solrIsEnabled = false; private $solrHost = ""; @@ -714,12 +728,13 @@ class AppSolr { } // create XML document $xmlDoc = $this->createSolrXMLDocument ( $aaAPPUIDs ); - + // update document $data = array ( 'workspace' => $this->solrInstance, 'document' => $xmlDoc ); + $oSolrUpdateDocument = Entity_SolrUpdateDocument::CreateForRequest ( $data ); G::LoadClass ( 'searchIndex' ); @@ -760,11 +775,14 @@ class AppSolr { $xmlDoc .= "\n"; // echo "APP Uids to index \n"; foreach ( $aaAPPUIDs as $aAPPUID ) { - $result = $this->getApplicationIndexData ( $aAPPUID ['APP_UID'] ); - - if ($result == null) + try { + $result = $this->getApplicationIndexData ( $aAPPUID ['APP_UID'] ); + } + catch(ApplicationWithoutDelegationRecordsException $e){ + //exception trying to get application information + //skip and continue with the next application continue; - + } $documentInformation = $result [0]; $dynaformFieldTypes = $result [1]; $lastUpdateDate = $result [2]; @@ -1049,7 +1067,7 @@ class AppSolr { } else { foreach ( $UnSerializedCaseData as $k => $value ) { - if (! is_array ( $value ) && $value != '' && $k != 'SYS_LANG' && $k != 'SYS_SKIN' && $k != 'SYS_SYS') { + if (!is_array ( $value ) && !is_object($value) && $value != '' && $k != 'SYS_LANG' && $k != 'SYS_SKIN' && $k != 'SYS_SYS') { // search the field type in array of dynaform fields if (! empty ( $dynaformFieldTypes ) && array_key_exists ( trim ( $k ), $dynaformFieldTypes )) { $type = $dynaformFieldTypes [trim ( $k )]; @@ -1157,7 +1175,6 @@ class AppSolr { } function getApplicationIndexData($AppUID) { - G::LoadClass ( 'memcached' ); // get all the application data @@ -1166,7 +1183,7 @@ class AppSolr { // this case occurs when the application doesn't have related delegation // records. if (empty ( $allAppDbData ) || ! isset ( $allAppDbData [0] )) { - throw new Exception ( "Application without delegation records. APP_UID: " . $AppUID ); + throw new ApplicationWithoutDelegationRecordsException ( "Application without delegation records. APP_UID: " . $AppUID ); } // copy the application information diff --git a/workflow/engine/classes/class.searchIndex.php b/workflow/engine/classes/class.searchIndex.php index 61a4d3836..0c377ce04 100644 --- a/workflow/engine/classes/class.searchIndex.php +++ b/workflow/engine/classes/class.searchIndex.php @@ -235,7 +235,7 @@ Class BpmnEngine_Services_SearchIndex G::LoadClass('solr'); $solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); - + //create list of facets $solr->updateDocument($solrUpdateDocumentEntity); } diff --git a/workflow/engine/classes/class.solr.php b/workflow/engine/classes/class.solr.php index 4057fbdb0..cdcc7edf6 100644 --- a/workflow/engine/classes/class.solr.php +++ b/workflow/engine/classes/class.solr.php @@ -40,7 +40,7 @@ class BpmnEngine_SearchIndexAccess_Solr { // get configuration information in base to workspace parameter // get total number of documents in registry - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/select/?q=*:*"; $solrIntruct .= self::SOLR_VERSION; @@ -54,7 +54,7 @@ class BpmnEngine_SearchIndexAccess_Solr { // verify the result of solr $responseSolrTotal = json_decode ( $responseTotal, true ); if ($responseSolrTotal['responseHeader']['status'] != 0) { - throw new Exception ( "Error returning the total number of documents in Solr." ); + throw new Exception ( "Error returning the total number of documents in Solr." . $solrIntruct); } $numTotalDocs = $responseSolrTotal ['response'] ['numFound']; return $numTotalDocs; @@ -101,7 +101,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $filters .= '&fq=' . urlencode ( $value ); } - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/select/?q=$query"; $solrIntruct .= "&echoParams=none"; @@ -123,7 +123,7 @@ class BpmnEngine_SearchIndexAccess_Solr { // decode $responseSolr = json_decode ( $response, true ); if ($responseSolr['responseHeader']['status'] != 0) { - throw new Exception ( "Error executing query to Solr." ); + throw new Exception ( "Error executing query to Solr." . $solrIntruct); } return $responseSolr; @@ -142,10 +142,10 @@ class BpmnEngine_SearchIndexAccess_Solr { return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $solrUpdateDocument->workspace; $solrIntruct .= "/update"; - + $handler = curl_init ( $solrIntruct ); curl_setopt ( $handler, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $handler, CURLOPT_HTTPHEADER, array ( @@ -154,12 +154,11 @@ class BpmnEngine_SearchIndexAccess_Solr { curl_setopt ( $handler, CURLOPT_BINARYTRANSFER, TRUE ); // --data-binary curl_setopt ( $handler, CURLOPT_POSTFIELDS, $solrUpdateDocument->document ); // data $response = curl_exec ( $handler ); - curl_close ( $handler ); - + $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error updating document in Solr." ); + throw new Exception ( "Error updating document in Solr." . $solrIntruct); } } @@ -176,7 +175,7 @@ class BpmnEngine_SearchIndexAccess_Solr { return; $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; @@ -192,7 +191,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error commiting changes in Solr." ); + throw new Exception ( "Error commiting changes in Solr." . $solrIntruct); } } @@ -210,7 +209,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; @@ -226,7 +225,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error rolling back changes in Solr." ); + throw new Exception ( "Error rolling back changes in Solr." . $solrIntruct); } } @@ -244,7 +243,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; @@ -260,7 +259,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error optimizing changes in Solr." ); + throw new Exception ( "Error optimizing changes in Solr." . $solrIntruct); } } @@ -270,7 +269,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/admin/luke?numTerms=0&wt=json"; @@ -281,7 +280,7 @@ class BpmnEngine_SearchIndexAccess_Solr { // decode $responseSolr = json_decode ( $response, true ); if ($responseSolr['responseHeader']['status'] != 0) { - throw new Exception ( "Error getting index fields in Solr." ); + throw new Exception ( "Error getting index fields in Solr." . $solrIntruct); } return $responseSolr; } @@ -301,7 +300,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; @@ -318,7 +317,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error deleting all documents in Solr." ); + throw new Exception ( "Error deleting all documents in Solr." . $solrIntruct); } } @@ -337,7 +336,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $solrIntruct = ''; // get configuration information in base to workspace parameter - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/update"; @@ -354,7 +353,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $swOk = strpos ( $response, '0' ); if (! $swOk) { - throw new Exception ( "Error deleting document in Solr." ); + throw new Exception ( "Error deleting document in Solr." . $solrIntruct); } } @@ -403,7 +402,7 @@ class BpmnEngine_SearchIndexAccess_Solr { $resultFormat = '&wt=json'; - $solrIntruct = $this->solrHost; + $solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct .= $workspace; $solrIntruct .= "/select/?q=$query"; $solrIntruct .= "&echoParams=none"; @@ -424,7 +423,7 @@ class BpmnEngine_SearchIndexAccess_Solr { // decode $responseSolr = json_decode ( $response, true ); if ($responseSolr['responseHeader']['status'] != 0) { - throw new Exception ( "Error getting faceted list from Solr." ); + throw new Exception ( "Error getting faceted list from Solr." . $solrIntruct); } return $responseSolr; diff --git a/workflow/engine/classes/class.system.php b/workflow/engine/classes/class.system.php index b6c076843..938f947b4 100755 --- a/workflow/engine/classes/class.system.php +++ b/workflow/engine/classes/class.system.php @@ -1008,7 +1008,7 @@ class System { return $cities; } - public static function getSystemConfiguration($globalIniFile = '', $wsIniFile = '') + public static function getSystemConfiguration($globalIniFile = '', $wsIniFile = '', $wsName = '') { $readGlobalIniFile = false; $readWsIniFile = false; @@ -1019,12 +1019,15 @@ class System { if (empty($wsIniFile)) { if (defined('PATH_DB')) { // if we're on a valid workspace env. - $uriParts = explode('/', getenv("REQUEST_URI")); - - if (substr($uriParts[1], 0, 3 ) == 'sys') { - $wsName = substr($uriParts[1], 3); - $wsIniFile = PATH_DB . $wsName . PATH_SEP . 'env.ini'; + if (empty($wsName)) { + $uriParts = explode('/', getenv("REQUEST_URI")); + + if (substr($uriParts[1], 0, 3 ) == 'sys') { + $wsName = substr($uriParts[1], 3); + } } + + $wsIniFile = PATH_DB . $wsName . PATH_SEP . 'env.ini'; } } @@ -1121,9 +1124,14 @@ class System { return $result; } - function solrEnv() + function solrEnv($sysName = '') { - $conf = System::getSystemConfiguration(); + if (empty($sysName)) { + $conf = System::getSystemConfiguration(); + } + else { + $conf = System::getSystemConfiguration('', '', $sysName); + } if (!isset($conf['solr_enabled']) || !isset($conf['solr_host']) || !isset($conf['solr_instance'])) { return false; diff --git a/workflow/engine/classes/entities/Base.php b/workflow/engine/classes/entities/Base.php index 5b885763a..39046d3ef 100644 --- a/workflow/engine/classes/entities/Base.php +++ b/workflow/engine/classes/entities/Base.php @@ -59,7 +59,8 @@ class Entity_Base { // get aliases from class $className = get_class ( $this ); if (method_exists ( $className, 'GetAliases' )) { - $aliases = $className::GetAliases (); + $aliases = call_user_func(array($className, 'GetAliases')); + //$aliases = $className::GetAliases (); foreach ( $this as $field => $value ) if (isset ( $aliases [$field] )) { // echo "Field exists in Aliases: " . $field . "\n"; @@ -84,8 +85,8 @@ class Entity_Base { // get aliases from class $className = get_class ( $this ); if (method_exists ( $className, 'GetAliases' )) { - $aliases = $className::GetAliases (); - + $aliases = call_user_func(array($className, 'GetAliases')); + //$aliases = $className::GetAliases (); foreach ( $this as $field => $value ) if (isset ( $aliases [$field] )) $this->{$field} = $aAliasData [$aliases [$field]]; @@ -107,7 +108,8 @@ class Entity_Base { $aliases = array (); $swAliases = false; if (method_exists ( $className, 'GetAliases' )) { - $aliases = $className::GetAliases (); + $aliases = call_user_func(array($className, 'GetAliases')); + //$aliases = $className::GetAliases (); $swAliases = true; } // use object properties or aliases to initialize