public function action_change_password() { Util_security::check_method('POST'); Util_security::check_csrf(); $form = $this->form_setting_password(); $val = $form->validation(); if (!$val->run()) { Session::set_flash('error', $val->show_errors()); $this->action_password(); return; } $post = $val->validated(); $error_message = ''; $is_transaction_rollback = false; try { DB::start_transaction(); $this->change_password($post['old_password'], $post['password']); DB::commit_transaction(); $mail = new Site_Mail('memberSettingPassword'); $mail->send($this->u->member_auth->email, array('to_name' => $this->u->name)); Session::set_flash('message', term('site.password') . 'を変更しました。'); Response::redirect('member/setting'); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (WrongPasswordException $e) { $is_transaction_rollback = true; $error_message = sprintf('現在の%sが正しくありません。', term('site.password')); } catch (\Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('site.password') . 'の変更に失敗しました。'; } catch (Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } $this->action_password(); }
/** * Mmeber leave * * @access public * @return Response */ public function action_index() { $val = self::get_validation_object(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $success_message = sprintf('%sを%sしました。', term('form.invite', 'site.mail'), term('form.post')); $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new ValidationFailedException($val->show_errors()); } $post = $val->validated(); if (Model_MemberPre::get_one4invite_member_id_and_email($this->u->id, $post['email'])) { throw new ValidationFailedException(sprintf('その%sは既に%sです。', term('site.email'), term('form.invited'))); } DB::start_transaction(); $token = Model_MemberPre::save_with_token($post['email'], null, $this->u->id); DB::commit_transaction(); $mail = new Site_Mail('memberInvite'); $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token), 'invite_member_name' => $this->u->name, 'invite_message' => $post['message'])); Session::set_flash('message', $success_message); Response::redirect('member/invite'); } catch (ValidationFailedException $e) { $error_message = Site_Controller::get_error_message($e); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e); } if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } if ($error_message) { Session::set_flash('error', $error_message); } } $this->set_title_and_breadcrumbs(term('form.invite_friend'), null, $this->u); $this->template->content = \View::forge('member/invite', array('val' => $val, 'member_pres' => Model_MemberPre::get4invite_member_id($this->u->id))); }
/** * News delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { $id = (int) $id; \Util_security::check_method('POST'); \Util_security::check_csrf(); $error_message = ''; $is_transaction_rollback = false; try { $member = \Model_Member::check_authority($id); $message = \Site_Member::remove($member); \Session::set_flash('message', $message); } catch (\EmailValidationFailedException $e) { \Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (\EmailSendingFailedException $e) { \Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('member.view') . 'が存在しません。'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $is_transaction_rollback = true; if (!($error_message = $e->getMessage())) { $error_message = term('site.left') . 'に失敗しました。'; } } if ($error_message) { if ($is_transaction_rollback && \DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); } \Response::redirect(\Site_Util::get_redirect_uri('admin/member')); }
/** * News delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); $content_page = \Content\Model_ContentPage::check_authority($id); $error_message = ''; try { \DB::start_transaction(); $content_page->delete(); \DB::commit_transaction(); \Session::set_flash('message', term('content.page') . 'を削除しました。'); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); } \Response::redirect(\Site_Util::get_redirect_uri('admin/content/page')); }
/** * Action image delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_csrf(); $site_image = \Model_SiteImage::check_authority($id); try { \DB::start_transaction(); $site_image->delete(); \DB::commit_transaction(); \Session::set_flash('message', term('site.image') . 'を削除しました。'); \Response::redirect('admin/content/image'); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (Exception $e) { $error_message = $e->getMessage(); } if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); \Response::redirect('admin/content/image/' . $id); }
public function action_delete() { Util_security::check_method('POST'); Util_security::check_csrf(); $form = $this->form_leave(); $val = $form->validation(); if (!$val->run()) { Session::set_flash('error', $val->show_errors()); $this->action_index(); return; } if (!$this->u->check_registered_oauth(true) && !$this->auth_instance->check_password()) { Session::set_flash('error', term('site.password') . 'が正しくありません'); $this->action_index(); return; } $error_message = ''; $is_transaction_rollback = false; try { $message = Site_Member::remove($this->u); $this->auth_instance->logout(); Session::set_flash('message', $message); Response::redirect(conf('login_uri.site')); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('member.view') . 'が存在しません。'; } catch (Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; if (!($error_message = $e->getMessage())) { $error_message = term('site.left') . 'に失敗しました。'; } } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } $this->action_index(); }
/** * News edit * * @access public * @params integer * @return Response */ public function action_edit($id = null) { $news = \News\Model_News::check_authority($id); $val = self::get_validation_object($news); $news_images = array(); $news_files = array(); $images = array(); $files = array(); $is_enabled_image = conf('image.isEnabled', 'news'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $is_modal_upload_image = conf('image.isModalUpload', 'news'); if ($is_enabled_image && !$is_modal_upload_image) { $news_images = \News\Model_NewsImage::get4news_id($news->id); $images = \Site_Upload::get_file_objects($news_images, $news->id, true, null, 'img', $is_insert_body_image); } if ($is_enabled_file = \Config::get('news.file.isEnabled')) { $news_files = \News\Model_NewsFile::get4news_id($news->id); $files = \Site_Upload::get_file_objects($news_files, $news->id, true, null, 'file'); } $posted_links = array(); $saved_links = array(); if ($is_enabled_link = \Config::get('news.link.isEnabled')) { $saved_links = $this->get_saved_links($news->id); } $tags = \Config::get('news.tags.isEnabled') ? \News\Model_NewsTag::get_names4news_id($news->id) : array(); $image_tmps = array(); $file_tmps = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); if ($is_enabled_link) { $posted_links = $this->get_posted_links(); $val = $this->add_validation_object_posted_links($val, $saved_links, true); $val = $this->add_validation_object_posted_links($val, $posted_links); } $moved_images = array(); $moved_files = array(); $news_image_ids = array(); $news_file_ids = array(); $error_message = ''; try { if ($is_enabled_image) { $image_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize(); } if ($is_enabled_file) { $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize(null, null, 'file'); } // 識別名の変更がない場合は unique を確認しない if (trim(\Input::post('slug')) == $news->slug) { $val->fieldset()->field('slug')->delete_rule('unique'); } if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); if ($post['format'] == 2) { $post['body'] = preg_replace('/^\\>/um', '>', $post['body']); } $news->set_values($post); $message = sprintf('%sを%sしました。', term('news.view'), term('form.edit')); if ($is_published = !$news->is_published && empty($post['is_draft'])) { $news->is_published = 1; $message = sprintf('%sを%sしました。', term('news.view'), term('form.publish')); } if ($post['published_at_time'] && !\Util_Date::check_is_same_minute($post['published_at_time'], $news->published_at)) { $news->published_at = $post['published_at_time'] . ':00'; } elseif ($is_published) { $news->published_at = date('Y-m-d H:i:s'); } \DB::start_transaction(); $news->save(); if ($is_enabled_image) { list($moved_images, $news_image_ids) = \Site_FileTmp::save_images($image_tmps, $news->id, 'news_id', 'news_image'); \Site_Upload::update_image_objs4file_objects($news_images, $images); } if ($is_enabled_file) { list($moved_files, $news_file_ids) = \Site_FileTmp::save_images($file_tmps, $news->id, 'news_id', 'news_file', null, 'file'); \Site_Upload::update_image_objs4file_objects($news_files, $files); } if ($is_enabled_link) { $this->save_posted_links($saved_links, $news->id, true); $this->save_posted_links($posted_links, $news->id); } if (\Config::get('news.tags.isEnabled')) { \News\Model_NewsTag::save_tags($post['tags'], $news->id); } //// timeline 投稿 //if (is_enabled('timeline')) //{ // if ($is_published) // { // \Timeline\Site_Model::save_timeline($this->u->id, $note->public_flag, 'note', $note->id); // } // elseif ($is_update_public_flag) // { // // timeline の public_flag の更新 // \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($note->public_flag, 'note', $note->id, \Config::get('timeline.types.note')); // } //} \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_images); \Session::set_flash('message', $message); \Response::redirect('admin/news/detail/' . $news->id); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_images) { \Site_FileTmp::move_files_to_tmp_dir($moved_images); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } $image_tmps = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id, true, 'img'); $file_tmps = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id, true, 'file'); \Session::set_flash('error', $error_message); } } $images = array_merge($images, $image_tmps); $files = array_merge($files, $file_tmps); $this->set_title_and_breadcrumbs(term('form.edit'), array('admin/news' => term('news.view', 'admin.view'), 'admin/news/' . $news->id => $news->title)); $this->template->post_header = \View::forge('news/_parts/form_header'); $this->template->post_footer = \View::forge('news/_parts/form_footer', array('news' => $news)); $this->template->content = \View::forge('news/_parts/form', array('val' => $val, 'saved_links' => $saved_links, 'posted_links' => $posted_links, 'news' => $news, 'is_edit' => true, 'images' => $images, 'files' => $files, 'tags' => $tags)); }
/** * Execute confirm signup * * @access public * @return Response */ public function action_confirm_signup() { Util_security::check_method('POST'); Util_security::check_csrf(); if (!($form = Fieldset::instance('confirm_signup'))) { $form = $this->get_form_signup_confirm(); } $val = $form->validation(); $val->fieldset()->field('email')->delete_rule('unique'); $redirect_uri = conf('login_uri.site'); $success_message = '仮登録が完了しました。受信したメール内に記載された URL より本登録を完了してください。'; $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); if (Model_MemberAuth::get4email($post['email'])) { if (conf('member.register.email.hideUniqueCheck')) { Session::set_flash('message', $success_message); Response::redirect($redirect_uri); } throw new FuelException('その' . term('site.email') . 'は登録できません。'); } DB::start_transaction(); $token = Model_MemberPre::save_with_token($post['email'], $post['password']); DB::commit_transaction(); $mail = new Site_Mail('memberSignup'); $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token))); Session::set_flash('message', $success_message); Response::redirect($redirect_uri); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); $this->action_signup(); }
protected function controller_common_api(callable $func) { try { $this->check_response_format($this->api_accept_formats); if (Input::method() != 'GET' && !$this->api_not_check_csrf) { Util_security::check_csrf(); } $this->response_body = $func() ?: $this->response_body; // execute main. if (Site_Model::check_is_orm_obj($this->response_body)) { throw new \FuelException('Response body not allowed Orm obj.'); } $status_code = 200; } catch (\HttpNotFoundException $e) { $status_code = 404; } catch (\ApiNotAuthorizedException $e) { $status_code = 401; } catch (\HttpForbiddenException $e) { $status_code = 403; } catch (\HttpMethodNotAllowed $e) { $status_code = 405; } catch (\HttpBadRequestException $e) { $status_code = 400; } catch (\HttpInvalidInputException $e) { $status_code = 400; } catch (\ValidationFailedException $e) { $this->response_body['errors']['message'] = Site_Controller::get_error_message($e); $status_code = 400; } catch (\DisableToUpdateException $e) { $this->response_body['errors']['message'] = $e->getMessage() ?: term('form.update') . 'が禁止されています。'; $status_code = 400; } catch (\Database_Exception $e) { $this->response_body['errors']['message'] = Site_Controller::get_error_message($e, true); $status_code = 500; } catch (\FuelException $e) { $status_code = 500; } catch (\Exception $e) { $status_code = 500; } if ($status_code == 500) { if (!empty($e)) { Util_Toolkit::log_error($e->getMessage()); } if (\DB::in_transaction()) { \DB::rollback_transaction(); } } $response_body = Site_Controller::supply_response_body($this->response_body, $status_code, $this->format); return self::response($response_body, $status_code); }
/** * Execute reset password. * * @access public * @return Response */ public function action_reset_password() { // Already logged in Auth::check() and Response::redirect('member'); $member_password_pre = Model_MemberPasswordPre::get4token(Input::param('token')); if (!$member_password_pre || !Site_Util::check_token_lifetime($member_password_pre->updated_at, conf('member.recover.password.token_lifetime'))) { Session::set_flash('error', sprintf('URLが%sです。', term('form.disabled'))); throw new HttpNotFoundException(); } $form = $this->form_reset_password(); $val = $form->validation(); if (Input::method() == 'POST') { Util_security::check_csrf(); $auth = Auth::instance(); $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new FuelException($val->show_errors() ?: term('site.password') . 'が正しくありません'); } $post = $val->validated(); $to_email = $member_password_pre->email; $to_name = $member_password_pre->member->name; DB::start_transaction(); $auth->change_password_simple($member_password_pre->member_id, $post['password']); $member_password_pre->delete(); // 仮登録情報の削除 DB::commit_transaction(); $mail = new Site_Mail('memberResetPassword'); $mail->send($to_email, array('to_name' => $to_name)); $auth->login($to_email, $post['password']); Session::set_flash('message', term('site.password') . 'を登録しました。'); Response::redirect('member'); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('site.password') . 'の登録に失敗しました。'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } } $this->set_title_and_breadcrumbs(term('site.password') . 'の再登録'); $data = array('val' => $val, 'member_password_pre' => $member_password_pre); $this->template->content = View::forge('member/recover/reset_password', $data); $this->template->content->set_safe('html_form', $form->build('member/recover/reset_password')); // form の action に入る }
/** * Mmeber_Profile_Image delete * * @access public * @return Response */ public function action_delete($album_image_id = null) { try { Util_security::check_csrf(); if (!conf('upload.types.img.types.m.save_as_album_image')) { throw new HttpNotFoundException(); } $album_image = \Album\Model_AlbumImage::check_authority($album_image_id, $this->u->id); if ($album_image->album->foreign_table != 'member') { throw new FuelException('Disabled to set album image as profile image.'); } DB::start_transaction(); $album_image->delete(); DB::commit_transaction(); Session::set_flash('message', term('profile', 'site.picture') . 'を削除しました。'); } catch (Database_Exception $e) { if (DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', Site_Controller::get_error_message($e, true)); } catch (FuelException $e) { if (DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $e->getMessage()); } Response::redirect('member/profile/image'); }
/** * Reset action. * * @access public * @params integer * @return Response */ public function action_reset($db_key = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); if (!($template = \Model_Template::get4name($db_key))) { throw new \HttpNotFoundException(); } $error_message = ''; try { \DB::start_transaction(); $template->delete(); \DB::commit_transaction(); \Session::set_flash('message', 'デフォルトに戻しました。'); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); } \Response::redirect('admin/content/template/mail'); }
/** * Execute register email. * * @access public * @return Response */ public function action_register($mode = null) { Util_security::check_method('POST'); Util_security::check_csrf(); list($mode, $is_registerd, $is_regist_mode, $action_name, $is_oauth_registerd_user) = $this->get_common_vals($mode); $this->set_validation_email($is_oauth_registerd_user); $this->set_validation_code(); $error_message = ''; $is_transaction_rollback = false; try { if (!$this->val_obj->run()) { throw new ValidationFailedException($this->val_obj->show_errors()); } $post = $this->val_obj->validated(); if (!$is_oauth_registerd_user && !$this->auth_instance->check_password()) { throw new ValidationFailedException(term('site.password') . 'が正しくありません'); } $member_email_pre = Model_MemberEmailPre::get4member_id($this->u->id); $code_error_message = sprintf('%sが正しくないか、%sが過ぎてます。再度%sを%sしてください。', term('form.confirm', 'site.code'), term('form.enabled', 'common.timelimit'), term('form.for_confirm', 'site.mail'), term('form.send')); $this->check_email_registered($member_email_pre ? $member_email_pre->email : $post['email'], $mode, $code_error_message, true); if (!$member_email_pre || !self::check_confirmation_code($member_email_pre, $post['code'])) { throw new ValidationFailedException($code_error_message); } $email = $member_email_pre->email; $values = array('email' => $email); if (!$is_oauth_registerd_user) { $values['password'] = $post['password']; $values['old_password'] = $post['password']; } DB::start_transaction(); if (!$this->auth_instance->update_user($values, $this->u->id)) { throw new FuelException('Change email error.'); } $member_email_pre->delete(); // 仮登録情報の削除 DB::commit_transaction(); $this->set_current_user(); $mail = new Site_Mail('memberRegisterEmailConfirm'); $mail->send($email, array('to_name' => $this->u->name)); Session::set_flash('message', sprintf('%sを%sしました。', term('site.email'), $action_name)); Response::redirect('member/setting'); } catch (ValidationFailedException $e) { $error_message = $e->getMessage(); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('site.email') . 'の変更に失敗しました。'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; if (!($error_message = $e->getMessage())) { $error_message = sprintf('%sの%sに失敗しました。', term('site.email'), $action_name); } } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } $this->action_register_confirm($mode); }
/** * Thread edit * * @access public * @params integer * @return Response */ public function action_edit($id = null) { $thread = Model_Thread::check_authority($id, $this->u->id); $val = self::get_validation_object($thread, true); $thread_images = \Thread\Model_ThreadImage::get4thread_id($thread->id); $images = \Site_Upload::get_file_objects($thread_images, $thread->id); $image_tmps = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $moved_images = array(); $news_image_ids = array(); $error_message = ''; try { $image_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); $thread->save_with_relations($this->u->id, $post); list($moved_images, $thread_image_ids) = \Site_FileTmp::save_images($image_tmps, $thread->id, 'thread_id', 'thread_image'); \Site_Upload::update_image_objs4file_objects($thread_images, $images); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_images); $message = sprintf('%sを%sしました。', term('thread'), term('form.edit')); \Session::set_flash('message', $message); \Response::redirect('thread/detail/' . $thread->id); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_images) { \Site_FileTmp::move_files_to_tmp_dir($moved_images); } $image_tmps = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id); \Session::set_flash('error', $error_message); } } $images = array_merge($images, $image_tmps); $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('thread'), term('form.do_edit')), array('/thread/' . $id => $thread->title), null, 'thread'); $this->template->post_header = \View::forge('_parts/form_header'); $this->template->post_footer = \View::forge('_parts/form_footer'); $this->template->content = \View::forge('_parts/form', array('val' => $val, 'thread' => $thread, 'is_edit' => true, 'images' => $images)); }