ctools.install 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. // Update the 'data' field to be type 'blob'.
  47. $schema['ctools_object_cache']['fields']['data'] = array(
  48. 'type' => 'blob',
  49. 'size' => 'big',
  50. 'description' => 'Serialized data being stored.',
  51. 'serialize' => TRUE,
  52. );
  53. // DO NOT MODIFY THIS TABLE -- this definition is used to create the table.
  54. // Changes to this table must be made in schema_3 or higher.
  55. $schema['ctools_css_cache'] = array(
  56. 'description' => 'A special cache used to store CSS that must be non-volatile.',
  57. 'fields' => array(
  58. 'cid' => array(
  59. 'type' => 'varchar',
  60. 'length' => '128',
  61. 'description' => 'The CSS ID this cache object belongs to.',
  62. 'not null' => TRUE,
  63. ),
  64. 'filename' => array(
  65. 'type' => 'varchar',
  66. 'length' => '255',
  67. 'description' => 'The filename this CSS is stored in.',
  68. ),
  69. 'css' => array(
  70. 'type' => 'text',
  71. 'size' => 'big',
  72. 'description' => 'CSS being stored.',
  73. 'serialize' => TRUE,
  74. ),
  75. 'filter' => array(
  76. 'type' => 'int',
  77. 'size' => 'tiny',
  78. 'description' => 'Whether or not this CSS needs to be filtered.',
  79. ),
  80. ),
  81. 'primary key' => array('cid'),
  82. );
  83. return $schema;
  84. }
  85. /**
  86. * CTools' initial schema; separated for the purposes of updates.
  87. *
  88. * DO NOT MAKE CHANGES HERE. This schema version is locked.
  89. */
  90. function ctools_schema_1() {
  91. $schema['ctools_object_cache'] = array(
  92. 'description' => t('A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.'),
  93. 'fields' => array(
  94. 'sid' => array(
  95. 'type' => 'varchar',
  96. 'length' => '64',
  97. 'not null' => TRUE,
  98. 'description' => 'The session ID this cache object belongs to.',
  99. ),
  100. 'name' => array(
  101. 'type' => 'varchar',
  102. 'length' => '32',
  103. 'not null' => TRUE,
  104. 'description' => 'The name of the object this cache is attached to.',
  105. ),
  106. 'obj' => array(
  107. 'type' => 'varchar',
  108. 'length' => '32',
  109. 'not null' => TRUE,
  110. '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.',
  111. ),
  112. 'updated' => array(
  113. 'type' => 'int',
  114. 'unsigned' => TRUE,
  115. 'not null' => TRUE,
  116. 'default' => 0,
  117. 'description' => 'The time this cache was created or updated.',
  118. ),
  119. 'data' => array(
  120. 'type' => 'text',
  121. 'size' => 'big',
  122. 'description' => 'Serialized data being stored.',
  123. 'serialize' => TRUE,
  124. ),
  125. ),
  126. 'primary key' => array('sid', 'obj', 'name'),
  127. 'indexes' => array('updated' => array('updated')),
  128. );
  129. return $schema;
  130. }
  131. /**
  132. * Enlarge the ctools_object_cache.name column to prevent truncation and weird
  133. * errors.
  134. */
  135. function ctools_update_6001() {
  136. // Perform updates like this to reduce code duplication.
  137. $schema = ctools_schema_2();
  138. db_change_field('ctools_object_cache', 'name', 'name', $schema['ctools_object_cache']['fields']['name']);
  139. }
  140. /**
  141. * Add the new css cache table.
  142. */
  143. function ctools_update_6002() {
  144. // Schema 2 is locked and should not be changed.
  145. $schema = ctools_schema_2();
  146. db_create_table('ctools_css_cache', $schema['ctools_css_cache']);
  147. }
  148. /**
  149. * Take over for the panels_views module if it was on.
  150. */
  151. function ctools_update_6003() {
  152. $result = db_query('SELECT status FROM {system} WHERE name = :name', array(':name' => 'panels_views'))->fetchField();
  153. if ($result) {
  154. db_delete('system')->condition('name', 'panels_views')->execute();
  155. module_enable(array('views_content'), TRUE);
  156. }
  157. }
  158. /**
  159. * Add primary key to the ctools_object_cache table.
  160. */
  161. function ctools_update_6004() {
  162. db_add_primary_key('ctools_object_cache', array('sid', 'obj', 'name'));
  163. db_drop_index('ctools_object_cache', 'sid_obj_name');
  164. }
  165. /**
  166. * Removed update.
  167. */
  168. function ctools_update_6005() {
  169. return array();
  170. }
  171. /**
  172. * ctools_custom_content table was originally here, but is now moved to
  173. * its own module.
  174. */
  175. function ctools_update_6007() {
  176. $ret = array();
  177. if (db_table_exists('ctools_custom_content')) {
  178. // Enable the module to make everything as seamless as possible.
  179. module_enable(array('ctools_custom_content'), TRUE);
  180. }
  181. return $ret;
  182. }
  183. /**
  184. * ctools_object_cache needs to be defined as a blob.
  185. */
  186. function ctools_update_6008() {
  187. db_delete('ctools_object_cache')
  188. ->execute();
  189. db_change_field('ctools_object_cache', 'data', 'data', array(
  190. 'type' => 'blob',
  191. 'size' => 'big',
  192. 'description' => 'Serialized data being stored.',
  193. 'serialize' => TRUE,
  194. )
  195. );
  196. }