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

Commit ed4b205

Browse files
author
Charles Marion
committed
ENH: Simplify installation
1 parent f0ab6c7 commit ed4b205

File tree

7 files changed

+109
-147
lines changed

7 files changed

+109
-147
lines changed

core/configs/application.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ default.timezone=America/New_York
2727
processing=onthefly
2828

2929
[module]
30-
task=true
3130

3231
[production]
3332
;Activate error reporting using Zend

core/controllers/AdminController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ function indexAction()
3737
$formArray['timezone']->setValue($applicationConfig['global']['default.timezone']);
3838
$this->view->configForm=$formArray;
3939

40+
$allModules=$this->Component->Utility->getAllModules();
41+
4042
if($this->_request->isPost())
4143
{
4244
$this->_helper->layout->disableLayout();
@@ -68,6 +70,32 @@ function indexAction()
6870
{
6971
unlink( BASE_PATH.'/core/configs/application.local.ini.old');
7072
}
73+
74+
$moduleConfigLocalFile=BASE_PATH."/modules/$moduleName/configs/module.local.ini";
75+
$moduleConfigFile=BASE_PATH."/modules/$moduleName/configs/module.ini";
76+
if(!file_exists($moduleConfigLocalFile))
77+
{
78+
copy($moduleConfigFile, $moduleConfigLocalFile);
79+
switch (Zend_Registry::get('configDatabase')->database->adapter)
80+
{
81+
case 'PDO_MYSQL':
82+
$this->Component->Utility->run_mysql_from_file(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$allModules[$moduleName]->version.'.sql',
83+
Zend_Registry::get('configDatabase')->database->params->host,
84+
Zend_Registry::get('configDatabase')->database->params->username,
85+
Zend_Registry::get('configDatabase')->database->params->password,
86+
Zend_Registry::get('configDatabase')->database->params->dbname,
87+
Zend_Registry::get('configDatabase')->database->params->port);
88+
break;
89+
case 'PDO_PGSQL':
90+
$this->Component->Utility->run_pgsql_from_file(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$moduleName]->version.'.sql',
91+
Zend_Registry::get('configDatabase')->database->params->host,
92+
Zend_Registry::get('configDatabase')->database->params->username,
93+
Zend_Registry::get('configDatabase')->database->params->password,
94+
Zend_Registry::get('configDatabase')->database->params->dbname,
95+
Zend_Registry::get('configDatabase')->database->params->port);
96+
break;
97+
}
98+
}
7199
rename(BASE_PATH.'/core/configs/application.local.ini', BASE_PATH.'/core/configs/application.local.ini.old');
72100
$applicationConfig['module'][$moduleName]=$modulevalue;
73101
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
@@ -98,7 +126,6 @@ function indexAction()
98126

99127
// get modules
100128
$modulesEnable= Zend_Registry::get('modulesEnable');
101-
$allModules=$this->Component->Utility->getAllModules();
102129

103130
foreach($allModules as $key=>$module)
104131
{

core/controllers/InstallController.php

Lines changed: 15 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function step2Action()
108108
switch($type)
109109
{
110110
case 'mysql':
111-
$this->run_mysql_from_file($sqlFile,
111+
$this->Component->Utility->run_mysql_from_file($sqlFile,
112112
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
113113
$params= array(
114114
'host' => $form->getValue('host'),
@@ -138,7 +138,7 @@ function step2Action()
138138
Zend_Registry::set('dbAdapter', $db);
139139
break;
140140
case 'pgsql':
141-
$this->run_pgsql_from_file($sqlFile,
141+
$this->Component->Utility->run_pgsql_from_file($sqlFile,
142142
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
143143
$params= array(
144144
'host' => $form->getValue('host'),
@@ -217,66 +217,30 @@ function step3Action()
217217
$formArray['process']->setValue($applicationConfig['global']['processing']);
218218

219219
$assetstrores=$this->Assetstore->getAll();
220-
$formArray['assetstore']->addMultiOptions(array(
221-
$assetstrores[0]->getKey() => $assetstrores[0]->getPath()
222-
));
223-
220+
224221
$this->view->form=$formArray;
225-
$allModules=$this->Component->Utility->getAllModules();
226-
$this->view->modules=$allModules;
227-
$this->view->defaultModules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
228222
$this->view->databaseType =Zend_Registry::get('configDatabase')->database->adapter;
229223
if($this->_request->isPost()&&$form->isValid($this->getRequest()->getPost()))
230224
{
231-
225+
$allModules=$this->Component->Utility->getAllModules();
226+
foreach($allModules as $key=>$module)
227+
{
228+
$configLocal=BASE_PATH."/modules/$key/configs/module.local.ini";
229+
if(file_exists($configLocal))
230+
{
231+
unlink($configLocal);
232+
}
233+
}
232234
$applicationConfig['global']['application.name']=$form->getValue('name');
233235
$applicationConfig['global']['application.lang']=$form->getValue('lang');
234236
$applicationConfig['global']['environment']=$form->getValue('environment');
235-
$applicationConfig['global']['defaultassetstore.id']=$form->getValue('assetstore');
237+
$applicationConfig['global']['defaultassetstore.id']=$assetstrores[0]->getKey();
236238
$applicationConfig['global']['smartoptimizer']=$form->getValue('smartoptimizer');
237239
$applicationConfig['global']['default.timezone']=$form->getValue('timezone');
238240
$applicationConfig['global']['processing']=$form->getValue('process');
239-
$applicationConfig['module']=array();
240-
$modules=$this->getRequest()->getPost();
241-
if(isset($modules['module']))
242-
{
243-
$modules=$modules['module'];
244-
}
245-
else
246-
{
247-
$modules=array();
248-
}
249-
foreach($modules as $key=>$module)
250-
{
251-
$applicationConfig['module'][$key]='true';
252-
switch (Zend_Registry::get('configDatabase')->database->adapter)
253-
{
254-
case 'PDO_MYSQL':
255-
$this->run_mysql_from_file(BASE_PATH.'/modules/'.$key.'/database/mysql/'.$allModules[$key]->version.'.sql',
256-
Zend_Registry::get('configDatabase')->database->params->host,
257-
Zend_Registry::get('configDatabase')->database->params->username,
258-
Zend_Registry::get('configDatabase')->database->params->password,
259-
Zend_Registry::get('configDatabase')->database->params->dbname,
260-
Zend_Registry::get('configDatabase')->database->params->port);
261-
break;
262-
case 'PDO_PGSQL':
263-
$this->run_pgsql_from_file(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$key]->version.'.sql',
264-
Zend_Registry::get('configDatabase')->database->params->host,
265-
Zend_Registry::get('configDatabase')->database->params->username,
266-
Zend_Registry::get('configDatabase')->database->params->password,
267-
Zend_Registry::get('configDatabase')->database->params->dbname,
268-
Zend_Registry::get('configDatabase')->database->params->port);
269-
break;
270-
}
271-
272-
$path=BASE_PATH.'/modules/'.$key.'/configs/module.ini';
273-
$newpath=BASE_PATH.'/modules/'.$key.'/configs/module.local.ini';
274-
$data=parse_ini_file ($path,true);
275-
@unlink($newpath);
276-
$this->Component->Utility->createInitFile($newpath, $data);
277-
}
241+
278242
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini',$applicationConfig);
279-
$this->_redirect("/");
243+
$this->_redirect("/admin");
280244
}
281245
} // end method step2Action
282246

@@ -338,66 +302,6 @@ public function testconnexionAction()
338302

339303

340304

341-
/** Function to run the sql script */
342-
function run_mysql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
343-
{
344-
$db = @mysql_connect("$host:$port", "$username", "$password");
345-
$select=@mysql_select_db($dbname,$db);
346-
if(!$db||!$select)
347-
{
348-
throw new Zend_Exception("Unable to connect.");
349-
}
350-
$requetes="";
351-
352-
$sql=file($sqlfile);
353-
foreach($sql as $l)
354-
{
355-
if (substr(trim($l),0,2)!="--")
356-
{
357-
$requetes .= $l;
358-
}
359-
}
360-
361-
$reqs = explode(";",$requetes);
362-
foreach($reqs as $req)
363-
{ // et on les éxécute
364-
if (!mysql_query($req,$db) && trim($req)!="")
365-
{
366-
throw new Zend_Exception("Unable to execute: ".$req );
367-
}
368-
}
369-
return true;
370-
}
371-
/** Function to run the sql script */
372-
function run_pgsql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
373-
{
374-
$pgdb = @pg_connect("host=$host port=$port dbname=$dbname user=$username password=$password");
375-
$file_content = file($sqlfile);
376-
$query = "";
377-
$linnum = 0;
378-
foreach ($file_content as $sql_line)
379-
{
380-
$tsl = trim($sql_line);
381-
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
382-
{
383-
$query .= $sql_line;
384-
if (preg_match("/;\s*$/", $sql_line))
385-
{
386-
$query = str_replace(";", "", "$query");
387-
$result = pg_query($query);
388-
if (!$result)
389-
{
390-
echo "Error line:".$linnum."<br>";
391-
return pg_last_error();
392-
}
393-
$query = "";
394-
}
395-
}
396-
$linnum++;
397-
} // end for each line
398-
return true;
399-
}
400-
401305
} // end class
402306

403307

core/controllers/components/UtilityComponent.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,68 @@ static public function safedelete($filename)
192192
unlink($filename);
193193
}
194194

195+
196+
197+
198+
/** Function to run the sql script */
199+
static function run_mysql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
200+
{
201+
$db = @mysql_connect("$host:$port", "$username", "$password");
202+
$select=@mysql_select_db($dbname,$db);
203+
if(!$db||!$select)
204+
{
205+
throw new Zend_Exception("Unable to connect.");
206+
}
207+
$requetes="";
208+
209+
$sql=file($sqlfile);
210+
foreach($sql as $l)
211+
{
212+
if (substr(trim($l),0,2)!="--")
213+
{
214+
$requetes .= $l;
215+
}
216+
}
217+
218+
$reqs = explode(";",$requetes);
219+
foreach($reqs as $req)
220+
{ // et on les éxécute
221+
if (!mysql_query($req,$db) && trim($req)!="")
222+
{
223+
throw new Zend_Exception("Unable to execute: ".$req );
224+
}
225+
}
226+
return true;
227+
}
228+
/** Function to run the sql script */
229+
static function run_pgsql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
230+
{
231+
$pgdb = @pg_connect("host=$host port=$port dbname=$dbname user=$username password=$password");
232+
$file_content = file($sqlfile);
233+
$query = "";
234+
$linnum = 0;
235+
foreach ($file_content as $sql_line)
236+
{
237+
$tsl = trim($sql_line);
238+
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
239+
{
240+
$query .= $sql_line;
241+
if (preg_match("/;\s*$/", $sql_line))
242+
{
243+
$query = str_replace(";", "", "$query");
244+
$result = pg_query($query);
245+
if (!$result)
246+
{
247+
echo "Error line:".$linnum."<br>";
248+
return pg_last_error();
249+
}
250+
$query = "";
251+
}
252+
}
253+
$linnum++;
254+
} // end for each line
255+
return true;
256+
}
257+
195258
} // end class
196259
?>

core/controllers/forms/InstallForm.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ public function createConfigForm()
107107

108108
$smartoptimizer = new Zend_Form_Element_Checkbox("smartoptimizer");
109109

110-
$assetstore = new Zend_Form_Element_Select('assetstore');
111110

112111
$submit = new Zend_Form_Element_Submit('submit');
113112
$submit ->setLabel('Create configuration');
114113

115-
$form->addElements(array($process,$timezone,$assetstore,$environment,$lang,$name,$smartoptimizer,$submit));
114+
$form->addElements(array($process,$timezone,$environment,$lang,$name,$smartoptimizer,$submit));
116115
return $form;
117116
}
118117
} // end class

core/views/admin/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/admin/admin.ind
114114
<b>{$module->fullname}</b><br/>
115115
{$module->description}
116116
</td>";
117-
if($module->configPage)
117+
if($module->configPage&&in_array($key, $this->modulesEnable))
118118
{
119119
echo "
120120
<td>

core/views/install/step3.phtml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,9 @@
3535
<label for='smartoptimizer'>CSS and Javascript optimizer</label>
3636
{$this->form['smartoptimizer']}
3737
</div>
38-
<div class='installAssetstrore'>
39-
<label for='assetstore'>Default Assetstore</label>
40-
{$this->form['assetstore']}
41-
</div>
4238
43-
<h3>Modules:</h3>
44-
<table>
4539
";
46-
foreach($this->modules as $key=>$module)
47-
{
48-
echo "
49-
<tr class='moduleElement'>
50-
<td>
51-
<b>{$module->fullname}</b><br/>
52-
{$module->description}
53-
</td>
54-
<td>";
55-
if(isset($module->db->{$this->databaseType}))
56-
{
57-
echo "
58-
<input type='checkbox' name='module[{$key}]' ".(($this->defaultModules->$key==1)?'checked':'')."/>";
59-
}
60-
else
61-
{
62-
echo "
63-
Module not available with your database type.
64-
";
65-
}
66-
echo"
67-
</td>
68-
</tr>
69-
";
70-
}
40+
7141
echo"
7242
</table>
7343
<div>

0 commit comments

Comments
 (0)