function views_schema

Same name in other branches
  1. 7.x-3.x views.install \views_schema()

Implementation of hook_schema().

Generate the current version of the database schema from the sequence of schema update functions. Uses a similar method to install.inc's drupal_get_schema_versions() to establish the update sequence.

To change the schema, add a new views_schema_N() function to match the associated views_update_N()

Parameters

$caller_function: The name of the function that called us. Used internally, if requesting a specific schema version.

9 calls to views_schema()
views_schema_6003 in ./views.install
Add missing unique key.
views_schema_6004 in ./views.install
Enlarge the views_object_cache.data column to prevent truncation and JS errors.
views_schema_6005 in ./views.install
Enlarge the base_table column
views_schema_6006 in ./views.install
Add the cache_views_data table to support standard caching.
views_schema_6008 in ./views.install
Add the primary key to views_display table.

... See full list

File

./views.install, line 42

Code

function views_schema($caller_function = FALSE) {
    static $get_current;
    static $schemas = array();
    // If called with no arguments, get the latest version of the schema.
    if (!isset($get_current)) {
        $get_current = $caller_function ? FALSE : TRUE;
    }
    // Generate a sorted list of available schema update functions.
    if ($get_current || empty($schemas)) {
        $get_current = FALSE;
        $functions = get_defined_functions();
        foreach ($functions['user'] as $function) {
            if (strpos($function, 'views_schema_') === 0) {
                $version = substr($function, strlen('views_schema_'));
                if (is_numeric($version)) {
                    $schemas[] = $version;
                }
            }
        }
        if ($schemas) {
            sort($schemas, SORT_NUMERIC);
            // If a specific version was requested, drop any later
            // updates from the sequence.
            if ($caller_function) {
                do {
                    $schema = array_pop($schemas);
                } while ($schemas && $caller_function != 'views_schema_' . $schema);
            }
        }
    }
    // Call views_schema_<n>, for the highest available <n>.
    if ($schema = array_pop($schemas)) {
        $function = 'views_schema_' . $schema;
        return $function();
    }
    return array();
}