Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BulkSourceUnassign.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 
22 {
26  private $unassignValidator;
27 
31  private $bulkSourceUnassign;
32 
36  private $sourceIndexer;
37 
41  private $legacyIndexer;
42 
46  private $defaultSourceProvider;
47 
51  private $getProductIdsBySkus;
52 
63  public function __construct(
64  BulkSourceUnassignValidatorInterface $unassignValidator,
65  BulkSourceUnassignResource $bulkSourceUnassign,
66  DefaultSourceProviderInterface $defaultSourceProvider,
67  GetProductIdsBySkus $getProductIdsBySkus,
68  SourceIndexer $sourceIndexer,
69  LegacyIndexer $legacyIndexer
70  ) {
71  $this->unassignValidator = $unassignValidator;
72  $this->bulkSourceUnassign = $bulkSourceUnassign;
73  $this->sourceIndexer = $sourceIndexer;
74  $this->legacyIndexer = $legacyIndexer;
75  $this->defaultSourceProvider = $defaultSourceProvider;
76  $this->getProductIdsBySkus = $getProductIdsBySkus;
77  }
78 
84  private function reindexLegacy(array $skus): void
85  {
86  $productIds = array_values($this->getProductIdsBySkus->execute($skus));
87  $this->legacyIndexer->executeList($productIds);
88  }
89 
94  public function execute(array $skus, array $sourceCodes): int
95  {
96  $validationResult = $this->unassignValidator->validate($skus, $sourceCodes);
97  if (!$validationResult->isValid()) {
98  throw new ValidationException(__('Validation Failed'), null, 0, $validationResult);
99  }
100 
101  $res = $this->bulkSourceUnassign->execute($skus, $sourceCodes);
102 
103  $this->sourceIndexer->executeList($sourceCodes);
104  if (in_array($this->defaultSourceProvider->getCode(), $sourceCodes, true)) {
105  $this->reindexLegacy($skus);
106  }
107 
108  return $res;
109  }
110 }
__construct(BulkSourceUnassignValidatorInterface $unassignValidator, BulkSourceUnassignResource $bulkSourceUnassign, DefaultSourceProviderInterface $defaultSourceProvider, GetProductIdsBySkus $getProductIdsBySkus, SourceIndexer $sourceIndexer, LegacyIndexer $legacyIndexer)
__()
Definition: __.php:13
foreach($websiteCodes as $websiteCode) $skus