Back to RemoveOldFilesCommand class

Method doExecute

protected int
doExecute
(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
Internal function to execute the command.
Parameters
  • \Symfony\Component\Console\Input\InputInterface $input The input to inject into the command.
  • \Symfony\Component\Console\Output\OutputInterface $output The output to inject into the command.
Returns
  • int The command exit code
Since
  • 4.0.0

Method doExecute - Source code

/**
 * Internal function to execute the command.
 *
 * @param   InputInterface  $input   The input to inject into the command.
 * @param   OutputInterface $output  The output to inject into the command.
 *
 * @return  integer  The command exit code
 *
 * @since   4.0.0
 */
protected function doExecute(InputInterface $input, OutputInterface $output) : int
{
    $symfonyStyle = new SymfonyStyle($input, $output);
    $dryRun = $input->getOption('dry-run');
    $symfonyStyle->title('Removing Unneeded Files & Folders' . ($dryRun ? ' - Dry Run' : ''));
    // We need the update script
    \JLoader::register('JoomlaInstallerScript', JPATH_ADMINISTRATOR . '/components/com_admin/script.php');
    $status = (new \JoomlaInstallerScript())->deleteUnexistingFiles($dryRun, true);
    if ($output->isVeryVerbose() || $output->isDebug()) {
        foreach ($status['files_checked'] as $file) {
            $exists = in_array($file, array_values($status['files_exist']));
            if ($exists) {
                $symfonyStyle->writeln('<error>File Checked & Exists</error> - ' . $file, OutputInterface::VERBOSITY_VERY_VERBOSE);
            } else {
                $symfonyStyle->writeln('<info>File Checked & Doesn\'t Exist</info> - ' . $file, OutputInterface::VERBOSITY_DEBUG);
            }
        }
        foreach ($status['folders_checked'] as $folder) {
            $exists = in_array($folder, array_values($status['folders_exist']));
            if ($exists) {
                $symfonyStyle->writeln('<error>Folder Checked & Exists</error> - ' . $folder, OutputInterface::VERBOSITY_VERY_VERBOSE);
            } else {
                $symfonyStyle->writeln('<info>Folder Checked & Doesn\'t Exist</info> - ' . $folder, OutputInterface::VERBOSITY_DEBUG);
            }
        }
    }
    if ($dryRun === false) {
        foreach ($status['files_deleted'] as $file) {
            $symfonyStyle->writeln('<comment>File Deleted = ' . $file . '</comment>', OutputInterface::VERBOSITY_VERBOSE);
        }
        foreach ($status['files_errors'] as $error) {
            $symfonyStyle->error($error);
        }
        foreach ($status['folders_deleted'] as $folder) {
            $symfonyStyle->writeln('<comment>Folder Deleted = ' . $folder . '</comment>', OutputInterface::VERBOSITY_VERBOSE);
        }
        foreach ($status['folders_errors'] as $error) {
            $symfonyStyle->error($error);
        }
    }
    $symfonyStyle->success(sprintf($dryRun ? '%s Files checked and %s would be deleted' : '%s Files checked and %s deleted', \count($status['files_checked']), $dryRun ? \count($status['files_exist']) : \count($status['files_deleted'])));
    $symfonyStyle->success(sprintf($dryRun ? '%s Folders checked and %s would be deleted' : '%s Folders checked and %s deleted', \count($status['folders_checked']), $dryRun ? \count($status['folders_exist']) : \count($status['folders_deleted'])));
    return Command::SUCCESS;
}