Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the namespace parameter to cacheable instances #42

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ specified, released under the MIT licence as follows:

----- begin license block -----

Copyright 2011-2017 Symphony Team
Copyright 2011-2019 Symphony Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 17 additions & 8 deletions data-sources/datasource.remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,30 @@ public static function buildCacheInformation(XMLElement $wrapper, Cacheable $cac
}
}

/**
* Returns an instance of the cache for the Remote Datasource
*
* @since Remote Datasource 2.4.0
* @return Cacheable
*/
public static function getCache() {
return Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
}

/*-------------------------------------------------------------------------
Editor
-------------------------------------------------------------------------*/

public static function buildEditor(XMLElement $wrapper, array &$errors = array(), array $settings = null, $handle = null)
{
if (!is_null($handle) && isset($settings[self::getClass()])) {
$cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
$cache = self::getCache();
$cache_id = self::buildCacheID($settings[self::getClass()]);
}

// If `clear_cache` is set, clear it..
if (isset($cache_id) && in_array('clear_cache', Administration::instance()->Page->getContext())) {
$cache->delete($cache_id);
$cache->delete($cache_id, $handle);
Administration::instance()->Page->pageAlert(
__('Data source cache cleared at %s.', array(Widget::Time()->generate()))
. '<a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">'
Expand Down Expand Up @@ -762,10 +772,9 @@ public static function prepare(array $settings, array $params, $template)
'namespaces' => $namespaces,
'paramoutput' => $outputparams
));
$cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
$cache_id = self::buildCacheID($settings);
$data = self::transformResult(self::$url_result, $settings['format']);
$cache->write($cache_id, $data, $settings['cache']);
$cache_id = self::buildCacheID($settings);
self::getCache()->write($cache_id, $data, $settings['cache'], $params['rootelement']);
}

return sprintf(
Expand Down Expand Up @@ -838,8 +847,7 @@ public function execute(array &$param_pool = null)

// Check for an existing Cache for this Datasource
$cache_id = self::buildCacheID($this);
$cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
$cachedData = $cache->read($cache_id);
$cachedData = self::getCache()->read($cache_id, $this->dsParamROOTELEMENT);
$writeToCache = null;
$isCacheValid = true;
$creation = DateTimeObj::get('c');
Expand Down Expand Up @@ -964,7 +972,7 @@ public function execute(array &$param_pool = null)
$this->_force_empty_result = true;
} else {
if ($this->dsParamCACHE > 0 && $writeToCache) {
$cache->write($cache_id, $data, $this->dsParamCACHE);
self::getCache()->write($cache_id, $data, $this->dsParamCACHE, $this->dsParamROOTELEMENT);
}

if (!empty($this->dsParamOUTPUTPARAM)) {
Expand All @@ -974,6 +982,7 @@ public function execute(array &$param_pool = null)
$result->setValue(PHP_EOL . str_repeat("\t", 2) . preg_replace('/([\r\n]+)/', "$1\t", $ret));
$result->setAttribute('status', ($isCacheValid === true ? 'fresh' : 'stale'));
$result->setAttribute('cache-id', $cache_id);
$result->setAttribute('cache-namespace', $this->dsParamROOTELEMENT);
$result->setAttribute('creation', $creation);
}
}
Expand Down
5 changes: 4 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
</author>
</authors>
<releases>
<release version="2.3.1" date="2019-01-16" min="2.4" max="3.x.x">
<release version="2.4.0" date="2019-02-27" min="2.6" max="3.x.x">
- Pass namespace to the cacheable instance
</release>
<release version="2.3.1" date="2019-02-27" min="2.4" max="3.x.x">
- [#37](https://github.com/symphonycms/remote_datasource/issues/37) Fix error when multiple datasources are added to the same page with different formats.
</release>
<release version="2.3.0" date="2017-07-12" min="2.4" max="3.x.x">
Expand Down