Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-31901, MDL-28666 merged files API changes

  • Loading branch information...
commit 6dd299befac44fd266670d91c83096f4f932091a 1 parent dafe129
Marina Glancy authored May 14, 2012
7  lib/filelib.php
@@ -598,7 +598,12 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
598 598
             $item->datemodified = $file->get_timemodified();
599 599
             $item->datecreated = $file->get_timecreated();
600 600
             $item->isref = $file->is_external_file();
601  
-            $item->refcount = $fs->get_reference_count($file);
  601
+            // find the file this draft file was created from and count all references in local
  602
+            // system pointing to that file
  603
+            $source = unserialize($file->get_source());
  604
+            if (isset($source->original)) {
  605
+                $item->refcount = $fs->search_references_count($source->original);
  606
+            }
602 607
 
603 608
             // TODO MDL-32900 this is not the correct way to check that it is archive, use filetype_parser instead
604 609
             if ($icon == 'zip') {
19  lib/filestorage/stored_file.php
@@ -197,25 +197,6 @@ public function delete_reference() {
197 197
     }
198 198
 
199 199
     /**
200  
-     * Update some file record fields
201  
-     *
202  
-     * @param stdClass $dataobject
203  
-     */
204  
-    public function update($dataobject) {
205  
-        // TODO MDL-28666 THIS FUNCTION IS COPIED FROM UNFINISHED CODE OF MDL-28666.
206  
-        global $DB;
207  
-        $keys = array_keys((array)$this->file_record);
208  
-        foreach ($dataobject as $field => $value) {
209  
-            if (in_array($field, $keys)) {
210  
-                $this->file_record->$field = $value;
211  
-            } else {
212  
-                throw new coding_exception("Invalid field name, $field doesn't exist in file record");
213  
-            }
214  
-        }
215  
-        $DB->update_record('files', $this->file_record);
216  
-    }
217  
-
218  
-    /**
219 200
      * Is this a directory?
220 201
      *
221 202
      * Directories are only emulated, internally they are stored as empty
26  repository/draftfiles_ajax.php
@@ -143,25 +143,23 @@
143 143
         }
144 144
 
145 145
         if (!empty($updatedata)) {
146  
-            $updatedata['timemodified'] = $file->get_timemodified();
147  
-            $changes = array_diff(array_keys($updatedata), array('filepath'));
148  
-            if (!empty($changes)) {
149  
-                // any change except for the moving to another folder alters 'Date modified' of the file
150  
-                $updatedata['timemodified'] = time();
151  
-            }
152 146
             if (array_key_exists('filename', $updatedata) || array_key_exists('filepath', $updatedata)) {
153 147
                 // check that target file name does not exist
154 148
                 if ($fs->file_exists($user_context->id, 'user', 'draft', $draftid, $newfilepath, $newfilename)) {
155 149
                     die(json_encode((object)array('error' => get_string('fileexists', 'repository'))));
156 150
                 }
157  
-                try {
158  
-                    $newfile = $fs->create_file_from_storedfile($updatedata, $file);
159  
-                } catch (Exception $e) {
160  
-                    die(json_encode((object)array('error' => $e->getMessage())));
161  
-                }
162  
-                $file->delete();
163  
-            } else {
164  
-                $file->update((object)$updatedata);
  151
+                $file->rename($newfilepath, $newfilename);
  152
+            }
  153
+            if (array_key_exists('license', $updatedata)) {
  154
+                $file->set_license($updatedata['license']);
  155
+            }
  156
+            if (array_key_exists('author', $updatedata)) {
  157
+                $file->set_license($updatedata['author']);
  158
+            }
  159
+            $changes = array_diff(array_keys($updatedata), array('filepath'));
  160
+            if (!empty($changes)) {
  161
+                // any change except for the moving to another folder alters 'Date modified' of the file
  162
+                $file->set_timemodified(time());
165 163
             }
166 164
         }
167 165
 
2  repository/lib.php
@@ -1110,7 +1110,7 @@ public function get_reference_details($reference) {
1110 1110
      *                          repository::get_file_reference()
1111 1111
      * @param stored_file $storedfile created file reference
1112 1112
      */
1113  
-    public function cache_file_by_reference($reference, $storedfile = null) {
  1113
+    public function cache_file_by_reference($reference, $storedfile) {
1114 1114
     }
1115 1115
 
1116 1116
     /**

0 notes on commit 6dd299b

Please sign in to comment.
Something went wrong with that request. Please try again.