2012061800.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Restore disappeared subpages. This is caused by its parent page being deleted
  4. * when the parent page is a top level page. We take advantage of the fact that
  5. * the parent_guid was deleted for the subpages.
  6. *
  7. * This upgrade script will no longer work once we have converted all pages to
  8. * have the same entity subtype.
  9. */
  10. /**
  11. * Update subtype
  12. *
  13. * @param ElggObject $page
  14. */
  15. function pages_2012061800($page) {
  16. $dbprefix = elgg_get_config('dbprefix');
  17. $subtype_id = (int)get_subtype_id('object', 'page_top');
  18. $page_guid = (int)$page->guid;
  19. update_data("UPDATE {$dbprefix}entities
  20. SET subtype = $subtype_id WHERE guid = $page_guid");
  21. error_log("called");
  22. return true;
  23. }
  24. $previous_access = elgg_set_ignore_access(true);
  25. $dbprefix = elgg_get_config('dbprefix');
  26. $name_metastring_id = elgg_get_metastring_id('parent_guid');
  27. if (!$name_metastring_id) {
  28. return;
  29. }
  30. // Looking for pages without metadata
  31. $options = array(
  32. 'type' => 'object',
  33. 'subtype' => 'page',
  34. 'wheres' => "NOT EXISTS (
  35. SELECT 1 FROM {$dbprefix}metadata md
  36. WHERE md.entity_guid = e.guid
  37. AND md.name_id = $name_metastring_id)"
  38. );
  39. $batch = new ElggBatch('elgg_get_entities_from_metadata', $options, 'pages_2012061800', 50, false);
  40. elgg_set_ignore_access($previous_access);
  41. if ($batch->callbackResult) {
  42. error_log("Elgg Pages upgrade (2012061800) succeeded");
  43. }