Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Log_Helper_Data
  • Mage_Log_Model_Aggregation
  • Mage_Log_Model_Cron
  • Mage_Log_Model_Customer
  • Mage_Log_Model_Log
  • Mage_Log_Model_Mysql4_Aggregation
  • Mage_Log_Model_Mysql4_Customer
  • Mage_Log_Model_Mysql4_Log
  • Mage_Log_Model_Mysql4_Visitor
  • Mage_Log_Model_Mysql4_Visitor_Collection
  • Mage_Log_Model_Mysql4_Visitor_Online
  • Mage_Log_Model_Mysql4_Visitor_Online_Collection
  • Mage_Log_Model_Resource_Aggregation
  • Mage_Log_Model_Resource_Customer
  • Mage_Log_Model_Resource_Log
  • Mage_Log_Model_Resource_Visitor
  • Mage_Log_Model_Resource_Visitor_Collection
  • Mage_Log_Model_Resource_Visitor_Online
  • Mage_Log_Model_Resource_Visitor_Online_Collection
  • Mage_Log_Model_Visitor
  • Mage_Log_Model_Visitor_Online
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Log
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Log Resource Model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Log
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Log_Model_Resource_Log extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Init Resource model and connection
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('log/visitor', 'visitor_id');
 44:     }
 45: 
 46:     /**
 47:      * Clean logs
 48:      *
 49:      * @param Mage_Log_Model_Log $object
 50:      * @return Mage_Log_Model_Resource_Log
 51:      */
 52:     public function clean(Mage_Log_Model_Log $object)
 53:     {
 54:         $cleanTime = $object->getLogCleanTime();
 55: 
 56:         Mage::dispatchEvent('log_log_clean_before', array(
 57:             'log'   => $object
 58:         ));
 59: 
 60:         $this->_cleanVisitors($cleanTime);
 61:         $this->_cleanCustomers($cleanTime);
 62:         $this->_cleanUrls();
 63: 
 64:         Mage::dispatchEvent('log_log_clean_after', array(
 65:             'log'   => $object
 66:         ));
 67: 
 68:         return $this;
 69:     }
 70: 
 71:     /**
 72:      * Clean visitors table
 73:      *
 74:      * @param int $time
 75:      * @return Mage_Log_Model_Resource_Log
 76:      */
 77:     protected function _cleanVisitors($time)
 78:     {
 79:         $readAdapter    = $this->_getReadAdapter();
 80:         $writeAdapter   = $this->_getWriteAdapter();
 81: 
 82:         $timeLimit = $this->formatDate(Mage::getModel('core/date')->gmtTimestamp() - $time);
 83: 
 84:         while (true) {
 85:             $select = $readAdapter->select()
 86:                 ->from(
 87:                     array('visitor_table' => $this->getTable('log/visitor')),
 88:                     array('visitor_id' => 'visitor_table.visitor_id'))
 89:                 ->joinLeft(
 90:                     array('customer_table' => $this->getTable('log/customer')),
 91:                     'visitor_table.visitor_id = customer_table.visitor_id AND customer_table.log_id IS NULL',
 92:                     array())
 93:                 ->where('visitor_table.last_visit_at < ?', $timeLimit)
 94:                 ->limit(100);
 95: 
 96:             $visitorIds = $readAdapter->fetchCol($select);
 97: 
 98:             if (!$visitorIds) {
 99:                 break;
100:             }
101: 
102:             $condition = array('visitor_id IN (?)' => $visitorIds);
103:             
104:             // remove visitors from log/quote
105:             $writeAdapter->delete($this->getTable('log/quote_table'), $condition);
106: 
107:             // remove visitors from log/url
108:             $writeAdapter->delete($this->getTable('log/url_table'), $condition);
109: 
110:             // remove visitors from log/visitor_info
111:             $writeAdapter->delete($this->getTable('log/visitor_info'), $condition);
112: 
113:             // remove visitors from log/visitor
114:             $writeAdapter->delete($this->getTable('log/visitor'), $condition);
115:         }
116: 
117:         return $this;
118:     }
119: 
120:     /**
121:      * Clean customer table
122:      *
123:      * @param int $time
124:      * @return Mage_Log_Model_Resource_Log
125:      */
126:     protected function _cleanCustomers($time)
127:     {
128:         $readAdapter    = $this->_getReadAdapter();
129:         $writeAdapter   = $this->_getWriteAdapter();
130: 
131:         $timeLimit = $this->formatDate(Mage::getModel('core/date')->gmtTimestamp() - $time);
132: 
133:         // retrieve last active customer log id
134:         $lastLogId = $readAdapter->fetchOne(
135:             $readAdapter->select()
136:                 ->from($this->getTable('log/customer'), 'log_id')
137:                 ->where('login_at < ?', $timeLimit)
138:                 ->order('log_id DESC')
139:                 ->limit(1)
140:         );
141: 
142:         if (!$lastLogId) {
143:             return $this;
144:         }
145: 
146:         // Order by desc log_id before grouping (within-group aggregates query pattern)
147:         $select = $readAdapter->select()
148:             ->from(
149:                 array('log_customer_main' => $this->getTable('log/customer')),
150:                 array('log_id'))
151:             ->joinLeft(
152:                 array('log_customer' => $this->getTable('log/customer')),
153:                 'log_customer_main.customer_id = log_customer.customer_id '
154:                     . 'AND log_customer_main.log_id < log_customer.log_id',
155:                 array())
156:             ->where('log_customer.customer_id IS NULL')
157:             ->where('log_customer_main.log_id < ?', $lastLogId + 1);
158: 
159:         $needLogIds = array();
160:         $query = $readAdapter->query($select);
161:         while ($row = $query->fetch()) {
162:             $needLogIds[$row['log_id']] = 1;
163:         }
164: 
165:         $customerLogId = 0;
166:         while (true) {
167:             $visitorIds = array();
168:             $select = $readAdapter->select()
169:                 ->from(
170:                     $this->getTable('log/customer'),
171:                     array('log_id', 'visitor_id'))
172:                 ->where('log_id > ?', $customerLogId)
173:                 ->where('log_id < ?', $lastLogId + 1)
174:                 ->order('log_id')
175:                 ->limit(100);
176: 
177:             $query = $readAdapter->query($select);
178:             $count = 0;
179:             while ($row = $query->fetch()) {
180:                 $count++;
181:                 $customerLogId = $row['log_id'];
182:                 if (!isset($needLogIds[$row['log_id']])) {
183:                     $visitorIds[] = $row['visitor_id'];
184:                 }
185:             }
186: 
187:             if (!$count) {
188:                 break;
189:             }
190: 
191:             if ($visitorIds) {
192:                 $condition = array('visitor_id IN (?)' => $visitorIds);
193: 
194:                 // remove visitors from log/quote
195:                 $writeAdapter->delete($this->getTable('log/quote_table'), $condition);
196: 
197:                 // remove visitors from log/url
198:                 $writeAdapter->delete($this->getTable('log/url_table'), $condition);
199: 
200:                 // remove visitors from log/visitor_info
201:                 $writeAdapter->delete($this->getTable('log/visitor_info'), $condition);
202: 
203:                 // remove visitors from log/visitor
204:                 $writeAdapter->delete($this->getTable('log/visitor'), $condition);
205: 
206:                 // remove customers from log/customer
207:                 $writeAdapter->delete($this->getTable('log/customer'), $condition);
208:             }
209: 
210:             if ($customerLogId == $lastLogId) {
211:                 break;
212:             }
213:         }
214: 
215:         return $this;
216:     }
217: 
218:     /**
219:      * Clean url table
220:      *
221:      * @return Mage_Log_Model_Resource_Log
222:      */
223:     protected function _cleanUrls()
224:     {
225:         $readAdapter    = $this->_getReadAdapter();
226:         $writeAdapter   = $this->_getWriteAdapter();
227: 
228:         while (true) {
229:             $select = $readAdapter->select()
230:                 ->from(
231:                     array('url_info_table' => $this->getTable('log/url_info_table')),
232:                     array('url_id'))
233:                 ->joinLeft(
234:                     array('url_table' => $this->getTable('log/url_table')),
235:                     'url_info_table.url_id = url_table.url_id',
236:                     array())
237:                 ->where('url_table.url_id IS NULL')
238:                 ->limit(100);
239: 
240:             $urlIds = $readAdapter->fetchCol($select);
241: 
242:             if (!$urlIds) {
243:                 break;
244:             }
245: 
246:             $writeAdapter->delete(
247:                 $this->getTable('log/url_info_table'),
248:                 array('url_id IN (?)' => $urlIds)
249:             );
250:         }
251: 
252:         return $this;
253:     }
254: }
255: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0