/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->setDecorated(true); $this->appState->setAreaCode('catalog'); $connection = $this->attributeResource->getConnection(); $attributeTables = $this->getAttributeTables(); $progress = new \Symfony\Component\Console\Helper\ProgressBar($output, count($attributeTables)); $progress->setFormat('<comment>%message%</comment> %current%/%max% [%bar%] %percent:3s%% %elapsed%'); $this->attributeResource->beginTransaction(); try { // Find and remove unused attributes foreach ($attributeTables as $attributeTable) { $progress->setMessage($attributeTable . ' '); $affectedIds = $this->getAffectedAttributeIds($connection, $attributeTable); if (count($affectedIds) > 0) { $connection->delete($attributeTable, ['value_id in (?)' => $affectedIds]); } $progress->advance(); } $this->attributeResource->commit(); $output->writeln(""); $output->writeln("<info>Unused product attributes successfully cleaned up:</info>"); $output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>"); } catch (\Exception $exception) { $this->attributeResource->rollBack(); $output->writeln(""); $output->writeln("<error>{$exception->getMessage()}</error>"); } }
/** * @return array|false */ private function getUnusedProductAttribute() { $connection = $this->attributeResource->getConnection(); $select = $connection->select(); $select->from($this->attributeResource->getTable('catalog_product_entity_varchar')); $select->where('value = ?', 'Simple fixture store'); return $connection->fetchRow($select); }
/** * {@inheritdoc} */ public function getConnection() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getConnection'); if (!$pluginInfo) { return parent::getConnection(); } else { return $this->___callPlugins('getConnection', func_get_args(), $pluginInfo); } }