Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS. #183

Merged
merged 2 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -2311,6 +2311,21 @@ public static function get_versionnumber_by_stage($class, $stage, $id, $cache =
return $version ?: null;
}

/**
* Hook into {@link Hierarchy::prepopulateTreeDataCache}.
*
* @param DataList|array $recordList The list of records to prepopulate caches for. Null for all records.
* @param array $options A map of hints about what should be cached. "numChildrenMethod" and
* "childrenMethod" are allowed keys.
*/
public function onPrepopulateTreeDataCache($recordList = null, array $options = [])
{
$idList = is_array($recordList) ? $recordList :
($recordList instanceof DataList ? $recordList->column('ID') : null);
self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::DRAFT, $idList);
self::prepopulate_versionnumber_cache($this->owner->baseClass(), Versioned::LIVE, $idList);
}

/**
* Pre-populate the cache for Versioned::get_versionnumber_by_stage() for
* a list of record IDs, for more efficient database querying. If $idList
Expand Down
2 changes: 1 addition & 1 deletion tests/php/VersionedNumberCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testVersionNumberCache($stage, $ID, $cache, $expected)
*/
public function testPrepopulatedVersionNumberCache($stage, $ID, $cache, $expected)
{
Versioned::prepopulate_versionnumber_cache(TestObject::class, $stage);
TestObject::singleton()->onPrepopulateTreeDataCache();
$actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache);
$this->assertEquals(self::$expectedVersions[$expected], $actual);
}
Expand Down