From: dongsheng Date: Fri, 1 Aug 2008 03:40:37 +0000 (+0000) Subject: MDL-13766, use FILE_API in repository. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=6cbb4efbddf8ec75942669b36fdb8b0fb8fd187d;p=moodle.git MDL-13766, use FILE_API in repository. --- diff --git a/repository/ws.php b/repository/ws.php index 3221780442..4baa8fb990 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -1,6 +1,7 @@ repository_cache_expire = 60*60; @@ -58,10 +59,24 @@ if($action == 'list') { } elseif($action == 'download') { $ret = $repo->get_file($file, $title); // TODO - // Need to communicate with FILE API - // Copy the tmp file to final location + // Ask Petr how to use FILE_API here try { - echo json_encode($ret); + $pathname = $ret; + $entry = new object(); + $entry->contextid = SITEID; + $entry->filearea = 'repository'; + $entry->filepath = '/'; + $entry->filename = $title; + $entry->timecreated = time(); + $entry->timemodified = time(); + $entry->itemid = $USER->id; + $entry->mimetype = mimeinfo('type', $pathname); + $entry->userid = $USER->id; + $fs = get_file_storage(); + if ($file = $fs->create_file_from_pathname($entry, $pathname)) { + //echo json_encode($file->get_content_file_location()); + echo json_encode($file->get_itemid()); + } } catch (repository_exception $e){ $err = new stdclass; $err->e = $e->getMessage();