Skip to content

Commit

Permalink
Merge branch 'hotfix/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
qzminski committed Jul 27, 2018
2 parents afb193e + 28af3a1 commit ba01698
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/Codefog/Instagram/FrontendModule/InstagramModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,26 @@ private function storeMediaFiles(array $data)
foreach ($data as &$item) {
$url = $item['images']['standard_resolution']['url'];
$extension = pathinfo(explode('?', $url)[0], PATHINFO_EXTENSION);
$target = sprintf('%s/%s.%s', $folderModel->path, $item['id'], $extension);
$file = new File(sprintf('%s/%s.%s', $folderModel->path, $item['id'], $extension));

// Download the image
$ch = curl_init();
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url]);
$response = curl_exec($ch);
curl_close($ch);

// Save the image and add sync the database
if ($response !== false) {
$file = new File($target);
$file->write($response);
$file->close();

// Store the UUID in cache
if ($file->exists()) {
$item['contao']['uuid'] = StringUtil::binToUuid($file->getModel()->uuid);
if (!$file->exists()) {
$ch = curl_init();
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url]);
$response = curl_exec($ch);
curl_close($ch);

// Save the image and add sync the database
if ($response !== false) {
$file->write($response);
$file->close();
}
}

// Store the UUID in cache
if ($file->exists()) {
$item['contao']['uuid'] = StringUtil::binToUuid($file->getModel()->uuid);
}
}

return $data;
Expand Down

0 comments on commit ba01698

Please sign in to comment.