Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSDB削除、MysqliWrap削除、PDOWrapリファクタ、Model周りリファクタ等 #331 #332

Merged
merged 21 commits into from
Jun 13, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: mbstring, gd, gettext, fileinfo, pdo, pdo_mysql, mysqli, zip
extensions: mbstring, gd, gettext, fileinfo, pdo, pdo_mysql, zip

- uses: actions/checkout@v2

Binary file modified app/locale/en_US.UTF-8/LC_MESSAGES/messages.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions app/locale/en_US.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -1119,7 +1119,7 @@ msgid "Check connection library with MySQL"
msgstr ""

#: shell/../view/admin/common/install.html:78
msgid "Please enable pdo or mysqli"
msgid "Please enable pdo"
msgstr ""

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

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

msgid "(If not exists, will be try create)"
msgstr ""
Binary file modified app/locale/ja_JP.UTF-8/LC_MESSAGES/messages.mo
Binary file not shown.
8 changes: 4 additions & 4 deletions app/locale/ja_JP.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -1109,8 +1109,8 @@ msgid "Check connection library with MySQL"
msgstr "MySQLとの接続ライブラリチェック"

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

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

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

msgid "(If not exists, will be try create)"
msgstr "(未作成の場合、作成を試行します)"
53 changes: 31 additions & 22 deletions app/src/Model/BlogsModel.php
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
use Fc2blog\Web\Request;
use InvalidArgumentException;
use OutOfBoundsException;
use PDOException;

class BlogsModel extends Model
{
@@ -71,6 +72,7 @@ public static function isPasswordRegistered($blog_id): bool
* ディレクトリとして使用済みかどうか
* @param string $value
* @return bool|string
* @noinspection PhpUnused
*/
public static function usableDirectory(string $value)
{
@@ -233,39 +235,44 @@ public static function getTemplateIds($blog): array
/**
* ブログの一覧(SelectBox用)
* @param $user_id
* @return mixed
* @return array
*/
public function getSelectList($user_id)
public function getSelectList($user_id): array
{
return $this->find('list', array(
'fields' => array('id', 'name'),
'where' => 'user_id=?',
'params' => array($user_id),
'order' => 'created_at DESC',
));
try {
return $this->find('list', array(
'fields' => array('id', 'name'),
'where' => 'user_id=?',
'params' => array($user_id),
'order' => 'created_at DESC',
));
} catch (PDOException $e) {
// インストール前や初期化前など、クエリが出来ないケースがある
return [];
}
}

/**
* ブログIDをキーにユーザーIDを条件としてブログを取得
* @param $blog_id
* @param $id
* @param $user_id
* @param array $options
* @return mixed
*/
public function findByIdAndUserId($blog_id, $user_id, array $options = []): array
public function findByIdAndUserId($id, $user_id, array $options = []): array
{
$options['where'] = isset($options['where']) ? 'id=? AND user_id=? AND ' . $options['where'] : 'id=? AND user_id=?';
$options['params'] = isset($options['params']) ? array_merge(array($blog_id, $user_id), $options['params']) : array($blog_id, $user_id);
$options['params'] = isset($options['params']) ? array_merge(array($id, $user_id), $options['params']) : array($id, $user_id);
return $this->find('row', $options);
}

/**
* ユーザーIDをキーにしてブログを取得
* @param $user_id
* @param array $options
* @return mixed
* @return array
*/
public function findByUserId($user_id, $options = array())
public function findByUserId($user_id, array $options = array())
{
$options['where'] = isset($options['where']) ? 'user_id=? AND ' . $options['where'] : 'user_id=?';
$options['params'] = isset($options['params']) ? array_merge(array($user_id), $options['params']) : array($user_id);
@@ -286,7 +293,7 @@ public function findByRandom()
/**
* ログイン後最初に表示するブログを取得する
* @param $user
* @return mixed
* @return array
*/
public function getLoginBlog($user)
{
@@ -311,7 +318,7 @@ public function getLoginBlog($user)
/**
* ユーザーIDをキーにブログのリストを取得
* @param int $user_id
* @return mixed
* @return array
*/
public function getListByUserId(int $user_id)
{
@@ -349,7 +356,7 @@ public function insert(array $data, array $options = [])
{
// 主キーがauto_incrementじゃないのでreturn値の受け取り方を変更
$data['created_at'] = $data['updated_at'] = date('Y-m-d H:i:s');
$options['result'] = DBInterface::RESULT_SUCCESS;
$options['result'] = PDOQuery::RESULT_SUCCESS;
if (!parent::insert($data, $options)) {
return false;
}
@@ -496,7 +503,7 @@ public static function regeneratePluginPhpByBlogId(string $blog_id): void
* @param array $values
* @param $id
* @param array $options
* @return array|false|int|mixed
* @return array|int
*/
public function updateById(array $values, $id, array $options = [])
{
@@ -507,7 +514,8 @@ public function updateById(array $values, $id, array $options = [])
/**
* 最終投稿日時更新
* @param $id
* @return array|false|int|mixed
* @return array|int
* @noinspection PhpUnused
*/
public function updateLastPostedAt($id)
{
@@ -519,7 +527,7 @@ public function updateLastPostedAt($id)
* テンプレートの切り替え
* @param array $blog_template
* @param string $blog_id
* @return array|false|int|mixed
* @return array|int
*/
public function switchTemplate(array $blog_template, string $blog_id)
{
@@ -533,13 +541,12 @@ public function switchTemplate(array $blog_template, string $blog_id)
$reply_type = strstr($blog_template['html'], '<%comment_reply_body>') ?
Config::get('BLOG_TEMPLATE.COMMENT_TYPE.REPLY') : Config::get('BLOG_TEMPLATE.COMMENT_TYPE.AFTER');
// コメントの表示タイプを更新
Model::load('BlogSettings')->updateReplyType($device_type, $reply_type, $blog_id);
(new BlogSettingsModel())->updateReplyType($device_type, $reply_type, $blog_id);

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

if ($ret) {
// 更新に成功した場合 現在のテンプレートを削除
Model::load('BlogTemplates');
$template_path = BlogTemplatesModel::getTemplateFilePath($blog_id, $device_type);
is_file($template_path) && unlink($template_path);
$css_path = BlogTemplatesModel::getCssFilePath($blog_id, $device_type);
@@ -556,7 +563,7 @@ public function switchTemplate(array $blog_template, string $blog_id)
* @param array $options
* @return bool|int
*/
public function deleteByIdAndUserId($blog_id, int $user_id, $options = array())
public function deleteByIdAndUserId($blog_id, int $user_id, array $options = array())
{
if (!parent::deleteById($blog_id, array('where' => 'user_id=?', 'params' => array($user_id)))) {
return 0;
@@ -635,6 +642,7 @@ static public function isCorrectHttpSchemaByBlog(Request $request, Blog $blog):
* @param Request $request
* @param string $blog_id
* @return bool
* @noinspection PhpUnused
*/
static public function isCorrectHttpSchemaByBlogId(Request $request, string $blog_id): bool
{
@@ -762,6 +770,7 @@ static public function getDefaultBlogId(): ?string
/**
* @param Request $request
* @return string|null
* @noinspection PhpUnused
*/
static public function getBlogIdByRequestOrDefault(Request $request): ?string
{
9 changes: 5 additions & 4 deletions app/src/Model/CategoriesModel.php
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ public function validate(array $data, ?array &$valid_data = [], array $white_lis
* @param $data
* @param $model
* @return bool|string
* @noinspection PhpUnusedParameterInspection
*/
public static function uniqueName($value, $option, $key, $data, $model)
{
@@ -183,7 +184,7 @@ public function getEntryCategories($blog_id, $entry_id)
SQL;
$params = array($blog_id, $entry_id, $blog_id);
$options = array();
$options['result'] = DBInterface::RESULT_ALL;
$options['result'] = PDOQuery::RESULT_ALL;
return $this->findSql($sql, $params, $options);
}

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

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

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

2 changes: 1 addition & 1 deletion app/src/Model/CommentsModel.php
Original file line number Diff line number Diff line change
@@ -594,7 +594,7 @@ public function updateApproval($blog_id, $comment_id = null)
$params[] = $comment_id;
}
$sql .= ' AND open_status=' . Config::get('COMMENT.OPEN_STATUS.PENDING');
$options['result'] = DBInterface::RESULT_SUCCESS;
$options['result'] = PDOQuery::RESULT_SUCCESS;
return $this->executeSql($sql, $params, $options);
}

32 changes: 0 additions & 32 deletions app/src/Model/DBInterface.php

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/Model/EntriesModel.php
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ public function getArchives($blog_id)
ORDER BY concat(year, month) DESC;
SQL;
$params = array($blog_id);
$options = array('result' => DBInterface::RESULT_ALL);
$options = array('result' => PDOQuery::RESULT_ALL);
return $this->findSql($sql, $params, $options);
}

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

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

Loading