[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/sessions/model/ -> _hitlist.class.php (source)

   1  <?php
   2  /**

   3   * This file implements the Hitlist class.

   4   *

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * {@internal License choice

  12   * - If you have received this file as part of a package, please find the license.txt file in

  13   *   the same folder or the closest folder above for complete license terms.

  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  15   *   then you must choose one of the following licenses before using the file:

  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  18   * }}

  19   *

  20   * {@internal Open Source relicensing agreement:

  21   * Daniel HAHLER grants Francois PLANQUE the right to license

  22   * Daniel HAHLER's contributions to this file and the b2evolution project

  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  24   * }}

  25   *

  26   * @package evocore

  27   *

  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  29   * @author blueyed: Daniel HAHLER.

  30   * @author fplanque: Francois PLANQUE.

  31   *

  32   * @version $Id: _hitlist.class.php,v 1.1 2007/06/25 11:00:58 fplanque Exp $

  33   *

  34   */
  35  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  36  
  37  
  38  /**

  39   * A list of hits. Provides functions for maintaining and extraction of Hits.

  40   *

  41   * @package evocore

  42   */
  43  class Hitlist
  44  {
  45  
  46  
  47      /**

  48       * Delete a hit.

  49       *

  50       * @static

  51       * @param int ID to delete

  52       * @return mixed Return value of {@link DB::query()}

  53       */
  54  	function delete( $hit_ID )
  55      {
  56          global $DB;
  57  
  58          return $DB->query( "DELETE FROM T_hitlog WHERE hit_ID = $hit_ID", 'Delete a hit' );
  59      }
  60  
  61  
  62      /**

  63       * Delete all hits for a specific date

  64       *

  65       * @static

  66       * @param int unix timestamp to delete hits for

  67       * @return mixed Return value of {@link DB::query()}

  68       */
  69  	function prune( $date )
  70      {
  71          global $DB;
  72  
  73          $iso_date = date ('Y-m-d', $date);
  74          $sql = "
  75              DELETE FROM T_hitlog
  76               WHERE DATE_FORMAT(hit_datetime,'%Y-%m-%d') = '$iso_date'";
  77  
  78          return $DB->query( $sql, 'Prune hits for a specific date' );
  79      }
  80  
  81  
  82      /**

  83       * Change type for a hit

  84       *

  85       * @static

  86       * @param int ID to change

  87       * @param string new type, must be valid ENUM for hit_referer_type field

  88       * @return mixed Return value of {@link DB::query()}

  89       */
  90  	function change_type( $hit_ID, $type )
  91      {
  92          global $DB;
  93  
  94          $sql = '
  95                  UPDATE T_hitlog
  96                     SET hit_referer_type = '.$DB->quote($type).",
  97                         hit_datetime = hit_datetime " /* prevent mySQL from updating timestamp */ ."
  98                   WHERE hit_ID = $hit_ID";
  99          return $DB->query( $sql, 'Change type for a specific hit' );
 100      }
 101  
 102  
 103      /**

 104       * Auto pruning of old stats.

 105       *

 106       * It uses a general setting to store the day of the last prune, avoiding multiple prunes per day.

 107       * fplanque>> Check: How much faster is this than DELETING right away with an INDEX on the date field?

 108       *

 109       * Note: we're using {@link $localtimenow} to log hits, so use this for pruning, too.

 110       *

 111       * NOTE: do not call this directly, but only in conjuction with auto_prune_stats_mode.

 112       *

 113       * @static

 114       * @return string Empty, if ok.

 115       */
 116  	function dbprune()
 117      {
 118          /**

 119           * @var DB

 120           */
 121          global $DB;
 122          global $Debuglog, $Settings, $localtimenow;
 123  
 124          // Prune when $localtime is a NEW day (which will be the 1st request after midnight):

 125          $last_prune = $Settings->get( 'auto_prune_stats_done' );
 126          if( $last_prune >= date('Y-m-d', $localtimenow) )
 127          { // Already pruned today
 128              return T_('Pruning has already been done today');
 129          }
 130  
 131          $time_prune_before = ($localtimenow - ($Settings->get('auto_prune_stats') * 86400)); // 1 day = 86400 seconds

 132  
 133          $rows_affected = $DB->query( "
 134              DELETE FROM T_hitlog
 135              WHERE hit_datetime < '".date('Y-m-d', $time_prune_before)."'", 'Autopruning hit log' );
 136          $Debuglog->add( 'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_hitlog.', 'hit' );
 137  
 138          // Prune sessions that have timed out and are older than auto_prune_stats

 139          $sess_prune_before = ($localtimenow - $Settings->get( 'timeout_sessions' ));
 140          $smaller_time = min( $sess_prune_before, $time_prune_before );
 141          $sess_prune_YMD = date( 'Y-m-d H:i:s', $smaller_time );
 142  
 143          $rows_affected = $DB->query( "
 144              DELETE FROM T_sessions
 145              WHERE sess_lastseen < '".$sess_prune_YMD."'", 'Autoprune sessions' );
 146          $Debuglog->add( 'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_sessions.', 'hit' );
 147  
 148          // Prune non-referrered basedomains (where the according hits got deleted)

 149          // BUT only those with unknown dom_type/dom_status, because otherwise this

 150          //     info is useful when we get hit again.

 151          $mysql_ver = mysql_get_server_info();
 152          if( ($pos = strpos($mysql_ver, '.')) && substr( $mysql_ver, 0, $pos ) >= '4' )
 153          { // MySQL server version >= 4 (required for multi-table deletes):
 154              $rows_affected = $DB->query( "
 155                  DELETE T_basedomains
 156                    FROM T_basedomains LEFT JOIN T_hitlog ON hit_referer_dom_ID = dom_ID
 157                   WHERE hit_referer_dom_ID IS NULL
 158                   AND dom_type = 'unknown'
 159                   AND dom_status = 'unknown'" );
 160              $Debuglog->add( 'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_basedomains.', 'hit' );
 161          }
 162          else
 163          { // two queries for MySQL < 4
 164              $ids = $DB->get_row( "
 165                  SELECT dom_ID
 166                    FROM T_basedomains LEFT JOIN T_hitlog ON hit_referer_dom_ID = dom_ID
 167                   WHERE hit_referer_dom_ID IS NULL
 168                   AND dom_type = 'unknown'
 169                   AND dom_status = 'unknown'", ARRAY_N );
 170  
 171              if( !empty( $ids ) )
 172              {
 173                  $rows_affected = $DB->query( '
 174                      DELETE FROM T_basedomains
 175                       WHERE dom_ID IN ( '.implode( ', ', $ids ).' )' );
 176              }
 177  
 178              $Debuglog->add( 'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_basedomains (MySQL<4).', 'hit' );
 179          }
 180  
 181          $Settings->set( 'auto_prune_stats_done', date('Y-m-d H:i:s', $localtimenow) ); // save exact datetime

 182          $Settings->dbupdate();
 183  
 184          return ''; /* ok */
 185      }
 186  }
 187  
 188  /*

 189   * $Log: _hitlist.class.php,v $

 190   * Revision 1.1  2007/06/25 11:00:58  fplanque

 191   * MODULES (refactored MVC)

 192   *

 193   */
 194  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics