Skip to content

Commit

Permalink
Move redirection to a separate method for easier overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Jan 17, 2011
1 parent 7624b38 commit 19af831
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions controllers/upload.php
Expand Up @@ -69,29 +69,14 @@ public function post_upload(array $args)
$attachment = midgardmvc_helper_attachmentserver_helpers::get_by_locationname($parent, $_POST['locationname']);
if (!$attachment)
{
/**
* It seems we can't use the location like this
*
$attachment = midgardmvc_helper_attachmentserver_attachment($attachment->guid)
$attachment = new midgardmvc_helper_attachmentserver_attachment();
$attachment->parentguid = $parent->guid;
$attachment->locationname = $_POST['locationname'];
// Also the location is not md5 but sha1 or somesuch
$random = md5($parent->guid . $_POST['locationname'] . base_convert(mt_rand(0, (PHP_INT_MAX / 36)), 10, 36));
$attachment->location = "{$random[0]}/{$random[1]}/{$random}";
$attachment->title = $title;
$attachment->name = $file['name'];
$attachment->mimetype = $file['type'];
$attachment->create();
*/
// Workaround
$attachment = $parent->create_attachment($file['name'], $title, $file['type']);
if (is_null($attachment))
{
throw new midgardmvc_exception("\$parent->create_attachment('{$file['name']}', '{$title}', '{$file['type']}') failed");
}
$attachment_ext = new midgardmvc_helper_attachmentserver_attachment($attachment->guid);
$attachment_ext->locationname = $_POST['locationname']; // update will be called later
$attachment_ext->locationname = $_POST['locationname'];
$attachment_ext->update();
}
}
Expand All @@ -110,7 +95,11 @@ public function post_upload(array $args)
}

midgardmvc_helper_attachmentserver_helpers::copy_file_to_attachment($file['tmp_name'], $attachment);
$this->handle_result();
}

public function handle_result()
{
if ( isset($_POST['variant'])
&& !empty($_POST['variant']))
{
Expand All @@ -121,4 +110,4 @@ public function post_upload(array $args)
midgardmvc_core::get_instance()->head->relocate("/mgd:attachment/{$attachment->guid}/{$attachment->name}");
}
}
?>
?>

0 comments on commit 19af831

Please sign in to comment.