• R/O
  • SSH
  • HTTPS

jinrousiki: Commit


Commit MetaInfo

Revision2307 (tree)
Time2018-12-29 20:24:26
Authorumethyl

Log Message

IconDB::Update()

Change Summary

Incremental Difference

--- trunk/include/controller/icon_edit_class.php (revision 2306)
+++ trunk/include/controller/icon_edit_class.php (revision 2307)
@@ -31,14 +31,18 @@
3131 }
3232
3333 //アイコン名の文字列長チェック
34- $query_stack = [];
34+ $query = IconDB::GetQueryUpdate();
35+ $stack = [];
3536 foreach (UserIcon::ValidateText(IconEditMessage::TITLE, $url) as $key => $value) {
36- $query_stack[] = sprintf('%s = %s', $key, is_null($value) ? 'NULL' : "'{$value}'");
37+ if (true === is_null($value)) {
38+ $query->SetNull($key);
39+ } else {
40+ $stack[$key] = $value;
41+ }
3742 }
3843
39- if (Text::Exists($color)) { //色指定チェック
40- $color = UserIcon::ValidateColor($color, IconEditMessage::TITLE, $url);
41- $query_stack[] = sprintf("color = '%s'", $color);
44+ if (true === Text::Exists($color)) { //色指定チェック
45+ $stack['color'] = UserIcon::ValidateColor($color, IconEditMessage::TITLE, $url);
4246 }
4347
4448 //トランザクション開始
@@ -51,25 +55,27 @@
5155 self::OutputError(sprintf(IconEditMessage::NOT_EXISTS, $icon_no), $url);
5256 }
5357
54- if (IconDB::Duplicate($icon_no, $icon_name)) { //アイコン名重複チェック
58+ if (true === IconDB::Duplicate($icon_no, $icon_name)) { //アイコン名重複チェック
5559 self::OutputError(sprintf(IconEditMessage::DUPLICATE, $icon_name), $url);
5660 }
5761
58- if (IconDB::Using($icon_no)) { //編集制限チェック
62+ if (true === IconDB::Using($icon_no)) { //編集制限チェック
5963 self::OutputError(IconEditMessage::USING, $url);
6064 }
6165
6266 if (IconDB::Disable($icon_no) !== $disable) { //非表示フラグチェック
63- $query_stack[] = sprintf('disable = %s', $disable ? Query::ENABLE : Query::DISABLE);
67+ $query->SetData('disable', $disable ? Query::ENABLE : Query::DISABLE);
6468 }
69+ $query->Set(array_keys($stack));
6570
66- if (count($query_stack) < 1) { //変更が無いなら終了
71+ if (count($stack) < 1) { //変更が無いなら終了
72+ //現状はここに入ることは事実上無い。精度を上げる場合はDBから引いて比較すること
6773 self::OutputError(IconEditMessage::NO_CHANGE, $url);
6874 }
69- $query = ArrayFilter::ToCSV($query_stack);
70- //self::OutputError($query, $url); //テスト用
75+ $list = array_merge(array_values($stack), [$icon_no]);
76+ //self::OutputError($query->p() . print_r($list, true), $url); //テスト用
7177
72- if (IconDB::Update($icon_no, $query) && DB::Commit()) {
78+ if (IconDB::Update($query, $list) && DB::Commit()) {
7379 $str = sprintf('%s?icon_no=%d', self::URL, $icon_no);
7480 HTML::OutputResult(IconEditMessage::TITLE, IconEditMessage::SUCCESS, $str);
7581 } else {
@@ -79,7 +85,7 @@
7985
8086 //エラー出力
8187 private static function OutputError($str, $url = null) {
82- if (isset($url)) {
88+ if (false === is_null($url)) {
8389 $str = Text::Join($str, $url);
8490 }
8591 HTML::OutputResult(IconEditMessage::TITLE, $str);
--- trunk/include/database/db_class.php (revision 2306)
+++ trunk/include/database/db_class.php (revision 2307)
@@ -423,6 +423,11 @@
423423 return $this->StoreData('set', 'set_data', $column, $data);
424424 }
425425
426+ //SET 句登録 (NULL 指定)
427+ public function SetNull($column) {
428+ return $this->SetData($column, 'NULL');
429+ }
430+
426431 //WHERE 句登録
427432 public function Where(array $list = []) {
428433 return $this->Store('where', $list);
--- trunk/include/database/icon_db_class.php (revision 2306)
+++ trunk/include/database/icon_db_class.php (revision 2307)
@@ -122,8 +122,8 @@
122122 }
123123
124124 //アイコン情報更新
125- public static function Update($icon_no, $data) {
126- DB::Prepare(sprintf('UPDATE user_icon SET %s WHERE icon_no = ?', $data), [$icon_no]);
125+ public static function Update(Query $query, array $list) {
126+ DB::Prepare($query->Build(), $list);
127127 return DB::FetchBool();
128128 }
129129
@@ -134,6 +134,7 @@
134134 if (false === DB::FetchBool()) { //レコード削除
135135 return false;
136136 }
137+
137138 unlink(Icon::GetFile($file)); //ファイル削除
138139 DB::Optimize('user_icon'); //テーブル最適化 + コミット
139140 return true;
@@ -141,7 +142,7 @@
141142
142143 //セッション削除
143144 public static function ClearSession($icon_no) {
144- $query = self::GetQueryUpdate()->SetData('session_id', 'NULL');
145+ $query = self::GetQueryUpdate()->SetNull('session_id');
145146
146147 DB::Prepare($query->Build(), [$icon_no]);
147148 return DB::FetchBool();
@@ -170,6 +171,11 @@
170171 return $stack;
171172 }
172173
174+ //共通 Query 取得 (UPDATE 用)
175+ public static function GetQueryUpdate() {
176+ return self::GetQueryBase()->Update()->Where(['icon_no']);
177+ }
178+
173179 //共通 Query 取得
174180 private static function GetQuery(array $column) {
175181 return self::GetQuerySelect($column)->Where(['icon_no']);
@@ -185,11 +191,6 @@
185191 return self::GetQuerySelect(['icon_no']);
186192 }
187193
188- //共通 Query 取得 (UPDATE 用)
189- private static function GetQueryUpdate() {
190- return self::GetQueryBase()->Update()->Where(['icon_no']);
191- }
192-
193194 //共通 Query Base 取得
194195 private static function GetQueryBase() {
195196 return Query::Init()->Table('user_icon');
Show on old repository browser