You are here

function lingotek_update_7201 in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.install \lingotek_update_7201()
  2. 7.2 lingotek.install \lingotek_update_7201()
  3. 7.3 lingotek.install \lingotek_update_7201()
  4. 7.4 lingotek.install \lingotek_update_7201()
  5. 7.5 lingotek.install \lingotek_update_7201()

Save per-node Lingotek project associations for all existing content.

File

./lingotek.install, line 351

Code

function lingotek_update_7201(&$sandbox) {
  $lingotek_nodes = array();
  $default_lingotek_project = variable_get('lingotek_project', 0);
  if ($default_lingotek_project) {
    if (!isset($sandbox['progress'])) {
      $result = db_select('lingotek', 'l')
        ->distinct(TRUE)
        ->fields('l', array(
        'nid',
      ))
        ->execute();
      foreach ($result as $row) {
        $lingotek_nodes[] = $row->nid;
      }
      $sandbox['progress'] = 0;
      $sandbox['max'] = count($lingotek_nodes);
      $sandbox['nodes'] = $lingotek_nodes;
    }
    $process_node = lingotek_node_load_default(array_shift($sandbox['nodes']));
    if ($process_node->nid && !lingotek_keystore('node', $process_node->nid, 'project_id')) {
      lingotek_keystore('node', $process_node->nid, 'project_id', $default_lingotek_project);
    }
    $sandbox['progress'] = (int) (count($sandbox['nodes']) / $sandbox['max']);
  }
  $sandbox['#finished'] = empty($sandbox['nodes']);
}