Skip to content

Commit

Permalink
Upload theme logos to S3
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiphan committed Feb 17, 2019
1 parent d59a902 commit f149c43
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Model/Theme/Design/Backend/Logo/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
namespace Thai\S3\Model\Theme\Design\Backend\Logo;

use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\Theme\Model\Design\Backend\Logo;
use Thai\S3\Helper\Data;

/**
* Plugin for Logo.
*
* @see Logo
*/
class Plugin
{
/**
* @var Data
*/
private $helper;

/**
* @var Database
*/
private $database;

/**
* @param Data $helper
* @param Database $database
*/
public function __construct(
Data $helper,
Database $database
)
{
$this->helper = $helper;
$this->database = $database;
}

/**
* @param Logo $subject
* @param Logo $result
* @return Logo
*/
public function afterBeforeSave(Logo $subject, Logo $result)
{
if ($this->helper->checkS3Usage()) {
$imgFile = $subject::UPLOAD_DIR . '/' . $subject->getValue();
$relativeImgFile = $this->database->getMediaRelativePath($imgFile);
$this->database->getStorageDatabaseModel()->saveFile($relativeImgFile);
}

return $result;
}
}
3 changes: 3 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Theme\Model\Design\Backend\Logo">
<plugin name="thai_s3_model_theme_design_backend_logo_plugin" type="Thai\S3\Model\Theme\Design\Backend\Logo\Plugin" />
</type>
</config>

0 comments on commit f149c43

Please sign in to comment.