8
8
use Fc2blog \Web \Request ;
9
9
use InvalidArgumentException ;
10
10
use OutOfBoundsException ;
11
+ use PDOException ;
11
12
12
13
class BlogsModel extends Model
13
14
{
@@ -71,6 +72,7 @@ public static function isPasswordRegistered($blog_id): bool
71
72
* ディレクトリとして使用済みかどうか
72
73
* @param string $value
73
74
* @return bool|string
75
+ * @noinspection PhpUnused
74
76
*/
75
77
public static function usableDirectory (string $ value )
76
78
{
@@ -233,39 +235,44 @@ public static function getTemplateIds($blog): array
233
235
/**
234
236
* ブログの一覧(SelectBox用)
235
237
* @param $user_id
236
- * @return mixed
238
+ * @return array
237
239
*/
238
- public function getSelectList ($ user_id )
240
+ public function getSelectList ($ user_id ): array
239
241
{
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
+ }
246
253
}
247
254
248
255
/**
249
256
* ブログIDをキーにユーザーIDを条件としてブログを取得
250
- * @param $blog_id
257
+ * @param $id
251
258
* @param $user_id
252
259
* @param array $options
253
260
* @return mixed
254
261
*/
255
- public function findByIdAndUserId ($ blog_id , $ user_id , array $ options = []): array
262
+ public function findByIdAndUserId ($ id , $ user_id , array $ options = []): array
256
263
{
257
264
$ 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 );
259
266
return $ this ->find ('row ' , $ options );
260
267
}
261
268
262
269
/**
263
270
* ユーザーIDをキーにしてブログを取得
264
271
* @param $user_id
265
272
* @param array $options
266
- * @return mixed
273
+ * @return array
267
274
*/
268
- public function findByUserId ($ user_id , $ options = array ())
275
+ public function findByUserId ($ user_id , array $ options = array ())
269
276
{
270
277
$ options ['where ' ] = isset ($ options ['where ' ]) ? 'user_id=? AND ' . $ options ['where ' ] : 'user_id=? ' ;
271
278
$ options ['params ' ] = isset ($ options ['params ' ]) ? array_merge (array ($ user_id ), $ options ['params ' ]) : array ($ user_id );
@@ -286,7 +293,7 @@ public function findByRandom()
286
293
/**
287
294
* ログイン後最初に表示するブログを取得する
288
295
* @param $user
289
- * @return mixed
296
+ * @return array
290
297
*/
291
298
public function getLoginBlog ($ user )
292
299
{
@@ -311,7 +318,7 @@ public function getLoginBlog($user)
311
318
/**
312
319
* ユーザーIDをキーにブログのリストを取得
313
320
* @param int $user_id
314
- * @return mixed
321
+ * @return array
315
322
*/
316
323
public function getListByUserId (int $ user_id )
317
324
{
@@ -349,7 +356,7 @@ public function insert(array $data, array $options = [])
349
356
{
350
357
// 主キーがauto_incrementじゃないのでreturn値の受け取り方を変更
351
358
$ 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 ;
353
360
if (!parent ::insert ($ data , $ options )) {
354
361
return false ;
355
362
}
@@ -496,7 +503,7 @@ public static function regeneratePluginPhpByBlogId(string $blog_id): void
496
503
* @param array $values
497
504
* @param $id
498
505
* @param array $options
499
- * @return array|false| int|mixed
506
+ * @return array|int
500
507
*/
501
508
public function updateById (array $ values , $ id , array $ options = [])
502
509
{
@@ -507,7 +514,8 @@ public function updateById(array $values, $id, array $options = [])
507
514
/**
508
515
* 最終投稿日時更新
509
516
* @param $id
510
- * @return array|false|int|mixed
517
+ * @return array|int
518
+ * @noinspection PhpUnused
511
519
*/
512
520
public function updateLastPostedAt ($ id )
513
521
{
@@ -519,7 +527,7 @@ public function updateLastPostedAt($id)
519
527
* テンプレートの切り替え
520
528
* @param array $blog_template
521
529
* @param string $blog_id
522
- * @return array|false| int|mixed
530
+ * @return array|int
523
531
*/
524
532
public function switchTemplate (array $ blog_template , string $ blog_id )
525
533
{
@@ -533,13 +541,12 @@ public function switchTemplate(array $blog_template, string $blog_id)
533
541
$ reply_type = strstr ($ blog_template ['html ' ], '<%comment_reply_body> ' ) ?
534
542
Config::get ('BLOG_TEMPLATE.COMMENT_TYPE.REPLY ' ) : Config::get ('BLOG_TEMPLATE.COMMENT_TYPE.AFTER ' );
535
543
// コメントの表示タイプを更新
536
- Model:: load ( ' BlogSettings ' )->updateReplyType ($ device_type , $ reply_type , $ blog_id );
544
+ ( new BlogSettingsModel () )->updateReplyType ($ device_type , $ reply_type , $ blog_id );
537
545
538
546
$ ret = $ this ->updateById ($ data , $ blog_id );
539
547
540
548
if ($ ret ) {
541
549
// 更新に成功した場合 現在のテンプレートを削除
542
- Model::load ('BlogTemplates ' );
543
550
$ template_path = BlogTemplatesModel::getTemplateFilePath ($ blog_id , $ device_type );
544
551
is_file ($ template_path ) && unlink ($ template_path );
545
552
$ css_path = BlogTemplatesModel::getCssFilePath ($ blog_id , $ device_type );
@@ -556,7 +563,7 @@ public function switchTemplate(array $blog_template, string $blog_id)
556
563
* @param array $options
557
564
* @return bool|int
558
565
*/
559
- public function deleteByIdAndUserId ($ blog_id , int $ user_id , $ options = array ())
566
+ public function deleteByIdAndUserId ($ blog_id , int $ user_id , array $ options = array ())
560
567
{
561
568
if (!parent ::deleteById ($ blog_id , array ('where ' => 'user_id=? ' , 'params ' => array ($ user_id )))) {
562
569
return 0 ;
@@ -635,6 +642,7 @@ static public function isCorrectHttpSchemaByBlog(Request $request, Blog $blog):
635
642
* @param Request $request
636
643
* @param string $blog_id
637
644
* @return bool
645
+ * @noinspection PhpUnused
638
646
*/
639
647
static public function isCorrectHttpSchemaByBlogId (Request $ request , string $ blog_id ): bool
640
648
{
@@ -762,6 +770,7 @@ static public function getDefaultBlogId(): ?string
762
770
/**
763
771
* @param Request $request
764
772
* @return string|null
773
+ * @noinspection PhpUnused
765
774
*/
766
775
static public function getBlogIdByRequestOrDefault (Request $ request ): ?string
767
776
{
0 commit comments