0
<?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();
            }

        }
    }
}
1
  • Could you please explain your question?
    – Daniel
    Commented Jun 1, 2023 at 13:07

1 Answer 1

1

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.