serial.install 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Serial module.
  5. */
  6. /**
  7. * Implements hook_field_schema().
  8. */
  9. function serial_field_schema($field) {
  10. $columns = array();
  11. switch ($field['type']) {
  12. case 'serial':
  13. $columns['value'] = array(
  14. 'type' => 'int',
  15. 'unsigned' => TRUE,
  16. 'not null' => TRUE,
  17. 'sortable' => TRUE,
  18. 'views' => TRUE,
  19. 'index' => TRUE,
  20. );
  21. break;
  22. }
  23. return array('columns' => $columns);
  24. }
  25. /**
  26. * Implements hook_schema().
  27. */
  28. function serial_schema() {
  29. // Get the standard schema:
  30. module_load_include('inc', 'serial');
  31. $table_schema = _serial_get_table_schema();
  32. $schema = array();
  33. foreach (_serial_get_all_fields() as $field) {
  34. $schema[_serial_get_table_name($field->bundle, $field->field_name)] = $table_schema;
  35. }
  36. // Return the schema of all the assistant tables (one per field instance).
  37. return $schema;
  38. }
  39. /**
  40. * Upgrade path.
  41. *
  42. * Switches from nids to uniqids.
  43. */
  44. function serial_update_7130() {
  45. module_load_include('inc', 'serial');
  46. $table_schema = _serial_get_table_schema();
  47. // Update the schema of old assistant tables.
  48. foreach (_serial_get_all_fields() as $field) {
  49. // Empty the table.
  50. $table = _serial_get_table_name($field->bundle, $field->field_name);
  51. db_delete($table)->execute();
  52. // Drop nid field and key.
  53. db_drop_field($table, 'nid');
  54. db_drop_unique_key($table, 'nid');
  55. // Add uniqid field and key.
  56. db_add_field($table, 'uniqid', $table_schema['fields']['uniqid']);
  57. db_add_unique_key($table, 'uniqid', array('uniqid'));
  58. }
  59. }