@@ -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 ' ]);
0 commit comments