ctools.install 7.5 KB

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