Logo.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Backend model for uploading transactional emails custom logo image
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Config\Model\Config\Backend\Email;
  12. /**
  13. * @deprecated 100.1.5
  14. */
  15. class Logo extends \Magento\Config\Model\Config\Backend\Image
  16. {
  17. /**
  18. * The tail part of directory path for uploading
  19. */
  20. const UPLOAD_DIR = 'email/logo';
  21. /**
  22. * Upload max file size in kilobytes
  23. *
  24. * @var int
  25. */
  26. protected $_maxFileSize = 2048;
  27. /**
  28. * Return path to directory for upload file
  29. *
  30. * @return string
  31. */
  32. protected function _getUploadDir()
  33. {
  34. return $this->_mediaDirectory->getAbsolutePath($this->_appendScopeInfo(self::UPLOAD_DIR));
  35. }
  36. /**
  37. * Makes a decision about whether to add info about the scope
  38. *
  39. * @return boolean
  40. */
  41. protected function _addWhetherScopeInfo()
  42. {
  43. return true;
  44. }
  45. /**
  46. * @return string|null
  47. */
  48. protected function getTmpFileName()
  49. {
  50. $tmpName = null;
  51. if (isset($_FILES['groups'])) {
  52. $tmpName = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value'];
  53. } else {
  54. $tmpName = is_array($this->getValue()) ? $this->getValue()['tmp_name'] : null;
  55. }
  56. return $tmpName;
  57. }
  58. /**
  59. * Save uploaded file before saving config value
  60. *
  61. * Save changes and delete file if "delete" option passed
  62. *
  63. * @return $this
  64. */
  65. public function beforeSave()
  66. {
  67. $value = $this->getValue();
  68. $deleteFlag = is_array($value) && !empty($value['delete']);
  69. $fileTmpName = $this->getTmpFileName();
  70. if ($this->getOldValue() && ($fileTmpName || $deleteFlag)) {
  71. $this->_mediaDirectory->delete(self::UPLOAD_DIR . '/' . $this->getOldValue());
  72. }
  73. return parent::beforeSave();
  74. }
  75. }