mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-31901, MDL-28666 merged files API changes
This commit is contained in:
parent
dafe129637
commit
6dd299befa
@ -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') {
|
||||
|
@ -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?
|
||||
*
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user