diff --git a/app/Mage.php b/app/Mage.php index 482bd1172d..46ef862f92 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -82,7 +82,7 @@ final class Mage { public static function getVersion() { - return '1.3.1'; + return '1.3.1.1'; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php index ef1e11edaf..e24e8c4185 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Online/Grid.php @@ -33,7 +33,10 @@ */ class Mage_Adminhtml_Block_Customer_Online_Grid extends Mage_Adminhtml_Block_Widget_Grid { - + /** + * Initialize Grid block + * + */ public function __construct() { parent::__construct(); @@ -50,18 +53,15 @@ public function __construct() */ protected function _prepareCollection() { - $collection = Mage::getResourceSingleton('log/visitor_collection') - ->useOnlineFilter(); + $collection = Mage::getModel('log/visitor_online') + ->prepare() + ->getCollection(); + /* @var $collection Mage_Log_Model_Mysql4_Visitor_Online_Collection */ + $collection->addCustomerData(); $this->setCollection($collection); - parent::_prepareCollection(); - foreach ($this->getCollection()->getItems() as $item) { - $item->addIpData($item) - //->addCustomerData($item) - ->addQuoteData($item); - } return $this; } @@ -73,84 +73,93 @@ protected function _prepareCollection() protected function _prepareColumns() { $this->addColumn('customer_id', array( - 'header'=>Mage::helper('customer')->__('ID'), - 'width'=>'40px', - 'align'=>'right', - 'type' => 'number', - 'default' => Mage::helper('customer')->__('n/a'), - 'index'=>'customer_id') - ); + 'header' => Mage::helper('customer')->__('ID'), + 'width' => '40px', + 'align' => 'right', + 'type' => 'number', + 'default' => Mage::helper('customer')->__('n/a'), + 'index' => 'customer_id' + )); $this->addColumn('firstname', array( - 'header'=> Mage::helper('customer')->__('First Name'), - 'default' => Mage::helper('customer')->__('Guest'), - 'index'=>'customer_firstname') - ); + 'header' => Mage::helper('customer')->__('First Name'), + 'default' => Mage::helper('customer')->__('Guest'), + 'index' => 'customer_firstname' + )); $this->addColumn('lastname', array( - 'header'=> Mage::helper('customer')->__('Last Name'), - 'default' => Mage::helper('customer')->__('n/a'), - 'index'=>'customer_lastname') - ); + 'header' => Mage::helper('customer')->__('Last Name'), + 'default' => Mage::helper('customer')->__('n/a'), + 'index' => 'customer_lastname' + )); $this->addColumn('email', array( - 'header'=> Mage::helper('customer')->__('Email'), - 'default' => Mage::helper('customer')->__('n/a'), - 'index'=>'customer_email') - ); + 'header' => Mage::helper('customer')->__('Email'), + 'default' => Mage::helper('customer')->__('n/a'), + 'index' => 'customer_email' + )); $this->addColumn('ip_address', array( - 'header'=> Mage::helper('customer')->__('IP Address'), - 'index'=>'remote_addr', - 'default' => Mage::helper('customer')->__('n/a'), - 'renderer'=>'adminhtml/customer_online_grid_renderer_ip', - 'filter' => false, - 'sort' => false + 'header' => Mage::helper('customer')->__('IP Address'), + 'default' => Mage::helper('customer')->__('n/a'), + 'index' => 'remote_addr', + 'renderer' => 'adminhtml/customer_online_grid_renderer_ip', + 'filter' => false, + 'sort' => false )); $this->addColumn('session_start_time', array( - 'header'=> Mage::helper('customer')->__('Session Start Time'), - 'align'=>'left', - 'type' => 'datetime', - 'default' => Mage::helper('customer')->__('n/a'), - 'width' => '200px', - 'index'=>'first_visit_at') - ); + 'header' => Mage::helper('customer')->__('Session Start Time'), + 'align' => 'left', + 'width' => '200px', + 'type' => 'datetime', + 'default' => Mage::helper('customer')->__('n/a'), + 'index' =>'first_visit_at' + )); $this->addColumn('last_activity', array( - 'header'=> Mage::helper('customer')->__('Last Activity'), - 'align'=>'left', - 'type' => 'datetime', - 'default' => Mage::helper('customer')->__('n/a'), - 'width' => '200px', - 'index'=>'last_visit_at') + 'header' => Mage::helper('customer')->__('Last Activity'), + 'align' => 'left', + 'width' => '200px', + 'type' => 'datetime', + 'default' => Mage::helper('customer')->__('n/a'), + 'index' => 'last_visit_at' + )); + + $typeOptions = array( + Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER => Mage::helper('customer')->__('Customer'), + Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR => Mage::helper('customer')->__('Visitor'), ); $this->addColumn('type', array( - 'header'=> Mage::helper('customer')->__('Type'), - 'index'=>'type', - 'type' => 'options', - 'options' => array( - Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER => Mage::helper('customer')->__('Customer'), - Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR => Mage::helper('customer')->__('Visitor'), - ), - 'renderer'=>'adminhtml/customer_online_grid_renderer_type', + 'header' => Mage::helper('customer')->__('Type'), + 'index' => 'type', + 'type' => 'options', + 'options' => $typeOptions, +// 'renderer' => 'adminhtml/customer_online_grid_renderer_type', + 'index' => 'visitor_type' )); $this->addColumn('last_url', array( - 'header'=> Mage::helper('customer')->__('Last Url'), - 'type' => 'wrapline', + 'header' => Mage::helper('customer')->__('Last Url'), + 'type' => 'wrapline', 'lineLength' => '60', - 'default' => Mage::helper('customer')->__('n/a'), - 'renderer'=>'adminhtml/customer_online_grid_renderer_url', - 'index'=>'url') - ); + 'default' => Mage::helper('customer')->__('n/a'), + 'renderer' => 'adminhtml/customer_online_grid_renderer_url', + 'index' => 'last_url' + )); return parent::_prepareColumns(); } + /** + * Retrieve Row URL + * + * @param Mage_Core_Model_Abstract + * @return string + */ public function getRowUrl($row) { - return ( intval($row->getCustomerId()) > 0 ) ? $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId())) : ''; + return $row->getCustomerId() ? $this->getUrl('*/customer/edit', array('id' => $row->getCustomerId())) : ''; } } diff --git a/app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php b/app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php index d39021b870..1b2aeddb20 100644 --- a/app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php +++ b/app/code/core/Mage/AmazonPayments/Model/Payment/Asp.php @@ -194,14 +194,18 @@ public function getPayRedirectParams() $orderId = $this->getOrder()->getRealOrderId(); $amount = Mage::app()->getStore()->roundPrice($this->getOrder()->getBaseGrandTotal()); $currencyCode = $this->getOrder()->getBaseCurrency(); + + $urlModel = Mage::getModel('core/url') + ->setUseSession(false); + return $this->getApi()->getPayParams( $orderId, $amount, $currencyCode, - Mage::getUrl('amazonpayments/asp/returnCancel'), - Mage::getUrl('amazonpayments/asp/returnSuccess'), - Mage::getUrl('amazonpayments/asp/notification') - ); + $urlModel->getUrl('amazonpayments/asp/returnCancel'), + $urlModel->getUrl('amazonpayments/asp/returnSuccess'), + $urlModel->getUrl('amazonpayments/asp/notification') + ); } /** diff --git a/app/code/core/Mage/AmazonPayments/etc/system.xml b/app/code/core/Mage/AmazonPayments/etc/system.xml index d34fce6834..cedb72a8a4 100644 --- a/app/code/core/Mage/AmazonPayments/etc/system.xml +++ b/app/code/core/Mage/AmazonPayments/etc/system.xml @@ -49,7 +49,7 @@ 601 1 1 - 0 + 1 <label>Title</label> @@ -237,7 +237,7 @@ <sort_order>601</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> - <show_in_store>0</show_in_store> + <show_in_store>1</show_in_store> <fields> <title translate="label"> <label>Title</label> diff --git a/app/code/core/Mage/Catalog/Model/Product/Url.php b/app/code/core/Mage/Catalog/Model/Product/Url.php index 7294725072..87824aa3cc 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Url.php +++ b/app/code/core/Mage/Catalog/Model/Product/Url.php @@ -79,11 +79,15 @@ protected function _validImage($image) * @param bool $useSid * @return string */ - public function getProductUrl($product, $useSid = true) + public function getProductUrl($product, $useSid = null) { - $cacheUrlKey = 'url_' - . ($product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 'NONE') - . '_' . intval($useSid); + if ($useSid === null) { + $useSid = Mage::app()->getUseSessionInUrl(); + } + + $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 0; + + $cacheUrlKey = sprintf('url_%d_%d', $categoryId, $useSid); $url = $product->getData($cacheUrlKey); if (is_null($url)) { @@ -93,7 +97,9 @@ public function getProductUrl($product, $useSid = true) // auto add SID to URL $originalSid = $this->getUrlInstance()->getUseSession(); - $this->getUrlInstance()->setUseSession($useSid); + if ($originalSid != $useSid) { + $this->getUrlInstance()->setUseSession($useSid); + } if ($product->hasData('request_path') && $product->getRequestPath() != '') { $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($product->getRequestPath())); diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php index 2afcd86fd4..ff9af93dab 100644 --- a/app/code/core/Mage/Core/Model/App.php +++ b/app/code/core/Mage/Core/Model/App.php @@ -207,6 +207,14 @@ class Mage_Core_Model_App */ protected $_updateMode = false; + /** + * Use session in URL flag + * + * @see Mage_Core_Model_Url + * @var bool + */ + protected $_useSessionInUrl = true; + /** * Use session var instead of SID for session in URL * @@ -1216,4 +1224,26 @@ public function getUseSessionVar() { return $this->_useSessionVar; } + + /** + * Set Use session in URL flag + * + * @param bool $flag + * @return Mage_Core_Model_App + */ + public function setUseSessionInUrl($flag = true) + { + $this->_useSessionInUrl = (bool)$flag; + return $this; + } + + /** + * Retrieve use session in URL flag + * + * @return bool + */ + public function getUseSessionInUrl() + { + return $this->_useSessionInUrl; + } } diff --git a/app/code/core/Mage/Core/Model/Email/Template.php b/app/code/core/Mage/Core/Model/Email/Template.php index 7a85f16dc5..86776fbfc2 100644 --- a/app/code/core/Mage/Core/Model/Email/Template.php +++ b/app/code/core/Mage/Core/Model/Email/Template.php @@ -269,6 +269,7 @@ public function save() public function getProcessedTemplate(array $variables = array()) { $processor = $this->getTemplateFilter(); + $processor->setUseSessionInUrl(false); if(!$this->_preprocessFlag) { $variables['this'] = $this; diff --git a/app/code/core/Mage/Core/Model/Email/Template/Filter.php b/app/code/core/Mage/Core/Model/Email/Template/Filter.php index 36c5c6b57e..dad482ff4f 100644 --- a/app/code/core/Mage/Core/Model/Email/Template/Filter.php +++ b/app/code/core/Mage/Core/Model/Email/Template/Filter.php @@ -20,13 +20,34 @@ * * @category Mage * @package Mage_Core - * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + +/** + * Core Email Template Filter Model + * + * @category Mage + * @package Mage_Core + * @author Magento Core Team <core@magentocommerce.com> + */ class Mage_Core_Model_Email_Template_Filter extends Varien_Filter_Template { + /** + * Use absolute links flag + * + * @var bool + */ protected $_useAbsoluteLinks = false; + + /** + * Use session in URL flag + * + * @var bool + */ + protected $_useSessionInUrl; + /** * Url Instance * @@ -34,12 +55,36 @@ class Mage_Core_Model_Email_Template_Filter extends Varien_Filter_Template */ protected static $_urlInstance; + /** + * Set use absolute links flag + * + * @param bool $flag + * @return Mage_Core_Model_Email_Template_Filter + */ public function setUseAbsoluteLinks($flag) { $this->_useAbsoluteLinks = $flag; return $this; } + /** + * Set Use session in URL flag + * + * @param bool $flag + * @return Mage_Core_Model_Email_Template_Filter + */ + public function setUseSessionInUrl($flag) + { + $this->_useSessionInUrl = (bool)$flag; + return $this; + } + + /** + * Retrieve Block html directive + * + * @param array $construction + * @return string + */ public function blockDirective($construction) { $skipParams = array('type', 'id', 'output'); @@ -74,10 +119,15 @@ public function blockDirective($construction) return $block->$method(); } + /** + * Retrieve layout html directive + * + * @param array $construction + * @return string + */ public function layoutDirective($construction) { $skipParams = array('handle', 'area'); - $setArea = null; $params = $this->_getIncludeParameters($construction[2]); $layout = Mage::getModel('core/layout'); @@ -111,6 +161,12 @@ public function layoutDirective($construction) return $layout->getOutput(); } + /** + * Retrieve block parameters + * + * @param mixed $value + * @return array + */ protected function _getBlockParameters($value) { $tokenizer = new Varien_Filter_Template_Tokenizer_Parameter(); @@ -119,6 +175,12 @@ protected function _getBlockParameters($value) return $tokenizer->tokenize(); } + /** + * Retrieve Skin URL directive + * + * @param array $construction + * @return string + */ public function skinDirective($construction) { $params = $this->_getIncludeParameters($construction[2]); @@ -129,6 +191,25 @@ public function skinDirective($construction) return $url; } + /** + * Retrieve media file URL directive + * + * @param array $construction + * @return string + */ + public function mediaDirective($construction) + { + $params = $this->_getIncludeParameters($construction[2]); + return Mage::getBaseUrl('media') . $params['url']; + } + + /** + * Retrieve store URL directive + * Support url and direct_url properties + * + * @param array $construction + * @return string + */ public function storeDirective($construction) { $params = $this->_getIncludeParameters($construction[2]); @@ -143,6 +224,10 @@ public function storeDirective($construction) } $params['_absolute'] = $this->_useAbsoluteLinks; + if ($this->_useSessionInUrl === false) { + $params['_nosid'] = true; + } + if (isset($params['direct_url'])) { $path = ''; $params['_direct'] = $params['direct_url']; @@ -177,5 +262,4 @@ public function storeDirective($construction) return $url; } - -} \ No newline at end of file +} diff --git a/app/code/core/Mage/Core/Model/Url.php b/app/code/core/Mage/Core/Model/Url.php index 4651b9a5dd..1c6a80a732 100644 --- a/app/code/core/Mage/Core/Model/Url.php +++ b/app/code/core/Mage/Core/Model/Url.php @@ -96,7 +96,7 @@ class Mage_Core_Model_Url extends Varien_Object * @var array */ protected $_reservedRouteParams = array( - '_store', '_type', '_secure', '_forced_secure', '_use_rewrite', + '_store', '_type', '_secure', '_forced_secure', '_use_rewrite', '_nosid', '_absolute', '_current', '_direct', '_fragment', '_escape', '_query' ); @@ -112,7 +112,7 @@ class Mage_Core_Model_Url extends Varien_Object * * @var bool */ - protected $_useSession = true; + protected $_useSession; protected function _construct() { @@ -187,6 +187,9 @@ public function setRouteFrontName($name) */ public function getUseSession() { + if (is_null($this->_useSession)) { + $this->_useSession = Mage::app()->getUseSessionInUrl(); + } return $this->_useSession; } @@ -765,6 +768,12 @@ public function getUrl($routePath=null, $routeParams=null) $query = $routeParams['_query']; unset($routeParams['_query']); } + + $noSid = null; + if (isset($routeParams['_nosid'])) { + $noSid = (bool)$routeParams['_nosid']; + unset($routeParams['_nosid']); + } $url = $this->getRouteUrl($routePath, $routeParams); /** * Apply query params, need call after getRouteUrl for rewrite _current values @@ -780,7 +789,9 @@ public function getUrl($routePath=null, $routeParams=null) } } - $this->_prepareSessionUrl($url); + if ($noSid !== true) { + $this->_prepareSessionUrl($url); + } if ($query = $this->getQuery($escapeQuery)) { $url .= '?'.$query; diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php new file mode 100644 index 0000000000..584a0d7fe9 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online.php @@ -0,0 +1,132 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @category Mage + * @package Mage_Log + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + + +/** + * Log Prepare Online visitors resource collection + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team <core@magentocommerce.com> + */ +class Mage_Log_Model_Mysql4_Visitor_Online extends Mage_Core_Model_Mysql4_Abstract +{ + /** + * Initialize connection and define resource + * + */ + protected function _construct() + { + $this->_init('log/visitor_online', 'visitor_id'); + } + + /** + * Prepare online visitors for collection + * + * @param Mage_Log_Model_Visitor_Online $object + * @return Mage_Log_Model_Mysql4_Visitor_Online + */ + public function prepare(Mage_Log_Model_Visitor_Online $object) + { + if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) { + return $this; + } + + $this->_getWriteAdapter()->beginTransaction(); + $this->_getWriteAdapter()->truncate($this->getMainTable()); + + $visitors = array(); + $lastUrls = array(); + + // retrieve online visitors general data + $whereCond = sprintf('last_visit_at >= (? - INTERVAL %d MINUTE)', + $object->getOnlineInterval()); + $select = $this->_getReadAdapter()->select() + ->from( + $this->getTable('log/visitor'), + array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id')) + ->where($whereCond, now()); + + $query = $this->_getReadAdapter()->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']] = $row; + $lastUrls[$row['last_url_id']] = $row['visitor_id']; + $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_VISITOR; + $visitors[$row['visitor_id']]['customer_id'] = null; + } + + if (!$visitors) { + $this->commit(); + return $this; + } + + // retrieve visitor remote addr + $select = $this->_getReadAdapter()->select() + ->from( + $this->getTable('log/visitor_info'), + array('visitor_id', 'remote_addr')) + ->where('visitor_id IN(?)', array_keys($visitors)); + $query = $this->_getReadAdapter()->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr']; + } + + // retrieve visitor last URLs + $select = $this->_getReadAdapter()->select() + ->from( + $this->getTable('log/url_info_table'), + array('url_id', 'url')) + ->where('url_id IN(?)', array_keys($lastUrls)); + $query = $this->_getReadAdapter()->query($select); + while ($row = $query->fetch()) { + $visitorId = $lastUrls[$row['url_id']]; + $visitors[$visitorId]['last_url'] = $row['url']; + } + + // retrieve customers + $select = $this->_getReadAdapter()->select() + ->from( + $this->getTable('log/customer'), + array('visitor_id', 'customer_id')) + ->where('visitor_id IN(?)', array_keys($visitors)); + $query = $this->_getReadAdapter()->query($select); + while ($row = $query->fetch()) { + $visitors[$row['visitor_id']]['visitor_type'] = Mage_Log_Model_Visitor::VISITOR_TYPE_CUSTOMER; + $visitors[$row['visitor_id']]['customer_id'] = $row['customer_id']; + } + + foreach ($visitors as $visitorData) { + unset($visitorData['last_url_id']); + $this->_getWriteAdapter()->insert($this->getMainTable(), $visitorData); + } + + $this->_getWriteAdapter()->commit(); + + $object->setPrepareAt(); + + return $this; + } +} diff --git a/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php new file mode 100644 index 0000000000..c0f9dd7445 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Mysql4/Visitor/Online/Collection.php @@ -0,0 +1,92 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @category Mage + * @package Mage_Log + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + + +/** + * Log Online visitors collection + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team <core@magentocommerce.com> + */ +class Mage_Log_Model_Mysql4_Visitor_Online_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract +{ + /** + * Initialize collection model + * + */ + protected function _construct() + { + $this->_init('log/visitor_online'); + } + + /** + * Add Customer data to collection + * + * @return Mage_Log_Model_Mysql4_Visitor_Online_Collection + */ + public function addCustomerData() + { + $customer = Mage::getModel('customer/customer'); + // alias => attribute_code + $attributes = array( + 'customer_lastname' => 'lastname', + 'customer_firstname' => 'firstname', + 'customer_email' => 'email' + ); + + foreach ($attributes as $alias => $attributeCode) { + $attribute = $customer->getAttribute($attributeCode); + /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ + + if ($attribute->getBackendType() == 'static') { + $tableAlias = 'customer_' . $attribute->getAttributeCode(); + + $this->getSelect()->joinLeft( + array($tableAlias => $attribute->getBackend()->getTable()), + sprintf('%s.entity_id=main_table.customer_id', $tableAlias), + array($alias => $attribute->getAttributeCode()) + ); + } + else { + $tableAlias = 'customer_' . $attribute->getAttributeCode(); + + $joinConds = array( + sprintf('%s.entity_id=main_table.customer_id', $tableAlias), + $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute->getAttributeId()) + ); + + $this->getSelect()->joinLeft( + array($tableAlias => $attribute->getBackend()->getTable()), + join(' AND ', $joinConds), + array($alias => 'value') + ); + } + } + + return $this; + } +} diff --git a/app/code/core/Mage/Log/Model/Visitor/Online.php b/app/code/core/Mage/Log/Model/Visitor/Online.php new file mode 100644 index 0000000000..25b253c3a7 --- /dev/null +++ b/app/code/core/Mage/Log/Model/Visitor/Online.php @@ -0,0 +1,118 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @category Mage + * @package Mage_Log + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + + +/** + * Prepare Log Online Visitors Model + * + * @category Mage + * @package Mage_Log + * @author Magento Core Team <core@magentocommerce.com> + */ +class Mage_Log_Model_Visitor_Online extends Mage_Core_Model_Abstract +{ + const XML_PATH_ONLINE_INTERVAL = 'customer/online_customers/online_minutes_interval'; + const XML_PATH_UPDATE_FREQUENCY = 'log/visitor/online_update_frequency'; + + /** + * Initialize resource model + * + */ + protected function _construct() + { + $this->_init('log/visitor_online'); + } + + /** + * Retrieve resource instance wrapper + * + * @return Mage_Log_Model_Mysql4_Visitor_Online + */ + protected function _getResource() + { + return parent::_getResource(); + } + + /** + * Prepare Online visitors collection + * + * @return Mage_Log_Model_Visitor_Online + */ + public function prepare() + { + $this->_getResource()->prepare($this); + return $this; + } + + /** + * Retrieve last prepare at timestamp + * + * @return int + */ + public function getPrepareAt() + { + return Mage::app()->loadCache('log_visitor_online_prepare_at'); + } + + /** + * Set Prepare at timestamp (if time is null, set current timestamp) + * + * @param int $time + * @return Mage_Log_Model_Mysql4_Visitor_Online + */ + public function setPrepareAt($time = null) + { + if (is_null($time)) { + $time = time(); + } + Mage::app()->saveCache($time, 'log_visitor_online_prepare_at'); + return $this; + } + + /** + * Retrieve data update Frequency in second + * + * @return int + */ + public function getUpdateFrequency() + { + return Mage::getStoreConfig(self::XML_PATH_UPDATE_FREQUENCY); + } + + /** + * Retrieve Online Interval (in minutes) + * + * @return int + */ + public function getOnlineInterval() + { + $value = intval(Mage::getStoreConfig(self::XML_PATH_ONLINE_INTERVAL)); + if (!$value) { + $value = Mage_Log_Model_Visitor::DEFAULT_ONLINE_MINUTES_INTERVAL; + } + return $value; + } +} diff --git a/app/code/core/Mage/Log/etc/config.xml b/app/code/core/Mage/Log/etc/config.xml index 472def4884..9558efdd30 100644 --- a/app/code/core/Mage/Log/etc/config.xml +++ b/app/code/core/Mage/Log/etc/config.xml @@ -28,7 +28,7 @@ <config> <modules> <Mage_Log> - <version>0.7.4</version> + <version>0.7.6</version> </Mage_Log> </modules> <global> @@ -71,6 +71,9 @@ <quote_table> <table>log_quote</table> </quote_table> + <visitor_online> + <table>log_visitor_online</table> + </visitor_online> </entities> </log_mysql4> </models> @@ -176,6 +179,11 @@ </adminhtml> <default> + <log> + <visitor> + <online_update_frequency>60</online_update_frequency> + </visitor> + </log> <system> <log> <clean_after_day>180</clean_after_day> diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php new file mode 100644 index 0000000000..6fee6f29ab --- /dev/null +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.4-0.7.5.php @@ -0,0 +1,47 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @category Mage + * @package Mage_Log + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + + +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); +$installer->run(" +CREATE TABLE `{$installer->getTable('log_visitor_online')}` ( + `visitor_id` bigint(20) unsigned NOT NULL auto_increment, + `visitor_type` char(1) NOT NULL, + `remote_addr` int(11) NOT NULL, + `first_visit_at` datetime default NULL, + `last_visit_at` datetime default NULL, + `customer_id` int(10) unsigned default NULL, + `last_url` varchar(255) default NULL, + PRIMARY KEY (`visitor_id`), + KEY `IDX_VISITOR_TYPE` (`visitor_type`), + KEY `IDX_VISIT_TIME` (`first_visit_at`,`last_visit_at`), + KEY `IDX_CUSTOMER` (`customer_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +"); +$installer->endSetup(); diff --git a/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php new file mode 100644 index 0000000000..d59ad7a6fd --- /dev/null +++ b/app/code/core/Mage/Log/sql/log_setup/mysql4-upgrade-0.7.5-0.7.6.php @@ -0,0 +1,33 @@ +<?php +/** + * Magento + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@magentocommerce.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade Magento to newer + * versions in the future. If you wish to customize Magento for your + * needs please refer to http://www.magentocommerce.com for more information. + * + * @category Mage + * @package Mage_Log + * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + + +$installer = $this; +/* @var $installer Mage_Core_Model_Resource_Setup */ + +$installer->startSetup(); +$installer->getConnection()->modifyColumn($installer->getTable('log/visitor_online'), 'remote_addr', 'bigint(20) NOT NULL'); +$installer->endSetup(); diff --git a/cron.php b/cron.php index fdc9a1f5be..93fbe465c6 100644 --- a/cron.php +++ b/cron.php @@ -36,7 +36,7 @@ $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']); $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']); -Mage::app('admin'); +Mage::app('admin')->setUseSessionInUrl(false); try { Mage::getConfig()->init()->loadEventObservers('crontab');