Mage_Install_Model_Installer_Console Class Reference

Inheritance diagram for Mage_Install_Model_Installer_Console:

Mage_Install_Model_Installer_Abstract

List of all members.

Public Member Functions

 setArgs ($args=null)
 addError ($error)
 hasErrors ()
 getErrors ()
 getEncryptionKey ()
 init (Mage_Core_Model_App $app)
 install ()
 printOptions ()
 checkConsole ($url=null)

Protected Member Functions

 _getOptions ()
 _checkFlag ($value)
 _getDataModel ()
 _prepareData ()

Protected Attributes

 $_options
 $_args = array()
 $_dataModel
 $_app


Detailed Description

Definition at line 34 of file Console.php.


Member Function Documentation

_checkFlag ( value  )  [protected]

Check flag value

Returns true for 'yes', 1, 'true' Case insensitive

Parameters:
string $value
Returns:
boolean

Definition at line 216 of file Console.php.

00217     {
00218         $res = (1 == $value)
00219             || preg_match('/^(yes|y|true)$/i', $value);
00220         return $res;
00221     }

_getDataModel (  )  [protected]

Get data model (used to store data between installation steps

Returns:
Mage_Install_Model_Installer_Data

Definition at line 228 of file Console.php.

00229     {
00230         if (is_null($this->_dataModel)) {
00231             $this->_dataModel = Mage::getModel('install/installer_data');
00232         }
00233         return $this->_dataModel;
00234     }

_getOptions (  )  [protected]

Get available options list

Returns:
array

Definition at line 70 of file Console.php.

00071     {
00072         if (is_null($this->_options)) {
00073             $this->_options = array(
00074                 'license_agreement_accepted'    => array('required' => true, 'comment' => ''),
00075                 'locale'              => array('required' => true, 'comment' => ''),
00076                 'timezone'            => array('required' => true, 'comment' => ''),
00077                 'default_currency'    => array('required' => true, 'comment' => ''),
00078                 'db_host'             => array('required' => true, 'comment' => ''),
00079                 'db_name'             => array('required' => true, 'comment' => ''),
00080                 'db_user'             => array('required' => true, 'comment' => ''),
00081                 'db_pass'             => array('comment' => ''),
00082                 'db_prefix'           => array('comment' => ''),
00083                 'url'                 => array('required' => true, 'comment' => ''),
00084                 'skip_url_validation' => array('comment' => ''),
00085                 'use_rewrites'      => array('required' => true, 'comment' => ''),
00086                 'use_secure'        => array('required' => true, 'comment' => ''),
00087                 'secure_base_url'   => array('required' => true, 'comment' => ''),
00088                 'use_secure_admin'  => array('required' => true, 'comment' => ''),
00089                 'admin_lastname'    => array('required' => true, 'comment' => ''),
00090                 'admin_firstname'   => array('required' => true, 'comment' => ''),
00091                 'admin_email'       => array('required' => true, 'comment' => ''),
00092                 'admin_username'    => array('required' => true, 'comment' => ''),
00093                 'admin_password'    => array('required' => true, 'comment' => ''),
00094                 'encryption_key'    => array('comment' => ''),
00095                 'session_save'      => array('comment' => ''),
00096                 'admin_frontname'   => array('comment' => ''),
00097             );
00098         }
00099         return $this->_options;
00100     }

_prepareData (  )  [protected]

Prepare data ans save it in data model

Returns:
Mage_Install_Model_Installer_Console

Locale settings

Database and web config

Primary admin user

Definition at line 273 of file Console.php.

00274     {
00275         /**
00276          * Locale settings
00277          */
00278         $this->_getDataModel()->setLocaleData(array(
00279             'locale'            => $this->_args['locale'],
00280             'timezone'          => $this->_args['timezone'],
00281             'currency'          => $this->_args['default_currency'],
00282         ));
00283 
00284         /**
00285          * Database and web config
00286          */
00287         $this->_getDataModel()->setConfigData(array(
00288             'db_host'             => $this->_args['db_host'],
00289             'db_name'             => $this->_args['db_name'],
00290             'db_user'             => $this->_args['db_user'],
00291             'db_pass'             => $this->_args['db_pass'],
00292             'db_prefix'           => $this->_args['db_prefix'],
00293             'use_rewrites'        => $this->_checkFlag($this->_args['use_rewrites']),
00294             'use_secure'          => $this->_checkFlag($this->_args['use_secure']),
00295             'unsecure_base_url'   => $this->_args['url'],
00296             'secure_base_url'     => $this->_args['secure_base_url'],
00297             'use_secure_admin'    => $this->_checkFlag($this->_args['use_secure_admin']),
00298             'session_save'        => $this->_checkSessionSave($this->_args['session_save']),
00299             'admin_frontname'     => $this->_checkAdminFrontname($this->_args['admin_frontname']),
00300             'skip_url_validation' => $this->_checkFlag($this->_args['skip_url_validation']),
00301         ));
00302 
00303         /**
00304          * Primary admin user
00305          */
00306         $this->_getDataModel()->setAdminData(array(
00307             'firstname'         => $this->_args['admin_firstname'],
00308             'lastname'          => $this->_args['admin_lastname'],
00309             'email'             => $this->_args['admin_email'],
00310             'username'          => $this->_args['admin_username'],
00311             'password'          => $this->_args['admin_password'],
00312         ));
00313 
00314         return $this;
00315     }

addError ( error  ) 

Add error

Parameters:
string $error
Returns:
Mage_Install_Model_Installer_Console

Definition at line 181 of file Console.php.

00182     {
00183         $this->_getDataModel()->addError($error);
00184         return $this;
00185     }

checkConsole ( url = null  ) 

Check if installer is run in shell, and redirect if run on web

Parameters:
string $url fallback url to redirect to
Returns:
boolean

Definition at line 441 of file Console.php.

00442     {
00443         if (defined('STDIN') && defined('STDOUT') && (defined('STDERR'))) {
00444             return true;
00445         }
00446         if (is_null($url)) {
00447             $url = preg_replace('/install\.php/i', '', Mage::getBaseUrl());
00448             $url = preg_replace('/\/\/$/', '/', $url);
00449         }
00450         header('Location: ' . $url);
00451         return false;
00452     }

getEncryptionKey (  ) 

Get encryption key from data model

Returns:
string

Definition at line 241 of file Console.php.

00242     {
00243         return $this->_getDataModel()->getEncryptionKey();
00244     }

getErrors (  ) 

Get all errors

Returns:
array

Definition at line 202 of file Console.php.

00203     {
00204         return $this->_getDataModel()->getErrors();
00205     }

hasErrors (  ) 

Check if there were any errors

Returns:
boolean

Definition at line 192 of file Console.php.

00193     {
00194         return (count($this->_getDataModel()->getErrors()) > 0);
00195     }

init ( Mage_Core_Model_App app  ) 

Init installation

Parameters:
Mage_Core_Model_App $app
Returns:
boolean

Check if already installed

Definition at line 252 of file Console.php.

00253     {
00254         $this->_app = $app;
00255         $this->_getInstaller()->setDataModel($this->_getDataModel());
00256 
00257         /**
00258          * Check if already installed
00259          */
00260         if (Mage::isInstalled()) {
00261             $this->addError('ERROR: Magento is already installed');
00262             return false;
00263         }
00264 
00265         return true;
00266     }

install (  ) 

Install Magento

Returns:
boolean

Check if already installed

Skip URL validation, if set

Prepare data

Install configuration

Reinitialize configuration (to use new config data)

Install database

Create primary administrator user

Save encryption key or create if empty

Installation finish

Change directories mode to be writable by apache user

Definition at line 322 of file Console.php.

00323     {
00324         try {
00325 
00326             /**
00327              * Check if already installed
00328              */
00329             if (Mage::isInstalled()) {
00330                 $this->addError('ERROR: Magento is already installed');
00331                 return false;
00332             }
00333 
00334             /**
00335              * Skip URL validation, if set
00336              */
00337             $this->_getDataModel()->setSkipUrlValidation($this->_args['skip_url_validation']);
00338             $this->_getDataModel()->setSkipBaseUrlValidation($this->_args['skip_url_validation']);
00339 
00340             /**
00341              * Prepare data
00342              */
00343             $this->_prepareData();
00344 
00345             if ($this->hasErrors()) {
00346                 return false;
00347             }
00348 
00349             $installer = $this->_getInstaller();
00350 
00351             /**
00352              * Install configuration
00353              */
00354             $installer->installConfig($this->_getDataModel()->getConfigData()); // TODO fix wizard and simplify this everythere
00355 
00356             if ($this->hasErrors()) {
00357                 return false;
00358             }
00359 
00360             /**
00361              * Reinitialize configuration (to use new config data)
00362              */
00363 
00364             $this->_app->cleanCache();
00365             Mage::getConfig()->reinit();
00366 
00367             /**
00368              * Install database
00369              */
00370             $installer->installDb();
00371 
00372             if ($this->hasErrors()) {
00373                 return false;
00374             }
00375 
00376             /**
00377              * Create primary administrator user
00378              */
00379             $installer->createAdministrator($this->_getDataModel()->getAdminData());
00380 
00381             if ($this->hasErrors()) {
00382                 return false;
00383             }
00384 
00385             /**
00386              * Save encryption key or create if empty
00387              */
00388             $encryptionKey = empty($this->_args['encryption_key']) ? md5(time()) : $this->_args['encryption_key'];
00389             $this->_getDataModel()->setEncryptionKey($encryptionKey);
00390             $installer->installEnryptionKey($encryptionKey);
00391 
00392             if ($this->hasErrors()) {
00393                 return false;
00394             }
00395 
00396             /**
00397              * Installation finish
00398              */
00399             $installer->finish();
00400 
00401             if ($this->hasErrors()) {
00402                 return false;
00403             }
00404 
00405             /**
00406              * Change directories mode to be writable by apache user
00407              */
00408             @chmod('var/cache', 0777);
00409             @chmod('var/session', 0777);
00410 
00411         } catch (Exception $e) {
00412             $this->addError('ERROR: ' . $e->getMessage());
00413             return false;
00414         }
00415 
00416         return true;
00417     }

printOptions (  ) 

Print available currency, locale and timezone options

Returns:
Mage_Install_Model_Installer_Console

Definition at line 424 of file Console.php.

00425     {
00426         $options = array(
00427             'locale'    => $this->_app->getLocale()->getOptionLocales(),
00428             'currency'  => $this->_app->getLocale()->getOptionCurrencies(),
00429             'timezone'  => $this->_app->getLocale()->getOptionTimezones(),
00430         );
00431         var_export($options);
00432         return $this;
00433     }

setArgs ( args = null  ) 

Set and validate arguments

Parameters:
array $args
Returns:
boolean

Parse arguments

Check required arguments

Validate license aggreement acceptance

Set args values

Definition at line 108 of file Console.php.

00109     {
00110         if (empty($args)) {
00111             // take server args
00112             $args = $_SERVER['argv'];
00113         }
00114 
00115         /**
00116          * Parse arguments
00117          */
00118         $currentArg = false;
00119         $match = false;
00120         foreach ($args as $arg) {
00121             if (preg_match('/^--(.*)$/', $arg, $match)) {
00122                 // argument name
00123                 $currentArg = $match[1];
00124                 // in case if argument doen't need a value
00125                 $args[$currentArg] = true;
00126             } else {
00127                 // argument value
00128                 if ($currentArg) {
00129                     $args[$currentArg] = $arg;
00130                 }
00131                 $currentArg = false;
00132             }
00133         }
00134 
00135         if (isset($args['get_options'])) {
00136             $this->printOptions();
00137             return false;
00138         }
00139 
00140         /**
00141          * Check required arguments
00142          */
00143         foreach ($this->_getOptions() as $name => $option) {
00144             if (isset($option['required']) && $option['required'] && !isset($args[$name])) {
00145                 $error = 'ERROR: ' . 'You should provide the value for --' . $name .' parameter';
00146                 if (!empty($option['comment'])) {
00147                     $error .= ': ' . $option['comment'];
00148                 }
00149                 $this->addError($error);
00150             }
00151         }
00152 
00153         if ($this->hasErrors()) {
00154             return false;
00155         }
00156 
00157         /**
00158          * Validate license aggreement acceptance
00159          */
00160         if (!$this->_checkFlag($args['license_agreement_accepted'])) {
00161             $this->addError('ERROR: You have to accept Magento license agreement terms and conditions to continue installation');
00162             return false;
00163         }
00164 
00165         /**
00166          * Set args values
00167          */
00168         foreach ($this->_getOptions() as $name => $option) {
00169             $this->_args[$name] = isset($args[$name]) ? $args[$name] : '';
00170         }
00171 
00172         return true;
00173     }


Member Data Documentation

$_app [protected]

Definition at line 63 of file Console.php.

$_args = array() [protected]

Definition at line 49 of file Console.php.

$_dataModel [protected]

Definition at line 56 of file Console.php.

$_options [protected]

Definition at line 42 of file Console.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:27 2009 for Magento by  doxygen 1.5.8