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); } }
/** * post_config * * @access public * @return Response (json, html) */ public function post_config($name = null) { $this->api_accept_formats = array('json', 'html'); $this->controller_common_api(function () use($name) { if (!is_null(Input::post('name'))) { $name = Input::post('name'); } $value = Input::post('value'); self::check_name_format_for_update_config($name); $this->check_response_format_for_update_config($name); $this->response_body['message'] = self::get_success_message($name); $this->response_body['errors']['message_default'] = self::get_error_message_default($name); $member_id = (int) $this->u->id; if (!($member_config = Model_MemberConfig::get_one4member_id_and_name($member_id, $name))) { $member_config = Model_MemberConfig::forge(); $member_config->member_id = $member_id; $member_config->name = $name; } $current_value = isset($member_config->value) ? $member_config->value : null; $value = self::validate_posted_value($name, $current_value); $member_config->value = $value; \DB::start_transaction(); $member_config->save(); \DB::commit_transaction(); $response_body = self::get_response_for_update_config($name, array('id' => $member_id, $name => $value)); $this->response_body = $this->format == 'html' ? $response_body : array('html' => $response_body, 'message' => sprintf('%sを%sしました。', term('site.display', 'site.setting'), term('form.update'))); }); }
/** * post_update * * @access public * @return Response (json) */ public function post_update($member_id_to = null, $relation_type = null) { $this->controller_common_api(function () use($member_id_to, $relation_type) { $this->response_body['errors']['message_default'] = sprintf('%sの%sに%sしました。', term('follow'), term('form.update'), term('site.failure')); if (!self::check_relation_type($relation_type)) { throw new HttpNotFoundException(); } if (!is_null(Input::post('id'))) { $member_id_to = (int) Input::post('id'); } $member = Model_Member::check_authority($member_id_to); if ($member_id_to == $this->u->id) { throw new HttpInvalidInputException(); } $member_relation = Model_MemberRelation::get4member_id_from_to($this->u->id, $member_id_to); if (!$member_relation) { $member_relation = Model_MemberRelation::forge(); } $prop = 'is_' . $relation_type; $status_before = (bool) $member_relation->{$prop}; $status_after = !$status_before; \DB::start_transaction(); $member_relation->{$prop} = $status_after; $member_relation->member_id_to = $member_id_to; $member_relation->member_id_from = $this->u->id; $member_relation->save(); \DB::commit_transaction(); $this->response_body['isFollow'] = (int) $status_after; $this->response_body['html'] = $status_after ? sprintf('<span class="glyphicon glyphicon-ok"></span> %s', term('followed')) : term('do_follow'); $this->response_body['attr'] = $status_after ? array('class' => array('add' => 'btn-primary')) : array('class' => array('remove' => 'btn-primary')); $this->response_body['message'] = sprintf('%s%s', term('follow'), $status_after ? 'しました。' : 'を解除しました。'); return $this->response_body; }); }
public static function delete_timeline4id($timeline_id) { $delete_target_notice_cache_member_ids = array(); $writable_connection = \MyOrm\Model::connection(true); \DBUtil::set_connection($writable_connection); \DB::start_transaction(); if (is_enabled('notice')) { \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('timeline', $timeline_id); $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('timeline', $timeline_id); $delete_target_notice_cache_member_ids = \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids); \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids); } if (!\DB::delete('timeline')->where('id', $timeline_id)->execute()) { throw new \FuelException('Failed to delete timeline. id:' . $timeline_id); } \DB::commit_transaction(); \DBUtil::set_connection(null); // delete caches if ($delete_target_notice_cache_member_ids) { foreach ($delete_target_notice_cache_member_ids as $member_id) { \Notice\Site_Util::delete_unread_count_cache($member_id); } } Site_Util::delete_cache($timeline_id); }
/** * 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)); }
/** * Upload images * * @access public * @return Response (json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_upload($parent_id = null) { $this->api_accept_formats = array('html', 'json'); $this->api_not_check_csrf = true; $this->controller_common_api(function () use($parent_id) { $upload_type = 'img'; $news = \News\Model_News::check_authority($parent_id); if (!in_array($this->format, array('html', 'json'))) { throw new HttpNotFoundException(); } $thumbnail_size = \Input::post('thumbnail_size'); if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) { throw new \HttpInvalidInputException('Invalid input data'); } $insert_target = \Input::post('insert_target'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image); $uploadhandler = new \MyUploadHandler($options, false); \DB::start_transaction(); $files = $uploadhandler->post(false); $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']); \DB::commit_transaction(); $files['upload_type'] = $upload_type; $files['thumbnail_size'] = $thumbnail_size; $files['insert_target'] = $insert_target; $files['model'] = 'news'; $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null); }); }
/** * 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 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; }
/** * 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(); } }
/** * ユーザー情報の登録処理 * * @param array $userInfo ユーザー情報 */ public function addClient($userInfo) { try { DB::start_transaction(); // OpenIDとユーザー情報紐付く処理 DB::commit_transaction(); } catch (Exception $ex) { DB::rollback_transaction(); return NULL; } }
/** * 以下、admin_api 共通 controller * */ protected function common_post_update($field, $accepts_fields) { $this->controller_common_api(function () use($field, $accepts_fields) { if (!$field || !in_array($field, $accepts_fields)) { throw new \HttpNotFoundException(); } \DB::start_transaction(); $method = 'update_' . $field; $result = (bool) $this->{$method}(); \DB::commit_transaction(); $this->set_response_body_api(array('result' => $result)); }); }
/** * Delete profile option * * @access public * @param int $id target id * @return Response(json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_delete($id = null) { $this->controller_common_api(function () use($id) { $profile_option_id = \Input::post('id') ?: $id; $profile_option = \Model_ProfileOption::check_authority($profile_option_id, 0, 'profile'); if (!$profile_option->profile || !in_array($profile_option->profile->form_type, \Site_Profile::get_form_types_having_profile_options())) { throw new \HttpInvalidInputException(); } \DB::start_transaction(); $result = (bool) $profile_option->delete(); \DB::commit_transaction(); $this->set_response_body_api(array('result' => $result)); }); }
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); }
/** * 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; } }
/** * Create category * * @access public * @return Response(json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_create() { $this->api_accept_formats = array('html', 'json'); $this->controller_common_api(function () { $news_category = \News\Model_NewsCategory::forge(); // Lazy validation $name = trim(\Input::post('name', '')); $label = trim(\Input::post('label', '')); if (!strlen($name) || !strlen($label)) { throw new \ValidationFailedException('入力してください。'); } $news_category->name = $name; $news_category->label = $label; \DB::start_transaction(); $news_category->sort_order = \News\Model_NewsCategory::get_next_sort_order(); $result = (bool) $news_category->save(); \DB::commit_transaction(); $data = array('result' => $result, 'id' => $news_category->id); if ($this->format == 'html') { $data += array('name' => $news_category->name, 'label' => $news_category->label, 'delete_uri' => sprintf('admin/news/category/api/delete/%s.json', $news_category->id), 'edit_uri' => sprintf('admin/news/category/edit/%d', $news_category->id)); } $this->set_response_body_api($data, $this->format == 'html' ? '_parts/table/simple_row_sortable' : null); }); }
/** * キューの取得、実行中への更新 * * @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]; }
/** * * @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; } }
/** * 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; }
public function action_create() { try { if (Input::method() == 'POST') { $file = Input::file('news_photo_file'); $val = Model_News::validate('create'); if ($val->run()) { $config = array('path' => "/var/www/html/uploads/news_photo/", 'ext_whitelist' => array('jpg', 'jpeg', 'png'), 'file_chmod' => 0777, 'auto_rename' => true, 'overwrite' => true, 'randomize' => true, 'create_path' => true); // $allowList = array(".jpeg", ".jpg", ".png"); // $error = false; // $path = realpath(DOCROOT."/../../uploads/news_photo/").DS; $news_photo = ""; Upload::process($config); if (Upload::is_valid()) { Upload::save(); $news_photo = Upload::get_files()[0]; $news = Model_News::forge(array('news_title' => Input::post('news_title'), 'news_short_detail' => Input::post('news_short_detail'), 'news_detail' => Input::post('news_detail'), 'news_photo' => $news_photo['saved_as'], 'news_published' => Input::post('news_published'), 'created_at' => time(), 'published_at' => Input::post('news_published') == 1 ? time() : 0)); if ($news and $news->save()) { Session::set_flash('success', 'Added news #' . $news->id . '.'); Response::redirect('news/edit/' . $news->id); } else { Session::set_flash('error', 'Could not save news.'); } if ($file and $file->save()) { DB::commit_transaction(); \Fuel\Core\Session::set_flash('success', 'Upload success'); } } /*if($file['size'] > 0){ $ext = strtolower(substr($file['name'],strrpos($file['name'],"."))); if(!in_array($ext,$allowList)){ Session::set_flash('error', 'ชนิดของไฟล์ภาพไม่ถูกต้อง'); $error = true; } $filename = md5(time()); if(@copy($file['tmp_name'],$path.$filename.$ext)){ $news_photo = $filename.$ext; /* small thumbnail */ # parent::create_cropped_thumbnail($path.$filename.$ext,64,64,"-s"); # parent::create_cropped_thumbnail($path.$filename.$ext,128,128,"-s@2x"); /* */ /* medium thumbnail */ # parent::create_cropped_thumbnail($path.$filename.$ext,360,240,"-m"); # parent::create_cropped_thumbnail($path.$filename.$ext,720,480,"-m@2x"); /* } else { Session::set_flash('error', 'ไม่สามารถอัพโหลดไฟล์ภาพได้ โปรดลองใหม่อีกครั้ง'); $error = true; } }*/ /*if(!$error){ $news = Model_News::forge(array( 'news_title' => Input::post('news_title'), 'news_short_detail' => Input::post('news_short_detail'), 'news_detail' => Input::post('news_detail'), 'news_photo' => $news_photo, 'news_published' => Input::post('news_published'), 'created_at' => time(), 'published_at' => (Input::post('news_published')==1)?time():0 )); if ($news and $news->save()){ Session::set_flash('success', 'Added news #' . $news->id . '.'); Response::redirect('news/edit/'.$news->id); } else { Session::set_flash('error', 'Could not save news.'); } }*/ } else { $msg = '<ul>'; foreach ($val->error() as $field => $error) { $msg .= '<li>' . $error->get_message() . '</li>'; } $msg .= '</ul>'; Session::set_flash('error', $msg); } } $this->theme->set_template('edit'); $this->theme->get_template()->set_global('current_menu', "News", false); $this->theme->get_template()->set_global('current_menu_desc', "จัดการข่าวทั้งหมดในระบบ", false); $this->theme->get_template()->set('breadcrumb', array(array('title' => "Home", 'icon' => "fa-home", 'link' => Uri::create('home'), 'active' => false), array('title' => "News", 'icon' => "eicon-newspaper", 'link' => Uri::create('news/index'), 'active' => false), array('title' => "Create", 'icon' => "", 'link' => "", 'active' => true))); $this->theme->get_template()->set_global('mode', "create", false); $this->theme->get_template()->set('page_specific_js', "form_news.js"); $this->theme->set_partial('sidebar', 'common/sidebar'); $this->theme->set_partial('left', 'news/create'); } catch (Exception $e) { die($e->getMessage()); } }
/** * 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')); }
/** * 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 static function delete_file_all4member_id($member_id, $is_tmp = false, $limit = 0) { if (!$limit) { $limit = conf('batch.limit.delete.file', 10); } $model = Site_Model::get_model_name($is_tmp ? 'file_tmp' : 'file'); $query = $model::query(); if ($is_tmp) { $query->where('user_type', 0); } $query->where('member_id', $member_id)->limit($limit); while ($objs = $query->get()) { DB::start_transaction(); foreach ($objs as $obj) { $obj->delete(); } DB::commit_transaction(); } }