]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766, use FILE_API in repository.
authordongsheng <dongsheng>
Fri, 1 Aug 2008 03:40:37 +0000 (03:40 +0000)
committerdongsheng <dongsheng>
Fri, 1 Aug 2008 03:40:37 +0000 (03:40 +0000)
repository/ws.php

index 32217804427ce65296ecf63f65bcec78f5e67d9e..4baa8fb99069a0ce9c27f99942f15e3add5c924d 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 set_time_limit(0);
 require_once('../config.php');
+require_once('../lib/filelib.php');
 require_once('lib.php');
 // set one hour here
 $CFG->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();