You are here

function views_data_export_requirements in Views data export 7.4

Same name and namespace in other branches
  1. 6.2 views_data_export.install \views_data_export_requirements()
  2. 7.3 views_data_export.install \views_data_export_requirements()

Implements hook_requirements().

File

./views_data_export.install, line 162

Code

function views_data_export_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();
  switch ($phase) {
    case 'runtime':
      $requirements['views_data_export_temp'] = array(
        'title' => t('Views Data Export temporary directory'),
        'severity' => REQUIREMENT_OK,
        'value' => t('Exists'),
      );
      $path = variable_get('views_data_export_directory', 'temporary://views_plugin_display');
      if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
        $requirements['views_data_export_temp']['description'] = t('The Views Data Export temporary directory, %path could not be created due to a misconfigured directory. Please ensure that the temporary directory is correctly configured and that the webserver has permission to create directories.', array(
          '%path' => file_uri_target($path),
        ));
        $requirements['views_data_export_temp']['severity'] = REQUIREMENT_ERROR;
        $requirements['views_data_export_temp']['value'] = t('Unable to create');
      }
      $db_type = Database::getConnection()
        ->databaseType();
      switch ($db_type) {
        case 'mysql':

          // Check the max allowed packet size.
          $max_allowed_packet = db_query('SHOW VARIABLES WHERE variable_name = :name', array(
            ':name' => 'max_allowed_packet',
          ))
            ->fetchField(1);
          if (is_numeric($max_allowed_packet)) {
            if ($max_allowed_packet < 16 * 1024 * 1024) {
              $requirements['views_data_export'] = array(
                'title' => $t('MySQL - max allowed packet'),
                'value' => format_size($max_allowed_packet),
                'description' => $t("Your MySQL 'max_allowed_packet' setting may be too low for Views data export to function correctly, Drupal's requirements recommend setting it to at least 16M. See: !link", array(
                  '!link' => l('http://drupal.org/requirements', 'http://drupal.org/requirements'),
                )),
                'severity' => REQUIREMENT_WARNING,
              );
            }
          }
          break;
      }
      break;
  }
  return $requirements;
}