Fixes unit test after changes in [549].
[akelos.git] / app / controllers / framework_setup_controller.php
blob080bcccded586e74303761ed47450321005ca5fc
1 <?php
3 if(!defined('AK_ENVIRONMENT') || AK_ENVIRONMENT != 'setup'){
4 die();
7 error_reporting(E_ALL);
9 define('AK_WEB_REQUEST_CONNECT_TO_DATABASE_ON_INSTANTIATE', false);
11 define('AK_URL_REWRITE_ENABLED', false);
13 define('AK_AVAILABLE_LOCALES','en,ja,es');
14 define('AK_APP_LOCALES','en,ja,es');
16 defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
17 defined('AK_BASE_DIR') ? null : define('AK_BASE_DIR', str_replace(DS.'app'.DS.'controllers'.DS.'framework_setup_controller.php','',__FILE__));
18 defined('AK_CONFIG_DIR') ? null : define('AK_CONFIG_DIR', AK_BASE_DIR.DS.'config');
19 // defined('AK_FRAMEWORK_DIR') ? null : define('AK_FRAMEWORK_DIR', '/path/to/the/framework');
21 define('AK_AUTOMATICALLY_UPDATE_LANGUAGE_FILES', true);
22 define('AK_AUTOMATIC_CONFIG_VARS_ENCRYPTION', false);
24 define('AK_FTP_SHOW_ERRORS', false);
26 include_once(AK_CONFIG_DIR.DS.'boot.php');
27 require_once(AK_LIB_DIR.DS.'AkObject.php');
28 require_once(AK_LIB_DIR.DS.'AkInflector.php');
29 require_once(AK_LIB_DIR.DS.'Ak.php');
30 require_once(AK_LIB_DIR.DS.'AkActionController.php');
32 $_GET['controller'] = 'framework_setup';
35 class FrameworkSetupController extends AkActionController
37 var $layout = 'page';
39 function __construct()
41 parent::__construct();
42 $this->beforeFilter('initFrameworkSetup');
45 function initFrameworkSetup()
47 if(isset($_SESSION['__framework_setup'])){
48 $this->FrameworkSetup = unserialize($_SESSION['__framework_setup']);
49 }else{
50 $this->FrameworkSetup->setDefaultOptions();
54 function __destruct()
56 if(isset($this->FrameworkSetup)){
57 $_SESSION['__framework_setup'] = serialize($this->FrameworkSetup);
59 //Ak::debug($this->FrameworkSetup); Ak::debug($this->params);
62 function index()
64 // We need to avoid infinite loop if mod rewrite is disabled
65 if(strstr(@$this->params['ak'], 'url_rewrite_check')){
66 die();
70 function select_database()
72 $this->databases = $this->FrameworkSetup->getAvailableDatabases();
75 function set_database_details()
77 if($this->Request->isPost()){
78 foreach (array('development','production','testing') as $mode){
79 $this->FrameworkSetup->setDatabaseName(@$this->params[$mode.'_database_name'], $mode);
81 if($this->FrameworkSetup->getDatabaseType($mode) != 'sqlite'){
82 $this->FrameworkSetup->setDatabaseHost(@$this->params[$mode.'_database_host'], $mode);
83 $this->FrameworkSetup->setDatabaseUser(@$this->params[$mode.'_database_user'], $mode);
84 $this->FrameworkSetup->setDatabasePassword(@$this->params[$mode.'_database_password'], $mode);
87 if(!$this->FrameworkSetup->databaseConnection($mode)){
88 $this->FrameworkSetup->setDatabaseAdminUser(@$this->params['admin_database_user']);
89 $this->FrameworkSetup->setDatabaseAdminPassword(@$this->params['admin_database_password']);
90 // if(!$this->FrameworkSetup->createDatabase($mode)){
91 $this->flash_now = $this->t('Could not connect to %database database',
92 array('%database'=>$this->FrameworkSetup->getDatabaseName($mode)));
93 // }
97 if(empty($this->flash_now)){
98 $this->redirectToAction('file_settings');
101 return ;
102 }elseif(!empty($this->params['database_type'])){
103 if(!$this->FrameworkSetup->setDatabaseType($this->params['database_type'])){
104 $this->flash = $this->t('%database_type is not supported yet. '.
105 ' You must select one of the following databases: mysql, pgsql or sqlite',
106 array('%database_type'=>$this->params['database_type']));
107 $this->redirectToAction('file_settings');
108 return;
110 if(!$this->FrameworkSetup->isDatabaseDriverAvalible()){
111 $this->flash = $this->t('Seems that your current PHP settings '.
112 'do not support for %database_type databases',
113 array('%database_type'=>$this->params['database_type']));
114 $this->redirectToAction('file_settings');
115 return ;
121 function file_settings()
123 if($this->FrameworkSetup->needsFtpFileHandling()){
124 $this->redirectToAction('configure_ftp_details');
125 }else{
126 $this->redirectToAction('set_locales');
131 function configure_ftp_details()
133 if($this->Request->isPost()){
134 $this->FrameworkSetup->setFtpHost($this->params['ftp_host']);
135 $this->FrameworkSetup->setFtpUser($this->params['ftp_user']);
136 $this->FrameworkSetup->setFtpPassword($this->params['ftp_password']);
137 $this->FrameworkSetup->setFtpPath($this->params['ftp_path']);
139 if($this->FrameworkSetup->testFtpSettings()){
140 $this->redirectToAction('set_locales');
141 return ;
142 }else{
143 $this->flash_now = $this->t('Could not connect to selected ftp server');
144 return ;
148 if(!empty($this->params['check'])){
149 if($this->FrameworkSetup->needsFtpFileHandling()){
150 $this->flash_now = $this->t('Bad file permission. Please change file system privileges or set up a FTP account below');
151 }else{
152 $this->redirectToAction('set_locales');
153 return ;
157 if(!empty($this->params['skip'])){
158 $this->redirectToAction('set_locales');
159 return ;
164 function set_locales()
166 if($this->Request->isPost()){
167 if(!empty($this->params['locales'])){
168 $this->FrameworkSetup->setLocales($this->params['locales']);
169 $this->redirectToAction('perform_setup');
171 }else{
172 $this->flash_now = $this->t('You must supply at least one locale');
175 $this->locales = $this->FrameworkSetup->getLocales();
181 function perform_setup()
183 $this->configuration_file = $this->FrameworkSetup->getConfigurationFile();
184 if($this->FrameworkSetup->canWriteConfigurationFile()){
185 if( $this->FrameworkSetup->writeConfigurationFile($this->configuration_file) &&
186 $this->FrameworkSetup->writeRoutesFile() &&
187 $this->FrameworkSetup->runFrameworkInstaller()){
189 if($this->FrameworkSetup->hasUrlSuffix()){
190 $this->FrameworkSetup->modifyHtaccessFiles();
193 $this->FrameworkSetup->relativizeStylesheetPaths();
194 $this->FrameworkSetup->removeSetupFiles();
195 unset($_SESSION);
196 $this->redirectTo(array('controller'=>'page'));
203 function url_rewrite_check()
205 $this->layout = false;
206 $this->renderText('url_rewrite_working');
212 require_once(AK_LIB_DIR.DS.'AkDispatcher.php');
213 $Dispatcher =& new AkDispatcher();
214 $Dispatcher->dispatch();