serial.install 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Serial module.
  5. */
  6. /**
  7. * Implementation of 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. * Implementation of 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. $query = "SELECT i.bundle AS bundle, f.field_name AS field_name ".
  45. "FROM {field_config} f, {field_config_instance} i ".
  46. "WHERE f.field_name = i.field_name AND f.type = 'serial' AND i.deleted = 0";
  47. $result = db_query($query);
  48. foreach ($result as $field) {
  49. $table = _serial_get_table_name($field->bundle, $field->field_name);
  50. $schema[$table] = $table_schema;
  51. }
  52. // Return the schema of all the assistant tables (one per serial field instance):
  53. return $schema;
  54. }