<commit_before><?php
/**
* Log lizmap actions.
* @package   lizmap
* @subpackage view
* @author    3liz
* @copyright 2012 3liz
* @link      http://3liz.com
* @license    Mozilla Public License : http://www.mozilla.org/MPL/
*/

class lizmapLogListener extends jEventListener{

  /**
  * When a user logs in
  * @param string $login The login
  * @param object $user jAuth user
  *
  */
  function onAuthCanLogin($event){
  
    $key = 'login';
    $data = array(
      'key'=>$key,
      'user' => $event->getParam('login'),
      'repository'=> Null,
      'project'=> Null
    );
    
    $this->addLog($key, $data);
    
  }

  /**
  * Event emitted by lizmap controllers
  * @param string $key Key of the log item
  * @param string $content Content to log (optionnal)
  * @param string $repository Lizmap repository key (optionnal)
  * @param string $project Lizmap project key (optionnal)
  *
  */
  function onLizLogItem($event){
  
    $key = $event->getParam('key');
    
    // Build data array from event params
    $logItem = lizmap::getLogItem($key);
    $data = array();
    foreach($logItem->getRecordKeys() as $rk){
      if($event->getParam($rk))
        $data[$rk] = $event->getParam($rk);
    }
    
    $this->addLog($key, $data);

  }
  
  /**
  * Add log when needed
  * @param string $key Key of the log item to handle.
  * @param array $data Array of data to log for this item.
  *
  */
  function addLog($key, $data){
    
    // Get log item properties  
    $logItem = lizmap::getLogItem($key);
       
    // Optionnaly log detail
    if( $logItem->getData('logDetail') ){
    
      // user who modified the line
      if(!array_key_exists('user', $data)){     
        $juser = jAuth::getUserSession();
        $data['user'] = $juser->login; 
      }
            
      // Add IP if needed
      if( $logItem->getData('logIp') )
        $data['ip'] = $_SERVER['REMOTE_ADDR'];<commit_msg>[BUGFIX] Error if logItem does not exists<commit_after><?php
/**
* Log lizmap actions.
* @package   lizmap
* @subpackage view
* @author    3liz
* @copyright 2012 3liz
* @link      http://3liz.com
* @license    Mozilla Public License : http://www.mozilla.org/MPL/
*/

class lizmapLogListener extends jEventListener{

  /**
  * When a user logs in
  * @param string $login The login
  * @param object $user jAuth user
  *
  */
  function onAuthCanLogin($event){
  
    $key = 'login';
    $data = array(
      'key'=>$key,
      'user' => $event->getParam('login'),
      'repository'=> Null,
      'project'=> Null
    );
    
    $this->addLog($key, $data);
    
  }

  /**
  * Event emitted by lizmap controllers
  * @param string $key Key of the log item
  * @param string $content Content to log (optionnal)
  * @param string $repository Lizmap repository key (optionnal)
  * @param string $project Lizmap project key (optionnal)
  *
  */
  function onLizLogItem($event){
  
    $key = $event->getParam('key');
    
    // Build data array from event params
    $logItem = lizmap::getLogItem($key);
    $data = array();
    if ( $logItem ) {
      foreach($logItem->getRecordKeys() as $rk){
        if($event->getParam($rk))
          $data[$rk] = $event->getParam($rk);
      }
    
      $this->addLog($key, $data);
    }

  }
  
  /**
  * Add log when needed
  * @param string $key Key of the log item to handle.
  * @param array $data Array of data to log for this item.
  *
  */
  function addLog($key, $data){
    
    // Get log item properties  
    $logItem = lizmap::getLogItem($key);
       
    // Optionnaly log detail
    if( $logItem->getData('logDetail') ){
    
      // user who modified the line
      if(!array_key_exists('user', $data)){     
        $juser = jAuth::getUserSession();
        $data['user'] = $juser->login; 
      }
            
      // Add IP if needed
      if( $logItem->getData('logIp') )
        $data['ip'] = $_SERVER['REMOTE_ADDR'];
{'fraction_non_alphanumeric': 0.15118069815195073, 'fraction_numerical': 0.003593429158110883, 'mean_word_length': 2.464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4224793', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1286, 'n_words': 343}