Data.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ImportExport\Helper;
  7. /**
  8. * ImportExport data helper
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Data extends \Magento\Framework\App\Helper\AbstractHelper
  14. {
  15. /**#@+
  16. * XML path for config data
  17. */
  18. const XML_PATH_EXPORT_LOCAL_VALID_PATH = 'general/file/importexport_local_valid_paths';
  19. const XML_PATH_BUNCH_SIZE = 'general/file/bunch_size';
  20. /**#@-*/
  21. /**#@-*/
  22. protected $_fileSize;
  23. /**
  24. * @param \Magento\Framework\App\Helper\Context $context
  25. * @param \Magento\Framework\File\Size $fileSize
  26. */
  27. public function __construct(
  28. \Magento\Framework\App\Helper\Context $context,
  29. \Magento\Framework\File\Size $fileSize
  30. ) {
  31. $this->_fileSize = $fileSize;
  32. parent::__construct(
  33. $context
  34. );
  35. }
  36. /**
  37. * Get maximum upload size message
  38. *
  39. * @return \Magento\Framework\Phrase
  40. */
  41. public function getMaxUploadSizeMessage()
  42. {
  43. $maxImageSize = $this->_fileSize->getMaxFileSizeInMb();
  44. if ($maxImageSize) {
  45. $message = __('Make sure your file isn\'t more than %1M.', $maxImageSize);
  46. } else {
  47. $message = __('We can\'t provide the upload settings right now.');
  48. }
  49. return $message;
  50. }
  51. /**
  52. * Get valid path masks to files for importing/exporting
  53. *
  54. * @return string[]
  55. */
  56. public function getLocalValidPaths()
  57. {
  58. $paths = $this->scopeConfig->getValue(
  59. self::XML_PATH_EXPORT_LOCAL_VALID_PATH,
  60. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  61. );
  62. return $paths;
  63. }
  64. /**
  65. * Retrieve size of bunch (how many entities should be involved in one import iteration)
  66. *
  67. * @return int
  68. */
  69. public function getBunchSize()
  70. {
  71. return (int)$this->scopeConfig->getValue(
  72. self::XML_PATH_BUNCH_SIZE,
  73. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  74. );
  75. }
  76. }