ProgressBar example

$output->writeln('');

            return self::SUCCESS;
        }

        if ((int) $indexTask['doc_count'] > 0) {
            $table->addRow(['Indexing', 'in progress']);

            $table->render();
            $output->writeln('');

            $progressBar = new ProgressBar($output$totalProducts);
            $progressBar->advance($totalProducts - $indexTask['doc_count']);
            $output->writeln('');
        } else {
            $table->addRow(['Indexing', 'completed']);
            $table->render();
            $output->writeln('');
        }

        /** @var list<string> $usedIndices */
        $usedIndices = array_keys($this->client->indices()->getAlias(['name' => $indexTask['alias']]));

        
$path = $input->getArgument('path');
        }

        $numberOfFiles = 0;
        if (!$input->getOption('skip-scan')) {
            // Do not count directories, the many sub-dirs would otherwise throw off the progressbar             $numberOfFiles = \count(array_filter($mediaService->getFilesystem()->listContents($path, true)function Darray $element) {
                return $element['type'] === 'file';
            }));
        }

        $progress = new ProgressBar($output$numberOfFiles);

        $this->optimizeFiles($path$input$mediaService$optimizerService$progress$output);

        $progress->finish();

        return 0;
    }

    /** * @throws Exception */
    
if ($parent === null) {
                return 1;
            }
        }

        $copyProductAssociations = !$input->getOption('noArticleAssociations');

        $count = $this->container->get(ModelManager::class)
            ->getRepository(Category::class)
            ->getChildrenCountList($originalCategory->getId());

        $this->progressBar = new ProgressBar($output$count);
        $this->progressBar->start();

        try {
            $this->duplicateCategory($originalCategory->getId()$parent->getId()$copyProductAssociations);
        } catch (RuntimeException $e) {
            $output->writeln('<error>' . $e->getMessage() . '</error>');

            return 1;
        }

        $this->progressBar->finish();

        
/** * {@inheritdoc} */
    public function start($count$label = '')
    {
        $this->count = $count;
        $this->current = 0;
        if ($label) {
            $this->output->writeln($label);
        }
        $this->progress = new ProgressBar($this->output, $count);
        $this->progress->setFormat('very_verbose');
    }

    /** * {@inheritdoc} */
    public function advance($step = 1)
    {
        if ($this->current + $step > $this->count) {
            $step = $this->count - $this->current;
        }
        
public function migrate(MediaServiceInterface $fromFilesystem, MediaServiceInterface $toFileSystem, OutputInterface $output$skipScan = false)
    {
        $output->writeln(' // Migrating all media files in your filesystem. This might take some time, depending on the number of media files you have.');
        $output->writeln('');

        $filesToMigrate = 0;

        if (!$skipScan) {
            $filesToMigrate = $this->countFilesToMigrate('media', $fromFilesystem);
        }

        $progressBar = new ProgressBar($output$filesToMigrate);
        $progressBar->setFormat(" %current%/%max% [%bar%] %percent%%, %migrated% migrated, %skipped% skipped, %moved% moved, Elapsed: %elapsed%\n Current file: %filename%");
        $progressBar->setMessage('', 'filename');
        $this->migrateFilesIn('media', $fromFilesystem$toFileSystem$progressBar);
        $progressBar->finish();

        $rows = [];
        foreach ($this->counter as $key => $value) {
            $rows[] = [$key$value];
        }

        $output->writeln('');
        

        $stopwatch = new Stopwatch();
        $stopwatch->start('es-indexing');
        $this->io = new ShopwareStyle($input$output);

        if (!$this->enabled) {
            $this->io->error('Elasticsearch indexing is disabled');

            return self::FAILURE;
        }

        $progressBar = new ProgressBar($output);
        $progressBar->start();

        $offset = null;
        while ($message = $this->indexer->iterate($offset)) {
            $offset = $message->getOffset();

            $step = \count($message->getData()->getIds());

            if ($input->getOption('no-queue')) {
                $this->indexer->__invoke($message);

                
$question = new ConfirmationQuestion('This will delete all files unnecessary to build the administration. Do you want to continue? (y/n)');

        if (!$helper->ask($input$output$question)) {
            $output->writeln('Command aborted!');

            return 0;
        }

        $adminDir = \dirname((string) (new \ReflectionClass(Administration::class))->getFileName());
        $output->writeln('Deleting unnecessary files of the administration after the build process...');
        $progressBar = new ProgressBar($output, 100);

        $finder = new Finder();

        // Find all files in Administration/Resources/app/administration/src/module except for de-DE.json and en-GB.json         $finder->in($adminDir . '/Resources/app/administration/src/module')
            ->notName('de-DE.json')
            ->notName('en-GB.json')
            ->files();

        foreach ($finder as $file) {
            unlink($file->getRealPath());
        }
return implode("\n", $lines);
    }

    /** * @param int $max Maximum steps (0 if unknown) * * @return ProgressBar */
    public function createProgressBar($max = 0)
    {
        return new ProgressBar($this->output, $max);
    }

    /** * Clear screen */
    public function cls()
    {
        if (!$this->input->isInteractive()) {
            return;
        }

        
$output->writeln('Rebuild path info');
            $component->rebuildCategoryPath();
            $output->writeln('Removing assignments');
            $component->removeAllAssignments();
        }

        // Get total number of assignments to build         $output->write('Counting…');
        $count = $component->rebuildAllAssignmentsCount();
        $output->writeln("\rCounted {$count} items");

        $progressHelper = new ProgressBar($output$count);
        $progressHelper->setFormat(' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed%');

        // create the assignments         while ($progress < $count) {
            $component->rebuildAllAssignments($limit$progress);
            $progress += $limit;
            $progressHelper->advance();
        }
        $progressHelper->finish();

        $output->writeln("\nDone");

        
$this->setVisibility($this->filesystemAsset, $style, 'public');

        $style->info('Finished setting visibility of objects in all pre-defined buckets.');

        return Command::SUCCESS;
    }

    private function setVisibility(FilesystemOperator $filesystem, ShopwareStyle $style, string $visibility): void
    {
        $files = array_filter($filesystem->listContents('/', true)->toArray()fn (StorageAttributes $object): bool => $object->type() === 'file');
        ProgressBar::setFormatDefinition('custom', '[%bar%] %current%/%max% -- %message%');
        $progressBar = new ProgressBar($style, \count((array) $files));
        $progressBar->setFormat('custom');
        $progressBar->setMessage('');

        foreach ($files as $file) {
            $filesystem->setVisibility($file->path()$visibility);

            $progressBar->advance();
            $progressBar->setMessage($file->path());
        }

        $progressBar->finish();
    }
$this->output->writeln("Generating Thumbnails for Album {$album->getName()} (ID: {$album->getId()})");

        $em = $this->getContainer()->get(ModelManager::class);

        $repository = $em->getRepository(Media::class);

        $query = $repository->getAlbumMediaQuery($album->getId());
        $paginator = $em->createPaginator($query);

        $total = $paginator->count();

        $progressBar = new ProgressBar($this->output, $total);
        $progressBar->setRedrawFrequency(10);
        $progressBar->start();

        foreach ($paginator as $media) {
            try {
                $this->createMediaThumbnails($media);
            } catch (Exception $e) {
                $this->errors[] = $e->getMessage();
            }

            $progressBar->advance();
        }
Home | Imprint | This part of the site doesn't use cookies.