Juergen Posted January 23, 2023 Share Posted January 23, 2023 This is a reissue of a module of mine called "PublishingOptions", that I wrote a while ago. The big difference is that this module is written in PHP 8 and has some nice additional features. The old module could only publish and unpublish pages depending on date and time settings, but the new version goes much further. So you can decide what should happen after the publication end date has been reached. You have the following options: Unpublish the page - this is what the old version did Move the page to trash - new Delete the page permanently- new Move the page to a new position in the page tree - new The last option will be interesting if you want to move the page fe to an archive after a certain date. You can select the new parent page and after the publication end date has been reached, the page will be moved under the new parent page. You will find a more detailed instruction and download possibility at https://github.com/juergenweb/JkPublishPages This module is Alpha stage and should be tested carefully before using it on live sites. I have planned to add this module to the PW module download section, so everyone is invited to test it out and to report issues directly at GitHub. Thanx 11 1 Link to comment Share on other sites More sharing options...
Stefanowitsch Posted January 24, 2023 Share Posted January 24, 2023 Cool! I've been searching for a module like this. This comes in handy when users are preparing blog/news articles and want them to be published automatically on a specific date. I will definitely try it out. 2 Link to comment Share on other sites More sharing options...
Juergen Posted January 24, 2023 Author Share Posted January 24, 2023 Glad to hear that! ? Let me know, if you discover any issues. I will add this as soon as possible to the ProcessWire module directory, but as written, it needs to be tested first by several people. 1 Link to comment Share on other sites More sharing options...
Stefanowitsch Posted January 24, 2023 Share Posted January 24, 2023 I PHP 8.1 required? My projects run on PHP 8, because of several modules that do not work with 8.1 (yet!). Link to comment Share on other sites More sharing options...
Juergen Posted January 24, 2023 Author Share Posted January 24, 2023 No, it should work with 8.0, but not below. I have not checked it directly on my local server, but PHP-Storm does not complain after changing the version. I have changed the version on GitHub too, but you do not need to download it again. Please let me know, if something unexpected occurs, but I guess it will not.... BTW: In the module configuration settings set the CronJob interval to 1 minute for testing purposes, so you can check the functionality immediately. Later on, setting the value to 1 hour again, will be enough. Best regards 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 24, 2023 Author Share Posted January 24, 2023 BTW: You will get also a notice that your system does not fulfill the requirements if you have not installed LazyCron (not only if the PHP version is lower). You can ignore this, because LazyCron will be installed automatically during the module installation, if it is not installed. Unfortunately, Processwire gives you a warning that your system does not fulfill the requirements for the module, but not exactly what the problem is. ? 1 Link to comment Share on other sites More sharing options...
Stefanowitsch Posted February 7, 2023 Share Posted February 7, 2023 I have installed the module. On the module settings page in the "Add fields to template" checkbox-list some of my templates are missing (where I need to add the field). Does the module kind of "sort out" some templates depending on the settings here? Am I able to add the required fields "by hand" in the template settings instead? 1 Link to comment Share on other sites More sharing options...
Juergen Posted February 7, 2023 Author Share Posted February 7, 2023 Hello Stefanowitsch, you are right - this is exactly what it does. If you need a certain page to be selectable, you have to make some adjustments in the appropriate page template and sometimes in the template of the parent too. I recommend you to take a look at both template settings (current page template and parent page template) - in one or in both must be some restrictions set. If you need help, you can post a screenshots of both template settings here, and I will try to figure out the responsible setting. 1 hour ago, Stefanowitsch said: Am I able to add the required fields "by hand" in the template settings instead? This would not help you, because, apart from this module, ProcessWire does not let you choose and store a parent page, which will be not be allowed to be a parent page according to your template settings.? Link to comment Share on other sites More sharing options...
Stefanowitsch Posted February 7, 2023 Share Posted February 7, 2023 3 minutes ago, Juergen said: Hello Stefanowitsch, you are right - this is exactly what it does. If you need a certain page to be selectable, you have to make some adjustments in the appropriate page template and sometimes in the template of the parent too. I recommend you to take a look at both template settings (current page template and parent page template) - in one or in both must be some restrictions set. If you need help, you can post a screenshots of both template settings here, and I will try to figure out the responsible setting You are right. This setting here in the page template settings seems to be responsible for including/excluding the template in the module settings. This was set to "NO" in my case: May pages using this template have children? Is this critical for the module to work? I want to include the "Published From" field to a blog post template. This template should not be allowed to have subpages underneath it. 1 Link to comment Share on other sites More sharing options...
Juergen Posted February 7, 2023 Author Share Posted February 7, 2023 Sorry, @Stefanowitsch This was a missunderstanding. In your case every template should be visible. Link to comment Share on other sites More sharing options...
Juergen Posted February 7, 2023 Author Share Posted February 7, 2023 My explanation, was for the parent pages, not for adding the publishing fields to the template. To clearify: This blog post template will not be visible at the checkboxes list for the templates in your case? I will take a closer look on my local installation and give you a feed back after lunch. I guess there will be a problem in querying templates. 1 Link to comment Share on other sites More sharing options...
Stefanowitsch Posted February 7, 2023 Share Posted February 7, 2023 8 minutes ago, Juergen said: My explanation, was for the parent pages, not for adding the publishing fields to the template. To clearify: This blog post template will not be visible at the checkboxes list for the templates in your case? I will take a closer look on my local installation and give you a feed back after lunch. I guess there will be a problem in querying templates. I'll send you a PM with some screenshots of my page structure and the settings. 1 Link to comment Share on other sites More sharing options...
Juergen Posted February 7, 2023 Author Share Posted February 7, 2023 Hello @Stefanowitsch There was a wrong query string inside the method, which is responsible to find all frontend templates. I have corrected it on Github. You do not need to download and install the whole module. Please replace the file JkPublishPages.module from the module with the new one at Github and let me know, if it works now. I have bumped up the module version too, because this was a significant malfunction. BTW: you can set the child settings to no again and only to mention: the homepage is excluded from the templates. 1 Link to comment Share on other sites More sharing options...
Stefanowitsch Posted February 7, 2023 Share Posted February 7, 2023 Yes I can confirm now hat everything works as expected. 1 Link to comment Share on other sites More sharing options...
snck Posted December 8, 2023 Share Posted December 8, 2023 Hey @Juergen, today I ran into a really strange issue and it took me a while to track it down. I use FormBuilder and automatically save entries to PW pages. I had the issue that although I selected to save to published pages (in FormBuilder config for the form) my pages always had the unpublished status. I wanted to blame FormBuilder first, but then I noticed that there was a hook in JKPublishPages on page save: /** * Set page status to unpublished or remove unpublished status depending on if date range is out of date or not * This runs on manual save * @param HookEvent $event * @return void */ protected function setPageStatusManually(HookEvent $event): void { $page = $event->arguments(0); $from = true; if ($page->jk_publish_from) { $from = $page->jk_publish_from < time(); } else { $page->jk_publish_from = time(); } $to = true; if ($page->jk_publish_until) { $to = ($page->jk_publish_until > time()); } if (!$from || !$to) { $page->addStatus(Page::statusUnpublished); } } Shouldn't this contain a check so it only applies to the templates selected in JKPublicPages' module settings? In my case it sets pages that have no jk_publish_from and jk_publish_to fields to unpublished. When I comment out $page->addStatus(Page::statusUnpublished); or deactivate your module everything works as expected. Could you please check that and provide a fix? I guess this causes issues for others as well when creating pages from the API. Cheers, Flo 1 Link to comment Share on other sites More sharing options...
Juergen Posted December 8, 2023 Author Share Posted December 8, 2023 Hello Flo, thanks for reporting this issue and a possible solution. I have added a fix und bumped up the version number. Please update the module and check if the issue is gone now. Best regards Jürgen 1 1 Link to comment Share on other sites More sharing options...
snck Posted December 8, 2023 Share Posted December 8, 2023 @Juergen wow, that was quick! ? Installed it and everything is working as expected now. Thank you very much! ? 1 Link to comment Share on other sites More sharing options...
snck Posted April 24 Share Posted April 24 Hi @Juergen, unfortunately I have a problem again or maybe I am just really confused on how the module should work or might have worked in my case before. I have JkPublishPages enabled for one template only. This is an article page (news_article). Editors should be able to schedule publication of articles by selecting a date and saving (as unpublished). I would expect that JkPublishPages works in the following way: If no date (jk_publish_from or jk_publish_until) is given, the page status stays completely untouched (unpublished in my case) If jk_publish_from is given, JkPublishPages changes the page status to published on the first execution of LazyCron (after the selected date) If jk_publish_until is given, JkPublishPages changes the page status to unpublished on the first execution of LazyCron (after the selected date) Please correct me, if this is not the intended behavior. In my case whenever I create a new page or change an existing page, the jk_publish_from field gets populated automatically on page save with the current time, although I save the page as unpublished and keep the field empty. This in turn results in an (unwanted!) publishing on the page on the next execution of LazyCron. I think that the problem is in the following part of the code (lines 412ff): protected function setPageStatusManually(HookEvent $event): void { $page = $event->arguments(0); // check if jk_publish_from field is present on the given page if(!is_null($page->jk_publish_from)){ $from = true; bd($page->jk_publish_from); if ($page->jk_publish_from) { $from = $page->jk_publish_from < time(); bd($from); } else { $page->jk_publish_from = time(); bd($page->jk_publish_from); } $to = true; if ($page->jk_publish_until) { $to = ($page->jk_publish_until > time()); } if (!$from || !$to) { $page->addStatus(Page::statusUnpublished); } } } If jk_publish_from is empty on page save, it gets populated automatically. Is this intended? Shouldn't the module only act if a value has been (explicitly) added by the user? The editors brought up this issue because they often draft new articles without knowing the puplication date in advance. The drafts shall of course stay unpublished until they are ready to publish and explicitly scheduled or published manually. Your clarification is highly appreciated! Best Flo Link to comment Share on other sites More sharing options...
Juergen Posted April 24 Author Share Posted April 24 Hello Flo, thanks for reporting this issue! You are right - the automatic population of the "from" field should not happen if a page is unpublished at the moment of saving. I will not add a quick fix inside the Hook function only, which is responsible for this behaviour. Instead I will test the module functionality more intense before offering a new update. I guess (hope) I will offer a new update solving this issue til the end of this week. For the moment, please overwrite the "from" date with a far date in the future to prevent the page from beeing published. Best reagards Jürgen 1 Link to comment Share on other sites More sharing options...
snck Posted April 25 Share Posted April 25 @Juergen, thanks for your quick reaction and taking care of the issue! I would appreciate a solution that does not populate dates automatically (e.g. setting a "from" date not for unpublished, but only for published pages). In my opinion the module should only read and interpret these values. Link to comment Share on other sites More sharing options...
Juergen Posted April 25 Author Share Posted April 25 Hello Flo 7 minutes ago, snck said: I would appreciate a solution that does not populate dates automatically This is not so trivial as it may seem at the first sight, because there are use cases where automatic population makes sense: For example: An auto population has to take place if your page is unpublished and you push the publish button, but you do not have entered a date into the from field. In this scenario the current date and time have to be set (auto populated) inside the from field. I will test some other scenarios as well and I will provide another update, if there are some use cases not covered by this version. Link to comment Share on other sites More sharing options...
snck Posted April 25 Share Posted April 25 30 minutes ago, Juergen said: For example: An auto population has to take place if your page is unpublished and you push the publish button, but you do not have entered a date into the from field. In this scenario the current date and time have to be set (auto populated) inside the from field. Why would it? The page status is handled by PW. Why would your module need to change values if I publish a page manually? Link to comment Share on other sites More sharing options...
Juergen Posted April 25 Author Share Posted April 25 It is more consistent, if a page is published and the date and time of publishing is visible in the published from field too. Otherswise, it may seem a little bit strange to some users, if the page is published, but the publish from field is still empty. But you are right, if you mean the visibility is handled by ProcessWire only ? Link to comment Share on other sites More sharing options...
snck Posted April 25 Share Posted April 25 I would disagree on that. If you only want to schedule publication of some of your pages, you would not expect anything to appear in these fields on pages that have been published manually. In contrary I think it is misleading this way, because it looks like the publication had been scheduled, although it was not. I think it is much clearer if the fields give a clear indication of the user's intention: Blank = nothing happens Filled = publish/unpublish at this date/time Imho the page status is handled by PW and editors should be aware that they can publish and unpublish pages manually. Your module is a great addition, but in my eyes it should enhance the core functionality by offering a way to schedule publishing/unpublishing without forcing additional actions or altering page data. Maybe it would be a nice addition to show a status in the fields that informs the user about the effect of the module like that (in an InputfieldMarkup or as description of the fieldset): Page is currently PUBLISHED, no settings have been applied Page is currently UNPUBLISHED, will be published on XX.XX.XXXX – XX:XX:XX Page is currently PUBLISHED, will be unpublished on XX.XX.XXXX – XX:XX:XX You could even make it really fancy and include a countdown or something like that. This is of course just a quick thought and I do not want to "order" new features. I just wanted to address the user experience aspect and make a suggestion how it could be improved. 1 Link to comment Share on other sites More sharing options...
Juergen Posted April 25 Author Share Posted April 25 Making a visible alert/info about the current status and the future status too seems to be a good way and I can agree with it too. I will implement this feature and update the module after test runs. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now