Media.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Backup;
  7. /**
  8. * Class to work media folder and database backups
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Media extends Snapshot
  13. {
  14. /**
  15. * Implementation Rollback functionality for Media
  16. *
  17. * @throws \Magento\Framework\Exception\LocalizedException
  18. * @return bool
  19. */
  20. public function rollback()
  21. {
  22. $this->_prepareIgnoreList();
  23. return parent::rollback();
  24. }
  25. /**
  26. * Implementation Create Backup functionality for Media
  27. *
  28. * @throws \Magento\Framework\Exception\LocalizedException
  29. * @return bool
  30. */
  31. public function create()
  32. {
  33. $this->_prepareIgnoreList();
  34. return parent::create();
  35. }
  36. /**
  37. * Overlap getType
  38. *
  39. * @return string
  40. * @see BackupInterface::getType()
  41. */
  42. public function getType()
  43. {
  44. return 'media';
  45. }
  46. /**
  47. * Add all folders and files except media and db backup to ignore list
  48. *
  49. * @return $this
  50. */
  51. protected function _prepareIgnoreList()
  52. {
  53. $rootDir = $this->getRootDir();
  54. $map = [
  55. $rootDir => ['var', 'pub'],
  56. $rootDir . '/pub' => ['media'],
  57. $rootDir . '/var' => [$this->getDbBackupFilename()],
  58. ];
  59. foreach ($map as $path => $whiteList) {
  60. foreach (new \DirectoryIterator($path) as $item) {
  61. $filename = $item->getFilename();
  62. if (!$item->isDot() && !in_array($filename, $whiteList)) {
  63. $this->addIgnorePaths(str_replace('\\', '/', $item->getPathname()));
  64. }
  65. }
  66. }
  67. return $this;
  68. }
  69. }