You are here

mollie_payment.install in Mollie Payment 7

Same filename and directory in other branches
  1. 7.2 mollie_payment.install

File

mollie_payment.install
View source
<?php

/**
 * Install and update hooks for Mollie Payment.
 */

/**
 * Implements hook_schema().
 */
function mollie_payment_schema() {
  $schema['mollie_payment_payment_method_configurations'] = array(
    'description' => 'Configuration data for Mollie Payment payment methods.',
    'fields' => array(
      'pmid' => array(
        'description' => 'The pmid of the payment method within Payment.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'configuration' => array(
        'description' => 'Serialized representation of the configuration.',
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'pmid',
    ),
  );
  return $schema;
}

/**
 * Move payment method configuration from the variable store to an own
 * database table.
 */
function mollie_payment_update_7101() {
  global $conf;

  // Create the database table.
  $schema = drupal_get_schema_unprocessed('mollie_payment');
  db_create_table('mollie_payment_payment_method_configurations', $schema['mollie_payment_payment_method_configurations']);

  // Move existing configurations.
  foreach ($conf as $name => $value) {
    if (strpos($name, 'mollie_payment_') === 0 && strpos($name, '_controller_data') !== FALSE) {
      $info = explode('_', $name);
      $pmid = $info[2];
      mollie_payment_payment_method_configuration_save($pmid, $value);
      variable_del($name);
    }
  }
}

/**
 * Rename mollie_id to mollie_api_key.
 */
function mollie_payment_update_7102() {
  $records = db_select('mollie_payment_payment_method_configurations', 'c')
    ->fields('c', array(
    'pmid',
    'configuration',
  ))
    ->execute()
    ->fetchAllKeyed();
  foreach ($records as $pmid => $configuration) {
    $config = unserialize($configuration);
    $config['mollie_api_key'] = $config['mollie_id'];
    unset($config['mollie_id']);
    mollie_payment_payment_method_configuration_save($pmid, $config);
  }
  variable_del('mollie_payment_test_message');
}

Functions

Namesort descending Description
mollie_payment_schema Implements hook_schema().
mollie_payment_update_7101 Move payment method configuration from the variable store to an own database table.
mollie_payment_update_7102 Rename mollie_id to mollie_api_key.