Code Duplication    Length = 30-33 lines in 3 locations

src/Eccube/Controller/Admin/Store/PluginController.php 3 locations

@@ 269-298 (lines=30) @@
266
     *
267
     * @return RedirectResponse
268
     */
269
    public function enable(Plugin $Plugin, CacheUtil $cacheUtil)
270
    {
271
        $this->isTokenValid();
272
273
        if ($Plugin->isEnabled()) {
274
            $this->addError('admin.plugin.already.enable', 'admin');
275
        } else {
276
            $requires = $this->pluginService->findRequirePluginNeedEnable($Plugin->getCode());
277
            if (!empty($requires)) {
278
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $requires[0]]);
279
                $dependName = $requires[0];
280
                if ($DependPlugin) {
281
                    $dependName = $DependPlugin->getName();
282
                }
283
                $message = trans('admin.plugin.enable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
284
                $this->addError($message, 'admin');
285
286
                return $this->redirectToRoute('admin_store_plugin');
287
            }
288
            $this->pluginService->enable($Plugin);
289
            $this->addSuccess('admin.plugin.enable.complete', 'admin');
290
        }
291
292
        // キャッシュを削除してリダイレクト
293
        // リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。
294
        $url = $this->generateUrl('admin_store_plugin');
295
        $cacheUtil->clearCache();
296
297
        return $this->redirect($url);
298
    }
299
300
    /**
301
     * 対象のプラグインを無効にします。
@@ 309-341 (lines=33) @@
306
     *
307
     * @return RedirectResponse
308
     */
309
    public function disable(Plugin $Plugin, CacheUtil $cacheUtil)
310
    {
311
        $this->isTokenValid();
312
313
        if ($Plugin->isEnabled()) {
314
            $dependents = $this->pluginService->findDependentPluginNeedDisable($Plugin->getCode());
315
            if (!empty($dependents)) {
316
                $dependName = $dependents[0];
317
                $DependPlugin = $this->pluginRepository->findOneBy(['code' => $dependents[0]]);
318
                if ($DependPlugin) {
319
                    $dependName = $DependPlugin->getName();
320
                }
321
                $message = trans('admin.plugin.disable.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
322
                $this->addError($message, 'admin');
323
324
                return $this->redirectToRoute('admin_store_plugin');
325
            }
326
327
            $this->pluginService->disable($Plugin);
328
            $this->addSuccess('admin.plugin.disable.complete', 'admin');
329
        } else {
330
            $this->addError('admin.plugin.already.disable', 'admin');
331
332
            return $this->redirectToRoute('admin_store_plugin');
333
        }
334
335
        // キャッシュを削除してリダイレクト
336
        // リダイレクトにredirectToRoute関数を使用していないのは、削除したキャッシュが再生成されてしまうため。
337
        $url = $this->generateUrl('admin_store_plugin');
338
        $cacheUtil->clearCache();
339
340
        return $this->redirect($url);
341
    }
342
343
    /**
344
     * 対象のプラグインを削除します。
@@ 352-381 (lines=30) @@
349
     *
350
     * @return RedirectResponse
351
     */
352
    public function uninstall(Plugin $Plugin)
353
    {
354
        $this->isTokenValid();
355
356
        if ($Plugin->isEnabled()) {
357
            $this->addError('admin.plugin.uninstall.error.not_disable', 'admin');
358
359
            return $this->redirectToRoute('admin_store_plugin');
360
        }
361
362
        // Check other plugin depend on it
363
        $pluginCode = $Plugin->getCode();
364
        $otherDepend = $this->pluginService->findDependentPlugin($pluginCode);
365
        if (!empty($otherDepend)) {
366
            $DependPlugin = $this->pluginRepository->findOneBy(['code' => $otherDepend[0]]);
367
            $dependName = $otherDepend[0];
368
            if ($DependPlugin) {
369
                $dependName = $DependPlugin->getName();
370
            }
371
            $message = trans('admin.plugin.uninstall.depend', ['%name%' => $Plugin->getName(), '%depend_name%' => $dependName]);
372
            $this->addError($message, 'admin');
373
374
            return $this->redirectToRoute('admin_store_plugin');
375
        }
376
377
        $this->pluginService->uninstall($Plugin);
378
        $this->addSuccess('admin.plugin.uninstall.complete', 'admin');
379
380
        return $this->redirectToRoute('admin_store_plugin');
381
    }
382
383
    /**
384
     * @Route("/%eccube_admin_route%/store/plugin/handler", name="admin_store_plugin_handler")