Example #1
0
 /**
  * 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')));
     });
 }
Example #2
0
 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);
     }
 }
Example #3
0
 /**
  * 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));
 }
Example #4
0
 /**
  * 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;
     });
 }
Example #5
0
 /**
  * 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);
     });
 }
Example #6
0
 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);
 }
Example #7
0
 /**
  * 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()));
 }
Example #8
0
 /**
  * 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;
     }
 }
Example #10
0
 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));
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * ユーザー情報の登録処理
  * 
  * @param array $userInfo ユーザー情報
  */
 public function addClient($userInfo)
 {
     try {
         DB::start_transaction();
         // OpenIDとユーザー情報紐付く処理
         DB::commit_transaction();
     } catch (Exception $ex) {
         DB::rollback_transaction();
         return NULL;
     }
 }
Example #13
0
 /**
  * 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 function updateDB()
 {
     //Get the current values
     $oldValues = $this->getAllExisting();
     $this->dbObj->start_transaction();
     try {
         //Determine the diff between existing values and new values
         $addedTags = array();
         $removedTags = array();
         $changedTags = array();
         if (false !== $oldValues) {
             foreach ($oldValues as $tag => $v) {
                 $changes = array();
                 if (array_key_exists($tag, $this->updateInfo)) {
                     $changes = $this->dataUpdated($oldValues[$tag], $this->updateInfo[$tag]);
                     if (count($changes) > 0) {
                         $changedTags[$tag] = $changes;
                     }
                 } else {
                     $removedTags[] = $tag;
                 }
             }
             //Check if any new rows were added
             foreach ($this->updateInfo as $u) {
                 if (!array_key_exists($u->getTag(), $oldValues)) {
                     $addedTags[] = $u->getTag();
                 }
             }
         }
         $this->changedTags = $changedTags;
         $this->addedTags = $addedTags;
         $this->removedTags = $removedTags;
         //Add the new rows as new version
         $this->add($this->updateInfo);
     } catch (DBException $ex) {
         $this->dbObj->rollback();
         throw new Exception($ex->getMessage());
     }
     $this->dbObj->end_transaction();
 }
Example #15
0
 /**
  * 以下、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));
     });
 }
Example #16
0
 /**
  * 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));
     });
 }
Example #17
0
 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();
     }
 }
Example #18
0
 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();
 }
Example #19
0
 /**
  * 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)));
 }
Example #20
0
 public function insert_data($data, $id)
 {
     $check = true;
     try {
         $res_image = array();
         \DB::start_transaction();
         if (isset($data['content'])) {
             $res_image = $this->insert_image($data);
             if ($res_image === false) {
                 $check = false;
             }
         }
         if ($check) {
             $data['image_list'] = json_encode($res_image);
             $res_job = $this->job->save_data($data, $id);
             if ($id && $res_job === true) {
                 $job_id = $id;
             } elseif ($res_job > 0) {
                 $job_id = $res_job;
             } else {
                 $check = false;
             }
             if ($check) {
                 $data_job_add = Utility::set_data_job_add_recruit($data, $job_id);
                 if (count($data_job_add) && !$this->job_add->insert_multi_data($data_job_add, $this->job)) {
                     $check = false;
                 }
                 $data_job_recruit = Utility::set_data_job_add_recruit($data, $job_id, 'job_recruit_sub_title', 'job_recruit_text');
                 if (count($data_job_recruit) && !$this->job_recruit->insert_multi_data($data_job_recruit, $this->job)) {
                     $check = false;
                 }
             }
         }
         if ($check === false) {
             \DB::rollback_transaction();
         } else {
             \DB::commit_transaction();
         }
         // return query result
     } catch (Exception $e) {
         // rollback pending transactional queries
         \DB::rollback_transaction();
         throw $e;
     }
     return $check;
 }
Example #21
0
 public static function delete_album_image_multiple4ids($album_image_ids = array(), $with_delete_timeline = false)
 {
     if (!is_array($album_image_ids)) {
         $album_image_ids = (array) $album_image_ids;
     }
     $delete_target_notice_cache_member_ids = array();
     $delete_target_timeline_ids = array();
     $writable_connection = \MyOrm\Model::connection(true);
     \DBUtil::set_connection($writable_connection);
     \DB::start_transaction();
     foreach ($album_image_ids as $album_image_id) {
         if (is_enabled('notice')) {
             \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('album_image', $album_image_id);
             $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('album_image', $album_image_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 (is_enabled('timeline') && $with_delete_timeline) {
             $delete_target_timeline_ids += \timeline\site_noormmodel::delete_timeline_multiple4foreign_data('album_image', $album_image_id);
         }
     }
     $file_names = \Util_Orm::conv_col2array(Model_AlbumImage::get4ids($album_image_ids), 'file_name');
     \DB::delete('album_image')->where('id', 'in', $album_image_ids)->execute();
     \DB::commit_transaction();
     \DBUtil::set_connection(null);
     \DB::start_transaction();
     if ($files = \Model_File::get4names($file_names)) {
         foreach ($files as $file) {
             $file->delete();
         }
     }
     \DB::commit_transaction();
     // 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);
         }
     }
     if ($delete_target_timeline_ids) {
         foreach ($delete_target_timeline_ids as $timeline_id) {
             \Timeline\Site_Util::delete_cache($timeline_id);
         }
     }
 }
Example #22
0
 /**
  * The edit_all action.
  * 
  * @access  public
  * @return  void
  */
 public function action_edit_all()
 {
     $news_categories = \News\Model_NewsCategory::get_all();
     $posted_vals = array();
     if (\Input::method() == 'POST') {
         try {
             \Util_security::check_csrf();
             $posted_vals = \Input::post('labels');
             if (count($posted_vals) != count($news_categories)) {
                 throw new \httpinvalidinputexception();
             }
             \DB::start_transaction();
             foreach ($news_categories as $news_category) {
                 $value = $posted_vals[$news_category->id];
                 if (!strlen($value)) {
                     throw new \httpinvalidinputexception('未入力の項目があります。');
                 }
                 if ($value !== $news_category->label) {
                     $news_category->label = $value;
                     $news_category->save();
                 }
             }
             \DB::commit_transaction();
             \Session::set_flash('message', term('news.category.view') . 'を編集しました。');
             \Response::redirect('admin/news/category');
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $vals = array();
     foreach ($news_categories as $news_category) {
         $vals[$news_category->id] = isset($posted_vals[$news_category->id]) ? $posted_vals[$news_category->id] : $news_category->label;
     }
     $this->set_title_and_breadcrumbs(term('news.view', 'news.category.label', 'form.edit_all'), array('admin/news' => term('news.view', 'site.management'), 'admin/news/category' => term('news.category.view', 'site.management')));
     $this->template->content = \View::forge('news/category/edit_all', array('vals' => $vals, 'news_categories' => $news_categories));
 }
Example #23
0
 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);
 }
Example #24
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;
     }
 }
Example #25
0
 /**
  * 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);
     });
 }
Example #26
0
 /**
  * キューの取得、実行中への更新
  *
  * @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];
 }
Example #27
0
 /**
  * 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();
 }
Example #28
0
 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;
 }
Example #29
0
 /**
  * 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'));
 }
Example #30
0
 /**
  * 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'));
 }