From 6dd299befac44fd266670d91c83096f4f932091a Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 14 May 2012 11:53:18 +0800 Subject: [PATCH] MDL-31901, MDL-28666 merged files API changes --- lib/filelib.php | 7 ++++++- lib/filestorage/stored_file.php | 19 ------------------- repository/draftfiles_ajax.php | 26 ++++++++++++-------------- repository/lib.php | 2 +- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/lib/filelib.php b/lib/filelib.php index 6ca9e7d8375..11cba0fac86 100644 --- a/lib/filelib.php +++ b/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') { diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index 6d6f29411fb..f7e1589c0a2 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -196,25 +196,6 @@ class stored_file { $DB->delete_records('files_reference', array('id'=>$this->file_record->referencefileid)); } - /** - * 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? * diff --git a/repository/draftfiles_ajax.php b/repository/draftfiles_ajax.php index afe39ded7cb..618055146a3 100644 --- a/repository/draftfiles_ajax.php +++ b/repository/draftfiles_ajax.php @@ -143,25 +143,23 @@ switch ($action) { } 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()); } } diff --git a/repository/lib.php b/repository/lib.php index d9020e8df0f..9cea0f8eb39 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -1110,7 +1110,7 @@ abstract class repository { * 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) { } /**