ctools.install 8.4 KB

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