You are here

backup_migrate.install in Backup and Migrate 5.2

Install hooks for Backup and Migrate.

File

backup_migrate.install
View source
<?php

/**
 * @file
 * Install hooks for Backup and Migrate.
 */
function backup_migrate_requirements($phase) {
  $requirements = array();
  if ($GLOBALS['db_type'] !== 'mysqli' && $GLOBALS['db_type'] !== 'mysql') {
    $requirements['db_type']['description'] = $t('This module is only compatible with MySQL databases.');
    $requirements['db_type']['severity'] = REQUIREMENT_ERROR;
  }
}
function backup_migrate_install() {
  _backup_migreate_install_tables();
  _backup_migrate_setup_databaase_defaults();
}
function _backup_migreate_install_tables() {
  if ($GLOBALS['db_type'] == 'mysqli' || $GLOBALS['db_type'] == 'mysql') {
    drupal_set_message("Creating required backup_migrate.module MySQL tables for first install");
    db_query("CREATE TABLE {backup_migrate_profiles} (\n      profile_id int(10) UNSIGNED NOT NULL PRIMARY KEY,\n      name varchar(255) NOT NULL default '',\n      source_id varchar(32) NOT NULL default 'db_url:default',\n      exclude_tables text NOT NULL,\n      nodata_tables text NOT NULL,\n      filename varchar(50) NOT NULL default '',\n      append_timestamp tinyint(1),\n      timestamp_format varchar(14) NOT NULL default '',\n      compression varchar(8) NOT NULL default '',\n      destination_id varchar(32) NOT NULL default ''\n    ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
    db_query("CREATE TABLE {backup_migrate_destinations} (\n      destination_id int(10) UNSIGNED NOT NULL PRIMARY KEY,\n      name varchar(255) NOT NULL default '',\n      type varchar(32) NOT NULL default '',\n      location text NOT NULL,\n      username varchar(255) NOT NULL default '',\n      password varchar(255) NOT NULL default '',\n      settings text default ''\n    ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
    db_query("CREATE TABLE {backup_migrate_schedules} (\n      schedule_id int(10) UNSIGNED NOT NULL PRIMARY KEY,\n      name varchar(255) NOT NULL default '',\n      destination_id varchar(32) NOT NULL default '',\n      profile_id varchar(32) NOT NULL default '',\n      keep int(10) unsigned NOT NULL default '0',\n      period int(10) unsigned NOT NULL default '0',\n      last_run int(10) unsigned NOT NULL default '0',\n      enabled tinyint(1) default 1,\n      cron tinyint(1) default 1\n    ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
  }
}
function _backup_migrate_setup_databaase_defaults() {
  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/profiles.inc';
  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/db.inc';
  require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/files.inc';

  // Set up the default schedules.
  if (variable_get("backup_migrate_schedule_backup_period", 0) !== 0) {
    require_once './' . drupal_get_path('module', 'backup_migrate') . '/includes/schedules.inc';
    $schedule = array(
      'name' => t('Default Schedule'),
      'destination_id' => 'schedule,',
      'period' => variable_get("backup_migrate_schedule_backup_period", 0),
      'keep' => variable_get("backup_migrate_schedule_backup_keep", 0),
    );
    backup_migrate_schedule_save_schedule($schedule);
  }
  if (variable_get("backup_migrate_file_name", NULL)) {
    $settings = array(
      'source_id' => 'db_url:default',
      'exclude_tables' => variable_get("backup_migrate_exclude_tables", _backup_migrate_default_exclude_tables()),
      'nodata_tables' => variable_get("backup_migrate_nodata_tables", _backup_migrate_default_structure_only_tables()),
      'filename' => variable_get("backup_migrate_file_name", _backup_migrate_default_filename()),
      'append_timestamp' => variable_get("backup_migrate_append_timestamp", FALSE) ? 1 : 0,
      'timestamp_format' => variable_get("backup_migrate_timestamp_format", 'Y-m-d\\TH-i-s'),
      'compression' => variable_get("backup_migrate_compression", "none"),
    );
  }
  else {
    $settings = _backup_migrate_profile_default_profile();
  }
  $settings['name'] = t('Default Profile');
  backup_migrate_profile_save_profile($settings);
}

/**
 * Remove variables on uninstall.
 */
function backup_migrate_uninstall() {
  db_query("DROP TABLE {backup_migrate_profiles}");
  db_query("DROP TABLE {backup_migrate_destinations}");
  db_query("DROP TABLE {backup_migrate_schedules}");
  db_query("DELETE FROM {variable} WHERE name LIKE 'backup_migrate_%'");
  cache_clear_all('variables', 'cache');
}

/**
 * Update from 1.x to 2.x.
 */
function backup_migrate_update_2000() {

  // Updating from version 1.x, need to populate the db.
  _backup_migreate_install_tables();
  _backup_migrate_setup_databaase_defaults();
  return array();
}

Functions

Namesort descending Description
backup_migrate_install
backup_migrate_requirements @file Install hooks for Backup and Migrate.
backup_migrate_uninstall Remove variables on uninstall.
backup_migrate_update_2000 Update from 1.x to 2.x.
_backup_migrate_setup_databaase_defaults
_backup_migreate_install_tables