Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
nodeimg.php
1
<?php
2
namespace
Bitrix\Landing\Update\Block
;
3
4
use \Bitrix\Landing\File;
5
use \Bitrix\Landing\Internals\BlockTable;
6
use \Bitrix\Main\Entity;
7
use \Bitrix\Main\Update\Stepper;
8
use \Bitrix\Main\Config\Option;
9
use \Bitrix\Main\Localization\Loc;
10
11
Loc::loadMessages
(__FILE__);
12
13
class
NodeImg
extends
Stepper
14
{
15
protected
static
$moduleId
=
'landing'
;
16
22
public
function
getFileHash
($id)
23
{
24
return
md5($id .
'|'
. LICENSE_KEY);
25
}
26
32
public
function
execute
(array &$result)
33
{
34
$lastId = Option::get(
'landing'
,
'update_block_nodeimg'
, 0);
35
36
$toSave = array();
37
$finished =
true
;
38
39
// gets common quantity
40
$res = BlockTable::getList(array(
41
'select'
=> array(
42
new
\
Bitrix
\Main\
Entity
\
ExpressionField
(
43
'CNT'
,
'COUNT(*)'
44
)
45
)
46
));
47
if
($row = $res->fetch())
48
{
49
$result[
'count'
] = $row[
'CNT'
];
50
}
51
52
// gets group for update
53
$res = BlockTable::getList(array(
54
'select'
=> array(
55
'ID'
,
'CONTENT'
56
),
57
'filter'
=> array(
58
'>ID'
=> $lastId
59
),
60
'order'
=> array(
61
'ID'
=>
'ASC'
62
),
63
'limit'
=> 100
64
));
65
while
($row = $res->fetch())
66
{
67
$files = array();
68
$fileExist = preg_match_all(
69
'/data\-([?fileid|filehash]+)\="([^"]+)"[^>]+data\-[?fileid|filehash]+\="([^"]+)"/is'
,
70
$row[
'CONTENT'
],
71
$matches
72
);
73
if
($fileExist)
74
{
75
foreach
($matches[1] as $i => $attr)
76
{
77
if
($attr ==
'fileid'
)
78
{
79
$files[$matches[2][$i]] = $matches[3][$i];
80
}
81
else
82
{
83
$files[$matches[3][$i]] = $matches[2][$i];
84
}
85
}
86
foreach
($files as $fileId => $fileHash)
87
{
88
if
($fileId > 0 && $this->
getFileHash
($fileId) == $fileHash)
89
{
90
if
(!isset($toSave[$row[
'ID'
]]))
91
{
92
$toSave[$row[
'ID'
]] = array();
93
}
94
$toSave[$row[
'ID'
]][] = $fileId;
95
}
96
}
97
}
98
$lastId = $row[
'ID'
];
99
$result[
'steps'
]++;
100
$finished =
false
;
101
}
102
103
// add files from blocks
104
foreach
($toSave as $block => $files)
105
{
106
File::addToBlock
($block, $files);
107
}
108
109
// clear handlers all continue work
110
if
(!$finished)
111
{
112
Option::set(
'landing'
,
'update_block_nodeimg'
, $lastId);
113
return
true
;
114
}
115
else
116
{
117
Option::delete(
'landing'
, array(
'name'
=>
'update_block_nodeimg'
));
118
$eventManager = \Bitrix\Main\EventManager::getInstance();
119
$eventManager->unregisterEventHandler(
120
'landing'
,
121
'\Bitrix\Landing\Internals\Block::OnBeforeDelete'
,
122
'landing'
,
123
'\Bitrix\Landing\Update\Block\NodeImg'
,
124
'disableBlockDelete'
);
125
$eventManager->unregisterEventHandler(
126
'landing'
,
127
'onLandingPublication'
,
128
'landing'
,
129
'\Bitrix\Landing\Update\Block\NodeImg'
,
130
'disablePublication'
131
);
132
return
false
;
133
}
134
}
135
141
public
static
function
disableBlockDelete
(
Entity
\
Event
$event)
142
{
143
$result =
new
Entity\EventResult();
144
$result->setErrors(array(
145
new
Entity
\
EntityError
(
146
Loc::getMessage
(
'LANDING_BLOCK_DISABLE_DELETE'
),
147
'BLOCK_DISABLE_DELETE'
148
)
149
));
150
return
$result;
151
}
152
158
public
static
function
disablePublication
(\
Bitrix
\Main\
Event
$event)
159
{
160
$result =
new
Entity\EventResult;
161
$result->setErrors(array(
162
new
\
Bitrix
\Main\
Entity
\
EntityError
(
163
Loc::getMessage
(
'LANDING_DISABLE_PUBLICATION'
),
164
'LANDING_DISABLE_PUBLICATION'
165
)
166
));
167
return
$result;
168
}
169
}
Bitrix\Landing\File\addToBlock
static addToBlock(int $blockId, $fileId, bool $temp=false)
Definition
file.php:305
Bitrix\Landing\Update\Block\NodeImg
Definition
nodeimg.php:14
Bitrix\Landing\Update\Block\NodeImg\execute
execute(array &$result)
Definition
nodeimg.php:32
Bitrix\Landing\Update\Block\NodeImg\getFileHash
getFileHash($id)
Definition
nodeimg.php:22
Bitrix\Landing\Update\Block\NodeImg\disablePublication
static disablePublication(\Bitrix\Main\Event $event)
Definition
nodeimg.php:158
Bitrix\Landing\Update\Block\NodeImg\disableBlockDelete
static disableBlockDelete(Entity\Event $event)
Definition
nodeimg.php:141
Bitrix\Landing\Update\Block\NodeImg\$moduleId
static $moduleId
Definition
nodeimg.php:15
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\EntityError
Definition
entityerror.php:12
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\Update\Stepper
Definition
stepper.php:27
Bitrix\Landing\Update\Block
Definition
buttons.php:3
Bitrix
modules
landing
lib
update
block
nodeimg.php
Создано системой
1.10.0