You are here

l10n_update.install in Localization update 6

Same filename and directory in other branches
  1. 7.2 l10n_update.install
  2. 7 l10n_update.install

Install file for l10n remote updates.

File

l10n_update.install
View source
<?php

/**
 * @file
 *   Install file for l10n remote updates.
 */

/**
 * Implementation of hook_schema().
 */
function l10n_update_schema() {
  $schema['l10n_update_project'] = array(
    'description' => 'Update information for project translations.',
    'fields' => array(
      'name' => array(
        'description' => 'A unique short name to identify the project.',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
      ),
      'project_type' => array(
        'description' => 'Project type, may be core, module, theme',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
      ),
      'core' => array(
        'description' => 'Core compatibility string for this project.',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'version' => array(
        'description' => 'Human readable name for project used on the interface.',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'l10n_server' => array(
        'description' => 'Localization server for this project.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'l10n_path' => array(
        'description' => 'Server path this project updates.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'Status flag. TBD',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  $schema['l10n_update_file'] = array(
    'description' => 'File and download information for project translations.',
    'fields' => array(
      'project' => array(
        'description' => 'A unique short name to identify the project.',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
      ),
      'language' => array(
        'description' => 'Reference to the {languages}.language for this translation.',
        'type' => 'varchar',
        'length' => '12',
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'File origin: download or localfile',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
        'default' => '',
      ),
      'filename' => array(
        'description' => 'Link to translation file for download.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'fileurl' => array(
        'description' => 'Link to translation file for download.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'filepath' => array(
        'description' => 'File system path for importing the file.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'timestamp' => array(
        'description' => 'Unix timestamp of the time the file was downloaded or saved to disk. Zero if not yet downloaded.',
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
        'default' => 0,
      ),
      'version' => array(
        'description' => 'Version tag of the downloaded file.',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'Status flag. TBD',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'last_checked' => array(
        'description' => 'Unix timestamp of the last time this translation was downloaded from or checked at remote server and confirmed to be the most recent release available.',
        'type' => 'int',
        'not null' => FALSE,
        'disp-width' => '11',
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'project',
      'language',
    ),
  );
  $schema['cache_l10n_update'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['cache_l10n_update']['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
  return $schema;
}

/**
 * Add status field to translations table.
 */
function l10n_update_schema_alter(&$schema) {
  $schema['locales_target']['fields']['l10n_status'] = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
}

/**
 * Implementation of hook_install().
 */
function l10n_update_install() {
  $ret = array();
  drupal_install_schema('l10n_update');
  db_add_field($ret, 'locales_target', 'l10n_status', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  variable_set('l10n_update_rebuild_projects', 1);
  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function l10n_update_uninstall() {
  $ret = array();
  drupal_uninstall_schema('l10n_update');
  db_drop_field($ret, 'locales_target', 'l10n_status');
  variable_del('l10n_update_check_disabled');
  variable_del('l10n_update_check_frequency');
  variable_del('l10n_update_check_mode');
  variable_del('l10n_update_default_server');
  variable_del('l10n_update_default_update_url');
  variable_del('l10n_update_download_store');
  variable_del('l10n_update_import_mode');
  variable_del('l10n_update_rebuild_projects');
  return $ret;
}

/**
 * Implementation of hook_requirements().
 */
function l10n_update_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime' && variable_get('l10n_update_check_frequency', 0)) {
    if (l10n_update_get_projects() && l10n_update_language_list()) {
      $requirements['l10n_update']['title'] = t('Translation update status');
      if (l10n_update_available_updates()) {
        $destination = drupal_get_destination();
        $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
        $requirements['l10n_update']['value'] = t('There are available updates');
        $requirements['l10n_update']['description'] = t('There are new or updated translations available for currently installed modules and themes. To check for updates, you can visit the <a href="@check_manually">translation update page</a>.', array(
          '@check_manually' => url('admin/build/translate/update', array(
            'query' => $destination,
          )),
        ));
      }
      else {
        $requirements['l10n_update']['severity'] = REQUIREMENT_OK;
        $requirements['l10n_update']['value'] = t('All your translations are up to date');
      }
    }
    else {
      $requirements['l10n_update']['title'] = t('Translation update status');
      $requirements['l10n_update']['value'] = t('No update data available');
      $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;

      //$requirements['update_core']['reason'] = UPDATE_UNKNOWN;
      $requirements['l10n_update']['description'] = _l10n_update_no_data();
    }
  }
  if ($phase == 'runtime') {

    // Test the contents of the .htaccess file in the translations directory.
    $directory = variable_get('l10n_update_download_store', '');
    if ($directory) {
      l10n_update_ensure_htaccess();
      $htaccess_file = $directory . '/.htaccess';

      // Check for the string which was added to the recommended .htaccess file
      // in the latest security update.
      if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
        $requirements['l10n_update_htaccess'] = array(
          'title' => t('Translations directory'),
          'value' => t('Not fully protected'),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('See <a href="@url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', array(
            '@url' => 'http://drupal.org/SA-CORE-2013-003',
            '%directory' => $directory,
          )),
        );
      }
    }
  }
  return $requirements;
}

/**
 * Add status field to locales_target.
 */
function l10n_update_update_6001() {
  $ret = array();
  if (!db_column_exists('locales_target', 'l10n_status')) {
    db_add_field($ret, 'locales_target', 'l10n_status', array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ));
  }
  return $ret;
}

/**
 * Change status field name to l10n_status.
 */
function l10n_update_update_6002() {

  // I18n Strings module adds a 'status' column to 'locales_target' table.
  // L10n Update module previously added a column with the same name. To avoid
  // any collision we change the column name here, but only if it was added by
  // L10n Update module.
  $ret = array();
  if (!db_column_exists('locales_target', 'l10n_status') && db_column_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
    db_change_field($ret, 'locales_target', 'status', 'l10n_status', array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ));
  }
  elseif (!db_column_exists('locales_target', 'l10n_status')) {
    db_add_field($ret, 'locales_target', 'l10n_status', array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ));
  }
  return $ret;
}

/**
 * Delete 'last_updated' field from {l10n_update_file} table.
 */
function l10n_update_update_6003() {
  $ret = array();
  db_drop_field($ret, 'l10n_update_file', 'last_updated');
  return $ret;
}

/**
 * Delete 'import_date' field from {l10n_update_file} table.
 */
function l10n_update_update_6004() {
  $ret = array();
  db_drop_field($ret, 'l10n_update_file', 'import_date');
  return $ret;
}

/**
 * Create {cache_l10n_update} table.
 */
function l10n_update_update_6005() {
  if (!db_table_exists('cache_l10n_update')) {
    $ret = array();
    $schema = drupal_get_schema_unprocessed('system', 'cache');
    $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
    db_create_table($ret, 'cache_l10n_update', $schema);
    return $ret;
  }
}

/**
 * Add a .htaccess file to the translations directory.
 */
function l10n_update_update_6006() {
  l10n_update_ensure_htaccess();
  return array();
}

Functions

Namesort descending Description
l10n_update_install Implementation of hook_install().
l10n_update_requirements Implementation of hook_requirements().
l10n_update_schema Implementation of hook_schema().
l10n_update_schema_alter Add status field to translations table.
l10n_update_uninstall Implementation of hook_uninstall().
l10n_update_update_6001 Add status field to locales_target.
l10n_update_update_6002 Change status field name to l10n_status.
l10n_update_update_6003 Delete 'last_updated' field from {l10n_update_file} table.
l10n_update_update_6004 Delete 'import_date' field from {l10n_update_file} table.
l10n_update_update_6005 Create {cache_l10n_update} table.
l10n_update_update_6006 Add a .htaccess file to the translations directory.