Skip to content

Commit 2fb6701

Browse files
committed
Update CleanUp.php
1 parent 1e02412 commit 2fb6701

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

Console/Command/CleanUp.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Console\Input\InputInterface; // for InputInterface used in execute method
1313
use Symfony\Component\Console\Output\OutputInterface; // for OutputInterface used in execute method
1414
use Symfony\Component\Filesystem\Filesystem;
15+
use Magento\Framework\App\ResourceConnection;
1516

1617
class CleanUp extends Command
1718
{
@@ -35,21 +36,47 @@ class CleanUp extends Command
3536
'report_viewed_product_index',
3637
];
3738

39+
/**
40+
*
41+
* @var Filesystem
42+
*/
43+
private $filesystem;
44+
45+
/**
46+
*
47+
* @var ResourceConnection
48+
*/
49+
private $resource;
50+
51+
/**
52+
* @param Filesystem $filesystem
53+
* @param ResourceConnection $resource
54+
* @param string $name
55+
*/
56+
public function __construct(
57+
Filesystem $filesystem = null,
58+
ResourceConnection $resource = null,
59+
string $name = null
60+
) {
61+
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
62+
$this->resource = $resource ?: \Magento\Framework\App\ObjectManager::getInstance()->get(ResourceConnection::class);
63+
64+
parent::__construct($name);
65+
}
66+
3867
protected function configure()
3968
{
40-
// bin/magento cleanUp
69+
// command: bin/magento cleanUp
4170
$this->setName('cleanUp')
42-
->setDescription('Clear TMP Tables');
71+
->setDescription('Clear TMP Tables & Logs');
4372

4473
parent::configure();
4574
}
4675

4776
protected function execute(InputInterface $input, OutputInterface $output)
4877
{
49-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
50-
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
51-
$connection = $resource->getConnection('\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION');
52-
$fs = new Filesystem();
78+
$connection = $this->resource->getConnection();
79+
$fs = $this->filesystem;
5380
try {
5481
foreach ($this->tables as $table) {
5582
$connection->truncateTable($table);

0 commit comments

Comments
 (0)