New configure method, use profil to duplicate more easily on servers

This commit is contained in:
Michael RICOIS 2014-11-26 14:05:39 +00:00
parent fe8613fa27
commit f19db0de9f

View File

@ -15,19 +15,6 @@ set_include_path(implode(PATH_SEPARATOR, array(
get_include_path(),
)));
//Copy configuration
$configDir = realpath(dirname(__FILE__)).'/config';
$appconfigDir = APPLICATION_PATH.'/configs';
$hostname = exec('echo $(hostname)');
if ( !file_exists( $appconfigDir.'/application.ini') ) {
$result = copy($configDir.'/'.$hostname.'/application.ini', $appconfigDir.'/application.ini');
if ($result !== true) {
echo date('Y-m-d H:i:s')." - Erreur lors de la configuration\n";
exit(1);
}
}
//Use classmap autoloader - useful with opcode and realpath cache
require_once 'Zend/Loader/AutoloaderFactory.php';
require_once 'Zend/Loader/ClassMapAutoloader.php';
@ -54,18 +41,12 @@ Zend_Loader_AutoloaderFactory::factory(array(
// Zend_Application - Use it if you don't have autoloaders
//require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Affiche les informations d'utilisation",
'install' => "Installe et configure",
'install=s' => "Installe et configure",
)
);
$opts->parse();
@ -75,16 +56,38 @@ try {
}
//Usage
if(isset($opts->help))
if (isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
if(isset($opts->install))
if ($opts->install)
{
echo date('Y-m-d H:i:s')." - Démarrage de la configuration.\n";
//Copy configuration
$configDir = realpath(dirname(__FILE__)).'/profil';
$appconfigDir = APPLICATION_PATH.'/configs';
$profil = $opts->install;
if ( !file_exists( $appconfigDir.'/application.ini') ) {
$result = copy($configDir.'/'.$profil.'/application.ini', $appconfigDir.'/application.ini');
if ($result !== true) {
echo date('Y-m-d H:i:s')." - Impossible de copier la configuration.\n";
exit(1);
}
} else {
echo date('Y-m-d H:i:s')." - Le profil de configuration existe déja.\n";
exit(1);
}
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$c = new Zend_Config($application->getOptions());
//Create data directory and all his children
@ -98,6 +101,11 @@ if(isset($opts->install))
mkdir(APPLICATION_PATH.'/../data/cache');
}
if ( !file_exists(APPLICATION_PATH.'/../data/cache') )
{
mkdir(APPLICATION_PATH.'/../data/log');
}
if ( !file_exists(APPLICATION_PATH.'/../data/files') )
{
mkdir(APPLICATION_PATH.'/../data/files');
@ -117,17 +125,18 @@ if(isset($opts->install))
// genCache.php
// genCodeRatios.php
if ( substr(strtoupper(PHP_OS),0,3) == 'WIN' ) {
} else {
if ( substr(strtoupper(PHP_OS),0,3) != 'WIN' ) {
//Copy files
passthru('cp -rv '.realpath(dirname(__FILE__)).'/config/_files/* '.$c->profil->path->files.'/');
passthru('cp -rv '.realpath(dirname(__FILE__)).'/files/* '.$c->profil->path->files.'/');
//Modification des permissions
passthru('chown -R www-data: '.APPLICATION_PATH.'/../');
//Check WKHTMLTOPDF
$wkhtml = exec('echo $(which wkhtmltopdf)');
if ( empty(trim($wkhtml)) ) {
echo date('Y-m-d H:i:s')." - Warning : WKHTMLTOPDF non installé.\n";
}
}
//Check persistent data directories