Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Storage.php
Go to the documentation of this file.
1 <?php
8 
16 {
22  protected $_currentStorage = null;
23 
30 
36  protected $_coreFileStorageDb = null;
37 
41  protected $_storage;
42 
49 
56  public function __construct(
57  \Magento\Framework\App\Helper\Context $context,
58  \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb,
59  \Magento\MediaStorage\Model\File\Storage $storage,
60  \Magento\MediaStorage\Model\File\Storage\File $filesystemStorage
61  ) {
62  $this->_filesystemStorage = $filesystemStorage;
63  $this->_coreFileStorageDb = $coreFileStorageDb;
64  $this->_storage = $storage;
65  parent::__construct($context);
66  }
67 
73  public function getCurrentStorageCode()
74  {
75  if ($this->_currentStorage === null) {
76  $this->_currentStorage = (int)$this->scopeConfig->getValue(
77  \Magento\MediaStorage\Model\File\Storage::XML_PATH_STORAGE_MEDIA,
78  'default'
79  );
80  }
81 
83  }
84 
90  public function getStorageFileModel()
91  {
93  }
94 
101  public function isInternalStorage($storage = null)
102  {
103  $storage = $storage !== null ? (int)$storage : $this->getCurrentStorageCode();
104 
105  return in_array($storage, $this->_internalStorageList);
106  }
107 
115  public function getStorageModel($storage = null, $params = [])
116  {
117  return $this->_storage->getStorageModel($storage, $params);
118  }
119 
127  public function processStorageFile($filename)
128  {
129  if ($this->isInternalStorage()) {
130  return false;
131  }
132 
133  $dbHelper = $this->_coreFileStorageDb;
134 
135  $relativePath = $dbHelper->getMediaRelativePath($filename);
136  $file = $this->getStorageModel()->loadByFilename($relativePath);
137 
138  if (!$file->getId()) {
139  return false;
140  }
141 
142  return $this->saveFileToFileSystem($file);
143  }
144 
151  public function saveFileToFileSystem($file)
152  {
153  return $this->getStorageFileModel()->saveFile($file, true);
154  }
155 }
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDb, \Magento\MediaStorage\Model\File\Storage $storage, \Magento\MediaStorage\Model\File\Storage\File $filesystemStorage)
Definition: Storage.php:56
getStorageModel($storage=null, $params=[])
Definition: Storage.php:115
$relativePath
Definition: get.php:35
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18