Пример #1
0
 public function beforeSave($insert)
 {
     if (empty($this->ip)) {
         $this->ip = \Yii::$app->request->userIP;
     }
     if (empty($this->ip)) {
         return false;
     }
     $this->date = time();
     return parent::beforeSave($insert);
     // TODO: Change the autogenerated stub
 }
 public function up()
 {
     $commentsVotes = new \yii\db\Query();
     $commentsVotes = $commentsVotes->from(\Yii::$app->params['oldDb'] . '.joom_jcomments_votes');
     $commentsVotesCount = $commentsVotes->count();
     echo "    > migrating comments votes... Almost have {$commentsVotesCount} comments votes...\r\n";
     $i = 0;
     $prepared = [];
     foreach ($commentsVotes->each() as $commentsVote) {
         $i++;
         echo "    > comment {$i} from {$commentsVotesCount}... \r\n";
         $commentModel = new CommentsVote(['commentID' => $commentsVote['commentid'], 'date' => strtotime($commentsVote['date']), 'operation' => $commentsVote['value']]);
         $commentModel->ip = $commentsVote['ip'];
         if (!empty($commentModel->ip)) {
             $prepared[] = $commentModel->attributes;
         }
         if (count($prepared) >= 100 || $commentsVotesCount - $i == 0) {
             $this->batchInsert(CommentsVote::tableName(), array_keys($prepared[0]), $prepared);
             $prepared = [];
         }
     }
 }
 public function up()
 {
     \common\models\CommentsVote::deleteAll(['ipAddr' => 0]);
     $this->createIndex('vote', 'commentsVotes', ['commentID', 'ipAddr'], true);
 }
Пример #4
0
 public function getVotes()
 {
     return $this->hasMany(CommentsVote::className(), ['commentID' => 'id']);
 }