Skip to content

Commit 90ccdd7

Browse files
authoredJun 13, 2021
Merge pull request #332 from uzulla/issue332/remove-mysqli-support
MSDB削除、MysqliWrap削除、PDOWrapリファクタ、Model周りリファクタ等 #331
2 parents 11db0ab + 80ae2d3 commit 90ccdd7

File tree

24 files changed

+885
-1526
lines changed

24 files changed

+885
-1526
lines changed
 

‎.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
uses: shivammathur/setup-php@v2
1616
with:
1717
php-version: '8.0'
18-
extensions: mbstring, gd, gettext, fileinfo, pdo, pdo_mysql, mysqli, zip
18+
extensions: mbstring, gd, gettext, fileinfo, pdo, pdo_mysql, zip
1919

2020
- uses: actions/checkout@v2
2121

108 Bytes
Binary file not shown.

‎app/locale/en_US.UTF-8/LC_MESSAGES/messages.po

+3-3
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ msgid "Check connection library with MySQL"
11191119
msgstr ""
11201120

11211121
#: shell/../view/admin/common/install.html:78
1122-
msgid "Please enable pdo or mysqli"
1122+
msgid "Please enable pdo"
11231123
msgstr ""
11241124

11251125
#: shell/../view/admin/common/install.html:94
@@ -2498,8 +2498,8 @@ msgstr ""
24982498
msgid "The page you are looking for does not exist."
24992499
msgstr ""
25002500

2501-
msgid "Execute `Create database` failed. Please `Create database` your self."
2502-
msgstr ""
2501+
msgid "Please set correct the DB connection settings."
2502+
msgstr "DBの接続設定をご確認ください。"
25032503

25042504
msgid "(If not exists, will be try create)"
25052505
msgstr ""
-88 Bytes
Binary file not shown.

‎app/locale/ja_JP.UTF-8/LC_MESSAGES/messages.po

+4-4
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,8 @@ msgid "Check connection library with MySQL"
11091109
msgstr "MySQLとの接続ライブラリチェック"
11101110

11111111
#: shell/../view/admin/common/install.html:78
1112-
msgid "Please enable pdo or mysqli"
1113-
msgstr "mysqli または pdoを有効にしてください"
1112+
msgid "Please enable pdo"
1113+
msgstr "pdoを有効にしてください"
11141114

11151115
#: shell/../view/admin/common/install.html:94
11161116
msgid "Check connection to the MySQL"
@@ -2545,8 +2545,8 @@ msgstr "ブログに設置されたプラグイン、またはテンプレート
25452545
msgid "The page you are looking for does not exist."
25462546
msgstr "お探しのページは存在しません"
25472547

2548-
msgid "Execute `Create database` failed. Please `Create database` your self."
2549-
msgstr "`CREATE DATABASE`のsql実行に失敗しました、事前に`CREATE DATABASE`を実行してください。"
2548+
msgid "Please set correct the DB connection settings."
2549+
msgstr "DBの接続設定をご確認ください。"
25502550

25512551
msgid "(If not exists, will be try create)"
25522552
msgstr "(未作成の場合、作成を試行します)"

‎app/src/Model/BlogsModel.php

+31-22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Fc2blog\Web\Request;
99
use InvalidArgumentException;
1010
use OutOfBoundsException;
11+
use PDOException;
1112

1213
class BlogsModel extends Model
1314
{
@@ -71,6 +72,7 @@ public static function isPasswordRegistered($blog_id): bool
7172
* ディレクトリとして使用済みかどうか
7273
* @param string $value
7374
* @return bool|string
75+
* @noinspection PhpUnused
7476
*/
7577
public static function usableDirectory(string $value)
7678
{
@@ -233,39 +235,44 @@ public static function getTemplateIds($blog): array
233235
/**
234236
* ブログの一覧(SelectBox用)
235237
* @param $user_id
236-
* @return mixed
238+
* @return array
237239
*/
238-
public function getSelectList($user_id)
240+
public function getSelectList($user_id): array
239241
{
240-
return $this->find('list', array(
241-
'fields' => array('id', 'name'),
242-
'where' => 'user_id=?',
243-
'params' => array($user_id),
244-
'order' => 'created_at DESC',
245-
));
242+
try {
243+
return $this->find('list', array(
244+
'fields' => array('id', 'name'),
245+
'where' => 'user_id=?',
246+
'params' => array($user_id),
247+
'order' => 'created_at DESC',
248+
));
249+
} catch (PDOException $e) {
250+
// インストール前や初期化前など、クエリが出来ないケースがある
251+
return [];
252+
}
246253
}
247254

248255
/**
249256
* ブログIDをキーにユーザーIDを条件としてブログを取得
250-
* @param $blog_id
257+
* @param $id
251258
* @param $user_id
252259
* @param array $options
253260
* @return mixed
254261
*/
255-
public function findByIdAndUserId($blog_id, $user_id, array $options = []): array
262+
public function findByIdAndUserId($id, $user_id, array $options = []): array
256263
{
257264
$options['where'] = isset($options['where']) ? 'id=? AND user_id=? AND ' . $options['where'] : 'id=? AND user_id=?';
258-
$options['params'] = isset($options['params']) ? array_merge(array($blog_id, $user_id), $options['params']) : array($blog_id, $user_id);
265+
$options['params'] = isset($options['params']) ? array_merge(array($id, $user_id), $options['params']) : array($id, $user_id);
259266
return $this->find('row', $options);
260267
}
261268

262269
/**
263270
* ユーザーIDをキーにしてブログを取得
264271
* @param $user_id
265272
* @param array $options
266-
* @return mixed
273+
* @return array
267274
*/
268-
public function findByUserId($user_id, $options = array())
275+
public function findByUserId($user_id, array $options = array())
269276
{
270277
$options['where'] = isset($options['where']) ? 'user_id=? AND ' . $options['where'] : 'user_id=?';
271278
$options['params'] = isset($options['params']) ? array_merge(array($user_id), $options['params']) : array($user_id);
@@ -286,7 +293,7 @@ public function findByRandom()
286293
/**
287294
* ログイン後最初に表示するブログを取得する
288295
* @param $user
289-
* @return mixed
296+
* @return array
290297
*/
291298
public function getLoginBlog($user)
292299
{
@@ -311,7 +318,7 @@ public function getLoginBlog($user)
311318
/**
312319
* ユーザーIDをキーにブログのリストを取得
313320
* @param int $user_id
314-
* @return mixed
321+
* @return array
315322
*/
316323
public function getListByUserId(int $user_id)
317324
{
@@ -349,7 +356,7 @@ public function insert(array $data, array $options = [])
349356
{
350357
// 主キーがauto_incrementじゃないのでreturn値の受け取り方を変更
351358
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
352-
$options['result'] = DBInterface::RESULT_SUCCESS;
359+
$options['result'] = PDOQuery::RESULT_SUCCESS;
353360
if (!parent::insert($data, $options)) {
354361
return false;
355362
}
@@ -496,7 +503,7 @@ public static function regeneratePluginPhpByBlogId(string $blog_id): void
496503
* @param array $values
497504
* @param $id
498505
* @param array $options
499-
* @return array|false|int|mixed
506+
* @return array|int
500507
*/
501508
public function updateById(array $values, $id, array $options = [])
502509
{
@@ -507,7 +514,8 @@ public function updateById(array $values, $id, array $options = [])
507514
/**
508515
* 最終投稿日時更新
509516
* @param $id
510-
* @return array|false|int|mixed
517+
* @return array|int
518+
* @noinspection PhpUnused
511519
*/
512520
public function updateLastPostedAt($id)
513521
{
@@ -519,7 +527,7 @@ public function updateLastPostedAt($id)
519527
* テンプレートの切り替え
520528
* @param array $blog_template
521529
* @param string $blog_id
522-
* @return array|false|int|mixed
530+
* @return array|int
523531
*/
524532
public function switchTemplate(array $blog_template, string $blog_id)
525533
{
@@ -533,13 +541,12 @@ public function switchTemplate(array $blog_template, string $blog_id)
533541
$reply_type = strstr($blog_template['html'], '<%comment_reply_body>') ?
534542
Config::get('BLOG_TEMPLATE.COMMENT_TYPE.REPLY') : Config::get('BLOG_TEMPLATE.COMMENT_TYPE.AFTER');
535543
// コメントの表示タイプを更新
536-
Model::load('BlogSettings')->updateReplyType($device_type, $reply_type, $blog_id);
544+
(new BlogSettingsModel())->updateReplyType($device_type, $reply_type, $blog_id);
537545

538546
$ret = $this->updateById($data, $blog_id);
539547

540548
if ($ret) {
541549
// 更新に成功した場合 現在のテンプレートを削除
542-
Model::load('BlogTemplates');
543550
$template_path = BlogTemplatesModel::getTemplateFilePath($blog_id, $device_type);
544551
is_file($template_path) && unlink($template_path);
545552
$css_path = BlogTemplatesModel::getCssFilePath($blog_id, $device_type);
@@ -556,7 +563,7 @@ public function switchTemplate(array $blog_template, string $blog_id)
556563
* @param array $options
557564
* @return bool|int
558565
*/
559-
public function deleteByIdAndUserId($blog_id, int $user_id, $options = array())
566+
public function deleteByIdAndUserId($blog_id, int $user_id, array $options = array())
560567
{
561568
if (!parent::deleteById($blog_id, array('where' => 'user_id=?', 'params' => array($user_id)))) {
562569
return 0;
@@ -635,6 +642,7 @@ static public function isCorrectHttpSchemaByBlog(Request $request, Blog $blog):
635642
* @param Request $request
636643
* @param string $blog_id
637644
* @return bool
645+
* @noinspection PhpUnused
638646
*/
639647
static public function isCorrectHttpSchemaByBlogId(Request $request, string $blog_id): bool
640648
{
@@ -762,6 +770,7 @@ static public function getDefaultBlogId(): ?string
762770
/**
763771
* @param Request $request
764772
* @return string|null
773+
* @noinspection PhpUnused
765774
*/
766775
static public function getBlogIdByRequestOrDefault(Request $request): ?string
767776
{

‎app/src/Model/CategoriesModel.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function validate(array $data, ?array &$valid_data = [], array $white_lis
7171
* @param $data
7272
* @param $model
7373
* @return bool|string
74+
* @noinspection PhpUnusedParameterInspection
7475
*/
7576
public static function uniqueName($value, $option, $key, $data, $model)
7677
{
@@ -183,7 +184,7 @@ public function getEntryCategories($blog_id, $entry_id)
183184
SQL;
184185
$params = array($blog_id, $entry_id, $blog_id);
185186
$options = array();
186-
$options['result'] = DBInterface::RESULT_ALL;
187+
$options['result'] = PDOQuery::RESULT_ALL;
187188
return $this->findSql($sql, $params, $options);
188189
}
189190

@@ -210,7 +211,7 @@ public function getEntriesCategories($blog_id, $entry_ids = array())
210211
SQL;
211212
$params = array_merge(array($blog_id), $entry_ids, array($blog_id));
212213
$options = array();
213-
$options['result'] = DBInterface::RESULT_ALL;
214+
$options['result'] = PDOQuery::RESULT_ALL;
214215
$categories = $this->findSql($sql, $params, $options);
215216

216217
$entries_categories = array();
@@ -253,7 +254,7 @@ public function increaseCount($blog_id, $ids = array())
253254
}
254255
$sql = 'UPDATE ' . $this->getTableName() . ' SET count=count+1 WHERE blog_id=? AND id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')';
255256
$params = array_merge(array($blog_id), $ids);
256-
$options['result'] = DBInterface::RESULT_SUCCESS;
257+
$options['result'] = PDOQuery::RESULT_SUCCESS;
257258
return $this->executeSql($sql, $params, $options);
258259
}
259260

@@ -270,7 +271,7 @@ public function decreaseCount($blog_id, $ids = array())
270271
}
271272
$sql = 'UPDATE ' . $this->getTableName() . ' SET count=count-1 WHERE blog_id=? AND count>0 AND id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')';
272273
$params = array_merge(array($blog_id), $ids);
273-
$options['result'] = DBInterface::RESULT_SUCCESS;
274+
$options['result'] = PDOQuery::RESULT_SUCCESS;
274275
return $this->executeSql($sql, $params, $options);
275276
}
276277

‎app/src/Model/CommentsModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public function updateApproval($blog_id, $comment_id = null)
594594
$params[] = $comment_id;
595595
}
596596
$sql .= ' AND open_status=' . Config::get('COMMENT.OPEN_STATUS.PENDING');
597-
$options['result'] = DBInterface::RESULT_SUCCESS;
597+
$options['result'] = PDOQuery::RESULT_SUCCESS;
598598
return $this->executeSql($sql, $params, $options);
599599
}
600600

‎app/src/Model/DBInterface.php

-32
This file was deleted.

‎app/src/Model/EntriesModel.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function getArchives($blog_id)
136136
ORDER BY concat(year, month) DESC;
137137
SQL;
138138
$params = array($blog_id);
139-
$options = array('result' => DBInterface::RESULT_ALL);
139+
$options = array('result' => PDOQuery::RESULT_ALL);
140140
return $this->findSql($sql, $params, $options);
141141
}
142142

@@ -387,7 +387,7 @@ public function increaseCommentCount($blog_id, $entry_id)
387387
{
388388
$sql = 'UPDATE ' . $this->getTableName() . ' SET comment_count=comment_count+1 WHERE blog_id=? AND id=?';
389389
$params = array($blog_id, $entry_id);
390-
$options['result'] = DBInterface::RESULT_SUCCESS;
390+
$options['result'] = PDOQuery::RESULT_SUCCESS;
391391
return $this->executeSql($sql, $params, $options);
392392
}
393393

@@ -401,7 +401,7 @@ public function decreaseCommentCount($blog_id, $entry_id)
401401
{
402402
$sql = 'UPDATE ' . $this->getTableName() . ' SET comment_count=comment_count-1 WHERE blog_id=? AND id=? AND comment_count>0';
403403
$params = array($blog_id, $entry_id);
404-
$options['result'] = DBInterface::RESULT_SUCCESS;
404+
$options['result'] = PDOQuery::RESULT_SUCCESS;
405405
return $this->executeSql($sql, $params, $options);
406406
}
407407

‎app/src/Model/MSDB.php

-180
This file was deleted.

‎app/src/Model/Model.php

+3-595
Large diffs are not rendered by default.

‎app/src/Model/MySqliWrap.php

-351
This file was deleted.

‎app/src/Model/PDOConnection.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fc2blog\Model;
5+
6+
use PDO;
7+
8+
class PDOConnection
9+
{
10+
// TODO singleton は最終的に削除する
11+
private static $instance;
12+
13+
public static function getInstance(bool $rebuild = false): self
14+
{
15+
if (!isset(self::$instance) || $rebuild) {
16+
self::$instance = new self();
17+
self::$instance->pdo = static::createConnection();
18+
}
19+
return self::$instance;
20+
}
21+
22+
/** @var PDO */
23+
public $pdo;
24+
25+
public static function createConnection(): PDO
26+
{
27+
$host = DB_HOST;
28+
$port = DB_PORT;
29+
$user = DB_USER;
30+
$password = DB_PASSWORD;
31+
$database = DB_DATABASE;
32+
$charset = DB_CHARSET;
33+
34+
return new PDO(
35+
"mysql:host={$host};port={$port};dbname={$database};charset={$charset};",
36+
$user,
37+
$password,
38+
[
39+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
40+
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
41+
PDO::ATTR_EMULATE_PREPARES => false,
42+
]
43+
);
44+
}
45+
}

‎app/src/Model/PDOQuery.php

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Fc2blog\Model;
5+
6+
use Fc2blog\Config;
7+
use Fc2blog\Util\Log;
8+
use PDO;
9+
use PDOException;
10+
use PDOStatement;
11+
12+
class PDOQuery
13+
{
14+
// find等の挙動選択肢 TODO 削除し、別々のメソッドへ
15+
const RESULT_ONE = 'one'; // 1カラムのみ取得
16+
const RESULT_ROW = 'row'; // 1行のみ取得
17+
const RESULT_LIST = 'list'; // リスト形式で取得
18+
const RESULT_ALL = 'all'; // 全て取得
19+
const RESULT_STAT = 'statement'; // 結果ステートメントを返却する
20+
const RESULT_INSERT_ID = 'insert_id'; // AUTO_INCREMENTの値を返却
21+
const RESULT_AFFECTED = 'affected'; // 変更のあった行数を返却
22+
const RESULT_SUCCESS = 'success'; // SQLの実行結果が成功かどうかを返却
23+
24+
/**
25+
* 参照系SQLの実行
26+
* @param PDO $pdo
27+
* @param string $sql
28+
* @param array $params
29+
* @param array $options
30+
* @return array|int
31+
* @throw PDOException
32+
*/
33+
public static function find(PDO $pdo, string $sql, array $params = [], array $options = [])
34+
{
35+
$options = array_merge(['result' => static::RESULT_ALL], $options);
36+
try {
37+
$stmt = static::query($pdo, $sql, $params);
38+
} catch (PDOException $e) {
39+
Log::error("DB find error " . $e->getMessage() . " {$sql}", [$params]);
40+
throw $e;
41+
}
42+
return static::result($pdo, $stmt, $options['result']);
43+
}
44+
45+
/**
46+
* 更新系SQLの実行
47+
* @param PDO $pdo
48+
* @param string $sql
49+
* @param array $params
50+
* @param array $options
51+
* @return array|int
52+
*/
53+
public static function execute(PDO $pdo, string $sql, array $params = [], array $options = [])
54+
{
55+
$options = array_merge(['result' => static::RESULT_SUCCESS], $options);
56+
try {
57+
$stmt = static::query($pdo, $sql, $params);
58+
} catch (PDOException $e) {
59+
Log::error("DB execute error " . $e->getMessage() . " {$sql}", [$params]);
60+
throw $e;
61+
}
62+
return static::result($pdo, $stmt, $options['result']);
63+
}
64+
65+
/**
66+
* 複数行となるSQLの実行
67+
* @param PDO $pdo
68+
* @param $sql
69+
* @return bool
70+
*/
71+
public static function multiExecute(PDO $pdo, $sql): bool
72+
{
73+
$sql = preg_replace('/^--.*?\n/m', '', $sql);
74+
$sql = preg_replace('/\/\*.*?\*\//s', '', $sql);
75+
$sql_list = explode(';', $sql);
76+
foreach ($sql_list as $sql) {
77+
if (trim($sql) === '') continue; // 空クエリならスキップ
78+
static::execute($pdo, $sql);
79+
}
80+
return true;
81+
}
82+
83+
/**
84+
* PDOでSQLの実行
85+
* @param PDO $pdo
86+
* @param $sql
87+
* @param array $params
88+
* @return false|PDOStatement 成功時PDOStatement
89+
*/
90+
private static function query(PDO $pdo, $sql, array $params = [])
91+
{
92+
if (Config::get('SQL_DEBUG', 0)) {
93+
$mtime = microtime(true);
94+
}
95+
96+
if (!count($params)) {
97+
$stmt = $pdo->query($sql);
98+
} else {
99+
$stmt = $pdo->prepare($sql);
100+
$stmt->execute($params);
101+
}
102+
103+
if (isset($mtime) && Config::get('SQL_DEBUG', 0)) {
104+
$mtime = sprintf('%0.2fms', (microtime(true) - $mtime) * 1000);
105+
Log::debug_log("SQL {$mtime} {$sql}", ['params' => $params]);
106+
}
107+
return $stmt;
108+
}
109+
110+
/**
111+
* 結果内容の変換 TODO いつか削除する
112+
* @param PDO $pdo
113+
* @param $stmt
114+
* @param $type
115+
* @return array|int $typeによって様々な意味の返り値となる
116+
*/
117+
public static function result(PDO $pdo, $stmt, $type)
118+
{
119+
if ($stmt === false) {
120+
return [];
121+
}
122+
123+
switch ($type) {
124+
// 1カラムのみ取得
125+
case static::RESULT_ONE :
126+
return $stmt->fetchColumn();
127+
128+
// 1行のみ取得
129+
case static::RESULT_ROW :
130+
return $stmt->fetch();
131+
132+
// リスト形式で取得
133+
case static::RESULT_LIST :
134+
$rows = [];
135+
$stmt->setFetchMode(PDO::FETCH_NUM);
136+
foreach ($stmt as $value) {
137+
$rows[$value[0]] = $value[1];
138+
}
139+
return $rows;
140+
141+
// 全て取得
142+
case static::RESULT_ALL :
143+
return $stmt->fetchAll();
144+
145+
// InsertIDを返却
146+
case static::RESULT_INSERT_ID :
147+
return $pdo->lastInsertId();
148+
149+
// 影響のあった行数を返却
150+
case static::RESULT_AFFECTED :
151+
return $stmt->rowCount();
152+
153+
// 成功したかどうかを返却
154+
case static::RESULT_SUCCESS :
155+
return 1;
156+
157+
case static::RESULT_STAT:
158+
default:
159+
return $stmt;
160+
}
161+
}
162+
}

‎app/src/Model/PDOWrap.php

-243
This file was deleted.

‎app/src/Model/QueryTrait.php

+592
Large diffs are not rendered by default.

‎app/src/Model/TagsModel.php

+21-17
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function validate(array $data, ?array &$valid_data = [], array $white_lis
6161
* @param $data
6262
* @param $model
6363
* @return bool|string
64+
* @noinspection PhpUnusedParameterInspection
65+
* @noinspection PhpUnused
6466
*/
6567
public static function uniqueName($value, $option, $key, $data, $model)
6668
{
@@ -125,9 +127,10 @@ public function getListByNames(string $blog_id, array $tags = []): array
125127
* @param $name
126128
* @param $blog_id
127129
* @param array $options
128-
* @return mixed
130+
* @return array
131+
* @noinspection PhpUnused
129132
*/
130-
public function findByNameAndBlogId($name, $blog_id, $options = array())
133+
public function findByNameAndBlogId($name, $blog_id, array $options = array())
131134
{
132135
$options['where'] = isset($options['where']) ? 'name=? AND blog_id=? AND ' . $options['where'] : 'name=? AND blog_id=?';
133136
$options['params'] = isset($options['params']) ? array_merge(array($name, $blog_id), $options['params']) : array($name, $blog_id);
@@ -138,9 +141,9 @@ public function findByNameAndBlogId($name, $blog_id, $options = array())
138141
* 良く使用するタグ一覧を取得する
139142
* @param $blog_id
140143
* @param array $options
141-
* @return mixed
144+
* @return array
142145
*/
143-
public function getWellUsedTags($blog_id, $options = array())
146+
public function getWellUsedTags($blog_id, array $options = array())
144147
{
145148
$options['fields'] = 'id, name';
146149
$options['where'] = (isset($options['where']) && $options['where'] != "") ? 'blog_id=? AND ' . $options['where'] : 'blog_id=?';
@@ -170,7 +173,7 @@ public function getEntryTagNames($blog_id, $entry_id)
170173
* 記事のタグを取得する
171174
* @param $blog_id
172175
* @param $entry_id
173-
* @return mixed
176+
* @return array
174177
*/
175178
public function getEntryTags($blog_id, $entry_id)
176179
{
@@ -184,7 +187,7 @@ public function getEntryTags($blog_id, $entry_id)
184187
SQL;
185188
$params = array($blog_id, $entry_id, $blog_id);
186189
$options = array();
187-
$options['result'] = DBInterface::RESULT_ALL;
190+
$options['result'] = PDOQuery::RESULT_ALL;
188191
return $this->findSql($sql, $params, $options);
189192
}
190193

@@ -211,7 +214,7 @@ public function getEntriesTags($blog_id, $entry_ids)
211214
SQL;
212215
$params = array_merge(array($blog_id), $entry_ids, array($blog_id));
213216
$options = array();
214-
$options['result'] = DBInterface::RESULT_ALL;
217+
$options['result'] = PDOQuery::RESULT_ALL;
215218
$tags = $this->findSql($sql, $params, $options);
216219

217220
$entries_tags = array();
@@ -228,7 +231,7 @@ public function getEntriesTags($blog_id, $entry_ids)
228231
* 件数を増加させる処理
229232
* @param string $blog_id
230233
* @param array $ids
231-
* @return int|false
234+
* @return array|int
232235
*/
233236
public function increaseCount(string $blog_id, array $ids = array())
234237
{
@@ -237,7 +240,7 @@ public function increaseCount(string $blog_id, array $ids = array())
237240
}
238241
$sql = 'UPDATE ' . $this->getTableName() . ' SET count=count+1 WHERE blog_id=? AND id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')';
239242
$params = array_merge(array($blog_id), $ids);
240-
$options['result'] = DBInterface::RESULT_SUCCESS;
243+
$options['result'] = PDOQuery::RESULT_SUCCESS;
241244
return $this->executeSql($sql, $params, $options);
242245
}
243246

@@ -256,7 +259,7 @@ public function decreaseCount($blog_id, array $ids = [])
256259
' SET count=count-1 WHERE blog_id=? AND count>0 AND id ' .
257260
' IN (' . implode(',', array_fill(0, count($ids), '?')) . ')';
258261
$params = array_merge([$blog_id], $ids);
259-
$options['result'] = DBInterface::RESULT_SUCCESS;
262+
$options['result'] = PDOQuery::RESULT_SUCCESS;
260263
return
261264
# 有効タグ数の数え直し
262265
$this->executeSql($sql, $params, $options) &&
@@ -266,28 +269,29 @@ public function decreaseCount($blog_id, array $ids = [])
266269

267270
/**
268271
* idとblog_idをキーとした削除 + 付随情報も削除
269-
* @param $tag_id
272+
* @param $id
270273
* @param $blog_id
271274
* @param array $options
272-
* @return array|false|int|mixed
275+
* @return array|int
273276
*/
274-
public function deleteByIdAndBlogId($tag_id, $blog_id, $options = array())
277+
public function deleteByIdAndBlogId($id, $blog_id, array $options = array())
275278
{
276279
// タグの紐付け情報削除
277-
Model::load('EntryTags')->delete('blog_id=? AND tag_id=?', array($blog_id, $tag_id));
280+
(new EntryTagsModel())->delete('blog_id=? AND tag_id=?', array($blog_id, $id));
278281

279282
// 記事本体削除
280-
return parent::deleteByIdAndBlogId($tag_id, $blog_id, $options);
283+
return parent::deleteByIdAndBlogId($id, $blog_id, $options);
281284
}
282285

283286
/**
284287
* idとblog_idをキーとした削除 + 付随情報も削除
285-
* @param array $ids
288+
* @param array|int $ids
286289
* @param $blog_id
287290
* @param array $options
288291
* @return bool
292+
* @noinspection PhpUnused
289293
*/
290-
public function deleteByIdsAndBlogId($ids, $blog_id, $options = array())
294+
public function deleteByIdsAndBlogId($ids, $blog_id, array $options = array())
291295
{
292296
// 単体ID対応
293297
if (is_numeric($ids)) {

‎app/src/Util/Log.php

-14
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ public static function getLogger(): LoggerInterface
3232
return static::$logger;
3333
}
3434

35-
/**
36-
* 過去のDebug::logと互換性を持ったメソッド
37-
* @param string $message
38-
* @param mixed $context
39-
* @param string $class
40-
* @param string $filename
41-
* @param int $line
42-
*/
43-
public static function old_log(string $message, $context, string $class = 'log', string $filename = "-", int $line = 0): void
44-
{
45-
$logger = static::getLogger();
46-
$logger->debug("[{$class}]{$filename}:{$line} {$message}", [$context]);
47-
}
48-
4935
/**
5036
* @param string $message
5137
* @param array $context

‎app/src/Web/Controller/Admin/CommonController.php

+12-26
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Fc2blog\Model\BlogSettingsModel;
1010
use Fc2blog\Model\BlogsModel;
1111
use Fc2blog\Model\CommentsModel;
12-
use Fc2blog\Model\MSDB;
12+
use Fc2blog\Model\PDOConnection;
13+
use Fc2blog\Model\PDOQuery;
1314
use Fc2blog\Model\PluginsModel;
1415
use Fc2blog\Model\UsersModel;
1516
use Fc2blog\Web\Cookie;
@@ -170,18 +171,14 @@ public function install(Request $request): string
170171
$is_connect = true;
171172
$connect_message = '';
172173
try {
173-
MSDB::getInstance()->connect(false, false);
174+
PDOConnection::createConnection();
174175
} catch (Exception $e) {
175176
$is_connect = false;
176177
$connect_message = $e->getMessage();
177178
}
178179
$this->set('is_connect', $is_connect);
179180
$this->set('connect_message', $connect_message);
180181

181-
// DB設定確認
182-
$is_character = version_compare(MSDB::getInstance()->getVersion(), '5.5.0') >= 0 || DB_CHARSET != 'UTF8MB4';
183-
$this->set('is_character', $is_character);
184-
185182
// ドメイン確認
186183
$is_domain = DOMAIN != 'domain';
187184
$this->set('is_domain', $is_domain);
@@ -191,8 +188,8 @@ public function install(Request $request): string
191188
$is_gd = function_exists('gd_info');
192189
$this->set('is_gd', $is_gd);
193190

194-
$is_all_ok = $is_write_temp && $is_write_upload && $is_db_connect_lib && $is_connect && $is_character && $is_domain;
195-
$this->set('is_all_ok', $is_all_ok);
191+
$is_all_ok = $is_write_temp && $is_write_upload && $is_db_connect_lib && $is_connect && $is_domain;
192+
$this->set('is_all_ok', $is_all_ok);
196193

197194
return 'admin/common/install.twig';
198195

@@ -211,29 +208,18 @@ public function install(Request $request): string
211208
}
212209

213210
// DB接続確認
214-
$msdb = MSDB::getInstance(true);
215211
try {
216212
// DB接続確認(DATABASEの存在判定含む)
217-
$msdb->connect();
213+
$pdo = PDOConnection::createConnection();
218214
} catch (Exception $e) {
219-
// データベースの作成
220-
$msdb->close();
221-
$msdb->connect(false, false);
222-
$sql = 'CREATE DATABASE IF NOT EXISTS ' . DB_DATABASE . ' CHARACTER SET ' . DB_CHARSET;
223-
$msdb->execute($sql);
224-
$msdb->close();
225-
try {
226-
// 作成できたか確認
227-
$msdb->connect();
228-
} catch (Exception $e) {
229-
$this->setErrorMessage(__('Execute `Create database` failed. Please `Create database` your self.'));
230-
$this->redirect($request, $request->baseDirectory . 'common/install?state=0&error=db_create');
231-
}
215+
$this->setErrorMessage(__('Please set correct the DB connection settings.'));
216+
$this->redirect($request, $request->baseDirectory . 'common/install?state=0&error=db_create');
217+
return "";
232218
}
233219

234220
// テーブルの存在チェック
235221
$sql = "SHOW TABLES LIKE 'users'";
236-
$table = MSDB::getInstance()->find($sql);
222+
$table = PDOQuery::find($pdo, $sql);
237223

238224
if (is_countable($table) && count($table)) {
239225
// 既にDB登録完了
@@ -246,15 +232,15 @@ public function install(Request $request): string
246232
if (DB_CHARSET != 'UTF8MB4') {
247233
$sql = str_replace('utf8mb4', strtolower(DB_CHARSET), $sql);
248234
}
249-
$res = MSDB::getInstance()->multiExecute($sql);
235+
$res = PDOQuery::multiExecute($pdo, $sql);
250236
if ($res === false) {
251237
$this->setErrorMessage(__('Create' . ' table failed.'));
252238
$this->redirect($request, $request->baseDirectory . 'common/install?state=0&error=table_insert');
253239
}
254240

255241
// DBセットアップ成功チェック
256242
$sql = "SHOW TABLES LIKE 'users'";
257-
$table = MSDB::getInstance()->find($sql);
243+
$table = PDOQuery::find($pdo, $sql);
258244
if (!is_countable($table)) {
259245
$this->setErrorMessage(__('Create' . ' table failed.'));
260246
$this->redirect($request, $request->baseDirectory . 'common/install?state=0&error=table_insert');

‎app/src/include/bootstrap.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
define('APP_DIR', realpath(__DIR__ . '/../../') . '/'); // APPディレクトリのパス
55

66
// DBの接続ライブラリ
7-
if (class_exists('mysqli')) {
8-
define('DB_CONNECT_LIB', 'mysqli');
9-
} else if (class_exists('PDO')) {
10-
define('DB_CONNECT_LIB', 'PDO');
11-
}
7+
define('DB_CONNECT_LIB', 'PDO');
128

139
// 環境設定読み込み
1410
\Fc2blog\Config::read(__DIR__ . '/../config/init_config.php');

‎app/twig_templates/admin/common/install.twig

+1-19
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
{% if not is_db_connect_lib %}
7979
<span style="color: red;">NG!</span>
8080
<hr/>
81-
<p class="ng">{{ _('Please enable pdo or mysqli') }}</p>
81+
<p class="ng">{{ _('Please enable pdo') }}</p>
8282
{% endif %}
8383
</li>
8484

@@ -121,24 +121,6 @@
121121
</table>
122122
</li>
123123

124-
{% if is_connect %}
125-
<li class="{% if is_character %}ok{% endif %}{% if not is_character %}ng{% endif %}">
126-
{{ _('Character code check of MySQL') }} . . .
127-
{% if is_character %}
128-
OK
129-
{% endif %}
130-
{% if not is_character %}
131-
<span style="color: red;">NG!</span>
132-
<hr/>
133-
<p class="ng">
134-
{{ _('You can not use the character code of UTF8MB4 because the version of MySQL is older') }}<br/>
135-
{{ _('Please change to UTF8 DB_CHARSET') }}<br/>
136-
{{ _('Example') }}) define('DB_CHARSET', 'UTF8');
137-
</p>
138-
{% endif %}
139-
</li>
140-
{% endif %}
141-
142124
<li class="{% if is_domain %}ok{% endif %}{% if not is_domain %}ng{% endif %}">
143125
{{ _('Check the configuration of the domain') }} . . .
144126
{% if is_domain %}

‎dist_zip/installer/fc2blog_installer.php

-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767
if (!extension_loaded('PDO')) {
6868
$list[] = "PDO notfound. ";
6969
}
70-
if (!extension_loaded('mysqli')) {
71-
$list[] = "mysqli notfound. ";
72-
}
7370
if (!extension_loaded('mbstring')) {
7471
$list[] = "mbstring notfound. ";
7572
}

‎tests/App/Controller/Admin/Common/InstallTest.php

-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function testInstallCheck(): void
4545
$this->assertTrue($d['is_db_connect_lib']);
4646
$this->assertTrue($d['is_connect']);
4747
$this->assertEquals(0, strlen($d['connect_message']));
48-
$this->assertTrue($d['is_character']);
4948
$this->assertTrue($d['is_domain']);
5049
$this->assertTrue($d['is_gd']);
5150
$this->assertTrue($d['is_all_ok']);
@@ -82,8 +81,6 @@ public function testInstallFailCheck(): void
8281
// 確認がむずかしい
8382
$this->assertEquals(0, strlen($d['connect_message']));
8483
// 確認がむずかしい
85-
$this->assertTrue($d['is_character']);
86-
// 確認がむずかしい
8784
$this->assertTrue($d['is_domain']);
8885
// 確認がむずかしい
8986
$this->assertTrue($d['is_gd']);

0 commit comments

Comments
 (0)
Please sign in to comment.