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 actionDataBlocks() { $favs = Yii::$app->adminuser->identity->setting->get("blockfav", []); $groups = []; foreach (BlockGroup::find()->asArray()->all() as $group) { $blocks = []; $groupPosition = null; foreach (Block::find()->where(['group_id' => $group['id']])->all() as $block) { $obj = Block::objectId($block['id'], 0, 'admin'); if (!$obj || in_array(get_class($obj), Yii::$app->getModule('cmsadmin')->hiddenBlocks)) { continue; } if ($groupPosition == null) { $groupObject = Yii::createObject($obj->blockGroup()); $groupPosition = $groupObject->getPosition(); } $blocks[] = ['id' => $block['id'], 'name' => $obj->name(), 'full_name' => $obj->icon() === null ? $obj->name() : '<i class="material-icons">' . $obj->icon() . '</i> <span>' . $obj->name() . '</span>', 'favorized' => array_key_exists($block['id'], $favs)]; } if (empty($blocks)) { continue; } $group['is_fav'] = 0; $group['toggle_open'] = (int) Yii::$app->adminuser->identity->setting->get("togglegroup.{$group['id']}", 1); $groups[] = ['groupPosition' => $groupPosition, 'group' => $group, 'blocks' => $blocks]; } if (!empty($favs)) { $favblocks = []; foreach ($favs as $fav) { $favblocks[] = $fav; } array_unshift($groups, ['group' => ['toggle_open' => (int) Yii::$app->adminuser->identity->setting->get("togglegroup.99999", 1), 'id' => '99999', 'is_fav' => 1, 'name' => Module::t('block_group_favorites'), 'identifier' => 'favs', 'position' => 0], 'groupPosition' => 0, 'blocks' => $favblocks]); } return $groups; }
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.'); }