It would be nice to be able to set the workflow state for newly created nodes with the Migrate module.

Comments

apotek’s picture

  1. Create a module.
  2. Implement a nodeapi hook for the insert $op
  3. Check for the $node->migrate property on the node in the node api, to make sure the node being inserted is being inserted via migrate and not something else
  4. If $node->migrate, then call the workflow state transition function you want with the correct parameters.
  5. No need to complicate migrate module with this.
aidanlis’s picture

An easier solution, after several hours of experimentation, is putting something like this in your migrate class:

function prepare(stdClass $node, stdClass $row) {
  $node->workflow = STATE_ID;
}

Still, I think it would be nice to have a destination handler for this.

mikeryan’s picture

Title: Workflow support » Migration support for Workflow
Project: Migrate Extras » Workflow
Version: 6.x-2.x-dev » 7.x-1.x-dev
Component: Miscellaneous » Code

Migration support for a contrib module would best go into that module.

nancydru’s picture

Are you sure this is not already handled?

function workflow_node_insert($node) {
  // Skip if there are no workflows.
  if ($workflow = workflow_get_workflow_type_map_by_type($node->type)) {
    // If the state is not specified, use first valid state.
    // For example, a new node must move from (creation) to some
    // initial state.
    if (empty($node->workflow)) {
      $choices = workflow_field_choices($node);
      $keys = array_keys($choices);
      $sid = array_shift($keys);
    }
    if (!isset($sid)) {
      $sid = $node->workflow;
    }
    // And make the transition.
    workflow_transition($node, $sid);
  }
}
aidanlis’s picture

Might be now ... was not before.

nerdcore’s picture

I'm unsure how to extract the workflow data from the source during migration.

I've placed this inside my Migration constructor, but in prepare() there is still no sign of Migrate pulling these fields onto the $row array. Also, the mappings do look correct in the list of migration mapping (drush mm).

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('workflow', 'workflow');
    $this->addFieldMapping('workflow_scheduled_sid', 'workflow_scheduled_sid');
    $this->addFieldMapping('workflow_scheduled_timestamp', 'workflow_scheduled_timestamp');
    $this->addFieldMapping('workflow_scheduled_comment', 'workflow_scheduled_comment');
  }

  public function prepare($node, stdClass $row) {
    // No sign of those fields on $row here
  }
johnv’s picture

Issue summary: View changes
johnv’s picture

@nerdcore, which version are you using? If not using the latest 7.x-2.x, is it a new install?

nerdcore’s picture

I had been using 7.x-1.2 but just tried the same Migration after upgrading to both 7.x-2.0-beta4 and 7.x-2.x-dev and have encountered the same result with each version.

It is unclear to me at this time how to migrate workflow data at all. :/

johnv’s picture

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

I've never used Migrate before, so can't help you on that.
But it seems you are trying to convert to Workflow Node. Try using the new Workflow Field instead (disabling Workflow Node module). It uses Field API, and the value is like a normal 'integer' field.

nerdcore’s picture

@johnv If required I will move forward from 1.2 to 2.x-dev. However I've just tried this, performing all necessary DB updates, and my previous code to migrate these fields (with the Workflow Field module enabled, and Workflow Node since I am upgrading the module) does nothing.

Part of my confusion, and where my case would seem to deviate from the original post, is that I would like to bring ALL workflow data for a node from one Drupal site to another, including (at least) the State, Comments, and Scheduled State Change (boolean + date if applicable). Ideally I'd like to migrate the complete Workflow history for a node.

Is it possible to migrate Workflow history?

nerdcore’s picture

In regards to #4, my nodes are not receiving their previous Workflow state after migration.

Surprisingly I was unable to cause a node to transition states by manually calling workflow_transition(NODE, SID) as suggested in that comment. No number of calls to this function seem to have any effect on the Workflow State.

apotek’s picture

Comments #6 and on are about a completely separate issue. The original post was requesting to know best way to transition an incoming node to the right workstate within the destination cms. That was answered in a couple ways.

Beginning with comment #6, it seems like this issue is now a feature request for migrating workflow state data from one system to another. Please create a new feature request queue for this. Thanks.

apotek’s picture

Status: Active » Fixed

@aidanlis, given that you posted your own solution, we can close this, right?

apotek’s picture

Title: Migration support for Workflow » Ability to set workflow states during migration.
johnv’s picture

Title: Ability to set workflow states during migration. » Migration support for workflow states.

OK, i was not sure how nerdcore was different from OP, but it seems this issue handles the actual state, and the new issue #2170257 handles the state transition history.

About using workflow_transition in 7.x-1.2. It contains a third parameter 'force'. Setting it to TRUE might help:
function workflow_transition($node, $sid, $force = FALSE)

Status: Fixed » Closed (fixed)

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

johnv’s picture

Title: Migration support for workflow states. » Migrate support for workflow states.
jtjones23’s picture

Hi,

I'm trying to use the Migrate Workflow module to migrate a Drupal 6 workflow status and history. Should the process work for a Drupal 6 site? The workflow_node and workflow_node_history tables on the Drupal 7 site remain empty.

I get the following error messages:

Notice: Array to string conversion in FieldInfo->getBundleInstances() (line 360 of Sites/Drupal/.../modules/field/field.info.class.inc).
Warning: Illegal offset type in FieldInfo->getBundleInstances() (line 378 of Sites/Drupal/.../modules/field/field.info.class.inc).

I get the same messages using php 5.3.29 and 5.5.26