diff --git a/vendor/magento/module-cms/Model/ResourceModel/Page/Query/PageIdsList.php b/vendor/magento/module-cms/Model/ResourceModel/Page/Query/PageIdsList.php new file mode 100644 index 00000000000..356848855d2 --- /dev/null +++ b/vendor/magento/module-cms/Model/ResourceModel/Page/Query/PageIdsList.php @@ -0,0 +1,98 @@ +resourceConnection = $resourceConnection; + } + + /** + * Returns connection. + * + * @return AdapterInterface + */ + private function getConnection(): AdapterInterface + { + if (!$this->connection) { + $this->connection = $this->resourceConnection->getConnection(); + } + + return $this->connection; + } + + /** + * Get all pages that contain blocks identified by ids or identifiers + * + * @param array $ids + * @return array + */ + public function execute(array $ids = []): array + { + $select = $this->getConnection()->select() + ->from( + ['main_table' => $this->resourceConnection->getTableName('cms_page')], + ['main_table.page_id'] + ); + if (count($ids)) { + foreach ($ids as $id) { + $select->orWhere( + "MATCH (title, meta_keywords, meta_description, identifier, content) + AGAINST ('block_id=\"$id\"')" + ); + } + $identifiers = $this->getBlockIdentifiersByIds($ids); + foreach ($identifiers as $identifier) { + $select->orWhere( + "MATCH (title, meta_keywords, meta_description, identifier, content) + AGAINST ('block_id=\"$identifier\"')" + ); + } + } else { + $select->where("MATCH (title, meta_keywords, meta_description, identifier, content) + AGAINST ('block_id=')"); + } + + return $this->connection->fetchCol($select); + } + + /** + * Get blocks identifiers based on ids + * + * @param array $ids + * @return array + */ + private function getBlockIdentifiersByIds(array $ids): array + { + $select = $this->getConnection()->select() + ->from( + ['main_table' => $this->resourceConnection->getTableName('cms_block')], + ['main_table.identifier'] + )->where('block_id IN (?)', $ids, \Zend_Db::INT_TYPE); + + return $this->connection->fetchCol($select); + } +}