| @@ 153-170 (lines=18) @@ | ||
| 150 | if ($oldRating) { |
|
| 151 | if ($oldRating->status == $newRating->status) { |
|
| 152 | $oldRating->scenario = CommentsRating::SCENARIO_DELETE; |
|
| 153 | if ($oldRating->delete()) { |
|
| 154 | if ($oldRating->status == 1) { |
|
| 155 | CommentsHelper::deleteUprated($oldRating->comment_id); |
|
| 156 | } elseif ($oldRating->status == 2) { |
|
| 157 | CommentsHelper::deleteDownrated($oldRating->comment_id); |
|
| 158 | } |
|
| 159 | ||
| 160 | TagDependency::invalidate( |
|
| 161 | Yii::$app->cache, |
|
| 162 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
|
| 163 | ); |
|
| 164 | ||
| 165 | return [ |
|
| 166 | 'status' => 'success', |
|
| 167 | 'action' => 'unrated', |
|
| 168 | 'message' => Yii::t('comments', 'Comment rating has been updated successfully.') |
|
| 169 | ]; |
|
| 170 | } |
|
| 171 | } else { |
|
| 172 | $oldRating->status = $newRating->status; |
|
| 173 | $oldRating->scenario = CommentsRating::SCENARIO_UPDATE; |
|
| @@ 195-214 (lines=20) @@ | ||
| 192 | ]; |
|
| 193 | } |
|
| 194 | } |
|
| 195 | } else { |
|
| 196 | if ($newRating->save()) { |
|
| 197 | if ($newRating->status == 1) { |
|
| 198 | CommentsHelper::setUprated($newRating->comment_id); |
|
| 199 | } elseif ($newRating->status == 2) { |
|
| 200 | CommentsHelper::setDownrated($newRating->comment_id); |
|
| 201 | } |
|
| 202 | ||
| 203 | TagDependency::invalidate( |
|
| 204 | Yii::$app->cache, |
|
| 205 | Url::previous(Yii::$app->controller->module->urlCacheSessionKey) |
|
| 206 | ); |
|
| 207 | ||
| 208 | return [ |
|
| 209 | 'status' => 'success', |
|
| 210 | 'action' => 'rated', |
|
| 211 | 'message' => Yii::t('comments', 'Comment rating has been updated successfully.') |
|
| 212 | ]; |
|
| 213 | } |
|
| 214 | } |
|
| 215 | } else { |
|
| 216 | return [ |
|
| 217 | 'status' => 'error', |
|