Jump to content

Custom Upload Names


adrian

Recommended Posts

3 minutes ago, adrian said:

Ok, I think I have narrowed it down - if you don't have "overwrite" checked and you use $file->mtime it doesn't know how to name the file at the correct point it needs to. Let me see if I can fix.

Yep, I'm getting the same results with you.

  • Like 1
Link to comment
Share on other sites

@PWaddict - I have managed to solve the problem you are seeing, but there is another issue when using $file->mtime in the rename rule for images in repeaters that I am having trouble fixing. The problem is that when you save an image, the mtime changes and there is an order problem with the mtime changing before or after the renaming of the pagefile which is causing problems. I noticed though that it all works fine if you use $file->modified instead. Would that work ok for your needs instead of mtime?

  • Like 1
Link to comment
Share on other sites

9 hours ago, adrian said:

I noticed though that it all works fine if you use $file->modified instead. Would that work ok for your needs instead of mtime?

Thanks a lot. I switched from mtime to modified and the problem is gone :) Maybe you should add a note on the Rename rules to avoid using mtime.

Link to comment
Share on other sites

1 minute ago, PWaddict said:

Thanks a lot. I switched from mtime to modified and the problem is gone 🙂 Maybe you should add a note on the Rename rules to avoid using mtime.

Maybe I could programmatically replace mtime with modified. Can you think of any reason why mtime would actually be needed vs modified?

Link to comment
Share on other sites

3 minutes ago, adrian said:

Maybe I could programmatically replace mtime with modified. Can you think of any reason why mtime would actually be needed vs modified?

modified: Unix timestamp of when Pagefile (file, description or tags) was last modified.
mtime: Unix timestamp of when file (only) was last modified.

Taken from Pagefile API Reference.

Link to comment
Share on other sites

  • 5 months later...

I'm trying to use this module, but currently no renaming is happening, either on upload or after save.

My rule is : {$page->compGrade->title}_{$page->compSubject->title}_{$page->compMedium->title}_{$page->title}

$page->compSubject and $page->compMedium are Options fieldtype.

I get for example: imgp0887_upload_tmp.jpg which is definitely not right.

I'm on PW 3.0.144

There's not by any chance an issue with the module not handling mixed case field names? Processwire itself does allow mixed case field names, however I've struck several modules including from Ryan himself, that convert everything to lowercase, to match database table names.

That's the only thing I can think of that might be causing renaming not to work.

Here's screenshot of configuration below:

 

image.thumb.png.34047fdfaca68c058b87b018363a00dc.png

Link to comment
Share on other sites

Hey @Kiwi Chris - the "_upload_tmp" suffix is added when the value for one of the fields is not available yet. What should happen (and it working for me here) is that if there is no value for one of those fields listed in the format rule, after initial ajax loading of the image, it will have that "_upload_tmp" suffix, and then when you save the page, assuming you have selected something for those required format fields, the file will be renamed once again, now that it has the data it needs. 

BTW, I just tested with an Options fieldtype with a mixed case name, so there should be no problem there.

I am sure you've thought of this, but be aware that Options and Page Reference fields set to store multiple values will automatically use the first selected value.

Not sure where to go from here, but maybe you could start with a simple {$page->title} rule and if that works, add another field and see which one breaks it and we can investigate from there.

Link to comment
Share on other sites

1 minute ago, Kiwi Chris said:

I didn't realise it would drop the whole filename pattern rather than just the incorrect part

Yeah, it's the only way to handle it really because that upload_tmp suffix is needed to trigger the later rename. Anyway, glad you got it sorted.

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Hi there. I am pretty new to processwire. Been using the module and it works perfectly!

I have one question. Sometimes when images are uploaded, from the gui, the module adds a "-1" is there a get around for this?

I basically am trying to keep the name of the file same for each different upload.

 

Thank you!

 

image.png

Edited by helin
Link to comment
Share on other sites

Hi @helin,

Sorry for the late response. This has annoyed me for a long time and while it might seem like an easy fix, it has eluded me several times. I have put in another concerted effort and I think I have a working solution, but it would be great if you could test before I commit to the repo. Please try the attached file and let me know. It should work regardless of whether you have the "Rename on Save" option checked, but please note that if you upload a replacement file for a single image field (max allowed 1 file), then the -1 will be appended until you save the page - this is simply because the other image still exists until you save the page, so the filename must be adjusted, but it should now be removed if there are no other conflicting filenames.

 

ProcessCustomUploadNames.module.php

Link to comment
Share on other sites

  • 1 month later...

Hey @adrian, it seems it's impossible to delete a rule. When I click the trash icon the rule disappears but I'm getting the following error on console and when I press the submit button the rule appears again.

JqueryCore.js?v=183:2 Uncaught RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>)
    at nt (JqueryCore.js?v=183:2)
    at Function.nt.matches (JqueryCore.js?v=183:2)
    at Function.filter (JqueryCore.js?v=183:2)
    at init.v.fn.<computed> [as children] (JqueryCore.js?v=183:2)
    at Object.toggle (inputfields.js?v=31e:178)
    at Object.focus (inputfields.js?v=31e:400)
    at inputfields.js?v=31e:401
    at completed (inputfields.js?v=31e:191)
    at Object.toggle (inputfields.js?v=31e:246)

 

Link to comment
Share on other sites

@PWaddict - I am not having any problems deleting a rule. Can you please investigate the error further - is it specific to a particular browser? Are you running the regular Uikit theme? Can you try debugging the deleteRow function in the module's js file to see if you can prevent the error?

Link to comment
Share on other sites

35 minutes ago, adrian said:

@PWaddict - I am not having any problems deleting a rule. Can you please investigate the error further - is it specific to a particular browser? Are you running the regular Uikit theme? Can you try debugging the deleteRow function in the module's js file to see if you can prevent the error?

ProcessWire 3.0.165 (with default Uikit admin theme)
Google Chrome 87.0.4280.66 (Official Build) (64-bit)

I did more tests and I can only delete the last rule. So, if I want to delete the 1st or the 3rd etc, first I have set it as the last one, press the submit button to save the order list and then I can delete it.

Also tested on Firefox 83.0 (64-bit) and I'm getting the following console error if I try to delete any rule except the last one:

Uncaught TypeError: $(...).val() is undefined
    <anonymous> https://mysite.test/site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.js?v=1.2.9:68
    jQuery 2
    <anonymous> https://mysite.test/site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.js?v=1.2.9:59
    jQuery 9
    <anonymous> https://mysite.test/site/modules/ProcessCustomUploadNames/ProcessCustomUploadNames.js?v=1.2.9:54
    jQuery 11

 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Additional information: I've a image field called "image" and a page fieldset called "meta". The image is mapped on the template and also mapped on meta, which mapped to the template too. So the image field "image" is two times mapped.

$page->image
$page->meta->image

For $page->image I want to rename the image to "{$page->title}" and for $page->meta->image I want to rename the image to "preview".

How do I configure the rules to match both cases?

Thanks.

Link to comment
Share on other sites

@rjgamer - a few things:

1) Not sure if it will break anything, but I'd steer clear of naming a field "meta" because PW has an inbuilt meta field: https://processwire.com/api/ref/page/meta/

2) When selecting enabled pages, I am not sure it's going to work to select the actual repeater page parent (although I'd need to check to be sure). Does it work if you select the parent of the tree of pages that has the repeater field in their template?

3) It should be fine to have 2 separate rules for each of the fields - have you tried adding an extra rule to handle this?

Link to comment
Share on other sites

13 minutes ago, adrian said:

1) Not sure if it will break anything, but I'd steer clear of naming a field "meta" because PW has an inbuilt meta field: https://processwire.com/api/ref/page/meta/

Doesn't seem to make any problems yet. But you are right, I will rename it for "safety first" reasons.

13 minutes ago, adrian said:

2) When selecting enabled pages, I am not sure it's going to work to select the actual repeater page parent (although I'd need to check to be sure). Does it work if you select the parent of the tree of pages that has the repeater field in their template?

No, it doesn't work if I select "Repeaters" as parent page and it does not work if I explicit select the template or page.

13 minutes ago, adrian said:

3) It should be fine to have 2 separate rules for each of the fields - have you tried adding an extra rule to handle this?

Doesn't work, because both times the same page and field got matched.

The module can currently not set rules for page repeater and different handle the fields with similar names (connected over page repeater).

 

Link to comment
Share on other sites

@rjgamer - just did some testing and I remember now that it's not designed to handle repeater fields as separate pages like you are trying to do. I assumed that rules should be applied to all images on a page, whether they are within a repeater field or as a regular image field. It would have actually been much easier to set up the other way 🙂

I am sure the module could be modified to achieve what you're looking for, but not sure I can do it in a timely fashion for you. I will take a look when I get a chance though. Remember that PRs are always welcome!

Link to comment
Share on other sites

On 3/22/2021 at 3:57 PM, adrian said:

@rjgamer - just did some testing and I remember now that it's not designed to handle repeater fields as separate pages like you are trying to do. I assumed that rules should be applied to all images on a page, whether they are within a repeater field or as a regular image field. It would have actually been much easier to set up the other way 🙂

I am sure the module could be modified to achieve what you're looking for, but not sure I can do it in a timely fashion for you. I will take a look when I get a chance though. Remember that PRs are always welcome!

Thanks. My module development skills are to low for any professional pull request. I would be really happy if you could implement support specific page repeater rules.

On 3/22/2021 at 4:22 PM, adrian said:

@rjgamer - you could of course just use a different image field in the repeater so the rules can target it separately.

Yeah, thats the current and only way to get it done. But who wants 3-5 similar fields with different names? 😞

Link to comment
Share on other sites

  • 1 month later...

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.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      This module lets you add some custom menu items to the main admin menu, and you can set the dropdown links dynamically in a hook if needed.
      Sidenote: the module config uses some repeatable/sortable rows for the child link settings, similar to the ProFields Table interface. The data gets saved as JSON in a hidden textarea field. Might be interesting to other module developers?
      Custom Admin Menus
      Adds up to three custom menu items with optional dropdowns to the main admin menu.
      The menu items can link to admin pages, front-end pages, or pages on external websites.
      The links can be set to open in a new browser tab, and child links in the dropdown can be given an icon.
      Requires ProcessWire v3.0.178 or newer.
      Screenshots
      Example of menu items

      Module config for the menus

      Link list shown when parent menu item is not given a URL

      Advanced
      Setting child menu items dynamically
      If needed you can set the child menu items dynamically using a hook.
      Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $colours = $event->wire()->pages->findRaw('template=colour', ['title', 'url', 'page_icon']); $children = []; foreach($colours as $colour) { // Each child item should be an array with the following keys $children[] = [ 'icon' => $colour['page_icon'], 'label' => $colour['title'], 'url' => $colour['url'], 'newtab' => false, ]; } $event->return = $children; } }); Create multiple levels of flyout menus
      It's also possible to create multiple levels of flyout submenus using a hook.

      For each level a submenu can be defined in a "children" item. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); if($menu_number === 1) { $children = [ [ 'icon' => 'adjust', 'label' => 'One', 'url' => '/one/', 'newtab' => false, ], [ 'icon' => 'anchor', 'label' => 'Two', 'url' => '/two/', 'newtab' => false, 'children' => [ [ 'icon' => 'child', 'label' => 'Red', 'url' => '/red/', 'newtab' => false, ], [ 'icon' => 'bullhorn', 'label' => 'Green', 'url' => '/green/', 'newtab' => false, 'children' => [ [ 'icon' => 'wifi', 'label' => 'Small', 'url' => '/small/', 'newtab' => true, ], [ 'icon' => 'codepen', 'label' => 'Medium', 'url' => '/medium/', 'newtab' => false, ], [ 'icon' => 'cogs', 'label' => 'Large', 'url' => '/large/', 'newtab' => false, ], ] ], [ 'icon' => 'futbol-o', 'label' => 'Blue', 'url' => '/blue/', 'newtab' => true, ], ] ], [ 'icon' => 'hand-o-left', 'label' => 'Three', 'url' => '/three/', 'newtab' => false, ], ]; $event->return = $children; } }); Showing/hiding menus according to user role
      You can determine which menu items can be seen by a role by checking the user's role in the hook.
      For example, if a user has or lacks a role you could include different child menu items in the hook return value. Or if you want to conditionally hide a custom menu altogether you can set the return value to false. Example:
      $wire->addHookAfter('CustomAdminMenus::getMenuChildren', function(HookEvent $event) { // The menu number is the first argument $menu_number = $event->arguments(0); $user = $event->wire()->user; // For custom menu number 1... if($menu_number === 1) { // ...if user does not have some particular role... if(!$user->hasRole('foo')) { // ...do not show the menu $event->return = false; } } });  
      https://github.com/Toutouwai/CustomAdminMenus
      https://processwire.com/modules/custom-admin-menus/
    • By tcnet
      This module for ProcessWire sends a notification email for each failed login attempt. Similar modules exists already in the module directory of ProcessWire. However, this module is designed to notify, even if specified user doesn't exist.
      Settings
      The settings for this module are located in the menu Modules=>Configure=>LoginFailNotifier.
      Notification email
      Specifies the email address to which the notification emails should be sent.
        Email subject
      Specifies the subject line for the notification email.
        Post variables
      Specifies the $_POST variables to be included in the notification email. Each variable must be separated by a comma. For example: login_name,login_pass
        Server variables
      Specifies the $_SERVER variables to be included in the notification email. Each variable must be separated by a comma. For example: REMOTE_ADDR,HTTP_USER_AGENT
      Link to ProcessWire module directory:
      https://processwire.com/modules/login-fail-notifier/
      Link to github.com:
      https://github.com/techcnet/LoginFailNotifier
    • By Fokke
      ProcessWire 3.x markup module for rendering meta tags in HTML document head section. Note that this module is not a full-blown SEO solution, but rather a simple tool for rendering meta tags based on module configuration. Adding custom meta tags is also supported.
      Built-in meta tags
      The following meta tags are supported out-of-the-box:
      Document title consisting of page title and site name Character set Canonical Viewport Description Keywords Hreflang tags Open Graph og:title og:site_name og:type og:url og:description og:image og:image:width og:image:height Twitter meta tags twitter:card twitter:site twitter:creator twitter:title twitter:description twitter:image Facebook meta tags fb:app_id The full documentation with configurable options can be found here: https://github.com/Fokke-/MarkupMetadata
       
      Requirements:
      ProcessWire>=3.0.0 PHP >=7.1 Installation using Composer
      composer require fokke/markup-metadata Manual installation
      Download latest version from https://github.com/Fokke-/MarkupMetadata/archive/master.zip Extract module files to site/modules/MarkupMetadata directory.
    • By m.sieber
      ITRK-Service for ProcessWire
      Module for the automated transfer of imprint, data protection declaration and terms and conditions from IT-Recht Kanzlei to your ProcessWire installation
      What is ITRK Service for ProcessWire?
      ITRK-Service for ProcessWire is a free module for ProcessWire CMS. It provides an interface to the update service of IT-Recht Kanzlei, via which the legal texts of your online presence are automatically updated. In this way, the texts remain legally secure and warning-proof in the long term. Imprint, data protection declaration, revocation and general terms and conditions are currently supported.
      You can find our documentation (in german language) here: https://www.pupit.de/itrk-service-for-processwire/dokumentation/

      Download: https://www.pupit.de/itrk-service-for-processwire/
      Github: https://github.com/pupit-de/pwItrkServiceConnector
    • By LuisM
      Symprowire is a PHP MVC Framework based and built on Symfony using ProcessWire 3.x as DBAL and Service-Provider
      It acts as a Drop-In Replacement Module to handle the Request/Response outside the ProcessWire Admin. Even tough Symfony or any other mature MVC Framework could be intimidating at first, Symprowire tries to abstract Configuration and Symfony Internals away as much as possible to give you a quick start and lift the heavy work for you.
      The main Goal is to give an easy path to follow an MVC Approach during development with ProcessWire and open up the available eco-system.
      You can find the GitHub Repo and more Information here: https://github.com/Luis85/symprowire
      Documentation
      The Symprowire Wiki https://github.com/Luis85/symprowire/wiki How to create a simple Blog with Symprowire https://github.com/Luis85/symprowire/wiki/Symprowire-Blog-Tutorial Last Update
      16.07.2021 // RC 1 v0.6.0 centralized ProcessWire access trough out the Application by wrapping to a Service https://github.com/Luis85/symprowire/releases/tag/v0.6.0-rc-1 Requirements
      PHP ^7.4 Fresh ProcessWire ^3.0.181 with a Blank Profile Composer 2 (v1 should work, not recommended) The usual Symfony Requirements Features
      Twig Dependency Injection Monolog for Symprowire Support for .env YAML Configuration Symfony Console and Console Commands Symfony Webprofiler Full ProcessWire access inside your Controller and Services Webpack Encore support Caveats
      Symfony is no small Framework and will come with a price in terms of Memory Usage and added Overhead. To give you a taste I installed Tracy Debugger alongside to compare ProcessWire profiling with the included Symfony Webprofiler

      So in a fresh install Symprowire would atleast add another 2MB of Memory usage and around 40ms in response time, should be less in production due to the added overhead of the Webprofiler in dev env
       
×
×
  • Create New...