I'm trying to create a rule to publish a newly created node if certain conditions are met. However it seems whenever I use the "Publish the most recent pending revision" action on my rule, I get a load of errors. Does anyone know if there is something I'm doing wrong or if this is a bug?

How to repeat:

Create a rule using Rules module, set the event as 'After saving new content', and action as 'Publish the most recent pending revision'.

Export of my sample rule:

{ "rules_test_approve_new_node" : {
    "LABEL" : "Test approve new node",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "revisioning", "rules" ],
    "ON" : [ "node_insert" ],
    "DO" : [
      { "revisioning_rules_action_publish_latest" : { "node" : [ "node" ] } }
    ]
  }
}

Then create a new node and save. It will trigger error as below:

    Notice: Undefined property: stdClass::$current_status in revisioning_node_update() (line 601 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).
    Notice: Undefined property: stdClass::$current_title in revisioning_node_update() (line 602 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).
    Notice: Undefined property: stdClass::$current_comment in revisioning_node_update() (line 603 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).
    Notice: Undefined property: stdClass::$current_promote in revisioning_node_update() (line 604 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).
    Notice: Undefined property: stdClass::$current_sticky in revisioning_node_update() (line 605 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).
    PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'status' cannot be null: UPDATE {node} SET vid=:db_update_placeholder_0, status=:db_update_placeholder_1, title=:db_update_placeholder_2, comment=:db_update_placeholder_3, promote=:db_update_placeholder_4, sticky=:db_update_placeholder_5 WHERE (nid = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => 3 [:db_update_placeholder_1] => [:db_update_placeholder_2] => [:db_update_placeholder_3] => [:db_update_placeholder_4] => [:db_update_placeholder_5] => [:db_condition_placeholder_0] => 3 ) in revisioning_node_update() (line 607 of /private/var/www/drupal7-demo2/sites/all/modules/revisioning/revisioning.module).

And this is on a demo build using:

  • Drupal 7.14
  • Rules 7.x-2.1
  • Entity API 7.x-1.0-rc3
  • Revisioning 7.x-1.4

My content type has the following Publishing options settings:

  • Published = false
  • Promoted to front page = false
  • Sticky at top of lists = false
  • Create new revision = true
  • New revision in draft = true
  • New revision in draft - create new revision = Only when saving article content that is not already in draft/pending moderation

I could try to use the 'Publish content' rule instead of the 'Publish the most recent pending revision' action, but though that doesn't throw errors, the node doesn't get published.

Thanks

Comments

victoriachan’s picture

StatusFileSize
new491 bytes

The problem is coming from this chunk of code on revisioning_node_update($node) function:

  if (!empty($node->revision_moderation) && (isset($node->revision_condition) || !empty($node->revision))) {
    // Enter when revision moderation is on and revision_condition=0,1
    // Have to do this due to D7's "sick" denormalisation of node revision data.
    // Resetting the fields duplicated from new {node_revision} back to their
    // originial values to match the current revision as opposed to the latest
    // revision. The latter is done by node_save() just before it calls this
    // function.
    // By resetting {node.vid} {node.vid} < {node_revision.vid}, which makes
    // the newly created revision a pending revision in Revisioning's books.
    // Note: cannot use $node->old_vid as set by node_save(), as this refers to
    // the revision edited, which may not be the current, which is what we are
    // after here.
    db_update('node')
      ->fields(array(
        'vid'     => $node->current_revision_id,
        'status'  => $node->current_status,
        'title'   => $node->current_title,
        'comment' => $node->current_comment,
        'promote' => $node->current_promote,
        'sticky'  => $node->current_sticky))
      ->condition('nid', $node->nid)
      ->execute();
  }

The current_status etc fields are supposed to be set in revisioning_node_presave() but since this is a new node, the function returns at the following line and skipped the bit at the bottom which sets $node->current_status, $node->current_title, etc fields required by the code in revisioning_node_update().

if (!isset($node->nid)) { // new node
    return;
  }

I have attached a patch to set the $node->current_status, $node->current_title, etc fields as the value of the $node->status, etc fields if the current node is a new node. This seems to have fixed the issue for me.

johan.gant’s picture

I had a similar issue to this on my project. This patch works for me, thanks!

rdeboer’s picture

Status: Active » Fixed

Patch applied with attribution. Thanks Victoria.
Sorry for the delay.
Rik

Status: Fixed » Closed (fixed)

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

d.olaresko’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
StatusFileSize
new1.16 KB

Got the same problem. The problem is the column "comment" from table "node" is mandatory.
It means that we need to set some value otherwise it will cause PDO Exception.

I have attached patch that fixed it for me.

Status: Needs review » Needs work

The last submitted patch, 5: revisioning-publish_rule_bug-1627400-5.patch, failed testing.

rdeboer’s picture

Patch from #5 applied. Thanks Dmitry.

rdeboer’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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

samuel.mortenson’s picture

Status: Closed (fixed) » Needs review

This was never actually added to the development branch, it shouldn't be closed.

rdeboer’s picture

Version: 7.x-1.4 » 7.x-1.6
Assigned: Unassigned » rdeboer
Status: Needs review » Closed (fixed)

The patch was applied, although the code-comment was dropped from the patch.
See http://drupalcode.org/project/revisioning.git/commitdiff/1dfb0ea