Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Log - DOC block update #767

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/code/core/Mage/Log/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Mage_Log_Helper_Data extends Mage_Core_Helper_Abstract
const XML_PATH_LOG_ENABLED = 'system/log/enable_log';

/**
* @var Mage_Log_Helper_Data
* @var int
*/
protected $_logLevel;

Expand All @@ -41,6 +41,10 @@ class Mage_Log_Helper_Data extends Mage_Core_Helper_Abstract
*/
private $_allowedFileExtensions = array('log', 'txt', 'html', 'csv');

/**
* Mage_Log_Helper_Data constructor.
* @param array $data
*/
public function __construct(array $data = array())
{
$this->_logLevel = isset($data['log_level']) ? $data['log_level']
Expand Down Expand Up @@ -81,7 +85,7 @@ public function isLogDisabled()
/**
* Checking if file extensions is allowed. If passed then return true.
*
* @param $file
* @param string $file
* @return bool
*/
public function isLogFileExtensionValid($file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ class Mage_Log_Model_Adminhtml_System_Config_Source_Loglevel
*/
protected $_helper;

/**
* Mage_Log_Model_Adminhtml_System_Config_Source_Loglevel constructor.
* @param array $data
*/
public function __construct(array $data = array())
{
$this->_helper = !empty($data['helper']) ? $data['helper'] : Mage::helper('log');
}

/**
* @return array
*/
public function toOptionArray()
{
$options = array(
Expand Down
42 changes: 35 additions & 7 deletions app/code/core/Mage/Log/Model/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
*/
class Mage_Log_Model_Aggregation extends Mage_Core_Model_Abstract
{

/**
* Last record data
*
Expand Down Expand Up @@ -67,7 +66,7 @@ public function run()
* Remove empty records before $lastDate
*
* @param string $lastDate
* @return void
* @return Mage_Log_Model_Resource_Aggregation
*/
private function _removeEmpty($lastDate)
{
Expand Down Expand Up @@ -102,7 +101,7 @@ private function _process($store)
}

$lastDateRecord = $date;
$date = $to;
$date = $to;
}
return $lastDateRecord;
}
Expand All @@ -123,48 +122,77 @@ private function _save($data, $from, $to)
}
}

/**
* @param int $id
* @param array $data
*/
private function _update($id, $data)
{
return $this->_getResource()->saveLog($data, $id);
}

/**
* @param array $data
*/
private function _insert($data)
{
return $this->_getResource()->saveLog($data);
}

/**
* @param string $from
* @param string $to
* @param int $store
* @return array
*/
private function _getCounts($from, $to, $store)
{
return $this->_getResource()->getCounts($from, $to, $store);
}

/**
* @return false|string
*/
public function getLastRecordDate()
{
$result = $this->_getResource()->getLastRecordDate();
if (!$result)
if (!$result) {
$result = $this->_date(strtotime('now - 2 months'));
}

return $result;
}

/**
* @param string|int $in
* @param null $offset
* @return false|string
*/
private function _date($in, $offset = null)
{
$out = $in;
if (is_numeric($in))
if (is_numeric($in)) {
$out = date("Y-m-d H:i:s", $in);
}
return $out;
}

/**
* @param string|int $in
* @param null $offset
* @return false|int
*/
private function _timestamp($in, $offset = null)
{
$out = $in;
if (!is_numeric($in))
if (!is_numeric($in)) {
$out = strtotime($in);
}
return $out;
}

/**
* @param $in
* @param string|int $in
* @return string
*/
private function _round($in)
Expand Down
7 changes: 3 additions & 4 deletions app/code/core/Mage/Log/Model/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ protected function _sendLogCleanEmail()
}

$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
/* @var Mage_Core_Model_Translate $translate */
$translate->setTranslateInline(false);

$emailTemplate = Mage::getModel('core/email_template');
/* @var $emailTemplate Mage_Core_Model_Email_Template */
/* @var Mage_Core_Model_Email_Template $emailTemplate */
$emailTemplate->setDesignConfig(array('area' => 'backend'))
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_LOG_CLEAN_TEMPLATE),
Expand Down Expand Up @@ -95,8 +95,7 @@ public function logClean()

try {
Mage::getModel('log/log')->clean();
}
catch (Exception $e) {
} catch (Exception $e) {
$this->_errors[] = $e->getMessage();
$this->_errors[] = $e->getTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function _construct()
/**
* Load last log by customer id
*
* @param Mage_Customer_Model_Customer|int $customer
* @param Mage_Log_Model_Customer|int $customer
* @return $this
*/
public function loadByCustomer($customer)
Expand Down
3 changes: 3 additions & 0 deletions app/code/core/Mage/Log/Model/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ protected function _construct()
$this->_init('log/log');
}

/**
* @return float|int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why float? the config description is "Save Expired Items Days" and default value is "180"

Copy link
Contributor Author

@sreichel sreichel Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mage::getStoreConfig(self::XML_LOG_CLEAN_DAYS) returns a string ... multiplied its float.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, so we need a casting to int here.
I propose we either skip this docbloc change, and open a new PR fixing the docblock and adding cast.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created an issue for this change #949

*/
public function getLogCleanTime()
{
return Mage::getStoreConfig(self::XML_LOG_CLEAN_DAYS) * 60 * 60 * 24;
Expand Down
10 changes: 6 additions & 4 deletions app/code/core/Mage/Log/Model/Resource/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


/**
* Log aggregation resource model
* Log aggregation resource model
*
* @category Mage
* @package Mage_Log
Expand All @@ -52,8 +52,10 @@ public function getLastRecordDate()
{
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('log/summary_table'),
array($adapter->quoteIdentifier('date')=>'MAX(add_date)'));
->from(
$this->getTable('log/summary_table'),
array($adapter->quoteIdentifier('date')=>'MAX(add_date)')
);

return $adapter->fetchOne($select);
}
Expand Down Expand Up @@ -129,7 +131,7 @@ public function removeEmpty($date)
'add_date < ?' => $date,
'customer_count = 0',
'visitor_count = 0'
);
);
$adapter->delete($this->getTable('log/summary_table'), $condition);
}

Expand Down
11 changes: 7 additions & 4 deletions app/code/core/Mage/Log/Model/Resource/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function _construct()

/**
* Retrieve select object for load object data
*
*
* @param string $field
* @param mixed $value
* @param Mage_Log_Model_Customer $object
Expand All @@ -110,15 +110,18 @@ protected function _getLoadSelect($field, $value, $object)
->joinInner(
array('lvt' => $this->_visitorTable),
"lvt.visitor_id = {$table}.visitor_id",
array('last_visit_at'))
array('last_visit_at')
)
->joinInner(
array('lvit' => $this->_visitorInfoTable),
'lvt.visitor_id = lvit.visitor_id',
array('http_referer', 'remote_addr'))
array('http_referer', 'remote_addr')
)
->joinInner(
array('luit' => $this->_urlInfoTable),
'luit.url_id = lvt.last_url_id',
array('url'))
array('url')
)
->order("{$table}.login_at DESC")
->limit(1);
}
Expand Down
21 changes: 14 additions & 7 deletions app/code/core/Mage/Log/Model/Resource/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ protected function _cleanVisitors($time)
$select = $readAdapter->select()
->from(
array('visitor_table' => $this->getTable('log/visitor')),
array('visitor_id' => 'visitor_table.visitor_id'))
array('visitor_id' => 'visitor_table.visitor_id')
)
->joinLeft(
array('customer_table' => $this->getTable('log/customer')),
'visitor_table.visitor_id = customer_table.visitor_id AND customer_table.log_id IS NULL',
array())
array()
)
->where('visitor_table.last_visit_at < ?', $timeLimit)
->limit(100);

Expand Down Expand Up @@ -147,12 +149,14 @@ protected function _cleanCustomers($time)
$select = $readAdapter->select()
->from(
array('log_customer_main' => $this->getTable('log/customer')),
array('log_id'))
array('log_id')
)
->joinLeft(
array('log_customer' => $this->getTable('log/customer')),
'log_customer_main.customer_id = log_customer.customer_id '
. 'AND log_customer_main.log_id < log_customer.log_id',
array())
array()
)
->where('log_customer.customer_id IS NULL')
->where('log_customer_main.log_id < ?', $lastLogId + 1);

Expand All @@ -168,7 +172,8 @@ protected function _cleanCustomers($time)
$select = $readAdapter->select()
->from(
$this->getTable('log/customer'),
array('log_id', 'visitor_id'))
array('log_id', 'visitor_id')
)
->where('log_id > ?', $customerLogId)
->where('log_id < ?', $lastLogId + 1)
->order('log_id')
Expand Down Expand Up @@ -229,11 +234,13 @@ protected function _cleanUrls()
$select = $readAdapter->select()
->from(
array('url_info_table' => $this->getTable('log/url_info_table')),
array('url_id'))
array('url_id')
)
->joinLeft(
array('url_table' => $this->getTable('log/url_table')),
'url_info_table.url_id = url_table.url_id',
array())
array()
)
->where('url_table.url_id IS NULL')
->limit(100);

Expand Down
Loading