JobRemoveBackups.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Copyright © 2013-2017 Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Update\Queue;
  7. /**
  8. * Magento updater application 'remove_backups' job.
  9. */
  10. class JobRemoveBackups extends AbstractJob
  11. {
  12. const BACKUPS_FILE_NAMES = 'backups_file_names';
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function execute()
  17. {
  18. $filesToDelete = [];
  19. if (isset($this->params[self::BACKUPS_FILE_NAMES])) {
  20. $filesToDelete = $this->params[self::BACKUPS_FILE_NAMES];
  21. }
  22. if ($this->maintenanceMode->isOn() || $this->status->isUpdateError()) {
  23. throw new \RuntimeException("Cannot remove backup archives while setup is in progress.");
  24. }
  25. foreach ($filesToDelete as $archivePath) {
  26. if (file_exists($archivePath) && unlink($archivePath)) {
  27. $this->status->add(sprintf('"%s" was deleted successfully.', $archivePath), \Psr\Log\LogLevel::INFO);
  28. } else {
  29. throw new \RuntimeException(sprintf('Could not delete backup archive "%s"', $archivePath));
  30. }
  31. }
  32. }
  33. }