Skip to content

Commit 2393fe4

Browse files
committed
Merge branch '5.1.x' into 5.2.x
2 parents 38d5b19 + bac840f commit 2393fe4

File tree

7 files changed

+140
-3
lines changed

7 files changed

+140
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ node_modules
118118
/webroot/bc_custom_content
119119
/webroot/bc_spa_sample
120120
/webroot/debug_kit
121+
/webroot/.gitignore
122+
121123
# key
122124
/config/*.key
123125
/config/*.pem

config/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export TRUST_PROXY="false"
3838
# export HASH_TYPE="sha1"
3939
# export SECURITY_SALT=""
4040

41+
4142
# Uncomment these to define cache configuration via environment variables.
4243
#export CACHE_DURATION="+2 minutes"
4344
#export CACHE_DEFAULT_URL="file://tmp/cache/?prefix=${APP_NAME}_default&duration=${CACHE_DURATION}"

plugins/baser-core/src/Controller/ContentFoldersController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use BaserCore\Annotation\Checked;
1717
use BaserCore\Annotation\UnitTest;
1818
use BaserCore\Service\Front\ContentFoldersFrontServiceInterface;
19+
use BaserCore\Service\SiteConfigsService;
20+
use BaserCore\Service\SiteConfigsServiceInterface;
1921

2022
/**
2123
* Class ContentFoldersController
@@ -48,6 +50,12 @@ public function initialize(): void
4850
*/
4951
public function view(ContentFoldersFrontServiceInterface $service)
5052
{
53+
// コンテンツフォルダのindex機能を使用しないときは403にする
54+
$siteConfigsService = $this->getService(SiteConfigsServiceInterface::class);
55+
$siteConfig = $siteConfigsService->get();
56+
if (!empty($siteConfig->use_contents_folder_forbidden)) {
57+
throw new \Cake\Http\Exception\ForbiddenException(__d('baser_core', 'indexページが見つかりませんでした。'));
58+
}
5159
$contentFolder = $service->get(
5260
$this->getRequest()->getAttribute('currentContent')->entity_id,
5361
['status' => 'publish']

plugins/bc-admin-third/templates/Admin/SiteConfigs/index.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,25 @@ class="bca-collapse__btn"
421421
</td>
422422
</tr>
423423

424+
<tr>
425+
<th class="col-head bca-form-table__label">
426+
<?php echo $this->BcAdminForm->label('use_contents_folder_forbidden', __d('baser_core', 'コンテンツフォルダ')) ?>
427+
</th>
428+
<td class="col-input bca-form-table__input">
429+
<?php
430+
echo $this->BcAdminForm->control('use_contents_folder_forbidden', [
431+
'type' => 'checkbox',
432+
'label' => __d('baser_core', 'コンテンツフォルダの一覧機能を利用しない')
433+
]);
434+
?>
435+
<i class="bca-icon--question-circle bca-help"></i>
436+
<div class="bca-helptext">
437+
<?php echo __d('baser_core', 'indexページの無いコンテツフォルダにアクセスした際に、<br>一覧機能を使わずに403を返します。') ?>
438+
</div>
439+
<?php echo $this->BcAdminForm->error('use_contents_folder_forbidden') ?>
440+
</td>
441+
</tr>
442+
424443
<?php echo $this->BcAdminForm->dispatchAfterForm('Site') ?>
425444

426445
</table>

plugins/bc-custom-content/src/Model/Table/CustomContentsTable.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,31 @@ public function createSearchIndex($entity)
119119
];
120120
}
121121

122+
/**
123+
* 関連するエントリーの検索インデックスを作成する
124+
*
125+
* @param EntityInterface $entity
126+
* @return void
127+
*/
128+
public function createRelatedSearchIndexes(EntityInterface $entity)
129+
{
130+
if (!$entity || !isset($entity->custom_table_id)) {
131+
return;
132+
}
133+
$customEntriyTable = $this->CustomTables->getTableLocator()->get('BcCustomContent.CustomEntries');
134+
$customEntriyTable->setUp($entity->custom_table_id);
135+
136+
$entries = $customEntriyTable->find()
137+
->all();
138+
if (!$entries->count()) {
139+
return;
140+
}
141+
142+
foreach ($entries as $entry) {
143+
// 入れ子になっているとエラーになるため、一旦配列に変換してから再度patchEntityする
144+
$entry = $entry->toArray();
145+
$entity = $customEntriyTable->patchEntity($customEntriyTable->newEmptyEntity(), $entry);
146+
$customEntriyTable->save($entity);
147+
}
148+
}
122149
}

plugins/bc-custom-content/src/Model/Table/CustomEntriesTable.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,44 @@ public function createSearchIndex(CustomEntry $entry)
9696
/** @var Content $content */
9797
if (!$customContent) return false;
9898
$content = $customContent->content;
99+
100+
$status = $entry->status;
101+
$publishBegin = $entry->publish_begin;
102+
$publishEnd = $entry->publish_end;
103+
// コンテンツのステータスを優先する
104+
if (!$content->status) {
105+
$status = false;
106+
}
107+
108+
if ($publishBegin) {
109+
if ((!empty($content->publish_begin) && $content->publish_begin > $publishBegin)) {
110+
// コンテンツの公開開始の方が遅い場合
111+
$publishBegin = $content->publish_begin;
112+
} elseif (!empty($content->publish_end) && $content->publish_end < $publishBegin) {
113+
// 記事の公開開始より、コンテンツの公開終了が早い場合
114+
$publishBegin = $content->publish_end;
115+
}
116+
} else {
117+
if (!empty($content->publish_begin)) {
118+
// 記事の公開開始が定められていない
119+
$publishBegin = $content->publish_begin;
120+
}
121+
}
122+
if ($publishEnd) {
123+
if (!empty($content->publish_end) && $content->publish_end < $publishEnd) {
124+
// コンテンツの公開終了の方が早い場合
125+
$publishEnd = $content->publish_end;
126+
} elseif (!empty($content->publish_begin) && $content->publish_begin < $publishEnd) {
127+
// 記事の公開終了より、コンテンツの公開開始が早い場合
128+
$publishEnd = $content->publish_begin;
129+
}
130+
} else {
131+
if (!empty($content->publish_end)) {
132+
// 記事の公開終了が定められていない
133+
$publishEnd = $content->publish_end;
134+
}
135+
}
136+
99137
return [
100138
'type' => __d('baser_core', 'カスタムコンテンツ'),
101139
'model_id' => $entry->id,
@@ -104,9 +142,9 @@ public function createSearchIndex(CustomEntry $entry)
104142
'title' => $entry->title,
105143
'detail' => $this->createSearchDetail($entry),
106144
'url' => $content->url . 'view/' . ($entry->name?: $entry->id),
107-
'status' => $content->status,
108-
'publish_begin' => $content->publish_begin,
109-
'publish_end' => $content->publish_end
145+
'status' => $status,
146+
'publish_begin' => $publishBegin,
147+
'publish_end' => $publishEnd
110148
];
111149
}
112150

plugins/bc-custom-content/tests/TestCase/Model/Table/CustomContentsTableTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@
1212
namespace BcCustomContent\Test\TestCase\Model\Table;
1313

1414
use ArrayObject;
15+
use BaserCore\Service\BcDatabaseServiceInterface;
1516
use BaserCore\Service\PluginsServiceInterface;
1617
use BaserCore\TestSuite\BcTestCase;
18+
use BaserCore\Utility\BcContainerTrait;
1719
use BcCustomContent\Model\Table\CustomContentsTable;
1820
use BcCustomContent\Service\CustomContentsService;
1921
use BcCustomContent\Test\Factory\CustomContentFactory;
2022
use BcCustomContent\Test\Scenario\CustomContentsScenario;
2123
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;
2224
use BcCustomContent\Service\CustomContentsServiceInterface;
25+
use BcCustomContent\Service\CustomEntriesServiceInterface;
26+
use BcCustomContent\Test\Scenario\CustomTablesScenario;
2327
use Cake\Event\Event;
2428

2529
/**
@@ -33,6 +37,7 @@ class CustomContentsTableTest extends BcTestCase
3337
* ScenarioAwareTrait
3438
*/
3539
use ScenarioAwareTrait;
40+
use BcContainerTrait;
3641

3742
/**
3843
* Set up
@@ -131,6 +136,43 @@ public function test_createSearchIndex()
131136
$this->assertEquals($rs['publish_end'], '2021-12-31 23:59:59');
132137
}
133138

139+
/**
140+
* test createRelatedSearchIndexes
141+
*/
142+
public function test_createRelatedSearchIndexes()
143+
{
144+
$this->loadFixtureScenario(CustomContentsScenario::class);
145+
$this->loadFixtureScenario(CustomTablesScenario::class);
146+
$customEntriesService = $this->getService(CustomEntriesServiceInterface::class);
147+
$dataBaseService = $this->getService(BcDatabaseServiceInterface::class);
148+
$customEntriesService->setUp(2);
149+
150+
$customEntriesService->create([
151+
'custom_table_id' => 2,
152+
'name' => 'テスト職種1',
153+
'title' => 'テスト職種1',
154+
'status' => 1,
155+
'creator_id' => 1
156+
]);
157+
$customEntriesService->create([
158+
'custom_table_id' => 2,
159+
'name' => 'テスト職種2',
160+
'title' => 'テスト職種2',
161+
'status' => 1,
162+
'creator_id' => 1
163+
]);
164+
165+
$customContentService = new CustomContentsService();
166+
$customContent = $customContentService->get(2);
167+
168+
$this->CustomContentsTable->createRelatedSearchIndexes($customContent);
169+
170+
$searchIndexesTable = $this->getTableLocator()->get('BcSearchIndex.SearchIndexes');
171+
$this->assertEquals(2, $searchIndexesTable->find()->count());
172+
173+
$dataBaseService->dropTable('custom_entry_2_occupations');
174+
}
175+
134176
/**
135177
* test beforeSave
136178
*/

0 commit comments

Comments
 (0)