You are here

uc_recurring_subscription.install in UC Recurring Payments and Subscriptions 7.2

Installs the Recurring Subscription module.

File

modules/uc_recurring_subscription/uc_recurring_subscription.install
View source
<?php

/**
 * @file
 * Installs the Recurring Subscription module.
 */

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

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime') {
    if (!function_exists('uc_attribute_load_multiple')) {
      $requirements['uc_recurring_subscription'] = array(
        'title' => $t('Subscription Manager'),
        'value' => $t('Need a newer version of Ubercart.'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('This module requires a newer version of ubercart, read the <a href="@readme">README.txt</a>', array(
          '@readme' => url(drupal_get_path('module', 'uc_recurring_subscription') . '/README.txt'),
        )),
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 */
function uc_recurring_subscription_schema() {
  $schema['uc_recurring_subscription'] = array(
    'description' => 'Data for recurring fees attached to products.',
    'fields' => array(
      'nid' => array(
        'description' => 'The product ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'access' => array(
        'description' => 'Serialized list of drupal roles that should be applied on this subscription.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
      'ca' => array(
        'description' => 'Serialized list of drupal CA events to tie to this subscription.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
      'weight' => array(
        'description' => 'The order the product is listed.',
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'parent' => array(
        'description' => 'Allows subscription to inherit roles and notifications.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function uc_recurring_subscription_uninstall() {
  variable_del('uc_recurring_subscription_product_class');
  variable_del('uc_recurring_subscription_attribute');
}

/**
 * Implements hook_enable().
 */
function uc_recurring_subscription_enable() {
  $pcid = 'uc_recurring_subscription';
  if (db_query("SELECT COUNT(*) FROM {uc_product_classes} WHERE pcid = :pcid", array(
    ':pcid' => $pcid,
  ))
    ->fetchField() < 1) {
    db_insert('uc_product_classes')
      ->fields(array(
      'pcid' => $pcid,
      'name' => 'Recurring Subscription',
      'description' => 'A recurring subscription product used by the recurring subscription ui module to manage your subscription products',
    ))
      ->execute();
    uc_product_node_info(TRUE);
    node_types_rebuild();
    menu_rebuild();
  }
  variable_set('node_options_' . $pcid, variable_get('node_options_product', array(
    'status',
    'promote',
  )));
  variable_set('uc_recurring_subscription_product_class', $pcid);
  $attribute = new stdClass();

  //@todo. There is something incorrect here because if you uninstall and reinstall, you get duplicate entries in the db.
  $attribute->name = 'uc_recurring_subscription_payment_options';
  $attribute->label = 'Payment Option';
  $attribute->ordering = 0;
  $attribute->required = 1;
  $attribute->display = 1;
  $attribute->description = 'The subscription payment options';
  uc_attribute_save($attribute);
  uc_attribute_subject_save($attribute, 'class', 'uc_recurring_subscription');
  variable_set('uc_recurring_subscription_attribute', $attribute->aid);
}

/**
 * Rename the 'roles' column to 'access' in {uc_recurring_subscription}.
 */
function uc_recurring_subscription_update_6000() {
  db_change_field('uc_recurring_subscription', 'roles', 'access', array(
    'type' => 'text',
    'serialize' => TRUE,
  ));
}

Functions