File tree Expand file tree Collapse file tree 10 files changed +26
-38
lines changed
app/code/Magento/AwsS3/Driver
dev/tests/integration/testsuite/Magento/Catalog
lib/internal/Magento/Framework/Api Expand file tree Collapse file tree 10 files changed +26
-38
lines changed Original file line number Diff line number Diff line change @@ -344,7 +344,11 @@ public function isFile($path): bool
344344 $ path = $ this ->normalizeRelativePath ($ path );
345345 $ path = rtrim ($ path , '/ ' );
346346
347- return $ this ->adapter ->has ($ path ) && $ this ->adapter ->getMetadata ($ path )['type ' ] === self ::TYPE_FILE ;
347+ if ($ this ->adapter ->has ($ path ) && ($ meta = $ this ->adapter ->getMetadata ($ path ))) {
348+ return ($ meta ['type ' ] ?? null ) === self ::TYPE_FILE ;
349+ }
350+
351+ return false ;
348352 }
349353
350354 /**
Original file line number Diff line number Diff line change @@ -46,9 +46,10 @@ public static function setUpBeforeClass(): void
4646 $ mediaDirectory ->create ($ config ->getBaseTmpMediaPath ());
4747 $ mediaDirectory ->create ($ config ->getBaseMediaPath ());
4848
49- copy ($ fixtureDir . "/magento_image.jpg " , self ::$ _mediaTmpDir . "/magento_image.jpg " );
50- copy ($ fixtureDir . "/magento_image.jpg " , self ::$ _mediaDir . "/magento_image.jpg " );
51- copy ($ fixtureDir . "/magento_small_image.jpg " , self ::$ _mediaTmpDir . "/magento_small_image.jpg " );
49+ $ mediaDirectory ->getDriver ()->filePutContents (self ::$ _mediaTmpDir . "/magento_image.jpg " , file_get_contents ($ fixtureDir . "/magento_image.jpg " ));
50+ $ mediaDirectory ->getDriver ()->filePutContents (self ::$ _mediaDir . "/magento_image.jpg " , file_get_contents ($ fixtureDir . "/magento_image.jpg " ));
51+ $ mediaDirectory ->getDriver ()->filePutContents (self ::$ _mediaTmpDir . "/magento_small_image.jpg " , file_get_contents ($ fixtureDir . "/magento_small_image.jpg " ));
52+
5253 }
5354
5455 public static function tearDownAfterClass (): void
Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ protected function _copyFileToBaseTmpMediaPath($sourceFile)
246246
247247 $ mediaDirectory ->create ($ config ->getBaseTmpMediaPath ());
248248 $ targetFile = $ config ->getTmpMediaPath (basename ($ sourceFile ));
249- copy ( $ sourceFile , $ mediaDirectory ->getAbsolutePath ($ targetFile ));
249+ $ mediaDirectory -> getDriver ()-> filePutContents ( $ mediaDirectory ->getAbsolutePath ($ targetFile), file_get_contents ( $ sourceFile ));
250250
251251 return $ targetFile ;
252252 }
Original file line number Diff line number Diff line change 1010$ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
1111
1212/** @var $mediaDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
13- $ mediaDirectory = $ objectManager ->get (\Magento \Framework \Filesystem::class)
14- ->getDirectoryWrite (DirectoryList::MEDIA );
13+ $ mediaDirectory = $ objectManager ->get (\Magento \Framework \Filesystem::class)->getDirectoryWrite (DirectoryList::MEDIA );
1514$ fileName = 'magento_small_image.jpg ' ;
1615$ fileNameLong = 'magento_long_image_name_magento_long_image_name_magento_long_image_name.jpg ' ;
1716$ filePath = 'catalog/category/ ' . $ fileName ;
1817$ filePathLong = 'catalog/category/ ' . $ fileNameLong ;
1918$ mediaDirectory ->create ('catalog/category ' );
20-
21- copy (__DIR__ . DIRECTORY_SEPARATOR . $ fileName , $ mediaDirectory ->getAbsolutePath ($ filePath ));
22- copy (__DIR__ . DIRECTORY_SEPARATOR . $ fileNameLong , $ mediaDirectory ->getAbsolutePath ($ filePathLong ));
19+ $ shortImageContent = file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . $ fileName );
20+ $ longImageContent = file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . $ fileNameLong );
21+ $ mediaDirectory ->getDriver ()->filePutContents ($ mediaDirectory ->getAbsolutePath ($ filePath ), $ shortImageContent );
22+ $ mediaDirectory ->getDriver ()->filePutContents ($ mediaDirectory ->getAbsolutePath ($ filePathLong ), $ longImageContent );
23+ unset($ shortImageContent , $ longImageContent );
Original file line number Diff line number Diff line change 1515$ fileName = 'magento_small_image.jpg ' ;
1616$ tmpFilePath = 'catalog/tmp/category/ ' . $ fileName ;
1717$ mediaDirectory ->create ('catalog/tmp/category ' );
18-
19- copy (__DIR__ . DIRECTORY_SEPARATOR . $ fileName , $ mediaDirectory ->getAbsolutePath ($ tmpFilePath ));
18+ $ mediaDirectory ->getDriver ()->filePutContents ($ mediaDirectory ->getAbsolutePath ($ tmpFilePath ), file_get_contents (__DIR__ . DIRECTORY_SEPARATOR . $ fileName ));
Original file line number Diff line number Diff line change 2424$ images = ['magento_image.jpg ' , 'magento_small_image.jpg ' , 'magento_thumbnail.jpg ' ];
2525
2626foreach ($ images as $ image ) {
27- $ targetTmpFilePath = $ mediaDirectory ->getAbsolutePath () . DIRECTORY_SEPARATOR . $ targetTmpDirPath
28- . DIRECTORY_SEPARATOR . $ image ;
27+ $ targetTmpFilePath = $ mediaDirectory ->getAbsolutePath () . $ targetTmpDirPath . $ image ;
2928
3029 $ sourceFilePath = __DIR__ . DIRECTORY_SEPARATOR . $ image ;
30+ $ mediaDirectory ->getDriver ()->filePutContents ($ targetTmpFilePath , file_get_contents ($ sourceFilePath ));
3131
32- copy ($ sourceFilePath , $ targetTmpFilePath );
3332 // Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
3433 $ database ->saveFile ($ targetTmpFilePath );
3534}
Original file line number Diff line number Diff line change 3838$ mediaDirectory ->create ($ targetTmpDirPath );
3939
4040$ dist = $ mediaDirectory ->getAbsolutePath ($ mediaConfig ->getBaseMediaPath () . DIRECTORY_SEPARATOR . 'magento_image.jpg ' );
41- copy ( __DIR__ . '/magento_image.jpg ' , $ dist );
41+ $ mediaDirectory -> getDriver ()-> filePutContents ( $ dist , file_get_contents ( __DIR__ . '/magento_image.jpg ' ) );
4242
4343/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
4444$ productRepository = $ objectManager ->create (\Magento \Catalog \Api \ProductRepositoryInterface::class);
Original file line number Diff line number Diff line change 1212/** @var Magento\Catalog\Model\Product\Media\Config $config */
1313$ config = $ objectManager ->get (\Magento \Catalog \Model \Product \Media \Config::class);
1414
15- /** @var $tmpDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
16- $ tmpDirectory = $ filesystem ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
17- $ tmpDirectory ->create ($ config ->getBaseTmpMediaPath ());
15+ /** @var $mediaDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
16+ $ mediaDirectory = $ filesystem ->getDirectoryWrite (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
17+ $ mediaDirectory ->create ($ config ->getBaseTmpMediaPath ());
1818
19- $ targetTmpFilePath = $ tmpDirectory ->getAbsolutePath ($ config ->getBaseTmpMediaPath () . '/magento_small_image.jpg ' );
20- copy ( __DIR__ . '/magento_small_image.jpg ' , $ targetTmpFilePath );
19+ $ targetTmpFilePath = $ mediaDirectory ->getAbsolutePath ($ config ->getBaseTmpMediaPath () . '/magento_small_image.jpg ' );
20+ $ mediaDirectory -> getDriver ()-> filePutContents ( $ targetTmpFilePath , file_get_contents ( __DIR__ . '/magento_small_image.jpg ' ) );
2121// Copying the image to target dir is not necessary because during product save, it will be moved there from tmp dir
Original file line number Diff line number Diff line change 2424
2525$ baseTmpMediaPath = $ config ->getBaseTmpMediaPath ();
2626$ mediaDirectory ->create ($ baseTmpMediaPath );
27- copy ( __DIR__ . '/product_image.png ' , $ mediaDirectory -> getAbsolutePath ( $ baseTmpMediaPath . '/product_image.png ' ));
27+ $ mediaDirectory -> getDriver ()-> filePutContents ( $ mediaDirectory -> getAbsolutePath ( $ baseTmpMediaPath . '/product_image.png ' ), file_get_contents ( __DIR__ . '/product_image.png ' ));
2828
2929/** @var $productOne \Magento\Catalog\Model\Product */
3030$ productOne = $ objectManager ->create (\Magento \Catalog \Model \Product::class);
Original file line number Diff line number Diff line change @@ -39,20 +39,4 @@ public function processFileAttributes($fileAttributes)
3939 $ this ->_fileExists = true ;
4040 }
4141 }
42-
43- /**
44- * Move files from TMP folder into destination folder
45- *
46- * @param string $tmpPath
47- * @param string $destPath
48- * @return bool|void
49- */
50- protected function _moveFile ($ tmpPath , $ destPath )
51- {
52- if (is_uploaded_file ($ tmpPath )) {
53- return move_uploaded_file ($ tmpPath , $ destPath );
54- } elseif (is_file ($ tmpPath )) {
55- return rename ($ tmpPath , $ destPath );
56- }
57- }
5842}
You can’t perform that action at this time.
0 commit comments