<?php
namespace custommodule\ScheduleContentNotifier\Plugin;
use Magento\Cms\Model\Page;
use custommodule\ScheduleContentNotifier\Helper\Email;
use Magento\CmsStaging\Model\PageApplier;
use Magento\Framework\Indexer\CacheContext;
use Magento\Staging\Model\StagingApplierInterface;
use Magento\Staging\Api\UpdateRepositoryInterface;
/**
* Class PageApplier
*/
class PluginPageApplier
{
protected $_page;
protected $emailHelper;
/**
* @var UpdateRepositoryInterface
*/
protected $updateRepository;
/**
* @var \Magento\Framework\Indexer\CacheContext
*/
private $cacheContext;
/**
* PageStagingApplier constructor.
* @param CacheContext $cacheContext
*/
public function __construct(
UpdateRepositoryInterface $updateRepository,
CacheContext $cacheContext,
page $page,
Email $emailHelper,
) {
$this->updateRepository = $updateRepository;
$this->cacheContext = $cacheContext;
$this->_page = $page;
$this->emailHelper = $emailHelper;
}
/**
* @param array $entityIds
* @return void
*/
public function aroundExecute(PageApplier $subject, callable $proceed, array $entityIds)
{
if ($entityIds)
{
$currentVersionId = $this->updateRepository->getVersionMaxIdByTime(
strtotime("now")
);
$select = $this->_page->getCollection()->reset(\Zend_Db_Select::COLUMNS)->reset(\Magento\Framework\DB\Select::WHERE)->columns(['entity_id'])
->joinLeft(['ss' => 'staging_update'], 'e.created_in = ss.id', ['id'])
->where('e.entity_id IN (?)', $entityIds)
->where('e.created_in =?', $currentVersionId)
->where('ss.is_rollback IS NULL');
$result = $this->_page
->getConnection()
->fetchOne($select);
if (isset($result) && $result) {
$this->emailHelper->sendEmail();
}
}
}
}
-
Could you please explain your question?– DanielCommented Jun 1, 2023 at 13:07
Add a comment
|
1 Answer
The problem lies in attempting to invoke the "reset" function on the collection directly, rather than on the select. The collection does not possess a "reset" function. To resolve this, you should initially invoke "getSelect()" to obtain the select and subsequently call "reset" on it instead:
$select = $this->_page->getCollection()
->getSelect()
->reset(\Zend_Db_Select::COLUMNS)
->reset(\Magento\Framework\DB\Select::WHERE)
->columns(['entity_id'])
->joinLeft(['ss' => 'staging_update'], 'e.created_in = ss.id', ['id'])
->where('e.entity_id IN (?)', $entityIds)
->where('e.created_in =?', $currentVersionId)
->where('ss.is_rollback IS NULL');