Skip to content

Commit

Permalink
Merge branch 'integration'
Browse files Browse the repository at this point in the history
  • Loading branch information
brendo committed Sep 28, 2014
2 parents 3cddb3b + 810c7fc commit 401fa72
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
````
43 changes: 28 additions & 15 deletions data-sources/datasource.remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------------------*/
Expand Down Expand Up @@ -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/');
Expand Down Expand Up @@ -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()))
. '<a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">'
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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') {
Expand All @@ -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;
}
Expand All @@ -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'])));
}

Expand All @@ -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('<code>Mutex</code>')))
);
}
} else {

// The cache is good, use it!
$data = trim($cachedData['data']);
$creation = DateTimeObj::get('c', $cachedData['creation']);
Expand Down
4 changes: 4 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
</author>
</authors>
<releases>
<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
Expand Down
20 changes: 9 additions & 11 deletions lib/class.csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@ public static function convertToXML($data)
*/
public static function addRow(DOMDocument $doc, DOMElement $root, $row, $headers)
{
foreach ($row as $column) {
// Create <entry><header>value</header></entry>
$entry = $doc->createElement('entry');
// Create <entry><header>value</header></entry>
$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);
}
}

0 comments on commit 401fa72

Please sign in to comment.