Skip to content

Commit

Permalink
Merge branch '5.1.x' into fix-3703-2
Browse files Browse the repository at this point in the history
# Conflicts:
#	plugins/bc-installer/src/Command/InstallCommand.php
  • Loading branch information
seto1 committed Sep 13, 2024
2 parents 54cb1dd + 4608ef4 commit dc25e11
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 346 deletions.
42 changes: 0 additions & 42 deletions config/test_install.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ q {}","",""
"23","use_site_device_setting","0","",""
"24","use_site_lang_setting","0","",""
"25","use_update_notice","1","",""
"26","contents_sort_last_modified","","",""
"27","mail_additional_parameters","","",""
"28","outer_service_output_header","","",""
"29","outer_service_output_footer","","",""
"30","allow_simple_password","0","",""
"31","password_reset_days","","",""
"32","use_two_factor_authentication","0","",""
"26","mail_additional_parameters","","",""
"27","outer_service_output_header","","",""
"28","outer_service_output_footer","","",""
"29","allow_simple_password","0","",""
"30","password_reset_days","","",""
"31","use_two_factor_authentication","0","",""
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ q {}","",""
"23","use_site_device_setting","0","",""
"24","use_site_lang_setting","0","",""
"25","use_update_notice","1","",""
"26","contents_sort_last_modified","","",""
"27","mail_additional_parameters","","",""
"28","outer_service_output_header","","",""
"29","outer_service_output_footer","","",""
"30","allow_simple_password","0","",""
"31","password_reset_days","","",""
"32","use_two_factor_authentication","0","",""
"26","mail_additional_parameters","","",""
"27","outer_service_output_header","","",""
"28","outer_service_output_footer","","",""
"29","allow_simple_password","0","",""
"30","password_reset_days","","",""
"31","use_two_factor_authentication","0","",""
7 changes: 0 additions & 7 deletions plugins/baser-core/config/Seeds/SiteConfigsSeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,6 @@ public function run(): void
'created' => '',
'modified' => ''
],
[
'id' => '25',
'name' => 'contents_sort_last_modified',
'value' => '',
'created' => '',
'modified' => ''
],
[
'id' => '26',
'name' => 'mail_additional_parameters',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public function index(ContentsAdminServiceInterface $service, SiteConfigsService

switch($this->getRequest()->getQuery('list_type')) {
case 1:
// 並び替え最終更新時刻をリセット
$siteConfigService->resetValue('contents_sort_last_modified');
$contents = $service->getTreeIndex($this->getRequest()->getQueryParams());
break;
case 2:
Expand Down
42 changes: 19 additions & 23 deletions plugins/baser-core/src/Controller/Api/Admin/ContentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,30 +490,26 @@ public function move(ContentsServiceInterface $service)
{
$this->request->allowMethod(['post', 'put', 'patch']);
$url = $content = $errors = null;
if (!$service->isTreeModifiedByAnotherUser($this->getRequest()->getData('listDisplayed'))) {
try {
$beforeContent = $service->get($this->request->getData('origin.id'));
$beforeUrl = $beforeContent->url;
$content = $service->move($this->request->getData('origin'), $this->request->getData('target'));
$message = sprintf(
__d('baser_core', "コンテンツ「%s」の配置を移動しました。\n%s > %s"),
$content->title,
rawurldecode($beforeUrl),
rawurldecode($content->url)
);
$url = $service->getUrlById($content->id, true);
$this->BcMessage->setSuccess($message, true, false);
} catch (PersistenceFailedException $e) {
$errors = $e->getEntity()->getErrors();
$message = __d('baser_core', "入力エラーです。内容を修正してください。");
$this->setResponse($this->response->withStatus(400));
} catch (\Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage());
$this->setResponse($this->response->withStatus(500));
}
} else {
$message = __d('baser_core', 'コンテンツ一覧を表示後、他のログインユーザーがコンテンツの並び順を更新しました。<br>一度リロードしてから並び替えてください。');

try {
$beforeContent = $service->get($this->request->getData('origin.id'));
$beforeUrl = $beforeContent->url;
$content = $service->move($this->request->getData('origin'), $this->request->getData('target'));
$message = sprintf(
__d('baser_core', "コンテンツ「%s」の配置を移動しました。\n%s > %s"),
$content->title,
rawurldecode($beforeUrl),
rawurldecode($content->url)
);
$url = $service->getUrlById($content->id, true);
$this->BcMessage->setSuccess($message, true, false);
} catch (PersistenceFailedException $e) {
$errors = $e->getEntity()->getErrors();
$message = __d('baser_core', "入力エラーです。内容を修正してください。");
$this->setResponse($this->response->withStatus(400));
} catch (\Throwable $e) {
$message = __d('baser_core', 'データベース処理中にエラーが発生しました。' . $e->getMessage());
$this->setResponse($this->response->withStatus(500));
}

$this->set([
Expand Down
3 changes: 1 addition & 2 deletions plugins/baser-core/src/Model/Table/AppTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

use BaserCore\Utility\BcUtil;
use Cake\ORM\Association\BelongsToMany;
use Cake\ORM\Query;
use Cake\ORM\Table;
use Cake\I18n\FrozenTime;
use BaserCore\Annotation\NoTodo;
use BaserCore\Annotation\Checked;
use BaserCore\Annotation\UnitTest;
Expand Down Expand Up @@ -83,6 +81,7 @@ public function setTable(string $table)
* @return string
* @checked
* @noTodo
* @unitTest
*/
public function getTable(): string
{
Expand Down
33 changes: 4 additions & 29 deletions plugins/baser-core/src/Model/Table/ContentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ public function initialize(array $config): void
*/
protected $updatingSystemData = true;

/**
* 保存前の親ID
*
* IDの変更比較に利用
*
* @var null
*/
public $beforeSaveParentId = null;

/**
* Implemented Events
*
Expand Down Expand Up @@ -366,12 +357,10 @@ public function beforeMarshal(EventInterface $event, ArrayObject $content, Array
}
} else {
if (isset($content['name'])) {
try {
$oldName = $this->get($content['id'])->name;
} catch (\Exception $e) {
$oldName = null;
}
if($content['name'] !== $oldName) {
$old = $this->get($content['id']);
$content['lft'] = $old->lft;
$content['rght'] = $old->rght;
if($content['name'] !== $old->name) {
$content['name'] = BcUtil::urlencode(mb_substr($content['name'], 0, 230, 'UTF-8'));
}
}
Expand Down Expand Up @@ -468,15 +457,6 @@ public function getUniqueName($name, $parentId, $contentId = null)
*/
public function beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
if (!empty($entity->id)) {
try {
$this->beforeSaveParentId = $this->get($entity->id)->parent_id;
} catch (RecordNotFoundException) {
try {
$this->beforeSaveParentId = $this->getTrash($entity->id)->parent_id;
} catch (\Throwable) {}
}
}
if (!empty($entity->name)) {
$entity->name = $this->urlEncode(mb_substr(rawurldecode($entity->name), 0, 230, 'UTF-8'));
}
Expand Down Expand Up @@ -504,11 +484,6 @@ public function afterSave(EventInterface $event, EntityInterface $entity, ArrayO
$this->updateChildren($entity->id);
}
$this->updateRelateSubSiteContent($entity);
if (!empty($entity->parent_id) && $this->beforeSaveParentId != $entity->parent_id) {
$SiteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs');
$SiteConfig->updateContentsSortLastModified();
$this->beforeSaveParentId = null;
}
}
}

Expand Down
61 changes: 0 additions & 61 deletions plugins/baser-core/src/Model/Table/SiteConfigsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,67 +113,6 @@ public function getControlSource($field)
}
}

/**
* コンテンツ一覧を表示してから、コンテンツの並び順が変更されていないかどうか
* 60秒をブラウザのロード時間を加味したバッファとする
* @param $listDisplayed
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function isChangedContentsSortLastModified($listDisplayed)
{
$lastModified = $this->getValue('contents_sort_last_modified');
$changed = false;
if ($lastModified) {
$user = BcUtil::loginUser();
if (!$user) {
return false;
}
[$lastModified, $userId] = explode('|', $lastModified);
$lastModified = strtotime($lastModified);
if ($user->id !== (int)$userId) {
$listDisplayed = strtotime($listDisplayed);
if ($lastModified >= ($listDisplayed - 60)) {
$changed = true;
}
}
}
return $changed;
}

/**
* コンテンツ並び順変更時間を更新する
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function updateContentsSortLastModified()
{
$user = BcUtil::loginUser();
if (!$user) {
return false;
}
return $this->saveValue(
'contents_sort_last_modified',
date('Y-m-d H:i:s') . '|' . $user->id
);
}

/**
* コンテンツ並び替え順変更時間をリセットする
* @return bool
* @checked
* @noTodo
* @unitTest
*/
public function resetContentsSortLastModified()
{
return $this->saveValue('contents_sort_last_modified', '');
}

/**
* 指定したフィールドの値がDBのデータと比較して変更状態か確認
*
Expand Down
18 changes: 0 additions & 18 deletions plugins/baser-core/src/Service/ContentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -971,19 +971,6 @@ public function exists($id, $withTrash = false): bool
return $exists;
}

/**
*
*
* @checked
* @noTodo
* @unitTest
*/
public function isTreeModifiedByAnotherUser($listDisplayed)
{
$siteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs');
return $siteConfig->isChangedContentsSortLastModified($listDisplayed);
}

/**
* コンテンツを移動する
*
Expand Down Expand Up @@ -1035,11 +1022,6 @@ public function move($origin, $target)
}
// オフセットを元に移動
$result = $this->Contents->moveOffset($origin['id'], $offset);
if ($result && $origin['parentId'] === $target['parentId']) {
// 親が違う場合は、Contentモデルで更新してくれるが同じ場合更新しない仕様のためここで更新する
$siteConfig = TableRegistry::getTableLocator()->get('BaserCore.SiteConfigs');
$siteConfig->updateContentsSortLastModified();
}
if ($result) $this->saveSearchIndex($origin['id']);
return $result;
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/baser-core/tests/Scenario/SiteConfigsScenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,6 @@ public function load(...$args): mixed
'modified' => '2021-01-27 12:58:25'
]
)->persist();
SiteConfigFactory::make([
'id' => '30',
'name' => 'contents_sort_last_modified',
'value' => '',
'created' => '2021-01-27 12:58:10',
'modified' => '2021-01-27 12:58:25'
]
)->persist();
SiteConfigFactory::make([
'id' => '31',
'name' => 'editor',
Expand Down
22 changes: 19 additions & 3 deletions plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
namespace BaserCore\Test\TestCase\Model\Table;

use BaserCore\Model\Table\AppTable;
use BaserCore\Test\Factory\ContentFolderFactory;
use BaserCore\Test\Factory\PluginFactory;
use BaserCore\Test\Scenario\PermissionGroupsScenario;
use BaserCore\Test\Scenario\PluginsScenario;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Model\Table\PermissionsTable as TablePermissionsTable;
use Cake\Event\Event;
use BaserCore\Utility\BcUtil;
use Cake\Database\Connection;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
Expand Down Expand Up @@ -78,6 +77,23 @@ public function testInitialize()
);
}

/**
* test getTable
*/
public function testGetTable()
{
//デフォルトテーブル
$this->assertEquals('app', $this->App->getTable());

//プレフィックスを追加場合、
$dbConfig = BcUtil::getCurrentDbConfig();
$dbConfig['prefix'] = 'unittest_';
$connection = new Connection($dbConfig);
$this->App = $this->getTableLocator()->get('BaserCore.App')->setConnection($connection);

$this->assertEquals('unittest_app', $this->App->getTable());
}

/**
* Test getUrlPattern
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ public function testBeforeSave()
])->persist();
$data = ContentFactory::get(100);
$result = $this->Contents->dispatchEvent('Model.beforeSave', ['entity' => $data, 'options' => new ArrayObject()]);
$this->assertEquals(6, $this->Contents->beforeSaveParentId);
// nameフィールドがエンコードされてるかをテスト
$entity = $result->getData('entity');
$this->assertEquals(urlencode($value), $entity->name);
Expand Down Expand Up @@ -540,6 +539,7 @@ public function testUpdateSystemData()
$result = $this->execPrivateMethod($this->Contents, 'updateSystemData', [$content]);
$this->assertFalse($result);
// self_*を元にstatusなど補完する
ContentFactory::make(['id' => 100, 'name' => ''])->persist();
$data = [
'id' => 100,
'site_id' => 1,
Expand Down
Loading

0 comments on commit dc25e11

Please sign in to comment.