You are here

backup_migrate_s3.module in Backup and Migrate S3 7

Functions to define the S3 backup destination.

File

backup_migrate_s3.module
View source
<?php

/**
 * @file
 * Functions to define the S3 backup destination.
 */

/**
 * Implements hook_backup_migrate_destination_subtypes().
 */
function backup_migrate_s3_backup_migrate_destination_subtypes() {
  return array(
    's3-compatible' => array(
      'type_name' => t('S3 compatible'),
      'description' => t('Save the backup files to an s3 compatible service.'),
      'file' => drupal_get_path('module', 'backup_migrate_s3') . '/destinations.s3.inc',
      'class' => 'backup_migrate_destination_s3_compatible',
      'can_create' => TRUE,
      'remote' => TRUE,
    ),
  );
}
function backup_migrate_s3_libraries_info() {

  // A library that (naturally) evolves over time with API changes.
  $libraries['aws-sdk-php'] = array(
    'name' => 'AWS SDK for PHP',
    'vendor url' => 'http://aws.amazon.com/sdkforphp',
    'download url' => 'https://github.com/aws/aws-sdk-php/releases',
    'version arguments' => array(
      // It can be easier to parse the first characters of a minified file
      // instead of doing a multi-line pattern matching in a source file. See
      // 'lines' and 'cols' below.
      'file' => 'CHANGELOG.md',
      // Best practice: Document the actual version strings for later reference.
      // 2.x: this.majorVersion="2";this.minorVersion="1.3"
      // 3.x: majorVersion:'3',minorVersion:'2.0.1'
      'pattern' => '@## (\\d+\\.\\d+\\.\\d+)@',
    ),
    // Default list of files of the library to load. Important: Only specify
    // third-party files belonging to the library here, not integration files of
    // your module.
    'files' => array(
      // For PHP libraries, specify include files here, still relative to the
      // library path.
      'php' => array(
        'aws-autoloader.php',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_requirements().
 */
function backup_migrate_s3_requirements($phase) {
  $requirements = array();

  // Ensure translations do not break at install time
  $t = get_t();
  $requirements['backup_migrate_s3'] = array(
    'title' => $t('Backup And Migrate S3 Library'),
  );
  if (($library = libraries_detect('aws-sdk-php')) && !empty($library['installed'])) {
    if (version_compare($library['version'], '3.0.0', '>=')) {
      $requirements['backup_migrate_s3']['value'] = $t('%version is unsupported', array(
        '%version' => $library['version'],
      ));
      $requirements['backup_migrate_s3']['severity'] = REQUIREMENT_ERROR;
      $requirements['backup_migrate_s3']['description'] = $t('Please download install <a href="!url">version 2.x of aws-sdk-php library</a>.', array(
        '!url' => $library['download url'],
      ));
    }
    else {
      $requirements['backup_migrate_s3']['value'] = $library['version'];
      $requirements['backup_migrate_s3']['severity'] = REQUIREMENT_OK;
    }
  }
  else {
    $requirements['backup_migrate_s3']['value'] = $t('Not Installed');
    $requirements['backup_migrate_s3']['severity'] = REQUIREMENT_ERROR;
    $requirements['backup_migrate_s3']['description'] = $t('Please download install <a href="!url">version 2.x of aws-sdk-php library</a>.', array(
      '!url' => $library['download url'],
    ));
  }
  return $requirements;
}

Functions