sadams101 Posted August 9, 2022 Share Posted August 9, 2022 (edited) I my pages app, for some reason, whenever you edit an article the article's image is deleted and renamed in the background. Like most people who use the pages app, I often have to go into older articles and fix a typo or change something. Whenever I do this the article's image URL is changed. This can cause issues with image search in google, if your image was indexed and is suddenly throwing a 404, and it also causes problems with my weekly eNewsletter which I send out to my subscribers (I often cut and past last week's article content from my index page into that eNewsletter--if I should edit any of the articles within that eNewsletter after I've created it, the image is broken in my eNewsletter and the only fix is to correct it before it gets sent, or if the eNewsletter has already been sent to create a 2nd duplicate image with the old name). It would be great if the image wasn't deleted and renamed when you re-save an article. I can't really think of any reason why the current programming that causes this to happen would be helpful for anyone. Edited August 9, 2022 by sadams101 Link to comment Share on other sites More sharing options...
sadams101 Posted December 21, 2023 Author Share Posted December 21, 2023 I hope to propose a code update on this issue, and better explain what exactly is going on. Below is the issue, and this is when you have "Enable record image upload" on in the ACP (/admin/?app=cms&module=databases&controller=databases&do=form&id=2). In the Pages app if an article has an image (using the "Choose single file..." button) uploaded and saved, a thumbnail is created which is displayed on the home page, and category pages within the Pages app. If you then need to edit this article later for any reason, for example if it was pinned and you want to unpin it, or if you want to lock the article, or simply edit any text within the article (all of these actions are very common for publishers), re-saving the article, even if you do not upload a new image, will result in the original thumbnail being deleted (removed), and a new thumbnail being created. For example, on my home page this was the URL of the article image: https://www.mysite.com/uploads/monthly_2023_12/Colored_quinoa_CC--Michael_Hermann.thumb.webp.b584800290f53b053cc6b6072b832864.webp I opened the article, changed some text and saved it, and now this is the URL of the image on my home page: https://www.mysite.com/uploads/monthly_2023_12/Colored_quinoa_CC--Michael_Hermann.thumb.webp.136b728972637cf0163400ddd264bc29.webp The old image was deleted, the new image was added. Why is this a problem? Lots of broken 404 image links, or any other 404 links on any website is considered poor SEO by Google and other search engines. Google Search Console instantly picks up these lost images and lists them as issues that need to be fixed. I edit many articles a day, and this results in lots of 404 Not Found flags. Solution, which I hope IPS will incorporate in a future update (I paid @DawPi for this fix, and he agreed to let me share it here), is a simple code change in this file: applications\cms\sources\Records\Records.php else { $imageUploads[] = $values['record_image']; $fixedFieldSettings = static::database()->fixed_field_settings; if ( isset( $fixedFieldSettings['record_image']['thumb_dims'] ) ) { if ( $this->record_image_thumb ) { try { \IPS\File::get( 'cms_Records', $this->record_image_thumb )->delete(); } catch ( \Exception $e ) { } } $thumb = $values['record_image']->thumbnail( 'cms_Records', $fixedFieldSettings['record_image']['thumb_dims'][0], $fixedFieldSettings['record_image']['thumb_dims'][1] ); } else { $thumb = $values['record_image']; } $this->record_image = (string)$values['record_image']; $this->record_image_thumb = (string)$thumb; } and replace it with this code: else { $imageUploads[] = $values['record_image']; $fixedFieldSettings = static::database()->fixed_field_settings; if ( isset( $fixedFieldSettings['record_image']['thumb_dims'] ) ) { /* By DawPi */ if( $this->record_image != (string) $values['record_image'] ) { if ( $this->record_image_thumb ) { try { \IPS\File::get( 'cms_Records', $this->record_image_thumb )->delete(); } catch ( \Exception $e ) { } } $thumb = $values['record_image']->thumbnail( 'cms_Records', $fixedFieldSettings['record_image']['thumb_dims'][0], $fixedFieldSettings['record_image']['thumb_dims'][1] ); } else { $thumb = $this->record_image_thumb; } /* END */ } else { $thumb = $values['record_image']; } $this->record_image = (string)$values['record_image']; $this->record_image_thumb = (string)$thumb; } After doing this the thumb image will only be update if you actually upload a new image to the article, not when you simply save it again for any other reason. This fix eliminates the many 404 Not Found image issues with Google Search Console. Ioannis D and DawPi 2 Link to comment Share on other sites More sharing options...
Recommended Posts