示例#1
0
 public function run()
 {
     $allblocks = Block::find()->all();
     if (count($allblocks) == 0) {
         Config::set('rc1_block_classes_renameing', true);
     }
     if (!Config::has('rc1_block_classes_renameing')) {
         throw new Exception("You have to run the cmsadmin/updater/classes command in order to run the importer!");
     }
     $exists = [];
     foreach ($this->getImporter()->getDirectoryFiles('blocks') as $file) {
         $ns = $file['ns'];
         $model = Block::find()->where(['class' => $ns])->one();
         $blockObject = $this->createBlockObject($file['ns']);
         $blockGroupId = $this->getBlockGroupId($blockObject);
         if (!$model) {
             $block = new Block();
             $block->scenario = 'commandinsert';
             $block->setAttributes(['group_id' => $blockGroupId, 'class' => $ns]);
             $block->insert();
             $this->addLog($ns . ' new block has been added to database.');
         } else {
             $model->updateAttributes(['group_id' => $blockGroupId]);
             $exists[] = $model->id;
         }
     }
     foreach ($allblocks as $block) {
         if (!in_array($block->id, $exists)) {
             $this->addLog('block id ' . $block->id . ' removed from database.');
             $block->delete();
         }
     }
 }
 public function actionClasses()
 {
     if (Config::has('rc1_block_classes_renameing')) {
         return $this->outputError("You already have run the classes updater, so your system should be up-to-date already.");
     }
     foreach (Block::find()->all() as $block) {
         $ns = $block->class;
         foreach ($this->_classMapping as $old => $new) {
             if (StringHelper::startsWith($ns, $old)) {
                 $this->outputError('old: ' . $ns);
                 $newNs = StringHelper::replaceFirst($old, $new, $ns);
                 $block->updateAttributes(['class' => $newNs]);
                 $this->outputSuccess('new: ' . $newNs);
             }
         }
     }
     Config::set('rc1_block_classes_renameing', true);
     return $this->outputSuccess('OK. You can now run the import command.');
 }
示例#3
0
 /**
  * Run the import process.
  *
  * @return number
  */
 public function actionIndex()
 {
     try {
         $queue = [];
         $this->verbosePrint('Run import index', __METHOD__);
         foreach (Yii::$app->getModules() as $id => $module) {
             if ($module instanceof \luya\base\Module) {
                 $this->verbosePrint('collect module importers from module: ' . $id, __METHOD__);
                 $response = $module->import($this);
                 if (is_array($response)) {
                     // importer returns an array with class names
                     foreach ($response as $class) {
                         $this->verbosePrint("add object '{$class}' to queue list", __METHOD__);
                         $obj = new $class($this);
                         $prio = $obj->queueListPosition;
                         while (true) {
                             if (!array_key_exists($prio, $queue)) {
                                 break;
                             }
                             ++$prio;
                         }
                         $queue[$prio] = $obj;
                     }
                 }
             }
         }
         ksort($queue);
         foreach ($queue as $pos => $object) {
             $this->verbosePrint("run object '" . $object->className() . " on pos {$pos}.", __METHOD__);
             $objectResponse = $object->run();
             $this->verbosePrint("run object response: " . var_export($objectResponse, true), __METHOD__);
         }
         if (Yii::$app->hasModule('admin')) {
             Config::set('last_import_timestamp', time());
             Yii::$app->db->createCommand()->update('admin_user', ['force_reload' => 1])->execute();
         }
         $this->verbosePrint('importer finished, get log output: ' . var_export($this->getLog(), true), __METHOD__);
         foreach ($this->getLog() as $section => $value) {
             $this->outputInfo(PHP_EOL . $section . ":");
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     foreach ($v as $kk => $kv) {
                         if (is_array($kv)) {
                             $this->output(" - {$kk}: " . print_r($kv, true));
                         } else {
                             $this->output(" - {$kk}: {$kv}");
                         }
                     }
                 } else {
                     $this->output(" - " . $v);
                 }
             }
         }
         return $this->outputSuccess("Importer run successfull.");
     } catch (Exception $err) {
         return $this->outputError(sprintf("Exception while importing: '%s' in file '%s' on line '%s'.", $err->getMessage(), $err->getFile(), $err->getLine()));
     }
 }
示例#4
0
 /**
  * Setup the administration area.
  *
  * This action of setup will add a new user, group, languaga, permissions and default homepage and container.
  *
  * @return boolean
  */
 public function actionIndex()
 {
     if (!Config::has('last_import_timestamp')) {
         return $this->outputError("You have to run the 'import' process first. run in terminal: ./vendor/bin/luya import");
     }
     if (Config::has('setup_command_timestamp')) {
         return $this->outputError('The setup process already have been started on the ' . date('d.m.Y H:i', Config::get('setup_command_timestamp')) . '. If you want to reinstall your luya project. Drop all tables from your Database, run the migrate command, run the import command and then re-run the setup command');
     }
     if (empty($this->email)) {
         $this->email = $this->prompt('User E-Mail:', ['required' => true]);
     }
     if (empty($this->password)) {
         $this->password = $this->prompt('User Password:'******'required' => true]);
     }
     if (empty($this->firstname)) {
         $this->firstname = $this->prompt('Firstname:', ['required' => true]);
     }
     if (empty($this->lastname)) {
         $this->lastname = $this->prompt('Lastname:', ['required' => true]);
     }
     if (empty($this->langName)) {
         $this->langName = $this->prompt('Standard language:', ['required' => true, 'default' => 'English']);
     }
     if (empty($this->langShortCode)) {
         $this->langShortCode = $this->prompt('Short-Code of the Standard language:', ['required' => true, 'default' => 'en', 'validator' => function ($input, &$error) {
             if (strlen($input) !== 2) {
                 $error = 'The Short-Code must be 2 chars length only. Examples: de, en, fr, ru';
                 return false;
             }
             return true;
         }]);
     }
     if ($this->interactive) {
         if ($this->confirm("Confirm your login details in order to proceed with the Setup. E-Mail: {$this->email} Password: {$this->password} - Are those informations correct?") !== true) {
             return $this->outputError('Abort by user.');
         }
     }
     $salt = Yii::$app->security->generateRandomString();
     $pw = Yii::$app->security->generatePasswordHash($this->password . $salt);
     $this->insert('admin_user', ['title' => 1, 'firstname' => $this->firstname, 'lastname' => $this->lastname, 'email' => $this->email, 'password' => $pw, 'password_salt' => $salt, 'is_deleted' => 0]);
     $this->insert('admin_group', ['name' => 'Administrator', 'text' => 'Administrator Accounts have full access to all Areas and can create, update and delete all data records.']);
     $this->insert('admin_user_group', ['user_id' => 1, 'group_id' => 1]);
     // get the api-admin-user and api-admin-group auth rights
     $data = Yii::$app->db->createCommand("SELECT * FROM admin_auth WHERE api='api-admin-user' OR api='api-admin-group'")->queryAll();
     foreach ($data as $item) {
         $this->insert('admin_group_auth', ['group_id' => 1, 'auth_id' => $item['id'], 'crud_create' => 1, 'crud_update' => 1, 'crud_delete' => 1]);
     }
     $this->insert('admin_lang', ['name' => $this->langName, 'short_code' => $this->langShortCode, 'is_default' => 1]);
     if (Yii::$app->hasModule('cms')) {
         // insert default page
         $this->insert("cms_nav", ['nav_container_id' => 1, 'parent_nav_id' => 0, 'sort_index' => 0, 'is_deleted' => 0, 'is_hidden' => 0, 'is_offline' => 0, 'is_home' => 1, 'is_draft' => 0]);
         $this->insert("cms_nav_item", ['nav_id' => 1, 'lang_id' => 1, 'nav_item_type' => 1, 'nav_item_type_id' => 1, 'create_user_id' => 1, 'update_user_id' => 1, 'timestamp_create' => time(), 'title' => 'Homepage', 'alias' => 'homepage']);
         $this->insert('cms_nav_item_page', ['layout_id' => 1, 'create_user_id' => 1, 'timestamp_create' => time(), 'version_alias' => 'Initial', 'nav_item_id' => 1]);
     }
     Config::set('setup_command_timestamp', time());
     return $this->outputSuccess("Setup is finished. You can now login into the Administration-Area with the E-Mail '{$this->email}'.");
 }