BUG 9180 Correct coding convention

Correct coding convention and replace json_encode to G::json_encode and
json_decode to G::json_decode
This commit is contained in:
Herbert Saal Gutierrez
2012-05-30 17:47:28 -04:00
parent 1b2747987e
commit 01d65b3ff1
17 changed files with 1677 additions and 1355 deletions

View File

@@ -8,10 +8,8 @@
// php reindex_solr.php workspacename [reindexall|reindexmissing] // php reindex_solr.php workspacename [reindexall|reindexmissing]
// var_dump($argv); // var_dump($argv);
if (count ($argv) != 3) { if (count ($argv) != 3) {
print "Invalid command line arguments: \n syntax: php reindex_solr.php [workspace_name] [reindexall|reindexmissing] \n". print "Invalid command line arguments: \n syntax: php reindex_solr.php [workspace_name] [reindexall|reindexmissing] \n" . " Where reindexall : reindex all the database \n" . " reindexmissing: reindex only the missing records stored in database.\n";
" Where reindexall : reindex all the database \n". die ();
" reindexmissing: reindex only the missing records stored in database.\n";
die;
} }
$workspaceName = $argv [1]; $workspaceName = $argv [1];
$ScriptAction = $argv [2]; $ScriptAction = $argv [2];
@@ -217,7 +215,8 @@ else {
// @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' => // @file_put_contents(PATH_DATA . 'cron', serialize(array('bCronIsRunning' =>
// '0', 'sLastExecution' => date('Y-m-d H:i:s')))); // '0', 'sLastExecution' => date('Y-m-d H:i:s'))));
function processWorkspace() { function processWorkspace()
{
global $sLastExecution; global $sLastExecution;
global $ScriptAction; global $ScriptAction;
@@ -248,7 +247,8 @@ function processWorkspace() {
} }
} }
function saveLog($sSource, $sType, $sDescription) { function saveLog($sSource, $sType, $sDescription)
{
try { try {
global $isDebug; global $isDebug;
if ($isDebug) if ($isDebug)
@@ -270,7 +270,8 @@ function saveLog($sSource, $sType, $sDescription) {
} }
} }
function setExecutionMessage($m) { function setExecutionMessage($m)
{
$len = strlen ($m); $len = strlen ($m);
$linesize = 60; $linesize = 60;
$rOffset = $linesize - $len; $rOffset = $linesize - $len;
@@ -280,7 +281,8 @@ function setExecutionMessage($m) {
eprint ('.'); eprint ('.');
} }
function setExecutionResultMessage($m, $t = '') { function setExecutionResultMessage($m, $t = '')
{
$c = 'green'; $c = 'green';
if ($t == 'error') if ($t == 'error')
$c = 'red'; $c = 'red';

View File

@@ -1,4 +1,27 @@
<?php <?php
/**
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2012 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 5304 Ventura Drive,
* Delray Beach, FL, 33484, USA, or email info@colosa.com.
*
*/
require_once "classes/model/Application.php"; require_once "classes/model/Application.php";
require_once "classes/model/AppDelegation.php"; require_once "classes/model/AppDelegation.php";
require_once "classes/model/AppThread.php"; require_once "classes/model/AppThread.php";
@@ -13,93 +36,132 @@ require_once "entities/SolrUpdateDocument.php";
require_once "entities/AppSolrQueue.php"; require_once "entities/AppSolrQueue.php";
require_once "classes/model/AppSolrQueue.php"; require_once "classes/model/AppSolrQueue.php";
/** /**
* Invalid search text for Solr exception * Invalid search text for Solr exception
*
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* *
*/ */
class InvalidIndexSearchTextException extends Exception { class InvalidIndexSearchTextException extends Exception
{
// Redefine the exception so message isn't optional // Redefine the exception so message isn't optional
public function __construct($message, $code = 0) { public function __construct($message, $code = 0)
{
// some code // some code
// make sure everything is assigned properly // make sure everything is assigned properly
parent::__construct ($message, $code); parent::__construct ($message, $code);
} }
// custom string representation of object // custom string representation of object
public function __toString() { public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
} }
} }
/** /**
* Application without Delegations exception * Application without Delegations exception
*
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* *
* @category Colosa
* @copyright Copyright (c) 2005-2011 Colosa Inc. (http://www.colosa.com)
*/ */
class ApplicationWithoutDelegationRecordsException extends Exception { class ApplicationWithoutDelegationRecordsException extends Exception
{
// Redefine the exception so message isn't optional // Redefine the exception so message isn't optional
public function __construct($message, $code = 0) { public function __construct($message, $code = 0)
{
// some code // some code
// make sure everything is assigned properly // make sure everything is assigned properly
parent::__construct ($message, $code); parent::__construct ($message, $code);
} }
// custom string representation of object // custom string representation of object
public function __toString() { public function __toString()
{
return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
} }
} }
/** /**
* Implementation to display application data in the PMOS2 grids using Solr search service * Implementation to display application data in the PMOS2 grids using Solr
* search service
* *
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* @category Colosa
* @copyright Copyright (c) 2005-2011 Colosa Inc. (http://www.colosa.com)
* *
*/ */
class AppSolr { class AppSolr
private $solrIsEnabled = false; {
private $solrHost = ""; private $_solrIsEnabled = false;
private $solrInstance = ""; private $_solrHost = "";
private $_solrInstance = "";
function __construct($SolrEnabled, $SolrHost, $SolrInstance) { public function __construct($SolrEnabled, $SolrHost, $SolrInstance)
{
// define solr availability // define solr availability
$this->solrIsEnabled = $SolrEnabled; $this->_solrIsEnabled = $SolrEnabled;
$this->solrHost = $SolrHost; $this->_solrHost = $SolrHost;
$this->solrInstance = $SolrInstance; $this->_solrInstance = $SolrInstance;
} }
public function isSolrEnabled() { /**
return $this->solrIsEnabled; * Return if the Solr functionality is enabled.
* @return boolean true:enabled functionality, false:disabled functionality
*/
public function isSolrEnabled()
{
return $this->_solrIsEnabled;
} }
/** /**
* Gets the information of Grids using Solr server. * Gets the information of Grids using Solr server.
* *
* Returns the list of records for the grid depending of the function conditions * Returns the list of records for the grid depending of the function
* conditions
* If doCount is true only the count of records is returned. * If doCount is true only the count of records is returned.
* *
* @param string $userUid current logged user. * @param string $userUid
* @param int $start the offset to return the group of records. Used for pagination. * current logged user.
* @param int $limit The number of records to return in the set. * @param int $start
* @param string $action the action: todo, participated, draft, unassigned * the offset to return the group of records. Used for pagination.
* @param string $filter filter the results posible values ('read', 'unread', 'started', 'completed') * @param int $limit
* @param string $search search string * The number of records to return in the set.
* @param string $process PRO_UID to filter results by specified process. * @param string $action
* @param string $user USR_UID to filter results by specified user. * the action: todo, participated, draft, unassigned
* @param string $status filter by an application Status : TO_DO, COMPLETED, DRAFT * @param string $filter
* @param string $type default extjs * filter the results posible values ('read', 'unread', 'started',
* @param string $dateFrom filter by DEL_DELEGATE_DATE, not used * 'completed')
* @param string $dateTo filter by DEL_DELEGATE_DATE, not used * @param string $search
* @param string $callback default stcCallback1001 not used * search string
* @param string $dir sort direction ASC, DESC * @param string $process
* @param string $sort sort field * PRO_UID to filter results by specified process.
* @param boolean $doCount default=false, if true only the count of records is returned. * @param string $user
* USR_UID to filter results by specified user.
* @param string $status
* filter by an application Status : TO_DO, COMPLETED, DRAFT
* @param string $type
* default extjs
* @param string $dateFrom
* filter by DEL_DELEGATE_DATE, not used
* @param string $dateTo
* filter by DEL_DELEGATE_DATE, not used
* @param string $callback
* default stcCallback1001 not used
* @param string $dir
* sort direction ASC, DESC
* @param string $sort
* sort field
* @param boolean $doCount
* default=false, if true only the count of records is returned.
* @return array return the list of cases * @return array return the list of cases
*/ */
public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false)
$process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, {
$dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false) {
$callback = isset ($callback) ? $callback : 'stcCallback1001'; $callback = isset ($callback) ? $callback : 'stcCallback1001';
$dir = isset ($dir) ? $dir : 'DESC'; // direction of sort column $dir = isset ($dir) ? $dir : 'DESC'; // direction of sort column
@@ -319,7 +381,7 @@ class AppSolr {
} }
$data = array ( $data = array (
'workspace' => $this->solrInstance, // solr instance 'workspace' => $this->_solrInstance, // solr instance
'startAfter' => intval ($start), 'startAfter' => intval ($start),
'pageSize' => intval ($limit), 'pageSize' => intval ($limit),
'searchText' => $solrSearchText, 'searchText' => $solrSearchText,
@@ -333,9 +395,9 @@ class AppSolr {
'resultFormat' => 'json' 'resultFormat' => 'json'
); );
$solrRequestData = Entity_SolrRequestData::CreateForRequestPagination ( $data ); $solrRequestData = Entity_SolrRequestData::createForRequestPagination ($data);
// use search index to return list of cases // use search index to return list of cases
$searchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); $searchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost);
// execute query // execute query
$solrQueryResult = $searchIndex->getDataTablePaginatedList ($solrRequestData); $solrQueryResult = $searchIndex->getDataTablePaginatedList ($solrRequestData);
@@ -457,32 +519,41 @@ class AppSolr {
/** /**
* Get the array of counters of cases * Get the array of counters of cases
* @param string $userUid the current logged user uid identifier *
* @param string $userUid
* the current logged user uid identifier
*/ */
function getCasesCount($userUid){ public function getCasesCount($userUid)
{
$casesCount = array (); $casesCount = array ();
// get number of records in todo list // get number of records in todo list
$data = $this->getAppGridData($userUid, 0, 0, 'todo', null, null, null, null, null, null, $data = $this->getAppGridData ($userUid, 0, 0, 'todo', null, null, null, null, null,
null, null, null, null, null, true); null, null, null, null, null, null, true);
$casesCount ['to_do'] = $data ['totalCount']; $casesCount ['to_do'] = $data ['totalCount'];
// get number of records in participated list // get number of records in participated list
$data = $this->getAppGridData($userUid, 0, 0, 'sent', null, null, null, null, null, null, $data = $this->getAppGridData ($userUid, 0, 0, 'sent', null, null, null, null, null,
null, null, null, null, null, true); null, null, null, null, null, null, true);
$casesCount ['sent'] = $data ['totalCount']; $casesCount ['sent'] = $data ['totalCount'];
// get number of records in draft list // get number of records in draft list
$data = $this->getAppGridData($userUid, 0, 0, 'draft', null, null, null, null, null, null, $data = $this->getAppGridData ($userUid, 0, 0, 'draft', null, null, null, null, null,
null, null, null, null, null, true); null, null, null, null, null, null, true);
$casesCount ['draft'] = $data ['totalCount']; $casesCount ['draft'] = $data ['totalCount'];
// get number of records in unassigned list // get number of records in unassigned list
$data = $this->getAppGridData($userUid, 0, 0, 'unassigned', null, null, null, null, null, null, $data = $this->getAppGridData ($userUid, 0, 0, 'unassigned', null, null, null, null,
null, null, null, null, null, true); null, null, null, null, null, null, null, true);
$casesCount ['selfservice'] = $data ['totalCount']; $casesCount ['selfservice'] = $data ['totalCount'];
return $casesCount; return $casesCount;
} }
function getUserGroups($usrUID) { /**
* Get the user groups
* @param string $usrUID the user identifier
* @return array of user groups
*/
public function getUserGroups($usrUID)
{
$gu = new GroupUser (); $gu = new GroupUser ();
$rows = $gu->getAllUserGroups ($usrUID); $rows = $gu->getAllUserGroups ($usrUID);
return $rows; return $rows;
@@ -490,11 +561,15 @@ class AppSolr {
/** /**
* Get the application delegation record from database * Get the application delegation record from database
* @param string $appUID Application identifier *
* @param string $delIndex delegation index * @param string $appUID
* Application identifier
* @param string $delIndex
* delegation index
* @return array with delegation record. * @return array with delegation record.
*/ */
function getAppDelegationData($appUID, $delIndex) { public function getAppDelegationData($appUID, $delIndex)
{
$c = new Criteria (); $c = new Criteria ();
@@ -595,7 +670,8 @@ class AppSolr {
* @param string $plainSearchText * @param string $plainSearchText
* @return string formated Solr search string. * @return string formated Solr search string.
*/ */
function getSearchText($plainSearchText) { public function getSearchText($plainSearchText)
{
$formattedSearchText = ""; $formattedSearchText = "";
// if an error is found in string null is returned // if an error is found in string null is returned
$includeToken = true; $includeToken = true;
@@ -628,14 +704,14 @@ class AppSolr {
// cache the index fields // cache the index fields
G::LoadClass ('PMmemcached'); G::LoadClass ('PMmemcached');
$oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); $oMemcache = PMmemcached::getSingleton ($this->_solrInstance);
$ListFieldsInfo = $oMemcache->get ('Solr_Index_Fields'); $ListFieldsInfo = $oMemcache->get ('Solr_Index_Fields');
if (! $ListFieldsInfo) { if (! $ListFieldsInfo) {
G::LoadClass ('searchIndex'); G::LoadClass ('searchIndex');
$searchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); $searchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost);
// execute query // execute query
$ListFieldsInfo = $searchIndex->getIndexFields ( $this->solrInstance ); $ListFieldsInfo = $searchIndex->getIndexFields ($this->_solrInstance);
// cache // cache
$oMemcache->set ('Solr_Index_Fields', $ListFieldsInfo); $oMemcache->set ('Solr_Index_Fields', $ListFieldsInfo);
@@ -645,7 +721,9 @@ class AppSolr {
$tok = strtok ($plainSearchText, " "); $tok = strtok ($plainSearchText, " ");
while ($tok !== false) { while ($tok !== false) {
$fieldName = substr($tok, 0, strpos($tok, ":")); //strstr ( $tok, ":", true ); php 5.3 $fieldName = substr ($tok, 0, strpos ($tok, ":")); // strstr ( $tok,
// ":",
// true ); php 5.3
$searchText = strstr ($tok, ":"); $searchText = strstr ($tok, ":");
// verify if there's a field definition // verify if there's a field definition
@@ -750,16 +828,20 @@ class AppSolr {
if ($fromDateOriginal != '*') { if ($fromDateOriginal != '*') {
// TODO complete date creation // TODO complete date creation
//list($year, $month, $day) = sscanf($fromDateOriginal, '%04d/%02d/%02d'); // list($year, $month, $day) = sscanf($fromDateOriginal,
// '%04d/%02d/%02d');
// $fromDateDatetime = new DateTime($fromDateOriginal); // $fromDateDatetime = new DateTime($fromDateOriginal);
//$fromDateDatetime = date_create_from_format ( 'Y-m-d', $fromDateOriginal ); // $fromDateDatetime = date_create_from_format ( 'Y-m-d',
// $fromDateOriginal );
// $fromDateDatetime->getTimestamp () // $fromDateDatetime->getTimestamp ()
$fromDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal)); $fromDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal));
} }
if ($toDateOriginal != '*') { if ($toDateOriginal != '*') {
//list($year, $month, $day) = sscanf($fromDateOriginal, '%04d/%02d/%02d'); // list($year, $month, $day) = sscanf($fromDateOriginal,
// '%04d/%02d/%02d');
// $toDateDatetime = new DateTime($toDateOriginal); // $toDateDatetime = new DateTime($toDateOriginal);
//$toDateDatetime = date_create_from_format ( 'Y-m-d', $toDateOriginal ); // $toDateDatetime = date_create_from_format ( 'Y-m-d',
// $toDateOriginal );
$toDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal)); $toDate = gmdate ("Y-m-d\T00:00:00\Z", strtotime ($fromDateOriginal));
} }
$searchText = ":[" . $fromDate . " TO " . $toDate . "]"; $searchText = ":[" . $fromDate . " TO " . $toDate . "]";
@@ -786,10 +868,13 @@ class AppSolr {
/** /**
* Get all the application delegation records from database * Get all the application delegation records from database
* @param string $appUID Application identifier *
* @param string $appUID
* Application identifier
* @return array delegation records * @return array delegation records
*/ */
function getApplicationDelegationsIndex($appUID) { public function getApplicationDelegationsIndex($appUID)
{
$delIndexes = array (); $delIndexes = array ();
$c = new Criteria (); $c = new Criteria ();
@@ -815,10 +900,13 @@ class AppSolr {
/** /**
* Update the information of the specified applications in Solr * Update the information of the specified applications in Solr
* @param array $aaAPPUIDs Array of arrays of App_UID that must be updated, *
* @param array $aaAPPUIDs
* Array of arrays of App_UID that must be updated,
* APP_UID is permitted also * APP_UID is permitted also
*/ */
function updateApplicationSearchIndex($aaAPPUIDs) { public function updateApplicationSearchIndex($aaAPPUIDs)
{
if (empty ($aaAPPUIDs)) if (empty ($aaAPPUIDs))
return; return;
@@ -842,28 +930,30 @@ class AppSolr {
// update document // update document
$data = array ( $data = array (
'workspace' => $this->solrInstance, 'workspace' => $this->_solrInstance,
'document' => $xmlDoc 'document' => $xmlDoc
); );
$oSolrUpdateDocument = Entity_SolrUpdateDocument::CreateForRequest ( $data ); $oSolrUpdateDocument = Entity_SolrUpdateDocument::createForRequest ($data);
G::LoadClass ('searchIndex'); G::LoadClass ('searchIndex');
$oSearchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); $oSearchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost);
$oSearchIndex->updateIndexDocument ($oSolrUpdateDocument); $oSearchIndex->updateIndexDocument ($oSolrUpdateDocument);
// commit changes // commit changes
$oSearchIndex->commitIndexChanges ( $this->solrInstance ); $oSearchIndex->commitIndexChanges ($this->_solrInstance);
} }
/** /**
* Delete the specified application record from Solr * Delete the specified application record from Solr
* *
* @param string $appUID Application identifier * @param string $appUID
* Application identifier
*/ */
function deleteApplicationSearchIndex($appUID) { public function deleteApplicationSearchIndex($appUID)
{
if (empty ($appUID)) if (empty ($appUID))
return; return;
@@ -877,21 +967,25 @@ class AppSolr {
G::LoadClass ('searchIndex'); G::LoadClass ('searchIndex');
$oSearchIndex = new BpmnEngine_Services_SearchIndex ( $this->solrIsEnabled, $this->solrHost ); $oSearchIndex = new BpmnEngine_Services_SearchIndex ($this->_solrIsEnabled, $this->_solrHost);
$oSearchIndex->deleteDocumentFromIndex ( $this->solrInstance, $idQuery ); $oSearchIndex->deleteDocumentFromIndex ($this->_solrInstance, $idQuery);
// commit changes // commit changes
$oSearchIndex->commitIndexChanges ( $this->solrInstance ); $oSearchIndex->commitIndexChanges ($this->_solrInstance);
} }
/** /**
* Create XML data in Solr format of the specified applications * Create XML data in Solr format of the specified applications
* this function uses the buildSearchIndexDocumentPMOS2 function to create each record * this function uses the buildSearchIndexDocumentPMOS2 function to create
* @param array $aaAPPUIDs array of arrays of application identifiers * each record
*
* @param array $aaAPPUIDs
* array of arrays of application identifiers
* @return string The resulting XML document in Solr format * @return string The resulting XML document in Solr format
*/ */
function createSolrXMLDocument($aaAPPUIDs) { public function createSolrXMLDocument($aaAPPUIDs)
{
// search data from DB // search data from DB
$xmlDoc = "<?xml version='1.0' encoding='UTF-8'?>\n"; $xmlDoc = "<?xml version='1.0' encoding='UTF-8'?>\n";
$xmlDoc .= "<add>\n"; $xmlDoc .= "<add>\n";
@@ -920,7 +1014,10 @@ class AppSolr {
$unassignedGroups = $result [12]; $unassignedGroups = $result [12];
// create document // create document
$xmlDoc .= $this->buildSearchIndexDocumentPMOS2 ( $documentInformation, $dynaformFieldTypes, $lastUpdateDate, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, $unassignedUsers, $unassignedGroups ); $xmlDoc .= $this->buildSearchIndexDocumentPMOS2 ($documentInformation, $dynaformFieldTypes,
$lastUpdateDate, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread,
$draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser,
$unassignedUsers, $unassignedGroups);
} }
@@ -972,10 +1069,11 @@ class AppSolr {
* $participatedUsersCompletedByUser, * $participatedUsersCompletedByUser,
* $unassignedUsers, $unassignedGroups);* * $unassignedUsers, $unassignedGroups);*
*/ */
function buildSearchIndexDocumentPMOS2($documentData, $dynaformFieldTypes, $lastUpdateDate, public function buildSearchIndexDocumentPMOS2($documentData, $dynaformFieldTypes, $lastUpdateDate,
$maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser, $maxPriority, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser,
$participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser,
$unassignedUsers, $unassignedGroups) { $unassignedUsers, $unassignedGroups)
{
// build xml document // build xml document
$writer = new XMLWriter (); $writer = new XMLWriter ();
@@ -1215,19 +1313,13 @@ class AppSolr {
// try to convert string to date // try to convert string to date
// TODO convert to php 5.2 format // TODO convert to php 5.2 format
/* /*
$newdate = date_create_from_format ( 'Y-m-d H:i:s', $value ); * $newdate = date_create_from_format ( 'Y-m-d H:i:s', $value
if (! $newdate) { * ); if (! $newdate) { $newdate = date_create_from_format (
$newdate = date_create_from_format ( 'Y-m-d', $value ); * 'Y-m-d', $value ); $withHour = false; } if (! $newdate) {
$withHour = false; * $newdate = date_create_from_format ( 'd/m/Y', $value );
} * $withHour = false; } if (! $newdate) { $newdate =
if (! $newdate) { * date_create_from_format ( 'j/m/Y', $value ); $withHour =
$newdate = date_create_from_format ( 'd/m/Y', $value ); * false; }
$withHour = false;
}
if (! $newdate) {
$newdate = date_create_from_format ( 'j/m/Y', $value );
$withHour = false;
}
*/ */
$newdate = strtotime ($value); $newdate = strtotime ($value);
if (! $newdate) { if (! $newdate) {
@@ -1236,12 +1328,11 @@ class AppSolr {
else { else {
$typeSufix = '_tdt'; $typeSufix = '_tdt';
/* /*
if ($withHour) * if ($withHour) //$value = gmdate ( "Y-m-d\TH:i:s\Z",
//$value = gmdate ( "Y-m-d\TH:i:s\Z", $newdate->getTimestamp () ); * $newdate->getTimestamp () ); $value = gmdate (
$value = gmdate ( "Y-m-d\TH:i:s\Z", $newdate ); * "Y-m-d\TH:i:s\Z", $newdate ); else { $value = gmdate (
else { * "Y-m-d\T00:00:00\Z", $newdate ); }
$value = gmdate ( "Y-m-d\T00:00:00\Z", $newdate ); */
}*/
$value = gmdate ("Y-m-d\T00:00:00\Z", $newdate); $value = gmdate ("Y-m-d\T00:00:00\Z", $newdate);
} }
break; break;
@@ -1307,24 +1398,27 @@ class AppSolr {
/** /**
* Search records in specified application delegation data * Search records in specified application delegation data
* @param string $AppUID application identifier *
* @param string $AppUID
* application identifier
* @throws ApplicationWithoutDelegationRecordsException * @throws ApplicationWithoutDelegationRecordsException
* @return array array of arrays with the following information( * @return array array of arrays with the following information(
$documentInformation, * $documentInformation,
$dynaformFieldTypes, * $dynaformFieldTypes,
$lastUpdateDate, * $lastUpdateDate,
$maxPriority, * $maxPriority,
$assignedUsers, * $assignedUsers,
$assignedUsersRead, * $assignedUsersRead,
$assignedUsersUnread, * $assignedUsersUnread,
$draftUser, * $draftUser,
$participatedUsers, * $participatedUsers,
$participatedUsersStartedByUser, * $participatedUsersStartedByUser,
$participatedUsersCompletedByUser, * $participatedUsersCompletedByUser,
$unassignedUsers, * $unassignedUsers,
$unassignedGroups * $unassignedGroups
*/ */
function getApplicationIndexData($AppUID) { public function getApplicationIndexData($AppUID)
{
G::LoadClass ('memcached'); G::LoadClass ('memcached');
// get all the application data // get all the application data
@@ -1448,7 +1542,7 @@ class AppSolr {
foreach ($allAppDbData as $row) { foreach ($allAppDbData as $row) {
$unassignedUsersGroups = array (); $unassignedUsersGroups = array ();
// use cache // use cache
$oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); $oMemcache = PMmemcached::getSingleton ($this->_solrInstance);
$unassignedUsersGroups = $oMemcache->get ($row ['PRO_UID'] . "_" . $row ['TAS_UID']); $unassignedUsersGroups = $oMemcache->get ($row ['PRO_UID'] . "_" . $row ['TAS_UID']);
if (! $unassignedUsersGroups) { if (! $unassignedUsersGroups) {
@@ -1488,7 +1582,7 @@ class AppSolr {
// process // process
$dynaformFieldTypes = array (); $dynaformFieldTypes = array ();
// get cache instance // get cache instance
$oMemcache = PMmemcached::getSingleton ( $this->solrInstance ); $oMemcache = PMmemcached::getSingleton ($this->_solrInstance);
$dynaformFieldTypes = $oMemcache->get ($documentInformation ['PRO_UID']); $dynaformFieldTypes = $oMemcache->get ($documentInformation ['PRO_UID']);
if (! $dynaformFieldTypes) { if (! $dynaformFieldTypes) {
G::LoadClass ('dynaformhandler'); G::LoadClass ('dynaformhandler');
@@ -1542,14 +1636,22 @@ class AppSolr {
/** /**
* Find the maximun value of the specified column in the array and return the * Find the maximun value of the specified column in the array and return the
* row index * row index
* @param array $arr array of arrays with the data *
* @param string $column column name to search in * @param array $arr
* @param string $columnType column type STRING, NUMBER, DATE * array of arrays with the data
* @param string $columnCondition column condition * @param string $column
* @param string $condition the condition * column name to search in
* @param string $columnType
* column type STRING, NUMBER, DATE
* @param string $columnCondition
* column condition
* @param string $condition
* the condition
* @return integer The index of the maximun record in array * @return integer The index of the maximun record in array
*/ */
function aaGetMaximun($arr, $column, $columnType = 'STRING', $columnCondition = "", $condition = "") { public function aaGetMaximun($arr, $column, $columnType = 'STRING',
$columnCondition = "", $condition = "")
{
// get first value // get first value
$auxValue = $arr [0] [$column]; $auxValue = $arr [0] [$column];
$index = null; $index = null;
@@ -1581,14 +1683,21 @@ class AppSolr {
/** /**
* Get minimum of array of arrays * Get minimum of array of arrays
* *
* @param array $arr array of arrays with the data * @param array $arr
* @param string $column the name of the column to search in * array of arrays with the data
* @param string $columnType the column type STRING, NUMBER, DATE * @param string $column
* @param string $columnCondition the column condition * the name of the column to search in
* @param string $condition the condition * @param string $columnType
* the column type STRING, NUMBER, DATE
* @param string $columnCondition
* the column condition
* @param string $condition
* the condition
* @return Ambigous <NULL, unknown> Index of the minimun value found * @return Ambigous <NULL, unknown> Index of the minimun value found
*/ */
function aaGetMinimun($arr, $column, $columnType = 'STRING', $columnCondition = "", $condition = "") { public function aaGetMinimun($arr, $column, $columnType = 'STRING',
$columnCondition = "", $condition = "")
{
// get first value // get first value
$auxValue = $arr [0] [$column]; $auxValue = $arr [0] [$column];
$index = null; $index = null;
@@ -1627,7 +1736,8 @@ class AppSolr {
* contain the conditions that must fullfill 'Column'=>'Condition' * contain the conditions that must fullfill 'Column'=>'Condition'
* @return array array of indexes with the found records * @return array array of indexes with the found records
*/ */
function aaSearchRecords($arr, $andColumnsConditions) { public function aaSearchRecords($arr, $andColumnsConditions)
{
$indexes = array (); $indexes = array ();
$isEqual = true; $isEqual = true;
foreach ($arr as $i => $row) { foreach ($arr as $i => $row) {
@@ -1673,10 +1783,13 @@ class AppSolr {
/** /**
* Get application and delegation data from database * Get application and delegation data from database
* @param string $AppUID the application identifier *
* @param string $AppUID
* the application identifier
* @return array of records from database * @return array of records from database
*/ */
function getApplicationDelegationData($AppUID) { public function getApplicationDelegationData($AppUID)
{
$allAppDbData = array (); $allAppDbData = array ();
@@ -1783,12 +1896,17 @@ class AppSolr {
} }
/** /**
* Get the list of groups of unassigned users of the specified task from database * Get the list of groups of unassigned users of the specified task from
* @param string $ProUID Process identifier * database
* @param string $TaskUID task identifier *
* @param string $ProUID
* Process identifier
* @param string $TaskUID
* task identifier
* @return array of unassigned user groups * @return array of unassigned user groups
*/ */
function getTaskUnassignedUsersGroupsData($ProUID, $TaskUID) { public function getTaskUnassignedUsersGroupsData($ProUID, $TaskUID)
{
$unassignedUsersGroups = array (); $unassignedUsersGroups = array ();
$c = new Criteria (); $c = new Criteria ();
@@ -1828,10 +1946,13 @@ class AppSolr {
/** /**
* Get the list of dynaform file names associated with the specified process * Get the list of dynaform file names associated with the specified process
* from database * from database
* @param string $ProUID process identifier *
* @param string $ProUID
* process identifier
* @return array of dynaform file names * @return array of dynaform file names
*/ */
function getProcessDynaformFileNames($ProUID) { public function getProcessDynaformFileNames($ProUID)
{
$dynaformFileNames = array (); $dynaformFileNames = array ();
$c = new Criteria (); $c = new Criteria ();
@@ -1858,11 +1979,13 @@ class AppSolr {
* Store a flag indicating if the application was updated in database * Store a flag indicating if the application was updated in database
* table APP_SOLR_QUEUE * table APP_SOLR_QUEUE
* *
* @param string $AppUid applicatiom identifier * @param string $AppUid
* applicatiom identifier
* @param integer $updated * @param integer $updated
* 0:false, not updated, 1: updated, 2:deleted * 0:false, not updated, 1: updated, 2:deleted
*/ */
function applicationChangedUpdateSolrQueue($AppUid, $updated) { public function applicationChangedUpdateSolrQueue($AppUid, $updated)
{
$oAppSolrQueue = new AppSolrQueue (); $oAppSolrQueue = new AppSolrQueue ();
$oAppSolrQueue->createUpdate ($AppUid, $updated); $oAppSolrQueue->createUpdate ($AppUid, $updated);
@@ -1871,7 +1994,8 @@ class AppSolr {
/** /**
* Update application records in Solr that are stored in APP_SOLR_QUEUE table * Update application records in Solr that are stored in APP_SOLR_QUEUE table
*/ */
function synchronizePendingApplications() { public function synchronizePendingApplications()
{
// check table of pending updates // check table of pending updates
$oAppSolrQueue = new AppSolrQueue (); $oAppSolrQueue = new AppSolrQueue ();
@@ -1886,9 +2010,11 @@ class AppSolr {
/** /**
* Get the total number of application records in database * Get the total number of application records in database
*
* @return application counter * @return application counter
*/ */
function getCountApplicationsPMOS2() { public function getCountApplicationsPMOS2()
{
$c = new Criteria (); $c = new Criteria ();
$c->addSelectColumn (ApplicationPeer::APP_UID); $c->addSelectColumn (ApplicationPeer::APP_UID);
@@ -1900,11 +2026,15 @@ class AppSolr {
/** /**
* Get a paginated list of application uids from database. * Get a paginated list of application uids from database.
* @param integer $skip the offset from where to return the application records *
* @param integer $pagesize the size of the page * @param integer $skip
* the offset from where to return the application records
* @param integer $pagesize
* the size of the page
* @return array of application id's in the specified page. * @return array of application id's in the specified page.
*/ */
function getPagedApplicationUids($skip, $pagesize) { public function getPagedApplicationUids($skip, $pagesize)
{
$c = new Criteria (); $c = new Criteria ();
@@ -1930,7 +2060,8 @@ class AppSolr {
* Reindex all the application records in Solr server * Reindex all the application records in Solr server
* update applications in groups of 1000 * update applications in groups of 1000
*/ */
function reindexAllApplications() { public function reindexAllApplications()
{
$trunk = 1000; $trunk = 1000;
// delete all documents to begin reindex // delete all documents to begin reindex
// deleteAllDocuments(); // deleteAllDocuments();

View File

@@ -1,4 +1,26 @@
<?php <?php
/**
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2012 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 5304 Ventura Drive,
* Delray Beach, FL, 33484, USA, or email info@colosa.com.
*
*/
/** /**
@@ -7,23 +29,26 @@
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* *
*/ */
Class BpmnEngine_Services_SearchIndex class BpmnEngine_Services_SearchIndex
{ {
private $solrIsEnabled = false; private $_solrIsEnabled = false;
private $solrHost = ""; private $_solrHost = "";
function __construct($solrIsEnabled = false, $solrHost = ""){ function __construct($solrIsEnabled = false, $solrHost = "")
{
// check if Zend Library is available // check if Zend Library is available
// if(class_exists("Zend_Registry")){ // if(class_exists("Zend_Registry")){
// $registry = Zend_Registry::getInstance(); // $registry = Zend_Registry::getInstance();
// //check if configuration is enabled // //check if configuration is enabled
// $this->solrIsEnabled = $registry->isRegistered('solrEnabled') && $registry->get('solrEnabled') == 1; // $this->solrIsEnabled = $registry->isRegistered('solrEnabled') &&
// $this->solrHost = $registry->isRegistered('solrHost')?$registry->get('solrHost'):""; // $registry->get('solrEnabled') == 1;
// $this->solrHost =
// $registry->isRegistered('solrHost')?$registry->get('solrHost'):"";
// } // }
// else{ // else{
// //use the parameters to initialize class // //use the parameters to initialize class
$this->solrIsEnabled = $solrIsEnabled; $this->_solrIsEnabled = $solrIsEnabled;
$this->solrHost = $solrHost; $this->_solrHost = $solrHost;
// } // }
} }
/** /**
@@ -33,36 +58,43 @@ Class BpmnEngine_Services_SearchIndex
* @background = false * @background = false
* *
* no input parameters @param[in] * no input parameters @param[in]
* @param[out] bool true if index service is enabled false in other case *
* @param
* [out] bool true if index service is enabled false in other case
*/ */
public function isEnabled() public function isEnabled()
{ {
//require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); // require_once (ROOT_PATH .
// '/businessLogic/modules/SearchIndexAccess/Solr.php');
require_once ('class.solr.php'); require_once ('class.solr.php');
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
return $solr->isEnabled (); return $solr->isEnabled ();
} }
/** /**
* Get the list of facets in base to the specified query and filter * Get the list of facets in base to the specified query and filter
* @gearman = true * @gearman = true
* @rest = false * @rest = false
* @background = false * @background = false
* *
* @param[in] Entity_FacetRequest facetRequestEntity Facet request entity * @param
* @param[out] array FacetGroup * [in] Entity_FacetRequest facetRequestEntity Facet request entity
* @param
* [out] array FacetGroup
*/ */
function getFacetsList($facetRequestEntity) public function getFacetsList($facetRequestEntity)
{ {
require_once ('class.solr.php'); require_once ('class.solr.php');
//require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); // require_once (ROOT_PATH .
// '/businessLogic/modules/SearchIndexAccess/Solr.php');
require_once ('entities/FacetGroup.php'); require_once ('entities/FacetGroup.php');
require_once ('entities/FacetItem.php'); require_once ('entities/FacetItem.php');
require_once ('entities/SelectedFacetGroupItem.php'); require_once ('entities/SelectedFacetGroupItem.php');
require_once ('entities/FacetResult.php'); require_once ('entities/FacetResult.php');
/******************************************************************/ /**
* ***************************************************************
*/
// get array of selected facet groups // get array of selected facet groups
$facetRequestEntity->selectedFacetsString = str_replace (',,', ',', $facetRequestEntity->selectedFacetsString); $facetRequestEntity->selectedFacetsString = str_replace (',,', ',', $facetRequestEntity->selectedFacetsString);
// remove descriptions of selected facet groups // remove descriptions of selected facet groups
@@ -72,8 +104,7 @@ Class BpmnEngine_Services_SearchIndex
$aGroups = array_filter ($aGroups); // remove empty items $aGroups = array_filter ($aGroups); // remove empty items
$aSelectedFacetGroups = array (); $aSelectedFacetGroups = array ();
foreach($aGroups as $i => $value) foreach ($aGroups as $i => $value) {
{
$gi = explode (':::', $value); $gi = explode (':::', $value);
$gr = explode ('::', $gi [0]); $gr = explode ('::', $gi [0]);
$it = explode ('::', $gi [1]); $it = explode ('::', $gi [1]);
@@ -81,8 +112,7 @@ Class BpmnEngine_Services_SearchIndex
// create string for remove condition // create string for remove condition
$count = 0; $count = 0;
$removeCondition = str_replace ($value . ',', '', $facetRequestEntity->selectedFacetsString, $count); $removeCondition = str_replace ($value . ',', '', $facetRequestEntity->selectedFacetsString, $count);
if($count == 0) if ($count == 0) {
{
$removeCondition = str_replace ($value, '', $facetRequestEntity->selectedFacetsString, $count); $removeCondition = str_replace ($value, '', $facetRequestEntity->selectedFacetsString, $count);
} }
$selectedFacetGroupData = array ( $selectedFacetGroupData = array (
@@ -93,29 +123,38 @@ Class BpmnEngine_Services_SearchIndex
'selectedFacetRemoveCondition' => $removeCondition 'selectedFacetRemoveCondition' => $removeCondition
); );
$aSelectedFacetGroups[] = Entity_SelectedFacetGroupItem::CreateForRequest($selectedFacetGroupData); $aSelectedFacetGroups [] = Entity_SelectedFacetGroupItem::createForRequest ($selectedFacetGroupData);
} }
/******************************************************************/ /**
* ***************************************************************
*/
// convert request to index request // convert request to index request
// create filters // create filters
$filters = array (); $filters = array ();
if (! empty ($aSelectedFacetGroups)) { if (! empty ($aSelectedFacetGroups)) {
//exclude facetFields and facetDates included in filter from the next list of facets // exclude facetFields and facetDates included in filter from the next
// list of facets
foreach ($aSelectedFacetGroups as $value) { foreach ($aSelectedFacetGroups as $value) {
$facetRequestEntity->facetFields = array_diff($facetRequestEntity->facetFields, array($value->selectedFacetGroupName)); $facetRequestEntity->facetFields = array_diff ($facetRequestEntity->facetFields, array (
$facetRequestEntity->facetDates = array_diff($facetRequestEntity->facetDates, array($value->selectedFacetGroupName)); $value->selectedFacetGroupName
));
$facetRequestEntity->facetDates = array_diff ($facetRequestEntity->facetDates, array (
$value->selectedFacetGroupName
));
} }
//$facetFields = array_diff($facetFields, $facetInterfaceRequestEntity->selectedFacetGroups); // $facetFields = array_diff($facetFields,
//$facetDates = array_diff($facetDates, $facetInterfaceRequestEntity->selectedFacetGroups); // $facetInterfaceRequestEntity->selectedFacetGroups);
// $facetDates = array_diff($facetDates,
// $facetInterfaceRequestEntity->selectedFacetGroups);
foreach ($aSelectedFacetGroups as $group) { foreach ($aSelectedFacetGroups as $group) {
$filters [] = $group->selectedFacetGroupName . ':' . urlencode ($group->selectedFacetItemName); $filters [] = $group->selectedFacetGroupName . ':' . urlencode ($group->selectedFacetItemName);
} }
} }
$facetRequestEntity->filters = $filters; $facetRequestEntity->filters = $filters;
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// create list of facets // create list of facets
$facetsList = $solr->getFacetsList ($facetRequestEntity); $facetsList = $solr->getFacetsList ($facetRequestEntity);
@@ -126,54 +165,56 @@ Class BpmnEngine_Services_SearchIndex
$facetGroups = array (); $facetGroups = array ();
// convert facet fields result to objects // convert facet fields result to objects
/************************************************************************/ /**
* *********************************************************************
*/
// include facet field results // include facet field results
$facetFieldsResult = $facetsList ['facet_counts'] ['facet_fields']; $facetFieldsResult = $facetsList ['facet_counts'] ['facet_fields'];
if(!empty($facetFieldsResult)) if (! empty ($facetFieldsResult)) {
{ foreach ($facetFieldsResult as $facetGroup => $facetvalues) {
foreach($facetFieldsResult as $facetGroup => $facetvalues)
{
if (count ($facetvalues) > 0) // if the group have facets included if (count ($facetvalues) > 0) // if the group have facets included
{ {
$data = array('facetGroupName' => $facetGroup); $data = array (
'facetGroupName' => $facetGroup
);
$data ['facetGroupPrintName'] = $facetGroup; $data ['facetGroupPrintName'] = $facetGroup;
$data ['facetGroupType'] = 'field'; $data ['facetGroupType'] = 'field';
$facetItems = array (); $facetItems = array ();
for($i = 0; $i < count($facetvalues) ; $i+=2) for ($i = 0; $i < count ($facetvalues); $i += 2) {
{
$dataItem = array (); $dataItem = array ();
$dataItem ['facetName'] = $facetvalues [$i]; $dataItem ['facetName'] = $facetvalues [$i];
$dataItem ['facetPrintName'] = $facetvalues [$i]; $dataItem ['facetPrintName'] = $facetvalues [$i];
$dataItem ['facetCount'] = $facetvalues [$i + 1]; $dataItem ['facetCount'] = $facetvalues [$i + 1];
$dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName']; $dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName'];
$newFacetItem = Entity_FacetItem::CreateForInsert($dataItem); $newFacetItem = Entity_FacetItem::createForInsert ($dataItem);
$facetItems [] = $newFacetItem; $facetItems [] = $newFacetItem;
} }
$data ['facetItems'] = $facetItems; $data ['facetItems'] = $facetItems;
$newFacetGroup = Entity_FacetGroup::CreateForInsert($data); $newFacetGroup = Entity_FacetGroup::createForInsert ($data);
$facetGroups [] = $newFacetGroup; $facetGroups [] = $newFacetGroup;
} }
} }
} }
/************************************************************************/ /**
* *********************************************************************
*/
// include facet date ranges results // include facet date ranges results
$facetDatesResult = $facetsList ['facet_counts'] ['facet_dates']; $facetDatesResult = $facetsList ['facet_counts'] ['facet_dates'];
if(!empty($facetDatesResult)) if (! empty ($facetDatesResult)) {
foreach ($facetDatesResult as $facetGroup => $facetvalues) {
if (count ($facetvalues) > 3) // if the group have any facets included
// besides start, end and gap
{ {
foreach($facetDatesResult as $facetGroup => $facetvalues) $data = array (
{ 'facetGroupName' => $facetGroup
if(count($facetvalues) > 3) //if the group have any facets included besides start, end and gap );
{
$data = array('facetGroupName' => $facetGroup);
$data ['facetGroupPrintName'] = $facetGroup; $data ['facetGroupPrintName'] = $facetGroup;
$data ['facetGroupType'] = 'daterange'; $data ['facetGroupType'] = 'daterange';
$facetItems = array (); $facetItems = array ();
$facetvalueskeys = array_keys ($facetvalues); $facetvalueskeys = array_keys ($facetvalues);
foreach ($facetvalueskeys as $i => $k) foreach ($facetvalueskeys as $i => $k) {
{ if ($k != 'gap' && $k != 'start' && $k != 'end') {
if($k != 'gap' && $k != 'start' && $k != 'end')
{
$dataItem = array (); $dataItem = array ();
if ($i < count ($facetvalueskeys) - 4) { if ($i < count ($facetvalueskeys) - 4) {
@@ -188,13 +229,13 @@ Class BpmnEngine_Services_SearchIndex
$dataItem ['facetCount'] = $facetvalues [$k]; $dataItem ['facetCount'] = $facetvalues [$k];
$dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName']; $dataItem ['facetSelectCondition'] = $facetRequestEntity->selectedFacetsString . (empty ($facetRequestEntity->selectedFacetsString) ? '' : ',') . $data ['facetGroupName'] . '::' . $data ['facetGroupPrintName'] . ':::' . $dataItem ['facetName'] . '::' . $dataItem ['facetPrintName'];
$newFacetItem = Entity_FacetItem::CreateForInsert($dataItem); $newFacetItem = Entity_FacetItem::createForInsert ($dataItem);
$facetItems [] = $newFacetItem; $facetItems [] = $newFacetItem;
} }
} }
$data ['facetItems'] = $facetItems; $data ['facetItems'] = $facetItems;
$newFacetGroup = Entity_FacetGroup::CreateForInsert($data); $newFacetGroup = Entity_FacetGroup::createForInsert ($data);
$facetGroups [] = $newFacetGroup; $facetGroups [] = $newFacetGroup;
} }
@@ -202,32 +243,44 @@ Class BpmnEngine_Services_SearchIndex
} }
// TODO:convert facet queries // TODO:convert facet queries
// ----- // -----
/******************************************************************/ /**
* ***************************************************************
*/
// Create a filter string used in the filter of results of a datatable // Create a filter string used in the filter of results of a datatable
$filterText = ''; //the list of selected filters used for filtering result, send in ajax $filterText = ''; // the list of selected filters used for filtering result,
foreach($aSelectedFacetGroups as $selectedFacetGroup) // send in ajax
{ foreach ($aSelectedFacetGroups as $selectedFacetGroup) {
$filterText .= $selectedFacetGroup->selectedFacetGroupName . ':' . urlencode ($selectedFacetGroup->selectedFacetItemName) . ','; $filterText .= $selectedFacetGroup->selectedFacetGroupName . ':' . urlencode ($selectedFacetGroup->selectedFacetItemName) . ',';
} }
$filterText = substr_replace ($filterText, '', - 1); $filterText = substr_replace ($filterText, '', - 1);
// $filterText = ($filterText == '')?'':'&filterText='.$filterText; // $filterText = ($filterText == '')?'':'&filterText='.$filterText;
/******************************************************************/ /**
* ***************************************************************
*/
// Create result // Create result
$dataFacetResult = array ( $dataFacetResult = array (
'aFacetGroups' => $facetGroups, 'aFacetGroups' => $facetGroups,
'aSelectedFacetGroups' => $aSelectedFacetGroups, 'aSelectedFacetGroups' => $aSelectedFacetGroups,
'sFilterText' => $filterText 'sFilterText' => $filterText
); );
$facetResult = Entity_FacetResult::CreateForRequest($dataFacetResult); $facetResult = Entity_FacetResult::createForRequest ($dataFacetResult);
return $facetResult; return $facetResult;
} }
function getNumberDocuments($workspace){ /**
* Get the total number of documents in search server
* @param string $workspace
* @return integer number of documents
*
*/
public function getNumberDocuments($workspace)
{
require_once ('class.solr.php'); require_once ('class.solr.php');
//require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); // require_once (ROOT_PATH .
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); // '/businessLogic/modules/SearchIndexAccess/Solr.php');
$solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// create list of facets // create list of facets
$numberDocuments = $solr->getNumberDocuments ($workspace); $numberDocuments = $solr->getNumberDocuments ($workspace);
@@ -235,36 +288,59 @@ Class BpmnEngine_Services_SearchIndex
return $numberDocuments; return $numberDocuments;
} }
function updateIndexDocument($solrUpdateDocumentEntity){ /**
* Update document Index
* @param SolrUpdateDocumentEntity $solrUpdateDocumentEntity
*/
public function updateIndexDocument($solrUpdateDocumentEntity)
{
G::LoadClass ('solr'); G::LoadClass ('solr');
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// create list of facets // create list of facets
$solr->updateDocument ($solrUpdateDocumentEntity); $solr->updateDocument ($solrUpdateDocumentEntity);
} }
function deleteDocumentFromIndex($workspace, $idQuery){ /**
* Delete document from index
* @param string $workspace
* @param string $idQuery
*/
public function deleteDocumentFromIndex($workspace, $idQuery)
{
G::LoadClass ('solr'); G::LoadClass ('solr');
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// create list of facets // create list of facets
$solr->deleteDocument ($workspace, $idQuery); $solr->deleteDocument ($workspace, $idQuery);
} }
function commitIndexChanges($workspace){ /**
* Commit index changes
* @param string $workspace
*/
public function commitIndexChanges($workspace)
{
G::LoadClass ('solr'); G::LoadClass ('solr');
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// commit // commit
$solr->commitChanges ($workspace); $solr->commitChanges ($workspace);
} }
function getDataTablePaginatedList($solrRequestData){ /**
* Call Solr server to return the list of paginated pages.
* @param FacetRequest $solrRequestData
* @return Entity_SolrQueryResult
*/
public function getDataTablePaginatedList($solrRequestData)
{
require_once ('class.solr.php'); require_once ('class.solr.php');
//require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); // require_once (ROOT_PATH .
// '/businessLogic/modules/SearchIndexAccess/Solr.php');
require_once ('entities/SolrRequestData.php'); require_once ('entities/SolrRequestData.php');
require_once ('entities/SolrQueryResult.php'); require_once ('entities/SolrQueryResult.php');
@@ -284,11 +360,12 @@ Class BpmnEngine_Services_SearchIndex
} }
// remove placeholder fields // remove placeholder fields
// the placeholder doesn't affect the the solr's response // the placeholder doesn't affect the the solr's response
//$solrRequestData->includeCols = array_diff($solrRequestData->includeCols, array('')); // $solrRequestData->includeCols = array_diff($solrRequestData->includeCols,
// array(''));
// print_r($solrRequestData); // print_r($solrRequestData);
// execute query // execute query
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); $solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
$solrPaginatedResult = $solr->executeQuery ($solrRequestData); $solrPaginatedResult = $solr->executeQuery ($solrRequestData);
// get total number of documents in index // get total number of documents in index
@@ -302,7 +379,9 @@ Class BpmnEngine_Services_SearchIndex
// insert list of names in docs result // insert list of names in docs result
$data = array ( $data = array (
"sEcho" => '', // must be completed in response "sEcho" => '', // must be completed in response
"iTotalRecords" => intval($numTotalDocs), //we must get the total number of documents "iTotalRecords" => intval ($numTotalDocs), // we must get the
// total number of
// documents
"iTotalDisplayRecords" => $numFound, "iTotalDisplayRecords" => $numFound,
"aaData" => array () "aaData" => array ()
); );
@@ -312,32 +391,40 @@ Class BpmnEngine_Services_SearchIndex
foreach ($solrRequestData->includeCols as $columnName) { foreach ($solrRequestData->includeCols as $columnName) {
if ($columnName == '') { if ($columnName == '') {
$data ['aaData'] [$i] [] = ''; // placeholder $data ['aaData'] [$i] [] = ''; // placeholder
}else{ }
else {
if (isset ($doc [$columnName])) { if (isset ($doc [$columnName])) {
$data ['aaData'] [$i] [] = $doc [$columnName]; $data ['aaData'] [$i] [] = $doc [$columnName];
}else{ }
else {
$data ['aaData'] [$i] [] = ''; $data ['aaData'] [$i] [] = '';
} }
} }
} }
} }
$solrQueryResponse = Entity_SolrQueryResult::CreateForRequest($data); $solrQueryResponse = Entity_SolrQueryResult::createForRequest ($data);
// //
return $solrQueryResponse; return $solrQueryResponse;
} }
function getIndexFields($workspace){ /**
* Return the list of stored fields in the index.
* @param string $workspace
* @return array of index fields
*/
public function getIndexFields($workspace)
{
// global $indexFields; // global $indexFields;
// cache // cache
// if(!empty($indexFields)) // if(!empty($indexFields))
// return $indexFields; // return $indexFields;
require_once ('class.solr.php'); require_once ('class.solr.php');
//require_once (ROOT_PATH . '/businessLogic/modules/SearchIndexAccess/Solr.php'); // require_once (ROOT_PATH .
$solr = new BpmnEngine_SearchIndexAccess_Solr($this->solrIsEnabled, $this->solrHost); // '/businessLogic/modules/SearchIndexAccess/Solr.php');
$solr = new BpmnEngine_SearchIndexAccess_Solr ($this->_solrIsEnabled, $this->_solrHost);
// print "SearchIndex!!!!"; // print "SearchIndex!!!!";
// create list of facets // create list of facets
@@ -352,7 +439,8 @@ Class BpmnEngine_Services_SearchIndex
// $listFields[strtolower($originalFieldName)] = $key; // $listFields[strtolower($originalFieldName)] = $key;
// Maintain case sensitive variable names // Maintain case sensitive variable names
$listFields [$originalFieldName] = $key; $listFields [$originalFieldName] = $key;
}else{ }
else {
// $listFields[strtolower($key)] = $key; // $listFields[strtolower($key)] = $key;
// Maintain case sensitive variable names // Maintain case sensitive variable names
$listFields [$key] = $key; $listFields [$key] = $key;

View File

@@ -1,19 +1,44 @@
<?php <?php
/**
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2012 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 5304 Ventura Drive,
* Delray Beach, FL, 33484, USA, or email info@colosa.com.
*
*/
/** /**
* Interface to the Solr Search server * Interface to the Solr Search server
* @author Herbert Saal Gutierrez * @author Herbert Saal Gutierrez
* *
*/ */
class BpmnEngine_SearchIndexAccess_Solr { class BpmnEngine_SearchIndexAccess_Solr
{
const SOLR_VERSION = '&version=2.2'; const SOLR_VERSION = '&version=2.2';
private $solrIsEnabled = false; private $_solrIsEnabled = false;
private $solrHost = ""; private $_solrHost = "";
function __construct($solrIsEnabled = false, $solrHost = "") { public function __construct($solrIsEnabled = false, $solrHost = "")
{
// use the parameters to initialize class // use the parameters to initialize class
$this->solrIsEnabled = $solrIsEnabled; $this->_solrIsEnabled = $solrIsEnabled;
$this->solrHost = $solrHost; $this->_solrHost = $solrHost;
} }
/** /**
@@ -24,10 +49,11 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return bool * @return bool
*/ */
function isEnabled() { public function isEnabled()
{
// verify solr server response // verify solr server response
return $this->solrIsEnabled; return $this->_solrIsEnabled;
} }
/** /**
@@ -40,13 +66,14 @@ class BpmnEngine_SearchIndexAccess_Solr {
* workspace: workspace name * workspace: workspace name
* @return total * @return total
*/ */
function getNumberDocuments($workspace) { public function getNumberDocuments($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
// get total number of documents in registry // get total number of documents in registry
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=*:*"; $solrIntruct .= "/select/?q=*:*";
$solrIntruct .= self::SOLR_VERSION; $solrIntruct .= self::SOLR_VERSION;
@@ -58,7 +85,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
curl_close ($handlerTotal); curl_close ($handlerTotal);
// verify the result of solr // verify the result of solr
$responseSolrTotal = json_decode ( $responseTotal, true ); $responseSolrTotal = G::json_decode ($responseTotal, true);
if ($responseSolrTotal ['responseHeader'] ['status'] != 0) { if ($responseSolrTotal ['responseHeader'] ['status'] != 0) {
throw new Exception ("Error returning the total number of documents in Solr." . $solrIntruct); throw new Exception ("Error returning the total number of documents in Solr." . $solrIntruct);
} }
@@ -74,8 +101,9 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function executeQuery($solrRequestData) { public function executeQuery($solrRequestData)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
@@ -107,7 +135,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
$filters .= '&fq=' . urlencode ($value); $filters .= '&fq=' . urlencode ($value);
} }
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=$query"; $solrIntruct .= "/select/?q=$query";
$solrIntruct .= "&echoParams=none"; $solrIntruct .= "&echoParams=none";
@@ -126,7 +154,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
curl_close ($handler); curl_close ($handler);
// decode // decode
$responseSolr = json_decode ( $response, true ); $responseSolr = G::json_decode ($response, true);
if ($responseSolr ['responseHeader'] ['status'] != 0) { if ($responseSolr ['responseHeader'] ['status'] != 0) {
throw new Exception ("Error executing query to Solr." . $solrIntruct); throw new Exception ("Error executing query to Solr." . $solrIntruct);
} }
@@ -142,12 +170,13 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function updateDocument($solrUpdateDocument) { public function updateDocument($solrUpdateDocument)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $solrUpdateDocument->workspace; $solrIntruct .= $solrUpdateDocument->workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -175,12 +204,13 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function commitChanges($workspace) { public function commitChanges($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -208,13 +238,14 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function rollbackChanges($workspace) { public function rollbackChanges($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -242,13 +273,14 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function optimizeChanges($workspace) { public function optimizeChanges($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -270,17 +302,20 @@ class BpmnEngine_SearchIndexAccess_Solr {
/** /**
* Return the list of the stored fields in Solr * Return the list of the stored fields in Solr
* @param string $workspace Solr instance name *
* @param string $workspace
* Solr instance name
* @throws Exception * @throws Exception
* @return void|mixed array of field names * @return void mixed of field names
*/ */
function getListIndexedStoredFields($workspace) { public function getListIndexedStoredFields($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/admin/luke?numTerms=0&wt=json"; $solrIntruct .= "/admin/luke?numTerms=0&wt=json";
@@ -289,7 +324,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
$response = curl_exec ($handler); $response = curl_exec ($handler);
curl_close ($handler); curl_close ($handler);
// decode // decode
$responseSolr = json_decode ( $response, true ); $responseSolr = G::json_decode ($response, true);
if ($responseSolr ['responseHeader'] ['status'] != 0) { if ($responseSolr ['responseHeader'] ['status'] != 0) {
throw new Exception ("Error getting index fields in Solr." . $solrIntruct); throw new Exception ("Error getting index fields in Solr." . $solrIntruct);
} }
@@ -304,14 +339,15 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function deleteAllDocuments($workspace) { public function deleteAllDocuments($workspace)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
// $registry = Zend_Registry::getInstance(); // $registry = Zend_Registry::getInstance();
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -340,14 +376,15 @@ class BpmnEngine_SearchIndexAccess_Solr {
* *
* @return solr response * @return solr response
*/ */
function deleteDocument($workspace, $idQuery) { public function deleteDocument($workspace, $idQuery)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
// $registry = Zend_Registry::getInstance(); // $registry = Zend_Registry::getInstance();
$solrIntruct = ''; $solrIntruct = '';
// get configuration information in base to workspace parameter // get configuration information in base to workspace parameter
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/update"; $solrIntruct .= "/update";
@@ -374,8 +411,9 @@ class BpmnEngine_SearchIndexAccess_Solr {
* @param Entity_FacetRequest $facetRequestEntity * @param Entity_FacetRequest $facetRequestEntity
* @return solr response: list of facets array * @return solr response: list of facets array
*/ */
function getFacetsList($facetRequest) { public function getFacetsList($facetRequest)
if (! $this->solrIsEnabled) {
if (! $this->_solrIsEnabled)
return; return;
$solrIntruct = ''; $solrIntruct = '';
@@ -413,7 +451,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
$resultFormat = '&wt=json'; $resultFormat = '&wt=json';
$solrIntruct = (substr($this->solrHost, -1) == "/")?$this->solrHost:$this->solrHost . "/"; $solrIntruct = (substr ($this->_solrHost, - 1) == "/") ? $this->_solrHost : $this->_solrHost . "/";
$solrIntruct .= $workspace; $solrIntruct .= $workspace;
$solrIntruct .= "/select/?q=$query"; $solrIntruct .= "/select/?q=$query";
$solrIntruct .= "&echoParams=none"; $solrIntruct .= "&echoParams=none";
@@ -432,7 +470,7 @@ class BpmnEngine_SearchIndexAccess_Solr {
curl_close ($handler); curl_close ($handler);
// decode // decode
$responseSolr = json_decode ( $response, true ); $responseSolr = G::json_decode ($response, true);
if ($responseSolr ['responseHeader'] ['status'] != 0) { if ($responseSolr ['responseHeader'] ['status'] != 0) {
throw new Exception ("Error getting faceted list from Solr." . $solrIntruct); throw new Exception ("Error getting faceted list from Solr." . $solrIntruct);
} }

View File

@@ -4,20 +4,24 @@ require_once ('Base.php');
/** /**
* Application Solr Queue * Application Solr Queue
*/ */
class Entity_AppSolrQueue extends Entity_Base { class Entity_AppSolrQueue extends Entity_Base
{
public $appUid = ''; public $appUid = '';
public $appUpdated = 0; public $appUpdated = 0;
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_AppSolrQueue (); $obj = new Entity_AppSolrQueue ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_AppSolrQueue (); $obj = new Entity_AppSolrQueue ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,12 +1,14 @@
<?php <?php
class Entity_Base { class Entity_Base
{
/** /**
* this function check if a field is in the data sent in the constructor * this function check if a field is in the data sent in the constructor
* you can specify an array, and this function will use like alias * you can specify an array, and this function will use like alias
*/ */
protected function validateField($field, $default = false) { protected function validateField($field, $default = false)
{
$fieldIsEmpty = true; $fieldIsEmpty = true;
// this is a trick, if $fields is a string, $fields will be an array with // this is a trick, if $fields is a string, $fields will be an array with
@@ -37,7 +39,8 @@ class Entity_Base {
} }
} }
protected function validateRequiredFields($requiredFields = array()) { protected function validateRequiredFields($requiredFields = array())
{
foreach ($requiredFields as $k => $field) { foreach ($requiredFields as $k => $field) {
if ($this->{$field} === NULL) { if ($this->{$field} === NULL) {
throw (new Exception ("Field $field is required in " . get_class ($this))); throw (new Exception ("Field $field is required in " . get_class ($this)));
@@ -47,6 +50,7 @@ class Entity_Base {
} }
/** /**
*
* *
* *
* Copy the values of the Entity to the array of aliases * Copy the values of the Entity to the array of aliases
@@ -54,12 +58,16 @@ class Entity_Base {
* *
* @return Array of alias with the Entity values * @return Array of alias with the Entity values
*/ */
public function getAliasDataArray() { public function getAliasDataArray()
{
$aAlias = array (); $aAlias = array ();
// get aliases from class // get aliases from class
$className = get_class ($this); $className = get_class ($this);
if (method_exists ($className, 'GetAliases')) { if (method_exists ($className, 'GetAliases')) {
$aliases = call_user_func(array($className, 'GetAliases')); $aliases = call_user_func (array (
$className,
'GetAliases'
));
// $aliases = $className::GetAliases (); // $aliases = $className::GetAliases ();
foreach ($this as $field => $value) foreach ($this as $field => $value)
if (isset ($aliases [$field])) { if (isset ($aliases [$field])) {
@@ -74,6 +82,7 @@ class Entity_Base {
} }
/** /**
*
* *
* *
* Set the data from array of alias to Entity * Set the data from array of alias to Entity
@@ -81,11 +90,15 @@ class Entity_Base {
* @param $aAliasData array * @param $aAliasData array
* of data of aliases * of data of aliases
*/ */
public function setAliasDataArray($aAliasData) { public function setAliasDataArray($aAliasData)
{
// get aliases from class // get aliases from class
$className = get_class ($this); $className = get_class ($this);
if (method_exists ($className, 'GetAliases')) { if (method_exists ($className, 'GetAliases')) {
$aliases = call_user_func(array($className, 'GetAliases')); $aliases = call_user_func (array (
$className,
'GetAliases'
));
// $aliases = $className::GetAliases (); // $aliases = $className::GetAliases ();
foreach ($this as $field => $value) foreach ($this as $field => $value)
if (isset ($aliases [$field])) if (isset ($aliases [$field]))
@@ -94,6 +107,7 @@ class Entity_Base {
} }
/** /**
*
* *
* *
* Initialize object with values from $data. * Initialize object with values from $data.
@@ -102,13 +116,17 @@ class Entity_Base {
* @param * @param
* $data * $data
*/ */
protected function initializeObject($data) { protected function initializeObject($data)
{
// get aliases from class // get aliases from class
$className = get_class ($this); $className = get_class ($this);
$aliases = array (); $aliases = array ();
$swAliases = false; $swAliases = false;
if (method_exists ($className, 'GetAliases')) { if (method_exists ($className, 'GetAliases')) {
$aliases = call_user_func(array($className, 'GetAliases')); $aliases = call_user_func (array (
$className,
'GetAliases'
));
// $aliases = $className::GetAliases (); // $aliases = $className::GetAliases ();
$swAliases = true; $swAliases = true;
} }
@@ -122,13 +140,15 @@ class Entity_Base {
} }
} }
public function serialize() { public function serialize()
{
if (isset ($this->temp)) if (isset ($this->temp))
unset ($this->temp); unset ($this->temp);
return serialize ($this); return serialize ($this);
} }
public function unserialize($str) { public function unserialize($str)
{
$className = get_class ($this); $className = get_class ($this);
$data = unserialize ($str); $data = unserialize ($str);
return new $className ($data); return new $className ($data);

View File

@@ -2,8 +2,6 @@
require_once ('Base.php'); require_once ('Base.php');
/** /**
*
*
* Facet group entity that represent a facet group * Facet group entity that represent a facet group
* *
* @property $facetGroupName: The name of the facet (field name in solr index) * @property $facetGroupName: The name of the facet (field name in solr index)
@@ -16,22 +14,26 @@ require_once ('Base.php');
* @author dev-HebertSaak * @author dev-HebertSaak
* *
*/ */
class Entity_FacetGroup extends Entity_Base { class Entity_FacetGroup extends Entity_Base
{
public $facetGroupName = ''; public $facetGroupName = '';
public $facetGroupPrintName = ''; public $facetGroupPrintName = '';
public $facetGroupType = ''; // field, daterange, query public $facetGroupType = ''; // field, daterange, query
public $facetGroupId = ''; public $facetGroupId = '';
public $facetItems = array (); public $facetItems = array ();
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetGroup (); $obj = new Entity_FacetGroup ();
return $obj; return $obj;
} }
static function CreateForInsert($data) { static function createForInsert($data)
{
$obj = new Entity_FacetGroup (); $obj = new Entity_FacetGroup ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,7 +1,8 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_FacetInterfaceRequest extends Entity_Base { class Entity_FacetInterfaceRequest extends Entity_Base
{
public $searchText = ''; public $searchText = '';
public $selectedFacetsString = ''; // string of selected facet groups and public $selectedFacetsString = ''; // string of selected facet groups and
// items in format: // items in format:
@@ -10,15 +11,18 @@ class Entity_FacetInterfaceRequest extends Entity_Base {
// var $selectedFacetFields = array(); // var $selectedFacetFields = array();
// var $selectedFacetTypes = array(); // var $selectedFacetTypes = array();
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetInterfaceRequest (); $obj = new Entity_FacetInterfaceRequest ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_FacetInterfaceRequest (); $obj = new Entity_FacetInterfaceRequest ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,22 +1,26 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_FacetInterfaceResult extends Entity_Base { class Entity_FacetInterfaceResult extends Entity_Base
{
// array of facetsgroups, array of Entity_SelectedFacetGroupItem, filter text // array of facetsgroups, array of Entity_SelectedFacetGroupItem, filter text
public $aFacetGroup = array (); public $aFacetGroup = array ();
public $aSelectedFacetGroupItem = array (); public $aSelectedFacetGroupItem = array ();
public $sFilterText = ''; public $sFilterText = '';
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetInterfaceResult (); $obj = new Entity_FacetInterfaceResult ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_FacetInterfaceResult (); $obj = new Entity_FacetInterfaceResult ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -2,6 +2,7 @@
require_once ('Base.php'); require_once ('Base.php');
/** /**
*
* *
* *
* Entity Face item, represent an option in a facet group * Entity Face item, represent an option in a facet group
@@ -9,22 +10,26 @@ require_once ('Base.php');
* @author dev-HebertSaak * @author dev-HebertSaak
* *
*/ */
class Entity_FacetItem extends Entity_Base { class Entity_FacetItem extends Entity_Base
{
public $facetName = ''; public $facetName = '';
public $facetPrintName = ''; public $facetPrintName = '';
public $facetCount = ''; public $facetCount = '';
public $facetSelectCondition = ''; // selected condition used to select public $facetSelectCondition = ''; // selected condition used to select
// this facet // this facet
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetItem (); $obj = new Entity_FacetItem ();
return $obj; return $obj;
} }
static function CreateForInsert($data) { static function createForInsert($data)
{
$obj = new Entity_FacetItem (); $obj = new Entity_FacetItem ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,7 +1,8 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_FacetRequest extends Entity_Base { class Entity_FacetRequest extends Entity_Base
{
public $workspace = ''; public $workspace = '';
public $searchText = ''; public $searchText = '';
public $facetFields = array (); public $facetFields = array ();
@@ -14,15 +15,18 @@ class Entity_FacetRequest extends Entity_Base {
public $filters = array (); public $filters = array ();
public $selectedFacetsString = ''; public $selectedFacetsString = '';
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetRequest (); $obj = new Entity_FacetRequest ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_FacetRequest (); $obj = new Entity_FacetRequest ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,20 +1,24 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_FacetResult extends Entity_Base { class Entity_FacetResult extends Entity_Base
{
public $aFacetGroups = array (); public $aFacetGroups = array ();
public $aSelectedFacetGroups = array (); public $aSelectedFacetGroups = array ();
public $sFilterText = ''; public $sFilterText = '';
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_FacetResult (); $obj = new Entity_FacetResult ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_FacetResult (); $obj = new Entity_FacetResult ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,7 +1,8 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_SelectedFacetGroupItem extends Entity_Base { class Entity_SelectedFacetGroupItem extends Entity_Base
{
public $selectedFacetGroupName = ''; public $selectedFacetGroupName = '';
public $selectedFacetGroupPrintName = ''; public $selectedFacetGroupPrintName = '';
public $selectedFacetItemName = ''; public $selectedFacetItemName = '';
@@ -10,15 +11,18 @@ class Entity_SelectedFacetGroupItem extends Entity_Base {
// selected facets without this // selected facets without this
// facet // facet
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_SelectedFacetGroupItem (); $obj = new Entity_SelectedFacetGroupItem ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_SelectedFacetGroupItem (); $obj = new Entity_SelectedFacetGroupItem ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,22 +1,26 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_SolrQueryResult extends Entity_Base { class Entity_SolrQueryResult extends Entity_Base
{
public $sEcho = ''; public $sEcho = '';
public $iTotalRecords = 0; public $iTotalRecords = 0;
public $iTotalDisplayRecords = 10; public $iTotalDisplayRecords = 10;
public $aaData = array (); // array of arrays of records to public $aaData = array (); // array of arrays of records to
// display // display
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_SolrQueryResult (); $obj = new Entity_SolrQueryResult ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_SolrQueryResult (); $obj = new Entity_SolrQueryResult ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,7 +1,8 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_SolrRequestData extends Entity_Base { class Entity_SolrRequestData extends Entity_Base
{
public $workspace = ''; public $workspace = '';
public $startAfter = 0; public $startAfter = 0;
public $pageSize = 10; public $pageSize = 10;
@@ -17,15 +18,18 @@ class Entity_SolrRequestData extends Entity_Base {
public $includeCols = array (); public $includeCols = array ();
public $resultFormat = 'xml'; // json, xml, php public $resultFormat = 'xml'; // json, xml, php
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_SolrRequestData (); $obj = new Entity_SolrRequestData ();
return $obj; return $obj;
} }
static function CreateForRequestPagination($data) { static function createForRequestPagination($data)
{
$obj = new Entity_SolrRequestData (); $obj = new Entity_SolrRequestData ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -1,19 +1,23 @@
<?php <?php
require_once ('Base.php'); require_once ('Base.php');
class Entity_SolrUpdateDocument extends Entity_Base { class Entity_SolrUpdateDocument extends Entity_Base
{
var $workspace = ''; var $workspace = '';
var $document = ''; var $document = '';
private function __construct() { private function __construct()
{
} }
static function CreateEmpty() { static function createEmpty()
{
$obj = new Entity_SolrUpdateDocument (); $obj = new Entity_SolrUpdateDocument ();
return $obj; return $obj;
} }
static function CreateForRequest($data) { static function createForRequest($data)
{
$obj = new Entity_SolrUpdateDocument (); $obj = new Entity_SolrUpdateDocument ();
$obj->initializeObject ($data); $obj->initializeObject ($data);

View File

@@ -109,7 +109,7 @@ class AppSolrQueue extends BaseAppSolrQueue {
$row = $rs->getRow(); $row = $rs->getRow();
while (is_array($row)) { while (is_array($row)) {
$appSolrQueue = Entity_AppSolrQueue::CreateEmpty(); $appSolrQueue = Entity_AppSolrQueue::createEmpty();
$appSolrQueue->appUid = $row['APP_UID']; $appSolrQueue->appUid = $row['APP_UID'];
$appSolrQueue->appUpdated = $row['APP_UPDATED']; $appSolrQueue->appUpdated = $row['APP_UPDATED'];
$updatedApplications[] = $appSolrQueue; $updatedApplications[] = $appSolrQueue;