Commit b422c571 authored by Ruslan Kabalin's avatar Ruslan Kabalin
Browse files

filebrowser: ignore unexisting files in select interface


Signed-off-by: default avatarRuslan Kabalin <ruslan.kabalin@luns.net.uk>
parent 0b1f14a3
......@@ -293,12 +293,18 @@ function editpost_submit(Pieform $form, $values) {
if (!empty($new) || !empty($old)) {
foreach ($old as $o) {
if (!in_array($o, $new)) {
$postobj->detach($o);
try {
$postobj->detach($o);
}
catch (ArtefactNotFoundException $e) {}
}
}
foreach ($new as $n) {
if (!in_array($n, $old)) {
$postobj->attach($n);
try {
$postobj->attach($n);
}
catch (ArtefactNotFoundException $e) {}
}
}
}
......
......@@ -533,7 +533,16 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
$keys = array_keys($select);
$add = (int) $keys[0];
if (isset($element['selectcallback']) && is_callable($element['selectcallback'])) {
$element['selectcallback']($add);
try {
$element['selectcallback']($add);
}
catch (ArtefactNotFoundException $e) {
$result = array(
'error' => true,
'message' => get_string('selectingfailed', 'artefact.file'),
);
return $result;
}
}
else {
$result['select'] = $add;
......@@ -548,7 +557,16 @@ function pieform_element_filebrowser_doupdate(Pieform $form, $element) {
$keys = array_keys($unselect);
$del = (int) $keys[0];
if (isset($element['unselectcallback']) && is_callable($element['unselectcallback'])) {
$element['unselectcallback']($del);
try {
$element['unselectcallback']($del);
}
catch (ArtefactNotFoundException $e) {
$result = array(
'error' => true,
'message' => get_string('removingfailed', 'artefact.file'),
);
return $result;
}
}
else {
$result['unselect'] = $del;
......
......@@ -57,7 +57,7 @@ $string['maxquotatoolow'] = 'The maximum quota cannot be lower than the default
$string['maxquotaexceeded'] = 'You specified a quota above the maximum available setting for this site (%s). Try specifying a lower value or contact the site administrator to have them increase the maximum quota.';
$string['maxquotaexceededform'] = 'Please specify a file quota of less than %s.';
$string['maxquotadescription'] = 'You can set the maximum quota that an administrator can give to a user. Existing user quotas will not be affected.';
$string['deletingfailed'] = 'Deleting failed: file or folder does not exists any more';
$string['deletingfailed'] = 'Deleting failed: file or folder does not exist any more';
$string['deletefile?'] = 'Are you sure you want to delete this file?';
$string['deletefolder?'] = 'Are you sure you want to delete this folder?';
$string['Description'] = 'Description';
......@@ -68,7 +68,7 @@ $string['downloadfile'] = 'Download %s';
$string['downloadoriginalversion'] = 'Download the original version';
$string['editfile'] = 'Edit file';
$string['editfolder'] = 'Edit folder';
$string['editingfailed'] = 'Editing failed: file or folder does not exists any more';
$string['editingfailed'] = 'Editing failed: file or folder does not exist any more';
$string['emptyfolder'] = 'Empty folder';
$string['file'] = 'File'; // Capitalised to be consistent with names of all the other artefact types
$string['File'] = 'File';
......@@ -108,7 +108,7 @@ $string['movefaileddestinationnotfolder'] = 'You can only move files into folder
$string['movefailednotfileartefact'] = 'Only file, folder and image artefacts can be moved.';
$string['movefailednotowner'] = 'You do not have permission to move the file into this folder';
$string['movefailed'] = 'Move failed.';
$string['movingfailed'] = 'Moving failed: file or folder does not exists any more';
$string['movingfailed'] = 'Moving failed: file or folder does not exist any more';
$string['nametoolong'] = 'That name is too long. Please choose a shorter one.';
$string['nofilesfound'] = 'No files found';
$string['notpublishable'] = 'You do not have permission to publish this file';
......@@ -117,8 +117,10 @@ $string['Owner'] = 'Owner';
$string['parentfolder'] = 'Parent folder';
$string['Preview'] = 'Preview';
$string['requireagreement'] = 'Require Agreement';
$string['removingfailed'] = 'Removing failed: file or folder does not exist any more';
$string['savechanges'] = 'Save changes';
$string['selectafile'] = 'Select a file';
$string['selectingfailed'] = 'Selecting failed: file or folder does not exist any more';
$string['Size'] = 'Size';
$string['spaceused'] = 'Space used';
$string['timeouterror'] = 'File upload failed: try uploading the file again';
......
......@@ -1047,6 +1047,9 @@ abstract class ArtefactType {
if (record_exists('artefact_attachment', 'artefact', $this->get('id'), 'attachment', $attachmentid)) {
return;
}
if (!record_exists('artefact', 'id', $attachmentid)) {
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'mahara', $attachmentid));
}
$data = new StdClass;
$data->artefact = $this->get('id');
$data->attachment = $attachmentid;
......@@ -1084,6 +1087,9 @@ abstract class ArtefactType {
delete_records('artefact_attachment', 'artefact', $this->id);
return;
}
if (!record_exists('artefact', 'id', $attachmentid)) {
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'mahara', $attachmentid));
}
delete_records('artefact_attachment', 'artefact', $this->get('id'), 'attachment', $attachmentid);
delete_records('artefact_parent_cache', 'parent', $this->get('id'), 'artefact', $attachmentid);
if ($this->get('parent')) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment