|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Mode File |
|
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
|
|
|
|
|
12
|
|
|
namespace Exchange1c\Mode; |
|
13
|
|
|
|
|
14
|
|
|
class File extends \Exchange1c\Mode { |
|
15
|
|
|
|
|
16
|
|
|
public function process() { |
|
17
|
|
|
$dir = $this->exchange->path; |
|
18
|
|
|
\Tools::createDir($dir); |
|
19
|
|
|
$file = new \Exchange1c\Exchange\File(); |
|
20
|
|
|
$file->name = $_GET['filename']; |
|
21
|
|
|
$file->exchange_id = $this->exchange->id; |
|
22
|
|
|
$file->status = 'pending'; |
|
23
|
|
|
$file->save(); |
|
24
|
|
|
|
|
25
|
|
|
$filename = \Tools::parsePath($_GET['filename']); |
|
26
|
|
|
if (strpos($filename, '/') !== false) { |
|
27
|
|
|
$subDir = substr($filename, 0, strrpos($filename, "/") + 1); |
|
28
|
|
|
\Tools::createDir($dir . '/' . $subDir); |
|
29
|
|
|
} |
|
30
|
|
|
$text = ''; |
|
31
|
|
|
if (false === file_put_contents($dir . '/' . $filename, file_get_contents("php://input"), FILE_APPEND)) { |
|
32
|
|
|
$text = 'Fail on save file: ' . $filename; |
|
33
|
|
|
$file->status = 'failure'; |
|
34
|
|
|
} else { |
|
35
|
|
|
$file->size = ceil(filesize($dir . '/' . $filename)); |
|
36
|
|
|
$file->name = $filename; |
|
37
|
|
|
$file->status = 'success'; |
|
38
|
|
|
} |
|
39
|
|
|
if (strpos($filename, '1cbitrix') !== false) { |
|
40
|
|
|
$data = new \SimpleXMLElement(file_get_contents($dir . '/' . $filename)); |
|
41
|
|
|
$orders = new \Exchange1c\Parser\Orders($data); |
|
42
|
|
|
$orders->process(); |
|
43
|
|
|
} |
|
44
|
|
|
if ($file->status === 'success') { |
|
45
|
|
|
$pathinfo = pathinfo($filename); |
|
46
|
|
|
if ($pathinfo['extension'] === 'zip') { |
|
47
|
|
|
$zip = new \ZipArchive; |
|
48
|
|
|
if ($zip->open($dir . '/' . $filename) === TRUE) { |
|
49
|
|
|
$zip->extractTo($dir); |
|
50
|
|
|
$zip->close(); |
|
51
|
|
|
} else { |
|
|
|
|
|
|
52
|
|
|
//comment for chained files working |
|
53
|
|
|
//$text = 'Fail on unzip file: ' . $filename; |
|
|
|
|
|
|
54
|
|
|
//$file->status = 'failure'; |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
$file->save(); |
|
59
|
|
|
\App::$cur->exchange1c->response($file->status, $text, false); |
|
60
|
|
|
$this->end($file->status); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for the
elsebranches ofifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
elsebranches can be removed.could be turned into
This is much more concise to read.