Elgg  Version master
Go to the documentation of this file.
1 <?php
3 namespace Elgg\Entity;
20  public function __invoke(\Elgg\Event $event): void {
21  $retention = (int) elgg_get_config('trash_retention');
22  if ($retention < 1) {
23  return;
24  }
27  /* @var $entities \ElggBatch */
28  $entities = elgg_get_entities([
29  'limit' => false,
30  'batch' => true,
31  'batch_inc_offset' => false,
32  'wheres' => [
33  function(QueryBuilder $qb, $main_alias) {
34  // only deleted items
35  return $qb->compare("{$main_alias}.deleted", '=', 'yes', ELGG_VALUE_STRING);
36  },
37  function(QueryBuilder $qb, $main_alias) use ($retention) {
38  // past the retention period
39  return $qb->compare("{$main_alias}.time_deleted", '<', \Elgg\Values::normalizeTimestamp("-{$retention} days"), ELGG_VALUE_TIMESTAMP);
40  },
41  function(QueryBuilder $qb, $main_alias) {
42  // get only the root deleted items (not the related/sub items)
43  // the related items will be deleted with the root item
45  $sub->select('guid_one')
46  ->where($qb->compare('relationship', '=', 'deleted_with'));
48  return $qb->compare("{$main_alias}.guid", 'not in', $sub->getSQL());
49  }
50  ],
51  'sort_by' => [
52  'property' => 'time_deleted',
53  'direction' => 'ASC',
54  ],
55  ]);
57  $starttime = microtime(true);
59  /* @var $entity \ElggEntity */
60  foreach ($entities as $entity) {
61  if ((microtime(true) - $starttime) > 300) {
62  // limit the cleanup to 5 minutes
63  break;
64  }
66  if (!$entity->delete(true, true)) {
67  $entities->reportFailure();
68  }
69  }
70  });
71  }
72 }
Show a notice about the retention period of trashed items.
Definition: notice.php:6
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
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
subquery(string $table, string $alias=null)
Creates a new SelectQueryBuilder for join/where sub queries using the DB connection of the primary Qu...
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
Cleanup deleted entities from the database.
Database abstraction query builder.
elgg_call() flags
Definition: constants.php:130
Definition: reset.php:8
Definition: constants.php:132
static normalizeTimestamp($time)
Returns timestamp value of the time representation.
Definition: Values.php:63
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
Definition: constants.php:136
Definition: constants.php:115
Definition: constants.php:112
__invoke(\Elgg\Event $event)
After a grace period remove deleted entities from the database.
Definition: queue.php:12
Models an event passed to event handlers.
Definition: Event.php:11