Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Sep 21, 2019
2 parents 6bc9fa9 + 25a94f8 commit 0faec07
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 174 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
<a name="0.9.5"></a>
# [0.9.5](https://github.com/flextype/flextype/compare/v0.9.4...v0.9.5) (2019-09-21)
### Bug Fixes

* **core:** issue with cache in the Entries API - fetchAll method #234 2779777
* **core:** issue with emitter twig function #234 426a073
* **core:** issue with empty entries folder Entries API - fetchAll method #234 cf61f2d
* **core:** issue with Cache ID for Themes list #234 594f4a3
* **admin-plugin:** issue with active button styles on Themes Manager page #234 434f336
* **admin-plugin:** issue with emitter twig function #234 806b18e
* **admin-plugin:** Russian translations #233
* **site-plugin:** notice for undefined $query['format'] #234 8bde8eb

### Code Refactoring
* **core:** remove $response from Forms render method #234
* **core:** add property forms to Flextype\EntriesController #234

### BREAKING CHANGES
Changed emitter execution in the templates

FROM
```
{{ emitter.emit('EVENT_NAME') }}
```

TO
```
{% do emitter.emit('EVENT_NAME') %}
```

<a name="0.9.4"></a>
# [0.9.4](https://github.com/flextype/flextype/compare/v0.9.3...v0.9.4) (2019-09-11)
### Added
Expand Down
2 changes: 1 addition & 1 deletion flextype/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @var string
*/
define('FLEXTYPE_VERSION', '0.9.4');
define('FLEXTYPE_VERSION', '0.9.5');

/**
* Start the session
Expand Down
155 changes: 86 additions & 69 deletions flextype/core/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public function fetchAll(string $id, array $args = []) : array
// Init Entries
$entries = [];

// Init Entries
$this->entries = $entries;

// Set Expression
$expression = $this->expression;

Expand Down Expand Up @@ -235,34 +238,16 @@ public function fetchAll(string $id, array $args = []) : array
// Get entries list
$entries_list = Filesystem::listContents($entries_path, $bind_recursive);

// Get Entries Timestamp
$entries_timestamp = Filesystem::getDirTimestamp($entries_path);

// Create unique entries $cache_id
$cache_id = md5($entries_timestamp .
$bind_id .
($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 {
// If entries founded in entries folder
if (count($entries_list) > 0) {

// Entries IDs
$entries_ids = '';

// Entries IDs timestamps
$entries_ids_timestamps = '';

// Create entries array from entries list and ignore current requested entry
//echo count($entries_list);
foreach ($entries_list as $current_entry) {
if (strpos($current_entry['path'], $bind_id . '/entry' . '.' . 'md') !== false) {
// ignore ...
Expand All @@ -280,64 +265,96 @@ public function fetchAll(string $id, array $args = []) : array

// Add entry into the entries
$entries[$uid] = $entry;

// Create entries IDs list
$entries_ids .= $uid;

// Create entries IDs timestamps
$entries_ids_timestamps .= Filesystem::getTimestamp($current_entry['path'] . '/entry.md');
}
}
}

// Create Array Collection from entries array
$collection = new ArrayCollection($entries);
// Create unique entries $cache_id
$cache_id = md5($bind_id .
$entries_ids .
$entries_ids_timestamps .
($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 Criteria for filtering Selectable collections.
$criteria = new Criteria();
// Create Array Collection from entries array
$collection = new ArrayCollection($entries);

// 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);
}
// Create Criteria for filtering Selectable collections.
$criteria = new Criteria();

// 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: 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: 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: 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: 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: 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: set max result
if ($bind_set_max_result) {
$criteria->setMaxResults($bind_set_max_result);
}
// 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 first result
if ($bind_set_first_result) {
$criteria->setFirstResult($bind_set_first_result);
}
// Exec: set max result
if ($bind_set_max_result) {
$criteria->setMaxResults($bind_set_max_result);
}

// Get entries for matching criterias
$entries = $collection->matching($criteria);
// Exec: set first result
if ($bind_set_first_result) {
$criteria->setFirstResult($bind_set_first_result);
}

// Gets a native PHP array representation of the collection.
$entries = $entries->toArray();
// Get entries for matching criterias
$entries = $collection->matching($criteria);

// Save entries into the cache
$this->flextype['cache']->save($cache_id, $entries);
}
// Gets a native PHP array representation of the collection.
$entries = $entries->toArray();

// Set entries into the property entries
$this->entries = $entries;
// 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');
// Run event onEntriesAfterInitialized
$this->flextype['emitter']->emit('onEntriesAfterInitialized');
}

// Return entries
return $this->entries;
Expand Down
3 changes: 1 addition & 2 deletions flextype/core/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ public function __construct($flextype)
* @param array $fieldset Fieldset
* @param array $values Fieldset values
* @param Request $request PSR7 request
* @param Response $response PSR7 response
*
* @return string Returns form based on fieldsets
*
* @access public
*/
public function render(array $fieldset, array $values = [], Request $request, Response $response) : string
public function render(array $fieldset, array $values = [], Request $request) : string
{
$form = Form::open(null, ['id' => 'form']);
$form .= $this->_csrfHiddenField();
Expand Down
4 changes: 2 additions & 2 deletions flextype/core/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ private function getThemesCacheID(array $themes_list) : string
if (is_array($themes_list) && count($themes_list) > 0) {
foreach ($themes_list as $theme) {
if (! Filesystem::has($_themes_settings = PATH['themes'] . '/' . $theme['dirname'] . '/settings.yaml') or
! Filesystem::has($_themes_manifest = PATH['themes'] . '/' . $theme['dirname'] . '/plugin.yaml')) {
! Filesystem::has($_themes_manifest = PATH['themes'] . '/' . $theme['dirname'] . '/theme.yaml')) {
continue;
}

$_themes_cache_id .= filemtime($_themes_settings) . filemtime($_themes_manifest);
$_themes_cache_id .= $_themes_settings . filemtime($_themes_settings) . $_themes_manifest . filemtime($_themes_manifest);
}
}

Expand Down
4 changes: 2 additions & 2 deletions flextype/twig/EmitterTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct($flextype)
public function getGlobals()
{
return [
'emmiter' => new EmitterTwig($this->flextype),
'emitter' => new EmitterTwig($this->flextype),
];
}
}
Expand All @@ -56,7 +56,7 @@ public function __construct($flextype)
/**
* Emitting event
*/
public function emmit($event)
public function emit($event)
{
return $this->flextype['emitter']->emit($event);
}
Expand Down
3 changes: 2 additions & 1 deletion site/plugins/admin/app/Controllers/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @property Csrf $csrf
* @property Themes $themes
* @property Slugify $slugify
* @property Forms $forms
*/
class EntriesController extends Controller
{
Expand Down Expand Up @@ -697,7 +698,7 @@ public function edit(Request $request, Response $response) : Response
'parts' => $parts,
'i' => count($parts),
'last' => Arr::last($parts),
'form' => $this->forms->render($fieldsets, $entry, $request, $response),
'form' => $this->forms->render($fieldsets, $entry, $request),
'menu_item' => 'entries',
'links' => [
'entries' => [
Expand Down

0 comments on commit 0faec07

Please sign in to comment.