Skip to content

Commit 7304a74

Browse files
ENH Use new DataList caching (#237)
Replaces deprecated `DataObject::get_one()` and `DataObject::get_by_id()` in favour of the new DataList query caching.
1 parent 031a8c6 commit 7304a74

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

code/BasicFieldsTestPage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public function requireDefaultRecords()
127127
{
128128
parent::requireDefaultRecords();
129129

130-
if ($inst = DataObject::get_one('BasicFieldsTestPage') && static::config()->get('regenerate_on_build')) {
130+
$inst = BasicFieldsTestPage::get()->setUseCache(true)->first();
131+
if ($inst && static::config()->get('regenerate_on_build')) {
131132
$data = $this->getDefaultData();
132133
$inst->update($data);
133134
$inst->write();
@@ -139,7 +140,6 @@ public function requireDefaultRecords()
139140
$inst->Listbox()->add($thirdCat);
140141
$inst->CheckboxSet()->add($firstCat);
141142
$inst->CheckboxSet()->add($thirdCat);
142-
143143
}
144144
}
145145

code/TestCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function map()
3636

3737
public function requireDefaultRecords()
3838
{
39-
if (!DataObject::get_one(static::class)) {
39+
if (static::get()->count() === 0) {
4040
foreach (array("A", "B", "C", "D") as $item) {
4141
$page = new static();
4242
$page->Title = "Test Category $item";

code/TestPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function requireDefaultRecords()
4040
return;
4141
}
4242

43-
if (!DataObject::get_one(static::class)) {
43+
if (static::get()->count() === 0) {
4444
// Try to create common parent
4545
$defaultAdminService = DefaultAdminService::singleton();
4646
Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () {

code/TestRegistryPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestRegistryPage extends RegistryPage
1111
{
1212
public function requireDefaultRecords()
1313
{
14-
if (!DataObject::get_one(static::class)) {
14+
if (static::get()->count() === 0) {
1515
// Try to create common parent
1616
$defaultAdminService = DefaultAdminService::singleton();
1717
Member::actAs($defaultAdminService->findOrCreateDefaultAdmin(), function () {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^8.3",
19-
"silverstripe/framework": "^6",
19+
"silverstripe/framework": "^6.1",
2020
"silverstripe/cms": "^6",
2121
"guzzlehttp/guzzle": "^7.9",
2222
"fzaninotto/faker": "^1.9.2"

0 commit comments

Comments
 (0)