iframe.install 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the text module.
  5. */
  6. /**
  7. * Implements hook_field_schema().
  8. */
  9. function iframe_field_schema($field) {
  10. if ('iframe' == $field['type']) {
  11. $schema = array();
  12. $columns = array(
  13. 'url' => array(
  14. 'type' => 'varchar',
  15. 'length' => 1024,
  16. 'not null' => FALSE,
  17. 'sortable' => TRUE,
  18. ),
  19. 'title' => array(
  20. 'type' => 'varchar',
  21. 'length' => 255,
  22. 'not null' => FALSE,
  23. 'sortable' => TRUE,
  24. ),
  25. 'class' => array(
  26. 'type' => 'varchar',
  27. 'length' => '255',
  28. 'not null' => FALSE,
  29. ),
  30. 'width' => array(
  31. 'type' => 'varchar',
  32. 'length' => 4,
  33. 'not null' => FALSE,
  34. ),
  35. 'height' => array(
  36. 'type' => 'varchar',
  37. 'length' => 4,
  38. 'not null' => FALSE,
  39. ),
  40. 'frameborder' => array(
  41. 'type' => 'int',
  42. 'size' => 'tiny',
  43. 'not null' => TRUE,
  44. 'default' => 0,
  45. ),
  46. 'scrolling' => array(
  47. 'type' => 'varchar',
  48. 'length' => 4,
  49. 'not null' => TRUE,
  50. 'default' => 'auto',
  51. ),
  52. 'transparency' => array(
  53. 'type' => 'int',
  54. 'size' => 'tiny',
  55. 'not null' => TRUE,
  56. 'default' => 0,
  57. ),
  58. 'tokensupport' => array(
  59. 'type' => 'int',
  60. 'size' => 'tiny',
  61. 'not null' => TRUE,
  62. 'default' => 0,
  63. ),
  64. );
  65. $schema['columns'] = $columns;
  66. return $schema;
  67. }
  68. }
  69. /**
  70. * Helper: Returns all fields created on the system of the type defined in mymodule.
  71. */
  72. function iframe_get_mymodule_fields() {
  73. module_load_include('module', 'iframe', 'iframe');
  74. $types = array_keys(iframe_field_info()); // field types defined in mymodule
  75. $fields = array();
  76. foreach (field_info_fields() as $field) {
  77. if (in_array($field['type'], $types)) {
  78. $fields[] = $field;
  79. }
  80. }
  81. return $fields;
  82. }
  83. /**
  84. * Helper: add or change one column
  85. */
  86. function iframe_addorchange_column($field_suffix, $spec) {
  87. if (empty($field_suffix) || !is_array($spec) || !isset($spec['type'])) {
  88. die('Cannot add or change column!');
  89. }
  90. $fields = iframe_get_mymodule_fields();
  91. foreach ($fields as $field) {
  92. if (isset($field['storage']) && isset($field['storage']['type'])
  93. && 0 !== strcmp($field['storage']['type'], 'field_sql_storage')
  94. ) {
  95. $message = t('Iframe: Cannot change field name @name because of different storage_type: @type.',
  96. array('@name' => $field['field_name'], '@type' => $field['storage']['type']));
  97. drupal_set_message($message, 'warning');
  98. continue;
  99. }
  100. $table_prefixes = array(
  101. _field_sql_storage_tablename($field),
  102. _field_sql_storage_revision_tablename($field)
  103. );
  104. foreach ($table_prefixes as $table_prefix) {
  105. $field_name = $field['field_name']; // eg 'field_dimensions' ;
  106. $column = $field_name . '_' . $field_suffix;
  107. if (db_field_exists($table_prefix, $column)) {
  108. db_change_field($table_prefix, $column, $column, $spec);
  109. }
  110. else {
  111. db_add_field($table_prefix, $column, $spec);
  112. }
  113. }
  114. }
  115. }
  116. /**
  117. * Update 7100 : add new column "tokensupport"
  118. */
  119. function iframe_update_7100() {
  120. $spec = array(
  121. 'type' => 'int',
  122. 'size' => 'tiny',
  123. 'not null' => TRUE,
  124. 'default' => 0,
  125. );
  126. iframe_addorchange_column('tokensupport', $spec);
  127. }
  128. /**
  129. * Update 7101 : adjust or synchronize length of "url" field for all users
  130. */
  131. function iframe_update_7101() {
  132. $spec = array(
  133. 'type' => 'varchar',
  134. 'length' => 1024,
  135. 'not null' => FALSE,
  136. 'sortable' => TRUE,
  137. );
  138. iframe_addorchange_column('url', $spec);
  139. }