When selecting 'Revert' from the '/moderation' page, the reverted revision is drafted and the current published revision becomes un-published.

This is not expected behavior and does not match the previous 7.x-1.3 behavior.

Previously, when creating a new revision, the previous revision remains published and new revision is draft.

My expected behavior is that when reverting a previous revision, the revision is reverted in a drafted state as a forward draft of the previously published revision.

The importance of the forward revision is to maintain the integrity of any currently published content. Currently, reverting causes the state of the revision to vary (sometimes the reverted revision is published, sometimes it is drafted) and can cause data to become unpublished un-intentionally.

Because of this, I would consider this issue Major as it effects published content and can cause published content to become unpublished unintentionally.

Comments

mrgoodfellow created an issue. See original summary.

mrgoodfellow’s picture

After some consideration I believe I have figured out the optimal workflow for the 'revert' button.

Current workflow:
When a revision is reverted, the previous published revision is unpublished.

Proposed Workflow (minor change)
When a revision is reverted, at the 'Are you sure you want to revert to the revision from..." page when you are presented with option to 'revert' or 'cancel' I would like to also present the editable contents of that revision.

That way, before the revision is completed, any necessary changes and the appropriate status can be applied.

This prevents users from attempting to access a node a recieving a 404 error during the time that the reverted (drafted) revision is edited and published.

Thoughts? Feedback? Any Idea where I get started or what function actually handles the revision submission page?

DamienMcKenna’s picture

Project: Drafty » Workbench Moderation
Version: 7.x-1.0-rc1 » 7.x-3.x-dev

Drafty doesn't provide a UI, it comes from Workbench Moderation, so I've moved the issue over there.

mrgoodfellow’s picture

In drupal core: node.pages.inc has the function: function node_revision_revert_confirm($form, $form_state, $node_revision) {

I was able to get the editable contents printed to the revert page by changing this function in core, but I was not able to determine a sufficient hook process to accomplish this using a custom module or patch to workbench moderation:

function node_revision_revert_confirm($form, $form_state, $node_revision) {
	watchdog("node_page_inc", '<pre>' . print_r( $node_revision, true) . '</pre>');
  $form['#node_revision'] = $node_revision;
  $return = drupal_get_form($node_revision->type . '_node_form', $node_revision);
  watchdog("twc_docs", '<pre>' . print_r( $page['content'], true) . '</pre>');	
  echo render($return);
  return confirm_form($form, t('Are you sure you want to revert to the revision from %revision-date?', array('%revision-date' => format_date($node_revision->revision_timestamp))), 'node/' . $node_revision->nid . '/revisions', '', t('Revert'), t('Cancel'));
}

Update: I was able to find a hook to alter the form for revision confirmation. I need to finish this function so that it sufficiently revises the confirm_form in function node_revision_revert_confirm() to include any revised values. Still in progress

/**
 * Implements hook_form_alter().
 */
function MY_MODULE_form_node_revision_revert_confirm_alter(&$form, &$form_state, $form_id) {
	if ($form_id == 'node_revision_revert_confirm') {
	watchdog("node_revision", 'Form ID ' . $form_id);
	watchdog("node_revision", 'Form <pre>' . print_r( $form, true) . '</pre>');
	watchdog("node_revision", 'Form State <pre>' . print_r( $form_state, true) . '</pre>');
	$getform = drupal_get_form($form['#node_revision']->type . '_node_form', $form['#node_revision']);
	watchdog("node_revision", 'Return <pre>' . print_r( $getform, true) . '</pre>');	
	//echo render($return);
	}
}
mrgoodfellow’s picture

Category: Feature request » Bug report

Updating to bug report as this is a change to workflow between 7.x-1.3 and 7.x-3.0

In 7.x-1.3 when creating a new revision the previous revision remains published and new revision is draft.

After updating to 7.x-3.0 the previous revision is unpublished.

Looking into this it appears the issue is that we are missing a flag to set the revision as a draft revision:
$entity->is_draft_revision = TRUE;

Trying to figure out the best place to hook this, it looks like it may need to be hook_entity_presave()

Any advice would be awesome as I'm digging into this issue!

mrgoodfellow’s picture

Priority: Normal » Major
Issue summary: View changes
mrgoodfellow’s picture

Issue summary: View changes
mrgoodfellow’s picture

Digging into the actions of drafty that manage this function, it looks like the issue is in how the 'is_new' option is applied to that revision form. I was able to force all new revisions to a drafted (or published = 1) state by hooking into the hook_form_alter() function as follows:

function MY_MODULE_form_node_revision_revert_confirm_alter(&$form, &$form_state, $form_id) {
	//set all new revisions to publish in drafted status
	$node_revision = $form['#node_revision'];
	$node_revision->status = 0;
}

Looking further into drafty it looks like the forward revision process is handled by: drafty_entity_is_new() which is called by drafty_entity_presave() which can be hooked into:

I tried to assign an is_new value with the hook_entity_presave() but was unable to get it to work properly:

function MY_MODULE_entity_presave($entity, $type) {
	$entity->is_new = TRUE;
}

For now I am going to apply '$node_revision->status = 1;' to force all revisions to a published state, although this is a temporary solution and not ideal.