public function up()
 {
     $this->addColumn('news', 'unpublishDate', Schema::TYPE_DATETIME);
     $this->addColumn('news', 'checkedDate', Schema::TYPE_DATETIME);
     $this->addColumn('news', 'checked', Schema::TYPE_INTEGER . ' UNSIGNED NOT NULL DEFAULT 0');
     $this->addColumn('news', 'creator', Schema::TYPE_INTEGER . ' UNSIGNED NOT NULL DEFAULT 0');
     $this->addColumn('news', 'textPreview', $this->text());
     $this->addColumn('news', 'publishTimestamp', $this->integer()->unsigned()->notNull()->defaultValue(0));
     $this->createIndex('publishTimestamp', 'news', 'publishTimestamp');
     $this->execute("UPDATE `news` SET `publishTimestamp` = UNIX_TIMESTAMP(STR_TO_DATE(`publishDate`, '%Y-%m-%d %H:%i:%s'))");
     $this->alterColumn('news', 'author', Schema::TYPE_STRING);
     $newsList = new \yii\db\Query();
     $newsList = $newsList->from(\Yii::$app->params['oldDb'] . '.joom_content');
     $newsListCount = $newsList->count();
     echo "    > migrating news... Almost have {$newsListCount} news...\r\n";
     echo "    > prepare news...\r\n";
     $i = 0;
     foreach ($newsList->each(25) as $news) {
         $i++;
         echo "    > news {$i} from {$newsListCount}... \r\n";
         $newNews = new News(['id' => $news['id']]);
         $newNews->creator = $news['created_by'];
         $newNews->author = $news['created_by_alias'];
         $newNews->title = $news['title'];
         $newNews->textPreview = $news['introtext'];
         $newNews->text = $news['fulltext'];
         $newNews->link = $news['alias'];
         $newNews->published = $news['access'] == '1' ? 1 : 0;
         $newNews->deleted = $news['state'] == '-2' ? 1 : 0;
         $newNews->publishDate = $news['publish_up'];
         $newNews->favorite = $news['featured'];
         $newNews->hits = $news['hits'];
         $newNews->meta_description = $news['metadesc'];
         $newNews->meta_keywords = $news['metakey'];
         $newNews->category = $news['catid'];
         $newNews->unpublishDate = $news['publish_down'];
         $newNews->checkedDate = $news['checked_out_time'];
         $newNews->checked = $news['checked_out'];
         $newNews->image = $newNews->getImagePreview();
         $newNews->publishTimestamp = $news['publish_up'] ? strtotime($news['publish_up']) : 0;
         $newNews->publishTimestamp = $newNews->publishTimestamp < 0 ? 0 : $newNews->publishTimestamp;
         $prepared[] = $newNews->attributes;
         if (count($prepared) >= 50 || $newsListCount - $i == 0) {
             $this->batchInsert(News::tableName(), array_keys($prepared[0]), $prepared);
             $prepared = [];
         }
     }
 }