You are here

entity_translation_hierarchy.install in Language Hierarchy 7

File

modules/entity_translation_hierarchy/entity_translation_hierarchy.install
View source
<?php

/**
 * Implements hook_update_dependencies().
 */
function entity_translation_hierarchy_update_dependencies() {
  $dependencies = array();
  $dependencies['entity_translation_hierarchy'][7002] = array(
    'entity_translation' => 7006,
  );
  return $dependencies;
}

/**
 * Implements hook_schema_alter().
 */
function entity_translation_hierarchy_schema_alter(&$schema) {
  $schema['entity_translation']['fields']['blocking'] = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  );
  $schema['entity_translation_revision']['fields']['blocking'] = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  );
}

/**
 * Implements hook_install().
 */
function entity_translation_hierarchy_install() {
  db_add_field('entity_translation', 'blocking', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  ));
  db_add_field('entity_translation_revision', 'blocking', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  ));

  // entity_translation_hierarchy_form_alter() needs to run after entity_translation_form_alter().
  db_update('system')
    ->fields(array(
    'weight' => 12,
  ))
    ->condition('name', 'entity_translation_hierarchy')
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function entity_translation_hierarchy_uninstall() {
  db_drop_field('entity_translation', 'blocking');
  db_drop_field('entity_translation_revision', 'blocking');
}

/**
 * Implements hook_update_N().
 */
function entity_translation_hierarchy_update_7001() {
  db_add_field('entity_translation', 'blocking', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  ));

  // entity_translation_hierarchy_form_alter() needs to run after entity_translation_form_alter().
  db_update('system')
    ->fields(array(
    'weight' => 12,
  ))
    ->condition('name', 'entity_translation_hierarchy')
    ->execute();

  // Copy information about blocking translations.
  $result = db_query("SELECT entity_id, language FROM {entity_translation_hierarchy} WHERE blocking = 1");
  foreach ($result as $translation) {
    db_update('entity_translation')
      ->fields(array(
      'blocking' => 1,
    ))
      ->condition('entity_id', $translation->entity_id)
      ->condition('language', $translation->language)
      ->execute();
  }
  db_drop_table('entity_translation_hierarchy');
}

/**
 * Add the blocking column to the entity translation revision table.
 */
function entity_translation_hierarchy_update_7002() {
  db_add_field('entity_translation_revision', 'blocking', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'description' => 'Flag to mark the translation as blocking.',
  ));
}