<commit_before><?php

namespace luya\cms\admin\importers;

use Yii;
use luya\cms\models\Block;
use luya\cms\models\BlockGroup;
use luya\console\Importer;
use luya\admin\models\Config;
use yii\console\Exception;

class BlockImporter extends Importer
{
    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;
            }
        }<commit_msg>remove rc1 import command<commit_after><?php

namespace luya\cms\admin\importers;

use Yii;
use luya\cms\models\Block;
use luya\cms\models\BlockGroup;
use luya\console\Importer;

class BlockImporter extends Importer
{
    public function run()
    {
        $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;
            }
        }
{'fraction_non_alphanumeric': 0.15042608373471655, 'fraction_numerical': 0.0014820303816228233, 'mean_word_length': 1.7522935779816513, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4507218', 'n_tokens_mistral': 770, 'n_tokens_neox': 742, 'n_words': 147}