You are here

vkxp.install in VK CrossPoster 7.2

Same filename and directory in other branches
  1. 6.3 vkxp.install
  2. 6 vkxp.install
  3. 6.2 vkxp.install
  4. 7 vkxp.install

vkxp.install Requirements and uninstall functions for the vkxp module.

File

vkxp.install
View source
<?php

/**
 * @file vkxp.install
 * Requirements and uninstall functions for the vkxp module.
 */

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

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime') {

    // Check for presence of curl support.
    if (!function_exists('curl_init')) {
      $requirements['vkxp_curl'] = array(
        'title' => $t('cURL Support for VKontakte CrossPoster'),
        'value' => $t('VKontakte CrossPoster requires <a href="@url">cURL support in PHP</a> to function fully.  Without this, contents will not be posted to vkontakte.', array(
          '@url' => 'http://php.net/manual/en/book.curl.php',
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    else {
      $requirements['vkxp_curl'] = array(
        'title' => $t('cURL Support for VKontakte CrossPoster'),
        'value' => $t('cURL enabled'),
        'severity' => REQUIREMENT_OK,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function vkxp_install() {
  vkxp_update_7213();
}

/**
 * Implements hook_uninstall().
 */
function vkxp_uninstall() {

  // Delete variables from database.
  $query = db_select('variable', 'v');
  $query
    ->addField('v', 'name');
  $query
    ->condition('name', db_like('vkxp_') . '%', 'LIKE');
  $vars = $query
    ->execute()
    ->fetchCol();
  if (!empty($vars)) {
    foreach ($vars as $var) {
      variable_del($var);
    }
  }

  // Delete vkxp send status property.
  db_drop_field('node', 'vkxp_sent');
}

/**
 * Implements hook_schema_alter().
 */
function vkxp_schema_alter(&$schema) {
  $schema['node']['fields']['vkxp_sent'] = array(
    'definition' => 'Was sent to vk',
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  );
}

/**
 * Changes name of variable that stores owner ID.
 */
function vkxp_update_7212() {
  $owner_id = variable_get('vkxp_group_id');
  if (!empty($owner_id)) {
    variable_set('vkxp_owner_id', $owner_id);
  }
  variable_del('vkxp_group_id');
}

/**
 * Add new status property to node.
 */
function vkxp_update_7213() {
  db_add_field('node', 'vkxp_sent', array(
    'definition' => 'Was sent to vk',
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
}

/**
 * Replace message text with token.
 */
function vkxp_update_7214() {
  $content_types = array_keys(node_type_get_types());
  foreach ($content_types as $ct) {
    $var = variable_get('vkxp_node_message_field_' . $ct, 'title');
    if (!strpos($var, '[')) {
      if ($var == 'title') {
        $var = '[node:title]';
      }
      else {
        $var = '[node:' . $var . ']';
      }
    }
    variable_set('vkxp_node_message_field_' . $ct, $var);
  }
}

Functions

Namesort descending Description
vkxp_install Implements hook_install().
vkxp_requirements Implements hook_requirements().
vkxp_schema_alter Implements hook_schema_alter().
vkxp_uninstall Implements hook_uninstall().
vkxp_update_7212 Changes name of variable that stores owner ID.
vkxp_update_7213 Add new status property to node.
vkxp_update_7214 Replace message text with token.