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