Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Install_Block_Abstract
  • Mage_Install_Block_Admin
  • Mage_Install_Block_Begin
  • Mage_Install_Block_Config
  • Mage_Install_Block_Db_Main
  • Mage_Install_Block_Db_Type
  • Mage_Install_Block_Db_Type_Mysql4
  • Mage_Install_Block_Download
  • Mage_Install_Block_End
  • Mage_Install_Block_Locale
  • Mage_Install_Block_State
  • Mage_Install_Controller_Action
  • Mage_Install_Helper_Data
  • Mage_Install_IndexController
  • Mage_Install_Model_Config
  • Mage_Install_Model_Installer
  • Mage_Install_Model_Installer_Abstract
  • Mage_Install_Model_Installer_Config
  • Mage_Install_Model_Installer_Console
  • Mage_Install_Model_Installer_Data
  • Mage_Install_Model_Installer_Db
  • Mage_Install_Model_Installer_Db_Abstract
  • Mage_Install_Model_Installer_Db_Mysql4
  • Mage_Install_Model_Installer_Env
  • Mage_Install_Model_Installer_Filesystem
  • Mage_Install_Model_Installer_Pear
  • Mage_Install_Model_Observer
  • Mage_Install_Model_Session
  • Mage_Install_Model_Wizard
  • Mage_Install_WizardController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Install
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Console installer
 30:  * @category   Mage
 31:  * @package    Mage_Install
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Install_Model_Installer_Console extends Mage_Install_Model_Installer_Abstract
 35: {
 36: 
 37:     /**
 38:      * Available options
 39:      *
 40:      * @var array
 41:      */
 42:     protected $_options;
 43: 
 44:     /**
 45:      * Script arguments
 46:      *
 47:      * @var array
 48:      */
 49:     protected $_args = array();
 50: 
 51:     /**
 52:      * Installer data model to store data between installations steps
 53:      *
 54:      * @var Mage_Install_Model_Installer_Data|Mage_Install_Model_Session
 55:      */
 56:     protected $_dataModel;
 57: 
 58:     /**
 59:      * Current application
 60:      *
 61:      * @var Mage_Core_Model_App
 62:      */
 63:     protected $_app;
 64: 
 65:     /**
 66:      * Get available options list
 67:      *
 68:      * @return array
 69:      */
 70:     protected function _getOptions()
 71:     {
 72:         if (is_null($this->_options)) {
 73:             $this->_options = array(
 74:                 'license_agreement_accepted'    => array('required' => true, 'comment' => ''),
 75:                 'locale'              => array('required' => true, 'comment' => ''),
 76:                 'timezone'            => array('required' => true, 'comment' => ''),
 77:                 'default_currency'    => array('required' => true, 'comment' => ''),
 78:                 'db_model'            => array('comment' => ''),
 79:                 'db_host'             => array('required' => true, 'comment' => ''),
 80:                 'db_name'             => array('required' => true, 'comment' => ''),
 81:                 'db_user'             => array('required' => true, 'comment' => ''),
 82:                 'db_pass'             => array('comment' => ''),
 83:                 'db_prefix'           => array('comment' => ''),
 84:                 'url'                 => array('required' => true, 'comment' => ''),
 85:                 'skip_url_validation' => array('comment' => ''),
 86:                 'use_rewrites'      => array('required' => true, 'comment' => ''),
 87:                 'use_secure'        => array('required' => true, 'comment' => ''),
 88:                 'secure_base_url'   => array('required' => true, 'comment' => ''),
 89:                 'use_secure_admin'  => array('required' => true, 'comment' => ''),
 90:                 'admin_lastname'    => array('required' => true, 'comment' => ''),
 91:                 'admin_firstname'   => array('required' => true, 'comment' => ''),
 92:                 'admin_email'       => array('required' => true, 'comment' => ''),
 93:                 'admin_username'    => array('required' => true, 'comment' => ''),
 94:                 'admin_password'    => array('required' => true, 'comment' => ''),
 95:                 'encryption_key'    => array('comment' => ''),
 96:                 'session_save'      => array('comment' => ''),
 97:                 'admin_frontname'   => array('comment' => ''),
 98:                 'enable_charts'     => array('comment' => ''),
 99:             );
100:         }
101:         return $this->_options;
102:     }
103: 
104:     /**
105:      * Set and validate arguments
106:      *
107:      * @param array $args
108:      * @return boolean
109:      */
110:     public function setArgs($args = null)
111:     {
112:         if (empty($args)) {
113:             // take server args
114:             $args = $_SERVER['argv'];
115:         }
116: 
117:         /**
118:          * Parse arguments
119:          */
120:         $currentArg = false;
121:         $match = false;
122:         foreach ($args as $arg) {
123:             if (preg_match('/^--(.*)$/', $arg, $match)) {
124:                 // argument name
125:                 $currentArg = $match[1];
126:                 // in case if argument doen't need a value
127:                 $args[$currentArg] = true;
128:             } else {
129:                 // argument value
130:                 if ($currentArg) {
131:                     $args[$currentArg] = $arg;
132:                 }
133:                 $currentArg = false;
134:             }
135:         }
136: 
137:         if (isset($args['get_options'])) {
138:             $this->printOptions();
139:             return false;
140:         }
141: 
142:         /**
143:          * Check required arguments
144:          */
145:         foreach ($this->_getOptions() as $name => $option) {
146:             if (isset($option['required']) && $option['required'] && !isset($args[$name])) {
147:                 $error = 'ERROR: ' . 'You should provide the value for --' . $name . ' parameter';
148:                 if (!empty($option['comment'])) {
149:                     $error .= ': ' . $option['comment'];
150:                 }
151:                 $this->addError($error);
152:             }
153:         }
154: 
155:         if ($this->hasErrors()) {
156:             return false;
157:         }
158: 
159:         /**
160:          * Validate license aggreement acceptance
161:          */
162:         if (!$this->_checkFlag($args['license_agreement_accepted'])) {
163:             $this->addError('ERROR: You have to accept Magento license agreement terms and conditions to continue installation');
164:             return false;
165:         }
166: 
167:         /**
168:          * Set args values
169:          */
170:         foreach ($this->_getOptions() as $name => $option) {
171:             $this->_args[$name] = isset($args[$name]) ? $args[$name] : '';
172:         }
173: 
174:         return true;
175:     }
176: 
177:     /**
178:      * Add error
179:      *
180:      * @param string $error
181:      * @return Mage_Install_Model_Installer_Console
182:      */
183:     public function addError($error)
184:     {
185:         $this->_getDataModel()->addError($error);
186:         return $this;
187:     }
188: 
189:     /**
190:      * Check if there were any errors
191:      *
192:      * @return boolean
193:      */
194:     public function hasErrors()
195:     {
196:         return (count($this->_getDataModel()->getErrors()) > 0);
197:     }
198: 
199:     /**
200:      * Get all errors
201:      *
202:      * @return array
203:      */
204:     public function getErrors()
205:     {
206:         return $this->_getDataModel()->getErrors();
207:     }
208: 
209:     /**
210:      * Check flag value
211:      *
212:      * Returns true for 'yes', 1, 'true'
213:      * Case insensitive
214:      *
215:      * @param string $value
216:      * @return boolean
217:      */
218:     protected function _checkFlag($value)
219:     {
220:         $res = (1 == $value)
221:             || preg_match('/^(yes|y|true)$/i', $value);
222:         return $res;
223:     }
224: 
225:     /**
226:      * Get data model (used to store data between installation steps
227:      *
228:      * @return Mage_Install_Model_Installer_Data
229:      */
230:     protected function _getDataModel()
231:     {
232:         if (is_null($this->_dataModel)) {
233:             $this->_dataModel = Mage::getModel('install/installer_data');
234:         }
235:         return $this->_dataModel;
236:     }
237: 
238:     /**
239:      * Get encryption key from data model
240:      *
241:      * @return string
242:      */
243:     public function getEncryptionKey()
244:     {
245:         return $this->_getDataModel()->getEncryptionKey();
246:     }
247: 
248:     /**
249:      * Init installation
250:      *
251:      * @param Mage_Core_Model_App $app
252:      * @return boolean
253:      */
254:     public function init(Mage_Core_Model_App $app)
255:     {
256:         $this->_app = $app;
257:         $this->_getInstaller()->setDataModel($this->_getDataModel());
258: 
259:         /**
260:          * Check if already installed
261:          */
262:         if (Mage::isInstalled()) {
263:             $this->addError('ERROR: Magento is already installed');
264:             return false;
265:         }
266: 
267:         return true;
268:     }
269: 
270:     /**
271:      * Prepare data ans save it in data model
272:      *
273:      * @return Mage_Install_Model_Installer_Console
274:      */
275:     protected function _prepareData()
276:     {
277:         /**
278:          * Locale settings
279:          */
280:         $this->_getDataModel()->setLocaleData(array(
281:             'locale'            => $this->_args['locale'],
282:             'timezone'          => $this->_args['timezone'],
283:             'currency'          => $this->_args['default_currency'],
284:         ));
285: 
286:         /**
287:          * Database and web config
288:          */
289:         $this->_getDataModel()->setConfigData(array(
290:             'db_model'            => $this->_args['db_model'],
291:             'db_host'             => $this->_args['db_host'],
292:             'db_name'             => $this->_args['db_name'],
293:             'db_user'             => $this->_args['db_user'],
294:             'db_pass'             => $this->_args['db_pass'],
295:             'db_prefix'           => $this->_args['db_prefix'],
296:             'use_rewrites'        => $this->_checkFlag($this->_args['use_rewrites']),
297:             'use_secure'          => $this->_checkFlag($this->_args['use_secure']),
298:             'unsecure_base_url'   => $this->_args['url'],
299:             'secure_base_url'     => $this->_args['secure_base_url'],
300:             'use_secure_admin'    => $this->_checkFlag($this->_args['use_secure_admin']),
301:             'session_save'        => $this->_checkSessionSave($this->_args['session_save']),
302:             'admin_frontname'     => $this->_checkAdminFrontname($this->_args['admin_frontname']),
303:             'skip_url_validation' => $this->_checkFlag($this->_args['skip_url_validation']),
304:             'enable_charts'       => $this->_checkFlag($this->_args['enable_charts']),
305:         ));
306: 
307:         /**
308:          * Primary admin user
309:          */
310:         $this->_getDataModel()->setAdminData(array(
311:             'firstname'         => $this->_args['admin_firstname'],
312:             'lastname'          => $this->_args['admin_lastname'],
313:             'email'             => $this->_args['admin_email'],
314:             'username'          => $this->_args['admin_username'],
315:             'new_password'      => $this->_args['admin_password'],
316:         ));
317: 
318:         return $this;
319:     }
320: 
321:     /**
322:      * Install Magento
323:      *
324:      * @return boolean
325:      */
326:     public function install()
327:     {
328:         try {
329: 
330:             /**
331:              * Check if already installed
332:              */
333:             if (Mage::isInstalled()) {
334:                 $this->addError('ERROR: Magento is already installed');
335:                 return false;
336:             }
337: 
338:             /**
339:              * Skip URL validation, if set
340:              */
341:             $this->_getDataModel()->setSkipUrlValidation($this->_args['skip_url_validation']);
342:             $this->_getDataModel()->setSkipBaseUrlValidation($this->_args['skip_url_validation']);
343: 
344:             /**
345:              * Prepare data
346:              */
347:             $this->_prepareData();
348: 
349:             if ($this->hasErrors()) {
350:                 return false;
351:             }
352: 
353:             $installer = $this->_getInstaller();
354: 
355:             /**
356:              * Install configuration
357:              */
358:             $installer->installConfig($this->_getDataModel()->getConfigData()); // TODO fix wizard and simplify this everywhere
359: 
360:             if ($this->hasErrors()) {
361:                 return false;
362:             }
363: 
364:             /**
365:              * Reinitialize configuration (to use new config data)
366:              */
367: 
368:             $this->_app->cleanCache();
369:             Mage::getConfig()->reinit();
370: 
371:             /**
372:              * Install database
373:              */
374:             $installer->installDb();
375: 
376:             if ($this->hasErrors()) {
377:                 return false;
378:             }
379: 
380:             // apply data updates
381:             Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
382: 
383:             /**
384:              * Validate entered data for administrator user
385:              */
386:             $user = $installer->validateAndPrepareAdministrator($this->_getDataModel()->getAdminData());
387: 
388:             if ($this->hasErrors()) {
389:                 return false;
390:             }
391: 
392:             /**
393:              * Prepare encryption key and validate it
394:              */
395:             $encryptionKey = empty($this->_args['encryption_key'])
396:                 ? md5(Mage::helper('core')->getRandomString(10))
397:                 : $this->_args['encryption_key'];
398:             $this->_getDataModel()->setEncryptionKey($encryptionKey);
399:             $installer->validateEncryptionKey($encryptionKey);
400: 
401:             if ($this->hasErrors()) {
402:                 return false;
403:             }
404: 
405:             /**
406:              * Create primary administrator user
407:              */
408:             $installer->createAdministrator($user);
409: 
410:             if ($this->hasErrors()) {
411:                 return false;
412:             }
413: 
414:             /**
415:              * Save encryption key or create if empty
416:              */
417:             $installer->installEnryptionKey($encryptionKey);
418: 
419:             if ($this->hasErrors()) {
420:                 return false;
421:             }
422: 
423:             /**
424:              * Installation finish
425:              */
426:             $installer->finish();
427: 
428:             if ($this->hasErrors()) {
429:                 return false;
430:             }
431: 
432:             /**
433:              * Change directories mode to be writable by apache user
434:              */
435:             @chmod('var/cache', 0777);
436:             @chmod('var/session', 0777);
437: 
438:         } catch (Exception $e) {
439:             $this->addError('ERROR: ' . $e->getMessage());
440:             return false;
441:         }
442: 
443:         return true;
444:     }
445: 
446:     /**
447:      * Print available currency, locale and timezone options
448:      *
449:      * @return Mage_Install_Model_Installer_Console
450:      */
451:     public function printOptions()
452:     {
453:         $options = array(
454:             'locale'    => $this->_app->getLocale()->getOptionLocales(),
455:             'currency'  => $this->_app->getLocale()->getOptionCurrencies(),
456:             'timezone'  => $this->_app->getLocale()->getOptionTimezones(),
457:         );
458:         var_export($options);
459:         return $this;
460:     }
461: 
462:     /**
463:      * Check if installer is run in shell, and redirect if run on web
464:      *
465:      * @param string $url fallback url to redirect to
466:      * @return boolean
467:      */
468:     public function checkConsole($url=null)
469:     {
470:         if (defined('STDIN') && defined('STDOUT') && (defined('STDERR'))) {
471:             return true;
472:         }
473:         if (is_null($url)) {
474:             $url = preg_replace('/install\.php/i', '', Mage::getBaseUrl());
475:             $url = preg_replace('/\/\/$/', '/', $url);
476:         }
477:         header('Location: ' . $url);
478:         return false;
479:     }
480: 
481: }
482: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0