Skip to content

Commit

Permalink
fix(core): fix issue with system fields data types in the Entries API #…
Browse files Browse the repository at this point in the history
…383

slug field should be string
routable field should be boolean
visibility field should be string one of (visible, draft, hidden)
created_at field should be int unix timestamp
published_at field should be int unix timestamp
modified_at field should be int unix timestamp
  • Loading branch information
Awilum committed Feb 26, 2020
1 parent abcc3b1 commit 218050a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions flextype/core/Entries.php
Expand Up @@ -184,23 +184,23 @@ public function fetchSingle(string $id) : array
//

// Entry Published At
$entry_decoded['published_at'] = (int) strtottime($entry_decoded['published_at']) ?? Filesystem::getTimestamp($entry_file);
$entry_decoded['published_at'] = isset($entry_decoded['published_at']) ? (int) strtotime($entry_decoded['published_at']) : (int) Filesystem::getTimestamp($entry_file);

// Entry Created At
$entry_decoded['created_at'] = (int) strtottime($entry_decoded['created_at']) ?? Filesystem::getTimestamp($entry_file);
$entry_decoded['created_at'] = isset($entry_decoded['created_at']) ? (int) strtotime($entry_decoded['created_at']) : (int) Filesystem::getTimestamp($entry_file);

// Entry Modified
$entry_decoded['modified_at'] = (int) Filesystem::getTimestamp($entry_file);

// Entry Slug
$entry_decoded['slug'] = (string) $entry_decoded['slug'] ?? ltrim(rtrim($id, '/'), '/');
$entry_decoded['slug'] = isset($entry_decoded['slug']) ? (string) $entry_decoded['slug'] : (string) ltrim(rtrim($id, '/'), '/');

// Entry Routable
$entry_decoded['routable'] = (bool) $entry_decoded['routable'] ?? true;
$entry_decoded['routable'] = isset($entry_decoded['routable']) ? (bool) $entry_decoded['routable'] : true;

// Entry Visibility
if (isset($entry_decoded['visibility']) && in_array($this->visibility[$entry_decoded['visibility']])) {
$entry_decoded['visibility'] = (string) $entry_decoded['visibility'];
if (isset($entry_decoded['visibility']) && in_array($entry_decoded['visibility'], $this->visibility)) {
$entry_decoded['visibility'] = (string) $this->visibility[$entry_decoded['visibility']];
} else {
$entry_decoded['visibility'] = (string) $this->visibility['visible'];
}
Expand Down

0 comments on commit 218050a

Please sign in to comment.