Skip to content

Commit

Permalink
log usage statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Aug 9, 2016
1 parent a22b602 commit d40aed3
Show file tree
Hide file tree
Showing 36 changed files with 188 additions and 67 deletions.
2 changes: 1 addition & 1 deletion controllers/Admin/CarrierController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Carrier;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_CarrierController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/CarrierShippingRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Tool as PimTool;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/CountryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Country;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_CountryController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/CurrencyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Currency;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_CurrencyController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/CustomerGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\CustomerGroup;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_CustomerGroupController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Product\Filter;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_FilterController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/HelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_HelperController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/IndexesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Index;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Model\Object;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Plugin;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_InstallController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ManufacturerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Manufacturer;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_ManufacturerController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/MessagingContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Messaging\Contact;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_MessagingContactController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/MessagingThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_MessagingThreadController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/MessagingThreadStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Messaging\Thread\State;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_MessagingThreadStateController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_ObjectController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Plugin;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Model\Object;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/OrderStateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Order\State;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_OrderStateController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/PriceRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Cart\PriceRule;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Tool as PimTool;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Tool as PimTool;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ProductPriceRuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Tool as PimTool;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ProductSpecificPriceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use Pimcore\Tool as PimTool;

/**
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use CoreShop\Tool;
use CoreShop\Model;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;
use CoreShop\Helper\ReportQuery;

/**
Expand Down
3 changes: 1 addition & 2 deletions controllers/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use CoreShop\Plugin;
use CoreShop\Model;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_SettingsController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ShopController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Shop;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_ShopController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/StateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\State;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_StateController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/TaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Tax;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_TaxController
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/TaxRuleGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\TaxRuleGroup;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_TaxRuleGroupController
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion controllers/Admin/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_UpdateController+
*/
class CoreShop_Admin_UpdateController extends \Pimcore\Controller\Action\Admin
class CoreShop_Admin_UpdateController extends Admin
{
public function init()
{
Expand Down
2 changes: 1 addition & 1 deletion controllers/Admin/ZoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

use CoreShop\Model\Zone;
use Pimcore\Controller\Action\Admin;
use CoreShop\Controller\Action\Admin;

/**
* Class CoreShop_Admin_ZoneController
Expand Down
39 changes: 39 additions & 0 deletions lib/CoreShop/Controller/Action/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,43 @@
*/
class Admin extends \Pimcore\Controller\Action\Admin
{
public function init()
{
parent::init();

$this->logCoreShopUsageStatistics();
}

/**
* @throws \Zend_Json_Exception
*/
protected function logCoreShopUsageStatistics()
{
$params = [];
$disallowedKeys = ["_dc", "module", "controller", "action", "password"];
foreach ($this->getAllParams() as $key => $value) {
if (is_json($value)) {
$value = \Zend_Json::decode($value);
if (is_array($value)) {
array_walk_recursive($value, function (&$item, $key) {
if (strpos($key, "pass") !== false) {
$item = "*************";
}
});
}
$value = \Zend_Json::encode($value);
}


if (!in_array($key, $disallowedKeys) && is_string($value)) {
$params[$key] = (strlen($value) > 40) ? substr($value, 0, 40) . "..." : $value;
}
}

\Pimcore\Log\Simple::log("coreshop-usagelog",
($this->getUser() ? $this->getUser()->getId() : "0") . "|" .
$this->getParam("module") . "|" .
$this->getParam("controller") . "|" .
$this->getParam("action")."|" . @json_encode($params));
}
}
42 changes: 42 additions & 0 deletions lib/CoreShop/Maintenance/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* CoreShop.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2016 Dominik Pfaffenbauer (http://www.pfaffenbauer.at)
* @license http://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Maintenance;

use Pimcore\Tool;

/**
* Class Log
* @package CoreShop\Maintenance
*/
class Log {
/**
*
*/
public static function maintenance()
{
$logFile = PIMCORE_LOG_DIRECTORY . "/coreshop-usagelog.log";

if (is_file($logFile) && filesize($logFile) > 200000) {
$data = gzencode(file_get_contents($logFile));
$response = Tool::getHttpData("https://www.coreshop.org/usage-statistics/", [], ["data" => $data, "hostname" => Tool::getHostname()]);
if (strpos($response, "true") !== false) {
@unlink($logFile);
\Logger::debug("Usage statistics are transmitted and logfile was cleaned");
} else {
\Logger::debug("Unable to send usage statistics");
}
}
}
}
4 changes: 3 additions & 1 deletion lib/CoreShop/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class Configuration extends AbstractModel
*/
protected static $systemKeys = [
'SYSTEM.ISINSTALLED',
'SYSTEM.MULTISHOP.ENABLED'
'SYSTEM.MULTISHOP.ENABLED',
'SYSTEM.LOG.USAGESTATISTICS',
'SYSTEM.CURRENCY.AUTO_EXCHANGE_RATES'
];

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/CoreShop/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public function init()
if (Configuration::get('SYSTEM.CART.AUTO_CLEANUP')) {
$manager->registerJob(new Job('coreshop_cart_cleanup', '\\CoreShop\\Model\\Cart', 'maintenance'));
}
if (Configuration::get('SYSTEM.LOG.USAGESTATISTICS')) {
$manager->registerJob(new Job('coreshop_send_usage_statistcs', '\\CoreShop\\Maintenance\\Log', 'maintenance'));
}
}
});

Expand Down
1 change: 1 addition & 0 deletions lib/CoreShop/Plugin/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ public function createConfig()
Configuration::set("SYSTEM.BASE.PRICES.GROSS", false);
Configuration::set("SYSTEM.SHIPPING.CARRIER_SORT", "grade");
Configuration::set("SYSTEM.BASE.TAX.ENABLED", true);
Configuration::set("SYSTEM.LOG.USAGESTATISTICS", true);
}

/**
Expand Down
Loading

0 comments on commit d40aed3

Please sign in to comment.