metadataPool = $metadataPool; $this->resourceConnection = $resourceConnection; $this->dateTime = $dateTime; $this->scopeConfig = $scopeConfig; $this->date = $time; } /** * Remove all expired bulks and corresponding operations * * @return void */ public function execute() { $metadata = $this->metadataPool->getMetadata(BulkSummaryInterface::class); $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName()); $bulkLifetime = 3600 * 24 * (int)$this->scopeConfig->getValue('system/bulk/lifetime'); $maxBulkStartTime = $this->dateTime->formatDate($this->date->gmtTimestamp() - $bulkLifetime); $connection->delete($metadata->getEntityTable(), ['start_time <= ?' => $maxBulkStartTime]); } }