Skip to content

Commit

Permalink
Merge pull request #2 from gruenspar/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
pogster authored Jul 3, 2018
2 parents 1b6fa18 + 08fa853 commit 7d07a7f
Show file tree
Hide file tree
Showing 69 changed files with 578 additions and 93 deletions.
56 changes: 38 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
language: php
sudo: false

php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0

env:
- MAGENTO_VERSION="1.6.2.0"
- MAGENTO_VERSION="1.7.0.2"
- MAGENTO_VERSION="1.8.1.0"
- MAGENTO_VERSION="1.9.0.1"
- MAGENTO_VERSION="magento-mirror-1.6.2.0"
- MAGENTO_VERSION="magento-mirror-1.7.0.2"
- MAGENTO_VERSION="magento-mirror-1.8.1.0"
- MAGENTO_VERSION="magento-mirror-1.9.0.1"
- MAGENTO_VERSION="magento-mirror-1.9.1.1"
- MAGENTO_VERSION="magento-mirror-1.9.2.4"
- MAGENTO_VERSION="magento-mirror-1.9.3.2"

before_install:
- mkdir test/
- curl -sS https://getcomposer.org/installer | php
- chmod +x ./composer.phar
- ./composer.phar --version
- ./composer.phar install --dev
matrix:
fast_finish: true
exclude:
# Old Magento Versions are not officially supported to run with PHP 5.5
- php: 5.5
env: MAGENTO_VERSION="magento-mirror-1.6.2.0"
- php: 5.5
env: MAGENTO_VERSION="magento-mirror-1.7.0.2"

before_script:
- CURR_DIR=$(pwd)
- bin/mage-ci install test ${MAGENTO_VERSION} magento_test -c -t -r http://mage-ci.firegento.com
- bin/mage-ci install-module test $CURR_DIR
- git clone https://github.com/EcomDev/EcomDev_PHPUnit.git ./phpunit/
- bin/mage-ci install-module $CURR_DIR/test $CURR_DIR/phpunit/
# Old Magento Versions are not officially supported to run with PHP 5.6
- php: 5.6
env: MAGENTO_VERSION="magento-mirror-1.6.2.0"
- php: 5.6
env: MAGENTO_VERSION="magento-mirror-1.7.0.2"
- php: 5.6
env: MAGENTO_VERSION="magento-mirror-1.8.1.0"
- php: 5.6
env: MAGENTO_VERSION="magento-mirror-1.9.0.1"

# Old Magento Versions are not officially supported to run with PHP 7.0
- php: 7.0
env: MAGENTO_VERSION="magento-mirror-1.6.2.0"
- php: 7.0
env: MAGENTO_VERSION="magento-mirror-1.7.0.2"
- php: 7.0
env: MAGENTO_VERSION="magento-mirror-1.8.1.0"
- php: 7.0
env: MAGENTO_VERSION="magento-mirror-1.9.0.1"

script:
- bin/mage-ci phpunit test
- curl --retry 2 --retry-delay 5 -f -sSL https://raw.githubusercontent.com/therouv/MageTestStand/master/setup.sh | bash
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
"require": {
"magento-hackathon/magento-composer-installer": "*"
},
"require-dev": {
"ecomdev/mage-ci": "master-dev"
},
"config": {
"bin-dir": "bin"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.firegento.com"
"url": "https://packages.firegento.com"
}
],
"extra": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright 2014 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/

/**
* Displays the logging history grid container
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function _prepareColumns()

/* @var $adminUsers FireGento_AdminMonitoring_Model_System_Config_Source_Admin_User */
$adminUsers = Mage::getModel('firegento_adminmonitoring/system_config_source_admin_user');
$userOptions = $adminUsers->toOptionHash();
$userOptions = $adminUsers->toOptionHash(false);
$this->addColumn('user_id', array(
'header' => $this->getMonitoringHelper()->__('User'),
'index' => 'user_id',
Expand Down
56 changes: 54 additions & 2 deletions src/app/code/community/FireGento/AdminMonitoring/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,66 @@ class FireGento_AdminMonitoring_Helper_Data extends Mage_Core_Helper_Abstract
const ACTION_INSERT = 1;
const ACTION_UPDATE = 2;
const ACTION_DELETE = 3;
const ACTION_LOGIN = 4;
const ACTION_LOGIN = 4;

/**
* STATUS
*/
const STATUS_SUCCESS = 1;
const STATUS_FAILURE = 2;

/**
* Retrieve status name from status id
*
* @param int $id Status id
* @return string Status name
*/
public function statusIdToName($id)
{
switch ($id) {
case self::STATUS_SUCCESS:
return $this->__("Success");
case self::STATUS_FAILURE:
return $this->__("Fail");
}
}

/**
* Retrieve action name from action id
*
* @param int $id Action id
* @return string Action name
*/
public function actionIdToName($id)
{
switch ($id) {
case self::ACTION_INSERT:
return $this->__("Insert");
case self::ACTION_UPDATE:
return $this->__("Update");
case self::ACTION_DELETE:
return $this->__("Delete");
case self::ACTION_LOGIN:
return $this->__("Login");
}
}

/**
* Checks if the given admin user id is excluded
*
* @param int $userId User ID
* @return bool
*/
public function isAdminUserIdExcluded($userId)
{
$excludedUserIds = explode(',', Mage::getStoreConfig('admin/firegento_adminmonitoring/exclude_admin_users'));
if (in_array($userId, $excludedUserIds)) {
return true;
}

return false;
}

/**
* Retrieve the attribute type by provided class name
*
Expand Down Expand Up @@ -113,7 +165,7 @@ public function getRowUrl(FireGento_AdminMonitoring_Model_History $row)
* @param string $separator Separator
* @return string
*/
public function getFullActionName($separator='_')
public function getFullActionName($separator = '_')
{
$request = array(
Mage::app()->getRequest()->getModuleName(),
Expand Down
50 changes: 47 additions & 3 deletions src/app/code/community/FireGento/AdminMonitoring/Model/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright 2014 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/

/**
* Cleans the history after a configurable amount of time.
*
Expand All @@ -27,9 +28,21 @@
*/
class FireGento_AdminMonitoring_Model_Clean
{
const XML_PATH_ADMINMONITORING_INTERVAL = 'admin/firegento_adminmonitoring/interval';
const XML_PATH_ADMINMONITORING_INTERVAL = 'admin/firegento_adminmonitoring/interval';
const XML_PATH_ADMINMONITORING_CLEAN_ENABLED = 'admin/firegento_adminmonitoring/enable_cleaning';

/**
* Clean in chunks.
*
* CHUNK_SIZE determines the items cleared per chunk.
*
* CHUNK_RUNS determines the number of chunks cleaned per call to clean()
*
* I.e. per call of clean(), at most CHUNK_SIZE * CHUNK_RUNS items are cleaned.
*/
const CHUNK_SIZE = 1000;
const CHUNK_RUNS = 250;

/**
* Cronjob method for cleaning the database table.
*
Expand Down Expand Up @@ -63,22 +76,53 @@ public function clean()
return $this;
}

$this->cleanInChunks();

return $this;
}

/**
* Clean the database table for the given interval, usink chunks to avoid memory over-usage.
*
* @return $this
*/
protected function cleanInChunks()
{
$numChunks = 0;
do {
$cleanedItems = $this->cleanChunk();
} while ($cleanedItems == static::CHUNK_SIZE && $numChunks++ < static::CHUNK_RUNS);

return $this;
}

/**
* Clean a chunk of the items in database table for the given interval.
*
* @return int Number of items deleted
*/
protected function cleanChunk()
{
$interval = Mage::getStoreConfig(self::XML_PATH_ADMINMONITORING_INTERVAL);

/* @var $adminMonitoringCollection FireGento_AdminMonitoring_Model_Resource_History_Collection */
$adminMonitoringCollection = Mage::getModel('firegento_adminmonitoring/history')
->getCollection()
->setPageSize(static::CHUNK_SIZE)
->addFieldToFilter(
'created_at',
array(
'lt' => new Zend_Db_Expr("DATE_SUB('" . now() . "', INTERVAL " . (int) $interval . " DAY)")
'lt' => new Zend_Db_Expr("DATE_SUB('" . now() . "', INTERVAL " . (int)$interval . " DAY)")
)
);

$count = 0;

foreach ($adminMonitoringCollection as $history) {
$history->delete();
$count++;
}

return $this;
return $count;
}
}
34 changes: 34 additions & 0 deletions src/app/code/community/FireGento/AdminMonitoring/Model/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
*/
class FireGento_AdminMonitoring_Model_History extends Mage_Core_Model_Abstract
{
/**
* @var bool
*/
protected $_forcedLogging = false;

/**
* Inits the resource model and resource collection model
*/
Expand All @@ -44,6 +49,35 @@ protected function _construct()
$this->_init('firegento_adminmonitoring/history');
}

/**
* Processing object before save data
*
* @return FireGento_AdminMonitoring_Model_History
*/
protected function _beforeSave()
{
if (Mage::helper('firegento_adminmonitoring')->isAdminUserIdExcluded($this->getData('user_id'))
&& !$this->_forcedLogging
) {
$this->_dataSaveAllowed = false;
}

return parent::_beforeSave();
}

/**
* Set the forced logging value
*
* @param bool $flag Flag
* @return FireGento_AdminMonitoring_Model_History
*/
public function setForcedLogging($flag)
{
$this->_forcedLogging = $flag;

return $this;
}

/**
* Retrieve the original model
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright 2014 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/

/**
* History Data Model
*
Expand Down Expand Up @@ -69,6 +70,8 @@ public function getContent()
}
$model->load($this->_savedModel->getId());

Mage::dispatchEvent('firegento_adminmonitoring_enrich_model_content', ['object' => $model]);

return $this->_filterObligatoryFields($model->getData());
}

Expand All @@ -95,8 +98,11 @@ protected function _filterObligatoryFields($data)
*/
public function getOrigContent()
{
$data = $this->_savedModel->getOrigData();
return $this->_filterObligatoryFields($data);
$data = new Varien_Object($this->_savedModel->getOrigData());

Mage::dispatchEvent('firegento_adminmonitoring_enrich_model_orig_content', ['data_object' => $data, 'model_object' => $this->_savedModel]);

return $this->_filterObligatoryFields($data->getData());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @copyright 2014 FireGento Team (http://www.firegento.com)
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/

/**
* History Diff Model
*
Expand Down Expand Up @@ -86,6 +87,7 @@ private function getObjectDiff()
public function getSerializedDiff()
{
$dataDiff = $this->getObjectDiff();

return json_encode($dataDiff);
}
}
Loading

0 comments on commit 7d07a7f

Please sign in to comment.