Jump to content

Jan Romero

Members
  • Posts

    680
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Jan Romero

  1. Neat. FWIW Tracy also shows hooks that were triggered during the request (in the debug panel). If you, like me, usually define your hook methods as closures, it’ll just say “{closure}”, but it does link to the source, so that’s nice! On the other hand it seems to show all hooks that were defined and doesn’t say whether they actually ran.
  2. I feel like it should be supported, since PW itself uses two modules directories, core and site, and they’re not hardcoded. When ProcessWire instantiates itself, it calls addPath() for /site/modules/ here (the core modules path is added in Modules::__construct): // from ProcessWire::load(Config $config) $modules = $this->wire('modules', new Modules($config->paths->modules), true); $modules->addPath($config->paths->siteModules); $modules->setSubstitutes($config->substituteModules); $modules->init(); https://github.com/processwire/processwire/blob/3cc76cc886a49313b4bfb9a1a904bd88d11b7cb7/wire/core/ProcessWire.php#L557 The problem is that addPath() needs to be called between the instantiation of Modules and the init() call and there’s no way for us to get in there. Unfortunately there don’t appear to be any hookable methods during this process (I don’t think hooks can be attached before this point anyway?). But I think you can get away with just adding your path after the fact and calling Modules::refresh(): // seems to work in init.php wire('modules')->addPath(__DIR__ . '/modules-2/'); wire('modules')->refresh(); Of course this adds a lot of unnecessary cost to every request, because it basically loads all modules again. And I don’t think it’ll work for preload modules. If this is important to you maybe ask Ryan to make this a config setting? ProcessWire already uses an array for module directories, only the assumption that the first two entries are core/modules and site/modules seems to be baked in.
  3. Chill 😅 You could post little travel logs instead next time 😉
  4. May want to pass ['noHooks' => true] to the save() call to prevent the hook from being called recursively: https://processwire.com/api/ref/pages/save/ (I also like the 'quiet' option).
  5. I have a local copy that uploads changes via FTP on every save because it’s easy. If I’m just trying stuff out in production I slap “if (user()->isSuperuser())” on it 🤣
  6. This seems to be because the XHR request that gets the live results as JSON requests the same URL and headers as a normal visit to the search page, so the browser gives you its cached version. You can also observe it the other way around: If you head to https://processwire.com/search/?q=hello and then use the search box for the same keyword, the browser console will show a JSON parse error because the live search got the full page instead of JSON. I imagine this could be fixed by sending the ol’ X-Requested-With: XMLHttpRequest header. Or by using the appropriate content negotiation header (I think “Accept: application/json”?).
  7. Interesting, I hadn’t heard of Mollie. You seem to have something misconfigured, might want to adjust the page name: It’s currently ”rockmollie-1“, but your short url forwards to “rockmollie” 🙂
  8. Adding all pages and then saving is the way to go. ProcessWire’s arrays have change tracking so they’ll know which items were added or removed. You can dump the field before saving and you should see a property called "added" or some such that lists them. Try TracyDebugger’s bd() method (recommended!) or just var_dump().
  9. Any particular reason for this curly brackets syntax? I’m far from a PHP pro but I’ve never seen that and $assetPage->content_tags->add($tagPage) should suffice. I might look at your code again later when I’m on desktop. Also, might be obvious, but make sure you save the tagPages before adding them 😅
  10. The difference between the two snippets you posted is that $pages->find() will make a database query and $page->event_locations->find() filters the repeater items already in memory (a PageArray). Confusingly, there are some features that are only available in one or the other. My guess is probably the “today” condition doesn’t work with in-memory selectors, because it doesn’t know you’re comparing dates at that point. So under the hood it’ll be something like 1726956531 >= 'today' (or maybe '09/22/2024 00:08' >= 'today' due to output formatting, I’m not sure). As @da² suggested, try this: $pages->find('template=repeater_event_locations, event_date>=today, include=all, event_locations.owner.id=' . $page->id . ', sort=event_date, sort=location.location_city') That should get all repeater items from the database which belong to $page. If you want to use $page->event_locations instead, I would suggest just foreaching them and skipping the ones you don’t want. You’re going to foreach them anyway, so you might as well do filtering and output in a single loop. But the other option should be more performant, because you’re never loading the ones you don’t need.
  11. I’m assuming you do something like this: <a href="<?=$manufacturer->url()?>#siding">Get Wood</a> Go to the template settings of the $manufacturer page’s template and in the URLs tab, set the slash option to “No”: This will make the url() method generate links without the trailing slash and it will stop redirecting to the slashed version. That said, I’m pretty sure the links should work either way.
  12. Can’t you autoload your Process module? https://processwire.com/docs/modules/development/#automatically-loading-modules If you set 'autoload' => 'template=admin' in getModuleInfo() the ready() method should be called on every request within the PW admin. You can then determine if your hooks are needed as you’re already doing. I'm not sure what you mean by this, but you can use $modules->get('TestUpdate') to get an instance of your module? Yes, you can use $config->urls->admin, for example, but since you're creating a Process module, you should be able to get the entire URL using $this->getProcessPage(). That should be way to go since users can theoretically move or rename your Process page (as well as the Admin itself). If you're inside a request to the Process page, it will get you the current Page. Otherwise it will get the first page using the Process.
  13. Seconding this, of course! However, the WireCache fix reminded me of an old issue that still persists as far as I can tell 😉 No upvotes, but still feels like a bug to me: https://github.com/processwire/processwire-issues/issues/1604 It’s about the preloading feature preventing fresh cache values from being generated.
  14. AFAIK ProcessWire’s pagefileSecure feature only works on the page level. So when your page is viewable by guests, its files will be viewable as well. However, when pagefileSecure is active, all files should be routed through the hookable method ProcessPageView::___sendFile(). It’s a short little method you could hook to add your own logic. For example: $this->addHookBefore('ProcessPageView::sendFile(template=MY_SPECIAL_TEMPLATE)', function(HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); $filename = $event->arguments(1); if ($this->wire->user->isGuest()) throw new Wire404Exception('File not found', Wire404Exception::codeFile); });
  15. This was solved a couple of months after the OP by this PR: https://github.com/processwire/processwire/pull/161. See also the announcement blog post: https://processwire.com/blog/posts/pw-3.0.178/ Must be enabled in config.php: $config->wireInputArrayDepth = 2;
  16. Oh excellent, thanks! I’ve been asking myself this, but been too lazy to actually figure it out instead of just changing the table manually for project-specific modules 😄
  17. This is difficult to fix without more of the surrounding code. This isn’t on Github by any chance? If you’re not comfortable with fixing it yourself, you should probably give someone with expertise in PHP or ProcessWire direct access. Also please use the code formatting to post snippets, instead of quotes. Try to see if you can find where $contact is declared in the first 25 lines of structure.php. Apparently it’s a Boolean, but is expected to be a Page.
  18. Before PHP 8 you could put anything into the count() function and it would return 1 if it wasn’t null. The code in line 241 in includes/_head.php depends on this old behaviour, so you’ll have to rewrite it. Since there only ever seems to be a single image or none at all, you can probably just remove count() entirely: if ($page->eyecatcher) { … } There may be more instances of similar things in the codebase as PHP 8 deprecated several things. Shouldn’t be too hard to fix, though.
  19. I don’t pretend to have a good understanding of this stuff, but does the PW installer perhaps rely on output buffering to modify headers after starting the response body? Do the errors go away when you set this to 4096? Edit: I see this is exactly what the AI said. ignore me
  20. Gitea. I’m using it on Windows and it’s literally a a single executable that you swap for updates. Run it as a service with a Sqlite file next to it, done. Straight bussin, as I believe they say. https://about.gitea.com Also, I made my own little Pocket/ReadItLater thing using ProcessWire when Pocket started to get incredibly annoying a couple of years ago. It’s not presemtable, but I use it every day, lol.
  21. Did your hoster send you a scary email about the old Adminer script containing known vulnerabilities? Cause that happened to me ?
  22. That’s how you’re supposed to do it as far as I know. Just swap /wire/ and you’re done. See the docs for more details on .htaccess and /index.php, which you do sometimes need to update, but it doesn’t happen very often: https://processwire.com/docs/start/install/upgrade/ Non-core modules will be installed to /site/modules/ so they are not affected by PW updates. Don’t manually put modules into /wire/modules/! Indeed you should never* change anything in the /wire/ directory at all. *Of course, feel free to hack on the core as much as you like, but you’ll need to take extra steps when updating to avoid wiping out your changes. And updates may break your modifications in other ways, I suppose. I’m not sure it’ll break anything, I guess you’ll have to test it ? ProcessWire caches some information about installed modules in the “caches” database table, so you may need to delete that? But generally I’d imagine things to go smoothly. Yeah, if you update .htaccess you need to make sure to keep the changes you made to suit your environment. It rarely changes, though, so it’s not too messy to just check out the last handfull of diffs and see what you may need to add: https://github.com/processwire/processwire/commits/dev/htaccess.txt. As you can see, the last change was in January, but I’ve gone back a couple of years and really nothing critical happened.
  23. I have also started on this and I’m not sure how to approach it really. For instance, the sidebar with the authors is both kinda bad UX and wastefully implemented. Indeed the entire thing is wasteful as heck. Every time a book cover comes into view it preloads not only its entire details page, but also, for some reason, ONE MEGABYTE of random other stuff. Like check this out, this is what your browser deals with for EVERY book cover you see in that demo: [Removed because it triggered some kind of spam protection, lol. Sorry about that! Just check out your dev tools when visiting the demo from the OP.] Doesn’t seem like that much at first glance until you notice the weird repetition at the top and also, check out that horizontal scrollbar. Every book cover you look at seems to load EVERY AUTHOR EVER. Like… what? I’m not a galaxy-brained react dev, so maybe this is genius beyond my comprehension? Anyway I’m kinda not into loading all authors even once just to filter them client-side, but deviating from the orginal seems like a cop-out?
×
×
  • Create New...