![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/mageworx/module-open-ai/Model/ResourceModel/QueueItem/ |
<?php declare(strict_types = 1); namespace MageWorx\OpenAI\Model\ResourceModel\QueueItem; use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; use Magento\Framework\Data\Collection\EntityFactoryInterface; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\Event\ManagerInterface; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use MageWorx\OpenAI\Api\Data\QueueItemInterface; use MageWorx\OpenAI\Model\Queue\QueueItem as Model; use MageWorx\OpenAI\Model\ResourceModel\DependencyChecker; use MageWorx\OpenAI\Model\ResourceModel\QueueItem as ResourceModel; use Psr\Log\LoggerInterface; class Collection extends AbstractCollection { protected DependencyChecker $dependencyChecker; public function __construct( EntityFactoryInterface $entityFactory, LoggerInterface $logger, FetchStrategyInterface $fetchStrategy, ManagerInterface $eventManager, DependencyChecker $dependencyChecker, AdapterInterface $connection = null, AbstractDb $resource = null ) { $this->dependencyChecker = $dependencyChecker; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } /** * Define model & resource model */ protected function _construct() { $this->_init(Model::class, ResourceModel::class); } /** * Add filter to get only items with all dependencies ready * * @return Collection */ public function addReadyDependenciesFilter(): Collection { $dependencyTable = $this->getTable('mageworx_openai_queue_dependencies'); $queueItemTable = $this->getMainTable(); // We need to make sure the subquery selects dependencies of dependencies as well $subSelect = $this->getConnection()->select() ->from( ['dependency' => $dependencyTable], ['dependency.dependency_item_id'] ) ->join( ['queue_item' => $queueItemTable], 'queue_item.entity_id = dependency.dependency_item_id', [] ) ->where('queue_item.status != ?', QueueItemInterface::STATUS_READY) ->where('dependency.queue_item_id = main_table.entity_id'); // Add NOT EXISTS condition to ensure we only get items with all dependencies ready $this->getSelect()->where('NOT EXISTS (?)', $subSelect); return $this; } }