Permalink
Browse files

MDL-31901, MDL-28666 merged files API changes

  • Loading branch information...
1 parent dafe129 commit 6dd299befac44fd266670d91c83096f4f932091a @marinaglancy marinaglancy committed May 14, 2012
Showing with 19 additions and 35 deletions.
  1. +6 −1 lib/filelib.php
  2. +0 −19 lib/filestorage/stored_file.php
  3. +12 −14 repository/draftfiles_ajax.php
  4. +1 −1 repository/lib.php
View
7 lib/filelib.php
@@ -598,7 +598,12 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
$item->datemodified = $file->get_timemodified();
$item->datecreated = $file->get_timecreated();
$item->isref = $file->is_external_file();
- $item->refcount = $fs->get_reference_count($file);
+ // find the file this draft file was created from and count all references in local
+ // system pointing to that file
+ $source = unserialize($file->get_source());
+ if (isset($source->original)) {
+ $item->refcount = $fs->search_references_count($source->original);
+ }
// TODO MDL-32900 this is not the correct way to check that it is archive, use filetype_parser instead
if ($icon == 'zip') {
View
19 lib/filestorage/stored_file.php
@@ -197,25 +197,6 @@ public function delete_reference() {
}
/**
- * Update some file record fields
- *
- * @param stdClass $dataobject
- */
- public function update($dataobject) {
- // TODO MDL-28666 THIS FUNCTION IS COPIED FROM UNFINISHED CODE OF MDL-28666.
- global $DB;
- $keys = array_keys((array)$this->file_record);
- foreach ($dataobject as $field => $value) {
- if (in_array($field, $keys)) {
- $this->file_record->$field = $value;
- } else {
- throw new coding_exception("Invalid field name, $field doesn't exist in file record");
- }
- }
- $DB->update_record('files', $this->file_record);
- }
-
- /**
* Is this a directory?
*
* Directories are only emulated, internally they are stored as empty
View
26 repository/draftfiles_ajax.php
@@ -143,25 +143,23 @@
}
if (!empty($updatedata)) {
- $updatedata['timemodified'] = $file->get_timemodified();
- $changes = array_diff(array_keys($updatedata), array('filepath'));
- if (!empty($changes)) {
- // any change except for the moving to another folder alters 'Date modified' of the file
- $updatedata['timemodified'] = time();
- }
if (array_key_exists('filename', $updatedata) || array_key_exists('filepath', $updatedata)) {
// check that target file name does not exist
if ($fs->file_exists($user_context->id, 'user', 'draft', $draftid, $newfilepath, $newfilename)) {
die(json_encode((object)array('error' => get_string('fileexists', 'repository'))));
}
- try {
- $newfile = $fs->create_file_from_storedfile($updatedata, $file);
- } catch (Exception $e) {
- die(json_encode((object)array('error' => $e->getMessage())));
- }
- $file->delete();
- } else {
- $file->update((object)$updatedata);
+ $file->rename($newfilepath, $newfilename);
+ }
+ if (array_key_exists('license', $updatedata)) {
+ $file->set_license($updatedata['license']);
+ }
+ if (array_key_exists('author', $updatedata)) {
+ $file->set_license($updatedata['author']);
+ }
+ $changes = array_diff(array_keys($updatedata), array('filepath'));
+ if (!empty($changes)) {
+ // any change except for the moving to another folder alters 'Date modified' of the file
+ $file->set_timemodified(time());
}
}
View
2 repository/lib.php
@@ -1110,7 +1110,7 @@ public function get_reference_details($reference) {
* repository::get_file_reference()
* @param stored_file $storedfile created file reference
*/
- public function cache_file_by_reference($reference, $storedfile = null) {
+ public function cache_file_by_reference($reference, $storedfile) {
}
/**

0 comments on commit 6dd299b

Please sign in to comment.