upgrade.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Upgrade default widgets for Elgg 1.8
  4. *
  5. * Pre-1.8, default widgets were stored as metadata on a defaultwidgets object.
  6. * Now they are stored as widget objects owned by the site.
  7. *
  8. * @package Elgg.Core
  9. * @subpackage Widgets.Management
  10. */
  11. $object = elgg_get_entities(array(
  12. 'type' => 'object',
  13. 'subtype' => 'moddefaultwidgets',
  14. 'limit' => 1,
  15. ));
  16. if (!$object) {
  17. forward(REFERER);
  18. }
  19. $object = $object[0];
  20. $site = elgg_get_site_entity();
  21. $ia = elgg_set_ignore_access(true);
  22. foreach (array('profile', 'dashboard') as $context) {
  23. if (isset($object->$context)) {
  24. elgg_push_context($context);
  25. elgg_push_context('default_widgets');
  26. elgg_push_context('widgets');
  27. // deserialize the widget information
  28. list($left, $middle, $right) = split('%%', $object->$context);
  29. $left_widgets = split('::', $left);
  30. $middle_widgets = split('::', $middle);
  31. $right_widgets = split('::', $right);
  32. // 1st column is right column in default theme
  33. $widgets = array(
  34. 1 => array_reverse($right_widgets),
  35. 2 => array_reverse($middle_widgets),
  36. 3 => array_reverse($left_widgets),
  37. );
  38. foreach ($widgets as $column => $column_widgets) {
  39. foreach ($column_widgets as $handler) {
  40. $guid = elgg_create_widget($site->getGUID(), $handler, $context);
  41. if ($guid) {
  42. $widget = get_entity($guid);
  43. $widget->move($column, 0);
  44. }
  45. }
  46. }
  47. elgg_pop_context();
  48. elgg_pop_context();
  49. elgg_pop_context();
  50. }
  51. }
  52. elgg_set_ignore_access($ia);
  53. $object->delete();
  54. system_message(elgg_echo('upgrade:core'));
  55. forward(REFERER);