2012100501.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Move text of first annotation to group forum topic object and delete annotation
  4. *
  5. * First determine if the upgrade is needed and then if needed, batch the update
  6. */
  7. $tasks = elgg_get_entities(array(
  8. 'type' => 'object',
  9. 'subtype' => 'tasks',
  10. 'limit' => 1,
  11. ));
  12. // if not topics, no upgrade required
  13. if (empty($tasks)) {
  14. return;
  15. }
  16. function tasks_2012100501($task) {
  17. require_once(elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php');
  18. if ($task->long_description) {
  19. $task->description = $task->long_description;
  20. $task->deleteMetadata('long_description');
  21. $task->save();
  22. }
  23. if ($task->parent_guid) {
  24. $task->list_guid = $task->parent_guid;
  25. $task->deleteMetadata('parent_guid');
  26. }
  27. else {
  28. $task->list_guid = 0;
  29. }
  30. /* Active was set as default, so it is not indicative of which tasks are
  31. really active */
  32. $task->deleteMetadata('active');
  33. if ($task->done) {
  34. $task->status = 'done';
  35. $task->deleteMetadata('done');
  36. } else {
  37. $task->status = 'new';
  38. }
  39. // reset priority since old system was a mess
  40. $task->priority = 2;
  41. upgrade_change_subtype($task, 'task');
  42. // update river
  43. $options = array('object_guid' => $task->guid);
  44. $items = elgg_get_river($options);
  45. foreach($items as $item) {
  46. if ($item->action_type == 'create') {
  47. upgrade_update_river($item->id, 'river/object/task/create', $task->guid, 0);
  48. }
  49. elseif(in_array($item->action_type, array('done', 'undone', 'subscribe', 'unsubscribe'))) {
  50. elgg_delete_river(array('id' => $item->id));
  51. }
  52. }
  53. return true;
  54. }
  55. /*
  56. * Run upgrade. First topics, then replies.
  57. */
  58. $previous_access = elgg_set_ignore_access(true);
  59. $options = array(
  60. 'type' => 'object',
  61. 'subtype' => 'tasks',
  62. 'limit' => 0,
  63. );
  64. $batch = new ElggBatch('elgg_get_entities', $options, "tasks_2012100501", 100, false);
  65. elgg_set_ignore_access($previous_access);
  66. if ($batch->callbackResult) {
  67. error_log("Elgg Tasks upgrade (2012100501) succeeded");
  68. } else {
  69. error_log("Elgg Tasks upgrade (2012100501) failed");
  70. }