Example #1
0
 public function bootstrap($app)
 {
     Event::on(RatingModule::className(), RatingModule::EVENT_RATING_ADD, function ($event) {
         $torrent = \Yii::$app->db->cache(function ($db) use($event) {
             return Torrent::findOne($event->recordId);
         });
         $torrent->rating_avg = ($torrent->rating_votes * $torrent->rating_avg + $event->rating) / ($torrent->rating_votes + 1);
         $torrent->rating_votes = $torrent->rating_votes + 1;
         $torrent->save(false);
     });
     Event::on(ComplainModule::className(), ComplainModule::EVENT_COMPLAINT_ADD, function ($event) {
         if ($event->total >= \Yii::$app->params['numberComplaintsToHide'] && ($event->type === Complaint::TYPE_FAKE || $event->type === Complaint::TYPE_VIRUS)) {
             $torrent = \Yii::$app->db->cache(function ($db) use($event) {
                 return Torrent::findOne($event->recordId);
             });
             $torrent->visible_status = Torrent::VISIBLE_STATUS_DIRECT;
             $torrent->save(false);
         }
     });
     Event::on(CommentModule::className(), CommentModule::EVENT_COMMENT_ADD, function ($event) {
         $torrent = \Yii::$app->db->cache(function ($db) use($event) {
             return Torrent::findOne($event->recordId);
         });
         $torrent->comments_count = $torrent->comments_count + 1;
         $torrent->save(false);
     });
 }
Example #2
0
 public static function getRecentTorrentDataProvider()
 {
     $query = Torrent::find();
     $query->with('scrapes');
     $query->where(['visible_status' => [0, 3]]);
     $query->addOrderBy(['id' => SORT_DESC]);
     $cmd = $query->createCommand();
     return new RecentTorrentsActiveDataProvider(['query' => $query, 'db' => Yii::$app->db, 'sort' => false, 'pagination' => ['pageSize' => 35]]);
 }
Example #3
0
 public function beforeAction($action)
 {
     $query = Yii::$app->request->getQueryParam('q');
     $queryLength = mb_strlen($query, 'UTF-8');
     if (40 == $queryLength && preg_match('#^[0-9a-f]{40}$#i', $query)) {
         if ($torrent = Torrent::find()->where(['hash' => $query])->one()) {
             $action->controller->redirect($torrent->getUrl());
         }
     }
     return parent::beforeAction($action);
 }
Example #4
0
 /**
  * Finds the Torrent model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Torrent the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $model = Yii::$app->db->cache(function ($db) use($id) {
         return Torrent::findOne($id);
     });
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 protected function checkUrl()
 {
     if ($this->torrent->getUrl() !== Yii::$app->request->getUrl()) {
         Yii::$app->response->redirect($this->torrent->getUrl(), 301);
     }
 }