diff --git a/README.md b/README.md index 9f61f4d..ef3f07f 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,14 @@ public static function prepareGateway(&$gateway) {} * the parsed xml string data returned by the Gateway by reference */ public function exposeData(&$data) {} + +/** + * This method is called when their is an http error + * or when content type is unsupported + * + * @since Remote Datasource 2.0 + * @param array $info + * info of the http request + */ +public function httpError(&$info) {} ```` diff --git a/data-sources/datasource.remote.php b/data-sources/datasource.remote.php index 82cebe4..106d8f6 100644 --- a/data-sources/datasource.remote.php +++ b/data-sources/datasource.remote.php @@ -71,6 +71,19 @@ public function exposeData(&$data) } + /** + * This method is called when their is an http error + * or when content type is unsupported + * + * @since Remote Datasource 2.0 + * @param array $info + * info of the http request + */ + public function httpError(&$info) + { + + } + /*------------------------------------------------------------------------- Utilities -------------------------------------------------------------------------*/ @@ -226,7 +239,7 @@ public static function buildCacheID($settings) */ public static function buildCacheInformation(XMLElement $wrapper, Cacheable $cache, $cache_id) { - $cachedData = $cache->check($cache_id); + $cachedData = $cache->read($cache_id); if (is_array($cachedData) && !empty($cachedData) && (time() < $cachedData['expiry'])) { $a = Widget::Anchor(__('Clear now'), SYMPHONY_URL . getCurrentPage() . 'clear_cache/'); @@ -256,7 +269,7 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array() // If `clear_cache` is set, clear it.. if (isset($cache_id) && in_array('clear_cache', Administration::instance()->Page->getContext())) { - $cache->forceExpiry($cache_id); + $cache->delete($cache_id); Administration::instance()->Page->pageAlert( __('Data source cache cleared at %s.', array(Widget::Time()->generate())) . '' @@ -639,7 +652,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->check($cache_id); + $cachedData = $cache->read($cache_id); $writeToCache = null; $isCacheValid = true; $creation = DateTimeObj::get('c'); @@ -678,6 +691,7 @@ public function execute(array &$param_pool = null) $writeToCache = false; $result->setAttribute('valid', 'false'); + $this->httpError($info); // 28 is CURLE_OPERATION_TIMEOUTED if ($info['curl_error'] == 28) { @@ -697,9 +711,9 @@ public function execute(array &$param_pool = null) } return $result; - } else if (strlen($data) > 0) { - // Handle where there is `$data` + // Handle where there is `$data` + } else if (strlen($data) > 0) { // If it's JSON, convert it to XML if ($this->dsParamFORMAT == 'json') { @@ -723,12 +737,11 @@ public function execute(array &$param_pool = null) ); } } elseif ($this->dsParamFORMAT == 'txt') { - $txtElement = new XMLElement('entry'); - $txtElement->setValue(General::wrapInCDATA($data)); - $data = $txtElement->generate(); - $txtElement = null; - } - else if (!General::validateXML($data, $errors, false, new XsltProcess)) { + $txtElement = new XMLElement('entry'); + $txtElement->setValue(General::wrapInCDATA($data)); + $data = $txtElement->generate(); + $txtElement = null; + } else if (!General::validateXML($data, $errors, false, new XsltProcess)) { // If the XML doesn't validate.. $writeToCache = false; } @@ -744,7 +757,7 @@ public function execute(array &$param_pool = null) if (strlen(trim($e['message'])) == 0) { continue; } - + $error->appendChild(new XMLElement('item', General::sanitize($e['message']))); } @@ -753,19 +766,19 @@ public function execute(array &$param_pool = null) return $result; } } elseif (strlen($data) == 0) { - + // If `$data` is empty, set the `force_empty_result` to true. $this->_force_empty_result = true; } } else { - + // Failed to acquire a lock $result->appendChild( new XMLElement('error', __('The %s class failed to acquire a lock.', array('Mutex'))) ); } } else { - + // The cache is good, use it! $data = trim($cachedData['data']); $creation = DateTimeObj::get('c', $cachedData['creation']); diff --git a/extension.meta.xml b/extension.meta.xml index 1f394ad..8494384 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -10,6 +10,10 @@ + + - Expose the CURL error via `httpError()` + - Fix error with CSV importing + - Add support for text format (a copy of the html response body) - Add some documentation diff --git a/lib/class.csv.php b/lib/class.csv.php index 4d09cf8..f39a4e8 100644 --- a/lib/class.csv.php +++ b/lib/class.csv.php @@ -50,19 +50,17 @@ public static function convertToXML($data) */ public static function addRow(DOMDocument $doc, DOMElement $root, $row, $headers) { - foreach ($row as $column) { - // Create
value
- $entry = $doc->createElement('entry'); + // Create
value
+ $entry = $doc->createElement('entry'); - foreach ($headers as $i => $header) { - $col = $doc->createElement($header); - $col = $entry->appendChild($col); + foreach ($headers as $i => $header) { + $col = $doc->createElement($header); + $col = $entry->appendChild($col); - $value = $doc->createTextNode($row[$i]); - $value = $col->appendChild($value); - } - - $root->appendChild($entry); + $value = $doc->createTextNode($row[$i]); + $value = $col->appendChild($value); } + + $root->appendChild($entry); } }