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

Commit

Permalink
ENH: Simplify installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed Apr 19, 2011
1 parent f0ab6c7 commit ed4b205
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 147 deletions.
1 change: 0 additions & 1 deletion core/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ default.timezone=America/New_York
processing=onthefly

[module]
task=true

[production]
;Activate error reporting using Zend
Expand Down
29 changes: 28 additions & 1 deletion core/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function indexAction()
$formArray['timezone']->setValue($applicationConfig['global']['default.timezone']);
$this->view->configForm=$formArray;

$allModules=$this->Component->Utility->getAllModules();

if($this->_request->isPost())
{
$this->_helper->layout->disableLayout();
Expand Down Expand Up @@ -68,6 +70,32 @@ function indexAction()
{
unlink( BASE_PATH.'/core/configs/application.local.ini.old');
}

$moduleConfigLocalFile=BASE_PATH."/modules/$moduleName/configs/module.local.ini";
$moduleConfigFile=BASE_PATH."/modules/$moduleName/configs/module.ini";
if(!file_exists($moduleConfigLocalFile))
{
copy($moduleConfigFile, $moduleConfigLocalFile);
switch (Zend_Registry::get('configDatabase')->database->adapter)
{
case 'PDO_MYSQL':
$this->Component->Utility->run_mysql_from_file(BASE_PATH.'/modules/'.$moduleName.'/database/mysql/'.$allModules[$moduleName]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
break;
case 'PDO_PGSQL':
$this->Component->Utility->run_pgsql_from_file(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$moduleName]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
break;
}
}
rename(BASE_PATH.'/core/configs/application.local.ini', BASE_PATH.'/core/configs/application.local.ini.old');
$applicationConfig['module'][$moduleName]=$modulevalue;
$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini', $applicationConfig);
Expand Down Expand Up @@ -98,7 +126,6 @@ function indexAction()

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

foreach($allModules as $key=>$module)
{
Expand Down
126 changes: 15 additions & 111 deletions core/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function step2Action()
switch($type)
{
case 'mysql':
$this->run_mysql_from_file($sqlFile,
$this->Component->Utility->run_mysql_from_file($sqlFile,
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
$params= array(
'host' => $form->getValue('host'),
Expand Down Expand Up @@ -138,7 +138,7 @@ function step2Action()
Zend_Registry::set('dbAdapter', $db);
break;
case 'pgsql':
$this->run_pgsql_from_file($sqlFile,
$this->Component->Utility->run_pgsql_from_file($sqlFile,
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'),$form->getValue('port'));
$params= array(
'host' => $form->getValue('host'),
Expand Down Expand Up @@ -217,66 +217,30 @@ function step3Action()
$formArray['process']->setValue($applicationConfig['global']['processing']);

$assetstrores=$this->Assetstore->getAll();
$formArray['assetstore']->addMultiOptions(array(
$assetstrores[0]->getKey() => $assetstrores[0]->getPath()
));


$this->view->form=$formArray;
$allModules=$this->Component->Utility->getAllModules();
$this->view->modules=$allModules;
$this->view->defaultModules = new Zend_Config_Ini(APPLICATION_CONFIG, 'module');
$this->view->databaseType =Zend_Registry::get('configDatabase')->database->adapter;
if($this->_request->isPost()&&$form->isValid($this->getRequest()->getPost()))
{

$allModules=$this->Component->Utility->getAllModules();
foreach($allModules as $key=>$module)
{
$configLocal=BASE_PATH."/modules/$key/configs/module.local.ini";
if(file_exists($configLocal))
{
unlink($configLocal);
}
}
$applicationConfig['global']['application.name']=$form->getValue('name');
$applicationConfig['global']['application.lang']=$form->getValue('lang');
$applicationConfig['global']['environment']=$form->getValue('environment');
$applicationConfig['global']['defaultassetstore.id']=$form->getValue('assetstore');
$applicationConfig['global']['defaultassetstore.id']=$assetstrores[0]->getKey();
$applicationConfig['global']['smartoptimizer']=$form->getValue('smartoptimizer');
$applicationConfig['global']['default.timezone']=$form->getValue('timezone');
$applicationConfig['global']['processing']=$form->getValue('process');
$applicationConfig['module']=array();
$modules=$this->getRequest()->getPost();
if(isset($modules['module']))
{
$modules=$modules['module'];
}
else
{
$modules=array();
}
foreach($modules as $key=>$module)
{
$applicationConfig['module'][$key]='true';
switch (Zend_Registry::get('configDatabase')->database->adapter)
{
case 'PDO_MYSQL':
$this->run_mysql_from_file(BASE_PATH.'/modules/'.$key.'/database/mysql/'.$allModules[$key]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
break;
case 'PDO_PGSQL':
$this->run_pgsql_from_file(BASE_PATH.'/modules/'.$key.'/database/pgsql/'.$allModules[$key]->version.'.sql',
Zend_Registry::get('configDatabase')->database->params->host,
Zend_Registry::get('configDatabase')->database->params->username,
Zend_Registry::get('configDatabase')->database->params->password,
Zend_Registry::get('configDatabase')->database->params->dbname,
Zend_Registry::get('configDatabase')->database->params->port);
break;
}

$path=BASE_PATH.'/modules/'.$key.'/configs/module.ini';
$newpath=BASE_PATH.'/modules/'.$key.'/configs/module.local.ini';
$data=parse_ini_file ($path,true);
@unlink($newpath);
$this->Component->Utility->createInitFile($newpath, $data);
}

$this->Component->Utility->createInitFile(BASE_PATH.'/core/configs/application.local.ini',$applicationConfig);
$this->_redirect("/");
$this->_redirect("/admin");
}
} // end method step2Action

Expand Down Expand Up @@ -338,66 +302,6 @@ public function testconnexionAction()



/** Function to run the sql script */
function run_mysql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
{
$db = @mysql_connect("$host:$port", "$username", "$password");
$select=@mysql_select_db($dbname,$db);
if(!$db||!$select)
{
throw new Zend_Exception("Unable to connect.");
}
$requetes="";

$sql=file($sqlfile);
foreach($sql as $l)
{
if (substr(trim($l),0,2)!="--")
{
$requetes .= $l;
}
}

$reqs = explode(";",$requetes);
foreach($reqs as $req)
{ // et on les éxécute
if (!mysql_query($req,$db) && trim($req)!="")
{
throw new Zend_Exception("Unable to execute: ".$req );
}
}
return true;
}
/** Function to run the sql script */
function run_pgsql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
{
$pgdb = @pg_connect("host=$host port=$port dbname=$dbname user=$username password=$password");
$file_content = file($sqlfile);
$query = "";
$linnum = 0;
foreach ($file_content as $sql_line)
{
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
{
$query .= $sql_line;
if (preg_match("/;\s*$/", $sql_line))
{
$query = str_replace(";", "", "$query");
$result = pg_query($query);
if (!$result)
{
echo "Error line:".$linnum."<br>";
return pg_last_error();
}
$query = "";
}
}
$linnum++;
} // end for each line
return true;
}

} // end class


63 changes: 63 additions & 0 deletions core/controllers/components/UtilityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,68 @@ static public function safedelete($filename)
unlink($filename);
}




/** Function to run the sql script */
static function run_mysql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
{
$db = @mysql_connect("$host:$port", "$username", "$password");
$select=@mysql_select_db($dbname,$db);
if(!$db||!$select)
{
throw new Zend_Exception("Unable to connect.");
}
$requetes="";

$sql=file($sqlfile);
foreach($sql as $l)
{
if (substr(trim($l),0,2)!="--")
{
$requetes .= $l;
}
}

$reqs = explode(";",$requetes);
foreach($reqs as $req)
{ // et on les éxécute
if (!mysql_query($req,$db) && trim($req)!="")
{
throw new Zend_Exception("Unable to execute: ".$req );
}
}
return true;
}
/** Function to run the sql script */
static function run_pgsql_from_file($sqlfile,$host,$username,$password,$dbname,$port)
{
$pgdb = @pg_connect("host=$host port=$port dbname=$dbname user=$username password=$password");
$file_content = file($sqlfile);
$query = "";
$linnum = 0;
foreach ($file_content as $sql_line)
{
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
{
$query .= $sql_line;
if (preg_match("/;\s*$/", $sql_line))
{
$query = str_replace(";", "", "$query");
$result = pg_query($query);
if (!$result)
{
echo "Error line:".$linnum."<br>";
return pg_last_error();
}
$query = "";
}
}
$linnum++;
} // end for each line
return true;
}

} // end class
?>
3 changes: 1 addition & 2 deletions core/controllers/forms/InstallForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ public function createConfigForm()

$smartoptimizer = new Zend_Form_Element_Checkbox("smartoptimizer");

$assetstore = new Zend_Form_Element_Select('assetstore');

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

$form->addElements(array($process,$timezone,$assetstore,$environment,$lang,$name,$smartoptimizer,$submit));
$form->addElements(array($process,$timezone,$environment,$lang,$name,$smartoptimizer,$submit));
return $form;
}
} // end class
Expand Down
2 changes: 1 addition & 1 deletion core/views/admin/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ $this->headScript()->appendFile($this->coreWebroot . '/public/js/admin/admin.ind
<b>{$module->fullname}</b><br/>
{$module->description}
</td>";
if($module->configPage)
if($module->configPage&&in_array($key, $this->modulesEnable))
{
echo "
<td>
Expand Down
32 changes: 1 addition & 31 deletions core/views/install/step3.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,9 @@
<label for='smartoptimizer'>CSS and Javascript optimizer</label>
{$this->form['smartoptimizer']}
</div>
<div class='installAssetstrore'>
<label for='assetstore'>Default Assetstore</label>
{$this->form['assetstore']}
</div>
<h3>Modules:</h3>
<table>
";
foreach($this->modules as $key=>$module)
{
echo "
<tr class='moduleElement'>
<td>
<b>{$module->fullname}</b><br/>
{$module->description}
</td>
<td>";
if(isset($module->db->{$this->databaseType}))
{
echo "
<input type='checkbox' name='module[{$key}]' ".(($this->defaultModules->$key==1)?'checked':'')."/>";
}
else
{
echo "
Module not available with your database type.
";
}
echo"
</td>
</tr>
";
}

echo"
</table>
<div>
Expand Down

0 comments on commit ed4b205

Please sign in to comment.