Skip to content

Commit

Permalink
Pass the namespace parameter to cacheable instances
Browse files Browse the repository at this point in the history
  • Loading branch information
brendo committed Jan 17, 2019
1 parent b8907d7 commit 4e4f645
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 68 deletions.
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
24 changes: 16 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 Down
121 changes: 62 additions & 59 deletions extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,62 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="remote_datasource" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Remote Datasource</name>
<description>A datasource that consumes XML, JSON, CSV or TEXT content.</description>
<repo type="github">https://github.com/symphonycms/remote_datasource</repo>
<url type="issues">https://github.com/symphonycms/remote_datasource/issues</url>
<url type="discuss">https://www.getsymphony.com/discuss/thread/110527/</url>
<authors>
<author>
<name github="symphonycms" symphony="team">Symphony Team</name>
</author>
</authors>
<releases>
<release version="2.3.0" date="2017-07-12" min="2.4" max="3.x.x">
- Bug fixes
- Added compatibility with Symphony 2.7.x and 3.x.x
</release>
<release version="2.2.1" date="2015-12-01" min="2.4" max="2.6.x">
- Fix for php 5.3 compat
</release>
<release version="2.2.0" date="2015-06-24" min="2.4" max="2.6.x">
- Make CSV style configurable.
- Fix `{$workspace}` path
</release>
<release version="2.1.3" date="2015-05-13" min="2.4" max="2.6.x">
- Fix a bug with late static binding on PHP 5.3.
</release>
<release version="2.1.2" date="2014-12-17" min="2.4" max="2.6.x">
- Fix the first cache of a result always resulting in an error
- Abstract the transformers for better extensibility
</release>
<release version="2.1.1" date="2014-09-28" min="2.4">
- Expose the CURL error via `httpError()`
- Fix error with CSV importing
</release>
<release version="2.1.0" date="2014-06-25" min="2.4">
- Add support for text format (a copy of the html response body)
- Add some documentation
</release>
<release version="2.0.1" date="2014-06-24" min="2.4">
- Clean-up
</release>
<release version="2.0.0" date="2014-05-06" min="2.4">
- Add support for Symphony 2.4
- Support CSV data format
- Allow `$gateway` to be manipulated and `$data` to previewed
- When the Datasource fails, data is added to the `?debug` page to assist in debugging
- Allow no cache to be set
- Sanitize XPath to allow for more complex queries
</release>
<release version="1.1.0" date="2013-02-19" min="2.3" max="2.4">
- Officially release the extension
- Add `url` to the resulting XML result so you can see what URL was actually fetched
- Fix bug where a result would always be `stale`
- Allow timeout to be user configurable in the Data Source Editor
- Various PHP E_NOTICE fixes
</release>
<release version="1.0.0" date="2012-03-11" min="2.3">
- Initial release
</release>
</releases>
<name>Remote Datasource</name>
<description>A datasource that consumes XML, JSON, CSV or TEXT content.</description>
<repo type="github">https://github.com/symphonycms/remote_datasource</repo>
<url type="issues">https://github.com/symphonycms/remote_datasource/issues</url>
<url type="discuss">https://www.getsymphony.com/discuss/thread/110527/</url>
<authors>
<author>
<name github="symphonycms" symphony="team">Symphony Team</name>
</author>
</authors>
<releases>
<release version="2.4.0" date="2019-01-19" min="2.6" max="3.x.x">
- Pass namespace to the cacheable instance
</release>
<release version="2.3.0" date="2017-07-12" min="2.4" max="3.x.x">
- Bug fixes
- Added compatibility with Symphony 2.7.x and 3.x.x
</release>
<release version="2.2.1" date="2015-12-01" min="2.4" max="2.6.x">
- Fix for php 5.3 compat
</release>
<release version="2.2.0" date="2015-06-24" min="2.4" max="2.6.x">
- Make CSV style configurable.
- Fix `{$workspace}` path
</release>
<release version="2.1.3" date="2015-05-13" min="2.4" max="2.6.x">
- Fix a bug with late static binding on PHP 5.3.
</release>
<release version="2.1.2" date="2014-12-17" min="2.4" max="2.6.x">
- Fix the first cache of a result always resulting in an error
- Abstract the transformers for better extensibility
</release>
<release version="2.1.1" date="2014-09-28" min="2.4">
- Expose the CURL error via `httpError()`
- Fix error with CSV importing
</release>
<release version="2.1.0" date="2014-06-25" min="2.4">
- Add support for text format (a copy of the html response body)
- Add some documentation
</release>
<release version="2.0.1" date="2014-06-24" min="2.4">
- Clean-up
</release>
<release version="2.0.0" date="2014-05-06" min="2.4">
- Add support for Symphony 2.4
- Support CSV data format
- Allow `$gateway` to be manipulated and `$data` to previewed
- When the Datasource fails, data is added to the `?debug` page to assist in debugging
- Allow no cache to be set
- Sanitize XPath to allow for more complex queries
</release>
<release version="1.1.0" date="2013-02-19" min="2.3" max="2.4">
- Officially release the extension
- Add `url` to the resulting XML result so you can see what URL was actually fetched
- Fix bug where a result would always be `stale`
- Allow timeout to be user configurable in the Data Source Editor
- Various PHP E_NOTICE fixes
</release>
<release version="1.0.0" date="2012-03-11" min="2.3">
- Initial release
</release>
</releases>
</extension>

0 comments on commit 4e4f645

Please sign in to comment.