-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.php
More file actions
129 lines (105 loc) · 3.41 KB
/
Copy pathscript.php
File metadata and controls
129 lines (105 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
use Bitrix\Main\ArgumentException;
use Bitrix\Main\Loader;
use Bitrix\Main\ObjectPropertyException;
use Bitrix\Main\SystemException;
use free\Main\Orm\FilesFormatTable;
$_SERVER['DOCUMENT_ROOT'] = realpath(__DIR__);
require_once 'bitrix/modules/main/cli/bootstrap.php';
class Parsing
{
public $formats = [];
public $csv = [];
/**
* @throws ObjectPropertyException
* @throws SystemException
* @throws ArgumentException
*/
public function __construct()
{
Loader::IncludeModule('highloadblock');
$this->formats = $this->getFormats();
$this->csv = $this->getCsv();
$this->extendedFormats();
$this->updateFormatTo();
}
/**
* @throws ObjectPropertyException
* @throws SystemException
* @throws ArgumentException
*/
public function getFormats(): array
{
$result = FilesFormatTable::query()
->setSelect(['*'])
->fetchAll();
foreach ($result as $item) {
$formats[$item['UF_FORMAT']] = $item;
}
return $formats ?? [];
}
/**
* @return array
*/
public function getCsv(): array
{
$id = '****
';
//ссыль на документ после spreadsheets/d/
$gid = '0';
// $gid = id страницы
$csv = file_get_contents('https://docs.google.com/spreadsheets/d/' . $id . '/export?format=csv&gid=' . $gid);
$csv = explode("\r\n", $csv);
return array_map('str_getcsv', $csv);
}
/**
* @return void
*/
public function extendedFormats(): void
{
foreach ($this->csv as $array) {
if (!isset($this->formats[$array[7]])) {
$result = FilesFormatTable::add(['UF_FORMAT' => $array[7]]);
if ($result->isSuccess()) {
$this->formats[$array[7]] = [
'ID' => $result->getId(),
'UF_FORMAT' => $array[7],
];
} else {
echo "произошёл факап";
var_dump($result->getErrorMessages());
}
}
}
}
public function updateFormatTo()
{
$updateFormats = [];
foreach ($this->csv as $array) {
$formatFrom = $array[7];
$formatTo = $array[9];
$idFormatFrom = $this->formats[$formatFrom]['ID'];
$idFormatTo = $this->formats[$formatTo]['ID'];
if (isset($idFormatTo, $idFormatFrom)) {
if (in_array($idFormatTo, $this->formats[$formatFrom]['UF_FORMAT_TO'])) {
continue;
}
$this->formats[$formatFrom]['UF_FORMAT_TO'][] = $idFormatTo;
$updateFormats[] = $formatFrom;
// $result = FilesFormatTable::update($idForUpdate, ['UF_FORMAT_TO' => $this->formats[$array[7]]['UF_FORMAT_TO']]);
echo '<pre>';
var_dump($idFormatTo);
echo '<pre>';
} else {
echo "";
}
}
var_dump($updateFormats);
$updateFormats = array_unique($updateFormats);
foreach ($updateFormats as $format) {
$id = $this->formats[$format]['ID'];
$result = FilesFormatTable::update($id, ['UF_FORMAT_TO' => $this->formats[$format]['UF_FORMAT_TO']]);
}
}
}
new Parsing();