ctools.install 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /**
  3. * @file
  4. * Contains install and update functions for ctools.
  5. */
  6. /**
  7. * Use requirements to ensure that the CTools CSS cache directory can be
  8. * created and that the PHP version requirement is met.
  9. */
  10. function ctools_requirements($phase) {
  11. $requirements = array();
  12. if ($phase == 'runtime') {
  13. $requirements['ctools_css_cache'] = array(
  14. 'title' => t('CTools CSS Cache'),
  15. 'severity' => REQUIREMENT_OK,
  16. 'value' => t('Exists'),
  17. );
  18. $path = 'public://ctools/css';
  19. if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
  20. $requirements['ctools_css_cache']['description'] = t('The CTools CSS cache directory, %path could not be created due to a misconfigured files directory. Please ensure that the files directory is correctly configured and that the webserver has permission to create directories.', array('%path' => file_uri_target($path)));
  21. $requirements['ctools_css_cache']['severity'] = REQUIREMENT_ERROR;
  22. $requirements['ctools_css_cache']['value'] = t('Unable to create');
  23. }
  24. if (!function_exists('error_get_last')) {
  25. $requirements['ctools_php_52']['title'] = t('CTools PHP requirements');
  26. $requirements['ctools_php_52']['description'] = t('CTools requires certain features only available in PHP 5.2.0 or higher.');
  27. $requirements['ctools_php_52']['severity'] = REQUIREMENT_WARNING;
  28. $requirements['ctools_php_52']['value'] = t('PHP !version', array('!version' => phpversion()));
  29. }
  30. }
  31. return $requirements;
  32. }
  33. /**
  34. * Implements hook_schemea
  35. */
  36. function ctools_schema() {
  37. return ctools_schema_2();
  38. }
  39. /**
  40. * Version 2 of the CTools schema.
  41. */
  42. function ctools_schema_2() {
  43. $schema = ctools_schema_1();
  44. // update the 'name' field to be 128 bytes long:
  45. $schema['ctools_object_cache']['fields']['name']['length'] = 128;
  46. // DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
  47. // Changes to this table must be made in schema_3 or higher.
  48. $schema['ctools_css_cache'] = array(
  49. 'description' => 'A special cache used to store CSS that must be non-volatile.',
  50. 'fields' => array(
  51. 'cid' => array(
  52. 'type' => 'varchar',
  53. 'length' => '128',
  54. 'description' => 'The CSS ID this cache object belongs to.',
  55. 'not null' => TRUE,
  56. ),
  57. 'filename' => array(
  58. 'type' => 'varchar',
  59. 'length' => '255',
  60. 'description' => 'The filename this CSS is stored in.',
  61. ),
  62. 'css' => array(
  63. 'type' => 'text',
  64. 'size' => 'big',
  65. 'description' => 'CSS being stored.',
  66. 'serialize' => TRUE,
  67. ),
  68. 'filter' => array(
  69. 'type' => 'int',
  70. 'size' => 'tiny',
  71. 'description' => 'Whether or not this CSS needs to be filtered.',
  72. ),
  73. ),
  74. 'primary key' => array('cid'),
  75. );
  76. return $schema;
  77. }
  78. /**
  79. * CTools' initial schema; separated for the purposes of updates.
  80. *
  81. * DO NOT MAKE CHANGES HERE. This schema version is locked.
  82. */
  83. function ctools_schema_1() {
  84. $schema['ctools_object_cache'] = array(
  85. 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
  86. 'fields' => array(
  87. 'sid' => array(
  88. 'type' => 'varchar',
  89. 'length' => '64',
  90. 'not null' => TRUE,
  91. 'description' => 'The session ID this cache object belongs to.',
  92. ),
  93. 'name' => array(
  94. 'type' => 'varchar',
  95. 'length' => '32',
  96. 'not null' => TRUE,
  97. 'description' => 'The name of the object this cache is attached to.',
  98. ),
  99. 'obj' => array(
  100. 'type' => 'varchar',
  101. 'length' => '32',
  102. 'not null' => TRUE,
  103. 'description' => 'The type of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.',
  104. ),
  105. 'updated' => array(
  106. 'type' => 'int',
  107. 'unsigned' => TRUE,
  108. 'not null' => TRUE,
  109. 'default' => 0,
  110. 'description' => 'The time this cache was created or updated.',
  111. ),
  112. 'data' => array(
  113. 'type' => 'text',
  114. 'size' => 'big',
  115. 'description' => 'Serialized data being stored.',
  116. 'serialize' => TRUE,
  117. ),
  118. ),
  119. 'primary key' => array('sid', 'obj', 'name'),
  120. 'indexes' => array('updated' => array('updated')),
  121. );
  122. return $schema;
  123. }
  124. /**
  125. * Enlarge the ctools_object_cache.name column to prevent truncation and weird
  126. * errors.
  127. */
  128. function ctools_update_6001() {
  129. // Perform updates like this to reduce code duplication.
  130. $schema = ctools_schema_2();
  131. db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
  132. }
  133. /**
  134. * Add the new css cache table.
  135. */
  136. function ctools_update_6002() {
  137. // Schema 2 is locked and should not be changed.
  138. $schema = ctools_schema_2();
  139. db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
  140. }
  141. /**
  142. * Take over for the panels_views module if it was on.
  143. */
  144. function ctools_update_6003() {
  145. $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
  146. if ($result) {
  147. db_delete('system')->condition('name', 'panels_views')->execute();
  148. module_enable(array('views_content'), TRUE);
  149. }
  150. }
  151. /**
  152. * Add primary key to the ctools_object_cache table.
  153. */
  154. function ctools_update_6004() {
  155. db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
  156. db_drop_index('ctools_object_cache', 'sid_obj_name');
  157. }
  158. /**
  159. * Removed update.
  160. */
  161. function ctools_update_6005() {
  162. return array();
  163. }
  164. /**
  165. * ctools_custom_content table was originally here, but is now moved to
  166. * its own module.
  167. */
  168. function ctools_update_6007() {
  169. $ret = array();
  170. if (db_table_exists('ctools_custom_content')) {
  171. // Enable the module to make everything as seamless as possible.
  172. module_enable(array('ctools_custom_content'), TRUE);
  173. }
  174. return $ret;
  175. }