Code Duplication    Length = 43-45 lines in 2 locations

src/Eccube/Controller/Admin/Content/BlockController.php 1 location

@@ 157-201 (lines=45) @@
154
        ));
155
    }
156
157
    public function delete(Application $app, Request $request, $id)
158
    {
159
        $this->isTokenValid($app);
160
161
        $DeviceType = $app['eccube.repository.master.device_type']
162
            ->find(DeviceType::DEVICE_TYPE_PC);
163
164
        $Block = $app['eccube.repository.block']->findOneBy(array(
165
            'id' => $id,
166
            'DeviceType' => $DeviceType
167
        ));
168
169
        if (!$Block) {
170
            $app->deleteMessage();
171
            return $app->redirect($app->url('admin_content_block'));
172
        }
173
174
        // ユーザーが作ったブロックのみ削除する
175
        // テンプレートが変更されていた場合、DBからはブロック削除されるがtwigファイルは残る
176
        if ($Block->getDeletableFlg() > 0) {
177
            $tplDir = $app['config']['block_realdir'];
178
            $file = $tplDir . '/' . $Block->getFileName() . '.twig';
179
            $fs = new Filesystem();
180
            if ($fs->exists($file)) {
181
                $fs->remove($file);
182
            }
183
            $app['orm.em']->remove($Block);
184
            $app['orm.em']->flush();
185
186
            $event = new EventArgs(
187
                array(
188
                    'Block' => $Block,
189
                ),
190
                $request
191
            );
192
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_BLOCK_DELETE_COMPLETE, $event);
193
194
            $app->addSuccess('admin.delete.complete', 'admin');
195
            //twigテンプレートのみ削除
196
            \Eccube\Util\Cache::clear($app, false, true);
197
        }
198
199
200
        return $app->redirect($app->url('admin_content_block'));
201
    }
202
}
203

src/Eccube/Controller/Admin/Content/PageController.php 1 location

@@ 166-208 (lines=43) @@
163
        ));
164
    }
165
166
    public function delete(Application $app, Request $request, $id = null)
167
    {
168
        $this->isTokenValid($app);
169
170
        $DeviceType = $app['eccube.repository.master.device_type']
171
            ->find(DeviceType::DEVICE_TYPE_PC);
172
173
        $PageLayout = $app['eccube.repository.page_layout']
174
            ->findOneBy(array(
175
                'id' => $id,
176
                'DeviceType' => $DeviceType
177
            ));
178
179
        if (!$PageLayout) {
180
            $app->deleteMessage();
181
182
            return $app->redirect($app->url('admin_content_page'));
183
        }
184
185
        // ユーザーが作ったページのみ削除する
186
        if ($PageLayout->getEditFlg() == PageLayout::EDIT_FLG_USER) {
187
            $templatePath = $app['eccube.repository.page_layout']->getWriteTemplatePath(true);
188
            $file = $templatePath.'/'.$PageLayout->getFileName().'.twig';
189
            $fs = new Filesystem();
190
            if ($fs->exists($file)) {
191
                $fs->remove($file);
192
            }
193
            $app['orm.em']->remove($PageLayout);
194
            $app['orm.em']->flush();
195
196
            $event = new EventArgs(
197
                array(
198
                    'DeviceType' => $DeviceType,
199
                    'PageLayout' => $PageLayout,
200
                ),
201
                $request
202
            );
203
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_PAGE_DELETE_COMPLETE, $event);
204
205
            $app->addSuccess('admin.delete.complete', 'admin');
206
        }
207
208
        return $app->redirect($app->url('admin_content_page'));
209
    }
210
}
211