Skip to content
Browse files

PHP CS Fixes for PSR-2 in installer.

  • Loading branch information...
1 parent 69533ea commit 2eefe35a014ba451a11b6a372901f2f3cc9b7d32 @philsturgeon philsturgeon committed Feb 25, 2014
Showing with 1,093 additions and 1,093 deletions.
  1. +118 −118 installer/controllers/ajax.php
  2. +460 −460 installer/controllers/installer.php
  3. +282 −282 installer/libraries/Installer_lib.php
  4. +233 −233 installer/libraries/Module_import.php
View
236 installer/controllers/ajax.php
@@ -8,123 +8,123 @@
*/
class Ajax extends CI_Controller
{
- /**
- * At start this controller should:
- * 1. Check that this is indeed an AJAX request.
- * 2. Set the language used by the user.
- * 3. Load the language files.
- */
- public function __construct()
- {
- if ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') === false) {
- show_error('You should not be here');
- }
-
- parent::__construct();
-
- $languages = array();
- $languages_directory = realpath(dirname(__FILE__).'/../language/');
- foreach (glob($languages_directory.'/*', GLOB_ONLYDIR) as $path) {
- $path = basename($path);
-
- if ( ! in_array($path, array('.', '..'))) {
- $languages[] = $path;
- }
- }
-
- // Check if the language is supported and set it.
- if (in_array($this->session->userdata('language'), $languages)) {
- $this->config->set_item('language', $this->session->userdata('language'));
- }
- unset($languages);
-
- // also we load some generic language labels
- $this->lang->load('installer');
- }
-
- public function confirm_database()
- {
- // TODO Maybe actually use this somewhere?
- $create_db = $this->input->post('create_db') === 'true';
-
- // Set some headers for our JSON
- header('Cache-Control: no-cache, must-revalidate');
- header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
- header('Content-type: application/json');
-
- try {
- // Create a connection to see if data is correct
- $this->installer_lib->create_connection(array(
- 'driver' => $this->input->post('driver'),
- 'database' => $this->input->post('database'),
- 'hostname' => $this->input->post('hostname'),
- 'port' => $this->input->post('port'),
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password'),
- ));
- } catch (Exception $e) {
- exit(json_encode(array(
- 'success' => false,
- 'message' => lang('db_failure').$e->getMessage(),
- )));
- }
-
- echo json_encode(array(
- 'success' => true,
- 'message' => lang('db_success'),
- ));
- }
-
- /**
- * Sends statistics back to pyrocms.com
- *
- * These are only used to see which OS's we should develop for and are anonymous.
- *
- * @author jeroenvdgulik
- * @since 1.0.1
- */
- public function statistics()
- {
- $this->load->library('installer_lib');
- $this->installer_lib->mysql_acceptable('server');
- $this->installer_lib->mysql_acceptable('client');
- $this->installer_lib->gd_acceptable();
-
- $data = array(
- 'version' => CMS_VERSION,
- 'php_version' => phpversion(),
- 'webserver_hash' => md5($this->session->userdata('http_server').$this->input->server('SERVER_NAME').$this->input->server('SERVER_ADDR').$this->input->server('SERVER_SIGNATURE')),
- 'webserver_software' => $this->input->server('SERVER_SOFTWARE'),
- 'dbserver' => $this->installer_lib->mysql_server_version,
- 'dbclient' => $this->installer_lib->mysql_client_version,
- 'gd_version' => $this->installer_lib->gd_version,
- 'zlib_version' => $this->installer_lib->zlib_available(),
- 'curl' => $this->installer_lib->curl_available(),
- );
-
- include '../system/sparks/curl/1.2.1/libraries/Curl.php';
- $url = 'https://www.pyrocms.com/statistics/add';
- $curl = new Curl;
- $curl->simple_post($url, $data);
- }
-
- /**
- * Check if apache's mod_rewrite is enabled
- *
- * @return string
- */
- public function check_rewrite()
- {
- // if it doesn't exist then warn them at least
- if ( ! function_exists('apache_get_modules')) {
- return print(lang('rewrite_fail'));
- }
-
- if (in_array('mod_rewrite', apache_get_modules())) {
- return print('enabled');
- }
-
- return print(lang('mod_rewrite'));
- }
+ /**
+ * At start this controller should:
+ * 1. Check that this is indeed an AJAX request.
+ * 2. Set the language used by the user.
+ * 3. Load the language files.
+ */
+ public function __construct()
+ {
+ if ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') === false) {
+ show_error('You should not be here');
+ }
+
+ parent::__construct();
+
+ $languages = array();
+ $languages_directory = realpath(dirname(__FILE__).'/../language/');
+ foreach (glob($languages_directory.'/*', GLOB_ONLYDIR) as $path) {
+ $path = basename($path);
+
+ if ( ! in_array($path, array('.', '..'))) {
+ $languages[] = $path;
+ }
+ }
+
+ // Check if the language is supported and set it.
+ if (in_array($this->session->userdata('language'), $languages)) {
+ $this->config->set_item('language', $this->session->userdata('language'));
+ }
+ unset($languages);
+
+ // also we load some generic language labels
+ $this->lang->load('installer');
+ }
+
+ public function confirm_database()
+ {
+ // TODO Maybe actually use this somewhere?
+ $create_db = $this->input->post('create_db') === 'true';
+
+ // Set some headers for our JSON
+ header('Cache-Control: no-cache, must-revalidate');
+ header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
+ header('Content-type: application/json');
+
+ try {
+ // Create a connection to see if data is correct
+ $this->installer_lib->create_connection(array(
+ 'driver' => $this->input->post('driver'),
+ 'database' => $this->input->post('database'),
+ 'hostname' => $this->input->post('hostname'),
+ 'port' => $this->input->post('port'),
+ 'username' => $this->input->post('username'),
+ 'password' => $this->input->post('password'),
+ ));
+ } catch (Exception $e) {
+ exit(json_encode(array(
+ 'success' => false,
+ 'message' => lang('db_failure').$e->getMessage(),
+ )));
+ }
+
+ echo json_encode(array(
+ 'success' => true,
+ 'message' => lang('db_success'),
+ ));
+ }
+
+ /**
+ * Sends statistics back to pyrocms.com
+ *
+ * These are only used to see which OS's we should develop for and are anonymous.
+ *
+ * @author jeroenvdgulik
+ * @since 1.0.1
+ */
+ public function statistics()
+ {
+ $this->load->library('installer_lib');
+ $this->installer_lib->mysql_acceptable('server');
+ $this->installer_lib->mysql_acceptable('client');
+ $this->installer_lib->gd_acceptable();
+
+ $data = array(
+ 'version' => CMS_VERSION,
+ 'php_version' => phpversion(),
+ 'webserver_hash' => md5($this->session->userdata('http_server').$this->input->server('SERVER_NAME').$this->input->server('SERVER_ADDR').$this->input->server('SERVER_SIGNATURE')),
+ 'webserver_software' => $this->input->server('SERVER_SOFTWARE'),
+ 'dbserver' => $this->installer_lib->mysql_server_version,
+ 'dbclient' => $this->installer_lib->mysql_client_version,
+ 'gd_version' => $this->installer_lib->gd_version,
+ 'zlib_version' => $this->installer_lib->zlib_available(),
+ 'curl' => $this->installer_lib->curl_available(),
+ );
+
+ include '../system/sparks/curl/1.2.1/libraries/Curl.php';
+ $url = 'https://www.pyrocms.com/statistics/add';
+ $curl = new Curl;
+ $curl->simple_post($url, $data);
+ }
+
+ /**
+ * Check if apache's mod_rewrite is enabled
+ *
+ * @return string
+ */
+ public function check_rewrite()
+ {
+ // if it doesn't exist then warn them at least
+ if ( ! function_exists('apache_get_modules')) {
+ return print(lang('rewrite_fail'));
+ }
+
+ if (in_array('mod_rewrite', apache_get_modules())) {
+ return print('enabled');
+ }
+
+ return print(lang('mod_rewrite'));
+ }
}
View
920 installer/controllers/installer.php
@@ -8,7 +8,7 @@
// This is a copy of the function that exists in system/cms/core/My_Controller.php
function ci()
{
- return get_instance();
+ return get_instance();
}
/**
@@ -30,123 +30,123 @@ function ci()
*/
class Installer extends CI_Controller
{
- /** @var array Languages supported by the installer */
- private $languages = array();
-
- /** @var array Directories that need to be writable */
- private $writable_directories = array(
- 'system/cms/cache',
- 'system/cms/config',
- 'addons',
- 'assets/cache',
- 'uploads',
- 'system/cms/modules/streams_core/models',
- );
-
- /** @var array Files that need to be writable */
- private $writable_files = array(
- 'system/cms/config/config.php'
- );
-
- /** @var string The translations directory */
- private $languages_directory = '../language/';
-
- /** @var array The view variables for creating the language menu */
- private $language_nav = array();
-
- /**
- * At start this controller should:
- * 1. Load the array of supported servers
- * 2. Set the language used by the user.
- * 3. Load the language files.
- * 4. Load the Form validation library.
- */
- public function __construct()
- {
- parent::__construct();
-
- // Load the config file that contains a list of supported servers
- $this->load->config('servers');
-
- // Get the supported languages
- $this->_discover_languages();
-
- if ($this->session->userdata('language')) {
- $this->config->set_item('language', $this->session->userdata('language'));
- }
- $current_language = $this->config->item('language');
-
- // Load the global installer language file
- $this->lang->load('installer');
-
- define('SITE_REF', 'default');
-
- // Where is PyroCMS installed?
- define('PYROPATH', dirname(FCPATH).'/system/cms/');
- define('ADDONPATH', dirname(FCPATH).'/addons/'.SITE_REF.'/');
- define('SHARED_ADDONPATH', dirname(FCPATH).'/addons/shared_addons/');
-
- // Let us load stuff from the main application
- $this->load->add_package_path(PYROPATH);
-
- // set the supported languages to be saved in Settings for emails and .etc
- // modules > settings > details.php uses this
- require_once(PYROPATH.'/config/language.php');
-
- // Check that the language configuration has been loaded.
- isset($config) or exit('Could not load language configuration.');
-
- // Define the default language code as constant
- define('DEFAULT_LANG', $config['default_language']);
-
- $image_url = base_url('assets/img/flags/__CODE__.gif');
-
- // Work out some misrepresented language codes to specific language flags
- $flag_exchange = array(
- 'english' => 'gb',
- 'chinese_simplified' => 'cn',
- 'chinese_traditional' => 'cn',
- 'danish' => 'dk',
- 'czech' => 'cz',
- );
-
- // Generate the language array for the navigation.
- foreach ($config['supported_languages'] as $code => $info) {
- // There is a translation available and we haven't already put that in there.
- if (in_array($info['folder'], $this->languages) && ! array_key_exists($info['folder'], $this->language_nav)) {
- $this->language_nav[$info['folder']] = array(
- 'code' => $code,
- 'folder' => $info['folder'],
- 'name' => $info['name'],
- 'action_url' => site_url('installer/change/'.$info['folder']),
- 'image_url' => str_replace('__CODE__', (in_array($info['folder'], array_keys($flag_exchange))) ? $flag_exchange[$info['folder']] : $code, $image_url),
- );
- }
- }
-
- ksort($this->language_nav);
-
- // Load form validation library
- $this->load->library('form_validation');
- }
-
- /**
- * Index method
- */
- public function index()
- {
- $data = new stdClass;
+ /** @var array Languages supported by the installer */
+ private $languages = array();
+
+ /** @var array Directories that need to be writable */
+ private $writable_directories = array(
+ 'system/cms/cache',
+ 'system/cms/config',
+ 'addons',
+ 'assets/cache',
+ 'uploads',
+ 'system/cms/modules/streams_core/models',
+ );
+
+ /** @var array Files that need to be writable */
+ private $writable_files = array(
+ 'system/cms/config/config.php'
+ );
+
+ /** @var string The translations directory */
+ private $languages_directory = '../language/';
+
+ /** @var array The view variables for creating the language menu */
+ private $language_nav = array();
+
+ /**
+ * At start this controller should:
+ * 1. Load the array of supported servers
+ * 2. Set the language used by the user.
+ * 3. Load the language files.
+ * 4. Load the Form validation library.
+ */
+ public function __construct()
+ {
+ parent::__construct();
+
+ // Load the config file that contains a list of supported servers
+ $this->load->config('servers');
+
+ // Get the supported languages
+ $this->_discover_languages();
+
+ if ($this->session->userdata('language')) {
+ $this->config->set_item('language', $this->session->userdata('language'));
+ }
+ $current_language = $this->config->item('language');
+
+ // Load the global installer language file
+ $this->lang->load('installer');
+
+ define('SITE_REF', 'default');
+
+ // Where is PyroCMS installed?
+ define('PYROPATH', dirname(FCPATH).'/system/cms/');
+ define('ADDONPATH', dirname(FCPATH).'/addons/'.SITE_REF.'/');
+ define('SHARED_ADDONPATH', dirname(FCPATH).'/addons/shared_addons/');
+
+ // Let us load stuff from the main application
+ $this->load->add_package_path(PYROPATH);
+
+ // set the supported languages to be saved in Settings for emails and .etc
+ // modules > settings > details.php uses this
+ require_once(PYROPATH.'/config/language.php');
+
+ // Check that the language configuration has been loaded.
+ isset($config) or exit('Could not load language configuration.');
+
+ // Define the default language code as constant
+ define('DEFAULT_LANG', $config['default_language']);
+
+ $image_url = base_url('assets/img/flags/__CODE__.gif');
+
+ // Work out some misrepresented language codes to specific language flags
+ $flag_exchange = array(
+ 'english' => 'gb',
+ 'chinese_simplified' => 'cn',
+ 'chinese_traditional' => 'cn',
+ 'danish' => 'dk',
+ 'czech' => 'cz',
+ );
+
+ // Generate the language array for the navigation.
+ foreach ($config['supported_languages'] as $code => $info) {
+ // There is a translation available and we haven't already put that in there.
+ if (in_array($info['folder'], $this->languages) && ! array_key_exists($info['folder'], $this->language_nav)) {
+ $this->language_nav[$info['folder']] = array(
+ 'code' => $code,
+ 'folder' => $info['folder'],
+ 'name' => $info['name'],
+ 'action_url' => site_url('installer/change/'.$info['folder']),
+ 'image_url' => str_replace('__CODE__', (in_array($info['folder'], array_keys($flag_exchange))) ? $flag_exchange[$info['folder']] : $code, $image_url),
+ );
+ }
+ }
+
+ ksort($this->language_nav);
+
+ // Load form validation library
+ $this->load->library('form_validation');
+ }
+
+ /**
+ * Index method
+ */
+ public function index()
+ {
+ $data = new stdClass;
// TODO No idea why this is here. Potentially lazy passing of data to ajax.php
$this->session->set_userdata('http_server', $this->input->post('http_server'));
- $driver = $this->input->post('db_driver');
- $hostname = $this->input->post('hostname');
- $location = $this->input->post('location');
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $port = $this->input->post('port');
- $database = $this->input->post('database');
+ $driver = $this->input->post('db_driver');
+ $hostname = $this->input->post('hostname');
+ $location = $this->input->post('location');
+ $username = $this->input->post('username');
+ $password = $this->input->post('password');
+ $port = $this->input->post('port');
+ $database = $this->input->post('database');
// Set rules
$this->form_validation->set_rules(array(
@@ -157,8 +157,8 @@ public function index()
),
array(
'field' => 'hostname',
- 'label' => 'lang:server',
- 'rules' => 'trim|required|callback_test_db_connection'
+ 'label' => 'lang:server',
+ 'rules' => 'trim|required|callback_test_db_connection'
),
array(
'field' => 'location',
@@ -167,18 +167,18 @@ public function index()
),
array(
'field' => 'username',
- 'label' => 'lang:username',
+ 'label' => 'lang:username',
'rules' => 'trim'.(in_array($driver, array('mysql', 'pgsql')) ? '|required' : '')
),
array(
'field' => 'password',
- 'label' => 'lang:password',
- 'rules' => 'trim'
+ 'label' => 'lang:password',
+ 'rules' => 'trim'
),
array(
'field' => 'port',
'label' => 'lang:port',
- 'rules' => 'trim'.(in_array($driver, array('mysql', 'pgsql')) ? '|required' : '')
+ 'rules' => 'trim'.(in_array($driver, array('mysql', 'pgsql')) ? '|required' : '')
),
array(
'field' => 'database',
@@ -187,18 +187,18 @@ public function index()
),
array(
'field' => 'http_server',
- 'label' => 'lang:server_settings',
- 'rules' => 'trim|required'
+ 'label' => 'lang:server_settings',
+ 'rules' => 'trim|required'
),
));
// If the form validation passed
- if ($this->form_validation->run()) {
+ if ($this->form_validation->run()) {
// Set the flashdata message
$this->session->set_flashdata('success', lang('db_success'));
// Redirect to the second step
- $this->session->set_userdata('step_1_passed', TRUE);
+ $this->session->set_userdata('step_1_passed', TRUE);
redirect('installer/step_2');
}
@@ -230,340 +230,340 @@ public function index()
$data->selected_db_driver = $this->input->post('db_driver');
}
- $this->_render_view('step_1', (array) $data);
- }
-
- /**
- * Function to test the DB connection (used for the form validation)
- *
- * @return bool
- */
- public function test_db_connection()
- {
- $db_config = array(
- 'driver' => $this->input->post('db_driver'),
- 'database' => $this->input->post('database'),
- 'location' => $this->input->post('location'),
- 'hostname' => $this->input->post('hostname'),
- 'port' => $this->input->post('port'),
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password'),
- 'create_db' => $this->input->post('create_db'),
- 'site_ref' => 'default',
- );
-
- // Store this for later
- $this->session->set_userdata('db_config', $db_config);
-
- try {
- // Create a connection to see if data is correct
- $this->installer_lib->create_connection($db_config);
- } catch (Exception $e) {
- $this->form_validation->set_message('test_db_connection', lang('db_failure').$e->getMessage());
- return false;
- }
-
- return true;
- }
-
- /**
- * First actual installation step
- */
- public function step_2()
- {
- // Did the user enter the DB settings ?
- if ( ! $this->session->userdata('step_1_passed')) {
- // Set the flashdata message
- $this->session->set_flashdata('message', lang('step1_failure'));
- $this->session->set_flashdata('message_type', 'failure');
-
- redirect('');
- }
-
- $data = new stdClass;
-
- // Check the PHP version
- $data->php_acceptable = $this->installer_lib->php_acceptable();
- $data->php_version = PHP_VERSION;
-
- // Check the GD data
- $data->gd_acceptable = $this->installer_lib->gd_acceptable();
- $data->gd_version = $this->installer_lib->gd_version;
-
- // Check to see if Zlib is enabled
- $data->zlib_enabled = $this->installer_lib->zlib_available();
-
- // Check to see if Curl is enabled
- $data->curl_enabled = $this->installer_lib->curl_available();
-
- // Get the server
- $selected_server = $this->session->userdata('http_server');
- $supported_servers = $this->config->item('supported_servers');
-
- $data->http_server = new stdClass;
- $data->http_server->supported = $this->installer_lib->verify_http_server($this->session->userdata('http_server'));
- $data->http_server->name = @$supported_servers[$selected_server]['name'];
-
- // Check the final results
- $data->step_passed = $this->installer_lib->check_server($data);
-
- // Skip Step 2 if it passes
- if ($data->step_passed) {
- $this->session->set_userdata('step_2_passed', true);
-
- redirect('installer/step_3');
- }
-
- $this->session->set_userdata('step_2_passed', $data->step_passed);
-
- // Load the view files
-
- $this->_render_view('step_2', (array) $data);
- }
-
- /**
- * Another step, yay!
- */
- public function step_3()
- {
- if ( ! $this->session->userdata('step_1_passed') OR ! $this->session->userdata('step_2_passed')) {
- // Redirect the user back to step 1
- redirect('installer/step_2');
- }
-
- // Load the file helper
- $this->load->helper('file');
-
- // Get the write permissions for the folders
- $permissions = array();
- foreach ($this->writable_directories as $dir) {
- @chmod('../'.$dir, 0777);
- $permissions['directories'][$dir] = is_really_writable('../'.$dir);
- }
-
- foreach ($this->writable_files as $file) {
- @chmod('../'.$file, 0666);
- $permissions['files'][$file] = is_really_writable('../'.$file);
- }
-
- $data = array();
- // If all permissions are TRUE, go ahead
- $data['step_passed'] = ! in_array(false, $permissions['directories']) && !in_array(false, $permissions['files']);
- $this->session->set_userdata('step_3_passed', $data['step_passed']);
-
- // Skip Step 2 if it passes
- if ($data['step_passed']) {
- $this->session->set_userdata('step_3_passed', true);
-
- redirect('installer/step_4');
- }
-
- // View variables
- $data['permissions'] = $permissions;
-
- $this->_render_view('step_3', $data);
- }
-
- /**
- * Another step, damn thee steps, damn thee!
- */
- public function step_4()
- {
- if ( ! $this->session->userdata('step_1_passed') OR ! $this->session->userdata('step_2_passed') OR ! $this->session->userdata('step_3_passed')) {
- // Redirect the user back to step 2
- redirect('installer/step_2');
- }
-
- // Set rules
- $this->form_validation->set_rules(array(
- array(
- 'field' => 'user[username]',
- 'label' => 'lang:user_name',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'user[firstname]',
- 'label' => 'lang:first_name',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'user[lastname]',
- 'label' => 'lang:last_name',
- 'rules' => 'trim|required'
- ),
- array(
- 'field' => 'user[email]',
- 'label' => 'lang:email',
- 'rules' => 'trim|required|valid_email'
- ),
- array(
- 'field' => 'user[password]',
- 'label' => 'lang:password',
- 'rules' => 'trim|min_length[6]|max_length[20]|required'
- ),
- ));
-
- // If the form validation failed (or did not run)
- if ($this->form_validation->run() == false) {
- $this->_render_view('step_4');
- }
-
- // If the form validation passed
- else {
- // Grab the connection config from the session
- $db_config = $this->session->userdata('db_config');
-
- // First User details
- $user = $this->input->post('user');
-
- // Create the database if that is what they asked us to do
- if ( ! empty($db_config['create_db'])) {
- // Create an PDO connection and instance
- $pdo = $this->installer_lib->create_connection($db_config);
-
- // Make the database
- $this->installer_lib->create_db($pdo, $db_config['database']);
- }
-
- // Let's try to install the system with this new PDO instance
- try {
- $pdb = $this->installer_lib->install($user, $db_config);
- } catch (InstallerException $e) {
-
- $this->_render_view('step_4', array(
- 'messages' => array(
- 'error' => $e->getMessage(),
- )
- ));
-
- return;
- }
-
- // Success!
- $this->session->set_flashdata('success', lang('success'));
-
- // Store the default username and password in the session data
- $this->session->set_userdata('user', $user);
-
- // Define the default user email to be used in the settings module install
- define('DEFAULT_EMAIL', $this->input->post('user_email'));
-
- // Import the modules
- $this->load->library('module_import', array(
- 'pdb' => $pdb,
- ));
-
- $this->module_import->import_all();
-
- $themeManager = new ThemeManager();
- $themeManager->setLocations(array(
- PYROPATH.'themes/',
- ));
-
- $themeManager->registerUnavailableThemes();
-
- $widgetManager = new WidgetManager();
- $widgetManager->setLocations(array(
- PYROPATH.'widgets/',
- ));
- $widgetManager->registerUnavailableWidgets();
-
- redirect('installer/complete');
- }
- }
-
-
- /**
- * We're done, thank god for that
- */
- public function complete()
- {
- // check if we came from step4
- if ( ! $this->session->userdata('user')) {
- redirect(site_url());
- }
-
- $server_name = $this->session->userdata('http_server');
- $supported_servers = $this->config->item('supported_servers');
-
- // Load our user's settings
- $data = $this->session->userdata('user');
-
- // Create the admin link
- $data['website_url'] = 'http://'.$this->input->server('HTTP_HOST').preg_replace('/installer\/index.php$/', '', $this->input->server('SCRIPT_NAME'));
- $data['control_panel_url'] = $data['website_url'].($supported_servers[$server_name]['rewrite_support'] === true ? 'admin' : 'index.php/admin');
-
- // Let's remove our session since it contains data we don't want anyone to see
- $this->session->sess_destroy();
-
- $this->_render_view('complete', $data);
- }
-
- /**
- * Changes the active language
- *
- * @author jeroenvdgulik
- * @since 0.9.8.1
- *
- * @param string $language
- */
- public function change($language)
- {
- $this->_discover_languages();
-
- if (in_array($language, $this->languages)) {
- $this->session->set_userdata('language', $language);
- }
-
- redirect('installer');
- }
-
- /**
- * Set up class properties related to translations.
- *
- * Populates the supported languages array and sets the
- * installer translations directory as an absolute path
- */
- private function _discover_languages()
- {
- // Convert the translation directory path to absolute
- if ($this->languages_directory === '../language/') {
- $this->languages_directory = realpath(dirname(__FILE__).'/'.$this->languages_directory);
- }
-
- // Get the supported language array populated
- if (empty($this->languages)) {
- foreach (glob($this->languages_directory.'/*', GLOB_ONLYDIR) as $path) {
- $path = basename($path);
-
- if ( ! in_array($path, array('.', '..'))) {
- $this->languages[] = $path;
- }
- }
- }
- }
-
- /**
- * Parse the view replacing the variables found in it.
- *
- * @param string $view The name of the view.
- * @param array $any,... optional, Unlimited number of variables to merge with the standard controller view variables.
- *
- * @return string|void
- */
- private function _render_view($view)
- {
- $args = array_slice(func_get_args(), 1);
- $out = array_merge($this->lang->language, array('language_nav' => $this->language_nav));
-
- foreach ($args as $arg) {
- if (is_array($arg)) {
- $out = array_merge($out, $arg);
- }
- }
-
- $this->load->view('global', array(
- 'page_output' => $this->parser->parse($view, $out, true)
- ));
- }
+ $this->_render_view('step_1', (array) $data);
+ }
+
+ /**
+ * Function to test the DB connection (used for the form validation)
+ *
+ * @return bool
+ */
+ public function test_db_connection()
+ {
+ $db_config = array(
+ 'driver' => $this->input->post('db_driver'),
+ 'database' => $this->input->post('database'),
+ 'location' => $this->input->post('location'),
+ 'hostname' => $this->input->post('hostname'),
+ 'port' => $this->input->post('port'),
+ 'username' => $this->input->post('username'),
+ 'password' => $this->input->post('password'),
+ 'create_db' => $this->input->post('create_db'),
+ 'site_ref' => 'default',
+ );
+
+ // Store this for later
+ $this->session->set_userdata('db_config', $db_config);
+
+ try {
+ // Create a connection to see if data is correct
+ $this->installer_lib->create_connection($db_config);
+ } catch (Exception $e) {
+ $this->form_validation->set_message('test_db_connection', lang('db_failure').$e->getMessage());
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * First actual installation step
+ */
+ public function step_2()
+ {
+ // Did the user enter the DB settings ?
+ if ( ! $this->session->userdata('step_1_passed')) {
+ // Set the flashdata message
+ $this->session->set_flashdata('message', lang('step1_failure'));
+ $this->session->set_flashdata('message_type', 'failure');
+
+ redirect('');
+ }
+
+ $data = new stdClass;
+
+ // Check the PHP version
+ $data->php_acceptable = $this->installer_lib->php_acceptable();
+ $data->php_version = PHP_VERSION;
+
+ // Check the GD data
+ $data->gd_acceptable = $this->installer_lib->gd_acceptable();
+ $data->gd_version = $this->installer_lib->gd_version;
+
+ // Check to see if Zlib is enabled
+ $data->zlib_enabled = $this->installer_lib->zlib_available();
+
+ // Check to see if Curl is enabled
+ $data->curl_enabled = $this->installer_lib->curl_available();
+
+ // Get the server
+ $selected_server = $this->session->userdata('http_server');
+ $supported_servers = $this->config->item('supported_servers');
+
+ $data->http_server = new stdClass;
+ $data->http_server->supported = $this->installer_lib->verify_http_server($this->session->userdata('http_server'));
+ $data->http_server->name = @$supported_servers[$selected_server]['name'];
+
+ // Check the final results
+ $data->step_passed = $this->installer_lib->check_server($data);
+
+ // Skip Step 2 if it passes
+ if ($data->step_passed) {
+ $this->session->set_userdata('step_2_passed', true);
+
+ redirect('installer/step_3');
+ }
+
+ $this->session->set_userdata('step_2_passed', $data->step_passed);
+
+ // Load the view files
+
+ $this->_render_view('step_2', (array) $data);
+ }
+
+ /**
+ * Another step, yay!
+ */
+ public function step_3()
+ {
+ if ( ! $this->session->userdata('step_1_passed') OR ! $this->session->userdata('step_2_passed')) {
+ // Redirect the user back to step 1
+ redirect('installer/step_2');
+ }
+
+ // Load the file helper
+ $this->load->helper('file');
+
+ // Get the write permissions for the folders
+ $permissions = array();
+ foreach ($this->writable_directories as $dir) {
+ @chmod('../'.$dir, 0777);
+ $permissions['directories'][$dir] = is_really_writable('../'.$dir);
+ }
+
+ foreach ($this->writable_files as $file) {
+ @chmod('../'.$file, 0666);
+ $permissions['files'][$file] = is_really_writable('../'.$file);
+ }
+
+ $data = array();
+ // If all permissions are TRUE, go ahead
+ $data['step_passed'] = ! in_array(false, $permissions['directories']) && !in_array(false, $permissions['files']);
+ $this->session->set_userdata('step_3_passed', $data['step_passed']);
+
+ // Skip Step 2 if it passes
+ if ($data['step_passed']) {
+ $this->session->set_userdata('step_3_passed', true);
+
+ redirect('installer/step_4');
+ }
+
+ // View variables
+ $data['permissions'] = $permissions;
+
+ $this->_render_view('step_3', $data);
+ }
+
+ /**
+ * Another step, damn thee steps, damn thee!
+ */
+ public function step_4()
+ {
+ if ( ! $this->session->userdata('step_1_passed') OR ! $this->session->userdata('step_2_passed') OR ! $this->session->userdata('step_3_passed')) {
+ // Redirect the user back to step 2
+ redirect('installer/step_2');
+ }
+
+ // Set rules
+ $this->form_validation->set_rules(array(
+ array(
+ 'field' => 'user[username]',
+ 'label' => 'lang:user_name',
+ 'rules' => 'trim|required'
+ ),
+ array(
+ 'field' => 'user[firstname]',
+ 'label' => 'lang:first_name',
+ 'rules' => 'trim|required'
+ ),
+ array(
+ 'field' => 'user[lastname]',
+ 'label' => 'lang:last_name',
+ 'rules' => 'trim|required'
+ ),
+ array(
+ 'field' => 'user[email]',
+ 'label' => 'lang:email',
+ 'rules' => 'trim|required|valid_email'
+ ),
+ array(
+ 'field' => 'user[password]',
+ 'label' => 'lang:password',
+ 'rules' => 'trim|min_length[6]|max_length[20]|required'
+ ),
+ ));
+
+ // If the form validation failed (or did not run)
+ if ($this->form_validation->run() == false) {
+ $this->_render_view('step_4');
+ }
+
+ // If the form validation passed
+ else {
+ // Grab the connection config from the session
+ $db_config = $this->session->userdata('db_config');
+
+ // First User details
+ $user = $this->input->post('user');
+
+ // Create the database if that is what they asked us to do
+ if ( ! empty($db_config['create_db'])) {
+ // Create an PDO connection and instance
+ $pdo = $this->installer_lib->create_connection($db_config);
+
+ // Make the database
+ $this->installer_lib->create_db($pdo, $db_config['database']);
+ }
+
+ // Let's try to install the system with this new PDO instance
+ try {
+ $pdb = $this->installer_lib->install($user, $db_config);
+ } catch (InstallerException $e) {
+
+ $this->_render_view('step_4', array(
+ 'messages' => array(
+ 'error' => $e->getMessage(),
+ )
+ ));
+
+ return;
+ }
+
+ // Success!
+ $this->session->set_flashdata('success', lang('success'));
+
+ // Store the default username and password in the session data
+ $this->session->set_userdata('user', $user);
+
+ // Define the default user email to be used in the settings module install
+ define('DEFAULT_EMAIL', $this->input->post('user_email'));
+
+ // Import the modules
+ $this->load->library('module_import', array(
+ 'pdb' => $pdb,
+ ));
+
+ $this->module_import->import_all();
+
+ $themeManager = new ThemeManager();
+ $themeManager->setLocations(array(
+ PYROPATH.'themes/',
+ ));
+
+ $themeManager->registerUnavailableThemes();
+
+ $widgetManager = new WidgetManager();
+ $widgetManager->setLocations(array(
+ PYROPATH.'widgets/',
+ ));
+ $widgetManager->registerUnavailableWidgets();
+
+ redirect('installer/complete');
+ }
+ }
+
+
+ /**
+ * We're done, thank god for that
+ */
+ public function complete()
+ {
+ // check if we came from step4
+ if ( ! $this->session->userdata('user')) {
+ redirect(site_url());
+ }
+
+ $server_name = $this->session->userdata('http_server');
+ $supported_servers = $this->config->item('supported_servers');
+
+ // Load our user's settings
+ $data = $this->session->userdata('user');
+
+ // Create the admin link
+ $data['website_url'] = 'http://'.$this->input->server('HTTP_HOST').preg_replace('/installer\/index.php$/', '', $this->input->server('SCRIPT_NAME'));
+ $data['control_panel_url'] = $data['website_url'].($supported_servers[$server_name]['rewrite_support'] === true ? 'admin' : 'index.php/admin');
+
+ // Let's remove our session since it contains data we don't want anyone to see
+ $this->session->sess_destroy();
+
+ $this->_render_view('complete', $data);
+ }
+
+ /**
+ * Changes the active language
+ *
+ * @author jeroenvdgulik
+ * @since 0.9.8.1
+ *
+ * @param string $language
+ */
+ public function change($language)
+ {
+ $this->_discover_languages();
+
+ if (in_array($language, $this->languages)) {
+ $this->session->set_userdata('language', $language);
+ }
+
+ redirect('installer');
+ }
+
+ /**
+ * Set up class properties related to translations.
+ *
+ * Populates the supported languages array and sets the
+ * installer translations directory as an absolute path
+ */
+ private function _discover_languages()
+ {
+ // Convert the translation directory path to absolute
+ if ($this->languages_directory === '../language/') {
+ $this->languages_directory = realpath(dirname(__FILE__).'/'.$this->languages_directory);
+ }
+
+ // Get the supported language array populated
+ if (empty($this->languages)) {
+ foreach (glob($this->languages_directory.'/*', GLOB_ONLYDIR) as $path) {
+ $path = basename($path);
+
+ if ( ! in_array($path, array('.', '..'))) {
+ $this->languages[] = $path;
+ }
+ }
+ }
+ }
+
+ /**
+ * Parse the view replacing the variables found in it.
+ *
+ * @param string $view The name of the view.
+ * @param array $any,... optional, Unlimited number of variables to merge with the standard controller view variables.
+ *
+ * @return string|void
+ */
+ private function _render_view($view)
+ {
+ $args = array_slice(func_get_args(), 1);
+ $out = array_merge($this->lang->language, array('language_nav' => $this->language_nav));
+
+ foreach ($args as $arg) {
+ if (is_array($arg)) {
+ $out = array_merge($out, $arg);
+ }
+ }
+
+ $this->load->view('global', array(
+ 'page_output' => $this->parser->parse($view, $out, true)
+ ));
+ }
}
View
564 installer/libraries/Installer_lib.php
@@ -9,218 +9,218 @@
*/
class Installer_lib
{
- /** @const string MIN_PHP_VERSION The minimum PHP version requirement */
- const MIN_PHP_VERSION = '5.3.9';
-
- /** @var string The GD extension version */
- public $gd_version;
-
- /**
- * Function to see if the PHP version is acceptable (at least version 5)
- *
- * @return bool
- */
- public function php_acceptable()
- {
- // Is this version of PHP greater than minimum version required?
- return version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>=');
- }
-
- /**
- * Function to check that MySQL and its PHP module is installed properly
- *
- * @return bool
- */
- public function check_db_extensions()
- {
- $has_pdo = extension_loaded('pdo');
-
- return array(
- 'mysql' => $has_pdo and extension_loaded('pdo_mysql'),
- 'sqlite' => $has_pdo and extension_loaded('pdo_sqlite'),
- 'pgsql' => $has_pdo and extension_loaded('pdo_pgsql'),
- );
- }
-
- /**
- * Check if zlib is installed
- *
- * @return bool
- */
- public function zlib_available()
- {
- return extension_loaded('zlib');
- }
-
- /**
- * Check the CURL is available
- *
- * @return bool
- */
- public function curl_available()
- {
- return function_exists('curl_init');
- }
-
- /**
- * Function to retrieve the GD library version
- *
- * @return string The GD library version.
- */
- public function gd_acceptable()
- {
- // Homeboy is not rockin GD at all
- if ( ! function_exists('gd_info')) {
- return false;
- }
-
- $gd_info = gd_info();
- $this->gd_version = preg_replace('/[^0-9\.]/', '', $gd_info['GD Version']);
-
- // If the GD version is at least 1.0
- return ($this->gd_version >= 1);
- }
-
- /**
- * Function to validate the server settings.
- *
- * @param object $data The data that contains server related information.
- *
- * @return bool
- */
- public function check_server($data)
- {
- // Check PHP
- if ( ! $this->php_acceptable()) {
- return false;
- }
-
- if ($data->http_server->supported === false) {
- return false;
- }
-
- // If PHP, MySQL, etc is good but either server, GD, and/or Zlib is unknown, say partial
- if ($data->http_server->supported === 'partial' or $this->gd_acceptable() === false or $this->zlib_available() === false) {
- return 'partial';
- }
-
- // Must be fine
- return true;
- }
-
- /**
- * Function to validate whether the specified server is a supported server.
- *
- * The function returns an array with two keys: supported and non_apache.
- * The supported key will be set to TRUE whenever the server is supported.
- * The non_apache server will be set to TRUE whenever the user is using a server other than Apache.
- *
- * This enables the system to determine whether mod_rewrite should be used or not.
- *
- * @param string $server_name The name of the HTTP server such as Abyss, Cherokee, Apache, etc
- *
- * @return array
- */
- public function verify_http_server($server_name)
- {
- // Set all the required variables
- if ($server_name == 'other') {
- return 'partial';
- }
-
- $supported_servers = ci()->config->item('supported_servers');
-
- return array_key_exists($server_name, $supported_servers);
- }
-
- /**
- * Make sure we can connect to the database
- *
- * @return PDO
- * @throws InstallerException If connection fails
- */
- public function create_connection($config)
- {
- switch ($config['driver']) {
- case 'mysql':
- case 'pgsql':
- $dsn = "{$config['driver']}:host={$config['hostname']};port={$config['port']}";
- break;
- case 'sqlite':
- $dsn = "sqlite:{$config['location']}";
- break;
- default:
- throw new InstallerException("Unknown database driver type: {$config['driver']}");
- }
-
- // Try and connect, but bitch if error
- return new PDO($dsn, $config['username'], $config['password'], array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ));
- }
-
- /**
- * Make sure we can connect to the database
- *
- * @param PDO $database Array of hostname, username, etc
- * @param array $database Array of hostname, username, etc
- *
- * @return bool
- */
- public function create_db(PDO $conn, $database)
- {
- try {
- return $conn->query("CREATE DATABASE {$database}");
- } catch (PDOException $e) {
-
- // PostgreSQL says this is a duplicate database
- if ($e->getCode() === '42P04') {
- // If this table already exists then great, our work here is done
- return true;
- } else {
- // Unkown issue creating the table
- throw new InstallerException("Unkown issue creating the database: ".$e->getMessage());
- }
- }
- }
-
- /**
- * Install the PyroCMS database and write the database.php file
- *
- * @param array $user The data from the database user form
- * @param array $db The data from the database information form
- *
- * @throws InstallerException
- * @return array
- */
- public function install(array $user, array $db)
- {
- $config = array(
- 'driver' => $db['driver'],
+ /** @const string MIN_PHP_VERSION The minimum PHP version requirement */
+ const MIN_PHP_VERSION = '5.3.9';
+
+ /** @var string The GD extension version */
+ public $gd_version;
+
+ /**
+ * Function to see if the PHP version is acceptable (at least version 5)
+ *
+ * @return bool
+ */
+ public function php_acceptable()
+ {
+ // Is this version of PHP greater than minimum version required?
+ return version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>=');
+ }
+
+ /**
+ * Function to check that MySQL and its PHP module is installed properly
+ *
+ * @return bool
+ */
+ public function check_db_extensions()
+ {
+ $has_pdo = extension_loaded('pdo');
+
+ return array(
+ 'mysql' => $has_pdo and extension_loaded('pdo_mysql'),
+ 'sqlite' => $has_pdo and extension_loaded('pdo_sqlite'),
+ 'pgsql' => $has_pdo and extension_loaded('pdo_pgsql'),
+ );
+ }
+
+ /**
+ * Check if zlib is installed
+ *
+ * @return bool
+ */
+ public function zlib_available()
+ {
+ return extension_loaded('zlib');
+ }
+
+ /**
+ * Check the CURL is available
+ *
+ * @return bool
+ */
+ public function curl_available()
+ {
+ return function_exists('curl_init');
+ }
+
+ /**
+ * Function to retrieve the GD library version
+ *
+ * @return string The GD library version.
+ */
+ public function gd_acceptable()
+ {
+ // Homeboy is not rockin GD at all
+ if ( ! function_exists('gd_info')) {
+ return false;
+ }
+
+ $gd_info = gd_info();
+ $this->gd_version = preg_replace('/[^0-9\.]/', '', $gd_info['GD Version']);
+
+ // If the GD version is at least 1.0
+ return ($this->gd_version >= 1);
+ }
+
+ /**
+ * Function to validate the server settings.
+ *
+ * @param object $data The data that contains server related information.
+ *
+ * @return bool
+ */
+ public function check_server($data)
+ {
+ // Check PHP
+ if ( ! $this->php_acceptable()) {
+ return false;
+ }
+
+ if ($data->http_server->supported === false) {
+ return false;
+ }
+
+ // If PHP, MySQL, etc is good but either server, GD, and/or Zlib is unknown, say partial
+ if ($data->http_server->supported === 'partial' or $this->gd_acceptable() === false or $this->zlib_available() === false) {
+ return 'partial';
+ }
+
+ // Must be fine
+ return true;
+ }
+
+ /**
+ * Function to validate whether the specified server is a supported server.
+ *
+ * The function returns an array with two keys: supported and non_apache.
+ * The supported key will be set to TRUE whenever the server is supported.
+ * The non_apache server will be set to TRUE whenever the user is using a server other than Apache.
+ *
+ * This enables the system to determine whether mod_rewrite should be used or not.
+ *
+ * @param string $server_name The name of the HTTP server such as Abyss, Cherokee, Apache, etc
+ *
+ * @return array
+ */
+ public function verify_http_server($server_name)
+ {
+ // Set all the required variables
+ if ($server_name == 'other') {
+ return 'partial';
+ }
+
+ $supported_servers = ci()->config->item('supported_servers');
+
+ return array_key_exists($server_name, $supported_servers);
+ }
+
+ /**
+ * Make sure we can connect to the database
+ *
+ * @return PDO
+ * @throws InstallerException If connection fails
+ */
+ public function create_connection($config)
+ {
+ switch ($config['driver']) {
+ case 'mysql':
+ case 'pgsql':
+ $dsn = "{$config['driver']}:host={$config['hostname']};port={$config['port']}";
+ break;
+ case 'sqlite':
+ $dsn = "sqlite:{$config['location']}";
+ break;
+ default:
+ throw new InstallerException("Unknown database driver type: {$config['driver']}");
+ }
+
+ // Try and connect, but bitch if error
+ return new PDO($dsn, $config['username'], $config['password'], array(
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
+ ));
+ }
+
+ /**
+ * Make sure we can connect to the database
+ *
+ * @param PDO $database Array of hostname, username, etc
+ * @param array $database Array of hostname, username, etc
+ *
+ * @return bool
+ */
+ public function create_db(PDO $conn, $database)
+ {
+ try {
+ return $conn->query("CREATE DATABASE {$database}");
+ } catch (PDOException $e) {
+
+ // PostgreSQL says this is a duplicate database
+ if ($e->getCode() === '42P04') {
+ // If this table already exists then great, our work here is done
+ return true;
+ } else {
+ // Unkown issue creating the table
+ throw new InstallerException("Unkown issue creating the database: ".$e->getMessage());
+ }
+ }
+ }
+
+ /**
+ * Install the PyroCMS database and write the database.php file
+ *
+ * @param array $user The data from the database user form
+ * @param array $db The data from the database information form
+ *
+ * @throws InstallerException
+ * @return array
+ */
+ public function install(array $user, array $db)
+ {
+ $config = array(
+ 'driver' => $db['driver'],
'password' => $db["password"],
- 'prefix' => '',
- 'charset' => "utf8",
- 'collation' => "utf8_unicode_ci",
- );
-
- // Create a connection
- switch ($db['driver']) {
- case 'mysql':
- case 'pgsql':
- $config['host'] = $db['hostname'];
- $config['port'] = $db['port'];
- $config['username'] = $db["username"];
- $config['database'] = $db["database"];
- break;
- case 'sqlite':
- $config['database'] = $db['location'];
- break;
- default:
- throw new InstallerException("Unknown database driver type: {$db['driver']}");
- break;
- }
-
- $capsule = new Capsule;
+ 'prefix' => '',
+ 'charset' => "utf8",
+ 'collation' => "utf8_unicode_ci",
+ );
+
+ // Create a connection
+ switch ($db['driver']) {
+ case 'mysql':
+ case 'pgsql':
+ $config['host'] = $db['hostname'];
+ $config['port'] = $db['port'];
+ $config['username'] = $db["username"];
+ $config['database'] = $db["database"];
+ break;
+ case 'sqlite':
+ $config['database'] = $db['location'];
+ break;
+ default:
+ throw new InstallerException("Unknown database driver type: {$db['driver']}");
+ break;
+ }
+
+ $capsule = new Capsule;
$capsule->addConnection($config);
$container = $capsule->getContainer();
@@ -233,84 +233,84 @@ public function install(array $user, array $db)
$capsule->setCacheManager(ci()->cache);
- // Set the fetch mode FETCH_CLASS so we
+ // Set the fetch mode FETCH_CLASS so we
// get objects back by default.
$capsule->setFetchMode(PDO::FETCH_CLASS);
-
+
$capsule->bootEloquent();
-
+
$capsule->setAsGlobal();
- // Connect using the Laravel Database component
+ // Connect using the Laravel Database component
$conn = $capsule->connection();
- ci()->load->model('install_m');
-
- // Basic installation done with this PDO connection
- ci()->install_m->set_default_structure($conn, $user, $db);
-
- // Write the database file
- if ( ! $this->write_db_file($db)) {
- throw new InstallerException('Failed to write database.php file.');
- }
-
- // Write the config file.
- if ( ! $this->write_config_file()) {
- throw new InstallerException('Failed to write config.php file.');
- }
-
- return $conn;
- }
-
- /**
- * Writes the database file based on the provided database settings
- *
- * @param array $db The database connection information
- */
- public function write_db_file($db)
- {
- $replace = array(
- '{driver}' => $db['driver'],
- '{hostname}' => $db['hostname'],
- '{port}' => $db['port'],
- '{database}' => $db['database'],
- '{username}' => $db['username'],
- '{password}' => $db['password']
- );
-
- return $this->_write_file_vars('../system/cms/config/database.php', './assets/config/database.php', $replace);
- }
-
- /**
- * Writes the config file.n
- *
- * @return bool
- */
- public function write_config_file()
- {
- $server_name = ci()->session->userdata('http_server');
- $supported_servers = ci()->config->item('supported_servers');
-
- // Able to use clean URLs?
- $index_page = ($supported_servers[$server_name]['rewrite_support'] !== false) ? '' : 'index.php';
-
- return $this->_write_file_vars('../system/cms/config/config.php', './assets/config/config.php', array('{index}' => $index_page));
- }
-
- /**
- * Write a file by replacing the placeholders found in a template file with values provided.
- *
- * @param string $destination The path to where the file should be written.
- * @param string $template The path to the template file.
- * @param array $replacements Contains 'placeholder => value' pairs for the replacements
- *
- * @return bool
- */
- private function _write_file_vars($destination, $template, $replacements)
- {
- $str = str_replace(array_keys($replacements), $replacements, file_get_contents($template));
- return (file_put_contents($destination, $str) !== false);
- }
+ ci()->load->model('install_m');
+
+ // Basic installation done with this PDO connection
+ ci()->install_m->set_default_structure($conn, $user, $db);
+
+ // Write the database file
+ if ( ! $this->write_db_file($db)) {
+ throw new InstallerException('Failed to write database.php file.');
+ }
+
+ // Write the config file.
+ if ( ! $this->write_config_file()) {
+ throw new InstallerException('Failed to write config.php file.');
+ }
+
+ return $conn;
+ }
+
+ /**
+ * Writes the database file based on the provided database settings
+ *
+ * @param array $db The database connection information
+ */
+ public function write_db_file($db)
+ {
+ $replace = array(
+ '{driver}' => $db['driver'],
+ '{hostname}' => $db['hostname'],
+ '{port}' => $db['port'],
+ '{database}' => $db['database'],
+ '{username}' => $db['username'],
+ '{password}' => $db['password']
+ );
+
+ return $this->_write_file_vars('../system/cms/config/database.php', './assets/config/database.php', $replace);
+ }
+
+ /**
+ * Writes the config file.n
+ *
+ * @return bool
+ */
+ public function write_config_file()
+ {
+ $server_name = ci()->session->userdata('http_server');
+ $supported_servers = ci()->config->item('supported_servers');
+
+ // Able to use clean URLs?
+ $index_page = ($supported_servers[$server_name]['rewrite_support'] !== false) ? '' : 'index.php';
+
+ return $this->_write_file_vars('../system/cms/config/config.php', './assets/config/config.php', array('{index}' => $index_page));
+ }
+
+ /**
+ * Write a file by replacing the placeholders found in a template file with values provided.
+ *
+ * @param string $destination The path to where the file should be written.
+ * @param string $template The path to the template file.
+ * @param array $replacements Contains 'placeholder => value' pairs for the replacements
+ *
+ * @return bool
+ */
+ private function _write_file_vars($destination, $template, $replacements)
+ {
+ $str = str_replace(array_keys($replacements), $replacements, file_get_contents($template));
+ return (file_put_contents($destination, $str) !== false);
+ }
}
View
466 installer/libraries/Module_import.php
@@ -7,250 +7,250 @@
class Module_import
{
- public function __construct(array $params)
- {
- ci()->pdb = $this->pdb = $params['pdb'];
-
- // Make sure folders exist for addon structure
- $this->buildFolderStructure(ADDONPATH, dirname(FCPATH));
-
- // Lets PSR-0 up our modules
- $this->registerAutoloader(new ClassLoader, realpath(PYROPATH), true);
- }
-
- /**
- * Build folder structure
- * Creates folders if they are missing for modules, themes, widgets, etc
- *
- * @param string $app_path The location of the PyroCMS application folder
- * @param string $base_path The location of the root of the PyroCMS installation
- */
- public function buildFolderStructure($app_path, $base_path)
- {
- // create the site specific addon folder
- is_dir($app_path.'modules') or mkdir($app_path.'modules', DIR_READ_MODE, true);
- is_dir($app_path.'themes') or mkdir($app_path.'themes', DIR_READ_MODE, true);
- is_dir($app_path.'widgets') or mkdir($app_path.'widgets', DIR_READ_MODE, true);
- is_dir($app_path.'field_types') or mkdir($app_path.'field_types', DIR_READ_MODE, true);
-
- // create the site specific upload folder
- if ( ! is_dir($base_path.'/uploads/default')) {
- mkdir($base_path.'/uploads/default', DIR_WRITE_MODE, true);
- }
- }
-
- /**
- * Register Autoloader
- *
- * @param Composer\Autoload\ClassLoader $loader Instance of the Composer autoloader
- * @param string $app_path The location of the PyroCMS application folder
- *
- * @return Composer\Autoload\ClassLoader
- */
- public function registerAutoloader(ClassLoader $loader, $app_path, $is_core = false)
- {
- $loader->add('Pyro\\Module\\Addons', $app_path.'/modules/addons/src/');
- $loader->add('Pyro\\Module\\Streams_core', $app_path.'/modules/streams_core/src/');
- $loader->add('Pyro\\Module\\Streams', $app_path.'/modules/streams_core/src/');
-
- $slugs = array();
-
- // Go through EVERY module and register its src folder
+ public function __construct(array $params)
+ {
+ ci()->pdb = $this->pdb = $params['pdb'];
+
+ // Make sure folders exist for addon structure
+ $this->buildFolderStructure(ADDONPATH, dirname(FCPATH));
+
+ // Lets PSR-0 up our modules
+ $this->registerAutoloader(new ClassLoader, realpath(PYROPATH), true);
+ }
+
+ /**
+ * Build folder structure
+ * Creates folders if they are missing for modules, themes, widgets, etc
+ *
+ * @param string $app_path The location of the PyroCMS application folder
+ * @param string $base_path The location of the root of the PyroCMS installation
+ */
+ public function buildFolderStructure($app_path, $base_path)
+ {
+ // create the site specific addon folder
+ is_dir($app_path.'modules') or mkdir($app_path.'modules', DIR_READ_MODE, true);
+ is_dir($app_path.'themes') or mkdir($app_path.'themes', DIR_READ_MODE, true);
+ is_dir($app_path.'widgets') or mkdir($app_path.'widgets', DIR_READ_MODE, true);
+ is_dir($app_path.'field_types') or mkdir($app_path.'field_types', DIR_READ_MODE, true);
+
+ // create the site specific upload folder
+ if ( ! is_dir($base_path.'/uploads/default')) {
+ mkdir($base_path.'/uploads/default', DIR_WRITE_MODE, true);
+ }
+ }
+
+ /**
+ * Register Autoloader
+ *
+ * @param Composer\Autoload\ClassLoader $loader Instance of the Composer autoloader
+ * @param string $app_path The location of the PyroCMS application folder
+ *
+ * @return Composer\Autoload\ClassLoader
+ */
+ public function registerAutoloader(ClassLoader $loader, $app_path, $is_core = false)
+ {
+ $loader->add('Pyro\\Module\\Addons', $app_path.'/modules/addons/src/');
+ $loader->add('Pyro\\Module\\Streams_core', $app_path.'/modules/streams_core/src/');
+ $loader->add('Pyro\\Module\\Streams', $app_path.'/modules/streams_core/src/');
+
+ $slugs = array();
+
+ // Go through EVERY module and register its src folder
foreach (glob("{$app_path}/modules/*/src/", GLOB_ONLYDIR) as $dir) {
- // Turn 'modules/blog/src/' into 'blog'
- $slugs[] = $slug = basename(dirname($dir));
+ // Turn 'modules/blog/src/' into 'blog'
+ $slugs[] = $slug = basename(dirname($dir));
- // That 'blog' should now be 'Pyro\Module\Blog'
- $namespace = 'Pyro\\Module\\'.ucfirst($slug);
+ // That 'blog' should now be 'Pyro\Module\Blog'
+ $namespace = 'Pyro\\Module\\'.ucfirst($slug);
- $loader->add($namespace, $dir);
- }
+ $loader->add($namespace, $dir);
+ }
// activate the autoloader
$loader->register();
- foreach ($slugs as $slug) {
-
- if ($details_class = $this->spawnClass($slug, $is_core)) {
+ foreach ($slugs as $slug) {
- $module_info = $details_class->info();
+ if ($details_class = $this->spawnClass($slug, $is_core)) {
- $field_types = isset($module_info['field_types']) ? $module_info['field_types'] : false;
+ $module_info = $details_class->info();
- FieldTypeManager::registerFolderFieldTypes("{$app_path}/modules/{$slug}/field_types/", $field_types);
- }
- }
+ $field_types = isset($module_info['field_types']) ? $module_info['field_types'] : false;
+
+ FieldTypeManager::registerFolderFieldTypes("{$app_path}/modules/{$slug}/field_types/", $field_types);
+ }
+ }
return $loader;
- }
-
- /**
- * Installs a module
- *
- * @param string $slug The module slug
- * @param bool $is_core
- *
- * @return bool
- */
- public function install($slug, $is_core = false)
- {
- if ( ! ($details_class = $this->spawnClass($slug, $is_core))) {
- exit("The module $slug is missing a details.php");
- }
-
- // Get some basic info
- $module = $details_class->info();
-
- // Now lets set some details ourselves
- $module['version'] = $details_class->version;
- $module['is_core'] = $is_core;
- $module['enabled'] = true;
- $module['installed'] = true;
- $module['slug'] = $slug;
-
- // set the site_ref and upload_path for third-party devs
- $details_class->site_ref = 'default';
- $details_class->upload_path = 'uploads/default/';
-
- // Run the install method to get it into the database
- // try
- // {
- $details_class->install($this->pdb, $this->pdb->getSchemaBuilder());
- // }
- // catch (Exception $e)
- // {
- // // TODO Do something useful
- // exit('HEY '.$e->getMessage()." in ".$e->getFile()."<br />");
-
- // return false;
- // }
-
- // Looks like it installed ok, add a record
- return $this->add($module);
- }
-
- /**
- * Add
- *
- * Insert the database record for a single module
- *
- * @param array Array of module informaiton.
- * @return boolean
- */
- public function add($module)
- {
- return $this->pdb
- ->table('modules')
- ->insert(array(
- 'name' => serialize($module['name']),
- 'slug' => $module['slug'],
- 'version' => $module['version'],
- 'description' => serialize($module['description']),