Skip to content

Commit 7833beb

Browse files
committed
Merge branch 'release/1.2.2'
2 parents 1b6fa18 + 31cec94 commit 7833beb

File tree

64 files changed

+443
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+443
-65
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ env:
1010
- MAGENTO_VERSION="1.7.0.2"
1111
- MAGENTO_VERSION="1.8.1.0"
1212
- MAGENTO_VERSION="1.9.0.1"
13+
- MAGENTO_VERSION="1.9.1.0"
14+
15+
matrix:
16+
fast_finish: true
17+
exclude:
18+
- php: 5.5
19+
env: MAGENTO_VERSION="1.6.2.0"
20+
- php: 5.5
21+
env: MAGENTO_VERSION="1.7.0.2"
1322

1423
before_install:
1524
- mkdir test/

src/app/code/community/FireGento/AdminMonitoring/Block/Adminhtml/History.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright 2014 FireGento Team (http://www.firegento.com)
1919
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
2020
*/
21+
2122
/**
2223
* Displays the logging history grid container
2324
*

src/app/code/community/FireGento/AdminMonitoring/Block/Adminhtml/History/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function _prepareColumns()
113113

114114
/* @var $adminUsers FireGento_AdminMonitoring_Model_System_Config_Source_Admin_User */
115115
$adminUsers = Mage::getModel('firegento_adminmonitoring/system_config_source_admin_user');
116-
$userOptions = $adminUsers->toOptionHash();
116+
$userOptions = $adminUsers->toOptionHash(false);
117117
$this->addColumn('user_id', array(
118118
'header' => $this->getMonitoringHelper()->__('User'),
119119
'index' => 'user_id',

src/app/code/community/FireGento/AdminMonitoring/Helper/Data.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,30 @@ class FireGento_AdminMonitoring_Helper_Data extends Mage_Core_Helper_Abstract
4242
const ACTION_INSERT = 1;
4343
const ACTION_UPDATE = 2;
4444
const ACTION_DELETE = 3;
45-
const ACTION_LOGIN = 4;
45+
const ACTION_LOGIN = 4;
4646

4747
/**
4848
* STATUS
4949
*/
5050
const STATUS_SUCCESS = 1;
5151
const STATUS_FAILURE = 2;
5252

53+
/**
54+
* Checks if the given admin user id is excluded
55+
*
56+
* @param int $userId User ID
57+
* @return bool
58+
*/
59+
public function isAdminUserIdExcluded($userId)
60+
{
61+
$excludedUserIds = explode(',', Mage::getStoreConfig('admin/firegento_adminmonitoring/exclude_admin_users'));
62+
if (in_array($userId, $excludedUserIds)) {
63+
return true;
64+
}
65+
66+
return false;
67+
}
68+
5369
/**
5470
* Retrieve the attribute type by provided class name
5571
*
@@ -113,7 +129,7 @@ public function getRowUrl(FireGento_AdminMonitoring_Model_History $row)
113129
* @param string $separator Separator
114130
* @return string
115131
*/
116-
public function getFullActionName($separator='_')
132+
public function getFullActionName($separator = '_')
117133
{
118134
$request = array(
119135
Mage::app()->getRequest()->getModuleName(),

src/app/code/community/FireGento/AdminMonitoring/Model/Clean.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright 2014 FireGento Team (http://www.firegento.com)
1919
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
2020
*/
21+
2122
/**
2223
* Cleans the history after a configurable amount of time.
2324
*
@@ -27,9 +28,21 @@
2728
*/
2829
class FireGento_AdminMonitoring_Model_Clean
2930
{
30-
const XML_PATH_ADMINMONITORING_INTERVAL = 'admin/firegento_adminmonitoring/interval';
31+
const XML_PATH_ADMINMONITORING_INTERVAL = 'admin/firegento_adminmonitoring/interval';
3132
const XML_PATH_ADMINMONITORING_CLEAN_ENABLED = 'admin/firegento_adminmonitoring/enable_cleaning';
3233

34+
/**
35+
* Clean in chunks.
36+
*
37+
* CHUNK_SIZE determines the items cleared per chunk.
38+
*
39+
* CHUNK_RUNS determines the number of chunks cleaned per call to clean()
40+
*
41+
* I.e. per call of clean(), at most CHUNK_SIZE * CHUNK_RUNS items are cleaned.
42+
*/
43+
const CHUNK_SIZE = 1000;
44+
const CHUNK_RUNS = 250;
45+
3346
/**
3447
* Cronjob method for cleaning the database table.
3548
*
@@ -63,22 +76,53 @@ public function clean()
6376
return $this;
6477
}
6578

79+
$this->cleanInChunks();
80+
81+
return $this;
82+
}
83+
84+
/**
85+
* Clean the database table for the given interval, usink chunks to avoid memory over-usage.
86+
*
87+
* @return $this
88+
*/
89+
protected function cleanInChunks()
90+
{
91+
$numChunks = 0;
92+
do {
93+
$cleanedItems = $this->cleanChunk();
94+
} while ($cleanedItems == static::CHUNK_SIZE && $numChunks++ < static::CHUNK_RUNS);
95+
96+
return $this;
97+
}
98+
99+
/**
100+
* Clean a chunk of the items in database table for the given interval.
101+
*
102+
* @return int Number of items deleted
103+
*/
104+
protected function cleanChunk()
105+
{
66106
$interval = Mage::getStoreConfig(self::XML_PATH_ADMINMONITORING_INTERVAL);
67107

68108
/* @var $adminMonitoringCollection FireGento_AdminMonitoring_Model_Resource_History_Collection */
69109
$adminMonitoringCollection = Mage::getModel('firegento_adminmonitoring/history')
70110
->getCollection()
111+
->setPageSize(static::CHUNK_SIZE)
71112
->addFieldToFilter(
72113
'created_at',
73114
array(
74-
'lt' => new Zend_Db_Expr("DATE_SUB('" . now() . "', INTERVAL " . (int) $interval . " DAY)")
115+
'lt' => new Zend_Db_Expr("DATE_SUB('" . now() . "', INTERVAL " . (int)$interval . " DAY)")
75116
)
76117
);
77118

119+
$count = 0;
120+
78121
foreach ($adminMonitoringCollection as $history) {
79122
$history->delete();
123+
$count++;
80124
}
81125

82-
return $this;
126+
return $count;
83127
}
84128
}

src/app/code/community/FireGento/AdminMonitoring/Model/History.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
*/
3737
class FireGento_AdminMonitoring_Model_History extends Mage_Core_Model_Abstract
3838
{
39+
/**
40+
* @var bool
41+
*/
42+
protected $_forcedLogging = false;
43+
3944
/**
4045
* Inits the resource model and resource collection model
4146
*/
@@ -44,6 +49,35 @@ protected function _construct()
4449
$this->_init('firegento_adminmonitoring/history');
4550
}
4651

52+
/**
53+
* Processing object before save data
54+
*
55+
* @return FireGento_AdminMonitoring_Model_History
56+
*/
57+
protected function _beforeSave()
58+
{
59+
if (Mage::helper('firegento_adminmonitoring')->isAdminUserIdExcluded($this->getData('user_id'))
60+
&& !$this->_forcedLogging
61+
) {
62+
$this->_dataSaveAllowed = false;
63+
}
64+
65+
return parent::_beforeSave();
66+
}
67+
68+
/**
69+
* Set the forced logging value
70+
*
71+
* @param bool $flag Flag
72+
* @return FireGento_AdminMonitoring_Model_History
73+
*/
74+
public function setForcedLogging($flag)
75+
{
76+
$this->_forcedLogging = $flag;
77+
78+
return $this;
79+
}
80+
4781
/**
4882
* Retrieve the original model
4983
*

src/app/code/community/FireGento/AdminMonitoring/Model/History/Data.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright 2014 FireGento Team (http://www.firegento.com)
1919
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
2020
*/
21+
2122
/**
2223
* History Data Model
2324
*
@@ -96,6 +97,7 @@ protected function _filterObligatoryFields($data)
9697
public function getOrigContent()
9798
{
9899
$data = $this->_savedModel->getOrigData();
100+
99101
return $this->_filterObligatoryFields($data);
100102
}
101103

src/app/code/community/FireGento/AdminMonitoring/Model/History/Diff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright 2014 FireGento Team (http://www.firegento.com)
1919
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
2020
*/
21+
2122
/**
2223
* History Diff Model
2324
*
@@ -86,6 +87,7 @@ private function getObjectDiff()
8687
public function getSerializedDiff()
8788
{
8889
$dataDiff = $this->getObjectDiff();
90+
8991
return json_encode($dataDiff);
9092
}
9193
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* This file is part of a FireGento e.V. module.
4+
*
5+
* This FireGento e.V. module is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License version 3 as
7+
* published by the Free Software Foundation.
8+
*
9+
* This script is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* PHP version 5
14+
*
15+
* @category FireGento
16+
* @package FireGento_AdminMonitoring
17+
* @author FireGento Team <team@firegento.com>
18+
* @copyright 2014 FireGento Team (http://www.firegento.com)
19+
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
20+
*/
21+
/**
22+
* Observes Category Move
23+
*
24+
* @category FireGento
25+
* @package FireGento_AdminMonitoring
26+
* @author FireGento Team <team@firegento.com>
27+
*/
28+
class FireGento_AdminMonitoring_Model_Observer_Category_Move
29+
extends FireGento_AdminMonitoring_Model_Observer_Log
30+
{
31+
32+
/**
33+
* Observe the category move
34+
*
35+
* @param Varien_Event_Observer $observer Observer Instance
36+
* @return void
37+
*/
38+
public function catalogCategoryMove(Varien_Event_Observer $observer)
39+
{
40+
$category = $observer->getCategory();
41+
42+
$dataModel = Mage::getModel('firegento_adminmonitoring/history_data', $category);
43+
$diffModel = Mage::getModel('firegento_adminmonitoring/history_diff', $dataModel);
44+
45+
$eventData = array(
46+
'object_id' => $dataModel->getObjectId(),
47+
'object_type' => $dataModel->getObjectType(),
48+
'content' => $dataModel->getSerializedContent(),
49+
'content_diff' => $diffModel->getSerializedDiff(),
50+
'action' => FireGento_AdminMonitoring_Helper_Data::ACTION_UPDATE,
51+
);
52+
53+
Mage::dispatchEvent('firegento_adminmonitoring_log', $eventData);
54+
}
55+
}

src/app/code/community/FireGento/AdminMonitoring/Model/Observer/Log.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @copyright 2014 FireGento Team (http://www.firegento.com)
1919
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
2020
*/
21+
2122
/**
2223
* Logging model
2324
*
@@ -37,16 +38,16 @@ public function log(Varien_Event_Observer $observer)
3738
/* @var $history FireGento_AdminMonitoring_Model_History */
3839
$history = Mage::getModel('firegento_adminmonitoring/history');
3940
$history->setData(array(
40-
'object_id' => $observer->getObjectId(),
41-
'object_type' => $observer->getObjectType(),
42-
'content' => $observer->getContent(),
43-
'content_diff' => $observer->getContentDiff(),
44-
'user_agent' => $this->getUserAgent(),
45-
'ip' => $this->getRemoteAddr(),
46-
'user_id' => $this->getUserId(),
47-
'user_name' => $this->getUserName(),
48-
'action' => $observer->getAction(),
49-
'created_at' => now(),
41+
'object_id' => $observer->getObjectId(),
42+
'object_type' => $observer->getObjectType(),
43+
'content' => $observer->getContent(),
44+
'content_diff' => $observer->getContentDiff(),
45+
'user_agent' => $this->getUserAgent(),
46+
'ip' => $this->getRemoteAddr(),
47+
'user_id' => $this->getUserId(),
48+
'user_name' => $this->getUserName(),
49+
'action' => $observer->getAction(),
50+
'created_at' => now(),
5051
));
5152

5253
$history->save();
@@ -93,6 +94,7 @@ public function getUser()
9394
{
9495
/* @var $session Mage_Admin_Model_Session */
9596
$session = Mage::getSingleton('admin/session');
97+
9698
return $session->getUser();
9799
}
98100

@@ -103,7 +105,7 @@ public function getUser()
103105
*/
104106
public function getUserAgent()
105107
{
106-
return (isset($_SERVER['HTTP_USER_AGENT']) ? (string) $_SERVER['HTTP_USER_AGENT'] : '');
108+
return (isset($_SERVER['HTTP_USER_AGENT']) ? (string)$_SERVER['HTTP_USER_AGENT'] : '');
107109
}
108110

109111
/**

0 commit comments

Comments
 (0)