2011030101.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $topics = elgg_get_entities(array(
  8. 'type' => 'object',
  9. 'subtype' => 'groupforumtopic',
  10. 'limit' => 5,
  11. 'order_by' => 'e.time_created asc',
  12. ));
  13. // if not topics, no upgrade required
  14. if (!$topics) {
  15. return;
  16. }
  17. // if all five of the topics have empty descriptions, we need to upgrade
  18. foreach ($topics as $topic) {
  19. if ($topic->description) {
  20. return;
  21. }
  22. }
  23. /**
  24. * Condense first annotation into object
  25. *
  26. * @param ElggObject $topic
  27. */
  28. function groups_2011030101($topic) {
  29. // do not upgrade topics that have already been upgraded
  30. if ($topic->description) {
  31. return true;
  32. }
  33. $annotation = $topic->getAnnotations(array(
  34. 'annotation_name' => 'group_topic_post',
  35. 'limit' => 1,
  36. ));
  37. if (!$annotation) {
  38. // no text for this forum post so we delete (probably caused by #2624)
  39. return $topic->delete();
  40. }
  41. $topic->description = $annotation[0]->value;
  42. $topic->save();
  43. return $annotation[0]->delete();
  44. }
  45. $previous_access = elgg_set_ignore_access(true);
  46. $options = array(
  47. 'type' => 'object',
  48. 'subtype' => 'groupforumtopic',
  49. 'limit' => 0,
  50. );
  51. $batch = new ElggBatch('elgg_get_entities', $options, 'groups_2011030101', 100);
  52. elgg_set_ignore_access($previous_access);
  53. if ($batch->callbackResult) {
  54. error_log("Elgg Groups upgrade (2011030101) succeeded");
  55. } else {
  56. error_log("Elgg Groups upgrade (2011030101) failed");
  57. }