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 getCachedMarkup returns NULL instead of string if file doesn't exist #562

Conversation

sabina-talipova
Copy link
Contributor

Description

  • Check if file exist before return cached link for this file from getCachedMarkup method.
  • Method handle_shortcode should return string.

Test steps

  • Set FileShortcodeProvider::allow_session_grant = true;
  • Create new Page or open existing one in CMS;
  • Click Insert Link to a file in Content field;
  • Select any existing file and Save page;
  • Remove file from backend or change link in DB record;
  • Open Page in CMS again;
  • You should not see any Errors;
  • Shortcode link should lead to "Home" page;

Parent issue

Comment on lines 105 to 106
$url = $url ?? '';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested without this and it doesn't seem to change anything... seems to not be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File::getURL() returns null

public function getURL($grant = false)
.
And then we set this value in $markup in cache. After we return $item['markup'] in getCachedMarkup method.
So probably, there are some cases where we can get null from getCachedMarkup
I'll add checking in the getCachedMarkup method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -139,11 +141,12 @@ public static function handle_shortcode($arguments, $content, $parser, $shortcod
protected static function getCachedMarkup($cache, $cacheKey, $arguments): string
{
$item = $cache->get($cacheKey);
if ($item && !empty($item['filename'])) {
$assetStore = Injector::inst()->get(AssetStore::class);
if ($item && !empty($item['filename']) && $assetStore->exists($item['filename'], $item['hash'])) {
Copy link
Member

@GuySartorelli GuySartorelli Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($item && !empty($item['filename']) && $assetStore->exists($item['filename'], $item['hash'])) {
if ($item && !empty($item['filename'])) {

Move this below (see #562 (comment)) - we shouldn't hit the filesystem if we're not even allowing the grant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@@ -139,11 +141,12 @@ public static function handle_shortcode($arguments, $content, $parser, $shortcod
protected static function getCachedMarkup($cache, $cacheKey, $arguments): string
{
$item = $cache->get($cacheKey);
if ($item && !empty($item['filename'])) {
$assetStore = Injector::inst()->get(AssetStore::class);
if ($item && !empty($item['filename']) && $assetStore->exists($item['filename'], $item['hash'])) {
// Initiate a protected asset grant if necessary
$allowSessionGrant = static::getGrant(null, $arguments);
if ($allowSessionGrant) {
Copy link
Member

@GuySartorelli GuySartorelli Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($allowSessionGrant) {
if ($allowSessionGrant && $assetStore->exists($item['filename'], $item['hash'])) {

Moved as per #562 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@sabina-talipova sabina-talipova force-pushed the pulls/1.13/fix-cachemarkup-issue branch from 7e2cebf to bd9ebb7 Compare July 11, 2023 02:25
Sabina Talipova added 2 commits July 11, 2023 14:28
@GuySartorelli GuySartorelli merged commit 7c8440d into silverstripe:1.13 Jul 11, 2023
8 checks passed
@GuySartorelli GuySartorelli deleted the pulls/1.13/fix-cachemarkup-issue branch July 11, 2023 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants