示例#1
0
 /**
  * 将演讲集迁移到新的资讯里面
  *
  * @return void
  * @author 
  **/
 public function actionIndex()
 {
     echo "========== start processing ==========\n\n";
     $i = 1;
     $info = Speech::find()->where(['is_del' => 0])->all();
     foreach ($info as $speech) {
         preg_match('/[\\w][\\w-]*\\.(?:com\\.cn|com|cn|co|net|org|gov|cc|biz|info)/isU', $speech->video_url, $match);
         if (isset($match[0]) && $match[0] == 'youku.com' && strlen($speech->video_url) > 5) {
             // if (file_exists($src_file = Yii::getAlias("@frontend/web/{$speech->photo_url}"))) {
             // 复制图片
             $ext = '.jpg';
             if (strlen($speech->photo_url) > 0) {
                 $src_file = Yii::getAlias("@frontend/web/{$speech->photo_url}{$ext}");
                 $new_file = 'speech' . substr($speech->photo_url, strpos($speech->photo_url, '/'));
                 $dist_file = Yii::getAlias("@frontend/web/source/{$new_file}{$ext}");
                 if (!is_dir(dirname($dist_file))) {
                     mkdir(dirname($dist_file), 0777, true);
                 }
                 $copied = @copy($src_file, $dist_file);
             }
             // 写入数据
             $post = Post::findOne(['migrate_id' => md5($speech->id)]);
             if (!$post) {
                 $post_model = new Post();
                 $post_model->news_title = $speech->title;
                 $post_model->news_type = 'news_video';
                 $post_model->news_des = $speech->short_intro;
                 $post_model->news_content = empty($speech->detailed_intro) ? ' ' : $speech->detailed_intro;
                 $post_model->news_author = $speech->author;
                 $post_model->news_cover_url = $new_file;
                 $post_model->news_video_url = $speech->video_url;
                 $post_model->news_active = 0;
                 $post_model->migrate_id = md5($speech->id);
                 $saved = $post_model->save();
                 // Msg
                 $saved_msg = $saved ? '成功' : '失败';
                 $copied_msg = $copied ? '成功' : '失败';
                 echo "Process_{$i}: {$src_file} -> {$dist_file} 复制{$copied_msg} \n";
                 echo "{$src_file} -> {$dist_file} 迁移{$saved_msg} \n";
                 $i++;
             }
         }
     }
     echo "Process Over\n";
 }
示例#2
0
 /**
  * undocumented function
  *
  * @return void
  * @author 
  **/
 public function actionDelete($id)
 {
     // 删除投票
     $post = Post::findOne($id);
     if ($post) {
         $post->news_active = 4;
         $post->save(false, ['news_active']);
     }
     Yii::$app->session->setFlash('success', '删除成功!');
     return $this->redirect(['index']);
 }