<?php

/**
 * @file
 * Install, update, and uninstall functions for the Archibald Import module.
 */

/**
 * Implements hook_install().
 */
function archibald_import_install() {
  // We need to execute our module hooks after Views, which has a weight of 10
  // by default.
  db_update('system')
    ->fields(array('weight' => 20))
    ->condition('name', 'archibald_import')
    ->execute();
}

/**
 * Implements hook_schema().
 */
function archibald_import_schema() {
  return array(
    'archibald_import_errors' => array(
      'description' => 'List of import errors for certain nodes.',
      'fields' => array(
        'nid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'no_user' => array(
          'type' => 'varchar',
          'length' => 255,
          'default' => '',
          'not null' => TRUE,
        ),
        'no_partner' => array(
          'type' => 'varchar',
          'length' => 255,
          'default' => '',
          'not null' => TRUE,
        ),
        'incorrect_catalog' => array(
          'type' => 'varchar',
          'length' => 255,
          'default' => '',
          'not null' => TRUE,
        ),
        'lom_id_conflict' => array(
          'type' => 'varchar',
          'length' => 255,
          'default' => '',
          'not null' => TRUE,
        ),
      ),
      'primary key' => array('nid'),
    ),
  );
}

/**
 * Implements hook_requirements().
 */
function archibald_import_requirements($phase) {
  $t = get_t();

  $return = array();

  $return['archibald_import__zip'] = array(
    'title' => $t("Archibald Import: ZIP PHP extension"),
  );
  if (!class_exists('ZipArchive')) {
    $return['archibald_import__zip']['value'] = $t("Missing");
    $return['archibald_import__zip']['description'] = $t("In order to use Archibald Import, you must install the PHP ZipArchive extension");
    $return['archibald_import__zip']['severity'] = REQUIREMENT_ERROR;
  }
  else {
    $return['archibald_import__zip']['value'] = $t("ZipArchive PHP extension is available");
    $return['archibald_import__zip']['severity'] = REQUIREMENT_OK;
  }

  return $return;
}

/**
 * Implements hook_update_N().
 *
 * - Make our module get executed AFTER Views.
 */
function archibald_import_update_7301() {
  // We need to execute our module hooks after Views, which has a weight of 10
  // by default.
  db_update('system')
    ->fields(array('weight' => 20))
    ->condition('name', 'archibald_import')
    ->execute();

  return array();
}
