Skip to content

Commit

Permalink
Fetch embed data if none returned from database
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaskill committed Mar 25, 2021
1 parent ee4ec72 commit e882dc6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Charcoal/Embed/Service/EmbedRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function processEmbed($ident, $format = null)
return [
'ident' => $ident,
'embed_data' => $this->formatEmbed($ident, $format),
'last_update_date' => (new \DateTime())->format('Y-m-d H:i:s')
'last_update_date' => (new \DateTime())->format('Y-m-d H:i:s'),
];
}

Expand Down Expand Up @@ -430,9 +430,17 @@ public function embedData($ident)
}

$item = $this->load($ident);
if ($item === false) {
$item = $this->processEmbed($ident, 'array');
$this->saveItem($item);
}

if (isset($item['embed_data'])) {
$data = json_decode($item['embed_data'], true);
if (is_string($item['embed_data'])) {
$data = json_decode($item['embed_data'], true);
} else {
$data = $item['embed_data'];
}

$this->validateTtl($item);

Expand Down

0 comments on commit e882dc6

Please sign in to comment.