You are here

function lingotek_workbench_moderation_transition in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.4 lingotek.module \lingotek_workbench_moderation_transition()

Implements hook_workbench_moderation_transition()

Upload content automatically only if new state corresponds auto-upload workbench_moderation variables Otherwise override upload

File

./lingotek.module, line 1314

Code

function lingotek_workbench_moderation_transition($node, $old_state, $new_state) {

  // Check global and node-specific settings
  // if this node is managed by lingotek, add lingotek wb variables
  if (isset($node->lingotek_push_once) && $node->lingotek_push_once || lingotek_node_pushed($node) || !lingotek_managed_by_entity_translation($node->type)) {
    $def_state = lingotek_variable_get(lingotek_lingonode($node->nid, 'create_lingotek_document_workbench_moderation'), 'lingotek_create_documents_by_default_workbench_moderation', workbench_moderation_state_published());
    $states = lingotek_get_workbench_moderation_states();

    // do not change status updates if only moderated (no node_save called)
    if (!isset($node->workbench_moderation_state_new)) {
      $node->skip_status_updates = TRUE;
    }

    // set lingonode variable for workbench moderation auto-upload
    if (isset($node->create_lingotek_document_workbench_moderation)) {
      lingotek_lingonode($node->nid, 'create_lingotek_document_workbench_moderation', $node->create_lingotek_document_workbench_moderation);
      $def_state = $node->create_lingotek_document_workbench_moderation;
    }

    // set lingonode variable for workbench moderation auto-download setting
    if (isset($node->syncMethod_wb)) {
      lingotek_lingonode($node->nid, 'sync_method_workbench_moderation', $node->syncMethod_wb);
    }
    if ($old_state == workbench_moderation_state_published() && $new_state != workbench_moderation_state_published()) {

      // if changing from published
      $node->status = 0;

      // unpublish
      node_save($node);
    }

    // Check new state against settings
    if ($new_state != $states[$def_state]) {

      // && !isset($node->is_new)) {
      $node->lingotek_upload_override = 0;
    }
  }
  lingotek_upload_document($node);
}