Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit f06ed1f

Browse files
author
Jamie Snape
committed
Migrate statistics module settings to database
1 parent d76792a commit f06ed1f

File tree

18 files changed

+449
-296
lines changed

18 files changed

+449
-296
lines changed

modules/statistics/Notification.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
class Statistics_Notification extends MIDAS_Notification
2323
{
2424
public $moduleName = 'statistics';
25+
public $_models = array('Setting');
2526
public $_moduleModels = array('Download', 'IpLocation');
2627
public $_moduleComponents = array('Report');
2728

@@ -86,9 +87,8 @@ public function getItemMenuLink($params)
8687
/** get layout footer */
8788
public function getFooter()
8889
{
89-
$modulesConfig = Zend_Registry::get('configsModules');
90-
$url = $modulesConfig['statistics']->piwik->url;
91-
$id = $modulesConfig['statistics']->piwik->id;
90+
$url = $this->Setting->getValueByName(STATISTICS_PIWIK_URL_KEY, $this->moduleName);
91+
$id = $this->Setting->getValueByName(STATISTICS_PIWIK_SITE_ID_KEY, $this->moduleName);
9292

9393
$baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
9494
$js = $baseUrl.'/modules/'.$this->moduleName.'/public/js/statistics.notify.js';
Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1+
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
2+
13
[global]
2-
; version of the module
3-
version = 1.0.3
4-
; full name
5-
fullname = Statistics Module
6-
; description
7-
description =
8-
; category
9-
category = Core
4+
fullname = "Statistics"
5+
description = "Enables statistics"
6+
category = "Core"
107
dependencies = scheduler
11-
12-
piwik.url = "http://localhost/piwik"
13-
piwik.id = "1"
14-
piwik.apikey =
15-
report = "0"
16-
17-
ipinfodb.apikey =
8+
uuid = "332c4681-fd33-4c72-b7ba-16839099ec6a"
9+
version = "1.1.0"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
define('STATISTICS_PIWIK_URL_KEY', 'piwik_url');
22+
define('STATISTICS_PIWIK_URL_DEFAULT_VALUE', '');
23+
define('STATISTICS_PIWIK_SITE_ID_KEY', 'piwik_site_id');
24+
define('STATISTICS_PIWIK_SITE_ID_DEFAULT_VALUE', '');
25+
define('STATISTICS_PIWIK_API_KEY_KEY', 'piwik_api_key');
26+
define('STATISTICS_PIWIK_API_KEY_DEFAULT_VALUE', '');
27+
define('STATISTICS_IP_INFO_DB_API_KEY_KEY', 'ip_info_db_api_key');
28+
define('STATISTICS_IP_INFO_DB_API_KEY_DEFAULT_VALUE', '');
29+
define('STATISTICS_SEND_DAILY_REPORTS_KEY', 'send_daily_reports');
30+
define('STATISTICS_SEND_DAILY_REPORTS_DEFAULT_VALUE', '');
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the statistics module. */
22+
class Statistics_AdminController extends Statistics_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** @var array */
28+
public $_moduleComponents = array('Admin');
29+
30+
/** Index action */
31+
public function indexAction()
32+
{
33+
$this->requireAdminPrivileges();
34+
35+
$this->view->pageTitle = 'Statistics Module Configuration';
36+
$form = new Statistics_Form_Admin();
37+
38+
if ($this->getRequest()->isPost()) {
39+
$data = $this->getRequest()->getPost();
40+
41+
if ($form->isValid($data)) {
42+
$values = $form->getValues();
43+
44+
foreach ($values as $key => $value) {
45+
if ($value !== null) {
46+
$this->Setting->setConfig($key, $value, $this->moduleName);
47+
}
48+
}
49+
50+
$this->ModuleComponent->Admin->schedulePerformGeolocationJob(
51+
$values[STATISTICS_IP_INFO_DB_API_KEY_KEY],
52+
$this->userSession->Dao
53+
);
54+
55+
$this->ModuleComponent->Admin->scheduleOrCancelSendReportJob(
56+
$values[STATISTICS_SEND_DAILY_REPORTS_KEY] == 1,
57+
$this->userSession->Dao
58+
);
59+
}
60+
61+
$form->populate($data);
62+
} else {
63+
$elements = $form->getElements();
64+
65+
foreach ($elements as $element) {
66+
$name = $element->getName();
67+
68+
if ($name !== 'csrf' && $name !== 'submit') {
69+
$value = $this->Setting->getValueByName($name, $this->moduleName);
70+
71+
if (!is_null($value)) {
72+
$form->setDefault($name, $value);
73+
}
74+
}
75+
}
76+
}
77+
78+
$this->view->form = $form;
79+
session_start();
80+
}
81+
}

modules/statistics/controllers/ConfigController.php

Lines changed: 0 additions & 120 deletions
This file was deleted.

modules/statistics/controllers/IndexController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Statistics_IndexController extends Statistics_AppController
2323
{
2424
public $_moduleModels = array('Download');
25-
public $_models = array('Errorlog', 'Assetstore');
25+
public $_models = array('Assetstore', 'Errorlog', 'Setting');
2626
public $_components = array('Utility');
2727

2828
/** index action */
@@ -99,9 +99,9 @@ public function indexAction()
9999

100100
$this->view->json['stats']['errors'] = $jqplotArray;
101101
$this->view->json['stats']['assetstores'] = $jqplotAssetstoreArray;
102-
$modulesConfig = Zend_Registry::get('configsModules');
103-
$this->view->piwikUrl = $modulesConfig['statistics']->piwik->url;
104-
$this->view->piwikId = $modulesConfig['statistics']->piwik->id;
105-
$this->view->piwikKey = $modulesConfig['statistics']->piwik->apikey;
102+
103+
$this->view->piwikUrl = $this->Setting->getValueByName(STATISTICS_PIWIK_URL_KEY, $this->moduleName);
104+
$this->view->piwikId = $this->Setting->getValueByName(STATISTICS_PIWIK_SITE_ID_KEY, $this->moduleName);
105+
$this->view->piwikKey = $this->Setting->getValueByName(STATISTICS_PIWIK_API_KEY_KEY, $this->moduleName);
106106
}
107107
}

0 commit comments

Comments
 (0)