Jump to content

Jonathan Lahijani

Members
  • Posts

    794
  • Joined

  • Last visited

  • Days Won

    40

Everything posted by Jonathan Lahijani

  1. Thanks for this module. I've been using it a lot recently given that the web app I'm building makes heavy use of roles and permissions and I appreciate the "helicopter view" the module gives you. Recently, I've been using access rules on fields within the context of a template. Unfortunately, ProcessWire doesn't have a "helicopter view" of being able to see those settings, which means you have to go into each template and click on a field to bring up the modal, then go to the access tab to see what the settings are. Now imagine having to do that for dozens of fields. I wonder if you've dealt with that and if a feature like that makes sense for this module (or if it's out of scope).
  2. @bernhard Is there a way for ProcessWire to know if it was executed from RockShell? Does RockShell leave some sort of signature that could be detected? Right now I'm working around this by putting this in the handle() method: $this->wire()->config->isRockShell = true; Somewhat related: Does it make sense to have RockShell put ProcessWire in CLI mode by default, because currently it doesn't do that and my assumption is that it would? Not sure of the pros/cons of doing that, but I'm assuming you given it some thought.
  3. @bernhard Here's a function that solves the original problem of how to MOVE (not copy!) repeater items from one page to another, which preserves IDs. I tested it and I believe I accounted for everything, but I recommend testing it more before using it in production. // move the repeater items from fromPage to toPage // the same repeater field must be assigned to both pages // note: fromPage and toPage can be repeater page items as well since they are technically pages function moveRepeaterItems(string $fieldName, Page|RepeaterPage $fromPage, Page|RepeaterPage $toPage): void { // checks if(!wire('fields')->get($fieldName)) { throw new WireException("Field '$fieldName' does not exist."); } if(!$fromPage->id) { throw new WireException("From page does not exist."); } if(!$toPage->id) { throw new WireException("To page does not exist."); } if(!$fromPage->hasField($fieldName)) { throw new WireException("From page does not have field '$fieldName'."); } if(!$toPage->hasField($fieldName)) { throw new WireException("To page does not have field '$fieldName'."); } if($toPage->get($fieldName)->count('include=all,check_access=0')) { throw new WireException("To page already has items in field '$fieldName'."); } // store the parent_id $parent_id = wire('database')->query("SELECT parent_id FROM field_{$fieldName} WHERE pages_id = '{$fromPage->id}'")->fetchColumn(); // delete potential (and likely) existing toPage data placeholder // prevents this error: Integrity constraint violation: 1062 Duplicate entry '1491109' for key 'PRIMARY' in /wire/core/WireDatabasePDO.php:783 // remember, this will be empty since we checked above that there are no items in the toPage field wire('database')->query("DELETE FROM `field_{$fieldName}` WHERE `pages_id` = '{$toPage->id}'"); // update the record in table 'field_$field' where pages_id=$fromPage->id and change the pages_id to $toPage->id wire('database')->query("UPDATE `field_{$fieldName}` SET `pages_id` = '{$toPage->id}' WHERE `pages_id` = '{$fromPage->id}'"); // update the record in table 'pages' where id=$parent_id: change name from 'for-page-{$fromPage->id}' to 'for-page-{$toPage->id}' wire('database')->query("UPDATE `pages` SET `name` = 'for-page-{$toPage->id}' WHERE `id` = '{$parent_id}'"); } // example moveRepeaterItems( fieldName: 'order_line_items', fromPage: $pages->get("/orders/foo/"), toPage: $pages->get("/orders/bar/") );
  4. A quick note: Keep in mind that the clone will not occur (ProcessPageEdit::processSubmitAction is never executed) if there's a required field on the page being cloned that has not been populated and/or the page is statusFlagged.
  5. I've only played around with the new admin theme and haven't committed to it yet. That was one thing I noticed as well and I feel the color difference in the original theme definitely makes it easier to visually separate nested fields.
  6. Is it possible to put TracyDebugger in Development mode regardless of whatever settings are in the "Access permission" section? Like is there a $config setting that can force Development mode in which overrides whatever is in Access permission? I have a special case where I want it in Development mode that none of the Access permissions will be quite flexible enough for. To be specific, I want it enabled in PW CLI mode (but on my dev server), which means I can't use user/role-based or IP-based detection. I also don't want to use "Force isLocal" because that will enable it for both CLI and GUI mode. I don't want it for GUI mode in that particular case since my dev server is technically publicly accessible and could lead to TracyDebugger being used as a hacking vector.
  7. https://x.com/adamwathan/status/1559250403547652097
  8. I looked at DaisyUI but it relies on @apply under the hood which the creator of Tailwind said he wish he could uninvent so that didn't sit well with me.
  9. @bernhard Within the Tailwind ecosystem, my goal was to find the "framework" that had the best JavaScript components (the typical things like accordions, tabs, etc.). I started with Tailwind UI but that was geared for headless, however behind the scenes in their demos they had a hidden Alpine.js based solution. That was hacky but I used it for a little bit. Then Alpine.js itself had their premium components and since the two pair well, I went with that for a while but it didn't feel right in the same way that UIkit does. Then I found Preline and played with that for a while, but a couple years ago it was good but not as good as Flowbite. So I stuck with Flowbite for the last 2 years. A couple months ago I re-visited Preline and they've made some incredible progress, so much so that I feel it's "ahead" of Flowbite. Then a month or two ago, the folks at Tailwind finally released non-headless / vanilla JS components officially for Tailwind UI, which I haven't experimented with yet but I'll probably switch to that if it makes sense (which I'm sure it will): https://tailwindcss.com/blog/vanilla-js-support-for-tailwind-plus Also, I've been thinking about eventually switching back to vanilla CSS at some point because of how much progress it's made in the last 15 years. I stopped writing vanilla CSS when Bootstrap 2 came out and every since then I've gone from one framework to another (Bootstrap 2 -> Foundation -> Bootstrap 3 -> Uikit2 -> Uikit3 -> Tailwind). I love UIkit but I feel it's antiquated now and not taking advantage of all the new cool features of CSS. I also came to not like being softly "jailed" in their way of doing things. Also I like the idea of not using a build-step so vanilla CSS is probably what I'll settle on when I'm ready.
  10. I really wish I knew about this issue 2 years ago. Like... really really wish.
  11. @ryan, can you pretty please look at this issue that has to do with a sub-selector bug that occurs when there are about 1500+ pages? https://github.com/processwire/processwire-issues/issues/2084 It would be nice to have that fixed before the next master version.
  12. Just wanted to say this module is working really well under a lot of load. 👍
  13. Thank you very much. This adjustment also fixes admin emails being sent when errors occur. Awesome!
  14. Ack! You're right. I did this API integration a year ago and I forgot about the 'auth' setting in my routes file. Thanks for mentioning this.
  15. @Sebi Is there a reason there is not a simple "API-key based authentication" auth-type, meaning to communicate with the API, you just need an API key (without having to deal with sessions or JWTs)? Would you allow a pull request to add this?
  16. Callbacks were introduced in this update (ProcessWire 2.0.235) but I feel like this was an important update that was not spoken about. Analogous to Rails callbacks.
  17. That worked... I replaced the try/catch block with just $app->run(); The error appeared in the console and logged to 'errors' log. I wonder if it can be refactored a bit? Ideally I'd like to run try/catch in my own rockshell command, but with the current approach rockshell's try/catch will override it, right?
  18. Basically, I'm running a rockshell command and I get this error due to a logic bug in my own code: Call to a member function getProduction() on null However because the error isn't really specific, I'm not sure where in my codebase that's exactly occurring (like which file and which line). It doesn't log it to ProcessWire's 'errors' log. If I run the same code that's inside my rockshell command "outside" of rockshell (using php on the command line), it will also error, but details about it like this: PHP Fatal error: Uncaught Error: Call to a member function getProduction() on null in /path/to/pw/site/classes/BlahPage.php:210 Stack trace: ... Is it possible to log errors to the error log?
  19. @bernhard Somewhere in my codebase, an exception is occurring. It's not rockshell specific, but I'm using rockshell to run a background job and at some point this exception occurs. However, the exception details are very minimal in rockshell's output (just a simple line) which doesn't give me enough information me to track it down. I would think the exception would get placed in ProcessWire's own logs, but it doesn't. Any thoughts on how I can get the exceptions to get logged to help me debug?
  20. I need to set up monitoring on my servers to detect this. I didn't realize DigitalOcean has a metrics tool. Going to set that up now. I will look into MariaDB using too much memory in general though. Thanks for the tip.
  21. Just a heads up for anyone using DigitalOcean and sending out emails using SMTP with port 587, DigitalOcean just recently started blocking this port on "new" droplets. I put "new" in quotes because that's not true: I have a droplet from months ago, before their supposed announced change, and it still got blocked. I didn't realize this until one of my clients brought it up. Good job DO! /s I use WireMailSmtp and power it with Mailgun's SMTP credentials with port 587. I've been doing it this way for a long time, although using Mailgun's direct API approach (of which WireMailgun uses) is more preferred and would avoid this issue. I will start taking that approach soon with new and existing sites. Using SMTP is convenient however. Anyway, I'm not the only one that's complaining: https://www.digitalocean.com/community/questions/smtp-587-ports-is-closed An easy fix, for now at least, is to use port 2525 which is not blocked and which Mailgun also supports: https://www.mailgun.com/blog/email/which-smtp-port-understanding-ports-25-465-587/
      • 5
      • Like
  22. They are droplets. One droplet is Ubuntu 22.04 and the other is 24.04. I don't think the droplets themselves have the same hardware specs. There wasn't a similarity between the sites that would possibly explain it, at least not an obvious one.
  23. (I'm putting this in the Dev Talk forum since I don't think this is ProcessWire specific.) I have a ProcessWire site on a DigitalOcean server using Ubuntu 24.04 with MariaDB and PHP. This site doesn't receive much traffic. On 4/1/2025 MariaDB crashed. Here's what systemctl said: > systemctl status mariadb.service × mariadb.service - MariaDB 10.11.11 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled) Active: failed (Result: exit-code) since Wed 2025-04-02 06:31:12 UTC; 9s ago Duration: 1month 5d 13h 27min 44.368s Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 752113 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS) Process: 752115 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 752118 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-> Process: 752178 ExecStart=/usr/sbin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE) Main PID: 752178 (code=exited, status=1/FAILURE) Status: "MariaDB server is down" CPU: 178ms Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [ERROR] InnoDB: Failed to read log at 73992704: I/O error Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [Note] InnoDB: Starting shutdown... Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [Note] Plugin 'FEEDBACK' is disabled. Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [ERROR] Unknown/unsupported storage engine: InnoDB Apr 02 06:31:12 myserver1 mariadbd[752178]: 2025-04-02 6:31:12 0 [ERROR] Aborting Apr 02 06:31:12 myserver1 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE Apr 02 06:31:12 myserver1 systemd[1]: mariadb.service: Failed with result 'exit-code'. Apr 02 06:31:12 myserver1 systemd[1]: Failed to start mariadb.service - MariaDB 10.11.11 database server. Not sure why that happened and this is a recently built ProcessWire site (no legacy cruft). I thought simply restarting MariaDB would fix it but it didn't. Not even restarting the server fixed it. After Googling and ChatGPTing, this post (and ChatGPT) recommended removing /var/lib/mysql/ib_logfile0 (and iblogfile1), then restarting. The replies to that post suggest that while it works, it's dangerous for reasons related to potentially losing data. Given that this site is not mission critical, that wasn't a concern and the approach suggested worked. Ok. --- Now today, on a totally different site and server (still DigitalOcean) with the same Ubuntu version and LAMP stack, MariaDB crashed in the same way. I ran the same command "systemctl status mariadb.service" on that server and the output was basically identical. Restarting MariaDB worked in this case so it was much easier to fix. Again, this site doesn't receive much traffic. --- I'm wondering what's going on here? While these sites do get the typical hack-bots trying to exploit WordPress or insecure env files and things like that, I don't think that's the story here, even though they do tend to hammer the server. It has to be one of the following reasons logically speaking: a bug with MariaDB and/or Ubuntu? a bug with ProcessWire? an issue with DigitalOcean underlying hardware? Unlikely. overloading of server resources from hackbots or even AI crawlers? I looked at my logs and that didn't seem immediately plausible something code related on my end? Possible because they are both running my home-grown ecommerce module. Anyone else have issues with MySQL or MariaDB crashing for odd reasons?
  24. Good question. It has to do with an order and production management system I'm developing. Imagine you ordered a blanket with a personalized design, like a family photo of your choosing, and your order is for 3 of them. That's a print-on-demand product that has to be ultimately manufactured by a fulfiller. A person in the fulfiller manufacturing company will get this order and see it as 3 separate "production jobs" (not one production job with a quantity of 3 -- it's done this way because each manufactured product has to have specific status tracking and other data associated with it), but since it's the exact same product and design, the artwork that needs to be printed (a jpg or png) is actually the same across all 3, and they all point to the same file (won't get into the details of how it's all structured, it's very complex). However I also designed the system so that an employee can understand a production job just by looking at the filenames of the artwork files they downloaded from the manufacturing system, which is required because after they download that file, it has to go through special ripping and printing software. The filename format would be like this: [manufacturer-location]___[provider]___[ship-by-date]___[product]___[production-job-id-x].png That "x" at the end is represents the number based on the quantity of that exact personalized product. A realistic example would be like this based on the quantity of 3 blankets that were originally ordered: losangeles___somebigecommercesite___2025-03-28___blanket-60x80___123456-1.png losangeles___somebigecommercesite___2025-03-28___blanket-60x80___123456-2.png losangeles___somebigecommercesite___2025-03-28___blanket-60x80___123456-3.png So going back to the download attribute and custom filenames, that original file may have been originally called 123.png (where '123' is the id of repeater the artwork file belongs to since that repeater has a single-file field), but when it is downloaded through the interface by a person in the manufacturing facility, it will download as losangeles___somebigecommercesite___2025-03-28___blanket-60x80___123456-1.png, -2, thanks to the download attribute. Those downloaded files can then easily be loaded into a ripping software and the worker won't need to "think" about which ones had multiple quantities since that is fully expressed as individual files.
  25. Some time ago, I learned you can add the "download" attribute to a link to force a browser to download the file when its clicked, like this: <a download href="my-awesome-file.jpg">Download</a> What I didn't realize until today is that you can actually specify a filename as a value for the download attribute like this which will automatically use that filename instead!: <a download="my___awesome___file.jpg" href="my-awesome-file.jpg">Download</a> This is incredibly convenient because it means if I want a user to download the same exact file 3 times but with specific filenames for each, I can just do this: <a download="my___awesome___file-1.jpg" href="my-awesome-file.jpg">Download 1</a> <a download="my___awesome___file-2.jpg" href="my-awesome-file.jpg">Download 2</a> <a download="my___awesome___file-3.jpg" href="my-awesome-file.jpg">Download 3</a> Furthermore, as you can see, I am using a triple underscore which ProcessWire cleans up and changes to a single underscore, as well as other changes (such as lowercasing everything) when uploading to a pagefile field. I want my filenames to be exactly as I upload and I know there's ways to prevent ProcessWire from doing that, but using the download attribute in the way I described works perfectly for my use case.
×
×
  • Create New...