Jump to content

Jonathan Lahijani

Members
  • Posts

    772
  • Joined

  • Last visited

  • Days Won

    35

Jonathan Lahijani last won the day on September 30

Jonathan Lahijani had the most liked content!

5 Followers

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA

Recent Profile Visitors

37,355 profile views

Jonathan Lahijani's Achievements

Hero Member

Hero Member (6/6)

2k

Reputation

1

Community Answers

  1. Oftentimes it's 3-5 projects at a time, with other projects being dormant or semi-dormant for a while. However there are times when I want to apply some setting across all of my sites, even the dormant ones. For example, a few years ago I decided to use SessionHandlerDB instead of the default, file-based session approach. I did this manually across all 50 sites (I suppose I could have scripted this). No need to boot up each development site with my current approach since it's all on a single LAMP server. But with Docker/DDEV, I'll have to spin up DDEV for each project then make the change, then shut it down. A little extra friction, but thinking about it as I write this, I don't think it's as bad as it sounds and I can probably automate it to some extent. How do you personally handle situations like that? If I get a Framework Desktop, I would get it with 128GB memory. It's very powerful.
  2. I'm planning on using DDEV sometime in the next few months when I buy a new computer (most likely Framework Desktop) and hopefully switch to Linux (looking to use Omarchy). It's going to be painful in the beginning (I really REALLY don't want to give up XYplorer and I hope I can adjust to a tiling window manager way of doing things), but Omarchy is where it's at for web developers. Right now, my dev setup is pretty simple: I have a separate bare-metal server (an old Dell Xeon workstation) running Ubuntu 24.04 and a LAMP stack (mostly everything installed with apt). I have Samba setup so I can access files from my Windows desktop machine for convenience. I use VSCode Remote SSH extension to edit files directly on the server. This has served me well and is not complicated at all. All of my ProcessWire projects exist there. One thing I do to keep things as efficient as possible is symlink the 'wire' directory of all my projects to a single folder that contains the latest version of ProcessWire (I'm not using Composer to manage ProcessWire itself). Therefore, if I want to update all my sites to the latest version of ProcessWire, I just symlink that folder and all the other sites are automatically updated. Sure, that kind of goes against proper source code control practices and such, but I'm always a solo developer and the strict level of isolation of environments between sites is typically not needed for 99% of the sites I work on, which is kind of the point of Docker/DDEV, but I still want to use it. Updating ProcessWire in this way is very efficienct (at the 'expense' of a potential site breaking which is very very rare). So my question is, if I have 50 ProcessWire sites created with DDEV, can I still symlink the 'wire' folder of all of them the same way I described above without any issues? I'm very rusty with Docker but looking to embrace it heavily. Also, is it "crazy" to have 50 ProcessWire projects started all at once (will that take up a lot of resources)? With my current setup, I don't have to launch anything because it's all served by a single Apache, MariaDB and PHP which is very convenient. With DDEV, I have to launch each one individually.
  3. Well it looks like they're switching to Laravel for Craft CMS v6: https://craftcms.com/blog/laravel This is very interesting and speaks to the idea of the CMS and web application framework powering it being 2 separate projects (Craft, etc.) vs. it being built around each other (ProcessWire). In my opinion, ProcessWire wouldn't be what we all love about it if it had such a huge dependency.
  4. Based on driving myself completely insane with noHooks for the last 2 years, and based on what Ryan specifically said here: ... I completely agree with Ryan. noHooks option should be absolutely avoided. Seriously, if you use it in advanced cases like I have been doing, you will hit every WTF issue known to man. It is not made for developer use, even though it gives off that vibe. I think that is a mistake. I will write more about this in depth soon, but at least in my situation, my goal was to ultimately update a page and all of its descendant repeaters (repeaters within repeaters) only after the page is its descendant repeaters have been saved completely first without hook interference. Using noHooks basically fucks up everything up (saying it's been frustrating dealing with it is an understatement) and there are unintended consequences everywhere! The correct way to do what I described is to do something like this, which took forever to figure out (every line has a specific reasoning behind it): // // /site/classes/OrderPage.php // class OrderPage extends Page { public function getAggregateRootPage() { return $this; } public function finalize() { // your code to finalize the page, such as populating an order_total field, etc. } } // // /site/classes/OrderLineItemsRepeaterPage.php // class OrderLineItemsRepeaterPage extends RepeaterPage { public function getAggregateRootPage() { return $this->getForPage(); } } // // /site/init.php or /site/ready.php (doesn't matter) // wire()->set('finishedPages', new PageArray()); // hook 1: use Pages::saved only to build list of pages to finalize wire()->set('finishedPagesHook', wire()->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments('page'); if(!method_exists($page, 'getAggregateRootPage')) return; wire('finishedPages')->add($page->getAggregateRootPage()); // duplicated pages won't get stored }, [ 'priority' => 1000 ]); // hook 2: use ProcessWire::finished to finalize the pages 🤌 wire()->addHookBefore('ProcessWire::finished', function(HookEvent $event) { wire()->removeHook(wire('finishedPagesHook')); foreach(wire('finishedPages') as $finishedPage) { $finishedPage->finalize(); } }, [ 'priority' => 1001 ]); When I demo my system one day which is way more complicated than the example code above, it will become clear. // TLDR: don't use noHooks when saving a page. DON'T! Instead, create a log of what pages need to be finalized, and act on those pages in ProcessWire::finished hook, which is when you can be absolutely sure the coast is clear. I wish I knew about that hook earlier. If you follow those simple rules, you don't have to think about CLI vs non-cli, ajax vs. non-ajax, whether the current page process implements WirePageEditor, uncache, getFresh, saved vs. saveReady, before vs. after hook, hook priority, editing a repeater on a page vs. editing the repeater "directly", where the hook should go (it should be in init.php/ready.php or in the init()/ready() method of a module), etc. Note: there's a whole other aspect to this in terms of locking the a page to prevent multiple saves (like if a page was being saved by an automated script and the same page was being saved by an editor in the GUI).
  5. Awesome. I use BunnyCDN as well (previously KeyCDN) configured with ProCache, mainly because they publish the list of IPs they use if their edge-servers need to pull assets (and then serve) from your website. While this post isn't directly related to your module, it matters if you are using WireRequestBlocker for the reasons I explained here (post only viewable if you have access). Long story short, if a CDN makes a request to a URL on your site that matches a blocking rule in WireRequestBlocker (rare, but it's bound to happen by accident) then the IP of that particular BunnyCDN edge-server will get blocked. Then if a visitor on your site is being sent assets from that edge server, then it will error because the CDN was never able to obtain it due to the edge-server being blocked. This is why the site might look fine in California, but broken in New York for example, as the user is being sent assets from different edge-servers. To prevent this from happening, I have a cronjob set up (runs every 24 hours) to grab the list of BunnyCDN edge-server IPs and I insert it into WireRequestBlockers "IP addresses to whitelist" field. This is a function that can do what I described above: function bunnycdnWhitelistIps() { if(!wire('modules')->isInstalled('WireRequestBlocker')) return false; // Fetch BunnyCDN edge server list $url = 'https://bunnycdn.com/api/system/edgeserverlist'; // Use cURL to fetch the content $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($httpCode !== 200 || $response === false) { throw new WireException("Error fetching data from BunnyCDN API. HTTP Code: $httpCode\n"); } // Parse the JSON response $data = json_decode($response, true); if(json_last_error() !== JSON_ERROR_NONE) { throw new WireException("Invalid IPs."); } // Extract IP addresses into an array $ipAddresses = []; if(isset($data) && is_array($data)) { foreach($data as $ip) { if(filter_var($ip, FILTER_VALIDATE_IP)) { $ipAddresses[] = $ip; } } } // Remove duplicates and sort $ipAddresses = array_unique($ipAddresses); sort($ipAddresses); $data = wire('modules')->getModuleConfigData('WireRequestBlocker'); $data['goodIps'] = implode("\n", $ipAddresses); wire('modules')->saveModuleConfigData('WireRequestBlocker', $data); }
  6. 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).
  7. @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.
  8. @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/") );
  9. 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.
  10. 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.
  11. 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.
  12. https://x.com/adamwathan/status/1559250403547652097
  13. 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.
  14. @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.
  15. I really wish I knew about this issue 2 years ago. Like... really really wish.
×
×
  • Create New...