You are here

function media_requirements in D7 Media 7.3

Same name and namespace in other branches
  1. 7.4 media.install \media_requirements()
  2. 7.2 media.install \media_requirements()

Implements hook_requirements().

File

./media.install, line 109
Install, update and uninstall functions for the Media module.

Code

function media_requirements($phase) {
  $t = get_t();

  // Make sure that file_entity module is 2.x version.
  // We can't add this check in .info file because drupal.org testbot can't
  // handle it. See #1734648.
  $requirements = array();
  if ($phase == 'update') {
    $info = system_get_info('module', 'file_entity');
    $file_entity_version = $info['version'];
    $file_entity_minimum_date = 1495439635;
    if (isset($info['datestamp'])) {
      $file_entity_installed_date = $info['datestamp'];
    }
    else {
      if (strpos($file_entity_version, '7.x-3') !== FALSE) {

        // Good version, any number that passes the condition is good.
        $file_entity_installed_date = $file_entity_minimum_date + 1;
      }
      else {

        // Check version 2 release and parse into a number.
        // No need to check version 1 as that's checked below.
        $version_number = str_replace('7.x-2.', '', $file_entity_version);
        if (is_numeric($version_number)) {

          // Plain number, so good version.
          $file_entity_installed_date = $file_entity_minimum_date + 1;
        }
        else {

          // Bad version or release (beta, alpha, unstable...).
          $file_entity_installed_date = $file_entity_minimum_date - 1;
        }
      }
    }

    // Time of 2017-05-22 07:53:55 is most recent commit in 7.x-2.0.
    if ($file_entity_installed_date < $file_entity_minimum_date) {
      $description = $t('Media 2.10 or newer requires <a href="@url">File entity 2.0 or newer (2.4 or higher recommended)</a>. Please download the correct version and make sure you have deleted the file_entity folder inside the media module directory.', array(
        '@url' => 'http://drupal.org/project/file_entity',
      ));
      $requirements['file_entity']['description'] = $description;
      $requirements['file_entity']['severity'] = REQUIREMENT_ERROR;
      $requirements['file_entity']['value'] = $file_entity_version;
      $requirements['file_entity']['title'] = $t('Fieldable Files (file_entity) module 7.x-2.0 or newer is required by Media');
      drupal_set_message($description, 'error', TRUE);
    }
    if (strpos($info['version'], '7.x-2') === FALSE && strpos($info['version'], '7.x-3') === FALSE) {
      $requirements['file_entity'] = array(
        'title' => $t('File entity 2.x or 3.x required.'),
        'value' => $t('Wrong version'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('Media requires <a href="@url">File entity 2.x or 3.x</a>. Please download the correct version and make sure you have deleted the file_entity folder inside the media module directory.', array(
          '@url' => 'http://drupal.org/project/file_entity',
        )),
      );
    }
  }
  return $requirements;
}