video_embed_field.install 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the video_embed_field module.
  5. *
  6. */
  7. /**
  8. * Install file for video_embed_field module
  9. * @author jcaldwell
  10. */
  11. /**
  12. * Implements hook_field_schema().
  13. */
  14. function video_embed_field_field_schema($field) {
  15. switch ($field['type']) {
  16. case 'video_embed_field':
  17. $columns = array(
  18. 'video_url' => array(
  19. 'type' => 'varchar',
  20. 'length' => 512,
  21. 'default' => '',
  22. ),
  23. 'thumbnail_path' => array(
  24. 'type' => 'varchar',
  25. 'length' => 512,
  26. 'default' => '',
  27. ),
  28. 'video_data' => array(
  29. 'type' => 'blob',
  30. 'not null' => FALSE,
  31. 'size' => 'big',
  32. 'serialize' => TRUE,
  33. ),
  34. 'embed_code' => array(
  35. 'type' => 'varchar',
  36. 'length' => 1024,
  37. 'default' => '',
  38. ),
  39. 'description' => array(
  40. 'type' => 'text',
  41. 'not null' => FALSE,
  42. ),
  43. );
  44. $indexes = array();
  45. break;
  46. }
  47. return array(
  48. 'columns' => $columns,
  49. 'indexes' => $indexes,
  50. );
  51. }
  52. /**
  53. * Implements hook_schema().
  54. */
  55. function video_embed_field_schema() {
  56. $schema['vef_video_styles'] = array(
  57. 'description' => 'Stores video embed styles.',
  58. 'export' => array(
  59. 'key' => 'name',
  60. 'primary key' => 'vsid',
  61. 'identifier' => 'video_embed_style', // Exports will be as $video_style
  62. 'default hook' => 'default_video_embed_styles', // Function hook name.
  63. 'api' => array(
  64. 'owner' => 'video_embed_field',
  65. 'api' => 'default_video_embed_styles', // Base name for api include files.
  66. 'minimum_version' => 1,
  67. 'current_version' => 1,
  68. ),
  69. ),
  70. 'fields' => array(
  71. 'vsid' => array(
  72. 'description' => 'The primary identifier for a video style.',
  73. 'type' => 'serial',
  74. 'unsigned' => TRUE,
  75. 'not null' => TRUE,
  76. 'no export' => TRUE,
  77. ),
  78. 'name' => array(
  79. 'description' => 'The style name.',
  80. 'type' => 'varchar',
  81. 'length' => '255',
  82. 'not null' => TRUE,
  83. ),
  84. 'data' => array(
  85. 'description' => 'The configuration data for the style.',
  86. 'type' => 'blob',
  87. 'size' => 'big',
  88. 'not null' => TRUE,
  89. 'serialize' => TRUE,
  90. ),
  91. ),
  92. 'primary key' => array('vsid'),
  93. 'unique keys' => array(
  94. 'name' => array('name'),
  95. ),
  96. );
  97. return $schema;
  98. }
  99. /**
  100. * Implements hook_uninstall().
  101. */
  102. function video_embed_field_uninstall() {
  103. //do nothing right now - should eventually remove all the variables
  104. }
  105. /**
  106. * Update 7000
  107. * Add an optional description form
  108. */
  109. function video_embed_field_update_7000() {
  110. // Get the list of fields of type 'video_embed_field'.
  111. $video_embed_fields = array();
  112. foreach (field_info_fields() as $field_name => $field_info) {
  113. if ($field_info['type'] == 'video_embed_field') {
  114. $video_embed_fields[$field_name] = field_read_field($field_name);
  115. }
  116. }
  117. foreach ($video_embed_fields as $field) {
  118. if ($field['deleted']) {
  119. $table = "field_deleted_data_{$field['id']}";
  120. $revision_table = "field_deleted_revision_{$field['id']}";
  121. }
  122. else {
  123. $table = "field_data_{$field['field_name']}";
  124. $revision_table = "field_revision_{$field['field_name']}";
  125. }
  126. $column = $field['field_name'] . '_' . 'description';
  127. db_add_field($table, $column, array('type' => 'text', 'not null' => FALSE));
  128. db_add_field($revision_table, $column, array('type' => 'text', 'not null' => FALSE));
  129. }
  130. return t('Additional columns added.');
  131. }
  132. /**
  133. * Update 7001
  134. * Add video style storage table
  135. */
  136. function video_embed_field_update_7001() {
  137. if (!db_table_exists('vef_video_styles')) {
  138. $schema = video_embed_field_schema();
  139. db_create_table('vef_video_styles', $schema['vef_video_styles']);
  140. }
  141. return t('Video styles storage table created.');
  142. }
  143. /**
  144. * Update 7002
  145. * Add field for storing the path to the video thumbnail
  146. */
  147. function video_embed_field_update_7002() {
  148. // Get the list of fields of type 'video_embed_field'.
  149. $video_embed_fields = array();
  150. foreach (field_info_fields() as $field_name => $field_info) {
  151. if ($field_info['type'] == 'video_embed_field') {
  152. $video_embed_fields[$field_name] = field_read_field($field_name);
  153. }
  154. }
  155. foreach ($video_embed_fields as $field) {
  156. if ($field['deleted']) {
  157. $table = "field_deleted_data_{$field['id']}";
  158. $revision_table = "field_deleted_revision_{$field['id']}";
  159. }
  160. else {
  161. $table = "field_data_{$field['field_name']}";
  162. $revision_table = "field_revision_{$field['field_name']}";
  163. }
  164. $column = $field['field_name'] . '_' . 'thumbnail_path';
  165. db_add_field($table, $column, array(
  166. 'type' => 'varchar',
  167. 'length' => 512,
  168. 'default' => '',
  169. ));
  170. db_add_field($revision_table, $column, array(
  171. 'type' => 'varchar',
  172. 'length' => 512,
  173. 'default' => '',
  174. ));
  175. }
  176. return t('Thumbnail column added.');
  177. }
  178. /**
  179. * Enable inline colorbox support if colorbox is installed [NO LONGER NEEDED - This update hook does nothing]
  180. */
  181. function video_embed_field_update_7003() {
  182. //this is no longer needed
  183. //variable_set('colorbox_inline', 1);
  184. }
  185. /**
  186. * Enable colorbox load support if colorbox is installed, we no longer need inline support
  187. */
  188. function video_embed_field_update_7004() {
  189. variable_set('colorbox_load', 1);
  190. }
  191. /**
  192. * Add data column to field database.
  193. */
  194. function video_embed_field_update_7005() {
  195. // Get the list of fields of type 'video_embed_field'.
  196. $video_embed_fields = array();
  197. foreach (field_info_fields() as $field_name => $field_info) {
  198. if ($field_info['type'] == 'video_embed_field') {
  199. $video_embed_fields[$field_name] = field_read_field($field_name);
  200. }
  201. }
  202. foreach ($video_embed_fields as $field) {
  203. if ($field['deleted']) {
  204. $table = "field_deleted_data_{$field['id']}";
  205. $revision_table = "field_deleted_revision_{$field['id']}";
  206. }
  207. else {
  208. $table = "field_data_{$field['field_name']}";
  209. $revision_table = "field_revision_{$field['field_name']}";
  210. }
  211. $column = $field['field_name'] . '_' . 'video_data';
  212. db_add_field($table, $column, array(
  213. 'type' => 'blob',
  214. 'not null' => FALSE,
  215. 'size' => 'big',
  216. 'serialize' => TRUE,
  217. ));
  218. db_add_field($revision_table, $column, array(
  219. 'type' => 'blob',
  220. 'not null' => FALSE,
  221. 'size' => 'big',
  222. 'serialize' => TRUE,
  223. ));
  224. }
  225. return t('Data column added. Please clear cache.');
  226. }