Skip to content

Commit 18800f0

Browse files
committed
ACP2E-1840: clear cache for pages that contain modified blocks.
1 parent 59f2672 commit 18800f0

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cms\Model\ResourceModel\Page\Query;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
13+
class PageIdsList
14+
{
15+
/**
16+
* @var ResourceConnection
17+
*/
18+
private $resourceConnection;
19+
20+
/**
21+
* @var AdapterInterface
22+
*/
23+
private $connection;
24+
25+
/**
26+
* @param ResourceConnection $resourceConnection
27+
*/
28+
public function __construct(ResourceConnection $resourceConnection)
29+
{
30+
$this->resourceConnection = $resourceConnection;
31+
}
32+
33+
/**
34+
* Returns connection.
35+
*
36+
* @return AdapterInterface
37+
*/
38+
private function getConnection(): AdapterInterface
39+
{
40+
if (!$this->connection) {
41+
$this->connection = $this->resourceConnection->getConnection();
42+
}
43+
44+
return $this->connection;
45+
}
46+
47+
/**
48+
* Get all pages that contain blocks identified by ids or identifiers
49+
*
50+
* @param array $ids
51+
* @return array
52+
*/
53+
public function execute(array $ids = []): array
54+
{
55+
$select = $this->getConnection()->select()
56+
->from(
57+
['main_table' => $this->resourceConnection->getTableName('cms_page')],
58+
['main_table.page_id']
59+
);
60+
if (count($ids)) {
61+
foreach ($ids as $id) {
62+
$select->orWhere(
63+
"MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=\"$id\"')"
64+
);
65+
}
66+
$identifiers = $this->getBlockIdentifiersByIds($ids);
67+
foreach ($identifiers as $identifier) {
68+
$select->orWhere(
69+
"MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=\"$identifier\"')"
70+
);
71+
}
72+
} else {
73+
$select->where("MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=')");
74+
}
75+
76+
return $this->connection->fetchCol($select);
77+
}
78+
79+
/**
80+
* Get blocks identifiers based on ids
81+
*
82+
* @param array $ids
83+
* @return array
84+
*/
85+
private function getBlockIdentifiersByIds(array $ids): array
86+
{
87+
$select = $this->getConnection()->select()
88+
->from(
89+
['main_table' => $this->resourceConnection->getTableName('cms_block')],
90+
['main_table.identifier']
91+
)->where('block_id IN (?)', $ids, \Zend_Db::INT_TYPE);
92+
93+
return $this->connection->fetchCol($select);
94+
}
95+
}

0 commit comments

Comments
 (0)