Ejemplo n.º 1
0
 public function actionUserInfo()
 {
     UserInfo::updateAll(['thanks_count' => 0, 'like_count' => 0, 'hate_count' => 0]);
     $meta = UserMeta::find()->all();
     foreach ($meta as $key => $value) {
         if (in_array($value->type, ['thanks', 'like', 'hate'])) {
             switch ($value->target_type) {
                 case 'topic':
                 case 'post':
                     $this->stdout("同步文章操作……\n");
                     $topic = Topic::findOne($value->target_id);
                     if (UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $topic->user_id])) {
                         $this->stdout("同步评论成功`(*∩_∩*)′\n");
                     } else {
                         $this->stdout("同步评论失败::>_<::\n");
                     }
                     break;
                 case 'comment':
                     $this->stdout("同步评论操作……\n");
                     $comment = PostComment::findOne($value->target_id);
                     if (UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $comment->user_id])) {
                         $this->stdout("同步评论成功`(*∩_∩*)′\n");
                     } else {
                         $this->stdout("同步评论失败::>_<:: \n");
                     }
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     return;
 }
Ejemplo n.º 2
0
 public function actionSync()
 {
     UserInfo::updateAll(['thanks_count' => 0, 'like_count' => 0, 'hate_count' => 0]);
     $meta = UserMeta::find()->all();
     foreach ($meta as $key => $value) {
         if (in_array($value->type, ['thanks', 'like', 'hate'])) {
             switch ($value->target_type) {
                 case 'topic':
                 case 'post':
                     echo '同步文章操作</br>';
                     $topic = Topic::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $topic->user_id]);
                     break;
                 case 'comment':
                     echo '同步评论操作</br>';
                     $comment = PostComment::findOne($value->target_id);
                     UserInfo::updateAllCounters([$value->type . '_count' => 1], ['user_id' => $comment->user_id]);
                     break;
                 default:
                     # code...
                     break;
             }
         }
     }
     return;
 }
Ejemplo n.º 3
0
 /**
  * @param AcceptanceTester $I
  */
 public function testUpdate(AcceptanceTester $I)
 {
     $I->wantTo('ensure that update post-comment works');
     $updatePage = UpdatePage::openBy($I);
     $I->see('Update Post Comment: 1', 'h1');
     $I->amGoingTo('submit post-comment with no correct email & url');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => 'tester.author@test', 'comment_author_url' => 'http://.com']);
     $I->expectTo('see that email & url not correct');
     $I->see('Email is not a valid email address.', '.help-block');
     $I->see('URL is not a valid URL.', '.help-block');
     $I->amGoingTo('submit post-comment with correct data');
     $updatePage->submit(['comment_author' => 'Tester', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://tester.com']);
     $I->expect('post-comment updated');
     $I->dontSee('Email is not a valid email address.', '.help-block');
     $I->dontSee('URL is not a valid URL.', '.help-block');
     PostComment::findOne(1)->updateAll(['comment_author' => 'Mr. WritesDown', 'comment_author_email' => '*****@*****.**', 'comment_author_url' => 'http://www.writesdown.com']);
 }
Ejemplo n.º 4
0
 /**
  * Finds the PostComment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return PostComment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PostComment::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }