Jump to content

Pete

Administrators
  • Posts

    4,018
  • Joined

  • Last visited

  • Days Won

    66

Everything posted by Pete

  1. I've got a scenario where I use ProcessWire as a CRM for a client and they have several companies using this now, so it's important to be able to update things easily across all installations. A tricky one recently was working out how to manage translations via API to avoid going into several installations, enabling language support and translating the file manually (in this case they wanted to tweak a message in LRP's confirmation routine). On your master installation, do your translation as normal Export to CSV Upload the CSV file somewhere where your updater code can reference it - I created a folder in site/assets called "uploads" for some CRM-specific stuff, so I added another folder under there for ' Use code similar to the below in your updater script on other installations to first create the JSON file to be translated (it may not already exist) and then import your CSV file and tidy up afterwards - something like the below: <?php $this->modules->refresh(); // I've found this helps first, mostly for modules that have just been pushed to the Git repo but doesn't hurt to do it every time $this->modules->install('LanguageSupport'); // This wasn't yet installed $languages = $this->wire()->languages; $default = $languages->get('default'); // We only use the default language as it's only for the UK market $default->of(false); // It will complain without outputformatting switched off under some scenarios $translator = new LanguageTranslator($default); $translator->addFileToTranslate('site/modules/LoginRegisterPro/LoginRegisterProConfirm.php'); // This generates the JSON file that you would see in PW on the translations page $languages->importTranslationsFile($default, $this->config->paths->assets . 'uploads/imports/default-site.csv'); // This imports the CSV we exported from our master installation unlink($this->config->paths->assets . 'uploads/imports/default-site.csv'); // And we don't need the file afterwards I appreciate it's not a particularly in-depth tutorial, but may help someone out there with a similar need. Our CRM installations are all on an Amazon EC2 instance under separate subdomains, so separate databases too and there's a shell script I use to iterate all the installation folders, get the latest updates from the Github repo and then run an updater script that will do more complex updates like the above code or perhaps alter tables etc. This may get trickier in future if we shift to using something like Docker, or that may make life easier, but at the moment this is all nicely manageable the way it is.
  2. Go for it - just be aware that you don't have the originals afterwards of course. You've reminded me I also have a Craft site I can run this on, although the client does usually manually resize their own images it would be good to check.
  3. It turned 25GB into 11GB by the way. There's still a lot of photos in there ?
  4. One other thing - I am also keeping a copy of the original uploads folder just in case. I've set max resolutions in various CMS' since 2001 and in later years you wonder why you ever set it as low as 800x800 for example ? This way I have the originals if I ever need them again, but I think for the content in question, 1600px max width/height should be absolutely fine. There will also likely be a write-up for this project - it's going to be a while longer though before it's ready.
  5. Hey folks, so in a project I'm working on there are 750+ news articles in WP that are image-heavy in recent years. WP has a habit of storing the original images full-size - well, ProcessWire does too but I always set max dimensions on the image fields to resize during upload to prevent 2mb+ images on my disk. This had resulted in an uploads folder some 25GB in size from 2003-2022. Disk space is, fortunately, cheap nowadays, however I soon realized after mulling it over with Ryan that the easiest and most sane option for importing all those articles was to scrape in the post content HTML into a PW CKEditor field (thanks SimpleHTMLDOM for making this so simple!) but leave the images alone - WP had already done resizes for various lightboxes and galleries so it was just the original, huge images I had to contend with. The solution - on my own copy of the WP uploads dir - was to run this command and watch it go: find ./ -type f \( -iname \*.jpg -o -iname \*.jpeg -o -iname \*.png \) -exec mogrify -quality 90 -verbose -resize 1600x1600\> {} \; It's basically searching all files and subfolders for .jpg, .jpeg and .png files and resizing to no more than 1600px landscape/portrait whilst preserving aspect ratio (no cropping) and 90% image quality. I chose those sizes as the various links in galleries and lightboxes were loading the original file, not one of the WP resized ones, so now we can be fairly sure that we're loading <500kb of image maximum instead of sometimes 10mb+ (some folks have really nice cameras ? ). I'm sure @horst can probably tell me if that command could be better. I think mogrify is usually for a batch of files for example, whereas the find command is serving them up individually so convert might be more appropriate than mogrify, but this command iterates through the files quickly and only resizes which ones it needs to and is happily chugging away right now so I'm happy with it. One thing to note is that any resizing can be a bit CPU-heavy, so if you have the chance to do this on a local server first or out of "normal" hours for site visitors then that's recommended as the server may slow down for the duration.
  6. It's on a CRON job so not a form, but also it's only happening occasionally, not for every email generated by that function. 100% it's since my new code so it's some weird combination of CRON and something else.
  7. Had a bit of time to look into my issue and it's only started since I changed some code, plus that code is run via a Cron job as the guest user so too many variables to check at the moment, but the fault doesn't seem to be in the system or any module at least so that's good.
  8. Experiencing the same lately, but not with every email sent from the same block of code which is all the more curious as it's the same email, just sometimes it'll send once, sometimes twice. I'm using WireMailSMTP with Postmark but will check it with the WireMailPostmark module when I get a chance to see if it's something in WireMailSMTP (unlikely I'm sure, just ruling things out).
  9. Thank you - I think when I last tried it both selects were in a combo field (Pro module) so may not work there but might with this update - I'll check.
  10. Can you remind me how dependent select fields work?
  11. Thanks guys will take a look at these ?
  12. Hi all, I've got a custom backend page add/edit modal and can hide the tabs I don't want on the page that opens in the modal easily enough, but is there an easy way to hide the "Save and Keep Unpublished" button and perhaps rename "Publish" as "Save"? I'm pretty sure I'll need a hook but not sure where to look.
  13. For anyone who comes across this topic, I'd done a Wordpress import and was storing the original filename in an extra field in my photos field, so my code to rename after I botched the names up the first time was: foreach ($page->photos as $photo) { $photo->rename($photo->wordpress_filename); } $page->save('photos'); I suspect that you can do this too if you have a separate array of old and new names - not tested but it is the same idea as above done a different way by getting the file by current name first, then renaming it: foreach ($renameArr as $old => $new) { $page->photos->getFile($old)->rename($new); } $page->save('photos'); The act of simply saving the relevant field after the renaming updates the database nicely whereas looking at the previous comments this wasn't always the case.
  14. @ryan I can confirm this on latest PW dev - having "tags" on an images field with extra custom fields, then removing tags from that field, then trying to upload images shows this error. For now I just re-enabled tags on that field.
  15. I think I've actually already spotted some workflow flaws that mean I couldn't use it for this project actually, but the offer of access/managing the repo still stands.
  16. @MarkE I may finally be using this module on a project many years after last being involved with it. Did you want access to the main repo to merge your changes into it? My needs may be somewhat different - updating a trip diary (single page, many entries) over the course of a trip - so I'd likely be using a modified version anyway but whilst I'm looking back at this topic I thought I'd ask ?
  17. Aha, I managed to get this to happen again. Step 1: delete two PageAutoComplete entries and save the page - the empty rows remain (I really wish empty rows wouldn't get saved but that's another story): Step 2: Typing into the fields in the two existing empty rows you can enter the same value twice (so below I just entered the Parkland Resort extra into the first of the two empty rows, and am able to add it again in the second of the empty rows) It respects the once-per-table setting when you add a new row, but not for empty existing rows. I do wonder if another belt-and-braces solution here is to simply check for and delete duplicate rows on save too?
  18. Okay so I resolved this by chance - it won't work in PageAutocomplete UNLESS you give it a "normal" field as an alternative, so here is what you need in the config for that field in the table: labelField=myFooLabel|title I suspect what is happening is the AJAX request doesn't know what myFooLabel is for some part of the request but this makes the items appear in the list using myFooLabel which was a nice surprise! Not really sure why it makes it work, just guessing above but it does work and that's the main thing ?
  19. You're right, it is working. I think I fell foul of having changed the table schema and sometimes it can get itself a bit mixed up. When I stripped out some extra settings from when my first column was a different fieldtype and re-saved it started behaving itself just fine. Thanks for checking!
  20. That's great, thank you ? The only tiny thing missing is being able to change the "replace image" label, but only because I changed the other labels to say "photo". I feel like I'm being picky now.
  21. This is a great approach, thanks @bernhard One place it doesn't work, and I don't know why, is using it as a labelField in a Profields Table using PageAutocomplete. When you select something and save it works fine, but the list of suggestions returned is blank. What I mean is this - there's a result for those 4 letters, but using this hook it doesn't display. As you can see from the Everest row though, I've used it to stitch the page title and a price field together so when you select the blank item from the list it's selected, but the label doesn't appear until the page is saved. If anyone smarter than me can figure out how to get it to work with PageAutocomplete in a Profields Table you would be my hero ?
  22. There's an issue with autocomplete - until you save you can still enter the same thing in multiple rows. Once saved they are indeed removed from the autocomplete the next time you try to add them but not before saving.
  23. Hiya, loving this dashboard for a few more complex projects. I have a request for the number panel - since I often add a link in the "detail", if the number is zero then the link isn't shown. It would be great if there was a way to show it regardless. Actually it's hard to tell if it's a bug or intentional. In DashboardPanelNumber.module if I wrap the number in is_numeric it works when zero is passed as the number as below: public function setup() { parent::setup(); $this->locale = $this->data['locale'] ?? setlocale(LC_ALL, 0); $this->detail = $this->data['detail'] ?? ''; $this->number = is_numeric($this->data['number']) ? $this->data['number'] : null; if (is_int($this->number) || is_float($this->number)) { $this->number = $this->formatNumber($this->number); } }
×
×
  • Create New...