Test Failed
Push — master ( aa6767...a0db34 )
by Alexey
05:07
created

Exchange1cController::reExchangeAction()   B

Complexity

Conditions 6
Paths 12

Size

Total Lines 56
Code Lines 45

Duplication

Lines 6
Ratio 10.71 %

Importance

Changes 0
Metric Value
cc 6
eloc 45
nc 12
nop 0
dl 6
loc 56
rs 8.7592
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Exchange1c admin controller
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class Exchange1cController extends adminController {
12
13
    public function reExchangeAction() {
14
        error_reporting(E_ALL);
15
        ini_set('error_reporting', E_ALL);
16
        ini_set('display_errors', 1);
17
        ini_set('display_startup_errors', 1);
18
        ini_set('memory_limit', '-1');
19
        ignore_user_abort(true);
20
        set_time_limit(0);
21
        Model::$logging = false;
22
        App::$cur->log->run = true;
23
        App::$cur->log->forceView = true;
24
        $reExchange = Exchange1c\Exchange::get((int) $_GET['item_pk']);
25
26
        $exchange = new \Exchange1c\Exchange();
27
        $exchange->type = $reExchange->type;
28
        $exchange->path = $reExchange->path;
29
        $exchange->save();
30
31
        foreach ($reExchange->files as $reFile) {
32
            if (strpos($reFile->name, '/')) {
33
                Tools::createDir($exchange->path . '/' . substr($reFile->name, 0, strrpos($reFile->name, '/')));
34
            }
35
            copy($reExchange->path . '/' . $reFile->name, $exchange->path . '/' . $reFile->name);
36
        }
37
38
        foreach ($reExchange->logs as $reLog) {
39
            if (!in_array($reLog->info, ['import'])) {
40
                continue;
41
            }
42
            $_GET = json_decode($reLog->query, true);
43
44
            $log = new \Exchange1c\Exchange\Log();
45
            $log->exchange_id = $exchange->id;
46
            $log->type = 'mode';
47
            $log->info = $reLog->info;
48
            $log->status = 'process';
49
            $log->query = $reLog->query;
50
            $log->save();
51
52
            $modeClass = 'Exchange1c\Mode\\' . ucfirst(strtolower($log->info));
53 View Code Duplication
            if (!class_exists($modeClass)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
                $log->status = 'failure';
55
                $log->info = 'mode class ' . $modeClass . ' not found';
56
                $log->date_end = date('Y-m-d H:i:s');
57
                $log->save();
58
            }
59
            $mode = new $modeClass;
60
            $mode->exchange = $exchange;
61
            $mode->log = $log;
62
            $key = \App::$cur->log->start('start migration');
63
            $mode->process();
64
            \App::$cur->log->end($key);
65
        }
66
        echo '<hr /><a href="/admin/exchange1c/Exchange">Назад</a>';
67
        Model::$logging = true;
68
    }
69
70
    public function findOldAction() {
71
        if (!empty($_POST['ids'])) {
72
            $countIds = 0;
73
            $countModels = 0;
74
            foreach ($_POST['ids'] as $id) {
75
                $id = \Migrations\Id::get($id);
76
                if (!$id) {
77
                    continue;
78
                }
79
                $modelName = $id->type;
80
                $model = $modelName::get($id->object_id);
81
                if ($model) {
82
                    $countModels++;
83
                    $model->delete();
84
                }
85
                $countIds++;
86
                $id->delete();
87
            }
88
            if ($countModels) {
89
                Msg::add("Удалено {$countModels} объектов с сайта");
90
            }
91
            if ($countIds) {
92
                Msg::add("Удалено {$countIds} объектов миграции");
93
            }
94
        }
95
        $this->view->page();
96
    }
97
98
}