ctools.install 8.0 KB

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