2015031300-1.11.0_dev-comment-access-sync-50c9764e5845315c.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Elgg 1.11.0-dev upgrade 2015031300
  4. * comment-access-sync
  5. *
  6. * Synchronize comment access_id with the container access_id
  7. */
  8. $access_status = access_get_show_hidden_status();
  9. access_show_hidden_entities(true);
  10. $ia = elgg_set_ignore_access(true);
  11. // there may be many instances in large databases
  12. // add \ElggUpgrade object if need to update comments
  13. $dbprefix = elgg_get_config('dbprefix');
  14. $options = array(
  15. 'type' => 'object',
  16. 'subtype' => 'comment',
  17. 'joins' => array(
  18. "JOIN {$dbprefix}entities e2 ON e.container_guid = e2.guid"
  19. ),
  20. 'wheres' => array(
  21. "e.access_id != e2.access_id"
  22. ),
  23. 'count' => true
  24. );
  25. if (elgg_get_entities($options)) {
  26. $path = "admin/upgrades/commentaccess";
  27. $upgrade = new \ElggUpgrade();
  28. // Create the upgrade if one with the same URL doesn't already exist
  29. if (!$upgrade->getUpgradeFromPath($path)) {
  30. $upgrade->setPath($path);
  31. $upgrade->title = 'Comments Access Upgrade';
  32. $upgrade->description = 'Some comments on this system have different access settings than their containers. Run this upgrade to synchronize comment access.';
  33. $upgrade->save();
  34. }
  35. }
  36. elgg_set_ignore_access($ia);
  37. access_show_hidden_entities($access_status);