Skip to content

Commit 401fa72

Browse files
committed
Merge branch 'integration'
2 parents 3cddb3b + 810c7fc commit 401fa72

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ public static function prepareGateway(&$gateway) {}
3535
* the parsed xml string data returned by the Gateway by reference
3636
*/
3737
public function exposeData(&$data) {}
38+
39+
/**
40+
* This method is called when their is an http error
41+
* or when content type is unsupported
42+
*
43+
* @since Remote Datasource 2.0
44+
* @param array $info
45+
* info of the http request
46+
*/
47+
public function httpError(&$info) {}
3848
````

data-sources/datasource.remote.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public function exposeData(&$data)
7171

7272
}
7373

74+
/**
75+
* This method is called when their is an http error
76+
* or when content type is unsupported
77+
*
78+
* @since Remote Datasource 2.0
79+
* @param array $info
80+
* info of the http request
81+
*/
82+
public function httpError(&$info)
83+
{
84+
85+
}
86+
7487
/*-------------------------------------------------------------------------
7588
Utilities
7689
-------------------------------------------------------------------------*/
@@ -226,7 +239,7 @@ public static function buildCacheID($settings)
226239
*/
227240
public static function buildCacheInformation(XMLElement $wrapper, Cacheable $cache, $cache_id)
228241
{
229-
$cachedData = $cache->check($cache_id);
242+
$cachedData = $cache->read($cache_id);
230243

231244
if (is_array($cachedData) && !empty($cachedData) && (time() < $cachedData['expiry'])) {
232245
$a = Widget::Anchor(__('Clear now'), SYMPHONY_URL . getCurrentPage() . 'clear_cache/');
@@ -256,7 +269,7 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
256269

257270
// If `clear_cache` is set, clear it..
258271
if (isset($cache_id) && in_array('clear_cache', Administration::instance()->Page->getContext())) {
259-
$cache->forceExpiry($cache_id);
272+
$cache->delete($cache_id);
260273
Administration::instance()->Page->pageAlert(
261274
__('Data source cache cleared at %s.', array(Widget::Time()->generate()))
262275
. '<a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">'
@@ -639,7 +652,7 @@ public function execute(array &$param_pool = null)
639652
// Check for an existing Cache for this Datasource
640653
$cache_id = self::buildCacheID($this);
641654
$cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
642-
$cachedData = $cache->check($cache_id);
655+
$cachedData = $cache->read($cache_id);
643656
$writeToCache = null;
644657
$isCacheValid = true;
645658
$creation = DateTimeObj::get('c');
@@ -678,6 +691,7 @@ public function execute(array &$param_pool = null)
678691
$writeToCache = false;
679692

680693
$result->setAttribute('valid', 'false');
694+
$this->httpError($info);
681695

682696
// 28 is CURLE_OPERATION_TIMEOUTED
683697
if ($info['curl_error'] == 28) {
@@ -697,9 +711,9 @@ public function execute(array &$param_pool = null)
697711
}
698712

699713
return $result;
700-
} else if (strlen($data) > 0) {
701714

702-
// Handle where there is `$data`
715+
// Handle where there is `$data`
716+
} else if (strlen($data) > 0) {
703717

704718
// If it's JSON, convert it to XML
705719
if ($this->dsParamFORMAT == 'json') {
@@ -723,12 +737,11 @@ public function execute(array &$param_pool = null)
723737
);
724738
}
725739
} elseif ($this->dsParamFORMAT == 'txt') {
726-
$txtElement = new XMLElement('entry');
727-
$txtElement->setValue(General::wrapInCDATA($data));
728-
$data = $txtElement->generate();
729-
$txtElement = null;
730-
}
731-
else if (!General::validateXML($data, $errors, false, new XsltProcess)) {
740+
$txtElement = new XMLElement('entry');
741+
$txtElement->setValue(General::wrapInCDATA($data));
742+
$data = $txtElement->generate();
743+
$txtElement = null;
744+
} else if (!General::validateXML($data, $errors, false, new XsltProcess)) {
732745
// If the XML doesn't validate..
733746
$writeToCache = false;
734747
}
@@ -744,7 +757,7 @@ public function execute(array &$param_pool = null)
744757
if (strlen(trim($e['message'])) == 0) {
745758
continue;
746759
}
747-
760+
748761
$error->appendChild(new XMLElement('item', General::sanitize($e['message'])));
749762
}
750763

@@ -753,19 +766,19 @@ public function execute(array &$param_pool = null)
753766
return $result;
754767
}
755768
} elseif (strlen($data) == 0) {
756-
769+
757770
// If `$data` is empty, set the `force_empty_result` to true.
758771
$this->_force_empty_result = true;
759772
}
760773
} else {
761-
774+
762775
// Failed to acquire a lock
763776
$result->appendChild(
764777
new XMLElement('error', __('The %s class failed to acquire a lock.', array('<code>Mutex</code>')))
765778
);
766779
}
767780
} else {
768-
781+
769782
// The cache is good, use it!
770783
$data = trim($cachedData['data']);
771784
$creation = DateTimeObj::get('c', $cachedData['creation']);

extension.meta.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
</author>
1111
</authors>
1212
<releases>
13+
<release version="2.1.1" date="2014-09-28" min="2.4">
14+
- Expose the CURL error via `httpError()`
15+
- Fix error with CSV importing
16+
</release>
1317
<release version="2.1.0" date="2014-06-25" min="2.4">
1418
- Add support for text format (a copy of the html response body)
1519
- Add some documentation

lib/class.csv.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,17 @@ public static function convertToXML($data)
5050
*/
5151
public static function addRow(DOMDocument $doc, DOMElement $root, $row, $headers)
5252
{
53-
foreach ($row as $column) {
54-
// Create <entry><header>value</header></entry>
55-
$entry = $doc->createElement('entry');
53+
// Create <entry><header>value</header></entry>
54+
$entry = $doc->createElement('entry');
5655

57-
foreach ($headers as $i => $header) {
58-
$col = $doc->createElement($header);
59-
$col = $entry->appendChild($col);
56+
foreach ($headers as $i => $header) {
57+
$col = $doc->createElement($header);
58+
$col = $entry->appendChild($col);
6059

61-
$value = $doc->createTextNode($row[$i]);
62-
$value = $col->appendChild($value);
63-
}
64-
65-
$root->appendChild($entry);
60+
$value = $doc->createTextNode($row[$i]);
61+
$value = $col->appendChild($value);
6662
}
63+
64+
$root->appendChild($entry);
6765
}
6866
}

0 commit comments

Comments
 (0)