[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Console; 11 12 use Joomla\Console\Command\AbstractCommand; 13 use Symfony\Component\Console\Command\Command; 14 use Symfony\Component\Console\Input\InputInterface; 15 use Symfony\Component\Console\Input\InputOption; 16 use Symfony\Component\Console\Output\OutputInterface; 17 use Symfony\Component\Console\Style\SymfonyStyle; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('JPATH_PLATFORM') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Console command for removing files which should have been cleared during an update 25 * 26 * @since 4.0.0 27 */ 28 class RemoveOldFilesCommand extends AbstractCommand 29 { 30 /** 31 * The default command name 32 * 33 * @var string 34 * @since 4.0.0 35 */ 36 protected static $defaultName = 'update:joomla:remove-old-files'; 37 38 /** 39 * Internal function to execute the command. 40 * 41 * @param InputInterface $input The input to inject into the command. 42 * @param OutputInterface $output The output to inject into the command. 43 * 44 * @return integer The command exit code 45 * 46 * @since 4.0.0 47 */ 48 protected function doExecute(InputInterface $input, OutputInterface $output): int 49 { 50 $symfonyStyle = new SymfonyStyle($input, $output); 51 52 $dryRun = $input->getOption('dry-run'); 53 54 $symfonyStyle->title('Removing Unneeded Files & Folders' . ($dryRun ? ' - Dry Run' : '')); 55 56 // We need the update script 57 \JLoader::register('JoomlaInstallerScript', JPATH_ADMINISTRATOR . '/components/com_admin/script.php'); 58 59 $status = (new \JoomlaInstallerScript())->deleteUnexistingFiles($dryRun, true); 60 61 if ($output->isVeryVerbose() || $output->isDebug()) { 62 foreach ($status['files_checked'] as $file) { 63 $exists = in_array($file, array_values($status['files_exist'])); 64 65 if ($exists) { 66 $symfonyStyle->writeln('<error>File Checked & Exists</error> - ' . $file, OutputInterface::VERBOSITY_VERY_VERBOSE); 67 } else { 68 $symfonyStyle->writeln('<info>File Checked & Doesn\'t Exist</info> - ' . $file, OutputInterface::VERBOSITY_DEBUG); 69 } 70 } 71 72 foreach ($status['folders_checked'] as $folder) { 73 $exists = in_array($folder, array_values($status['folders_exist'])); 74 75 if ($exists) { 76 $symfonyStyle->writeln('<error>Folder Checked & Exists</error> - ' . $folder, OutputInterface::VERBOSITY_VERY_VERBOSE); 77 } else { 78 $symfonyStyle->writeln('<info>Folder Checked & Doesn\'t Exist</info> - ' . $folder, OutputInterface::VERBOSITY_DEBUG); 79 } 80 } 81 } 82 83 if ($dryRun === false) { 84 foreach ($status['files_deleted'] as $file) { 85 $symfonyStyle->writeln('<comment>File Deleted = ' . $file . '</comment>', OutputInterface::VERBOSITY_VERBOSE); 86 } 87 88 foreach ($status['files_errors'] as $error) { 89 $symfonyStyle->error($error); 90 } 91 92 foreach ($status['folders_deleted'] as $folder) { 93 $symfonyStyle->writeln('<comment>Folder Deleted = ' . $folder . '</comment>', OutputInterface::VERBOSITY_VERBOSE); 94 } 95 96 foreach ($status['folders_errors'] as $error) { 97 $symfonyStyle->error($error); 98 } 99 } 100 101 $symfonyStyle->success( 102 sprintf( 103 $dryRun ? '%s Files checked and %s would be deleted' : '%s Files checked and %s deleted', 104 \count($status['files_checked']), 105 ($dryRun ? \count($status['files_exist']) : \count($status['files_deleted'])) 106 ) 107 ); 108 109 $symfonyStyle->success( 110 sprintf( 111 $dryRun ? '%s Folders checked and %s would be deleted' : '%s Folders checked and %s deleted', 112 \count($status['folders_checked']), 113 ($dryRun ? \count($status['folders_exist']) : \count($status['folders_deleted'])) 114 ) 115 ); 116 117 return Command::SUCCESS; 118 } 119 120 /** 121 * Configure the command. 122 * 123 * @return void 124 * 125 * @since 4.0.0 126 */ 127 protected function configure(): void 128 { 129 $help = "<info>%command.name%</info> removes old files which should have been deleted during a Joomla update 130 \nUsage: <info>php %command.full_name%</info>"; 131 132 $this->setDescription('Remove old system files'); 133 $this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Executes a dry run without deleting anything'); 134 $this->setHelp($help); 135 } 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |