![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/Catalog/Setup/Patch/Data/ |
<?php /** * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * Cnc * Radosław Stępień <[email protected]> <[email protected]> */ namespace Cnc\Catalog\Setup\Patch\Data; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Setup\Patch\DataPatchInterface; class UpdateProductPlaceholdersImages implements DataPatchInterface { const PLACEHOLDER_FILE_PATH = 'app/design/frontend/Cnc/default/web/images/placeholder'; const PLACEHOLDER_DESTINATION_PATH = 'pub/media/catalog/product/placeholder/default'; const PLACEHOLDER_FILE_NAME = 'image.jpg'; const IMAGES_PLACEHOLDERS_CONFIG_PATHS = [ 'catalog/placeholder/thumbnail_placeholder', 'catalog/placeholder/swatch_image_placeholder', 'catalog/placeholder/small_image_placeholder', 'catalog/placeholder/image_placeholder' ]; /** * @var File */ private $file; /** * @var WriterInterface */ private $writer; /** * UpdateProductPlaceholdersImages constructor. * @param File $file * @param WriterInterface $writer */ public function __construct( File $file, WriterInterface $writer ) { $this->file = $file; $this->writer = $writer; } /** * Get array of patches that have to be executed prior to this. * * Example of implementation: * * [ * \Vendor_Name\Module_Name\Setup\Patch\Patch1::class, * \Vendor_Name\Module_Name\Setup\Patch\Patch2::class * ] * * @return string[] */ public static function getDependencies() { return []; } /** * Get aliases (previous names) for the patch. * * @return string[] */ public function getAliases() { return []; } /** * Run code inside patch * If code fails, patch must be reverted, in case when we are speaking about schema - then under revert * means run PatchInterface::revert() * * If we speak about data, under revert means: $transaction->rollback() * * @return void * @throws FileSystemException */ public function apply() { $realPath = self::PLACEHOLDER_FILE_PATH . DIRECTORY_SEPARATOR . self::PLACEHOLDER_FILE_NAME; $newPath = self::PLACEHOLDER_DESTINATION_PATH . DIRECTORY_SEPARATOR . self::PLACEHOLDER_FILE_NAME; if (!$this->file->isDirectory(self::PLACEHOLDER_DESTINATION_PATH)) { $this->file->createDirectory(self::PLACEHOLDER_DESTINATION_PATH); } $this->file->copy($realPath, $newPath); foreach (self::IMAGES_PLACEHOLDERS_CONFIG_PATHS as $configPath) { $this->writer->save( $configPath, 'default' . DIRECTORY_SEPARATOR . self::PLACEHOLDER_FILE_NAME, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0 ); } } }