/** * {@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>"); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $path = base_path('vendor'); $vendor_paths = \File::directories($path); $path = rtrim(rtrim($path, '\\'), '/'); $this->info('Сканируем установленные пакеты на наличие папок .git и .svn'); $check_directories = []; foreach ($vendor_paths as $vendor_path) { $package_paths = File::directories($vendor_path); foreach ($package_paths as $package_path) { $check_directories[] = (string) $package_path; } } $progress = new \Symfony\Component\Console\Helper\ProgressBar($this->output, sizeof($check_directories)); $progress->setFormat('debug'); $progress->start(); foreach ($check_directories as $directory) { $progress->advance(); $is_git = $this->checkGit($directory); if (!$is_git) { $this->checkSvn($directory); } } $progress->finish(); $this->info(''); $this->info('Сканирование завершено.'); $table = []; $separator = ['-', '-', '-', '-']; if ($this->touched_git) { $this->info('Имеются изменные файлы GIT: '); foreach ($this->touched_git as $package_path => $files) { $package = larasafepath($package_path); foreach ($files as $file => $type) { $table[] = ['GIT', $package, larasafepath($file), \Illuminate\Support\Arr::get($this->git_types, $type, $type)]; } $table[] = $separator; } } if ($this->touched_svn) { $this->info('Имеются изменные файлы SVN: '); foreach ($this->touched_svn as $package_path => $files) { $package = larasafepath($package_path); foreach ($files as $file => $type) { $table[] = ['SVN', $package, trim(str_replace($package, '', larasafepath($file)), '/'), \Illuminate\Support\Arr::get($this->svn_types, $type, $type)]; } $table[] = $separator; } } if ($table) { unset($table[sizeof($table) - 1]); $this->info(''); $this->table(['VCS', 'package', 'file', 'type'], $table); } }
protected function dumpTables() { $this->info('Копирование информации из таблиц'); $progress = new \Symfony\Component\Console\Helper\ProgressBar($this->output, sizeof($this->tables)); $progress->setFormat('debug'); $progress->start(); foreach ($this->tables as $table) { $data = \DB::connection($this->connection_name)->table($table)->get(); $this->saveTable($table, $data); $progress->advance(); } $progress->finish(); $this->info(''); $this->info('Таблицы успешно скопированы'); }