mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 13:52:56 +02:00
fix(core): issue with empty entries folder Entries API - fetchAll method #234
This commit is contained in:
@@ -172,6 +172,9 @@ class Entries
|
||||
// Init Entries
|
||||
$entries = [];
|
||||
|
||||
// Init Entries
|
||||
$this->entries = $entries;
|
||||
|
||||
// Set Expression
|
||||
$expression = $this->expression;
|
||||
|
||||
@@ -235,117 +238,118 @@ class Entries
|
||||
// Get entries list
|
||||
$entries_list = Filesystem::listContents($entries_path, $bind_recursive);
|
||||
|
||||
// Get Entries Timestamp
|
||||
$entries_timestamp = Filesystem::getDirTimestamp($entries_path);
|
||||
// If entries founded in entries folder
|
||||
if (count($entries_list) > 0) {
|
||||
|
||||
// Entries IDs
|
||||
$entries_ids = '';
|
||||
// Entries IDs
|
||||
$entries_ids = '';
|
||||
|
||||
// Create entries array from entries list and ignore current requested entry
|
||||
foreach ($entries_list as $current_entry) {
|
||||
if (strpos($current_entry['path'], $bind_id . '/entry' . '.' . 'md') !== false) {
|
||||
// ignore ...
|
||||
} else {
|
||||
// We are checking...
|
||||
// Whether the requested entry is a director and whether the file entry is in this directory.
|
||||
if ($current_entry['type'] === 'dir' && Filesystem::has($current_entry['path'] . '/entry.md')) {
|
||||
// Get entry uid
|
||||
// 1. Remove entries path
|
||||
// 2. Remove left and right slashes
|
||||
$uid = ltrim(rtrim(str_replace(PATH['entries'], '', $current_entry['path']), '/'), '/');
|
||||
// Create entries array from entries list and ignore current requested entry
|
||||
foreach ($entries_list as $current_entry) {
|
||||
if (strpos($current_entry['path'], $bind_id . '/entry' . '.' . 'md') !== false) {
|
||||
// ignore ...
|
||||
} else {
|
||||
// We are checking...
|
||||
// Whether the requested entry is a director and whether the file entry is in this directory.
|
||||
if ($current_entry['type'] === 'dir' && Filesystem::has($current_entry['path'] . '/entry.md')) {
|
||||
// Get entry uid
|
||||
// 1. Remove entries path
|
||||
// 2. Remove left and right slashes
|
||||
$uid = ltrim(rtrim(str_replace(PATH['entries'], '', $current_entry['path']), '/'), '/');
|
||||
|
||||
// For each founded entry we should create $entries array.
|
||||
$entry = $this->fetch($uid);
|
||||
// For each founded entry we should create $entries array.
|
||||
$entry = $this->fetch($uid);
|
||||
|
||||
// Add entry into the entries
|
||||
$entries[$uid] = $entry;
|
||||
// Add entry into the entries
|
||||
$entries[$uid] = $entry;
|
||||
|
||||
// Create entries IDs list
|
||||
$entries_ids .= $uid;
|
||||
// Create entries IDs list
|
||||
$entries_ids .= $uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create unique entries $cache_id
|
||||
$cache_id = md5($entries_timestamp .
|
||||
$bind_id .
|
||||
$entries_ids .
|
||||
($bind_recursive ? 'true' : 'false') .
|
||||
($bind_set_max_result ? $bind_set_max_result : 'false') .
|
||||
($bind_set_first_result ? $bind_set_first_result : 'false') .
|
||||
($bind_where['where']['key'] ? $bind_where['where']['key'] : 'false') .
|
||||
($bind_where['where']['expr'] ? $bind_where['where']['expr'] : 'false') .
|
||||
($bind_where['where']['value'] ? $bind_where['where']['value'] : 'false') .
|
||||
($bind_and_where['and_where']['key'] ? $bind_and_where['and_where']['key'] : 'false') .
|
||||
($bind_and_where['and_where']['expr'] ? $bind_and_where['and_where']['expr'] : 'false') .
|
||||
($bind_and_where['and_where']['value'] ? $bind_and_where['and_where']['value'] : 'false') .
|
||||
($bind_or_where['or_where']['key'] ? $bind_or_where['or_where']['key'] : 'false') .
|
||||
($bind_or_where['or_where']['expr'] ? $bind_or_where['or_where']['expr'] : 'false') .
|
||||
($bind_or_where['or_where']['value'] ? $bind_or_where['or_where']['value'] : 'false') .
|
||||
($bind_order_by['order_by']['field'] ? $bind_order_by['order_by']['field'] : 'false') .
|
||||
($bind_order_by['order_by']['direction'] ? $bind_order_by['order_by']['direction'] : 'false'));
|
||||
|
||||
// If requested entries exist with a specific cache_id,
|
||||
// then we take them from the cache otherwise we look for them.
|
||||
if ($this->flextype['cache']->contains($cache_id)) {
|
||||
$entries = $this->flextype['cache']->fetch($cache_id);
|
||||
} else {
|
||||
|
||||
// Create Array Collection from entries array
|
||||
$collection = new ArrayCollection($entries);
|
||||
|
||||
// Create Criteria for filtering Selectable collections.
|
||||
$criteria = new Criteria();
|
||||
|
||||
// Exec: where
|
||||
if (isset($bind_where['where']['key']) && isset($bind_where['where']['expr']) && isset($bind_where['where']['value'])) {
|
||||
$expr = new Comparison($bind_where['where']['key'], $bind_where['where']['expr'], $bind_where['where']['value']);
|
||||
$criteria->where($expr);
|
||||
}
|
||||
|
||||
// Exec: and where
|
||||
if (isset($bind_and_where['and_where']['key']) && isset($bind_and_where['and_where']['expr']) && isset($bind_and_where['and_where']['value'])) {
|
||||
$expr = new Comparison($bind_and_where['and_where']['key'], $bind_and_where['and_where']['expr'], $bind_and_where['and_where']['value']);
|
||||
$criteria->andWhere($expr);
|
||||
}
|
||||
|
||||
// Exec: or where
|
||||
if (isset($bind_or_where['or_where']['key']) && isset($bind_or_where['or_where']['expr']) && isset($bind_or_where['or_where']['value'])) {
|
||||
$expr = new Comparison($bind_or_where['or_where']['key'], $bind_or_where['or_where']['expr'], $bind_or_where['or_where']['value']);
|
||||
$criteria->orWhere($expr);
|
||||
}
|
||||
|
||||
// Exec: order by
|
||||
if (isset($bind_order_by['order_by']['field']) && isset($bind_order_by['order_by']['direction'])) {
|
||||
$criteria->orderBy([$bind_order_by['order_by']['field'] => $direction[$bind_order_by['order_by']['direction']]]);
|
||||
}
|
||||
|
||||
// Exec: set max result
|
||||
if ($bind_set_max_result) {
|
||||
$criteria->setMaxResults($bind_set_max_result);
|
||||
}
|
||||
|
||||
// Exec: set first result
|
||||
if ($bind_set_first_result) {
|
||||
$criteria->setFirstResult($bind_set_first_result);
|
||||
}
|
||||
|
||||
// Get entries for matching criterias
|
||||
$entries = $collection->matching($criteria);
|
||||
|
||||
// Gets a native PHP array representation of the collection.
|
||||
$entries = $entries->toArray();
|
||||
|
||||
// Save entries into the cache
|
||||
$this->flextype['cache']->save($cache_id, $entries);
|
||||
}
|
||||
|
||||
// Set entries into the property entries
|
||||
$this->entries = $entries;
|
||||
|
||||
// Run event onEntriesAfterInitialized
|
||||
$this->flextype['emitter']->emit('onEntriesAfterInitialized');
|
||||
}
|
||||
|
||||
// Create unique entries $cache_id
|
||||
$cache_id = md5($entries_timestamp .
|
||||
$bind_id .
|
||||
$entries_ids .
|
||||
($bind_recursive ? 'true' : 'false') .
|
||||
($bind_set_max_result ? $bind_set_max_result : 'false') .
|
||||
($bind_set_first_result ? $bind_set_first_result : 'false') .
|
||||
($bind_where['where']['key'] ? $bind_where['where']['key'] : 'false') .
|
||||
($bind_where['where']['expr'] ? $bind_where['where']['expr'] : 'false') .
|
||||
($bind_where['where']['value'] ? $bind_where['where']['value'] : 'false') .
|
||||
($bind_and_where['and_where']['key'] ? $bind_and_where['and_where']['key'] : 'false') .
|
||||
($bind_and_where['and_where']['expr'] ? $bind_and_where['and_where']['expr'] : 'false') .
|
||||
($bind_and_where['and_where']['value'] ? $bind_and_where['and_where']['value'] : 'false') .
|
||||
($bind_or_where['or_where']['key'] ? $bind_or_where['or_where']['key'] : 'false') .
|
||||
($bind_or_where['or_where']['expr'] ? $bind_or_where['or_where']['expr'] : 'false') .
|
||||
($bind_or_where['or_where']['value'] ? $bind_or_where['or_where']['value'] : 'false') .
|
||||
($bind_order_by['order_by']['field'] ? $bind_order_by['order_by']['field'] : 'false') .
|
||||
($bind_order_by['order_by']['direction'] ? $bind_order_by['order_by']['direction'] : 'false'));
|
||||
|
||||
// If requested entries exist with a specific cache_id,
|
||||
// then we take them from the cache otherwise we look for them.
|
||||
if ($this->flextype['cache']->contains($cache_id)) {
|
||||
$entries = $this->flextype['cache']->fetch($cache_id);
|
||||
} else {
|
||||
|
||||
// Create Array Collection from entries array
|
||||
$collection = new ArrayCollection($entries);
|
||||
|
||||
// Create Criteria for filtering Selectable collections.
|
||||
$criteria = new Criteria();
|
||||
|
||||
// Exec: where
|
||||
if (isset($bind_where['where']['key']) && isset($bind_where['where']['expr']) && isset($bind_where['where']['value'])) {
|
||||
$expr = new Comparison($bind_where['where']['key'], $bind_where['where']['expr'], $bind_where['where']['value']);
|
||||
$criteria->where($expr);
|
||||
}
|
||||
|
||||
// Exec: and where
|
||||
if (isset($bind_and_where['and_where']['key']) && isset($bind_and_where['and_where']['expr']) && isset($bind_and_where['and_where']['value'])) {
|
||||
$expr = new Comparison($bind_and_where['and_where']['key'], $bind_and_where['and_where']['expr'], $bind_and_where['and_where']['value']);
|
||||
$criteria->andWhere($expr);
|
||||
}
|
||||
|
||||
// Exec: or where
|
||||
if (isset($bind_or_where['or_where']['key']) && isset($bind_or_where['or_where']['expr']) && isset($bind_or_where['or_where']['value'])) {
|
||||
$expr = new Comparison($bind_or_where['or_where']['key'], $bind_or_where['or_where']['expr'], $bind_or_where['or_where']['value']);
|
||||
$criteria->orWhere($expr);
|
||||
}
|
||||
|
||||
// Exec: order by
|
||||
if (isset($bind_order_by['order_by']['field']) && isset($bind_order_by['order_by']['direction'])) {
|
||||
$criteria->orderBy([$bind_order_by['order_by']['field'] => $direction[$bind_order_by['order_by']['direction']]]);
|
||||
}
|
||||
|
||||
// Exec: set max result
|
||||
if ($bind_set_max_result) {
|
||||
$criteria->setMaxResults($bind_set_max_result);
|
||||
}
|
||||
|
||||
// Exec: set first result
|
||||
if ($bind_set_first_result) {
|
||||
$criteria->setFirstResult($bind_set_first_result);
|
||||
}
|
||||
|
||||
// Get entries for matching criterias
|
||||
$entries = $collection->matching($criteria);
|
||||
|
||||
// Gets a native PHP array representation of the collection.
|
||||
$entries = $entries->toArray();
|
||||
|
||||
// Save entries into the cache
|
||||
$this->flextype['cache']->save($cache_id, $entries);
|
||||
}
|
||||
|
||||
// Set entries into the property entries
|
||||
$this->entries = $entries;
|
||||
|
||||
// Run event onEntriesAfterInitialized
|
||||
$this->flextype['emitter']->emit('onEntriesAfterInitialized');
|
||||
|
||||
// Return entries
|
||||
return $this->entries;
|
||||
}
|
||||
|
Reference in New Issue
Block a user