b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _hitlist.class.php

Documentation is available at _hitlist.class.php

  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-2010 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.22 2010/02/08 17:53:55 efy-yury 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.         global $Plugins;
  124.  
  125.         // Prune when $localtime is a NEW day (which will be the 1st request after midnight):
  126.         $last_prune $Settings->get'auto_prune_stats_done' );
  127.         if$last_prune >= date('Y-m-d'$localtimenow&& $last_prune <= date('Y-m-d'$localtimenow+86400) )
  128.         // Already pruned today (and not more than one day in the future -- which typically never happens)
  129.             return T_('Pruning has already been done today');
  130.         }
  131.  
  132.         $time_prune_before ($localtimenow ($Settings->get('auto_prune_stats'86400))// 1 day = 86400 seconds
  133.  
  134.         $rows_affected $DB->query"
  135.             DELETE FROM T_hitlog
  136.             WHERE hit_datetime < '".date('Y-m-d'$time_prune_before)."'"'Autopruning hit log' );
  137.         $Debuglog->add'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_hitlog.''request' );
  138.  
  139.         // Prune sessions that have timed out and are older than auto_prune_stats
  140.         $sess_prune_before ($localtimenow $Settings->get'timeout_sessions' ));
  141.         $smaller_time min$sess_prune_before$time_prune_before );
  142.         // allow plugins to prune session based data
  143.         $Plugins->trigger_event'BeforeSessionsDelete'$temp_array array'cutoff_timestamp' => $smaller_time ) );
  144.  
  145.         $rows_affected $DB->query'DELETE FROM T_sessions WHERE sess_lastseen < '.$DB->quote(date('Y-m-d H:i:s'$smaller_time))'Autoprune sessions' );
  146.         $Debuglog->add'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_sessions.''request' );
  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.         // Note: MySQL server version >= 4 is required for multi-table deletes, but v 4.1 is now a requirement for b2evolution:
  152.         $rows_affected $DB->query"
  153.             DELETE T_basedomains
  154.               FROM T_basedomains LEFT JOIN T_hitlog ON hit_referer_dom_ID = dom_ID
  155.              WHERE hit_referer_dom_ID IS NULL
  156.              AND dom_type = 'unknown'
  157.              AND dom_status = 'unknown'" );
  158.         $Debuglog->add'Hitlist::dbprune(): autopruned '.$rows_affected.' rows from T_basedomains.''request' );
  159.  
  160.         // Optimizing tables
  161.         $DB->query('OPTIMIZE TABLE T_hitlog');
  162.         $DB->query('OPTIMIZE TABLE T_sessions');
  163.         $DB->query('OPTIMIZE TABLE T_basedomains');
  164.  
  165.         $Settings->set'auto_prune_stats_done'date('Y-m-d H:i:s'$localtimenow) )// save exact datetime
  166.         $Settings->dbupdate();
  167.  
  168.         return ''/* ok */
  169.     }
  170. }
  171.  
  172. /*
  173.  * $Log: _hitlist.class.php,v $
  174.  * Revision 1.22  2010/02/08 17:53:55  efy-yury
  175.  * copyright 2009 -> 2010
  176.  *
  177.  * Revision 1.21  2009/12/08 22:38:13  fplanque
  178.  * User agent type is now saved directly into the hits table instead of a costly lookup in user agents table
  179.  *
  180.  * Revision 1.20  2009/11/30 00:22:05  fplanque
  181.  * clean up debug info
  182.  * show more timers in view of block caching
  183.  *
  184.  * Revision 1.19  2009/11/15 19:05:43  fplanque
  185.  * no message
  186.  *
  187.  * Revision 1.18  2009/11/11 23:32:27  blueyed
  188.  * Hitlist::dbprune: also prune if last prune is more than 1 day in the future.
  189.  *
  190.  * Revision 1.17  2009/09/19 12:57:20  blueyed
  191.  * Hitlist: Optimize tables after pruning entries.
  192.  *
  193.  * Revision 1.16  2009/09/19 12:52:54  blueyed
  194.  * Remove obsolete entries from T_ user agents when pruning hitlog info.
  195.  *
  196.  * Revision 1.15  2009/09/14 18:37:07  fplanque
  197.  * doc/cleanup/minor
  198.  *
  199.  * Revision 1.14  2009/09/13 21:26:50  blueyed
  200.  * SQL_NO_CACHE for SELECT queries using T_hitlog
  201.  *
  202.  * Revision 1.13  2009/07/06 22:55:11  fplanque
  203.  * minor
  204.  *
  205.  * Revision 1.12  2009/07/06 12:44:59  yabs
  206.  * Modifying BeforeSessionsDelete behaviour
  207.  *
  208.  * Revision 1.11  2009/07/05 00:50:29  fplanque
  209.  * no message
  210.  *
  211.  * Revision 1.10  2009/07/04 08:01:49  yabs
  212.  * doc
  213.  *
  214.  * Revision 1.9  2009/07/04 01:52:51  fplanque
  215.  * doc
  216.  *
  217.  * Revision 1.8  2009/07/02 22:01:15  blueyed
  218.  * Fix BeforeSessionsDelete: add it to base plugin class, test plugin and implement FPs requirements.
  219.  *
  220.  * Revision 1.7  2009/07/02 00:01:50  fplanque
  221.  * needs optimization.
  222.  */
  223. ?>

Documentation generated on Sat, 06 Mar 2010 04:12:57 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).