I am using Magento with Docker. I added the S3 extension in Docker; it’s installed
RUN composer require magecomp/magento-2-amazon-s3-remote-storage:1.0.8
My PHP version is 8.4. After the image build I run the Magento upgrade cmd getting deprecated errors
PHP Fatal error: Declaration of MagecompS3AmazonConsoleCommandS3Export::execute(SymfonyComponentConsoleInputInputInterface $input, SymfonyComponentConsoleOutputOutputInterface $output) must be compatible with SymfonyComponentConsoleCommandCommand::execute(SymfonyComponentConsoleInputInputInterface $input, SymfonyComponentConsoleOutputOutputInterface $output): int in /var/www/html/vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php on line 71
Then I created a patch and applied it using Docker, but getting error
Patch File
diff --git a/vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php b/vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php
--- a/vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php
+++ b/vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php
@@ -71,7 +61,7 @@
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
Error
=> ERROR [79/81] RUN patch -p1 < patches/Magecomp-php84.patch 0.3s
------
> [79/81] RUN patch -p1 < patches/Magecomp-php84.patch:
#0 0.268 patch: **** unexpected end of file in patch
#0 0.268 patching file vendor/magecomp/magento-2-amazon-s3-remote-storage/Console/Command/S3Export.php
#0 0.268 patch unexpectedly ends in middle of line
------
Dockerfile:140
Full File of S3Export.php
<?php
namespace MagecompS3AmazonConsoleCommand;
use MagentoFrameworkAppArea;
use MagentoFrameworkAppState;
use MagentoMediaStorageHelperFileStorage;
use MagentoMediaStorageHelperFileStorageFactory;
use SymfonyComponentConsoleCommandCommand;
use MagentoFrameworkDBAdapterAdapterInterface;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use MagecompS3AmazonHelperData as DataHelper;
use MagentoMediaStorageHelperFileStorageDatabase;
use MagentoFrameworkFileMime;
use MagentoFrameworkFilesystem;
use MagentoFrameworkObjectManagerInterface;
use MagentoFrameworkAppFilesystemDirectoryList;
use MagentoFrameworkFilesystemDriverFile;
use AwsS3S3Client;
class S3Export extends SymfonyComponentConsoleCommandCommand
{
protected $appState;
protected $helper;
protected $coreFileStorage;
protected $destinationModel;
protected $mime;
protected $client;
protected $storageHelper;
protected $_filesystem;
protected $_mediaBaseDirectory;
protected $_objectCreate;
protected $_file;
protected $errors;
public function __construct(
State $appState,
StorageFactory $coreFileStorageFactory,
DataHelper $helper,
Mime $mime,
Database $storageHelper,
Filesystem $filesystem,
ObjectManagerInterface $_objectCreate,
File $_file
) {
$this->appState = $appState;
$this->coreFileStorage = $coreFileStorageFactory->create();
$this->helper = $helper;
$this->mime = $mime;
$this->storageHelper = $storageHelper;
$this->_filesystem = $filesystem;
$this->_objectCreate = $_objectCreate;
$this->_file = $_file;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('amazons3:export');
$this->setDescription('Sync all media to Amazon S3.');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->setDecorated(true);
$this->appState->setAreaCode(MagentoFrameworkAppArea::AREA_GLOBAL);
try {
$output->writeln("");
if(!$this->helper->isS3Enabled())
{
$output->writeln('<error>Please Enable Amazon S3 Extension.</error>');
return 1;
}
$errors = $this->validate();
if ($errors) {
$output->writeln('<error>' . implode('</error>' . PHP_EOL . '<error>', $errors) . '</error>');
return 1;
}
$options = [
'version' => 'latest',
'region' => $this->helper->getRegion(),
'credentials' => [
'key' => $this->helper->getAccessKey(),
'secret' => $this->helper->getSecretKey(),
],
];
if ($this->helper->getEndpointEnabled()) {
$options['endpoint'] = $this->helper->getEndpoint();
$options['use_path_style_endpoint'] = true;
}
try {
$client1 = new S3Client($options);
} catch (Exception $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
return 1;
}
if (!$client1->doesBucketExist($this->helper->getBucket())) {
$output->writeln('<error>The AWS Authentication Failed</error>');
return 1;
}
if ($this->coreFileStorage->getCurrentStorageCode() === MagecompS3AmazonModelCoreFileStorage::STORAGE_MEDIA_S3) {
$output->writeln($this->coreFileStorage->getCurrentStorageCode().'<error>You are already using S3 as your media file storage backend!</error>');
return 1;
}
$sourceModel = $this->coreFileStorage->getStorageModel();
$offset = 0;
$temp = false;
if($this->helper->getRemoveMediaDiretory()){
$question = $this->_objectCreate->create('SymfonyComponentConsoleQuestionConfirmationQuestion', ['question'=>'Are you sure you want to remove media?(type : yes/no) :', 'default' => FALSE]);
$helper = $this->getHelper('question');
$ans = $helper->ask($input, $output, $question);
if ($ans == 'yes') {
$temp = true;
}else{
$temp = false;
}
}
while (($files = $sourceModel->exportFiles($offset, 1)) !== false) {
foreach ($files as $file) {
$object = ltrim($file['directory'] . '/' . $file['filename'], '/');
$output->writeln(sprintf('Uploading %s to use S3.', $object));
try {
$this->client = new S3Client($this->helper->getS3Options());
$uploadresponce= $this->client->putObject($this->getAllParams([
'Body' => $file['content'],
'Bucket' => $this->helper->getBucket(),
'ContentType' => $this->mime->getMimeType($this->getMediaBaseDirectory().'/'.$object),
'Key' => $file['directory'] . '/' . $file['filename'],
]));
$responce=$uploadresponce->ToArray()['@metadata']['statusCode'];
if($responce=="200" && $this->helper->getRemoveMediaDiretory()){
if($temp==true){
$mediapath = $this->helper->getAbsolutePath()."/".$object;
if ($this->_file->isExists($mediapath)) {
$this->_file->deleteFile($mediapath);
$output->writeln(sprintf('Remove Image %s to use S3.',$mediapath));
}
}
}
} catch (Exception $e) {
$output->writeln(sprintf('Error %s S3 :',$e->getMessage()));
$this->errors[] = $e->getMessage();
}
}
$offset += count($files);
}
return 0;
/*return MagentoFrameworkConsoleCli::RETURN_SUCCESS;*/
} catch (Exception $exception) {
$output->writeln("");
$output->writeln("<error>{$exception->getMessage()}</error>");
return 1;
/*return MagentoFrameworkConsoleCli::RETURN_FAILURE;*/
}
}
public function validate()
{
$errors = [];
if ($this->helper->getAccessKey() === null) {
$errors[] = 'You have not provided an AWS access key ID.';
}
if ($this->helper->getSecretKey() === null) {
$errors[] = 'You have not provided an AWS secret access key.';
}
if ($this->helper->getBucket() === null) {
$errors[] = 'You have not provided an S3 bucket.';
}
if ($this->helper->getRegion() === null) {
$errors[] = 'You have not provided an S3 region.';
}
return $errors;
}
public function getMediaBaseDirectory()
{
if (null === $this->_mediaBaseDirectory) {
$mediaDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
$this->_mediaBaseDirectory = rtrim($mediaDir, '/');
}
return $this->_mediaBaseDirectory;
}
public function getAllParams(array $headers = [])
{
$headers['ACL'] = 'public-read';
return $headers;
}
}
``` I don't know what the issue is