Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by thetuningspoon

  1. Why did I not know about this module until now?
  2. Mystery solved: https://github.com/processwire/processwire-issues/issues/430
  3. The resolution to this: https://github.com/processwire/processwire-issues/issues/430
  4. @dragan Yes. Unfortunately, findMany() has the same issue in that the queries are still separate and the initial queries still have to return all of the matching page IDs. Pages sum doesn't fit this use case, I don't think.
  5. We are putting PW through its paces on one of our projects. Currently we have 3.5 million pages and counting. Everything has been scaling well and is running great, except for some of our selectors that use subfields. Our project involves physical units (represented by PW pages) that transmit their status to our application each day, resulting in a new page for each transmission. We are using a page field on the unit to store a reference to its latest transmission. We then need to filter the units by their last transmission date, so we are using the following selector: $pages->find('template=unit, last_transmission.date_field<-1 day, last_transmission.date_field>=-7 day, sort=created, limit=10'); Once we had several thousand unit pages in the system, this selector began to fail. After doing some debugging to see what SQL PW was actually producing, we discovered that the problem was that the selector was generating three separate sql queries. One returned the ids of all of the units that had a last_transmission date greater than a given timestamp, one returned the ids of all the units that had a date less than a given timestamp, and the last took the results of the other two queries and applied any remaining selectors. Since there were several thousand units, the first two queries caused a memory error. We resolved this issue by using the created date instead of a custom date field on the last transmission, so the selector changed to: $pages->find('template=unit, last_transmission.created<-1 day, last_transmission.created>=-7 day, sort=created, limit=10'); For some reason PW was able to combine this into a single SQL query, whereas it was unable to do so with the custom field. Not sure if this is the intended behavior or not, but it looks like this is an area of PW core that might be improved upon. Has anyone else come across this issue and are there any other workarounds I might not be aware of?
  6. @kongondo Correct, I only want Page and not Child 1. Though it doesn't matter if Child 1 is matched too, because it has a different template from Page and I can exclude it by specifying the template in the selector. @tpr I tried your suggestion yesterday after seeing your post. The example I gave in my initial post was oversimplified. My selector is actually more like children.children.pageField=123 So that didn't work. Any ideas? I restructured the page tree to get things working for now (the pages I'm referencing in the selector are now direct children), but this may not be ideal in the long run.
  7. Just ran into a requirement on one of my sites which I don't think PW supports yet. I'm trying to match all pages that have a certain child, but the child is not an immediate child of the page. It is two levels down: Page -- Child 1 ---- Sub-child 1 ---- Sub-child 2 < I only want to select the parent Page if this one exists -- Child 2 This would be similar to the has_parent selector, but in the opposite direction. I searched the forums but didn't find any discussion of this feature/request. I seem to recall seeing it brought up at some point in the past, though.
  8. https://github.com/processwire/processwire-issues/issues/379
  9. @bernhard This looks amazing! I developed a CRM for a customer using ListerPro with some custom enhancements, but this is another level up! Must have been a LOT of work. Hope you were paid well
  10. @Robin S No, I am using ID. It works fine when editing the user in ProcessPageEdit (or from Access/Users), but not ProcessProfile.
  11. I just ran into this same issue. I tried to make a field dependent on one of the roles and it broke the profile, even though neither the roles field or the dependent field were visible in the profile at all. I created a copy of the ProcessProfile module under /site/modules/ and replaced this: if(count($form->getErrors())) { $this->error($this->_("Profile not saved")); return; } With this: $errors = $form->getErrors(); if(count($errors)) { if(count($errors) == 1 && strpos($errors[0], 'showIf') !== false) { // Everything is okay } else { $this->error(implode('; ', $errors)); // Show the actual errors instead of just a generic message return; } } This way if there is only one error message and it is related to a 'showIf' field dependency, the form will save anyway.
  12. I did try turning off SessionHandlerDB and using php's session_write_close() and that didn't seem to help either. I think I also tried $session->close() (which just calls php's function). Moreover, there are a couple ajax requests which do need to be able to write to the session, so a blanket session_write_close if $config->ajax is true wouldn't solve my issue Edit: I am going to try Redis. Will let you know how it goes.
  13. I am having trouble with executing multiple AJAX requests at the same time. The response is very slow and seems to be synchronous instead of asynchronous. I am using jQuery's ajax() function, so I don't think there's any issue on the client side. I think it is an issue with Session locking/blocking. I read somewhere that SessionHandlerDB would resolve this issue, but enabling it has not improved the situation any. I just want to confirm whether or not SessionHandlerDB is designed to handle concurrent requests efficiently, so I know what to rule out.
  14. @ukyo Is it possible to send each email individually, as with the base WireMail class? I tried the following, but it still includes all recipients in the email headers of each email that gets sent: foreach($recipients as $recipient) { $m->to(null); $m->to($recipient); $m->send(); }
  15. How are you calling WireMail? If you are using "$mail = new WireMail()" then I don't think it knows to use the WireMailPHPMailer module and will use the default WireMail() instead. Use "$mail = wireMail()" instead.
  16. Coming back to this... I just remembered that that this is what selector arrays were created for.
  17. @gebeer Thanks for that simple and effective solution! Note if you are using PW3 with namespaces you must use catch(\Exception $e) instead. The redirect at the end is optional. For my forms I only redirect on success.
  18. Just ran into this issue today. It seems like the subfield should disregard access settings since you are not actually getting the subfield, but are only checking for its relationship to the page you are getting. I see that there is still a todo note about this in FieldtypePage.module
  19. Thanks for that. I've read it over a few times now but I'm not quite getting it. How is this unnecessary? How else would one determine where each permission is applicable? Does he mean you could create a separate permission for each template, e.g. page-edit-home page-edit-basic-page, etc.? Yes, yes, yes... THIS sounds like the type of solution I would expect from ProcessWire. Simple, powerful, and un-opinionated. What became of this?
  20. Here is a simple hook I put together to allow for a custom redirect when a page is not viewable: /** * Automatically redirects users to the login page if they do not have view access to a page. To use, set "Show a 404 Page" in your template's Access settings. */ wire()->addHookBefore('ProcessPageView::pageNotFound', function($e) { $page = $e->arguments[0]; if($page === null || $page instanceof NullPage) return; // This was a real 404, not caused by page access (have to check for NullPage, not just null as implied in ProcessPageView docs) $e->session->redirect($this->pages->get(1)->url, false); // Redirect to the home page (login) }); This solves my immediate need. I can then hook Page::viewable() as needed and let PW take care of the rest. I'm hoping @ryan may have some guidance on all of this.
  21. An update: I missed something in my last post. It is possible to use a page ID instead of a URL for the redirect in the template Access tab, which solves the subfolder issue. However! For some strange reason, ProcessPageView::checkAccess specifically disallows using the home page (ID of 1) for the page ID here, silently overwriting it with page ID of the admin login form. This is unfortunate and ironic, as the enforced requirement of making the home page viewable to guests makes it a logical choice to serve as the login page for my application! The other strange behavior here is that if you do use a page ID instead of a URL, ProcessWire does not actually do a $session->redirect() to the page at all, but just renders the content of the alternate page at the original requested URL. This seems to be how ProcessWire's admin login works as well. Perhaps a way to keep the user on the original requested page after they login? This was a surprise to me, as it's not mentioned in the UI. I also found it interesting to discover that ProcessWire's own admin application shuns its own permissions system (or at least the template-level access part of it). If you look at the access settings for the Admin template, no view permissions are granted at all to any of the roles. Instead they are granted, I believe, based on the presence or absence of a single permission with the name of the process module associated with that page. This leads me to believe that I would be better off doing something similar in my own application. The more I dive into this more confused I'm becoming. This is really the only part of ProcessWire that seems unintuitive to me. I get the permissions -> roles -> users bit, but the template level access permissions seem arbitrary to me. For example: 1. Why are only certain permissions available to set on a per-template basis? 2. Why are four of these permissions displayed prominently in a table while the rest are in the "additional edit permissions and overrides" section? 3. What is it exactly that determines which permissions are special, and how do I create my own special permissions like these? 4. Why does the page-edit permission have 'sub-permissions' underneath it, but no other permission does? Is there a way of structuring my own custom permissions in the same fashion?
  22. Thanks, pwFoo, I will check that out. Here's another problem with method #1: The redirect URL field in the template Access settings is not relative to the subfolder that you have PW installed in (if you have it installed in a subfolder). I always develop in a subfolder, making this feature impractical.
  23. I've been getting more and more into building full fledged web apps using PW as a framework. I use PW for data modeling and storage, user management, etc., and extend the Page class for different templates to add functionality to specific types of pages/data models. It is a very simple and powerful way to develop. However, one thing that I have struggled with is finding the right way to approach page view access for users of an application (This would also apply to a password-protected area of any PW site). I'm going to try and boil this down to the most simple, common scenario, and go from there: I am building an app where every page in the app (except for the login screen) should be password protected. Should I... 1. Turn off page view access in the template access settings for the guest user and use the settings to redirect the user to a login page. This has the drawback that you cannot disable guest view of the home page (a built-in PW limitation that seems a bit arbitrary). You are also limited in how you can define what to do when the page is not viewable (you must use the options provided in the admin interface), and you do not have the option of continuing to load the page with an alternate view (for example, a login form). Also, sometimes it requires configuring a lot of settings for a lot of different templates. It also doesn't give you page-specific access control. 2. Leave the access settings wide open but write some code at the top of my template files, init.php, or ready.php to redirect users who are not logged in. This has the disadvantage that it only applies if ProcessWire gets that far into the page load process, and it doesn't effect any other aspect of ProcessWire (for example, whether the page is available in a $pages->find()). If I wanted, I could allow anyone to reach any page and just show/hide the content based on the user's permissions or role. If the user doesn't have permission, I could keep them on the same page but show the login. Once they logged in, they'd be on the page they were originally looking for. 3. Write my own hook before or after Page::viewable and/or ProcessPageView::execute (or somewhere else?) to switch access on or off and redirect based on my own requirements. This should be more reliable and secure than #2 and more flexible than #1, but it feels kind of like reinventing the wheel. Maybe the best approach is some combination of #1 and #3, with #2 reserved only for showing and hiding individual sections of a page that is already viewable. I'd be very interested to hear how others are handling this.
  24. Hi @Mike Rockett -- @melody and I took a look at this this morning. It looks like this is an issue with 0000-00-00 00:00:00 null dates in our strict MySQL environment. After replacing the NULL_DATE constant at the top of the module file with 'CURRENT_TIMESTAMP' and replacing the 0000-00-00 00:00:00 dates in Blueprints/schema-update-v2.sql and Blueprints/schema-update-v3.sql with the same, the problem went away after re-installing the module. Hope that helps.
  • Create New...