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

Commit

Permalink
Move core and module version information to database
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Sep 14, 2015
1 parent d00713f commit c3cc34f
Show file tree
Hide file tree
Showing 31 changed files with 1,959 additions and 389 deletions.
14 changes: 9 additions & 5 deletions core/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ public function preDispatch()
$this->view->metaDescription = Zend_Registry::get('configGlobal')->application->description;

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

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

/** @var ModuleModel */
public $Module;

/** @var NewUserInvitationModel */
public $NewUserInvitation;

Expand Down
182 changes: 78 additions & 104 deletions core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected function _initConfig()
/** Display the debug toolbar, if enabled. */
protected function _initZFDebug()
{
$this->bootstrap('config');
$this->bootstrap(array('Config', 'FrontController'));
$zfDebugPath = BASE_PATH.'/vendor/jokkedk/zfdebug/library';

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

$debug = new ZFDebug_Controller_Plugin_Debug($options);

$this->bootstrap('frontController');
$frontController = $this->getResource('frontController');
$frontController = $this->getResource('FrontController');
$frontController->registerPlugin($debug);

return $debug;
}

return false;
}

/** Register the module directories. */
protected function _initFrontModules()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$front->addModuleDirectory(BASE_PATH.'/modules');
$this->bootstrap('FrontController');
$frontController = $this->getResource('FrontController');
$frontController->addModuleDirectory(BASE_PATH.'/modules');

if (file_exists(BASE_PATH.'/privateModules')) {
$front->addModuleDirectory(BASE_PATH.'/privateModules');
$frontController->addModuleDirectory(BASE_PATH.'/privateModules');
}
}

Expand Down Expand Up @@ -272,132 +275,103 @@ protected function _initSass()
* Initialize the router.
*
* @return Zend_Controller_Router_Interface
* @throws Zend_Exception
*/
protected function _initRouter()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$this->bootstrap(array('Config', 'FrontController'));

// Init Modules
$frontController = Zend_Controller_Front::getInstance();
$frontController = $this->getResource('FrontController');
$frontController->addControllerDirectory(BASE_PATH.'/core/controllers');

$modules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
// routes modules
$listeModule = array();
$apiModules = array();
foreach ($modules as $key => $module) {
if ($module == 1 && file_exists(BASE_PATH.'/modules/'.$key) && file_exists(
BASE_PATH.'/modules/'.$key.'/AppController.php'
)
) {
$listeModule[] = $key;
// get web API controller directories and web API module names for enabled modules
if (file_exists(BASE_PATH.'/modules/'.$key.'/controllers/api')) {
$frontController->addControllerDirectory(
BASE_PATH.'/modules/'.$key.'/controllers/api',
'api'.$key
);
$apiModules[] = $key;
}
} elseif ($module == 1 && file_exists(BASE_PATH.'/privateModules/'.$key) && file_exists(
BASE_PATH.'/privateModules/'.$key.'/AppController.php'
)
) {
$listeModule[] = $key;
// get web API controller directories and web API module names for enabled modules
if (file_exists(BASE_PATH.'/privateModules/'.$key.'/controllers/api')) {
$frontController->addControllerDirectory(
BASE_PATH.'/privateModules/'.$key.'/controllers/api',
'api'.$key
);
$apiModules[] = $key;
}
}
}

// get web API controller directory for core APIs
require_once BASE_PATH.'/core/ApiController.php';
$frontController->addControllerDirectory(BASE_PATH.'/core/controllers/api', 'rest');
// add RESTful route for web APIs
$restRoute = new Zend_Rest_Route($frontController, array(), array('rest'));
$router->addRoute('api-core', $restRoute);
// loading modules elements
foreach ($listeModule as $m) {
$route = $m;
$nameModule = $m;
$router->addRoute(
$nameModule.'-1',
new Zend_Controller_Router_Route(
''.$route.'/:controller/:action/*', array('module' => $nameModule)
)
);
$router->addRoute(
$nameModule.'-2',
new Zend_Controller_Router_Route(
''.$route.'/:controller/',
array('module' => $nameModule, 'action' => 'index')
)
);
$router->addRoute(
$nameModule.'-3',
new Zend_Controller_Router_Route(
''.$route.'/',
array('module' => $nameModule, 'controller' => 'index', 'action' => 'index')
)
);

if (file_exists(BASE_PATH.'/modules/'.$route.'/AppController.php')) {
require_once BASE_PATH.'/modules/'.$route.'/AppController.php';
}
if (file_exists(BASE_PATH.'/modules/'.$route.'/models/AppDao.php')) {
require_once BASE_PATH.'/modules/'.$route.'/models/AppDao.php';
}
if (file_exists(BASE_PATH.'/modules/'.$route.'/models/AppModel.php')) {
require_once BASE_PATH.'/modules/'.$route.'/models/AppModel.php';
$router = $frontController->getRouter();
$router->addRoute('api-core', new Zend_Rest_Route($frontController, array(), array('rest')));

$enabledModules = array();

if (isset(Zend_Registry::get('configDatabase')->version) === false) {
Zend_Registry::set('models', array());

/** @var ModuleModel $moduleModel */
$moduleModel = MidasLoader::loadModel('Module');
$moduleDaos = $moduleModel->getEnabled();

/** @var ModuleDao $moduleDao */
foreach ($moduleDaos as $moduleDao) {
$enabledModules[] = $moduleDao->getName();
}
if (file_exists(BASE_PATH.'/modules/'.$route.'/constant/module.php')) {
require_once BASE_PATH.'/modules/'.$route.'/constant/module.php';
} else {
$modules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
$enabledModules = array_keys($modules->toArray(), 1);
}

$enabledApiModules = array();

/** @var string $enabledModule */
foreach ($enabledModules as $enabledModule) {
if (file_exists(BASE_PATH.'/modules/'.$enabledModule.'/AppController.php')) {
$moduleRoot = BASE_PATH.'/modules/'.$enabledModule;
} elseif (file_exists(BASE_PATH.'/privateModules/'.$enabledModule.'/AppController.php')) {
$moduleRoot = BASE_PATH.'/privateModules/'.$enabledModule;
} else {
throw new Zend_Exception('Module '.$enabledModule.'" does not exist.');
}

if (file_exists(BASE_PATH.'/privateModules/'.$route.'/AppController.php')) {
require_once BASE_PATH.'/privateModules/'.$route.'/AppController.php';
$frontController->addControllerDirectory($moduleRoot.'/controllers', $enabledModule);

if (file_exists($moduleRoot.'/constant/module.php')) {
require_once $moduleRoot.'/constant/module.php';
}
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/models/AppDao.php')) {
require_once BASE_PATH.'/privateModules/'.$route.'/models/AppDao.php';

if (file_exists($moduleRoot.'/AppController.php')) {
require_once $moduleRoot.'/AppController.php';
}
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/models/AppModel.php')) {
require_once BASE_PATH.'/privateModules/'.$route.'/models/AppModel.php';

if (file_exists($moduleRoot.'/models/AppDao.php')) {
require_once $moduleRoot.'/models/AppDao.php';
}
if (file_exists(BASE_PATH.'/privateModules/'.$route.'/constant/module.php')) {
require_once BASE_PATH.'/privateModules/'.$route.'/constant/module.php';

if (file_exists($moduleRoot.'/models/AppModel.php')) {
require_once $moduleRoot.'/models/AppModel.php';
}

$dir = BASE_PATH.'/modules/'.$route.'/models/base';
if (!is_dir($dir)) {
$dir = BASE_PATH.'/privateModules/'.$route.'/models/base';
if (file_exists($moduleRoot.'/controllers/api')) {
$frontController->addControllerDirectory($moduleRoot.'/controllers/api', 'api'.$enabledModule);
$enabledApiModules[] = $enabledModule;
}

if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != '.' && $object != '..') {
if (filetype($dir.'/'.$object) != 'dir') {
require_once $dir.'/'.$object;
}
$router->addRoute($enabledModule.'-1', new Zend_Controller_Router_Route($enabledModule.'/:controller/:action/*', array('module' => $enabledModule)));
$router->addRoute($enabledModule.'-2', new Zend_Controller_Router_Route($enabledModule.'/:controller/', array('module' => $enabledModule, 'action' => 'index')));
$router->addRoute($enabledModule.'-3', new Zend_Controller_Router_Route($enabledModule.'/', array('module' => $enabledModule, 'controller' => 'index', 'action' => 'index')));

$baseModels = $moduleRoot.'/models/base';

if (is_dir($baseModels)) {
$fileNames = array_diff(scandir($baseModels), array('..', '.'));

/** @var string $fileName */
foreach ($fileNames as $fileName) {
if (filetype($baseModels.'/'.$fileName) != 'dir') {
require_once $baseModels.'/'.$fileName;
}
}
}
}
Zend_Registry::set('modulesEnable', $listeModule);
Zend_Registry::set('modulesHaveApi', $apiModules);

Zend_Registry::set('modulesEnable', $enabledModules);
Zend_Registry::set('modulesHaveApi', $enabledApiModules);

return $router;
}

/** Register the plugins and helpers for the REST controllers. */
protected function _initREST()
{
$frontController = Zend_Controller_Front::getInstance();
$this->bootstrap('FrontController');
$frontController = $this->getResource('FrontController');

// register the RestHandler plugin
$frontController->registerPlugin(new REST_Controller_Plugin_RestHandler($frontController));
Expand Down
2 changes: 0 additions & 2 deletions core/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ cookie_secure = "0"
; show debug toolbar
debug_toolbar = "0"

[module]

[production]

[development]
Expand Down
1 change: 1 addition & 0 deletions core/configs/core.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ rest.formats[] = "json"
rest.formats[] = "html"
rest.formats[] = "php"
uuid = "67a81613-074d-4c9a-afb7-4613f3144a3d"
version = "3.4.1"

[testing]
3 changes: 0 additions & 3 deletions core/configs/database.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
version = ""

[development]
database.adapter = "PDO_MYSQL"
Expand All @@ -18,7 +17,6 @@ database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
version = ""

[testing]
database.adapter = "PDO_MYSQL"
Expand All @@ -28,4 +26,3 @@ database.params.unix_socket = ""
database.params.dbname = "midas_test"
database.params.username = "root"
database.params.password = ""
version = ""
Loading

0 comments on commit c3cc34f

Please sign in to comment.