Elgg  Version master
SyncContainerAccessHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Comments;
4 
11 
19  public function __invoke(\Elgg\Event $event) {
20  $entity = $event->getObject();
21  if (!$entity instanceof \ElggEntity) {
22  return;
23  }
24 
25  // only need update query if access_id of entity has been changed
26  if (!array_key_exists('access_id', $entity->getOriginalAttributes())) {
27  return;
28  }
29 
30  // need to override access in case comments ended up with ACCESS_PRIVATE
31  // and to ensure write permissions
32  elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity) {
34  'type' => 'object',
35  'subtype' => 'comment',
36  'container_guid' => $entity->guid,
37  'wheres' => [
38  function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($entity) {
39  return $qb->compare("{$main_alias}.access_id", '!=', $entity->access_id, ELGG_VALUE_INTEGER);
40  },
41  ],
42  'limit' => false,
43  'batch' => true,
44  'batch_inc_offset' => false,
45  ]);
46 
47  foreach ($comments as $comment) {
48  // Update comment access_id
49  $comment->access_id = $entity->access_id;
50  $comment->save();
51  }
52  });
53  }
54 }
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:304
Keeps comments access in sync with container access.
The Elgg database.
Definition: Database.php:26
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
__invoke(\Elgg\Event $event)
Update comment access to match that of the container.
Database abstraction query builder.
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
$entity
Definition: reset.php:8
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
if(!$entity instanceof\ElggEntity) if(!$entity->canComment()) $comment
Definition: save.php:42
if($owner_guid) if($container_guid) if($subtypes) $comments
$qb
Definition: queue.php:12
Models an event passed to event handlers.
Definition: Event.php:11