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

Commit f2ff2de

Browse files
author
Charles Ma
committed
ENH: refs #301 Added remoteprocessing module. Added private module directory
1 parent 2f6c89c commit f2ff2de

File tree

28 files changed

+531
-69
lines changed

28 files changed

+531
-69
lines changed

core/Bootstrap.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ protected function _initConfig()
177177
return $config;
178178
}
179179

180+
/** set up front */
181+
protected function _initFrontModules()
182+
{
183+
$this->bootstrap('frontController');
184+
$front = $this->getResource('frontController');
185+
$front->addModuleDirectory(BASE_PATH.'/modules');
186+
$front->addModuleDirectory(BASE_PATH.'/privateModules');
187+
}
180188

181189
/** init routes*/
182190
protected function _initRouter()
@@ -196,6 +204,10 @@ protected function _initRouter()
196204
{
197205
$listeModule[] = $key;
198206
}
207+
elseif($module == 1 && file_exists(BASE_PATH.'/privateModules/'.$key) && file_exists(BASE_PATH . "/privateModules/".$key."/AppController.php"))
208+
{
209+
$listeModule[] = $key;
210+
}
199211
}
200212

201213
// loading modules elements
@@ -218,7 +230,7 @@ protected function _initRouter()
218230
'module' => $nameModule,
219231
'controller' => 'index',
220232
'action' => 'index')));
221-
$frontController->addControllerDirectory(BASE_PATH . "/modules/".$route."/controllers", $nameModule);
233+
222234
if(file_exists(BASE_PATH . "/modules/".$route."/AppController.php"))
223235
{
224236
require_once BASE_PATH . "/modules/".$route."/AppController.php";
@@ -236,7 +248,29 @@ protected function _initRouter()
236248
require_once BASE_PATH . "/modules/".$route."/constant/module.php";
237249
}
238250

251+
if(file_exists(BASE_PATH . "/privateModules/".$route."/AppController.php"))
252+
{
253+
require_once BASE_PATH . "/privateModules/".$route."/AppController.php";
254+
}
255+
if(file_exists(BASE_PATH . "/privateModules/".$route."/models/AppDao.php"))
256+
{
257+
require_once BASE_PATH . "/privateModules/".$route."/models/AppDao.php";
258+
}
259+
if(file_exists(BASE_PATH . "/privateModules/".$route."/models/AppModel.php"))
260+
{
261+
require_once BASE_PATH . "/privateModules/".$route."/models/AppModel.php";
262+
}
263+
if(file_exists(BASE_PATH . "/privateModules/".$route."/constant/module.php"))
264+
{
265+
require_once BASE_PATH . "/privateModules/".$route."/constant/module.php";
266+
}
267+
239268
$dir = BASE_PATH . "/modules/".$route."/models/base";
269+
if(!is_dir($dir))
270+
{
271+
$dir = BASE_PATH . "/privateModules/".$route."/models/base";
272+
}
273+
240274
if(is_dir($dir))
241275
{
242276
$objects = scandir($dir);

core/ComponentLoader.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@ public function loadComponent($component, $module = '')
5151
}
5252
else
5353
{
54-
include_once BASE_PATH.'/modules/'.$module.'/controllers/components/'.$component.'Component.php';
54+
if(file_exists(BASE_PATH.'/modules/'.$module.'/controllers/components/'.$component.'Component.php'))
55+
{
56+
include_once BASE_PATH.'/modules/'.$module.'/controllers/components/'.$component.'Component.php';
57+
}
58+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/controllers/components/'.$component.'Component.php'))
59+
{
60+
include_once BASE_PATH.'/privateModules/'.$module.'/controllers/components/'.$component.'Component.php';
61+
}
62+
else
63+
{
64+
throw new Zend_Exception("Component file doesn't exit");
65+
}
5566
$name = ucfirst($module).'_'.$component.'Component';
5667
}
5768
if(class_exists($name))

core/GlobalController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,28 @@ public function preDispatch()
4848
$modulesEnable = Zend_Registry::get('modulesEnable');
4949
foreach($modulesEnable as $module)
5050
{
51-
$translaters[$module] = new Zend_Translate('csv', BASE_PATH."/modules/".$module."/translation/fr-main.csv", "en");
51+
if(file_exists(BASE_PATH."/modules/".$module."/translation/fr-main.csv"))
52+
{
53+
$translationFile = BASE_PATH."/modules/".$module."/translation/fr-main.csv";
54+
}
55+
elseif(file_exists(BASE_PATH."/privateModules/".$module."/translation/fr-main.csv"))
56+
{
57+
$translationFile = BASE_PATH."/privateModules/".$module."/translation/fr-main.csv";
58+
}
59+
else
60+
{
61+
throw new Zend_Exception('No translation file found in module '.$module);
62+
}
63+
64+
$translaters[$module] = new Zend_Translate('csv', $translationFile, "en");
5265
if(file_exists(BASE_PATH."/core/configs/".$module.".local.ini"))
5366
{
5467
$configs[$module] = new Zend_Config_Ini(BASE_PATH."/core/configs/".$module.".local.ini", 'global');
5568
}
69+
elseif(file_exists(BASE_PATH."/privateModules/".$module."/configs/module.ini"))
70+
{
71+
$configs[$module] = new Zend_Config_Ini(BASE_PATH."/privateModules/".$module."/configs/module.ini", 'global');
72+
}
5673
else
5774
{
5875
$configs[$module] = new Zend_Config_Ini(BASE_PATH."/modules/".$module."/configs/module.ini", 'global');
@@ -78,6 +95,16 @@ public function preDispatch()
7895
$this->_forward($request->getActionName(), $request->getControllerName().'Core', $key, array('forwardModule' => true));
7996
}
8097
}
98+
elseif(file_exists(BASE_PATH.'/privateModules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php'))
99+
{
100+
include_once BASE_PATH.'/privateModules/'.$key.'/controllers/'. ucfirst($request->getControllerName()).'CoreController.php';
101+
$name = ucfirst($key).'_'.ucfirst($request->getControllerName()).'CoreController';
102+
$controller = new $name($request, $response);
103+
if(method_exists($controller, $request->getActionName().'Action'))
104+
{
105+
$this->_forward($request->getActionName(), $request->getControllerName().'Core', $key, array('forwardModule' => true));
106+
}
107+
}
81108
}
82109
}
83110
parent::preDispatch();

core/controllers/AdminController.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,22 @@ function indexAction()
140140

141141
$moduleConfigLocalFile = BASE_PATH."/core/configs/".$moduleName.".local.ini";
142142
$moduleConfigFile = BASE_PATH."/modules/".$moduleName."/configs/module.ini";
143-
if(!file_exists($moduleConfigLocalFile))
143+
$moduleConfigPrivateFile = BASE_PATH."/privateModules/".$moduleName."/configs/module.ini";
144+
if(!file_exists($moduleConfigLocalFile) && file_exists($moduleConfigFile))
144145
{
145146
copy($moduleConfigFile, $moduleConfigLocalFile);
146147
$this->Component->Utility->installModule($moduleName);
147148
}
149+
elseif(!file_exists($moduleConfigLocalFile) && file_exists($moduleConfigPrivateFile))
150+
{
151+
copy($moduleConfigPrivateFile, $moduleConfigLocalFile);
152+
$this->Component->Utility->installModule($moduleName);
153+
}
154+
elseif(!file_exists($moduleConfigLocalFile))
155+
{
156+
throw new Zend_Exception("Unable to find config file");
157+
}
158+
148159
rename(BASE_PATH.'/core/configs/application.local.ini', BASE_PATH.'/core/configs/application.local.ini.old');
149160
$applicationConfig['module'][$moduleName] = $modulevalue;
150161
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
@@ -205,6 +216,10 @@ function indexAction()
205216
{
206217
$allModules[$key]->configPage = true;
207218
}
219+
elseif(file_exists(BASE_PATH."/privateModules/".$key."/controllers/ConfigController.php"))
220+
{
221+
$allModules[$key]->configPage = true;
222+
}
208223
else
209224
{
210225
$allModules[$key]->configPage = false;

core/controllers/components/UpgradeComponent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function initUpgrade($module, $db, $dbtype)
2828
{
2929
$this->dir = BASE_PATH.'/core/database/upgrade';
3030
}
31+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/database/upgrade'))
32+
{
33+
$this->dir = BASE_PATH.'/privateModules/'.$module.'/database/upgrade';
34+
}
3135
else
3236
{
3337
$this->dir = BASE_PATH.'/modules/'.$module.'/database/upgrade';

core/controllers/components/UtilityComponent.php

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,71 @@
1414
class UtilityComponent extends AppComponent
1515
{
1616
/** Get all the modules */
17-
static public function getAllModules()
17+
public function getAllModules()
1818
{
1919
$modules = array();
2020
if(file_exists(BASE_PATH.'/modules/') && opendir(BASE_PATH.'/modules/'))
2121
{
22-
$handle = opendir(BASE_PATH.'/modules/');
23-
while(false !== ($file = readdir($handle)))
22+
$array = $this->initModulesConfig(BASE_PATH.'/modules/');
23+
$modules = array_merge($modules, $array);
24+
}
25+
26+
if(file_exists(BASE_PATH.'/privateModules/') && opendir(BASE_PATH.'/privateModules/'))
27+
{
28+
$array = $this->initModulesConfig(BASE_PATH.'/privateModules/');
29+
$modules = array_merge($modules, $array);
30+
}
31+
32+
return $modules;
33+
}
34+
35+
/** find modules configuration in a folder */
36+
private function initModulesConfig($dir)
37+
{
38+
$handle = opendir($dir);
39+
while(false !== ($file = readdir($handle)))
40+
{
41+
if(file_exists($dir.$file.'/configs/module.ini'))
2442
{
25-
if(file_exists(BASE_PATH.'/modules/'.$file.'/configs/module.ini'))
43+
$config = new Zend_Config_Ini($dir.$file.'/configs/module.ini', 'global', true);
44+
$config->db = array();
45+
if(!file_exists($dir.$file.'/database'))
2646
{
27-
$config = new Zend_Config_Ini(BASE_PATH.'/modules/'.$file.'/configs/module.ini', 'global', true);
28-
$config->db = array();
29-
if(!file_exists(BASE_PATH.'/modules/'.$file.'/database'))
30-
{
31-
$config->db->PDO_MYSQL = true;
32-
$config->db->PDO_IBM = true;
33-
$config->db->PDO_OCI = true;
34-
$config->db->PDO_SQLITE = true;
35-
$config->db->CASSANDRA = true;
36-
$config->db->MONGO = true;
37-
}
38-
else
47+
$config->db->PDO_MYSQL = true;
48+
$config->db->PDO_IBM = true;
49+
$config->db->PDO_OCI = true;
50+
$config->db->PDO_SQLITE = true;
51+
$config->db->CASSANDRA = true;
52+
$config->db->MONGO = true;
53+
}
54+
else
55+
{
56+
$handleDB = opendir($dir.$file.'/database');
57+
if(file_exists($dir.$file.'/database'))
3958
{
40-
$handleDB = opendir(BASE_PATH.'/modules/'.$file.'/database');
41-
if(file_exists(BASE_PATH.'/modules/'.$file.'/database'))
59+
while(false !== ($fileDB = readdir($handleDB)))
4260
{
43-
while(false !== ($fileDB = readdir($handleDB)))
61+
if(file_exists($dir.$file.'/database/'.$fileDB.'/'))
4462
{
45-
if(file_exists(BASE_PATH.'/modules/'.$file.'/database/'.$fileDB.'/'))
63+
switch($fileDB)
4664
{
47-
switch($fileDB)
48-
{
49-
case 'mysql' : $config->db->PDO_MYSQL = true; break;
50-
case 'pgsql' : $config->db->PDO_PGSQL = true;break;
51-
case 'ibm' : $config->db->PDO_IBM = true;break;
52-
case 'oci' : $config->db->PDO_OCI = true;break;
53-
case 'sqlite' : $config->db->PDO_SQLITE = true;break;
54-
case 'cassandra' : $config->db->CASSANDRA = true;break;
55-
case 'mongo' : $config->db->MONGO = true;break;
56-
default : break;
57-
}
65+
case 'mysql' : $config->db->PDO_MYSQL = true; break;
66+
case 'pgsql' : $config->db->PDO_PGSQL = true;break;
67+
case 'ibm' : $config->db->PDO_IBM = true;break;
68+
case 'oci' : $config->db->PDO_OCI = true;break;
69+
case 'sqlite' : $config->db->PDO_SQLITE = true;break;
70+
case 'cassandra' : $config->db->CASSANDRA = true;break;
71+
case 'mongo' : $config->db->MONGO = true;break;
72+
default : break;
5873
}
5974
}
6075
}
6176
}
62-
$modules[$file] = $config;
6377
}
78+
$modules[$file] = $config;
6479
}
65-
closedir($handle);
6680
}
67-
81+
closedir($handle);
6882
return $modules;
6983
}
7084

core/models/MIDASModel.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,18 @@ public function initDao($name, $data, $module = null)
152152
}
153153
else
154154
{
155-
require_once BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. 'Dao.php';
155+
if(file_exists(BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. 'Dao.php'))
156+
{
157+
require_once BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. 'Dao.php';
158+
}
159+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. 'Dao.php'))
160+
{
161+
require_once BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. 'Dao.php';
162+
}
163+
else
164+
{
165+
throw new Zend_Exception("Unable to find dao file ".$name);
166+
}
156167
$name = ucfirst($module).'_'.$name. 'Dao';
157168
}
158169
if(class_exists($name))
@@ -260,7 +271,27 @@ public function loadDaoClass($name, $module = 'core')
260271
}
261272
else
262273
{
263-
require_once BASE_PATH . "/modules/".$module."/models/dao/".$name.".php";
274+
if(file_exists(BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. 'Dao.php'))
275+
{
276+
require_once BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. 'Dao.php';
277+
}
278+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. 'Dao.php'))
279+
{
280+
require_once BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. 'Dao.php';
281+
}
282+
if(file_exists(BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. '.php'))
283+
{
284+
require_once BASE_PATH.'/modules/'.$module.'/models/dao/'.$name. '.php';
285+
}
286+
elseif(file_exists(BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. '.php'))
287+
{
288+
require_once BASE_PATH.'/privateModules/'.$module.'/models/dao/'.$name. '.php';
289+
}
290+
else
291+
{
292+
throw new Zend_Exception("Unable to find dao file ".$name);
293+
}
294+
264295
if(!class_exists(ucfirst($module).'_'.$name))
265296
{
266297
throw new Zend_Exception('Unable to load dao class ' . ucfirst($module).'_'.$name);
@@ -286,7 +317,12 @@ public function load($key = null)
286317
$name = ucfirst($this->_name) . 'Dao';
287318
}
288319

289-
if(isset($this->moduleName))
320+
if(isset($this->_daoName) && isset($this->moduleName))
321+
{
322+
$this->loadDaoClass($name, $this->moduleName);
323+
$name = ucfirst($this->moduleName).'_'.$name;
324+
}
325+
elseif(isset($this->moduleName))
290326
{
291327
$this->loadDaoClass(ucfirst(substr($name, strpos($name, '_') + 1)), $this->moduleName);
292328
}

0 commit comments

Comments
 (0)