-
Notifications
You must be signed in to change notification settings - Fork 197
/
AttributeSetLeftoverDataCleaner.php
83 lines (75 loc) · 2.29 KB
/
AttributeSetLeftoverDataCleaner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Migration\Step\PostProcessing\Data;
use Migration\ResourceModel;
use Migration\App\ProgressBar;
use Migration\App\Progress;
use Migration\Logger\Manager as LogManager;
use \Migration\Step\PostProcessing\Model\AttributeSetLeftoverData as AttributeSetLeftoverDataModel;
/**
* Class AttributeSetLeftoverDataCleaner
*/
class AttributeSetLeftoverDataCleaner
{
/**
* @var ResourceModel\Destination
*/
private $destination;
/**
* @var ProgressBar\LogLevelProcessor
*/
private $progressBar;
/**
* @var Progress
*/
private $progress;
/**
* @var AttributeSetLeftoverDataModel
*/
private $attributeSetLeftoverDataModel;
/**
* @param ProgressBar\LogLevelProcessor $progressBar
* @param ResourceModel\Destination $destination
* @param Progress $progress
* @param AttributeSetLeftoverDataModel $attributeSetLeftoverDataModel
*/
public function __construct(
ProgressBar\LogLevelProcessor $progressBar,
ResourceModel\Destination $destination,
Progress $progress,
AttributeSetLeftoverDataModel $attributeSetLeftoverDataModel
) {
$this->destination = $destination;
$this->progressBar = $progressBar;
$this->progress = $progress;
$this->attributeSetLeftoverDataModel = $attributeSetLeftoverDataModel;
}
/**
* Records which are still in product entity tables but product attribute no longer exist in attribute set
*/
public function clean()
{
$entityValueIds = $this->attributeSetLeftoverDataModel->getLeftoverIds();
if (!$entityValueIds) {
return ;
}
foreach ($this->attributeSetLeftoverDataModel->getDocuments() as $document) {
$this->progressBar->advance(LogManager::LOG_LEVEL_INFO);
if (isset($entityValueIds[$document]) && $entityValueIds[$document]) {
$this->destination->deleteRecords($document, 'value_id', $entityValueIds[$document]);
}
}
}
/**
* Get documents
*
* @return array
*/
public function getDocuments()
{
return $this->attributeSetLeftoverDataModel->getDocuments();
}
}