Esempio n. 1
0
 public static function afterTopicDelete($topic_id)
 {
     $limit = 100;
     $offset = 0;
     while (1) {
         $comments = static::find()->select(['user_id'])->where(['topic_id' => $topic_id])->orderBy(['position' => SORT_ASC])->limit($limit)->offset($offset)->asArray()->all();
         if (empty($comments)) {
             break;
         }
         $uids = ArrayHelper::getColumn($comments, 'user_id');
         unset($comments);
         sort($uids);
         $uidCount = array_count_values($uids);
         unset($uids);
         $result = [];
         foreach ($uidCount as $key => $value) {
             $result[$value][] = $key;
         }
         foreach ($result as $key => $value) {
             UserInfo::updateAllCounters(['comment_count' => -$key], ['user_id' => $value]);
         }
         unset($result);
         $offset = $offset + 100;
     }
     return static::deleteAll(['topic_id' => $topic_id]);
 }
Esempio n. 2
0
 public static function afterTopicDelete($topic_id)
 {
     $limit = 100;
     $offset = 0;
     while (1) {
         $models = static::find()->select(['source_id'])->where(['type' => self::TYPE_TOPIC, 'target_id' => $topic_id])->orderBy(['id' => SORT_ASC])->limit($limit)->offset($offset)->asArray()->all();
         if (empty($models)) {
             break;
         }
         $uids = ArrayHelper::getColumn($models, 'source_id');
         sort($uids);
         UserInfo::updateAllCounters(['favorite_topic_count' => -1], ['user_id' => $uids]);
         $offset = $offset + 100;
     }
     return static::deleteAll(['type' => self::TYPE_TOPIC, 'target_id' => $topic_id]);
 }