31 public function __construct(?
int $blockId, array $params = [])
39 $this->block = $params[
'block'];
40 $this->content = $params[
'content'];
41 $this->manifest = $this->block->getManifest();
45 $this->block =
new Block($blockId);
46 $this->content = $this->block->getContent();
47 $this->manifest = $this->block->getManifest();
57 public function update(
bool $needSave =
false): string
60 if (isset($this->manifest[
'nodes']) && is_array($this->manifest[
'nodes']))
62 foreach ($this->manifest[
'nodes'] as $selector => $node)
64 if (in_array($node[
'type'], self::IMG_TYPES,
true))
66 $nodeClass = Node\Type::getClassName($node[
'type']);
67 $previousValues = call_user_func([$nodeClass,
'getNode'], $this->block, $selector);
69 foreach ($previousValues as $previousValue)
71 if (!($previousValue[
'id'] ??
null) && !($previousValue[
'id2x'] ??
null))
89 $previousValue[
'isLazy'] ===
'Y'
90 ? $previousValue[
'lazyOrigSrc']
91 : $previousValue[
'src']
93 if ($previousSrc !== $newSrc)
95 $srcForReplace[$previousSrc] = $newSrc;
98 if (strpos($newSrc, $hostUrl) === 0)
100 $srcForReplace[str_replace($hostUrl,
'', $previousSrc)] =
101 str_replace($hostUrl,
'', $newSrc);
105 if ($previousValue[
'id2x'])
110 $previousValue[
'isLazy'] ===
'Y'
111 ? $previousValue[
'lazyOrigSrc2x']
112 : $previousValue[
'src2x']
114 if ($previousSrc2x !== $newSrc2x)
116 $srcForReplace[$previousSrc2x] = $newSrc2x;
119 if (strpos($newSrc2x, $hostUrl) === 0)
121 $srcForReplace[str_replace($hostUrl,
'', $previousSrc2x)] =
122 str_replace($hostUrl,
'', $newSrc2x);
131 if (!empty($srcForReplace))
133 $this->content = str_replace(
134 array_keys($srcForReplace),
135 array_values($srcForReplace),
141 $this->block->saveContent($this->content);
142 $this->block->save();
173 $oldPath =
'/' . $duplicate->getSubdir() .
'/' . $duplicate->getFileName();
174 $newPath =
'/' . $original->getSubdir() .
'/' . $original->getFileName();
176 $resFiles = FileTable::query()
177 ->addSelect(
'ENTITY_ID')
179 ->where(
'FILE_ID', $duplicate->getId())
182 while($blockFile = $resFiles->fetch())
184 $resBlocks = BlockTable::query()
186 ->addSelect(
'CONTENT')
187 ->addSelect(
'LANDING.SITE_ID')
188 ->where(
'ID', $blockFile[
'ENTITY_ID'])
191 while(
$block = $resBlocks->fetch())
193 BlockTable::update(
$block[
'ID'], [
194 'CONTENT' => str_replace($oldPath, $newPath,
$block[
'CONTENT'])
196 $siteId = (int)
$block[
'LANDING_INTERNALS_BLOCK_LANDING_SITE_ID'];
197 if ($siteId && $siteId > 0)
199 $sitesToUpdate[] = $siteId;
204 $sitesToUpdate = array_unique($sitesToUpdate);
205 foreach($sitesToUpdate as $siteId)
211 $landingsForUpdate = [];
212 $resFiles = FileTable::query()
213 ->addSelect(
'ENTITY_ID')
215 ->where(
'FILE_ID', $duplicate->getId())
218 while($assetFile = $resFiles->fetch())
220 $landingsForUpdate[] = abs((
int)$assetFile[
'ENTITY_ID']);
222 $landingsForUpdate = array_unique($landingsForUpdate);
223 foreach($landingsForUpdate as $landingId)