In order to make this module more complete, and the node entities integration better. It may make sense adding the ability to schedule the publishing of the first node revision. As a side effect this would make this module a replacement for the Scheduler module.

In order to accomplish this, I propose we do the following:

  • Add options to enable this feature on module settings page.
  • Add the scheduling form fields under "Publishing options" when creating the node.
  • Add code to handle the published/status flag of the node.

The way this module was written, i.e. making each entity type a plugin, I think it should be easy to handle this special case.

Comments

merlinofchaos’s picture

It should be.

My theoretical ideas are:

1) setting the 'published_revision' to 0 sets the entity unpublished, if the entity supports having an unpublished state. Most entities don't, that I know of, but comments and nodes do. Though who'd schedule comments?

2) We have to make sure adjust to adjust assumption that there is always a published revision.

I agree, I don't believe this will be too hard. I don't think I have the time to do it but I'm willing to help guide a patch.

merlinofchaos’s picture

Looking through the code, the organization of this makes it relatively easy.

I think the biggest issue is that we need to be careful about the setting of the 'published' flag manually. If the user sets the node to published, we have to make sure to set the published revision to the current revision. Even if we disable the flag in the UI (which may not be a good idea) we still have to do this in case something behind the scenes publishes the entity.

recidive’s picture

Assigned: Unassigned » recidive
Status: Active » Needs work
StatusFileSize
new4.76 KB

I started working on a patch for this. The patch is not yet complete. The UI is there for new nodes. But they are not being published on schedule yet.

merlinofchaos’s picture

Hm. That *looks* like the schedule should publish them. Not sure what's missing.

Comments on what you have:

Because not all entities support a published flag, all of this needs to be switchable. I recommend having a 'supports_publishing_flag' on the entity plugin; it defaults to false and the node one sets this to true. Fieldable Panel Panes don't have a published flag so that's going to be important out of the gate.

Other than that, the list of revisions' table is going to need a special "not published" row. You can 'schedule' that which would then schedule revision_id 0 for the as the published_revision_id.

merlinofchaos’s picture

We may have to actually duplicate the schedule publishing widget in the revision tab as well as the publishing tab. Either that or we have to somehow combine the two.

recidive’s picture

Some parts of discussion with @merlinofchaos on IRC:

merlinofchaos: recidive: The UI I speak about is on the revisions tab -- i.e, node/%/revisions -- where we list the revisions and show which one is published. We also need to give them the ability to unpublish the current published revision there.
recidive: merlinofchaos: right, and this tab doesn't show up when there's only one revision
recidive: merlinofchaos: ok, I was looking for what prevent the revisions page to show up when there's only one revision
merlinofchaos: recidive: Oh that's probably the access callback on it
recidive: merlinofchaos: _node_revision_access ?
merlinofchaos: recidive: Probably yes. Would have to override that with one that will make sure revision access is available even with just one revision.

recidive: merlinofchaos: "set the draft revision current"
recidive: merlinofchaos: isn't this being done already?
merlinofchaos: recidive: In 99% of the cases yes.
merlinofchaos: recidive: But there's always some possibility that a prior revision is being edited and saved and that would change the current revision away from the draft revision.

merlinofchaos: recidive: One thing that bugs me here is that this gives us two different places on the node edit form where we might have the publish widget -- in the 'publication' section and in the 'revision' section.
recidive: merlinofchaos: I think it does make sense under "Publishing options"
recidive: merlinofchaos: The scheduler module adds a new tab
recidive: maybe we could add one to, e.g. "Scheduling"
recidive: merlinofchaos: and also options for the "published" checkbox, I'm not sure on this yet too
merlinofchaos: recidive: I was going to add a new tab but then it felt like it was extra weight.
merlinofchaos: recidive: I was thinking of maybe hiding the 'published' checkbox entirely.
recidive: merlinofchaos: so if date was left blank, it will be published or just be saved as draft?
merlinofchaos: recidive: If the box is checked and the date is blank, it'll be published immediately; if the box is unchecked, and there is no published draft (i.e, a new node) then it will be saved unpublished.
merlinofchaos: recidive: And if the box is checked and the date is in the future, it will be saved unpublished and then published on schedule.

merlinofchaos: I am also thinking we might want to not let users create unpublished entities if they won't have permission to view the entity when it's done. For nodes you need 'administer nodes' or 'view own unpublished content'

recidive’s picture

StatusFileSize
new7.03 KB

Here's an updated patch. Changing access callback to make it show the revions page when there's only one revision. Adding the 'supports_publishing_flag' but not using it yet.

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new7.54 KB

Here's an updated patch.

  • Moving form to a "Scheduling" vertical tab>
  • Making sure a schedule is created for first revision
  • Fixing code that set the status flag
merlinofchaos’s picture

I'm not sure we can have the access function in the plugin file. We can't guarantee that file is loaded at the time the menu is parsed and I don't think it loads the 'file' just to run the access function. I could be wrong on this, but I think that has to be in the .module. We can use the access switcher though.

I think control of the published flag may need to be optional. While I definitely see this as interesting and valuable I am concerned that it is an impediment for sites that do not want that. I am not sure of this, though, and need to think more on it. Discussion there could be valuable.

Otherwise I feel we are on the right track here.

recidive’s picture

StatusFileSize
new8.07 KB

Ok, I changed the access callback to the access switcher. New patch attached.

For the settings form for disbling this feature, where should we put that, any ideas?

Thanks for having the time to review the patch.

recidive’s picture

Re-rolled the patch.

I've found a problem when adding a node and checking the "Publish draft" but not entering a date. In this case date is set to time() so a schedule isn't created and the set_published_revision_current() method isn't called. I tried fixing this by overriding the update_entity_schedule() method, since this is where the scheduling bypass happen, couldn't get it to work yet. Here's what I added:

  public function update_entity_schedule($entity, $publish_date, $revision_id) {
    parent::update_entity_schedule($entity, $publish_date, $revision_id);

    // This will run when saving a node marked to be published and $publish_date
    // is empty or a past date.
    if ($publish_date <= time()) {
      $entity->status = !empty($entity->published_revision_id);
    }
  }

We need to figure out how to best change the status flag in this situation.

recidive’s picture

StatusFileSize
new8.07 KB

Re-rolled patch attached.

recidive’s picture

StatusFileSize
new8.7 KB

Fixed the problem with publishing immediately on node insert. I ended up overriding the hook_entity_insert() on ERSEntityNode like this:

  public function hook_entity_insert($entity) {
    parent::hook_entity_insert($entity);

    // When inserting a node, checking the "Publish draft" checkbox and not
    // entering a date, no schedule is created and
    // set_published_revision_current() doesn't get called, so we need to call
    // it here to make sure node status flag is set to TRUE.
    if (!empty($entity->published_revision_id) && empty($entity->status)) {
      $this->set_published_revision_current($entity->nid, $entity);
    }
  }

I wonder if the logic here shouldn't be on ERSEntityDefault hook_entity_insert() implementation instead.

merlinofchaos’s picture

That does seem like it probably could be done in the base plugin. It could be skipped if support for a published flag doesn't exist, so we don't do an extra save.

recidive’s picture

StatusFileSize
new8.43 KB

Updated patch moving the changes in #13 from ERSEntityNode to ERSEntityDefault. As discussed with @merliofchaos in IRC, we don't need to check for support for published flag, since there's no default implementation for set_published_revision_current(). Also it may be good to give other handlers the opportunity to do other stuff in set_published_revision_current().

Here's what still needs to be done:

1. Make operations show up for first revision on revisions table.
2. Add an operation "unpublish" to revisions table
3. Add setting for disabling scheduling first node revision completely.

Task #1 seems pretty straightforward, #2 need to decide where to implement this, on base plugin or node specific, we can show this operation only if it supports published flag, #3 need some guidance on how to override/alter ERS settings form, or to know where else to put this.

merlinofchaos’s picture

For #2: Probably in the base handler, with an if on ->supports_publishing_flag.

For #3: Let's hold off for now and ensure we need it before coding it.

recidive’s picture

Status: Needs review » Needs work

Ok, I will have another crack at this tomorrow:

Here's the list of things that needs to be done:

  • Make operations show up for first revision on revisions table.
  • Add an operation "unpublish" to revisions table
  • Make sure "Publish draft" checkbox is checked if node type defaults to "published" in content type settings.
  • Fix a bug which is making the first revision published after adding a draft (that was regression introduced when changing the set_published_revision_current() to the base class).
recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new15.88 KB

Here an improved patch, adding options to node type settings form for publishing new nodes and drafts by default.

Also added 'unpublish' operation to revisions table.

recidive’s picture

We still need to figure out how to make this code run only when the node is first inserted:

      // When publishing a revision immediately after inserting the entity
      // set_published_revision_current() doesn't get called, so we need to call
      // it here to make sure entity types do what they need to do in this method.
      if (!empty($entity->published_revision_id)) {
        $this->set_published_revision_current($entity_id, $entity);
      }

Here's a followup patch, with small fixes.

Also, attached are some screenshots for the node type settings and for the revisions table with unpublishing node feature.

paul kim consulting’s picture

recidive, thanks for your work on this. Is there any plans on scheduling an unpublish event in the future?

recidive’s picture

Hi Paul, I'm not sure it's on the plans. But it's for sure something we think about from time to time.

@merlinofchaos, can answer this better.

BTW, have you tested my patch?

Thanks.

merlinofchaos’s picture

Yes I think scheduling an unpublish is necessary. An unpublish link can go in the revisions list where there are currently no links because you can't manipulate the published revision.

recidive’s picture

@merlinofchaos my last patch includes the unpublish link next to the published revision on revisions table.

I think scheduling the unpublishing is out of the scope for this issue.

merlinofchaos’s picture

I disagree. Publishing is thoroughly schedulable; unpublishing should be similarly schedulable.

recidive’s picture

Status: Needs review » Needs work

Ok. Needs work then.

Paul Kim Disney’s picture

recidive -- am I correct is saying that scheduled unpublishing is actually working in ERS?

Looks to me like you have done the following:

1.) You've put back "Publish" checkbox in publishing options.
2.) You've put scheduling under "Revision information"
3.) The "Publish draft" acts a differently than Published in publishing options. "Publish draft" makes the guest-facing experience of this particular node THIS revision. Publish in Publishing option sets the publish state of THIS revision. So if you publish draft of a particular revision that is not set to Publish in Publishing options, the guest will get "Access denied".
4.) Timed publishing works correctly as long as cron is setup to run regularly. You can also run cron manually.
5.) To unpublish a node, you need to set a draft to be published under revision information, and uncheck published in Publishing options.
6.) The two terminologies are the same, but they do different things.

It's awfully confusing to have 2 terms dubbed "Publish". I am in favor of changing the "Publish Draft" to "Make this Draft Active", and replace all "Published" instances with "Active"

recidive’s picture

@Paul Kim Disney: No, I've not added back the "Publish" checkbox in "Publishing options". The screenshots I've sent above are from content type settings form.

It looks like you're describing ERS without my patch.

recidive’s picture

StatusFileSize
new60.14 KB
new25.34 KB
new21.36 KB

Updated patch implementing UI for scheduling entity unpublishing. It's not fully working as some code needs to be added as well as schema changes in ers_schedule table needs to be made to also accomodate unpublishing schedule.

Should we use the same table for unpublishing schedules? I think it will need a new column 'action' that can be set to either 'publish' or 'unpublish' and also change the 'publish_date' field to just 'date'. Also the 'revision_id' field will be empty for unpublishing schedules, but that shouldn't be a problem.

Attached are two screenshots, one for the unpublish link on revisions table and other for the node editing form.

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new21.51 KB

Here's an updated patch. Scheduling unpublishing is still broken. Need some help with this. The unpublishing schedule is being created on the revision page unpublish link, but not directly on node editing.

Edit: I'll be around tomorrow, to finish this.

merlinofchaos’s picture

StatusFileSize
new21.85 KB

Ok, I've done a little more work on this, but I've hit a mental wall for the moment and will have to come back to this in the morning. I've made a few minor adjustments.

I think for the UI we have to have either publish or unpublish, not both -- the ers_new_schedule supports only one or the other. Which might mean we need, instead of a checkbox, a selector: "No schedule", "Schedule publish", "Schedule unpublish", if we support unpublishing.

Otherwise, what seems to be happening on saving a node is that it tries to schedule unpublishing, and then the publishing stuff overwrites it; or it may simply get the wrong revision id because it's looking at the wrong thing.

Here's where I left off.

recidive’s picture

StatusFileSize
new24.39 KB

Here's an updated patch making the unpublish scheduling stuff work. There's just some small tweaks on UI left to do which are:

1. making the unpublishing schedule show up on revisions table and
2. make the '#states' work for disabling the schedule form based on schedule selector.

Needs review of work so far.

recidive’s picture

StatusFileSize
new24.75 KB

New patch fixing the '#states' by adding a wrapper and a checkbox to trigger states.

recidive’s picture

StatusFileSize
new26.09 KB

Adding the unpublishing schedule to revisions table.

merlinofchaos’s picture

Status: Needs review » Fixed

I am'd and pushed this.

Note that it introduced a whitespace error, we shoudl fix this:


[merlin@furor ers (master)]$ git am 1357058_11.patch
Applying: Issue #1357058: Making possible to schedule publishing first entity revision and to schedule entity unpublishing.
/var/www/ivillage/sites/all/modules/ers/.git/rebase-apply/patch:471: space before tab in indent.
        $publish_default = variable_get('ers_publish_new_' . $node->type, TRUE);
warning: 1 line adds whitespace errors.
[merlin@furor ers (master)]$ git push

My guess is there may be followups, but this is pretty good now.

recidive’s picture

StatusFileSize
new1.26 KB

Here's a small follow up patch that fixes the indentation problem and remove a debugging call.

merlinofchaos’s picture

Excellent. Pushed!

recidive’s picture

Version: » 7.x-1.x-dev

Here's another followup patch that fixes the following:

Fix some notices with UUID integration stuff.
Make scheduling first revision work again.
Make default values work again.
Make delete revision operation show up only if there are more then one revision.

I'm not quite happy with it, but the module is working better than without it.

recidive’s picture

StatusFileSize
new6.24 KB

Patch didn't get attached, due to validation error. Trying again.

recidive’s picture

StatusFileSize
new7.33 KB

New patch also fixes issue with scheduling drafts.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

merlinofchaos’s picture

Status: Closed (fixed) » Needs review
merlinofchaos’s picture

Status: Needs review » Fixed

Applied and pushed. Sorry about the delay here.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.