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

Commit 257f3fb

Browse files
author
Jamie Snape
committed
Reduce number of queries of module configurations
1 parent 48f78ec commit 257f3fb

File tree

6 files changed

+35
-70
lines changed

6 files changed

+35
-70
lines changed

core/AppController.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,11 @@ public function preDispatch()
131131

132132
$this->userSession = $user;
133133
$this->view->recentItems = array();
134-
$this->view->needUpgrade = false;
135134
$this->view->highNumberError = false;
136135
if ($user->Dao != null && $user->Dao instanceof UserDao) {
137136
if ($user->Dao->isAdmin() && $fc->getRequest()->getControllerName() != 'install' && $fc->getRequest(
138137
)->getControllerName() != 'error'
139138
) {
140-
if ($this->isUpgradeNeeded()) {
141-
$this->view->needUpgrade = true;
142-
}
143139
$errorlogModel = MidasLoader::loadModel('Errorlog');
144140
$count = $errorlogModel->countSince(
145141
date('Y-m-d H:i:s', strtotime('-24 hour')),
@@ -311,14 +307,14 @@ public function preDispatch()
311307
) {
312308
$this->_helper->layout->setLayout($layoutParam);
313309
} else {
314-
$modulesConfig = Zend_Registry::get('configsModules');
315-
foreach ($modulesConfig as $key => $module) {
316-
if (file_exists(BASE_PATH.'/modules/'.$key.'/layouts/layout-core.phtml')) {
317-
$this->_helper->layout->setLayoutPath(BASE_PATH.'/modules/'.$key.'/layouts/');
310+
$enabledModules = Zend_Registry::get('modulesEnable');
311+
foreach ($enabledModules as $enabledModule) {
312+
if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/layouts/layout-core.phtml')) {
313+
$this->_helper->layout->setLayoutPath(BASE_PATH.'/modules/'.$enabledModule.'/layouts/');
318314
$this->_helper->layout->setLayout('layout-core');
319315
}
320-
if (file_exists(BASE_PATH.'/privateModules/'.$key.'/layouts/layout-core.phtml')) {
321-
$this->_helper->layout->setLayoutPath(BASE_PATH.'/privateModules/'.$key.'/layouts/');
316+
if (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/layouts/layout-core.phtml')) {
317+
$this->_helper->layout->setLayoutPath(BASE_PATH.'/privateModules/'.$enabledModule.'/layouts/');
322318
$this->_helper->layout->setLayout('layout-core');
323319
}
324320
}
@@ -490,34 +486,6 @@ public function showNotificationMessage($message)
490486
$this->view->json['triggerNotification'][] = $message;
491487
}
492488

493-
/** check if midas needs to be upgraded */
494-
public function isUpgradeNeeded()
495-
{
496-
require_once BASE_PATH.'/core/controllers/components/UpgradeComponent.php';
497-
$upgradeComponent = new UpgradeComponent();
498-
$db = Zend_Registry::get('dbAdapter');
499-
$dbtype = Zend_Registry::get('configDatabase')->database->adapter;
500-
501-
$upgradeComponent->initUpgrade('core', $db, $dbtype);
502-
if ($upgradeComponent->getNewestVersion() > $upgradeComponent->transformVersionToNumeric(
503-
Zend_Registry::get('configDatabase')->version
504-
)
505-
) {
506-
return true;
507-
}
508-
$modulesConfig = Zend_Registry::get('configsModules');
509-
foreach ($modulesConfig as $key => $module) {
510-
$upgradeComponent->initUpgrade($key, $db, $dbtype);
511-
if ($upgradeComponent->getNewestVersion() != 0 && $upgradeComponent->getNewestVersion(
512-
) > $upgradeComponent->transformVersionToNumeric($module->version)
513-
) {
514-
return true;
515-
}
516-
}
517-
518-
return false;
519-
}
520-
521489
/** zend post dispatch */
522490
public function postDispatch()
523491
{

core/GlobalController.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ public function __construct(
4949
public function preDispatch()
5050
{
5151
UtilityComponent::setTimeLimit(0);
52-
$modulesEnable = Zend_Registry::get('modulesEnable');
52+
$enabledModules = Zend_Registry::get('modulesEnable');
5353

5454
if (Zend_Registry::get('configGlobal')->application->lang != 'en') {
5555
$translate = new Zend_Translate('csv', BASE_PATH.'/core/translation/fr-main.csv', 'en');
5656
Zend_Registry::set('translator', $translate);
5757
$translators = array();
5858

59-
foreach ($modulesEnable as $module) {
60-
if (file_exists(BASE_PATH.'/modules/'.$module.'/translation/fr-main.csv')) {
61-
$translators[$module] = new Zend_Translate(
59+
foreach ($enabledModules as $enabledModule) {
60+
if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv')) {
61+
$translators[$enabledModule] = new Zend_Translate(
6262
'csv',
63-
BASE_PATH.'/modules/'.$module.'/translation/fr-main.csv',
63+
BASE_PATH.'/modules/'.$enabledModule.'/translation/fr-main.csv',
6464
'en'
6565
);
66-
} elseif (file_exists(BASE_PATH.'/privateModules/'.$module.'/translation/fr-main.csv')) {
67-
$translators[$module] = new Zend_Translate(
66+
} elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv')) {
67+
$translators[$enabledModule] = new Zend_Translate(
6868
'csv',
69-
BASE_PATH.'/privateModules/'.$module.'/translation/fr-main.csv',
69+
BASE_PATH.'/privateModules/'.$enabledModule.'/translation/fr-main.csv',
7070
'en'
7171
);
7272
}
@@ -76,16 +76,16 @@ public function preDispatch()
7676
}
7777

7878
$configs = array();
79-
foreach ($modulesEnable as $module) {
80-
if (file_exists(LOCAL_CONFIGS_PATH.'/'.$module.'.local.ini')) {
81-
$configs[$module] = new Zend_Config_Ini(LOCAL_CONFIGS_PATH.'/'.$module.'.local.ini', 'global');
82-
} elseif (file_exists(BASE_PATH.'/privateModules/'.$module.'/configs/module.ini')) {
83-
$configs[$module] = new Zend_Config_Ini(
84-
BASE_PATH.'/privateModules/'.$module.'/configs/module.ini', 'global'
79+
foreach ($enabledModules as $enabledModule) {
80+
if (file_exists(LOCAL_CONFIGS_PATH.'/'.$enabledModule.'.local.ini')) {
81+
$configs[$enabledModule] = new Zend_Config_Ini(LOCAL_CONFIGS_PATH.'/'.$enabledModule.'.local.ini', 'global');
82+
} elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/configs/module.ini')) {
83+
$configs[$enabledModule] = new Zend_Config_Ini(
84+
BASE_PATH.'/privateModules/'.$enabledModule.'/configs/module.ini', 'global'
8585
);
8686
} else {
87-
$configs[$module] = new Zend_Config_Ini(
88-
BASE_PATH.'/modules/'.$module.'/configs/module.ini',
87+
$configs[$enabledModule] = new Zend_Config_Ini(
88+
BASE_PATH.'/modules/'.$enabledModule.'/configs/module.ini',
8989
'global'
9090
);
9191
}

core/controllers/AdminController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function indexAction()
204204
$this->view->assetstoreForm = $this->Form->Assetstore->createAssetstoreForm();
205205

206206
// get modules
207-
$modulesEnable = Zend_Registry::get('modulesEnable');
207+
$enabledModules = Zend_Registry::get('modulesEnable');
208208
$adapter = Zend_Registry::get('configDatabase')->database->adapter;
209209
foreach ($allModules as $key => $module) {
210210
if (file_exists(BASE_PATH."/modules/".$key."/controllers/ConfigController.php")) {
@@ -265,7 +265,7 @@ public function indexAction()
265265
ksort($modulesList);
266266
$this->view->countModules = $countModules;
267267
$this->view->modulesList = $modulesList;
268-
$this->view->modulesEnable = $modulesEnable;
268+
$this->view->modulesEnable = $enabledModules;
269269
$this->view->databaseType = Zend_Registry::get('configDatabase')->database->adapter;
270270
}
271271

@@ -352,10 +352,10 @@ public function showlogAction()
352352
return;
353353
}
354354

355-
$modulesConfig = Zend_Registry::get('configsModules');
355+
$enabledModules = Zend_Registry::get('modulesEnable');
356356
$modules = array('all', 'core');
357-
foreach ($modulesConfig as $key => $module) {
358-
$modules[] = $key;
357+
foreach ($enabledModules as $enabledModule) {
358+
$modules[] = $enabledModule;
359359
}
360360
$this->view->modulesLog = $modules;
361361
}

core/controllers/components/ApidocsComponent.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public function getEnabledResources()
3737
}
3838

3939
$modulesHaveApi = Zend_Registry::get('modulesHaveApi');
40-
$modulesEnabled = Zend_Registry::get('modulesEnable');
41-
$apiModules = array_intersect($modulesHaveApi, $modulesEnabled);
42-
foreach ($apiModules as $module) {
43-
foreach (glob(BASE_PATH.'/modules/'.$module.'/controllers/components/Api*.php') as $filename) {
44-
$resoucename = preg_replace('/Component\.php/', '', substr(basename($filename), 3));
45-
if (!in_array($resoucename, array(''))) {
46-
$apiResources[] = $module.'/'.$resoucename;
40+
$enabledModules = Zend_Registry::get('modulesEnable');
41+
$apiModules = array_intersect($modulesHaveApi, $enabledModules);
42+
foreach ($apiModules as $apiModule) {
43+
foreach (glob(BASE_PATH.'/modules/'.$apiModule.'/controllers/components/Api*.php') as $filename) {
44+
$resourceName = preg_replace('/Component\.php/', '', substr(basename($filename), 3));
45+
if (!in_array($resourceName, array(''))) {
46+
$apiResources[] = $apiModule.'/'.$resourceName;
4747
}
4848
}
4949
}

core/controllers/components/ApisystemComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function version($args)
4242
*/
4343
public function modulesList($args)
4444
{
45-
return array('modules' => array_keys(Zend_Registry::get('configsModules')));
45+
return array('modules' => Zend_Registry::get('modulesEnable'));
4646
}
4747

4848
/**

core/layouts/layout.phtml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,6 @@ echo $this->doctype().PHP_EOL;
253253
</div>
254254
<div class="Wrapper">
255255
<?php
256-
if ($this->needUpgrade) {
257-
echo '<span style="color:red;">Midas Platform needs to be upgraded. <a href="'.$this->webroot.'/admin/#ui-tabs-2">Upgrade</a></span><br/><br/>';
258-
}
259256
if ($this->highNumberError) {
260257
echo '<span style="color:red;">More than 5 errors have occured in the last 24 hours. <a href="'.$this->webroot.'/admin/#ui-tabs-4">Check the logs</a></span><br/><br/>';
261258
}

0 commit comments

Comments
 (0)