You are here

function lingotek_update_7200 in Lingotek Translation 7.3

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

File

./lingotek.install, line 190
Installation for Lingotek Community Translation Module.

Code

function lingotek_update_7200(&$sandbox) {
  drupal_load('module', 'lingotek');
  if (!isset($sandbox['progress'])) {
    $result = db_select('lingotek', 'n')
      ->distinct(TRUE)
      ->fields('n', array(
      db_escape_field('nid'),
    ))
      ->execute();
    $nodes = array();
    foreach ($result as $row) {
      array_push($nodes, $row->nid);
    }
    $sandbox['progress'] = 0;
    $sandbox['max'] = count($nodes);
    $sandbox['nodes'] = $nodes;
  }
  $node = lingotek_node_load_default($sandbox['nodes'][$sandbox['progress']]);
  if ($node !== FALSE) {
    if (!class_exists('LingotekApi')) {

      // The LingotekApi class might not have been introduced when this user last updated the Lingotek Translation module.
      registry_rebuild();
      require_once drupal_get_path('module', 'lingotek') . '/lib/Drupal/lingotek/LingotekApi.php';
    }
    if (class_exists('LingotekNode')) {
      LingotekApi::instance()
        ->updateContentDocument(LingotekNode::load($node));
    }
    else {
      throw new Exception('LingotekNode class missing. Please clear the Drupal cache and then run update.php again.');
    }
  }
  $sandbox['progress']++;
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($sandbox['#finished'] == 1) {
    lingotek_analyze_project();
  }
}