MDL-34290 repository_boxnet, boxlib use request timeouts

boxlib receives additional argument as request timeout
repository_boxnet::get_file_by_reference respects request timeouts and downloads file into moodle only if it is image
also some improvements to repository_boxnet source display functions;
also do not cache result of request in retrieving of listing, user is unable to see the new files he added to box.
This commit is contained in:
Marina Glancy 2012-07-31 10:54:48 +08:00
parent bc6f241ca2
commit f24b0f69ee
2 changed files with 38 additions and 23 deletions

View file

@ -176,7 +176,7 @@ class boxclient {
$params['action'] = 'get_account_tree';
$params['onelevel'] = 1;
$params['params[]'] = 'nozip';
$c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
$c = new curl(array('debug'=>$this->debug));
$c->setopt(array('CURLOPT_FOLLOWLOCATION'=>1));
try {
$args = array();
@ -196,23 +196,25 @@ class boxclient {
* Get box.net file info
*
* @param string $fileid
* @return string|null
* @param int $timeout request timeout in seconds
* @return stdClass|null
*/
function get_file_info($fileid) {
function get_file_info($fileid, $timeout = 0) {
$this->_clearErrors();
$params = array();
$params['action'] = 'get_file_info';
$params['file_id'] = $fileid;
$params['auth_token'] = $this->auth_token;
$params['api_key'] = $this->api_key;
$http = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
$xml = $http->get($this->_box_api_url, $params);
$o = simplexml_load_string(trim($xml));
if ($o->status == 's_get_file_info') {
return $o->info;
} else {
return null;
$http = new curl(array('debug'=>$this->debug));
$xml = $http->get($this->_box_api_url, $params, array('timeout' => $timeout));
if (!$http->get_errno()) {
$o = simplexml_load_string(trim($xml));
if ($o->status == 's_get_file_info') {
return $o->info;
}
}
return null;
}
/**