pathologic.install 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * .install file for Pathologic.
  5. */
  6. /**
  7. * Re-enable Pathologic under Drupal 7, preserving settings from Drupal 6.
  8. */
  9. function pathologic_update_7000($sandbox) {
  10. // Make sure {d6_upgrade_filter} exists. It won't exist for people upgrading
  11. // from beta versions of the D7 version of Pathologic on native D7 sites (not
  12. // upgraded from D6).
  13. if (db_table_exists('d6_upgrade_filter')) {
  14. // Get all Pathologic data from {d6_upgrade_filter}.
  15. $rez = db_select('d6_upgrade_filter', 'dup')
  16. ->fields('dup')
  17. ->condition('module', 'pathologic')
  18. ->execute();
  19. while ($instance = $rez->fetchObject()) {
  20. // Load the format
  21. if ($format = filter_format_load($instance->format)) {
  22. // Load filters.
  23. $format->filters = array();
  24. // Add the filters
  25. foreach (filter_list_format($instance->format) as $filter_name => $filter) {
  26. $format->filters[$filter_name] = (array)$filter;
  27. }
  28. // Add Pathologic
  29. $format->filters['pathologic'] = array(
  30. 'weight' => $instance->weight,
  31. 'status' => 1,
  32. 'settings' => array(
  33. 'absolute' => variable_get('filter_pathologic_absolute_' . $instance->format, TRUE),
  34. 'local_paths' => variable_get('filter_pathologic_local_paths_' . $instance->format, ''),
  35. ),
  36. );
  37. // Save the format
  38. filter_format_save($format);
  39. // Unset old variables
  40. variable_del('filter_pathologic_absolute_' . $instance->format);
  41. variable_del('filter_pathologic_local_paths_' . $instance->format);
  42. }
  43. }
  44. // Delete Pathologic data from {d6_upgrade_filter}…?
  45. // No, maybe we don't want to actually do that…?
  46. }
  47. }
  48. /**
  49. * Convert obsolete "absolute" setting to modern "protocol_style" setting for
  50. * each filter instance.
  51. */
  52. function pathologic_update_7200(&$sandbox) {
  53. foreach (filter_formats() as $format) {
  54. // @see http://drupal.org/node/1304930
  55. if (empty($format->filters)) {
  56. $format->filters = array();
  57. // Add the filters
  58. foreach (filter_list_format($format->format) as $filter_name => $filter) {
  59. $format->filters[$filter_name] = (array)$filter;
  60. }
  61. }
  62. if (isset($format->filters['pathologic'])) {
  63. $format->filters['pathologic']['settings']['protocol_style'] = $format->filters['pathologic']['settings']['absolute'] ? 'full' : 'path';
  64. unset($format->filters['pathologic']['settings']['absolute']);
  65. filter_format_save($format);
  66. }
  67. }
  68. }