Code Duplication    Length = 27-27 lines in 2 locations

backend/controllers/MediaCommentController.php 1 location

@@ 129-155 (lines=27) @@
126
     * The action depends on the value of the dropdown next to the button.
127
     * Only accept POST HTTP method.
128
     */
129
    public function actionBulkAction()
130
    {
131
        if (Yii::$app->request->post('action') === MediaComment::STATUS_APPROVED) {
132
            foreach (Yii::$app->request->post('ids', []) as $id) {
133
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_APPROVED]);
134
            }
135
        } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_NOT_APPROVED) {
136
            foreach (Yii::$app->request->post('ids', []) as $id) {
137
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_NOT_APPROVED]);
138
            }
139
        } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_TRASHED) {
140
            foreach (Yii::$app->request->post('ids', []) as $id) {
141
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_TRASHED]);
142
            }
143
        } elseif (Yii::$app->request->post('action') === 'delete') {
144
            foreach (Yii::$app->request->post('ids', []) as $id) {
145
                $model = $this->findModel($id);
146
                $media = $model->commentMedia;
147
                if ($model->delete()) {
148
                    if (!$model->parent) {
149
                        $media->updateAttributes(['comment_count', --$media->comment_count]);
150
                    }
151
                    MediaComment::deleteAll(['parent' => $model->id]);
152
                }
153
            }
154
        }
155
    }
156
157
    /**
158
     * Reply an existing MediaComment model.

backend/controllers/PostCommentController.php 1 location

@@ 136-162 (lines=27) @@
133
     * The action depends on the value of the dropdown next to the button.
134
     * Only accept POST HTTP method.
135
     */
136
    public function actionBulkAction()
137
    {
138
        if (Yii::$app->request->post('action') === PostComment::STATUS_APPROVED) {
139
            foreach (Yii::$app->request->post('ids', []) as $id) {
140
                $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_APPROVED]);
141
            }
142
        } elseif (Yii::$app->request->post('action') === PostComment::STATUS_NOT_APPROVED) {
143
            foreach (Yii::$app->request->post('ids', []) as $id) {
144
                $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_NOT_APPROVED]);
145
            }
146
        } elseif (Yii::$app->request->post('action') === PostComment::STATUS_TRASHED) {
147
            foreach (Yii::$app->request->post('ids', []) as $id) {
148
                $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_TRASHED]);
149
            }
150
        } elseif (Yii::$app->request->post('action') === 'delete') {
151
            foreach (Yii::$app->request->post('ids', []) as $id) {
152
                $model = $this->findModel($id);
153
                $post = $model->commentPost;
154
                if ($model->delete()) {
155
                    if (!$model->parent) {
156
                        $post->updateAttributes(['comment_count', --$post->comment_count]);
157
                    }
158
                    PostComment::deleteAll(['parent' => $model->id]);
159
                }
160
            }
161
        }
162
    }
163
164
    /**
165
     * Reply an existing PostComment model.