Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanupReservations.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
13 
18 {
22  private $resource;
23 
27  private $groupConcatMaxLen;
28 
33  public function __construct(
34  ResourceConnection $resource,
35  int $groupConcatMaxLen
36  ) {
37  $this->resource = $resource;
38  $this->groupConcatMaxLen = $groupConcatMaxLen;
39  }
40 
44  public function execute(): void
45  {
46  $connection = $this->resource->getConnection();
47  $reservationTable = $this->resource->getTableName('inventory_reservation');
48 
49  $select = $connection->select()
50  ->from(
51  $reservationTable,
52  ['GROUP_CONCAT(' . ReservationInterface::RESERVATION_ID . ')']
53  )
55  ->having('SUM(' . ReservationInterface::QUANTITY . ') = 0');
56  $connection->query('SET group_concat_max_len = ' . $this->groupConcatMaxLen);
57  $groupedReservationIds = implode(',', $connection->fetchCol($select));
58 
59  $condition = [ReservationInterface::RESERVATION_ID . ' IN (?)' => explode(',', $groupedReservationIds)];
60  $connection->delete($reservationTable, $condition);
61  }
62 }
$resource
Definition: bulk.php:12
__construct(ResourceConnection $resource, int $groupConcatMaxLen)
$connection
Definition: bulk.php:13