/** * Mmeber_profile edit * * @access public * @return Response */ public function action_edit($type = null) { list($type, $is_regist) = self::validate_type($type, $this->u->id); $form_member_profile = new Form_MemberProfile($type == 'regist' ? 'regist-config' : 'config', $this->u); $form_member_profile->set_validation(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); try { $form_member_profile->validate(true); \DB::start_transaction(); $form_member_profile->seve(); if ($is_regist) { Model_MemberConfig::delete_value($this->u->id, 'terms_un_agreement'); } \DB::commit_transaction(); $message = $is_regist ? sprintf('%sが%sしました。', term('site.registration'), term('form.complete')) : term('profile') . 'を編集しました。'; $redirect_uri = $is_regist ? $this->after_auth_uri : 'member/profile'; \Session::set_flash('message', $message); \Response::redirect($redirect_uri); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs(term('profile') . term($is_regist ? 'site.registration' : 'form.edit'), $is_regist ? array() : array('member/profile' => term('common.my', 'profile')), $is_regist ? null : $this->u); $this->template->content = View::forge('member/profile/edit', array('is_regist' => $is_regist, 'val' => $form_member_profile->get_validation(), 'member_public_flags' => $form_member_profile->get_member_public_flags(), 'profiles' => $form_member_profile->get_profiles(), 'member_profile_public_flags' => $form_member_profile->get_member_profile_public_flags())); }
/** * Mmeber setting timeline_view * * @access public * @return Response */ public function action_viewtype() { $page_name = term('timeline', 'site.view', 'site.setting'); $val = \Form_MemberConfig::get_validation($this->u->id, 'timeline_viewType'); if (Input::method() == 'POST') { Util_security::check_csrf(); try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); \Form_MemberConfig::save($this->u->id, $val, $post); \DB::commit_transaction(); \Session::set_flash('message', $page_name . 'を変更しました。'); \Response::redirect('member/setting'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u); $this->template->content = \View::forge('member/setting/timeline_viewtype', array('val' => $val)); }
public function action_regist() { try { DB::start_transaction(); //$this->checkCsrf(); // バリデーションチェック $val = Validation::forge(); $val->add("hospital_id", "病院ID")->add_rule("required"); $val->add("nickname", "清潔感")->add_rule("required"); $val->add("message", "内容")->add_rule("required"); $param = $this->validate($val); $hospitalId = $param["hospital_id"]; // 登録 $review = Model_Db_Thospitalreview::forge(); $review->t_hospital_review_hospital_id = $hospitalId; $review->t_hospital_review_nickname = $param["nickname"]; $review->t_hospital_review_message = $param["message"]; $review->t_hospital_review_status = ReviewStatus::CLOSED; $review->t_hospital_review_created_at = System::now(); if ($review->save() == 0) { throw new Exception("病院評価登録に失敗しました"); } DB::query("refresh materialized view v_hospital_review")->execute(); Cookie::set("review_" . $hospitalId, $hospitalId, Config::get("site.expire.review")); $this->response(); DB::commit_transaction(); } catch (Exception $e) { DB::rollback_transaction(); $this->error($e); } }
/** * Mmeber setting viewtype * * @access public * @return Response */ public function action_index() { $page_name = term('notice', 'site.setting'); $val = \Form_MemberConfig::get_validation($this->u->id, 'notice', 'Notice'); if (\Input::method() == 'POST') { \Util_security::check_csrf(); try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); \Form_MemberConfig::save($this->u->id, $val, $post); \DB::commit_transaction(); \Session::set_flash('message', $page_name . 'を変更しました。'); \Response::redirect('member/setting'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u); $this->template->content = \View::forge('member/setting/_parts/form', array('val' => $val, 'label_size' => 5, 'form_params' => array('common' => array('radio' => array('layout_type' => 'grid'))))); }
/** * * @param type $count * @throws Exception */ public function run($type = "") { $tran = array("address" => false); $tran = @$tran[$type]; if (is_null($tran)) { Log::error("{$type} migration nothing"); return; } if ($tran) { DB::start_transaction(); } try { $this->{$type}(); DB::query("refresh materialized view v_hospital")->execute(); DB::query("refresh materialized view v_hospital_access_time_from_station")->execute(); DB::query("refresh materialized view v_hospital_evaluate")->execute(); DB::query("refresh materialized view v_hospital_access")->execute(); DB::query("refresh materialized view v_hospital_review")->execute(); if ($tran) { DB::commit_transaction(); } Log::error("{$type} migration finish"); } catch (Exception $e) { if ($tran) { DB::rollback_transaction(); } Logger::error($e); throw $e; } }
/** * add_relation * @return type */ public static function add_relation() { try { if (!self::validation_add_relation()) { return self::error(); } # lat&lng -> geohash $geohash = Util_Geohash::encode(Input::post('lat'), Input::post('lng')); # transaction DB::start_transaction(); # shop_id指定 if (is_null(Input::post('shop_id'))) { # new shop $shop_id = Model_Shop::add(Input::post('shop_name')); } else { $data = Model_Shop::get_by_pk("shop", Input::post('shop_id')); if (!$data) { throw new Exception('shop_id ' . Input::post('shop_id') . " is not exsits."); } $shop_id = $data['shop_id']; } # new shop geo add if (is_null(Input::post('shop_id'))) { if (!self::add($shop_id, Input::post('lat'), Input::post('lng'), $geohash)) { throw new Exception("insert geo fail."); } } # fileupload & setting self::$file_name = self::file_upload($shop_id); self::$file_path = self::UPLOAD_DIR . Input::post('shop_id') . DS . self::$file_name; if (!self::$file_name) { throw new Exception('file upload fail.'); } # image resize # todo # image add if (!Model_Image::add($shop_id, Input::post('user_id'), self::$file_name)) { throw new Exception("insert image fail."); } # commit DB::commit_transaction(); # success $data = ['status' => CREATED]; } catch (Exception $ex) { # 画像ファイルが存在すれば削除 if (is_file(self::$file_path)) { unlink(self::$file_path); } # rollback DB::rollback_transaction(); $data = ['status' => DATABASE_ERROR, 'message' => '[database error]insert table fail.']; Log::error($ex); } return $data; }
/** * ユーザー情報の登録処理 * * @param array $userInfo ユーザー情報 */ public function addClient($userInfo) { try { DB::start_transaction(); // OpenIDとユーザー情報紐付く処理 DB::commit_transaction(); } catch (Exception $ex) { DB::rollback_transaction(); return NULL; } }
/** * clean queues * */ public function clean() { try { \DB::start_transaction(); $query = \DB::delete('task_queues')->where('job_status', \Model_TaskQueue::STATUS_SUCCESS)->where('updated_at', '<=', date('Y-m-d', strtotime(\Config::get('queue.success_queue_delete_term')))); $query->execute(); \DB::commit_transaction(); } catch (\Exception $e) { \DB::rollback_transaction(); } }
public static function run() { try { $users = \DB::select_array(['id', 'username'])->from('users')->execute(); \DB::start_transaction(); foreach ($users as $user) { \DB::update('auctions')->value('won_user', $user['id'])->where('won_user', '=', $user['username'])->execute(); } \DB::commit_transaction(); \DBUtil::modify_fields('auctions', ['won_user' => ['constraint' => 11, 'type' => 'int', 'name' => 'user_id']]); } catch (Exception $e) { \DB::rollback_transaction(); } }
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))); }
public function action_upload($folder, $sub = null) { if (\Fuel\Core\Input::method() == 'POST') { try { \Fuel\Core\DB::start_transaction(); $val = Model_Filemanager::validate('create'); if ($val->run()) { $config = array('path' => "/var/www/html/" . $this->_dir . "/" . $folder . "/" . $sub . DS, 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true); Upload::process($config); $img = ''; if (Upload::is_valid()) { Upload::save(); $img = Upload::get_files()[0]; } if (!\Fuel\Core\Input::post('id')) { $file = Model_Filemanager::forge(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img['saved_as'], 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source'))); } else { $file = Model_Filemanager::find_by_id(\Fuel\Core\Input::post('id')); if ($img == '') { $img = $file->value; } if ($file) { $file->set(array('folder' => $folder, 'key' => Input::post('key'), 'value' => $img, 'photographer' => \Fuel\Core\Input::post('photographer'), 'price' => \Fuel\Core\Input::post('price'), 'usage' => \Fuel\Core\Input::post('usage'), 'source' => \Fuel\Core\Input::post('source'))); } else { throw new Exception('File not found!'); } } if ($file and $file->save()) { DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Upload success'); } else { throw new Exception('Cannot save into database!'); } } else { throw new Exception($val->show_errors()); } } catch (Exception $e) { DB::rollback_transaction(); \Fuel\Core\Session::set_flash('error', $e->getMessage()); } } \Fuel\Core\Response::redirect(\Fuel\Core\Uri::create('filemanager/folder/' . $folder)); }
public function action_index() { if (Input::method() == 'POST') { $val = \Model_Ship::validate('default'); $values['sell_id'] = \Input::post('sell_id'); if ($val->run($values)) { $ship = \Model_Ship::forge(); $parts = Model_Part::find('all', ['where' => ['status' => \Config::get('my.status.ship.id')]]); try { \DB::start_transaction(); $ship->shipAuctionID = $val->validated('sell_id'); $ship->partStatus = 4; if (!$ship->save()) { throw new Exception("Could not create ship", 1); } foreach ($parts as $p) { $p->status = \Config::get('my.status.shipped.id'); $p->ship_number = $ship->shipNumber; if (!$p->save()) { throw new Exception("Could not save part ID:" . $p->id, 1); } } \DB::commit_transaction(); Session::set_flash('alert', ['status' => 'success', 'message' => 'Ship was successfully created']); } catch (\Exception $e) { DB::rollback_transaction(); Session::set_flash('alert', ['status' => 'danger', 'message' => $e->getMessage()]); } } else { Session::set_flash('alert', ['status' => 'danger', 'message' => 'Check sell ID']); } } $data['items'] = Model_Part::find('all', ['where' => ['status' => \Config::get('my.status.ship.id')], 'related' => ['auctions' => ['related' => ['vendor']]]]); $ship_count = DB::select(DB::expr('SUM(item_count) as count'))->from('auctions')->join('parts', 'LEFT')->on('parts.id', '=', 'auctions.part_id')->where('status', Config::get('my.status.ship.id'))->execute()->as_array(); $data['ship_count'] = $ship_count[0]['count']; $this->template->title = "Ship"; $this->template->content = View::forge('admin/list', $data); }
/** * キューの取得、実行中への更新 * * @param array $exclude_type 除外するduplicate_type * @return array queue info * @throw OutOfRangeException */ public static function pickup($exclude_type = array()) { \DB::start_transaction(); $query = \DB::select('*')->from('task_queues')->where('job_status', static::STATUS_WAIT)->where('deleted', \Config::get('queue.logical_delete.not_deleted'))->limit(1)->order_by('priority', 'ASC')->order_by('id', 'ASC'); if (!empty($exclude_type)) { $query->where('duplicate_type', 'NOT IN', $exclude_type); } $compiled = $query->compile(); $query = \DB::query($compiled . ' FOR UPDATE'); $result = $query->execute()->as_array(); if (empty($result)) { \DB::rollback_transaction(); return array(); } // control limit if ($result[0]['duplicate_type'] != static::DUPLICATE_TYPE_NONE) { $task_queue_limit = \Config::get('queue.duplicate_type'); if (!isset($task_queue_limit[intval($result[0]['duplicate_type'])])) { throw new \OutOfRangeException('taks_queues.duplicate_type: ' . $result[0]['duplicate_type'] . ' is not defined.'); } $limit = $task_queue_limit[intval($result[0]['duplicate_type'])]; $count = \DB::select(\DB::expr('COUNT(*) as cnt'))->from('task_queues')->where('job_status', static::STATUS_EXEC)->where('duplicate_type', $result[0]['duplicate_type'])->where('deleted', \Config::get('queue.logical_delete.not_deleted'))->execute()->as_array(); if ($count[0]['cnt'] >= $limit) { \DB::rollback_transaction(); // add exclude_type and retry pickup $exclude_type[] = $result[0]['duplicate_type']; return self::pickup($exclude_type); } } // update job_status $TaskQueue = static::find($result[0]['id']); $TaskQueue->job_status = static::STATUS_EXEC; $TaskQueue->save(); \DB::commit_transaction(); return $result[0]; }
/** * Save art-ids and cat-ids * * @params int $id art-id * @params array $cat cat.-ids * @params boolean $edit edit/add * * @return void * * @version 1.0 * @since 1.0 * @access public * @author Nguyen Van hiep */ public static function save_art_cat($art_id, $cats, $edit = false) { $cat_order = array(); if ($edit) { // Get list of current order $cat_order = DB::select()->from('art_cat')->where('art_id', $art_id)->execute()->as_array('cat_id', 'order'); DB::delete('art_cat')->where('art_id', $art_id)->execute(); } try { DB::start_transaction(); // Add new shift-role relations $query = DB::insert('art_cat')->columns(array('art_id', 'cat_id', 'order')); foreach ($cats as $cat_id) { $order = !empty($cat_order[$cat_id]) ? $cat_order[$cat_id] : 0; $query->values(array($art_id, $cat_id, $order)); } $query->execute(); DB::commit_transaction(); return true; } catch (Exception $e) { DB::rollback_transaction(); return false; } }
/** * 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); }
/** * Admin account delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); if (check_original_user($id, true)) { throw new \HttpForbiddenException(); } $user = Model_AdminUser::check_authority($id); try { $auth = \Auth::instance(); \DB::start_transaction(); $auth->delete_user($user->username); \DB::commit_transaction(); \Session::set_flash('message', term('admin.user.view') . 'を削除しました。'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } \Response::redirect(\Site_Util::get_redirect_uri('admin/account')); }
/** * 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')); }
/** * * @param type $count * @throws Exception */ public function run($count = 0, $init = false) { if ($init) { DB::start_transaction(); try { // テーブル初期化(テーブル名 => 自動採番) $tables = array("m_hospital" => true, "m_hospital_comment" => false, "m_hospital_director" => false, "m_hospital_image" => false, "m_hospital_access" => true, "m_hospital_timetable" => false, "t_hospital_review" => true, "t_hospital_evaluate" => true, "t_hospital_course_relation" => false, "t_hospital_features_relation" => false); foreach ($tables as $t => $serial) { DB::delete($t)->execute(); if ($serial) { DB::select("setval('{$t}_{$t}_id_seq', 1, false)")->execute(); } } DB::commit_transaction(); } catch (Exception $e) { DB::rollback_transaction(); Logger::error($e); throw $e; } } // ダミーデータ登録 for ($i = 0; $i < $count; $i++) { $type = HospitalType::TPEC; $entries = array(); $sum = array_sum($entries); $rand = rand(1, $sum); foreach ($entries as $key => $weight) { if (($sum -= $weight) < $rand) { $type = $key; } } DB::start_transaction(); try { Log::info($i + 1); $hospitalId = $this->registHsopital(rand(1, 3)); $this->registComment($hospitalId); $this->registDirector($hospitalId); $this->registFeatures($hospitalId); $this->registImage($hospitalId); $this->registTimetable($hospitalId); $this->registAccess($hospitalId); $this->registCourse($hospitalId); $this->registReview($hospitalId); $this->registEvaluate($hospitalId); DB::commit_transaction(); } catch (Exception $e) { DB::rollback_transaction(); Logger::error($e); throw $e; } } DB::start_transaction(); try { // ビューをリフレッシュ DB::query("refresh materialized view v_hospital")->execute(); DB::query("refresh materialized view v_hospital_access_time_from_station")->execute(); DB::query("refresh materialized view v_hospital_evaluate")->execute(); DB::query("refresh materialized view v_hospital_access")->execute(); DB::query("refresh materialized view v_hospital_review")->execute(); DB::commit_transaction(); } catch (Exception $e) { DB::rollback_transaction(); Logger::error($e); throw $e; } }
/** * Update cat. background to database * * @param integer $id cat. id * @param string $img cat. background-img * @param string $old old background * @return boolean * * @access public * @since 1.0 * @version 1.0 * @author Nguyen Van Hiep * @author Dao Anh Minh */ public static function save_bg($id, $img, $old = false) { try { if (!empty($old) and \Fuel\Core\File::exists(DOCROOT . 'assets/img/cat/' . $old)) { File::delete(DOCROOT . 'assets/img/cat/' . $old); } DB::update('cat')->value('bg', $img)->where('id', $id)->execute(); File::delete(DOCROOT . 'assets/img/cat/temp/' . $img); DB::commit_transaction(); return true; } catch (Exception $e) { DB::rollback_transaction(); return false; } }
public function action_entry() { // 登録時 if (Input::method() == 'POST') { // バリデーション $val = Model_Twitteruser::validate('create'); $input = array('uid' => Session::get('uid'), 'token' => Session::get('token'), 'secret' => Session::get('secret')); if ($val->run($input)) { // バリデーション成功時 $user = Model_User::forge(array('name' => Session::get('nickname'), 'password' => substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyz'), 0, 10), 'sex' => Input::post('sex'), 'birth_station_id' => Input::post('birth_station_id'))); $twitter_user = Model_TwitterUser::forge($input); if ($user and $twitter_user) { // ユーザー生成成功 try { \DB::start_transaction(); if ($user->save() === false) { // User保存失敗 throw new \Exception('user save failed.'); } $twitter_user->user_id = $user->id; if ($twitter_user->save() === false) { // TwitterUser保存失敗 throw new \Exception('twitter_user save failed.'); } //その他Userに付随する情報を作成 //user_state $state = Model_Userstate::forge(array('id' => $user->id, 'ride_state' => '0', 'now_station_id' => $user->birth_station_id)); if ($state->save() === false) { // user_state保存失敗 throw new \Exception('user_state save failed.'); } //user_fortune //ポイントは動的にできるように。。。 $fortune = Model_Userfortune::forge(array('id' => $user->id, 'points' => 10000, 'domination1' => ' ', 'domination2' => ' ', 'domination3' => ' ')); if ($fortune->save() == false) { // user_state保存失敗 throw new \Exception('user_fortune save failed.'); } // 保存成功 \DB::commit_transaction(); //サインアップ成功なのでいらないSessionは消す Session::delete('uid'); Session::delete('token'); Session::delete('secret'); Session::delete('nickname'); Model_User::login_twitter($user->id); Response::redirect('portal'); } catch (\Exception $e) { \DB::rollback_transaction(); Response::redirect('portal'); } } else { // ユーザー生成失敗 Response::redirect('portal'); } } else { // バリデーション失敗時 Response::redirect('portal'); } // 登録できたら ポータルに戻る. } // Viewに受け渡す用 $exp = ['name' => Session::get('nickname'), 'stations' => Model_Traininfo::get_birth_train_summary()]; $this->template->title = '新規アカウント登録'; $this->template->content = View_Twig::forge('portal/entry', $exp); }
/** * @author NamNT * action index */ public function action_index() { $data = array(); $model = new \Model_Personfile(); $person_id = \Input::get('person_id'); if (!$person_id) { Response::redirect('job/persons'); } $img = $model->get_data_detail($person_id); $data_img = array(); $k = 1; foreach ($img as $keys => $vals) { if (isset($vals['0'])) { $data_img[$k] = $vals['0']; $data_img[$k]['content'] = base64_encode($data_img[$k]['content']); } else { $data_img[$k]['content'] = null; $data_img[$k]['attr_id'] = $k; } ++$k; } $data['img'] = $data_img; $data['person_id'] = $person_id; if (\Input::method() == 'POST') { $datas = array(); $data_post = \Input::post(); if (isset($data_post['content'])) { $check = true; \DB::start_transaction(); $res = $model->delete_data($person_id); if ($res >= 0) { for ($i = 1; $i < 6; ++$i) { $data['content'] = isset($data_post['content'][$i]) ? base64_decode($data_post['content'][$i]) : null; $data['attr_id'] = $i; $data['person_id'] = $person_id; $data['created_at'] = date('Y-m-d H:i:s'); $data['updated_at'] = date('Y-m-d H:i:s'); $model = \Model_Personfile::forge(); $model->set($data); if (!$model->save()) { $check = false; break; } } } if ($res >= 0 && $check) { \DB::commit_transaction(); Session::set_flash('success', \Constants::$message_create_success); } else { \DB::rollback_transaction(); Session::set_flash('success', \Constants::$message_create_error); } Response::redirect('job/personfile?person_id=' . $person_id); } else { $res = $model->delete_data($person_id); if ($res >= 0) { Session::set_flash('success', \Constants::$message_create_success); } else { Session::set_flash('success', \Constants::$message_create_error); } Response::redirect('job/personfile?person_id=' . $person_id); } } $this->template->title = 'UOS求人システム'; $this->template->content = \View::forge('personfile/index', $data); }
/** * Admin change email. * * @access public * @return Response */ public function action_change_email() { \Util_security::check_method('POST'); \Util_security::check_csrf(); $form = $this->form_setting_email(); $val = $form->validation(); if ($val->run()) { try { $post = $val->validated(); $email = $post['email']; \DB::start_transaction(); if (!$this->auth_instance->update_user(array('email' => $email))) { throw new \FuelException('change email error.'); } \DB::commit_transaction(); $maildata = array(); $maildata['from_name'] = conf('mail.admin.from_name'); $maildata['from_address'] = conf('mail.admin.from_email'); $maildata['subject'] = term('site.email', 'form.update', 'form.complete') . 'の' . term('site.notice'); $maildata['to_address'] = $email; $maildata['to_name'] = $this->u->username; $this->send_change_email_mail($maildata); \Session::set_flash('message', term('site.email') . 'を変更しました。'); \Response::redirect('admin/setting'); } catch (\EmailValidationFailedException $e) { $this->display_error(term('member.view') . '登録: 送信エラー', __METHOD__ . ' email validation error: ' . $e->getMessage()); return; } catch (\EmailSendingFailedException $e) { $this->display_error(term('member.view') . '登録: 送信エラー', __METHOD__ . ' email sending error: ' . $e->getMessage()); return; } catch (\Auth\SimpleUserUpdateException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', sprintf('その%sは登録できません。', term('site.email'))); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', term('site.email') . 'の変更に失敗しました。'); } } else { \Session::set_flash('error', $val->show_errors()); } $this->action_email(); }
public function update_csv($file) { $data = $this->get_file_csv($file); //array_shift($data); if (!count($data)) { return false; } $model_job = new Model_Job(); $model_add = new Model_Jobadd(); $model_rec = new Model_Jobrecruit(); $k = 1; \DB::start_transaction(); $check = true; $no_update = array(); try { foreach ($data as $row) { if (!$check) { break; } $data = self::data_once_csv($row); $validate_field = $this->validate($data['job'], $data['job_add'], $data['job_rec'], $k); $res = $model_job->update_data_csv($data['job'], $data['job']['job_id'], $validate_field, $no_update, $k); if ($res === -1) { $this->error[$k]['job_id'] = $k . '行目:求人情報が存在していません。'; $check = false; } else { if ($res && $validate_field) { $res_delete_add = $model_add->delete_data($data['job']['job_id']); if ($res_delete_add >= 0) { if (count($data['job_add']) && !$model_add->insert_multi_data($data['job_add'], $model_job)) { $check = false; } } $res_delete_rec = $model_rec->delete_data($data['job']['job_id']); if ($res_delete_rec >= 0) { if (count($data['job_rec']) && !$model_rec->insert_multi_data($data['job_rec'], $model_job)) { $check = false; } } } else { $check = false; } } ++$k; } if (!$check) { \DB::rollback_transaction(); } else { \DB::commit_transaction(); } } catch (Exception $e) { // rollback pending transactional queries \DB::rollback_transaction(); throw $e; } $this->no_update = $no_update; return $check; }
/** * Create timeline * * @access public * @param int $parent_id target parent id * @return Response(json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_create() { $this->controller_common_api(function () { $this->response_body['errors']['message_default'] = term('timeline') . 'の' . term('form.post') . 'に失敗しました。'; $moved_files = array(); $album_image_ids = array(); $timeline = Model_Timeline::forge(); $val = \Validation::forge(); $val->add_model($timeline); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!strlen($post['body']) && !$file_tmps) { throw new \ValidationFailedException('Data is empty.'); } $type_key = 'normal'; $album_id = (int) \Input::post('album_id', 0); if ($file_tmps && $album_id) { $album = \Album\Model_Album::check_authority($album_id, $this->u->id); if (\Album\Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \ValidationFailedException('Album id is invalid.'); } $type_key = 'album_image'; } try { \DB::start_transaction(); if ($file_tmps) { if (!$album_id) { $type_key = 'album_image_timeline'; $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'timeline'); } list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $post['public_flag']); } else { $album_id = null; } $timeline = \Timeline\Site_Model::save_timeline($this->u->id, $post['public_flag'], $type_key, $album_id, null, $post['body'], $timeline, $album_image_ids); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files); } catch (\Exception $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } throw $e; } $data = array('id' => $timeline->id, 'message' => term('timeline') . 'を' . term('form.post') . 'しました。'); if (conf('service.facebook.shareDialog.myhome.autoPopupAfterCreated')) { $link = \Uri::create(Site_Util::get_detail_uri($timeline->id, $timeline->type)); $data['shareFacebook'] = array('obj' => array('link' => $link)); if ($album_image_ids && ($album_image = \Album\Model_AlbumImage::find($album_image_ids[0]))) { $data['shareFacebook']['obj']['picture'] = \Site_Util::get_media_uri(img_uri($album_image->file_name, 'thumbnail'), true); } } $this->set_response_body_api($data); }); }
/** * Update article orders to database * * @param integer $cat_id cat id * @param integer $article_id article id * @param integer $order article order * @return boolean * * @access public * @since 1.0 * @version 1.0 * @author Dao Anh Minh */ public static function update_order($cat_id, $art_id, $order) { try { DB::update('art_cat')->value('order', $order)->where('cat_id', '=', $cat_id)->where('art_id', '=', $art_id)->execute(); DB::commit_transaction(); return true; } catch (Exception $e) { DB::rollback_transaction(); return false; } }
/** * 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')); }
/** * Note publish * * @access public * @params integer * @return Response */ public function action_publish($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); $note = Model_Note::check_authority($id, $this->u->id); if ($note->is_published) { \Session::set_flash('error', '既に公開されています。'); \Response::redirect('note/detail/' . $id); } try { \DB::start_transaction(); list($is_changed, $is_published) = $note->save_with_relations($this->u->id, array('is_published' => 1)); \DB::commit_transaction(); \Session::set_flash('message', term('note') . 'を公開しました。'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } \Response::redirect('note/detail/' . $id); }
public function action_edit() { $lUserData = Input::post('user', null); $lAvatar = Input::post('avatar', null); $lDeleteAvatar = Input::post('delete_avatar', null); if (empty($lUserData)) { die(json_encode(['status' => 'error', 'message' => 'Empty data for updating user'], JSON_UNESCAPED_UNICODE)); } $lIsOwner = $lUserData['username'] == $this->current_user['username']; if ((empty($lUserData['username']) || !$lIsOwner) && !$this->is_admin) { die(json_encode(['status' => 'error', 'message' => 'Access denied'], JSON_UNESCAPED_UNICODE)); } $lUserName = $lUserData['username']; unset($lUserData['username']); try { DB::start_transaction(); $lOldData = Auth::get_profile_fields(); if (!empty($lAvatar)) { $lNewAvatar = FileHandler::prepareFiles($lAvatar, FileHandler::tempFolder()); foreach ($lNewAvatar as $lVal) { $lUserData['avatar_id'] = Model_Avatars::add(['file_name' => $lVal]); break; } if (!empty($lOldData['avatar_id'])) { $lToDeleteAvatar = Model_Avatars::getById($lOldData['avatar_id']); Model_Avatars::delete($lOldData['avatar_id']); } } if (!empty($lDeleteAvatar) && empty($lAvatar)) { $lOldAvatar = Model_Avatars::getById($lOldData['avatar_id']); foreach ($lDeleteAvatar as $lVal) { if ($lVal != $lOldData['avatar_id']) { break; } $lToDeleteAvatar = $lOldAvatar; Model_Avatars::delete($lVal); $lUserData['avatar_id'] = ''; break; } } $lResult = Auth::update_user($lUserData, $lUserName); if (!empty($lNewAvatar)) { FileHandler::moveFiles($lNewAvatar, FileHandler::tempFolder(), FileHandler::AVATAR_FOLDER); } if (!empty($lToDeleteAvatar)) { FileHandler::deleteFiles([FileHandler::AVATAR_FOLDER . $lToDeleteAvatar['file_name']]); } DB::commit_transaction(); } catch (Exception $e) { DB::rollback_transaction(); die(json_encode(['status' => 'error', 'message' => 'Error ' . $e], JSON_UNESCAPED_UNICODE)); } if ($lResult) { die(json_encode(['status' => 'ok'], JSON_UNESCAPED_UNICODE)); } die(json_encode(['status' => 'error', 'message' => 'Fields not were updated'], JSON_UNESCAPED_UNICODE)); }
/** * 登録&送信 * * @access public * @param * @return void * @author ida */ public function action_thanks() { if (!Security::check_token()) { \Response::redirect('errors/doubletransmission'); } Asset::css('jquery-ui.min.css', array(), 'add_css'); Asset::js('jquery-ui.min.js', array(), 'add_js'); $input_data = $this->getInputData(true); $input_data['created_user'] = $this->administrator->administrator_id; $input_data['send_status'] = \Model_Mail_Magazine::SEND_STATUS_WAITING; $additional_data = $this->getAdditionalData($input_data); $input_data['additional_serialize_data'] = serialize($additional_data); try { $db = Database_Connection::instance('master'); \DB::start_transaction(); $mail_magazine = \Model_Mail_Magazine::forge(); $mail_magazine->set($input_data)->save(); // メルマガ対象ユーザ登録 $query = $input_data['query']; $users = \DB::query($query)->execute(); foreach ($users as $user) { $data = array('mail_magazine_id' => $mail_magazine->mail_magazine_id, 'user_id' => $user['user_id'], 'send_status' => \Model_Mail_Magazine_User::SEND_STATUS_WAITING, 'created_user' => $this->administrator->administrator_id); $mail_magazine_user = \Model_Mail_Magazine_User::forge(); $mail_magazine_user->set($data)->save(); } \DB::commit_transaction(); } catch (\Exception $e) { \DB::rollback_transaction(); throw new \SystemException(\Model_Error::ER00000); } $view_model = \ViewModel::forge('admin/mailmagazine/thanks'); list($view_model, $replace_data) = $this->setupData($view_model, $input_data); // タスク実行 $oil_path = realpath(APPPATH . '/../../') . DS; $param = $mail_magazine->mail_magazine_id . ' ' . $this->administrator->administrator_id; exec('php ' . $oil_path . 'oil refine mail_magazine ' . $param . ' > /dev/null &'); $view_model->set('mail_magazine', $mail_magazine, true); $this->template->content = $view_model; }