Jump to content

JkPublishPages - Module to publish/unpublish, trash/delete or move a page depending on dates and times


Juergen
 Share

Recommended Posts

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.

move.thumb.png.eeddf1ffb17e212b1f5e59d69f985ad3.png

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

 

 

  • Like 11
  • Thanks 1
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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. ?

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

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?

  • Like 1
Link to comment
Share on other sites

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

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?

image.png.67115bbcb0bd5f1e1bdc68eab2eddbfa.png

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • 10 months later...

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

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

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

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

  • Like 1
Link to comment
Share on other sites

@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

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

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

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

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.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...