LSsearch : use LSlog_logger

This commit is contained in:
Benjamin Renard 2020-05-08 13:51:13 +02:00
parent e0a44cb8aa
commit 0cac3631c6

View file

@ -77,6 +77,9 @@ class LSsearch {
// Caches // Caches
private $_canCopy=NULL; private $_canCopy=NULL;
// Logger
private $logger = null;
/** /**
* Constructor * Constructor
* *
@ -87,6 +90,7 @@ class LSsearch {
* *
**/ **/
public function __construct($LSobject,$context,$params=null,$purgeParams=false) { public function __construct($LSobject,$context,$params=null,$purgeParams=false) {
$this -> logger = LSlog :: get_logger(get_called_class());
if (!LSsession :: loadLSobject($LSobject)) { if (!LSsession :: loadLSobject($LSobject)) {
return; return;
} }
@ -102,7 +106,7 @@ class LSsearch {
if (!$purgeParams) { if (!$purgeParams) {
if (! $this -> loadParamsFromSession()) { if (! $this -> loadParamsFromSession()) {
LSdebug('LSsearch : load default parameters'); $this -> logger -> debug('LSsearch : load default parameters');
$this -> loadDefaultParameters(); $this -> loadDefaultParameters();
} }
} }
@ -152,7 +156,7 @@ class LSsearch {
* @retval boolean True if params has been loaded from session or False * @retval boolean True if params has been loaded from session or False
*/ */
private function loadParamsFromSession() { private function loadParamsFromSession() {
LSdebug('LSsearch : load context params session '.$this -> context); $this -> logger -> debug('LSsearch : load context params session '.$this -> context);
if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context]) && is_array($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context])) { if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context]) && is_array($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context])) {
$params = $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context]; $params = $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context];
@ -172,7 +176,7 @@ class LSsearch {
* @retval void * @retval void
*/ */
private function saveParamsInSession() { private function saveParamsInSession() {
LSdebug('LSsearch : save context params session '.$this -> context); $this -> logger -> debug('LSsearch : save context params session '.$this -> context);
$params = $this -> params; $params = $this -> params;
if ($params['filter'] instanceof Net_LDAP2_Filter) { if ($params['filter'] instanceof Net_LDAP2_Filter) {
$params['filter'] = $params['filter'] -> asString(); $params['filter'] = $params['filter'] -> asString();
@ -180,7 +184,7 @@ class LSsearch {
foreach ($params as $param => $value) { foreach ($params as $param => $value) {
if ( !isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]) || $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) { if ( !isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]) || $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]!=$value) {
LSdebug("S: $param => ".varDump($value)); $this -> logger -> debug("S: $param => ".varDump($value));
$_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value; $_SESSION['LSsession']['LSsearch'][$this -> LSobject]['params'][$this -> context][$param]=$value;
} }
} }
@ -885,21 +889,21 @@ class LSsearch {
public function run($cache=true) { public function run($cache=true) {
$this -> generateSearchParams(); $this -> generateSearchParams();
if ($this -> _searchParams['filter'] instanceof Net_LDAP2_Filter) { if ($this -> _searchParams['filter'] instanceof Net_LDAP2_Filter) {
LSdebug('LSsearch : filter : '.$this -> _searchParams['filter']->asString()); $this -> logger -> debug('LSsearch : filter : '.$this -> _searchParams['filter']->asString());
} }
LSdebug('LSsearch : basedn : '.$this -> _searchParams['basedn'].' - scope : '.$this -> _searchParams['scope']); $this -> logger -> debug('LSsearch : basedn : '.$this -> _searchParams['basedn'].' - scope : '.$this -> _searchParams['scope']);
if( $cache && (!isset($_REQUEST['refresh'])) && (!$this -> params['withoutCache']) ) { if( $cache && (!isset($_REQUEST['refresh'])) && (!$this -> params['withoutCache']) ) {
LSdebug('LSsearch : with the cache'); $this -> logger -> debug('LSsearch : with the cache');
$this -> result = $this -> getResultFromCache(); $this -> result = $this -> getResultFromCache();
} }
else { else {
LSdebug('LSsearch : without the cache'); $this -> logger -> debug('LSsearch : without the cache');
$this -> setParam('withoutCache',false); $this -> setParam('withoutCache',false);
} }
if (!$this -> result) { if (!$this -> result) {
LSdebug('LSsearch : Not in cache'); $this -> logger -> debug('LSsearch : Not in cache');
$this -> result=array( $this -> result=array(
'sortBy' => NULL, 'sortBy' => NULL,
'sortDirection' => NULL 'sortDirection' => NULL
@ -967,7 +971,7 @@ class LSsearch {
**/ **/
public function addResultToCache() { public function addResultToCache() {
if ($this -> cacheIsEnabled()) { if ($this -> cacheIsEnabled()) {
LSdebug('LSsearch : Save result in cache.'); $this -> logger -> debug('LSsearch : Save result in cache.');
$hash=$this->getHash(); $hash=$this->getHash();
$_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash]=$this->result; $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash]=$this->result;
} }
@ -982,7 +986,7 @@ class LSsearch {
if ($this -> cacheIsEnabled()) { if ($this -> cacheIsEnabled()) {
$hash=$this->getHash(); $hash=$this->getHash();
if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash])) { if (isset($_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash])) {
LSdebug('LSsearch : Load result from cache.'); $this -> logger -> debug('LSsearch : Load result from cache.');
return $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash]; return $_SESSION['LSsession']['LSsearch'][$this -> LSobject][$hash];
} }
} }
@ -1011,7 +1015,7 @@ class LSsearch {
); );
if ($retval['total']>0) { if ($retval['total']>0) {
LSdebug('Total : '.$retval['total']); $this -> logger -> debug('Total : '.$retval['total']);
if (!$this->params['nbObjectsByPage']) { if (!$this->params['nbObjectsByPage']) {
$this->params['nbObjectsByPage']=NB_LSOBJECT_LIST; $this->params['nbObjectsByPage']=NB_LSOBJECT_LIST;
@ -1209,7 +1213,7 @@ class LSsearch {
**/ **/
private function doSort() { private function doSort() {
if (!$this -> sort) { if (!$this -> sort) {
LSdebug('doSort : sort is disabled'); $this -> logger -> debug('doSort : sort is disabled');
return true; return true;
} }
if (is_null($this -> params['sortBy'])) { if (is_null($this -> params['sortBy'])) {
@ -1224,11 +1228,11 @@ class LSsearch {
} }
if (isset($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']])) { if (isset($this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']])) {
LSdebug('doSort : from cache'); $this -> logger -> debug('doSort : from cache');
return true; return true;
} }
LSdebug('doSort : '.$this -> params['sortBy'].' - '.$this -> params['sortDirection']); $this -> logger -> debug('doSort : '.$this -> params['sortBy'].' - '.$this -> params['sortDirection']);
$this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]=range(0,($this -> total-1)); $this -> result['sort'][$this -> params['sortBy']][$this -> params['sortDirection']]=range(0,($this -> total-1));
@ -1357,6 +1361,7 @@ class LSsearch {
* @retval boolean True on succes, false otherwise * @retval boolean True on succes, false otherwise
**/ **/
public static function cli_search($command_args) { public static function cli_search($command_args) {
$logger = LSlog :: get_logger(get_called_class());
$objType = null; $objType = null;
$patterns = array(); $patterns = array();
$params = array( $params = array(
@ -1451,7 +1456,7 @@ class LSsearch {
// Load Console Table lib // Load Console Table lib
$console_table_path = LSconfig :: get('ConsoleTable', 'Console/Table.php', 'string'); $console_table_path = LSconfig :: get('ConsoleTable', 'Console/Table.php', 'string');
if (!LSsession :: includeFile($console_table_path, true)) if (!LSsession :: includeFile($console_table_path, true))
LSlog :: fatal('Fail to load ConsoleTable library.'); $logger -> fatal('Fail to load ConsoleTable library.');
if (!empty($patterns)) if (!empty($patterns))
$params['pattern'] = implode(' ', $patterns); $params['pattern'] = implode(' ', $patterns);
@ -1459,13 +1464,13 @@ class LSsearch {
$search = new LSsearch($objType, 'CLI', array(), true); $search = new LSsearch($objType, 'CLI', array(), true);
// Set search params // Set search params
LSlog :: debug('Search parameters : '.varDump($params)); $logger -> debug('Search parameters : '.varDump($params));
if (!$search -> setParams($params)) if (!$search -> setParams($params))
LSlog :: fatal('Fail to set search parameters.'); $logger -> fatal('Fail to set search parameters.');
// Run search // Run search
if (!$search -> run()) if (!$search -> run())
LSlog :: fatal('Fail to run search.'); $logger -> fatal('Fail to run search.');
// Retrieve page // Retrieve page
$page = $search -> getPage(($page_nb-1)); $page = $search -> getPage(($page_nb-1));
@ -1480,7 +1485,7 @@ class LSsearch {
// Check page // Check page
if (!is_array($page) || $page_nb > $page['nbPages']) if (!is_array($page) || $page_nb > $page['nbPages'])
LSlog :: fatal("Fail to retreive page #$page_nb."); $logger -> fatal("Fail to retreive page #$page_nb.");
if (empty($page['list'])) { if (empty($page['list'])) {
echo "No $objType object found.\n"; echo "No $objType object found.\n";
exit(0); exit(0);