Skip to content

Commit

Permalink
マーキング漏れを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Oct 10, 2023
1 parent fddf2da commit 818fc44
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function edit(BlogContentsAdminServiceInterface $service, int $id)
'data' => $this->getRequest()->getData()
]);
if ($event !== false) {
$data = ($event->getResult() === null || $event->getResult() === true) ? $event->getData('data') : $event->getResult();
$data = ($event->getResult() === null || $event->getResult() === true)? $event->getData('data') : $event->getResult();
$this->setRequest($this->getRequest()->withParsedBody($data));
}
try {
Expand Down Expand Up @@ -112,8 +112,11 @@ public function edit(BlogContentsAdminServiceInterface $service, int $id)
* ブログテンプレート編集画面にリダイレクトする
*
* @param string $template
* @return ResponseInterface
* @checked
* @noTodo
*/
protected function redirectEditBlog($template)
protected function redirectEditBlog(string $template): ResponseInterface
{
$path = 'Blog' . DS . $template;
$theme = BcUtil::getCurrentTheme();
Expand Down
82 changes: 18 additions & 64 deletions plugins/bc-blog/src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,13 @@ public function initialize(): void
/**
* beforeFilter
* @return void
* @checked
*/
public function beforeFilter(EventInterface $event)
{
$response = parent::beforeFilter($event);
if($response) return $response;

$blogContentId = null;

if ($this->request->getParam('action') !== 'tags') {
if (!empty($this->request->getParam('entityId'))) {
$blogContentId = $this->request->getParam('entityId');
} elseif (!empty($this->request->getParam('pass'))) {
// 後方互換のため pass もチェック
$blogContentId = $this->request->getParam('pass');
}
}

// if (empty($this->request->getAttribute('currentContent'))) {
// // ウィジェット系の際にコンテンツ管理上のURLでないので自動取得できない
// $content = $this->BcContents->getContent($blogContentId);
// if ($content) {
// $this->request = $this->request->withParam('Content', $content['Content']);
// $this->request = $this->request->withParam('Site', $content['Site']);
// }
// }

// コメント送信用のトークンを出力する為にセキュリティコンポーネントを利用しているが、
// 表示用のコントローラーなのでポストデータのチェックは必要ない
if ($response) return $response;
// TODO ブログコメントの送信でエラーとなるため、一時的に無効化している
$this->Security->setConfig('validatePost', false);
}

Expand All @@ -106,8 +85,8 @@ public function index(
BlogContentsServiceInterface $blogContentsService,
BlogPostsServiceInterface $blogPostsService)
{
$currentContent = $this->getRequest()->getAttribute('currentContent');
$blogContentId = (int) $currentContent?->entity_id;
$currentContent = $this->getRequest()->getAttribute('currentContent');
$blogContentId = (int)$currentContent?->entity_id;

/* @var BlogContent $blogContent */
$blogContent = $blogContentsService->get(
Expand Down Expand Up @@ -208,7 +187,7 @@ public function archives(
break;

case 'author':
if(count($pass) > 2) $this->notFound();
if (count($pass) > 2) $this->notFound();
$author = isset($pass[1])? $pass[1] : '';
$this->set($service->getViewVarsForArchivesByAuthor(
$this->paginate($blogPostsService->getIndexByAuthor($author, [
Expand All @@ -222,7 +201,7 @@ public function archives(
break;

case 'tag':
if(count($pass) > 2) $this->notFound();
if (count($pass) > 2) $this->notFound();
$tag = isset($pass[1])? $pass[1] : '';
$this->set($service->getViewVarsForArchivesByTag(
$this->paginate($blogPostsService->getIndexByTag($tag, [
Expand All @@ -236,7 +215,7 @@ public function archives(
break;

case 'date':
if(count($pass) > 4) $this->notFound();
if (count($pass) > 4) $this->notFound();
$year = $month = $day = '';
if (isset($pass[1]) && preg_match('/^\d{4}$/', $pass[1])) {
$year = $pass[1];
Expand All @@ -261,7 +240,7 @@ public function archives(
break;

default:
if(count($pass) > 1) $this->notFound();
if (count($pass) > 1) $this->notFound();
$this->set($service->getViewVarsForSingle(
$this->getRequest(),
$blogContent,
Expand All @@ -277,33 +256,6 @@ public function archives(
$this->render($template);
}

/**
* 記事リストを出力
* requestAction用
*
* @param int $blogContentId
* @param mixed $num
*/
public function posts($blogContentId, $limit = 5)
{
if (!empty($this->request->getParam('named.template'))) {
$template = $this->request->getParam('named.template');
} else {
$template = 'posts';
}

$this->request->withParam('named.template', null);

$this->layout = null;
$this->contentId = $blogContentId;

$datas = $this->_getBlogPosts(['num' => $limit]);

$this->set('posts', $datas);

$this->render($this->blogContent['BlogContent']['template'] . DS . $template);
}

/**
* 全体タグ一覧
* @param $name
Expand Down Expand Up @@ -353,13 +305,13 @@ public function ajax_add_comment(BlogCommentsServiceInterface $service, BcCaptch
$blogContent = $service->getBlogContent($postData['blog_content_id']);
try {
if ($blogContent->auth_captcha && !$bcCaptchaService->check(
$this->getRequest(),
$this->getRequest()->getData('captcha_id'),
$this->getRequest()->getData('auth_captcha')
)) {
$this->getRequest(),
$this->getRequest()->getData('captcha_id'),
$this->getRequest()->getData('auth_captcha')
)) {
$message = __d('baser_core', '画像の文字が間違っています。再度入力してください。');
return $this->response->withStatus(400)->withStringBody(json_encode([
'message'=> $message
'message' => $message
]));
}
$entity = $service->add($postData['blog_content_id'], $postData['blog_post_id'], $postData);
Expand All @@ -373,12 +325,12 @@ public function ajax_add_comment(BlogCommentsServiceInterface $service, BcCaptch
} catch (BcException $e) {
$message = $e->getMessage();
return $this->response->withStatus(400)->withStringBody(json_encode([
'message'=> $message
'message' => $message
]));
} catch (Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage());
return $this->response->withStatus(500)->withStringBody(json_encode([
'message'=> $message
'message' => $message
]));
}

Expand All @@ -399,6 +351,8 @@ public function ajax_add_comment(BlogCommentsServiceInterface $service, BcCaptch
* 認証用のキャプチャ画像を表示する
*
* @return void
* @checked
* @noTodo
*/
public function captcha(BcCaptchaServiceInterface $service, string $token)
{
Expand Down
31 changes: 16 additions & 15 deletions plugins/bc-blog/src/Event/BcBlogViewEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use Cake\Event\Event;
use Cake\Utility\Inflector;
use Cake\View\View;

/**
Expand All @@ -35,20 +34,22 @@ class BcBlogViewEventListener extends \BaserCore\Event\BcViewEventListener
'leftOfToolbar'
];

/**
* leftOfToolbar
* @param Event $event
*/
public function leftOfToolbar(Event $event)
{
if(BcUtil::isAdminSystem()) return;
$view = $event->getSubject();
$content = $view->getRequest()->getAttribute('currentContent');
if(!$content) return;
if ($content->type === 'BlogContent') {
echo $view->element('BcBlog.BlogPosts/left_of_toolbar');
}
}
/**
* leftOfToolbar
* @param Event $event
* @checked
* @noTodo
*/
public function leftOfToolbar(Event $event)
{
if (BcUtil::isAdminSystem()) return;
$view = $event->getSubject();
$content = $view->getRequest()->getAttribute('currentContent');
if (!$content) return;
if ($content->type === 'BlogContent') {
echo $view->element('BcBlog.BlogPosts/left_of_toolbar');
}
}

/**
* Before render
Expand Down
3 changes: 2 additions & 1 deletion plugins/bc-blog/src/Model/Table/BlogCategoriesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Cake\Datasource\EntityInterface;
use Cake\Datasource\ResultSetInterface;
use Cake\Event\EventInterface;
use Cake\ORM\Exception\PersistenceFailedException;
use Cake\Routing\Router;
use Cake\Validation\Validator;
use BaserCore\Annotation\NoTodo;
Expand Down Expand Up @@ -349,6 +348,8 @@ public function hasNewCategoryAddablePermission($userGroupId, $blogContentId)
*
* @param int $id
* @return bool
* @checked
* @noTodo
*/
public function hasChild($id)
{
Expand Down
9 changes: 6 additions & 3 deletions plugins/bc-blog/src/Model/Table/BlogCommentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

namespace BcBlog\Model\Table;

use BaserCore\Annotation\UnitTest;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
Expand All @@ -29,22 +30,24 @@ class BlogCommentsTable extends BlogAppTable
*
* @param Validator $validator
* @return Validator
* @checked
* @noTodo
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->scalar('name')
->notEmptyString('name', __d('baser_core', 'お名前を入力してください。'))
->notEmptyString('name', __d('baser_core', 'お名前を入力してください。'))
->maxLength('name', 50, __d('baser_core', 'お名前は50文字以内で入力してください。'));
$validator
->scalar('email')
->allowEmptyString('email')
->email('email', false, __d('baser_core', 'Eメールの形式が不正です。'))
->email('email', false, __d('baser_core', 'Eメールの形式が不正です。'))
->maxLength('email', 255, __d('baser_core', 'Eメールは255文字以内で入力してください。'));
$validator
->scalar('url')
->allowEmptyString('url')
->url('url', __d('baser_core', 'URLの形式が不正です。'))
->url('url', __d('baser_core', 'URLの形式が不正です。'))
->maxLength('url', 255, __d('baser_core', 'URLは255文字以内で入力してください。'));
$validator
->scalar('message')
Expand Down
15 changes: 9 additions & 6 deletions plugins/bc-blog/src/Model/Table/BlogContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public function createSearchIndex($blogContent)
*
* @param EntityInterface $entity
* @return void
* @checked
* @noTodo
*/
public function createRelatedSearchIndexes(EntityInterface $entity)
{
Expand All @@ -174,7 +176,7 @@ public function createRelatedSearchIndexes(EntityInterface $entity)
->where(['BlogPosts.blog_content_id' => $entity->id])
->contain(['BlogContents' => ['Contents']])
->all();
if(!$entities->count()) return;
if (!$entities->count()) return;
foreach($entities as $entity) {
// 保存するために強制的に dirty に設定
$entity->setDirty('id');
Expand All @@ -199,7 +201,8 @@ public function copy(
string $newTitle,
int $newAuthorId,
int $newSiteId = null
) {
)
{
$data = $this->find()->where(['BlogContents.id' => $id])->contain('Contents')->first();
$oldData = clone $data;

Expand All @@ -226,8 +229,8 @@ public function copy(
'author_id' => $newAuthorId,
'site_id' => $newSiteId,
'exclude_search' => false,
'description' => $data->content->description,
'eyecatch' => $data->content->eyecatch
'description' => $data->content->description,
'eyecatch' => $data->content->eyecatch
]);
$newBlogContent = $this->patchEntity($this->newEmptyEntity(), $data->toArray());
if (!is_null($newSiteId) && $siteId != $newSiteId) {
Expand All @@ -240,7 +243,7 @@ public function copy(

try {
$result = $this->save($newBlogContent);
if(!$result) {
if (!$result) {
$this->getConnection()->rollback();
return false;
}
Expand All @@ -249,7 +252,7 @@ public function copy(
->where(['BlogPosts.blog_content_id' => $id])
->order(['BlogPosts.id'])
->all();
if($blogPosts) {
if ($blogPosts) {
foreach($blogPosts as $blogPost) {
$blogPost->blog_category_id = null;
$blogPost->blog_content_id = $newBlogContent->id;
Expand Down
Loading

0 comments on commit 818fc44

Please sign in to comment.