44use Magento \Framework \App \ProductMetadataInterface ;
55use Symfony \Component \Console \Command \Command ;
66use Symfony \Component \Console \Input \InputInterface ;
7+ use Symfony \Component \Console \Input \InputOption ;
78use Symfony \Component \Console \Output \OutputInterface ;
89use Symfony \Component \Console \Question \ConfirmationQuestion ;
910
@@ -35,7 +36,14 @@ protected function configure()
3536 ->setDescription ("
3637 Restore product's 'Use Default Value' if the non-global value is the same as the global value
3738 " )
38- ->addOption ('dry-run ' );
39+ ->addOption ('dry-run ' )
40+ ->addOption (
41+ 'entity ' ,
42+ null ,
43+ InputOption::VALUE_OPTIONAL ,
44+ 'Set entity to cleanup (product or category) ' ,
45+ 'product '
46+ );
3947 }
4048
4149 /**
@@ -49,6 +57,12 @@ protected function configure()
4957 public function execute (InputInterface $ input , OutputInterface $ output )
5058 {
5159 $ isDryRun = $ input ->getOption ('dry-run ' );
60+ $ entity = $ input ->getOption ('entity ' );
61+
62+ if (!in_array ($ entity , ['product ' , 'category ' ])) {
63+ $ output ->writeln ('Please specify the entity with --entity. Possible options are product or category ' );
64+ return ;
65+ }
5266
5367 if (!$ isDryRun && $ input ->isInteractive ()) {
5468 $ output ->writeln ('WARNING: this is not a dry run. If you want to do a dry-run, add --dry-run. ' );
@@ -72,7 +86,7 @@ public function execute(InputInterface $input, OutputInterface $output)
7286
7387 foreach ($ tables as $ table ) {
7488 // Select all non-global values
75- $ fullTableName = $ db ->getTableName ('catalog_product_entity_ ' . $ table );
89+ $ fullTableName = $ db ->getTableName ('catalog_ ' . $ entity . ' _entity_ ' . $ table );
7690 $ rows = $ db ->fetchAll ('SELECT * FROM ' . $ fullTableName . ' WHERE store_id != 0 ' );
7791
7892 foreach ($ rows as $ row ) {
0 commit comments