serial.install 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Serial module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function serial_uninstall() {
  10. /*
  11. * Schema tables are now dropped automatically. However, if any work needs
  12. * to be done before this, do it here.
  13. */
  14. }
  15. /**
  16. * Implements hook_field_schema().
  17. */
  18. function serial_field_schema($field) {
  19. switch ($field['type']) {
  20. case 'serial':
  21. $columns['value'] = array(
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'sortable' => TRUE,
  26. 'views' => TRUE,
  27. 'index' => TRUE,
  28. );
  29. break;
  30. }
  31. return array(
  32. 'columns' => $columns
  33. );
  34. }
  35. /**
  36. * Implements hook_schema().
  37. */
  38. function serial_schema() {
  39. // Get the standard schema:
  40. module_load_include('inc', 'serial');
  41. $table_schema = _serial_get_table_schema();
  42. // Build the schema by iteration over all the serial field instances:
  43. $schema = array();
  44. $result = _serial_get_all_fields();
  45. foreach ($result as $field) {
  46. $table = _serial_get_table_name($field->bundle, $field->field_name);
  47. $schema[$table] = $table_schema;
  48. }
  49. // Return the schema of all the assistant tables (one per serial field instance):
  50. return $schema;
  51. }
  52. /**
  53. * Upgrade path.
  54. *
  55. * Switches from nids to uniqid.
  56. */
  57. function serial_update_7130() {
  58. // Get the new field schema.
  59. module_load_include('inc', 'serial');
  60. $table_schema = _serial_get_table_schema();
  61. $uniqid_schema = $table_schema['fields']['uniqid'];
  62. // Update the schema of old assistant tables.
  63. $result = _serial_get_all_fields();
  64. foreach ($result as $field) {
  65. // Empty the table.
  66. $table = _serial_get_table_name($field->bundle, $field->field_name);
  67. db_delete($table)->execute();
  68. // Drop nid field and key
  69. db_drop_field($table, 'nid');
  70. db_drop_unique_key($table, 'nid');
  71. // Add uniqid field and key
  72. db_add_field($table, 'uniqid', $uniqid_schema);
  73. db_add_unique_key($table, 'uniqid', array('uniqid'));
  74. }
  75. }