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

Commit c3cc34f

Browse files
author
Jamie Snape
committed
Move core and module version information to database
1 parent d00713f commit c3cc34f

31 files changed

+1959
-389
lines changed

core/AppController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ public function preDispatch()
6767
$this->view->metaDescription = Zend_Registry::get('configGlobal')->application->description;
6868

6969
// Set the version
70-
$this->view->version = '3.2.8';
71-
if (isset(Zend_Registry::get('configDatabase')->version)) {
72-
$this->view->version = Zend_Registry::get('configDatabase')->version;
73-
}
70+
$version = UtilityComponent::getCurrentModuleVersion('core');
71+
$this->view->version = $version !== false ? $version : '3.4.x';
7472

7573
require_once BASE_PATH.'/core/models/dao/UserDao.php';
7674
require_once BASE_PATH.'/core/models/dao/ItemDao.php';
@@ -127,7 +125,10 @@ public function preDispatch()
127125
if ($userDao != false) {
128126
// authenticate valid users in the appropriate method for the
129127
// current application version
130-
if (version_compare(Zend_Registry::get('configDatabase')->version, '3.2.12', '>=')) {
128+
if ($version === false) {
129+
throw new Zend_Exception('Core version is undefined.');
130+
}
131+
if (version_compare($version, '3.2.12', '>=')) {
131132
$auth = $userModel->hashExists($tmp[1]);
132133
} else {
133134
$auth = $userModel->legacyAuthenticate($userDao, '', '', $tmp[1]);
@@ -604,6 +605,9 @@ protected function t($text)
604605
/** @var MetadataModel */
605606
public $Metadata;
606607

608+
/** @var ModuleModel */
609+
public $Module;
610+
607611
/** @var NewUserInvitationModel */
608612
public $NewUserInvitation;
609613

core/Bootstrap.php

Lines changed: 78 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected function _initConfig()
180180
/** Display the debug toolbar, if enabled. */
181181
protected function _initZFDebug()
182182
{
183-
$this->bootstrap('config');
183+
$this->bootstrap(array('Config', 'FrontController'));
184184
$zfDebugPath = BASE_PATH.'/vendor/jokkedk/zfdebug/library';
185185

186186
if (Zend_Registry::get('configGlobal')->debug_toolbar === '1' && file_exists($zfDebugPath)) {
@@ -196,21 +196,24 @@ protected function _initZFDebug()
196196
);
197197

198198
$debug = new ZFDebug_Controller_Plugin_Debug($options);
199-
200-
$this->bootstrap('frontController');
201-
$frontController = $this->getResource('frontController');
199+
$frontController = $this->getResource('FrontController');
202200
$frontController->registerPlugin($debug);
201+
202+
return $debug;
203203
}
204+
205+
return false;
204206
}
205207

206208
/** Register the module directories. */
207209
protected function _initFrontModules()
208210
{
209-
$this->bootstrap('frontController');
210-
$front = $this->getResource('frontController');
211-
$front->addModuleDirectory(BASE_PATH.'/modules');
211+
$this->bootstrap('FrontController');
212+
$frontController = $this->getResource('FrontController');
213+
$frontController->addModuleDirectory(BASE_PATH.'/modules');
214+
212215
if (file_exists(BASE_PATH.'/privateModules')) {
213-
$front->addModuleDirectory(BASE_PATH.'/privateModules');
216+
$frontController->addModuleDirectory(BASE_PATH.'/privateModules');
214217
}
215218
}
216219

@@ -272,132 +275,103 @@ protected function _initSass()
272275
* Initialize the router.
273276
*
274277
* @return Zend_Controller_Router_Interface
278+
* @throws Zend_Exception
275279
*/
276280
protected function _initRouter()
277281
{
278-
$router = Zend_Controller_Front::getInstance()->getRouter();
282+
$this->bootstrap(array('Config', 'FrontController'));
279283

280-
// Init Modules
281-
$frontController = Zend_Controller_Front::getInstance();
284+
$frontController = $this->getResource('FrontController');
282285
$frontController->addControllerDirectory(BASE_PATH.'/core/controllers');
283286

284-
$modules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
285-
// routes modules
286-
$listeModule = array();
287-
$apiModules = array();
288-
foreach ($modules as $key => $module) {
289-
if ($module == 1 && file_exists(BASE_PATH.'/modules/'.$key) && file_exists(
290-
BASE_PATH.'/modules/'.$key.'/AppController.php'
291-
)
292-
) {
293-
$listeModule[] = $key;
294-
// get web API controller directories and web API module names for enabled modules
295-
if (file_exists(BASE_PATH.'/modules/'.$key.'/controllers/api')) {
296-
$frontController->addControllerDirectory(
297-
BASE_PATH.'/modules/'.$key.'/controllers/api',
298-
'api'.$key
299-
);
300-
$apiModules[] = $key;
301-
}
302-
} elseif ($module == 1 && file_exists(BASE_PATH.'/privateModules/'.$key) && file_exists(
303-
BASE_PATH.'/privateModules/'.$key.'/AppController.php'
304-
)
305-
) {
306-
$listeModule[] = $key;
307-
// get web API controller directories and web API module names for enabled modules
308-
if (file_exists(BASE_PATH.'/privateModules/'.$key.'/controllers/api')) {
309-
$frontController->addControllerDirectory(
310-
BASE_PATH.'/privateModules/'.$key.'/controllers/api',
311-
'api'.$key
312-
);
313-
$apiModules[] = $key;
314-
}
315-
}
316-
}
317-
318-
// get web API controller directory for core APIs
319287
require_once BASE_PATH.'/core/ApiController.php';
320288
$frontController->addControllerDirectory(BASE_PATH.'/core/controllers/api', 'rest');
321-
// add RESTful route for web APIs
322-
$restRoute = new Zend_Rest_Route($frontController, array(), array('rest'));
323-
$router->addRoute('api-core', $restRoute);
324-
// loading modules elements
325-
foreach ($listeModule as $m) {
326-
$route = $m;
327-
$nameModule = $m;
328-
$router->addRoute(
329-
$nameModule.'-1',
330-
new Zend_Controller_Router_Route(
331-
''.$route.'/:controller/:action/*', array('module' => $nameModule)
332-
)
333-
);
334-
$router->addRoute(
335-
$nameModule.'-2',
336-
new Zend_Controller_Router_Route(
337-
''.$route.'/:controller/',
338-
array('module' => $nameModule, 'action' => 'index')
339-
)
340-
);
341-
$router->addRoute(
342-
$nameModule.'-3',
343-
new Zend_Controller_Router_Route(
344-
''.$route.'/',
345-
array('module' => $nameModule, 'controller' => 'index', 'action' => 'index')
346-
)
347-
);
348289

349-
if (file_exists(BASE_PATH.'/modules/'.$route.'/AppController.php')) {
350-
require_once BASE_PATH.'/modules/'.$route.'/AppController.php';
351-
}
352-
if (file_exists(BASE_PATH.'/modules/'.$route.'/models/AppDao.php')) {
353-
require_once BASE_PATH.'/modules/'.$route.'/models/AppDao.php';
354-
}
355-
if (file_exists(BASE_PATH.'/modules/'.$route.'/models/AppModel.php')) {
356-
require_once BASE_PATH.'/modules/'.$route.'/models/AppModel.php';
290+
$router = $frontController->getRouter();
291+
$router->addRoute('api-core', new Zend_Rest_Route($frontController, array(), array('rest')));
292+
293+
$enabledModules = array();
294+
295+
if (isset(Zend_Registry::get('configDatabase')->version) === false) {
296+
Zend_Registry::set('models', array());
297+
298+
/** @var ModuleModel $moduleModel */
299+
$moduleModel = MidasLoader::loadModel('Module');
300+
$moduleDaos = $moduleModel->getEnabled();
301+
302+
/** @var ModuleDao $moduleDao */
303+
foreach ($moduleDaos as $moduleDao) {
304+
$enabledModules[] = $moduleDao->getName();
357305
}
358-
if (file_exists(BASE_PATH.'/modules/'.$route.'/constant/module.php')) {
359-
require_once BASE_PATH.'/modules/'.$route.'/constant/module.php';
306+
} else {
307+
$modules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
308+
$enabledModules = array_keys($modules->toArray(), 1);
309+
}
310+
311+
$enabledApiModules = array();
312+
313+
/** @var string $enabledModule */
314+
foreach ($enabledModules as $enabledModule) {
315+
if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/AppController.php')) {
316+
$moduleRoot = BASE_PATH.'/modules/'.$enabledModule;
317+
} elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/AppController.php')) {
318+
$moduleRoot = BASE_PATH.'/privateModules/'.$enabledModule;
319+
} else {
320+
throw new Zend_Exception('Module '.$enabledModule.'" does not exist.');
360321
}
361322

362-
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/AppController.php')) {
363-
require_once BASE_PATH.'/privateModules/'.$route.'/AppController.php';
323+
$frontController->addControllerDirectory($moduleRoot.'/controllers', $enabledModule);
324+
325+
if (file_exists($moduleRoot.'/constant/module.php')) {
326+
require_once $moduleRoot.'/constant/module.php';
364327
}
365-
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/models/AppDao.php')) {
366-
require_once BASE_PATH.'/privateModules/'.$route.'/models/AppDao.php';
328+
329+
if (file_exists($moduleRoot.'/AppController.php')) {
330+
require_once $moduleRoot.'/AppController.php';
367331
}
368-
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/models/AppModel.php')) {
369-
require_once BASE_PATH.'/privateModules/'.$route.'/models/AppModel.php';
332+
333+
if (file_exists($moduleRoot.'/models/AppDao.php')) {
334+
require_once $moduleRoot.'/models/AppDao.php';
370335
}
371-
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/constant/module.php')) {
372-
require_once BASE_PATH.'/privateModules/'.$route.'/constant/module.php';
336+
337+
if (file_exists($moduleRoot.'/models/AppModel.php')) {
338+
require_once $moduleRoot.'/models/AppModel.php';
373339
}
374340

375-
$dir = BASE_PATH.'/modules/'.$route.'/models/base';
376-
if (!is_dir($dir)) {
377-
$dir = BASE_PATH.'/privateModules/'.$route.'/models/base';
341+
if (file_exists($moduleRoot.'/controllers/api')) {
342+
$frontController->addControllerDirectory($moduleRoot.'/controllers/api', 'api'.$enabledModule);
343+
$enabledApiModules[] = $enabledModule;
378344
}
379345

380-
if (is_dir($dir)) {
381-
$objects = scandir($dir);
382-
foreach ($objects as $object) {
383-
if ($object != '.' && $object != '..') {
384-
if (filetype($dir.'/'.$object) != 'dir') {
385-
require_once $dir.'/'.$object;
386-
}
346+
$router->addRoute($enabledModule.'-1', new Zend_Controller_Router_Route($enabledModule.'/:controller/:action/*', array('module' => $enabledModule)));
347+
$router->addRoute($enabledModule.'-2', new Zend_Controller_Router_Route($enabledModule.'/:controller/', array('module' => $enabledModule, 'action' => 'index')));
348+
$router->addRoute($enabledModule.'-3', new Zend_Controller_Router_Route($enabledModule.'/', array('module' => $enabledModule, 'controller' => 'index', 'action' => 'index')));
349+
350+
$baseModels = $moduleRoot.'/models/base';
351+
352+
if (is_dir($baseModels)) {
353+
$fileNames = array_diff(scandir($baseModels), array('..', '.'));
354+
355+
/** @var string $fileName */
356+
foreach ($fileNames as $fileName) {
357+
if (filetype($baseModels.'/'.$fileName) != 'dir') {
358+
require_once $baseModels.'/'.$fileName;
387359
}
388360
}
389361
}
390362
}
391-
Zend_Registry::set('modulesEnable', $listeModule);
392-
Zend_Registry::set('modulesHaveApi', $apiModules);
363+
364+
Zend_Registry::set('modulesEnable', $enabledModules);
365+
Zend_Registry::set('modulesHaveApi', $enabledApiModules);
393366

394367
return $router;
395368
}
396369

397370
/** Register the plugins and helpers for the REST controllers. */
398371
protected function _initREST()
399372
{
400-
$frontController = Zend_Controller_Front::getInstance();
373+
$this->bootstrap('FrontController');
374+
$frontController = $this->getResource('FrontController');
401375

402376
// register the RestHandler plugin
403377
$frontController->registerPlugin(new REST_Controller_Plugin_RestHandler($frontController));

core/configs/application.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ cookie_secure = "0"
2828
; show debug toolbar
2929
debug_toolbar = "0"
3030

31-
[module]
32-
3331
[production]
3432

3533
[development]

core/configs/core.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ rest.formats[] = "json"
1515
rest.formats[] = "html"
1616
rest.formats[] = "php"
1717
uuid = "67a81613-074d-4c9a-afb7-4613f3144a3d"
18+
version = "3.4.1"
1819

1920
[testing]

core/configs/database.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ database.params.unix_socket = ""
88
database.params.dbname = "midas"
99
database.params.username = "root"
1010
database.params.password = ""
11-
version = ""
1211

1312
[development]
1413
database.adapter = "PDO_MYSQL"
@@ -18,7 +17,6 @@ database.params.unix_socket = ""
1817
database.params.dbname = "midas"
1918
database.params.username = "root"
2019
database.params.password = ""
21-
version = ""
2220

2321
[testing]
2422
database.adapter = "PDO_MYSQL"
@@ -28,4 +26,3 @@ database.params.unix_socket = ""
2826
database.params.dbname = "midas_test"
2927
database.params.username = "root"
3028
database.params.password = ""
31-
version = ""

0 commit comments

Comments
 (0)