Public Member Functions | |
clean (Mage_Log_Model_Log $object) | |
Protected Member Functions | |
_construct () | |
_cleanVisitors ($time) | |
_cleanCustomers ($time) | |
_cleanUrls () |
Definition at line 35 of file Log.php.
_cleanCustomers | ( | $ | time | ) | [protected] |
Clean customer table
int | $time |
Definition at line 135 of file Log.php.
00136 { 00137 // retrieve last active customer log id 00138 $row = $this->_getReadAdapter()->fetchRow( 00139 $this->_getReadAdapter()->select() 00140 ->from($this->getTable('log/customer'), 'log_id') 00141 ->where('login_at < ?', gmdate('Y-m-d H:i:s', time() - $time)) 00142 ->order('log_id DESC') 00143 ->limit(1) 00144 ); 00145 00146 if (!$row) { 00147 return $this; 00148 } 00149 00150 $lastLogId = $row['log_id']; 00151 00152 // Order by desc log_id before grouping (within-group aggregates query pattern) 00153 $select = $this->_getReadAdapter()->select() 00154 ->from( 00155 array('log_customer_main' => $this->getTable('log/customer')), 00156 array('log_id')) 00157 ->joinLeft( 00158 array('log_customer' => $this->getTable('log/customer')), 00159 'log_customer_main.customer_id = log_customer.customer_id AND log_customer_main.log_id < log_customer.log_id', 00160 array()) 00161 ->where('log_customer.customer_id IS NULL') 00162 ->where('log_customer_main.log_id<?', $lastLogId + 1); 00163 00164 $needLogIds = array(); 00165 $query = $this->_getReadAdapter()->query($select); 00166 while ($row = $query->fetch()) { 00167 $needLogIds[$row['log_id']] = 1; 00168 } 00169 00170 $customerLogId = 0; 00171 while (true) { 00172 $visitorIds = array(); 00173 $select = $this->_getReadAdapter()->select() 00174 ->from( 00175 $this->getTable('log/customer'), 00176 array('log_id', 'visitor_id')) 00177 ->where('log_id>?', $customerLogId) 00178 ->where('log_id<?', $lastLogId + 1) 00179 ->order('log_id') 00180 ->limit(100); 00181 00182 $query = $this->_getReadAdapter()->query($select); 00183 $count = 0; 00184 while ($row = $query->fetch()) { 00185 $count++; 00186 $customerLogId = $row['log_id']; 00187 if (!isset($needLogIds[$row['log_id']])) { 00188 $visitorIds[] = $row['visitor_id']; 00189 } 00190 } 00191 00192 if (!$count) { 00193 break; 00194 } 00195 00196 if ($visitorIds) { 00197 // remove visitors from log/quote 00198 $this->_getWriteAdapter()->delete( 00199 $this->getTable('log/quote_table'), 00200 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00201 ); 00202 00203 // remove visitors from log/url 00204 $this->_getWriteAdapter()->delete( 00205 $this->getTable('log/url_table'), 00206 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00207 ); 00208 00209 // remove visitors from log/visitor_info 00210 $this->_getWriteAdapter()->delete( 00211 $this->getTable('log/visitor_info'), 00212 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00213 ); 00214 00215 // remove visitors from log/visitor 00216 $this->_getWriteAdapter()->delete( 00217 $this->getTable('log/visitor'), 00218 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00219 ); 00220 00221 // remove customers from log/customer 00222 $this->_getWriteAdapter()->delete( 00223 $this->getTable('log/customer'), 00224 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00225 ); 00226 } 00227 00228 if ($customerLogId == $lastLogId) { 00229 break; 00230 } 00231 } 00232 00233 return $this; 00234 }
_cleanUrls | ( | ) | [protected] |
Clean url table
Definition at line 241 of file Log.php.
00242 { 00243 while (true) { 00244 $urlIds = array(); 00245 $select = $this->_getReadAdapter()->select() 00246 ->from( 00247 array('url_info_table' => $this->getTable('log/url_info_table')), 00248 array('url_id')) 00249 ->joinLeft( 00250 array('url_table' => $this->getTable('log/url_table')), 00251 'url_info_table.url_id = url_table.url_id', 00252 array()) 00253 ->where('url_table.url_id IS NULL') 00254 ->limit(100); 00255 $query = $this->_getReadAdapter()->query($select); 00256 while ($row = $query->fetch()) { 00257 $urlIds[] = $row['url_id']; 00258 } 00259 00260 if (!$urlIds) { 00261 break; 00262 } 00263 00264 $this->_getWriteAdapter()->delete( 00265 $this->getTable('log/url_info_table'), 00266 $this->_getWriteAdapter()->quoteInto('url_id IN(?)', $urlIds) 00267 ); 00268 } 00269 }
_cleanVisitors | ( | $ | time | ) | [protected] |
Clean visitors table
int | $time |
Definition at line 77 of file Log.php.
00078 { 00079 while (true) { 00080 $select = $this->_getReadAdapter()->select() 00081 ->from( 00082 array('visitor_table' => $this->getTable('log/visitor')), 00083 array('visitor_id' => 'visitor_table.visitor_id')) 00084 ->joinLeft( 00085 array('customer_table' => $this->getTable('log/customer')), 00086 'visitor_table.visitor_id = customer_table.visitor_id AND customer_table.log_id IS NULL', 00087 array()) 00088 ->where('visitor_table.last_visit_at < ?', gmdate('Y-m-d H:i:s', time() - $time)) 00089 ->limit(100); 00090 00091 $query = $this->_getReadAdapter()->query($select); 00092 $visitorIds = array(); 00093 while ($row = $query->fetch()) { 00094 $visitorIds[] = $row['visitor_id']; 00095 } 00096 00097 if (!$visitorIds) { 00098 break; 00099 } 00100 00101 // remove visitors from log/quote 00102 $this->_getWriteAdapter()->delete( 00103 $this->getTable('log/quote_table'), 00104 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00105 ); 00106 00107 // remove visitors from log/url 00108 $this->_getWriteAdapter()->delete( 00109 $this->getTable('log/url_table'), 00110 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00111 ); 00112 00113 // remove visitors from log/visitor_info 00114 $this->_getWriteAdapter()->delete( 00115 $this->getTable('log/visitor_info'), 00116 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00117 ); 00118 00119 // remove visitors from log/visitor 00120 $this->_getWriteAdapter()->delete( 00121 $this->getTable('log/visitor'), 00122 $this->_getWriteAdapter()->quoteInto('visitor_id IN(?)', $visitorIds) 00123 ); 00124 } 00125 00126 return $this; 00127 }
_construct | ( | ) | [protected] |
Init Resource model and connection
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 41 of file Log.php.
00042 { 00043 $this->_init('log/visitor', 'visitor_id'); 00044 }
clean | ( | Mage_Log_Model_Log $ | object | ) |
Clean logs
Mage_Log_Model_Log | $object |
Definition at line 52 of file Log.php.
00053 { 00054 $cleanTime = $object->getLogCleanTime(); 00055 00056 Mage::dispatchEvent('log_log_clean_before', array( 00057 'log' => $object 00058 )); 00059 00060 $this->_cleanVisitors($cleanTime); 00061 $this->_cleanCustomers($cleanTime); 00062 $this->_cleanUrls(); 00063 00064 Mage::dispatchEvent('log_log_clean_after', array( 00065 'log' => $object 00066 )); 00067 00068 return $this; 00069 }