Jump to content

Custom Upload Names


adrian

Recommended Posts

On 4/27/2021 at 5:43 AM, Kiwi Chris said:

This module works well, but with Lister Pro and inline editing within the Lister Pro table, even with the check box to update on save for this module, file names aren't renamed, although opening via a full edit and saving does work.

I suspect the issue might be the way Lister Pro works,  but if it's possible to get this module to work with inline editing mode in Lister Pro it would be handy.

Looks like the same issue I have with page repeater. It would be really cool to get this supported.

Link to comment
Share on other sites

Hi @adrian

With the 1.3.1 version when I try to save more than 1 repeater fields I'm getting this:

Look out Fatal Error: Uncaught Error: Call to a member function isTemp() on null in site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.module.php:414

#0 site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.module.php(225): ProcessCustomUploadNames->createNewFilename('/home/myusername...', 'myimage-16198119...', '', Object(Page), '287', Object(RepeaterPage))
#1 wire/core/Wire.php (397): ProcessCustomUploadNames->customRenameUploads(Object(HookEvent))
#2 wire/core/WireHooks.php (927): Wire->_callMethod('customRenameUpl...', Array)
#3 wire/core/Wire.php (465): WireHooks->runHooks(Object(Pages), 'saved', Array)
#4 wire/core/PagesEditor.php (746): Wire->__call('saved', Array)
#5 /home/myusername/publ (line 414 of site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.module.php)

 

Link to comment
Share on other sites

  • 2 weeks later...
6 hours ago, PWaddict said:

cause the 1.2.11 and 1.2.12 was generating duplicate images

Was this just in a repeater scenario?

I have been using the latest version extensively without any problems (and it solves lots of other issues), so I am assuming this is repeater specific?

I'll try to take a look shortly. Sorry, I haven't had much time for module maintenance lately.

Link to comment
Share on other sites

19 minutes ago, adrian said:

Was this just in a repeater scenario?

This was in a non-repeater. The duplicated images were generated on the 1.2.11 and 1.2.12 versions after uploading multiple images. I don't know if this happens on repeater too.

 

25 minutes ago, adrian said:

I have been using the latest version extensively without any problems (and it solves lots of other issues), so I am assuming this is repeater specific?

The fatal error I'm getting with the 1.3.1 version is when I try to save more than 1 repeater fields. I didn't have problems on non-repeaters.

 

27 minutes ago, adrian said:

I'll try to take a look shortly. Sorry, I haven't had much time for module maintenance lately.

No worries.

Link to comment
Share on other sites

@PWaddict - I have been trying to reproduce the issue with repeaters but can't so far. I have a feeling the duplicate image issue might not exist in 1.3.1 so I want to work on the repeater issue first and see if that fixes everything for you.

Can you please provide all the repeater field settings, the image field settings, and the CUN settings. There must be some combination I am not trying.

Link to comment
Share on other sites

38 minutes ago, adrian said:

Can you please provide all the repeater field settings, the image field settings, and the CUN settings. There must be some combination I am not trying.

Here are the settings for the repeater:

repeater_settings.thumb.png.12b1dc1b0943be59c2d9e3799218897b.png

 

Here are the settings (Details & Input) for the image field (Croppable Image 3):

image_settings_details.thumb.png.4438cc340ab44a5d320db54aaa2ea264.png

image_settings_input.thumb.png.559b285a8bd1c67eb478ff4c76a49e65.png

 

Here are the settings for Custom Upload Names:

ProcessCustomUploadNames_settings.thumb.png.485dfb2009b865e2767b40d0e015a635.png

 

I don't know if it matters but here are the settings for Auto Smush:

AutoSmush_settings.thumb.png.6e66447a3108300b8a7821ddbdaf7632.png

 

Make sure you have the 1.3.1 version installed of Custom Upload Names. The fatal error is happening if you try to edit already published more than 1 repeater pages and also when you try to create more than 1 new repeater pages.

  • Like 1
Link to comment
Share on other sites

On 4/26/2021 at 8:43 PM, Kiwi Chris said:

This module works well, but with Lister Pro and inline editing within the Lister Pro table, even with the check box to update on save for this module, file names aren't renamed, although opening via a full edit and saving does work.

I suspect the issue might be the way Lister Pro works,  but if it's possible to get this module to work with inline editing mode in Lister Pro it would be handy.

The reason is because ListerPro uses the saveField() when only field in the row is changed. If you edit two fields, then the rename will work because ListerPro then uses save() - you can see this starting on line 631 of the main ListerPro module file. It should be possible to make CUN work with this by adding a new hook to Pages::saveField.

I have this working but I think I need to test more for other possible side effects. If you'd like to help test, you can place:

            $this->addHookBefore('Pages::saveField', $this, 'customRenameUploads');

after this line: https://github.com/adrianbj/CustomUploadNames/blob/67b1d42aef4c23be92684420f0d282c0c4a9a8d4/ProcessCustomUploadNames.module.php#L101

Let me know how it goes for you.

  • Like 1
Link to comment
Share on other sites

I am having issues with a repeater as well. When I add an image it changes its name to "filename-upload-tmp", and not to the setting I have set up in the module. I updated to the latest version of the module, that didn't fix it. Seems like the issue is only for the images in the repeater.

Link to comment
Share on other sites

1 minute ago, Rostik RODE said:

I am having issues with a repeater as well. When I add an image it changes its name to "filename-upload-tmp", and not to the setting I have set up in the module. I updated to the latest version of the module, that didn't fix it. Seems like the issue is only for the images in the repeater.

Did it work fully with older versions of the module?

The problem is not actually repeater specific - the upload-tmp suffix is because the naming rule you defined relies on a field that isn't populated at the point when the image is uploaded. Obviously this happens in most situations with repeaters, but it will also happen with regular pages in that situation.

Can you share your settings like PWAddict did?

Link to comment
Share on other sites

Thanks @Rostik RODE - I just tested those settings and can't reproduce the issue you are seeing. Any chance the title field for the page somehow isn't set when the image is uploaded? Usually this is unlikely because title is required and the first thing that is set when creating a new page, but that it really the only reason I can think of for the upload-tmp suffix being added - it's there so that the module knows that file needs to be renamed later, once that field value is available.

Link to comment
Share on other sites

Sorry @Rostik RODE - I am at a bit of a loss - still can't reproduce. Any chance you could share a login to the site so I can test?

Are there any other modules / hooks that might be interfering with image naming? or anything else you can think of?

Link to comment
Share on other sites

thanks for your help! 

its not that big of a deal, not worth spending too much time. i cant think of why it wouldn't work just for that one repeater. i have another repeater, where its a single image, so same image field but with a limit of 1 file in place,  and it works correctly. so perhaps it something to do with that 

 

Link to comment
Share on other sites

3 minutes ago, Rostik RODE said:

i have another repeater, where its a single image, so same image field but with a limit of 1 file in place,  and it works correctly. so perhaps it something to do with that 

I did my test with a multiple images field (max: 0) just like in your screenshot. It might be helpful if you could test on another template / repeater field setup with support for multiple images and see if you can narrow it down. If you've got a setup that doesn't work, I am sure others will come across this at some point as well.

 

Link to comment
Share on other sites

  • 1 year later...

Hey @adrian,

thanks for the great module!

I have an issue with .webp files, they are not renamed at all on page save. JPG are renamed without any problem.

image.thumb.png.9ca8291be3d148d16c9396f972a057cd.png

What could I do to find a solution to this ?

Using PW v3.0.200, PHP 8.1, no errors in Tracy. 

Edited by Studio Lambelet
Clarification, added screenshot.
Link to comment
Share on other sites

  • 1 month later...

I encountered an odd error today and I cannot for the life of me work out what caused it:

image.png

However I added !is_null($fieldObject) before the count on the line in question (and the other 2 places that same piece of code crops up) and that sorted it. For whatever reason the field object was null.

EDIT: Ah - I think this is a PHP8 thing actually which explains why it was working last week and not this week - that's probably it 🙂 

  • Like 1
Link to comment
Share on other sites

37 minutes ago, Pete said:

EDIT: Ah - I think this is a PHP8 thing actually which explains why it was working last week and not this week - that's probably it 🙂 

Changelog

Version Description
8.0.0 count() will now throw TypeError on invalid countable types passed to the value parameter.
7.2.0 count() will now yield a warning on invalid countable types passed to the value parameter.

https://www.php.net/manual/en/function.count.php😉 

  • Like 2
Link to comment
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
×
×
  • Create New...