home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (ca.install)

This example Drupal source code file (ca.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, data, default, function, int, length, not, null, php, size, true, type, varchar

The ca.install Drupal example source code

<?php
// $Id: ca.install,v 1.1.2.8 2009/07/21 14:37:19 islandusurper Exp $

/**
 * @file
 * Install hooks for ca.module.
 */

/**
 * Implementation of hook_schema().
 */
function ca_schema() {
  $schema = array();

  $schema['ca_predicates'] = array(
    'fields' => array(
      'pid' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'type' => 'text',
      ),
      'class' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ca_trigger' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'conditions' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
      ),
      'actions' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'modified' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'ca_predicates_class' => array('class'),
      'ca_predicates_status' => array('status'),
      'ca_predicates_ca_trigger' => array('ca_trigger'),
    ),
    'primary key' => array('pid'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function ca_install() {
  drupal_install_schema('ca');
}

/**
 * Implementation of hook_uninstall().
 */
function ca_uninstall() {
  drupal_uninstall_schema('ca');
}

/**
 * Update argument IDs in saved predicates.
 */
function ca_update_6001() {
  $ret = array();

  $result = db_query("SELECT pid, conditions, actions FROM {ca_predicates}");
  while ($predicate = db_fetch_array($result)) {
    foreach (array('conditions', 'actions') as $section) {
      $data = $predicate[$section];
      $data = str_replace('s:5:"order";s:8:"uc_order";', 's:5:"order";s:5:"order";', $data);
      $data = str_replace('s:4:"user";', 's:7:"account";', $data);
      $predicate[$section] = $data;
    }
    db_query("UPDATE {ca_predicates} SET conditions = '%s', actions = '%s' WHERE pid = '%s'", $predicate['conditions'], $predicate['actions'], $predicate['pid']);
  }

  $ret[] = array('success' => TRUE, 'query' => 'Updated argument IDs in saved predicates.');

  return $ret;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal ca.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.