Elgg  Version 6.2
Seeding.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits;
4 
15 use Faker\Factory;
16 use Psr\Log\LogLevel;
17 
24 trait Seeding {
25 
26  use GroupHelpers;
27  use TimeHelpers;
28 
34  protected $MAX_ATTEMPTS = 10;
35 
39  protected $faker;
40 
48  public function faker(string $locale = 'en_US'): \Faker\Generator {
49  if (!isset($this->faker)) {
50  $this->faker = Factory::create($locale);
51  }
52 
53  $this->faker->addProvider(new LocalImage($this->faker));
54 
55  return $this->faker;
56  }
57 
63  public function getDomain(): string {
65  }
66 
72  public function getEmailDomain(): string {
74  if (!$email) {
75  $email = "noreply@{$this->getDomain()}";
76  }
77 
78  list(, $domain) = explode('@', $email);
79 
80  if (count(explode('.', $domain)) <= 1) {
81  $domain = 'example.net';
82  }
83 
84  return $domain;
85  }
86 
92  public function getRandomSubtype(): bool|string {
93  return substr(sha1(microtime() . rand()), 0, 25);
94  }
95 
105  public function createUser(array $properties = [], array $options = []): \ElggUser {
106 
107  $create = function () use ($properties, $options) {
108  $properties['__faker'] = true;
109 
110  if (empty($properties['password'])) {
111  $properties['password'] = elgg_generate_password();
112  }
113 
114  if (empty($properties['name'])) {
115  $properties['name'] = $this->faker()->name;
116  }
117 
118  if (empty($properties['username'])) {
119  $properties['username'] = $this->getRandomUsername($properties['name']);
120  }
121 
122  if (empty($properties['email'])) {
123  $properties['email'] = $this->getRandomEmail($properties['username']);
124  }
125 
126  if (empty($properties['subtype'])) {
127  $properties['subtype'] = 'user';
128  }
129 
130  $user = false;
131 
132  try {
134  'username' => elgg_extract('username', $properties),
135  'password' => elgg_extract('password', $properties),
136  'name' => elgg_extract('name', $properties),
137  'email' => elgg_extract('email', $properties),
138  'subtype' => elgg_extract('subtype', $properties),
139  ]);
140 
141  // make sure we have a cleanly loaded user entity
142  $user = get_user($user->guid);
143 
144  if (!isset($properties['time_created'])) {
145  $properties['time_created'] = $this->getRandomCreationTimestamp();
146  }
147 
148  if (!empty($properties['time_created'])) {
149  $user->time_created = $properties['time_created'];
150  }
151 
152  if (isset($properties['admin'])) {
153  if ($properties['admin']) {
154  $user->makeAdmin();
155  } else {
156  $user->removeAdmin();
157  }
158  }
159 
160  if (isset($properties['banned'])) {
161  if ($properties['banned']) {
162  $user->ban('Banned by seeder');
163  } else {
164  $user->unban();
165  }
166  }
167 
168  if (!isset($properties['validated'])) {
169  $properties['validated'] = $this->faker()->boolean(80);
170  }
171 
172  $user->setValidationStatus((bool) $properties['validated'], 'seeder');
173 
174  if (!$user->isValidated()) {
175  $user->disable('seeder invalidation');
176  }
177 
178  unset($properties['username']);
179  unset($properties['password']);
180  unset($properties['name']);
181  unset($properties['email']);
182  unset($properties['banned']);
183  unset($properties['admin']);
184  unset($properties['validated']);
185 
186  $user->setNotificationSetting('email', false);
187  $user->setNotificationSetting('site', true);
188 
189  $profile_fields = elgg_extract('profile_fields', $options, []);
190  /* @var $user \ElggUser */
191  $user = $this->populateMetadata($user, $profile_fields, $properties);
192 
193  $user->save();
194 
195  $this->log("Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
196 
197  return $user;
198  } catch (RegistrationException $e) {
199  if ($user && $user->guid) {
200  $user->delete();
201  }
202 
203  $attr_log = print_r($properties, true);
204  $this->log("User creation failed with message {$e->getMessage()} [properties: $attr_log]");
205 
206  return false;
207  }
208  };
209 
210  return elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($create) {
211  $user = false;
212  $attempts = 0;
213  while (!$user instanceof \ElggUser && $attempts < $this->MAX_ATTEMPTS) {
214  $attempts++;
215 
216  try {
217  $user = $create();
218  } catch (\Exception $ex) {
219  // try again
220  }
221  }
222 
223  if (!$user instanceof \ElggUser) {
224  throw new MaxAttemptsException("Unable to create a user after {$attempts} seeding attempts");
225  }
226 
227  return $user;
228  });
229  }
230 
240  public function createGroup(array $properties = [], array $options = []): \ElggGroup {
241 
242  $create = function () use ($properties, $options) {
243  $properties['__faker'] = true;
244 
245  if (!isset($properties['time_created'])) {
246  $properties['time_created'] = $this->getRandomCreationTimestamp();
247  }
248 
249  if (!isset($properties['access_id'])) {
250  $properties['access_id'] = ACCESS_PUBLIC;
251  }
252 
253  if (!isset($properties['content_access_mode'])) {
254  $properties['content_access_mode'] = \ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED;
255  }
256 
257  if (!isset($properties['membership'])) {
258  $properties['membership'] = ACCESS_PUBLIC;
259  }
260 
261  if (empty($properties['name'])) {
262  $properties['name'] = $this->faker()->sentence();
263  }
264 
265  if (empty($properties['description'])) {
266  $properties['description'] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
267  }
268 
269  if (!isset($properties['owner_guid'])) {
270  $user = _elgg_services()->session_manager->getLoggedInUser();
271  if (!$user) {
272  $user = $this->getRandomUser();
273  }
274 
275  if (!$user) {
276  return false;
277  }
278 
279  $properties['owner_guid'] = $user->guid;
280  }
281 
282  if (!elgg_entity_exists($properties['owner_guid'])) {
283  return false;
284  }
285 
286  if (!isset($properties['container_guid'])) {
287  $properties['container_guid'] = $properties['owner_guid'];
288  }
289 
290  if (!elgg_entity_exists($properties['container_guid'])) {
291  return false;
292  }
293 
294  if (empty($properties['subtype'])) {
295  $properties['subtype'] = 'group';
296  }
297 
298  $tool_options = elgg_extract('group_tool_options', $options, []);
299  /* @var $tool_options Collection|Tool[] */
300 
301  foreach ($tool_options as $group_option) {
302  $prop_name = $group_option->mapMetadataName();
303  $prop_value = $group_option->mapMetadataValue();
304  $properties[$prop_name] = $prop_value;
305  }
306 
307  if ($this->faker()->boolean(20)) {
308  $properties['featured_group'] = 'yes';
309  }
310 
311  $group = new \ElggGroup();
312  foreach ($properties as $name => $value) {
313  switch ($name) {
314  case 'type':
315  break;
316  case 'subtype':
317  $group->setSubtype($value);
318  break;
319  default:
320  $group->$name = $value;
321  break;
322  }
323  }
324 
325  $profile_fields = elgg_extract('profile_fields', $options, []);
326  $group = $this->populateMetadata($group, $profile_fields, $properties);
327 
328  if (!$group->save()) {
329  return false;
330  }
331 
332  if ($group->access_id === ACCESS_PRIVATE) {
333  $acl = $group->getOwnedAccessCollection('group_acl');
334  if ($acl instanceof \ElggAccessCollection) {
335  $group->access_id = $acl->id;
336  $group->save();
337  }
338  }
339 
340  $group->join(get_entity($properties['owner_guid']));
341 
343  'view' => 'river/group/create',
344  'action_type' => 'create',
345  'subject_guid' => $properties['owner_guid'],
346  'object_guid' => $group->guid,
347  'target_guid' => $properties['container_guid'],
348  'posted' => $group->time_created,
349  ]);
350 
351  $this->log("Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
352 
353  return $group;
354  };
355 
356  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($create) {
357  $group = false;
358  $attempts = 0;
359  while (!$group instanceof \ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
360  $attempts++;
361 
362  $group = $create();
363  }
364 
365  if (!$group instanceof \ElggGroup) {
366  throw new MaxAttemptsException("Unable to create a group after {$attempts} seeding attempts");
367  }
368 
369  return $group;
370  });
371  }
372 
382  public function createObject(array $properties = [], array $options = []): \ElggObject {
383  $default_properties = [
384  'title' => true,
385  'description' => true,
386  'tags' => true,
387  ];
388  $properties = array_merge($default_properties, $properties);
389 
390  $create = function () use ($properties, $options) {
391  $properties['__faker'] = true;
392 
393  if (!isset($properties['time_created'])) {
394  $properties['time_created'] = $this->getRandomCreationTimestamp();
395  }
396 
397  if ($properties['title'] === true) {
398  $properties['title'] = $this->faker()->sentence();
399  } elseif ($properties['title'] === false) {
400  unset($properties['title']);
401  }
402 
403  if ($properties['description'] === true) {
404  $properties['description'] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
405  } elseif ($properties['description'] === false) {
406  unset($properties['description']);
407  }
408 
409  if (empty($properties['subtype'])) {
410  $properties['subtype'] = $this->getRandomSubtype();
411  }
412 
413  if ($properties['tags'] === true) {
414  $properties['tags'] = $this->faker()->words(10);
415  } elseif ($properties['tags'] === false) {
416  unset($properties['tags']);
417  }
418 
419  if (!isset($properties['owner_guid'])) {
420  $user = _elgg_services()->session_manager->getLoggedInUser();
421  if (!$user) {
422  $user = $this->getRandomUser();
423  }
424 
425  if (!$user) {
426  return false;
427  }
428 
429  $properties['owner_guid'] = $user->guid;
430  }
431 
432  if (!elgg_entity_exists($properties['owner_guid'])) {
433  return false;
434  }
435 
436  if (!isset($properties['container_guid'])) {
437  $properties['container_guid'] = $properties['owner_guid'];
438  }
439 
440  if (!elgg_entity_exists($properties['container_guid'])) {
441  return false;
442  }
443 
444  if (!isset($properties['access_id'])) {
445  $properties['access_id'] = ACCESS_PUBLIC;
446  }
447 
448  $class = elgg_get_entity_class('object', $properties['subtype']);
449  if ($class && class_exists($class)) {
450  $object = new $class();
451  } else {
452  $object = new \ElggObject();
453  }
454 
455  foreach ($properties as $name => $value) {
456  switch ($name) {
457  case 'type':
458  break;
459  case 'subtype':
460  $object->setSubtype($value);
461  break;
462  default:
463  $object->$name = $value;
464  break;
465  }
466  }
467 
468  $profile_fields = elgg_extract('profile_fields', $options, []);
469  $object = $this->populateMetadata($object, $profile_fields, $properties);
470 
471  if (elgg_extract('save', $options, true)) {
472  if (!$object->save()) {
473  return false;
474  }
475  }
476 
477  $type_str = elgg_echo("item:object:{$object->getSubtype()}");
478 
479  $this->log("Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
480 
481  return $object;
482  };
483 
484  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($create) {
485  $object = false;
486  $attempts = 0;
487  while (!$object instanceof \ElggObject && $attempts < $this->MAX_ATTEMPTS) {
488  $attempts++;
489 
490  $object = $create();
491  }
492 
493  if (!$object instanceof \ElggObject) {
494  throw new MaxAttemptsException("Unable to create an object after {$attempts} seeding attempts");
495  }
496 
497  return $object;
498  });
499  }
500 
508  public function createSite(array $properties = []): \ElggSite {
509  // We don't want to create more than one site
511  }
512 
521  public function getRandomUser(array $exclude = [], bool $allow_create = true) {
522 
523  $exclude[] = 0;
524 
525  // make sure the random user isn't disabled
526  $users = elgg_call(ELGG_HIDE_DISABLED_ENTITIES, function() use ($exclude) {
527  return elgg_get_entities([
528  'types' => 'user',
529  'metadata_names' => ['__faker'],
530  'limit' => 1,
531  'wheres' => [
532  function(QueryBuilder $qb, $main_alias) use ($exclude) {
533  return $qb->compare("{$main_alias}.guid", 'NOT IN', $exclude, ELGG_VALUE_INTEGER);
534  }
535  ],
536  'order_by' => new OrderByClause('RAND()', null),
537  ]);
538  });
539 
540  if (!empty($users)) {
541  return $users[0];
542  }
543 
544  if ($allow_create) {
545  $profile_fields_config = _elgg_services()->fields->get('user', 'user');
546  $profile_fields = [];
547  foreach ($profile_fields_config as $field) {
548  $profile_fields[$field['name']] = $field['#type'];
549  }
550 
551  return $this->createUser([
552  'validated' => true,
553  ], [
554  'profile_fields' => $profile_fields,
555  ]);
556  }
557 
558  return false;
559  }
560 
569  public function getRandomGroup(array $exclude = [], bool $allow_create = true) {
570 
571  $exclude[] = 0;
572 
573  $groups = elgg_get_entities([
574  'types' => 'group',
575  'metadata_names' => ['__faker'],
576  'limit' => 1,
577  'wheres' => [
578  function(QueryBuilder $qb, $main_alias) use ($exclude) {
579  return $qb->compare("{$main_alias}.guid", 'NOT IN', $exclude, ELGG_VALUE_INTEGER);
580  }
581  ],
582  'order_by' => new OrderByClause('RAND()', null),
583  ]);
584 
585  if (!empty($groups)) {
586  return $groups[0];
587  }
588 
589  if ($allow_create) {
590  $profile_fields_config = _elgg_services()->fields->get('group', 'group');
591  $profile_fields = [];
592  foreach ($profile_fields_config as $field) {
593  $profile_fields[$field['name']] = $field['#type'];
594  }
595 
596  return $this->createGroup([
597  'access_id' => $this->getRandomGroupVisibility(),
598  'content_access_mode' => $this->getRandomGroupContentAccessMode(),
599  'membership' => $this->getRandomGroupMembership(),
600  ], [
601  'profile_fields' => $profile_fields,
602  'group_tool_options' => _elgg_services()->group_tools->all(),
603  ]);
604  }
605 
606  return false;
607  }
608 
617  public function getRandomAccessId(?\ElggUser $user = null, ?\ElggEntity $container = null) {
618  $access_array = elgg_get_write_access_array($user?->guid, false, [
619  'container_guid' => $container?->guid,
620  ]);
621 
622  return array_rand($access_array, 1);
623  }
624 
632  public function getRandomUsername($name = null) {
633 
634  $make = function($name = null) {
635  if (!$name) {
636  return elgg_strtolower($this->faker()->firstName . '.' . $this->faker()->lastName);
637  }
638 
639  return implode('.', preg_split('/\W/', $name));
640  };
641 
642  $validate = function($username) {
643  try {
644  _elgg_services()->accounts->assertValidUsername($username, true);
645  return true;
646  } catch (RegistrationException $e) {
647  return false;
648  }
649  };
650 
651  $username = $make($name);
652  while (!$validate($username)) {
653  $username = $make();
654  }
655 
656  return $username;
657  }
658 
666  public function getRandomEmail($base = null) {
667 
668  $make = function($base = null) {
669  $base = $this->getRandomUsername($base);
670  return $base . '@' . $this->getEmailDomain();
671  };
672 
673  $validate = function($email) {
674  try {
675  _elgg_services()->accounts->assertValidEmail($email, true);
676  return true;
677  } catch (RegistrationException $e) {
678  return false;
679  }
680  };
681 
682  $email = $make($base);
683  while (!$validate($email)) {
684  $email = $make();
685  }
686 
687  return $email;
688  }
689 
699  public function populateMetadata(\ElggEntity $entity, array $fields = [], array $metadata = []): \ElggEntity {
700 
701  foreach ($fields as $name => $type) {
702  if (isset($metadata[$name])) {
703  continue;
704  }
705 
706  switch ($name) {
707  case 'phone':
708  case 'mobile':
709  $metadata[$name] = $this->faker()->phoneNumber;
710  break;
711 
712  default:
713  switch ($type) {
714  case 'plaintext':
715  case 'longtext':
716  $metadata[$name] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
717  break;
718 
719  case 'text':
720  $metadata[$name] = $this->faker()->sentence;
721  break;
722 
723  case 'tags':
724  $metadata[$name] = $this->faker()->words(10);
725  break;
726 
727  case 'url':
728  $metadata[$name] = $this->faker()->url;
729  break;
730 
731  case 'email':
732  $metadata[$name] = $this->faker()->email;
733  break;
734 
735  case 'number':
736  $metadata[$name] = $this->faker()->randomNumber();
737  break;
738 
739  case 'date':
740  $metadata[$name] = $this->faker()->unixTime;
741  break;
742 
743  case 'password':
745  break;
746 
747  case 'location':
748  $metadata[$name] = $this->faker()->address;
749  $metadata['geo:lat'] = $this->faker()->latitude;
750  $metadata['geo:long'] = $this->faker()->longitude;
751  break;
752 
753  default:
754  $metadata[$name] = '';
755  break;
756  }
757  break;
758  }
759  }
760 
761  foreach ($metadata as $key => $value) {
762  if (array_key_exists($key, $fields) && $entity instanceof \ElggUser) {
763  $entity->setProfileData($key, $value, $this->getRandomAccessId($entity));
764  } else {
765  $entity->$key = $value;
766  }
767  }
768 
769  return $entity;
770  }
771 
779  public function createIcon(\ElggEntity $entity): bool {
780 
781  $icon_location = $this->faker()->image();
782  if (empty($icon_location)) {
783  return false;
784  }
785 
786  $result = $entity->saveIconFromLocalFile($icon_location);
787 
788  if ($result && $entity instanceof \ElggUser) {
789  $since = $this->create_since;
790  $this->setCreateSince($entity->time_created);
791 
793  'view' => 'river/user/default/profileiconupdate',
794  'action_type' => 'update',
795  'subject_guid' => $entity->guid,
796  'object_guid' => $entity->guid,
797  'posted' => $this->getRandomCreationTimestamp(),
798  ]);
799 
800  $this->create_since = $since;
801  }
802 
803  return $result;
804  }
805 
814  public function createComments(\ElggEntity $entity, $limit = null): int {
815  if (!elgg_entity_has_capability($entity->getType(), $entity->getSubtype(), 'commentable')) {
816  // the entity doesn't support comments
817  return 0;
818  }
819 
820  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity, $limit) {
821  $tries = 0;
822  $success = 0;
823 
824  if ($limit === null) {
825  $limit = $this->faker()->numberBetween(1, 20);
826  }
827 
828  $since = $this->create_since;
829  $this->setCreateSince($entity->time_created);
830 
831  while ($tries < $limit) {
832  $comment = new \ElggComment();
833  $comment->owner_guid = $this->getRandomUser()->guid ?: $entity->owner_guid;
834  $comment->container_guid = $entity->guid;
835  $comment->description = $this->faker()->paragraph;
836  $comment->time_created = $this->getRandomCreationTimestamp();
837  $comment->access_id = $entity->access_id;
838 
839  $tries++;
840  if ($comment->save()) {
841  $success++;
842  }
843  }
844 
845  $this->create_since = $since;
846 
847  return $success;
848  });
849  }
850 
859  public function createLikes(\ElggEntity $entity, $limit = null): int {
860  if (!elgg_entity_has_capability($entity->getType(), $entity->getSubtype(), 'likable')) {
861  // the entity doesn't support likes
862  return 0;
863  }
864 
865  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity, $limit) {
866  $success = 0;
867 
868  if ($limit === null) {
869  $limit = $this->faker()->numberBetween(1, 20);
870  }
871 
872  while ($success < $limit) {
873  if ($entity->annotate('likes', 'likes', ACCESS_PUBLIC, $this->getRandomUser()->guid)) {
874  $success++;
875  }
876  }
877 
878  return $success;
879  });
880  }
881 
890  public function log($msg, $level = LogLevel::NOTICE): void {
891  elgg_log($msg, $level);
892  }
893 }
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:58
getEmailDomain()
Get valid domain for emails.
Definition: Seeding.php:72
faker(string $locale='en_US')
Returns an instance of faker.
Definition: Seeding.php:48
createUser(array $properties=[], array $options=[])
Create a new fake user.
Definition: Seeding.php:105
createSite(array $properties=[])
Create a new fake site.
Definition: Seeding.php:508
getRandomSubtype()
Returns random unique subtype.
Definition: Seeding.php:92
trait Seeding
Seeding trait Can be used to easily create new random users, groups and objects in the database.
Definition: Seeding.php:24
getRandomAccessId(?\ElggUser $user=null, ?\ElggEntity $container=null)
Get random access id.
Definition: Seeding.php:617
createComments(\ElggEntity $entity, $limit=null)
Create comments/replies.
Definition: Seeding.php:814
getRandomGroup(array $exclude=[], bool $allow_create=true)
Returns random fake group.
Definition: Seeding.php:569
createObject(array $properties=[], array $options=[])
Create a new fake object.
Definition: Seeding.php:382
createIcon(\ElggEntity $entity)
Create an icon for an entity.
Definition: Seeding.php:779
getRandomEmail($base=null)
Generate a random valid email.
Definition: Seeding.php:666
createGroup(array $properties=[], array $options=[])
Create a new fake group.
Definition: Seeding.php:240
createLikes(\ElggEntity $entity, $limit=null)
Create likes.
Definition: Seeding.php:859
getRandomUsername($name=null)
Generates a unique available and valid username.
Definition: Seeding.php:632
getDomain()
Get site domain.
Definition: Seeding.php:63
getRandomUser(array $exclude=[], bool $allow_create=true)
Returns random fake user.
Definition: Seeding.php:521
populateMetadata(\ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.
Definition: Seeding.php:699
$fields
Save the configuration of the security.txt contents.
Definition: security_txt.php:6
$site email
Definition: settings.php:16
$entity
Definition: reset.php:8
$email
Definition: change_email.php:7
$username
Definition: delete.php:23
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
if(! $entity instanceof \ElggEntity) if(! $entity->canComment()) $comment
Definition: save.php:42
$type
Definition: delete.php:21
$container
Definition: delete.php:23
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
$class
Definition: summary.php:44
foreach( $paths as $path)
Definition: autoloader.php:12
$user
Definition: ban.php:7
if(empty($user_guids)) $users
Definition: ban.php:12
save()
Save this data to the appropriate database table.bool
Definition: ElggEntity.php:588
const CONTENT_ACCESS_MODE_UNRESTRICTED
Definition: ElggGroup.php:16
A collection of unique items.
Definition: Collection.php:14
Extends QueryBuilder with ORDER BY clauses.
Database abstraction query builder.
Provide images from a local folder for seeding.
Definition: LocalImage.php:10
Could not register a new user for whatever reason.
Base exception of exceptions in the Elgg system.
Definition: Exception.php:11
Thrown when the seeding has exceeded the max attempts for trying to create an \ElggEntity.
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:121
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:124
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:123
const ACCESS_PRIVATE
Definition: constants.php:10
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
const ACCESS_PUBLIC
Definition: constants.php:12
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
if($email instanceof \Elgg\Email) $object
Definition: body.php:24
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
Definition: item.php:48
if(elgg_extract('input_type', $vars)) if(elgg_extract('required', $vars)) if(elgg_extract('disabled', $vars)) $field
Definition: field.php:42
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:88
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
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:306
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
elgg_get_write_access_array(int $user_guid=0, bool $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:129
elgg_register_user(array $params=[])
Registers a user.
Definition: users.php:154
elgg_generate_password()
Generate a random 12 character clear text password.
Definition: users.php:134
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_get_entity_class(string $type, string $subtype)
Return the class name registered as a constructor for an entity of a given type and subtype.
Definition: entities.php:21
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:101
elgg_entity_has_capability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
Definition: entities.php:717
elgg_entity_exists(int $guid)
Does an entity exist?
Definition: entities.php:91
$value
Definition: generic.php:51
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:125
trait GroupHelpers
Group helpers for seeding.
getRandomGroupVisibility()
Returns random visibility value.
setCreateSince($since='now')
Set a time for entities to be created after.
Definition: TimeHelpers.php:33
getRandomCreationTimestamp()
Get a random timestamp between a lower and upper time.
Definition: TimeHelpers.php:54
getRandomGroupContentAccessMode()
Returns random content access mode value.
trait TimeHelpers
Trait to add time helpers.
Definition: TimeHelpers.php:13
getRandomGroupMembership()
Returns random membership mode.
$limit
Definition: pagination.php:28
$qb
Definition: queue.php:12
if(!elgg_get_config('trash_enabled')) $group
Definition: group.php:13
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:28
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
Definition: robots.php:10
$domain
Definition: layout.php:32
$metadata
Output annotation metadata.
Definition: metadata.php:9