Skip to content

Commit

Permalink
Merge pull request #8 from dauskonzept/7-bug-refactor-file_get_conten…
Browse files Browse the repository at this point in the history
…ts-to-use-requestfactory

[BUG] Refactored file_get_contents to use RequestFactory
  • Loading branch information
svenpet90 authored Jan 27, 2023
2 parents b4de732 + bb5e234 commit 16dc0cc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Classes/Command/ImportTweetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -75,20 +76,24 @@ class ImportTweetsCommand extends Command
*/
private array $categories = [];

private RequestFactory $requestFactory;

public function __construct(
NewsTweetRepository $newsRepository,
CategoryRepository $categoryRepository,
PersistenceManagerInterface $persistenceManager,
EventDispatcherInterface $eventDispatcher,
SlugService $slugService,
LoggerInterface $logger
LoggerInterface $logger,
RequestFactory $requestFactory
) {
$this->newsRepository = $newsRepository;
$this->categoryRepository = $categoryRepository;
$this->persistenceManager = $persistenceManager;
$this->eventDispatcher = $eventDispatcher;
$this->slugService = $slugService;
$this->logger = $logger;
$this->requestFactory = $requestFactory;

/** @var ExtensionConfiguration $extensionConfiguration */
$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
Expand Down Expand Up @@ -294,8 +299,9 @@ private function downloadFile(string $fileUrl, string $fileExtension): File
$directory = str_replace('1:', 'uploads', $directory);
$filePath = sprintf('%s/%s.%s', $directory, md5($fileUrl), $fileExtension);

$data = file_get_contents($fileUrl);
file_put_contents($filePath, $data);
$response = $this->requestFactory->request($fileUrl);
$imageData = $response->getBody()->getContents();
file_put_contents($filePath, $imageData);

/** @var ResourceFactory $resourceFactory */
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
Expand Down

0 comments on commit 16dc0cc

Please sign in to comment.