more module updates
This commit is contained in:
@@ -114,16 +114,16 @@ function _serial_get_table_schema() {
|
||||
'not null' => TRUE,
|
||||
'description' => 'The atomic serial field.',
|
||||
),
|
||||
'nid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'uniqid' => array(
|
||||
'description' => 'Unique temporary allocation Id.',
|
||||
'type' => 'varchar',
|
||||
'length' => 23,
|
||||
'not null' => TRUE,
|
||||
'description' => 'Id of the owner node.',
|
||||
),
|
||||
'default' => ''),
|
||||
),
|
||||
'primary key' => array('sid'),
|
||||
'unique keys' => array(
|
||||
'nid' => array('nid'),
|
||||
'uniqid' => array('uniqid'),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -142,29 +142,30 @@ function _serial_get_table_schema() {
|
||||
* @return
|
||||
* the unique serial value number.
|
||||
*/
|
||||
function _serial_generate_value($nid, $bundle, $field_name, $delete = TRUE) {
|
||||
function _serial_generate_value($bundle, $field_name, $delete = TRUE) {
|
||||
|
||||
// Get the name of the relevant table.
|
||||
$table = _serial_get_table_name($bundle, $field_name);
|
||||
|
||||
// Create a temporary record for this node and retrieve the serial value.
|
||||
// Insert a temporary record to get a new unique serial value.
|
||||
$uniqid = uniqid('', TRUE);
|
||||
$sid = db_insert($table)
|
||||
->fields(array(
|
||||
'nid' => $nid,
|
||||
'uniqid' => $uniqid,
|
||||
))
|
||||
->execute();
|
||||
|
||||
// If there's a reason why it's come back undefined, reset it.
|
||||
$sid = isset($sid) ? $sid : 0;
|
||||
|
||||
// Delete old temporary records:
|
||||
// Delete the temporary record.
|
||||
if ($delete && ($sid % 10) == 0) {
|
||||
db_delete($table)
|
||||
->condition('nid', $nid, '<')
|
||||
->execute();
|
||||
db_delete($table)
|
||||
->condition('uniqid', $uniqid, '=')
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Return the new unique serial value:
|
||||
// Return the new unique serial value.
|
||||
return $sid;
|
||||
}
|
||||
|
||||
@@ -189,22 +190,28 @@ function _serial_init_old_nodes($bundle, $field_name) {
|
||||
foreach ($result as $node) {
|
||||
$nid = $node->nid;
|
||||
$node = node_load($nid);
|
||||
$sid = _serial_generate_value($nid, $bundle, $field_name, FALSE);
|
||||
$sid = _serial_generate_value($bundle, $field_name, FALSE);
|
||||
$node->{$field_name} = array('und' => array(array('value' => $sid)));
|
||||
node_save($node);
|
||||
$last_nid = $nid;
|
||||
$count++;
|
||||
}
|
||||
|
||||
// Delete temporary records (except the last):
|
||||
if (isset($last_nid)) {
|
||||
$serial_table = _serial_get_table_name($bundle, $field_name);
|
||||
db_delete($serial_table)
|
||||
->condition('nid', $last_nid, '<')
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Return the number of existing nodes that have been initialized:
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the managed serial fields.
|
||||
*
|
||||
* @return result set containing pairs of (node type name, field name).
|
||||
*/
|
||||
function _serial_get_all_fields() {
|
||||
$query = db_select('field_config', 'f');
|
||||
$query->join('field_config_instance', 'i', 'i.field_name = f.field_name');
|
||||
$query->fields('i', array('bundle', 'field_name'))
|
||||
->condition('f.type', 'serial', '=')
|
||||
->condition('i.deleted', 0, '=');
|
||||
$result = $query->execute();
|
||||
return $result->fetchAll();
|
||||
}
|
||||
|
||||
|
@@ -6,9 +6,9 @@ dependencies[] = field
|
||||
files[] = serial.module
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-11-05
|
||||
version = "7.x-1.2"
|
||||
; Information added by drupal.org packaging script on 2013-10-15
|
||||
version = "7.x-1.3"
|
||||
core = "7.x"
|
||||
project = "serial"
|
||||
datestamp = "1320468935"
|
||||
datestamp = "1381844527"
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function serial_uninstall() {
|
||||
/*
|
||||
@@ -37,7 +37,7 @@ function serial_field_schema($field) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function serial_schema() {
|
||||
// Get the standard schema:
|
||||
@@ -46,10 +46,7 @@ function serial_schema() {
|
||||
|
||||
// Build the schema by iteration over all the serial field instances:
|
||||
$schema = array();
|
||||
$query = "SELECT i.bundle AS bundle, f.field_name AS field_name ".
|
||||
"FROM {field_config} f, {field_config_instance} i ".
|
||||
"WHERE f.field_name = i.field_name AND f.type = 'serial' AND i.deleted = 0";
|
||||
$result = db_query($query);
|
||||
$result = _serial_get_all_fields();
|
||||
foreach ($result as $field) {
|
||||
$table = _serial_get_table_name($field->bundle, $field->field_name);
|
||||
$schema[$table] = $table_schema;
|
||||
@@ -59,3 +56,31 @@ function serial_schema() {
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade path.
|
||||
*
|
||||
* Switches from nids to uniqid.
|
||||
*/
|
||||
function serial_update_7130() {
|
||||
// Get the new field schema.
|
||||
module_load_include('inc', 'serial');
|
||||
$table_schema = _serial_get_table_schema();
|
||||
$uniqid_schema = $table_schema['fields']['uniqid'];
|
||||
|
||||
// Update the schema of old assistant tables.
|
||||
$result = _serial_get_all_fields();
|
||||
foreach ($result as $field) {
|
||||
// Empty the table.
|
||||
$table = _serial_get_table_name($field->bundle, $field->field_name);
|
||||
db_delete($table)->execute();
|
||||
|
||||
// Drop nid field and key
|
||||
db_drop_field($table, 'nid');
|
||||
db_drop_unique_key($table, 'nid');
|
||||
|
||||
// Add uniqid field and key
|
||||
db_add_field($table, 'uniqid', $uniqid_schema);
|
||||
db_add_unique_key($table, 'uniqid', array('uniqid'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//==================//
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_info().
|
||||
* Implements hook_field_info().
|
||||
*/
|
||||
function serial_field_info() {
|
||||
return array(
|
||||
@@ -24,7 +24,7 @@ function serial_field_info() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_create_instance().
|
||||
* Implements hook_field_create_instance().
|
||||
*/
|
||||
function serial_field_create_instance($instance) {
|
||||
$field = field_read_field($instance['field_name']);
|
||||
@@ -45,7 +45,7 @@ function serial_field_create_instance($instance) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_delete_instance().
|
||||
* Implements hook_field_delete_instance().
|
||||
*/
|
||||
function serial_field_delete_instance($instance) {
|
||||
$field = field_read_field($instance['field_name']);
|
||||
@@ -57,7 +57,7 @@ function serial_field_delete_instance($instance) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_form_alter().
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function serial_form_alter(&$form, $form_state, $form_id) {
|
||||
|
||||
@@ -76,37 +76,50 @@ function serial_form_alter(&$form, $form_state, $form_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_insert().
|
||||
* Implements hook_field_presave().
|
||||
*/
|
||||
function serial_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
module_load_include('inc', 'serial');
|
||||
$sid = _serial_generate_value($entity->nid, $instance['bundle'], $field['field_name']);
|
||||
function serial_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
module_load_include('inc', 'serial');
|
||||
if (empty($items)) {
|
||||
$sid = _serial_generate_value($instance['bundle'], $field['field_name']);
|
||||
$items = array(array('value' => $sid));
|
||||
$entity->$field['field_name'] = $items;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_is_empty().
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function serial_field_is_empty($item, $field) {
|
||||
return FALSE; // never should be treated as empty
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_node_type_update()
|
||||
* Implements hook_node_presave().
|
||||
*/
|
||||
function serial_node_presave($node) {
|
||||
if (module_exists('auto_nodetitle')) {
|
||||
if (auto_nodetitle_get_setting($node->type)) {
|
||||
auto_nodetitle_set_title($node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_type_update().
|
||||
*/
|
||||
function serial_node_type_update($info) {
|
||||
// Handle content type rename:
|
||||
if (isset($info->old_type) && ($info->old_type != $info->type)) {
|
||||
module_load_include('inc', 'serial');
|
||||
_serial_rename_tables($info->old_type, $info->type);
|
||||
}
|
||||
// Handle content type rename:
|
||||
if (isset($info->old_type) && ($info->old_type != $info->type)) {
|
||||
module_load_include('inc', 'serial');
|
||||
_serial_rename_tables($info->old_type, $info->type);
|
||||
}
|
||||
}
|
||||
|
||||
// Tokens for fields are currently not supported - http://drupal.org/node/691078.
|
||||
|
||||
///**
|
||||
// * Implementation of hook_token_info().
|
||||
// * Implements hook_token_info().
|
||||
// */
|
||||
//function serial_token_info() {
|
||||
// $type = array(
|
||||
@@ -126,7 +139,7 @@ function serial_node_type_update($info) {
|
||||
//}
|
||||
//
|
||||
///**
|
||||
// * Implementation of hook_tokens().
|
||||
// * Implements hook_tokens().
|
||||
// */
|
||||
//function serial_tokens($type, $tokens, $data, $options) {
|
||||
// // TODO
|
||||
@@ -137,7 +150,7 @@ function serial_node_type_update($info) {
|
||||
//=================//
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_formatter_info().
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function serial_field_formatter_info() {
|
||||
return array(
|
||||
@@ -165,12 +178,12 @@ function serial_field_formatter_view($entity_type, $entity, $field, $instance, $
|
||||
return $element;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
** Theme Functions *********************************************************
|
||||
/****************************************************************************/
|
||||
/**
|
||||
* Theme Functions
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function serial_theme() {
|
||||
|
||||
@@ -196,7 +209,7 @@ function theme_serial_formatter_default($variables) {
|
||||
//==============//
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_widget_info().
|
||||
* Implements hook_field_widget_info().
|
||||
*/
|
||||
function serial_field_widget_info() {
|
||||
return array(
|
||||
@@ -208,7 +221,7 @@ function serial_field_widget_info() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_widget().
|
||||
* Implements hook_field_widget().
|
||||
*/
|
||||
function serial_field_widget(&$form, &$form_state, $field, $instance, $items, $delta = 0) {
|
||||
return array(
|
||||
|
Reference in New Issue
Block a user