workflow_fields.install in Workflow Fields 7
Same filename and directory in other branches
Install, update, and uninstall functions for the workflow_fields module.
File
workflow_fields.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the workflow_fields module.
*/
function workflow_fields_update_1() {
$ret = array();
db_add_field($ret, 'workflow_fields', 'rid', array(
'type' => 'int',
'not null' => TRUE,
'default' => '-1',
));
db_drop_primary_key($ret, 'workflow_fields');
db_add_primary_key($ret, 'workflow_fields', array(
'sid',
'rid',
));
return $ret;
}
function workflow_fields_update_2() {
$ret = array();
db_add_field($ret, 'workflow_fields', 'visible_userref', array(
'type' => 'varchar',
'length' => 100,
'not null' => FALSE,
));
db_add_field($ret, 'workflow_fields', 'editable_userref', array(
'type' => 'varchar',
'length' => 100,
'not null' => FALSE,
));
return $ret;
}
function workflow_fields_update_6003() {
$ret = array();
// That was a bug in earlier versions.
db_query("DELETE FROM {workflow_fields} WHERE name=''");
db_drop_index($ret, 'workflow_fields', 'sid');
db_add_field($ret, 'workflow_fields', 'visible_roles', array(
'type' => 'text',
'not null' => FALSE,
));
db_add_field($ret, 'workflow_fields', 'editable_roles', array(
'type' => 'text',
'not null' => FALSE,
));
db_change_field($ret, 'workflow_fields', 'visible', 'visible', array(
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
));
db_change_field($ret, 'workflow_fields', 'editable', 'editable', array(
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
));
// Move role permissions from old schema to new schema.
$distinct = db_query("SELECT DISTINCT sid, name, type FROM {workflow_fields}");
while ($row = db_fetch_array($distinct)) {
$permissions = db_query("SELECT rid, visible, editable, visible_userref, editable_userref FROM {workflow_fields} WHERE sid=%d AND name='%s' AND type='%s'", $row['sid'], $row['name'], $row['type']);
$visible_roles = array();
$editable_roles = array();
while ($permission = db_fetch_array($permissions)) {
if ($permission['visible']) {
$visible_roles[] = $permission['rid'] == -2 ? $permission['visible_userref'] : $permission['rid'];
}
if ($permission['editable']) {
$editable_roles[] = $permission['rid'] == -2 ? $permission['editable_userref'] : $permission['rid'];
}
}
db_query("INSERT INTO {workflow_fields} (sid, name, type, visible_roles, editable_roles) VALUES (%d, '%s', '%s', '%s', '%s')", $row['sid'], $row['name'], $row['type'], implode(',', $visible_roles), implode(',', $editable_roles));
}
db_query("DELETE FROM {workflow_fields} WHERE visible_roles IS NULL AND editable_roles IS NULL");
db_drop_field($ret, 'workflow_fields', 'rid');
db_drop_field($ret, 'workflow_fields', 'visible');
db_drop_field($ret, 'workflow_fields', 'editable');
db_drop_field($ret, 'workflow_fields', 'visible_userref');
db_drop_field($ret, 'workflow_fields', 'editable_userref');
db_add_primary_key($ret, 'workflow_fields', array(
'sid',
'name',
'type',
));
db_add_index($ret, 'workflow_fields', 'runtime', array(
'sid',
'type',
));
return $ret;
}
function workflow_fields_update_6004() {
$ret = array();
// Set the weight to be greater than fieldgroup's weight.
db_query("UPDATE {system} SET weight = 10 WHERE name = 'workflow_fields'");
return $ret;
}
function workflow_fields_schema() {
$schema['workflow_fields'] = array(
'fields' => array(
'sid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'type' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'visible_roles' => array(
'type' => 'text',
'not null' => FALSE,
),
'editable_roles' => array(
'type' => 'text',
'not null' => FALSE,
),
),
'primary key' => array(
'sid',
'name',
'type',
),
'indexes' => array(
'runtime' => array(
'sid',
'type',
),
),
);
return $schema;
}
Functions
Name![]() |
Description |
---|---|
workflow_fields_schema | |
workflow_fields_update_1 | @file Install, update, and uninstall functions for the workflow_fields module. |
workflow_fields_update_2 | |
workflow_fields_update_6003 | |
workflow_fields_update_6004 |