Commit f4db6242 authored by Alan McNatty's avatar Alan McNatty

Moved order so if file upload fails we don't leave a blog entry with no attachment

parent ac7f0e0e
......@@ -143,10 +143,36 @@ try {
}
catch (ParameterException $e) { }
// -- Start by creating a blog entry --
// -- Now check for files to upload --
$artefact_id = ''; // our resulting artefact id on creation
if ( $_FILES ) {
if ( $blog || ! $title ) { // set the filename to be the title of the artefact
$title = basename($_FILES['userfile']['name']);
}
try {
$data->title = ArtefactTypeFileBase::get_new_file_title($title, $data->parent, $data->owner);
if ( ! $blog ) { // only set a description if it's an artefact upload
$data->description = $description;
}
$data->tags = $tags;
$artefact_id = ArtefactTypeFile::save_uploaded_file('userfile', $data);
if ( $artefact_id ) {
$json['id'] = $artefact_id;
}
}
catch (QuotaExceededException $e) {
jsonreply( array('fail' => 'Quota exceeded' ) );
}
catch (UploadException $e) {
jsonreply( array('fail' => 'Failed to save file') );
}
}
// -- Next create a blog entry --
$postobj = ''; // our resulting blog post object on creation
$artefact_id = ''; // our resulting artefact id on creation
if ( $blog ) {
if ( ! ( $title && $description ) ) {
......@@ -159,7 +185,7 @@ if ( $blog ) {
// adding a post to a blog that is not theirs
throw new AccessDeniedException(get_string('youarenottheownerofthisblog', 'artefact.blog'));
}
// Should we create a new post of attach the new file to an existing post
// Should we create a new post or attach the new file to an existing post
$postids = get_records_sql_array("
SELECT a.id
FROM {artefact} a
......@@ -186,33 +212,6 @@ if ( $blog ) {
}
}
// -- Now check for files to upload --
if ( $_FILES ) {
if ( $blog || ! $title ) { // set the filename to be the title of the artefact
$title = basename($_FILES['userfile']['name']);
}
try {
$data->title = ArtefactTypeFileBase::get_new_file_title($title, $data->parent, $data->owner);
if ( ! $blog ) { // only set a description if it's an artefact upload
$data->description = $description;
}
$data->tags = $tags;
$artefact_id = ArtefactTypeFile::save_uploaded_file('userfile', $data);
if ( $artefact_id ) {
$json['id'] = $artefact_id;
}
}
catch (QuotaExceededException $e) {
jsonreply( array('fail' => 'Quota exceeded' ) );
}
catch (UploadException $e) {
jsonreply( array('fail' => 'Failed to save file') );
}
}
// Check to see if we're creating a journal entry
// -- Finally attach the file to the blog post once uploaded and --
......
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