<?php
namespace custommoduleScheduleContentNotifierPlugin;
use MagentoCmsModelPage;
use custommoduleScheduleContentNotifierHelperEmail;
use MagentoCmsStagingModelPageApplier;
use MagentoFrameworkIndexerCacheContext;
use MagentoStagingModelStagingApplierInterface;
use MagentoStagingApiUpdateRepositoryInterface;
/**
* Class PageApplier
*/
class PluginPageApplier
{
protected $_page;
protected $emailHelper;
/**
* @var UpdateRepositoryInterface
*/
protected $updateRepository;
/**
* @var MagentoFrameworkIndexerCacheContext
*/
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(MagentoFrameworkDBSelect::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();
}
}
}
}