Example #1
0
 /**
  * Initializes the console app by creating the command runner.
  */
 public function init()
 {
     // Set default timezone to UTC
     date_default_timezone_set('UTC');
     // Import all the built-in components
     foreach ($this->componentAliases as $alias) {
         Craft::import($alias);
     }
     // Attach our Craft app behavior.
     $this->attachBehavior('SchematicBehavior', new Schematic());
     // Attach our own custom Logger
     Craft::setLogger(new Logger());
     // Initialize Cache and LogRouter right away (order is important)
     $this->getComponent('cache');
     $this->getComponent('log');
     // So we can try to translate Yii framework strings
     $this->coreMessages->attachEventHandler('onMissingTranslation', ['Craft\\LocalizationHelper', 'findMissingTranslation']);
     // Set our own custom runtime path.
     $this->setRuntimePath(Craft::app()->path->getRuntimePath());
     // No need for these.
     Craft::app()->log->removeRoute('WebLogRoute');
     Craft::app()->log->removeRoute('ProfileLogRoute');
     // Set the edition components
     $this->_setEditionComponents();
     // Install Craft if needed
     if (!$this->isInstalled()) {
         $this->_installCraft();
     }
     // Set the schematic components
     $this->_setSchematicComponents();
     // Call parent::init() before the plugin console command logic so the command runner gets initialized
     parent::init();
     // Load the plugins
     Craft::app()->plugins->loadPlugins();
     // Validate some basics on the database configuration file.
     Craft::app()->validateDbConfigFile();
     // Add commands
     Craft::app()->commandRunner->commands = [];
     Craft::app()->commandRunner->addCommands(__DIR__ . '/../ConsoleCommands/');
 }