![]() 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/dev/tests/integration/testsuite/Magento/Catalog/_files/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); use Magento\Framework\App\Filesystem\DirectoryList; $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $mediaConfig \Magento\Catalog\Model\Product\Media\Config */ $mediaConfig = $objectManager->get(\Magento\Catalog\Model\Product\Media\Config::class); /** @var $database \Magento\MediaStorage\Helper\File\Storage\Database */ $database = $objectManager->get(\Magento\MediaStorage\Helper\File\Storage\Database::class); /** @var $mediaDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */ $mediaDirectory = $objectManager->get(\Magento\Framework\Filesystem::class) ->getDirectoryWrite(DirectoryList::MEDIA); $targetDirPath = $mediaConfig->getBaseMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/m/a/'); $targetTmpDirPath = $mediaConfig->getBaseTmpMediaPath() . str_replace('/', DIRECTORY_SEPARATOR, '/m/a/'); $mediaDirectory->create($targetDirPath); $mediaDirectory->create($targetTmpDirPath); $images = ['magento_image.jpg', 'magento_small_image.jpg', 'magento_thumbnail.jpg']; foreach ($images as $image) { $targetTmpFilePath = $mediaDirectory->getAbsolutePath() . $targetTmpDirPath . $image; $sourceFilePath = __DIR__ . DIRECTORY_SEPARATOR . $image; $mediaDirectory->getDriver()->filePutContents($targetTmpFilePath, file_get_contents($sourceFilePath)); // Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir $database->saveFile($targetTmpFilePath); }