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

Exchange1cController::findOldAction()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 5
nop 0
dl 0
loc 27
rs 6.7272
c 0
b 0
f 0
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
}