Skip to content

Commit 6dad086

Browse files
authored
Merge pull request #46 from valguss/magento2
Magento2
2 parents e8fc753 + cdee1e4 commit 6dad086

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Console/Command/RemoveUnusedMediaCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function execute(InputInterface $input, OutputInterface $output) : void
7070
);
7171

7272
$directoryIterator = new \RecursiveDirectoryIterator($imageDir);
73+
74+
$imagesToKeep = $connection->fetchCol(
75+
'SELECT value FROM ' . $mediaGalleryTable
76+
);
7377

7478
foreach (new \RecursiveIteratorIterator($directoryIterator) as $file) {
7579

@@ -89,10 +93,7 @@ public function execute(InputInterface $input, OutputInterface $output) : void
8993
continue;
9094
}
9195

92-
$imageFound = $connection->fetchOne(
93-
'SELECT value FROM ' . $mediaGalleryTable . ' WHERE value = ?', array($filePath)
94-
);
95-
if ($imageFound) {
96+
if (in_array($filePath, $imagesToKeep)) {
9697
continue;
9798
}
9899

Console/Command/RestoreUseDefaultValueCommand.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Hackathon\EAVCleaner\Console\Command;
33

4+
use Magento\Framework\App\ProductMetadataInterface;
45
use Symfony\Component\Console\Command\Command;
56
use Symfony\Component\Console\Input\InputInterface;
67
use Symfony\Component\Console\Output\OutputInterface;
@@ -10,6 +11,20 @@ class RestoreUseDefaultValueCommand extends Command
1011
{
1112
public $questionHelper;
1213

14+
/**
15+
* @var ProductMetaDataInterface
16+
*/
17+
protected $productMetaData;
18+
19+
public function __construct(
20+
ProductMetaDataInterface $productMetaData,
21+
string $name = null
22+
)
23+
{
24+
parent::__construct($name);
25+
$this->productMetaData = $productMetaData;
26+
}
27+
1328
/**
1429
* Init command
1530
*/
@@ -52,6 +67,8 @@ public function execute(InputInterface $input, OutputInterface $output)
5267
$counts = array();
5368
$i = 0;
5469
$tables = array('varchar', 'int', 'decimal', 'text', 'datetime');
70+
$column = $this->productMetaData->getEdition() === 'Enterprise' ? 'row_id' : 'entity_id';
71+
5572

5673
foreach ($tables as $table) {
5774
// Select all non-global values
@@ -62,8 +79,8 @@ public function execute(InputInterface $input, OutputInterface $output)
6279
// Select the global value if it's the same as the non-global value
6380
$results = $db->fetchAll(
6481
'SELECT * FROM ' . $fullTableName
65-
. ' WHERE attribute_id = ? AND store_id = ? AND entity_id = ? AND value = ?',
66-
array($row['attribute_id'], 0, $row['entity_id'], $row['value'])
82+
. ' WHERE attribute_id = ? AND store_id = ? AND ' . $column . ' = ? AND value = ?',
83+
array($row['attribute_id'], 0, $row[$column], $row['value'])
6784
);
6885

6986
if (count($results) > 0) {

0 commit comments

Comments
 (0)