Jump to content
muzzer

Trailing slash in template settings

Recommended Posts

Just upgrading site from 2.7 to 3.0.165.

The site has templates which have the setting "Should page URLs end with a slash" set to No.

On replacing the /wire folder, index.php and .htaccess to PW3 files all was working fine with the site UNTIL I loaded up the PW backend. Something happened here - I suspect on loading the backend several checks are performed and settings altered where necessary for freshly upgraded systems. Anyways, this setting mentioned above has now been set to Yes for all templates, causing rewriting issues. Easily fixed by setting back to "No" but why is this happening on upgrade, is this an upgrade bug?

Anyone else seen this?

Share this post


Link to post
Share on other sites

OK, I see I've actually run into this issue a long time ago and forgotten about it, even  posted about it but no resolution.
It appears all the template settings are returned to default, not just trailing slashes (that is just what make it show in this case as it creates a redirect loop). In this case it happened upon loading the PW backend (admin) but it's also now reverting the template to default settings when some other pages using the template are loaded. At no point do I alter the template via the API and I'm at a loss as to why this would happen. Is there any point in the core when a template settings would be defaulted which I could be tripping somehow?

This is phpMyadmin data for the PW template record before the page is loaded...

image.png.276ca3973a9ced170dd7b0153337955a.png

and after:

image.png.f77d11074578dfe8d7b4175ff00b0fb0.png

Share this post


Link to post
Share on other sites

OK I'm posting the simple workaround to this for anyone who may run into it in the future.

Basically it is a missing page image which is causing this odd behaviour, feel free to try to replicate;

I've got an image field on the page in question, image has been uploaded to the page via the API. Now somehow the image file has been deleted but the image info is still there in the PW page. When I access the image using the PW API it returns filesize 0 (no image file), debug data as follows:

image.png.07a946390eccfaf3bf7a3fb793834d04.png

When I attempt the $image->size() function on image it causes the template to lose it's data and return to PW default template settings. This is not a one off, I can replicate repeatedly.

The workaround (which I should not have to do really?) is to check the filesize before attempting a resize:

image.png.fbe355d43b7ca004f0afcaa66e4e2d2c.png

Perhaps it could be considered good practice to check the filesize prior to operations on the image but not doing so should not result in the template blanking it's settings. I'm guessing this situation of a missing image is either very rare or I've run into something odd on my particular instance as I can't find any mention of others encountering this issue. The exact same code and database under v2.7 runs fine for this page,

 

 

  • Like 4

Share this post


Link to post
Share on other sites
12 hours ago, muzzer said:

When I attempt the $image->size() function on image it causes the template to lose it's data and return to PW default template settings. This is not a one off, I can replicate repeatedly.

Could you please add the steps you are following to reproduce the problem? I'm trying to reproduce it but am not able to.

What I'm doing is:

  1. Template settings have slashUrls set to false (0).
  2. I upload an image to a "single" image field and save the page.
  3. I delete the uploaded image file from /site/assets/files/1234/
  4. I check the filesize of the PageImage to confirm that PW can not locate the file.
  5. I call the size() method on the PageImage with the now missing file. I tried with both the GD and ImageMagick sizer engines.
  6. I check the slashUrls setting of the template.

So far I don't experience any changes to the template settings of the page.

2021-01-02_093031.png.688683ca9040f625a63ee2b63c24866c.png

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S

Yes that is correct. But it gets more bizarre. This is the code which loops through the page images and is causing the problem (BTW it is all template data being lost, not just slashUrls):

foreach($room->smRoomImages as $image)
{
   $options = array( 'quality' => 80, 'upscaling' => false );
   $thumb1 = $image->size( 250,180, $options );
   $html .= "<img src='$thumb1->url' width='46%' height='' />";
}

I excluded the three lines in the loop and the problem resolved so I assumed it was the size() method causing the issue - but it is actually the next line in the loop - if I remove just the $thumb1->url from next line (leaving the img src attr empty as follows:) the issue vanishes.


foreach($room->smRoomImages as $image)
{
   $options = array( 'quality' => 80, 'upscaling' => false );
   $thumb1 = $image->size( 250,180, $options );
   $html .= "<img src='' width='46%' height='' />";
}

I realise this sounds just ridiculous but it is totally consistent - I've run this dozens of times with the described result with and without the "$thumb1->url". I can't replicate this on v2.7.

I'm not sure what debugger you've screenshotted there - I'm just reloading the template page in the admin and seeing the changes reflected there.
I'm not familiar with the workings of FileCompiler as yet as this is the first time using v3, but am wondering if something is going astray there, is that possible?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...