Elgg  Version master
Seeding.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits;
4 
15 use Faker\Factory;
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 {
64  return elgg_get_site_entity()->getDomain();
65  }
66 
72  public function getEmailDomain(): string {
73  $email = elgg_get_site_entity()->email;
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 
106  public function createUser(array $properties = [], array $options = []): \ElggUser {
107 
108  $create = function () use ($properties, $options) {
109  $properties['__faker'] = true;
110 
111  if (empty($properties['password'])) {
112  $properties['password'] = elgg_generate_password();
113  }
114 
115  if (empty($properties['name'])) {
116  $properties['name'] = $this->faker()->name;
117  }
118 
119  if (empty($properties['username'])) {
120  $properties['username'] = $this->getRandomUsername($properties['name']);
121  }
122 
123  if (empty($properties['email'])) {
124  $properties['email'] = $this->getRandomEmail($properties['username']);
125  }
126 
127  if (empty($properties['subtype'])) {
128  $properties['subtype'] = 'user';
129  }
130 
131  $user = false;
132 
133  try {
135  'username' => elgg_extract('username', $properties),
136  'password' => elgg_extract('password', $properties),
137  'name' => elgg_extract('name', $properties),
138  'email' => elgg_extract('email', $properties),
139  'subtype' => elgg_extract('subtype', $properties),
140  ]);
141 
142  // make sure we have a cleanly loaded user entity
143  $user = get_user($user->guid);
144 
145  if (!isset($properties['time_created'])) {
146  $properties['time_created'] = $this->getRandomCreationTimestamp();
147  }
148 
149  if (!empty($properties['time_created'])) {
150  $user->time_created = $properties['time_created'];
151  }
152 
153  if (isset($properties['admin'])) {
154  if ($properties['admin']) {
155  $user->makeAdmin();
156  } else {
157  $user->removeAdmin();
158  }
159  }
160 
161  if (isset($properties['banned'])) {
162  if ($properties['banned']) {
163  $user->ban('Banned by seeder');
164  } else {
165  $user->unban();
166  }
167  }
168 
169  if (!isset($properties['validated'])) {
170  $properties['validated'] = $this->faker()->boolean(80);
171  }
172 
173  $user->setValidationStatus((bool) $properties['validated'], 'seeder');
174 
175  if (!$user->isValidated()) {
176  $user->disable('seeder invalidation');
177  }
178 
179  unset($properties['username']);
180  unset($properties['password']);
181  unset($properties['name']);
182  unset($properties['email']);
183  unset($properties['banned']);
184  unset($properties['admin']);
185  unset($properties['validated']);
186 
187  $user->setNotificationSetting('email', false);
188  $user->setNotificationSetting('site', true);
189 
190  $profile_fields = elgg_extract('profile_fields', $options, []);
191  /* @var $user \ElggUser */
192  $user = $this->populateMetadata($user, $profile_fields, $properties);
193 
194  $user->save();
195 
196  $this->log("Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
197 
198  return $user;
199  } catch (RegistrationException $e) {
200  if ($user && $user->guid) {
201  $user->delete();
202  }
203 
204  $attr_log = print_r($properties, true);
205  $this->log("User creation failed with message {$e->getMessage()} [properties: $attr_log]");
206 
207  return false;
208  }
209  };
210 
211  return elgg_call(ELGG_IGNORE_ACCESS | ELGG_SHOW_DISABLED_ENTITIES, function() use ($create) {
212  $user = false;
213  $attempts = 0;
214  while (!$user instanceof \ElggUser && $attempts < $this->MAX_ATTEMPTS) {
215  $attempts++;
216 
217  try {
218  $user = $create();
219  } catch (\Exception $ex) {
220  // try again
221  }
222  }
223 
224  if (!$user instanceof \ElggUser) {
225  throw new MaxAttemptsException("Unable to create a user after {$attempts} seeding attempts");
226  }
227 
228  return $user;
229  });
230  }
231 
241  public function createGroup(array $properties = [], array $options = []): \ElggGroup {
242 
243  $create = function () use ($properties, $options) {
244  $properties['__faker'] = true;
245 
246  if (!isset($properties['time_created'])) {
247  $properties['time_created'] = $this->getRandomCreationTimestamp();
248  }
249 
250  if (!isset($properties['access_id'])) {
251  $properties['access_id'] = ACCESS_PUBLIC;
252  }
253 
254  if (!isset($properties['content_access_mode'])) {
255  $properties['content_access_mode'] = \ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED;
256  }
257 
258  if (!isset($properties['membership'])) {
259  $properties['membership'] = ACCESS_PUBLIC;
260  }
261 
262  if (empty($properties['name'])) {
263  $properties['name'] = $this->faker()->sentence();
264  }
265 
266  if (empty($properties['description'])) {
267  $properties['description'] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
268  }
269 
270  if (!isset($properties['owner_guid'])) {
271  $user = _elgg_services()->session_manager->getLoggedInUser();
272  if (!$user) {
273  $user = $this->getRandomUser();
274  }
275 
276  if (!$user) {
277  return false;
278  }
279 
280  $properties['owner_guid'] = $user->guid;
281  }
282 
283  if (!elgg_entity_exists($properties['owner_guid'])) {
284  return false;
285  }
286 
287  if (!isset($properties['container_guid'])) {
288  $properties['container_guid'] = $properties['owner_guid'];
289  }
290 
291  if (!elgg_entity_exists($properties['container_guid'])) {
292  return false;
293  }
294 
295  if (empty($properties['subtype'])) {
296  $properties['subtype'] = 'group';
297  }
298 
299  $tool_options = elgg_extract('group_tool_options', $options, []);
300  /* @var $tool_options Collection|Tool[] */
301 
302  foreach ($tool_options as $group_option) {
303  $prop_name = $group_option->mapMetadataName();
304  $prop_value = $group_option->mapMetadataValue();
305  $properties[$prop_name] = $prop_value;
306  }
307 
308  if ($this->faker()->boolean(20)) {
309  $properties['featured_group'] = 'yes';
310  }
311 
312  $group = new \ElggGroup();
313  foreach ($properties as $name => $value) {
314  switch ($name) {
315  case 'type':
316  break;
317  case 'subtype':
318  $group->setSubtype($value);
319  break;
320  default:
321  $group->$name = $value;
322  break;
323  }
324  }
325 
326  $profile_fields = elgg_extract('profile_fields', $options, []);
327  $group = $this->populateMetadata($group, $profile_fields, $properties);
328 
329  if (!$group->save()) {
330  return false;
331  }
332 
333  if ($group->access_id === ACCESS_PRIVATE) {
334  $acl = $group->getOwnedAccessCollection('group_acl');
335  if ($acl instanceof \ElggAccessCollection) {
336  $group->access_id = $acl->id;
337  $group->save();
338  }
339  }
340 
341  $group->join(get_entity($properties['owner_guid']));
342 
344  'view' => 'river/group/create',
345  'action_type' => 'create',
346  'subject_guid' => $properties['owner_guid'],
347  'object_guid' => $group->guid,
348  'target_guid' => $properties['container_guid'],
349  'posted' => $group->time_created,
350  ]);
351 
352  $this->log("Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
353 
354  return $group;
355  };
356 
357  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($create) {
358  $group = false;
359  $attempts = 0;
360  while (!$group instanceof \ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
361  $attempts++;
362 
363  $group = $create();
364  }
365 
366  if (!$group instanceof \ElggGroup) {
367  throw new MaxAttemptsException("Unable to create a group after {$attempts} seeding attempts");
368  }
369 
370  return $group;
371  });
372  }
373 
383  public function createObject(array $properties = [], array $options = []): \ElggObject {
384 
385  $create = function () use ($properties, $options) {
386  $properties['__faker'] = true;
387 
388  if (!isset($properties['time_created'])) {
389  $properties['time_created'] = $this->getRandomCreationTimestamp();
390  }
391 
392  if (empty($properties['title'])) {
393  $properties['title'] = $this->faker()->sentence();
394  }
395 
396  if (empty($properties['description'])) {
397  $properties['description'] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
398  }
399 
400  if (empty($properties['subtype'])) {
401  $properties['subtype'] = $this->getRandomSubtype();
402  }
403 
404  if (empty($properties['tags'])) {
405  $properties['tags'] = $this->faker()->words(10);
406  }
407 
408  if (!isset($properties['owner_guid'])) {
409  $user = _elgg_services()->session_manager->getLoggedInUser();
410  if (!$user) {
411  $user = $this->getRandomUser();
412  }
413 
414  if (!$user) {
415  return false;
416  }
417 
418  $properties['owner_guid'] = $user->guid;
419  }
420 
421  if (!elgg_entity_exists($properties['owner_guid'])) {
422  return false;
423  }
424 
425  if (!isset($properties['container_guid'])) {
426  $properties['container_guid'] = $properties['owner_guid'];
427  }
428 
429  if (!elgg_entity_exists($properties['container_guid'])) {
430  return false;
431  }
432 
433  if (!isset($properties['access_id'])) {
434  $properties['access_id'] = ACCESS_PUBLIC;
435  }
436 
437  $class = elgg_get_entity_class('object', $properties['subtype']);
438  if ($class && class_exists($class)) {
439  $object = new $class();
440  } else {
441  $object = new \ElggObject();
442  }
443 
444  foreach ($properties as $name => $value) {
445  switch ($name) {
446  case 'type':
447  break;
448  case 'subtype':
449  $object->setSubtype($value);
450  break;
451  default:
452  $object->$name = $value;
453  break;
454  }
455  }
456 
457  $profile_fields = elgg_extract('profile_fields', $options, []);
458  $object = $this->populateMetadata($object, $profile_fields, $properties);
459 
460  if (elgg_extract('save', $options, true)) {
461  if (!$object->save()) {
462  return false;
463  }
464  }
465 
466  $type_str = elgg_echo("item:object:{$object->getSubtype()}");
467 
468  $this->log("Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
469 
470  return $object;
471  };
472 
473  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($create) {
474  $object = false;
475  $attempts = 0;
476  while (!$object instanceof \ElggObject && $attempts < $this->MAX_ATTEMPTS) {
477  $attempts++;
478 
479  $object = $create();
480  }
481 
482  if (!$object instanceof \ElggObject) {
483  throw new MaxAttemptsException("Unable to create an object after {$attempts} seeding attempts");
484  }
485 
486  return $object;
487  });
488  }
489 
497  public function createSite(array $properties = []): \ElggSite {
498  // We don't want to create more than one site
499  return elgg_get_site_entity();
500  }
501 
510  public function getRandomUser(array $exclude = [], bool $allow_create = true) {
511 
512  $exclude[] = 0;
513 
514  // make sure the random user isn't disabled
515  $users = elgg_call(ELGG_HIDE_DISABLED_ENTITIES, function() use ($exclude) {
516  return elgg_get_entities([
517  'types' => 'user',
518  'metadata_names' => ['__faker'],
519  'limit' => 1,
520  'wheres' => [
521  function(QueryBuilder $qb, $main_alias) use ($exclude) {
522  return $qb->compare("{$main_alias}.guid", 'NOT IN', $exclude, ELGG_VALUE_INTEGER);
523  }
524  ],
525  'order_by' => new OrderByClause('RAND()', null),
526  ]);
527  });
528 
529  if (!empty($users)) {
530  return $users[0];
531  }
532 
533  if ($allow_create) {
534  $profile_fields_config = _elgg_services()->fields->get('user', 'user');
535  $profile_fields = [];
536  foreach ($profile_fields_config as $field) {
537  $profile_fields[$field['name']] = $field['#type'];
538  }
539 
540  return $this->createUser([
541  'validated' => true,
542  ], [
543  'profile_fields' => $profile_fields,
544  ]);
545  }
546 
547  return false;
548  }
549 
558  public function getRandomGroup(array $exclude = [], bool $allow_create = true) {
559 
560  $exclude[] = 0;
561 
562  $groups = elgg_get_entities([
563  'types' => 'group',
564  'metadata_names' => ['__faker'],
565  'limit' => 1,
566  'wheres' => [
567  function(QueryBuilder $qb, $main_alias) use ($exclude) {
568  return $qb->compare("{$main_alias}.guid", 'NOT IN', $exclude, ELGG_VALUE_INTEGER);
569  }
570  ],
571  'order_by' => new OrderByClause('RAND()', null),
572  ]);
573 
574  if (!empty($groups)) {
575  return $groups[0];
576  }
577 
578  if ($allow_create) {
579  $profile_fields_config = _elgg_services()->fields->get('group', 'group');
580  $profile_fields = [];
581  foreach ($profile_fields_config as $field) {
582  $profile_fields[$field['name']] = $field['#type'];
583  }
584 
585  return $this->createGroup([
586  'access_id' => $this->getRandomGroupVisibility(),
587  'content_access_mode' => $this->getRandomGroupContentAccessMode(),
588  'membership' => $this->getRandomGroupMembership(),
589  ], [
590  'profile_fields' => $profile_fields,
591  'group_tool_options' => _elgg_services()->group_tools->all(),
592  ]);
593  }
594 
595  return false;
596  }
597 
606  public function getRandomAccessId(\ElggUser $user = null, \ElggEntity $container = null) {
607  $access_array = elgg_get_write_access_array($user->guid, false, [
608  'container_guid' => $container?->guid,
609  ]);
610 
611  return array_rand($access_array, 1);
612  }
613 
621  public function getRandomUsername($name = null) {
622 
623  $make = function($name = null) {
624  if (!$name) {
625  return elgg_strtolower($this->faker()->firstName . '.' . $this->faker()->lastName);
626  }
627 
628  return implode('.', preg_split('/\W/', $name));
629  };
630 
631  $validate = function($username) {
632  try {
633  _elgg_services()->accounts->assertValidUsername($username, true);
634  return true;
635  } catch (RegistrationException $e) {
636  return false;
637  }
638  };
639 
640  $username = $make($name);
641  while (!$validate($username)) {
642  $username = $make();
643  }
644 
645  return $username;
646  }
647 
655  public function getRandomEmail($base = null) {
656 
657  $make = function($base = null) {
658  $base = $this->getRandomUsername($base);
659  return $base . '@' . $this->getEmailDomain();
660  };
661 
662  $validate = function($email) {
663  try {
664  _elgg_services()->accounts->assertValidEmail($email, true);
665  return true;
666  } catch (RegistrationException $e) {
667  return false;
668  }
669  };
670 
671  $email = $make($base);
672  while (!$validate($email)) {
673  $email = $make();
674  }
675 
676  return $email;
677  }
678 
688  public function populateMetadata(\ElggEntity $entity, array $fields = [], array $metadata = []): \ElggEntity {
689 
690  foreach ($fields as $name => $type) {
691  if (isset($metadata[$name])) {
692  continue;
693  }
694 
695  switch ($name) {
696  case 'phone':
697  case 'mobile':
698  $metadata[$name] = $this->faker()->phoneNumber;
699  break;
700 
701  default:
702  switch ($type) {
703  case 'plaintext':
704  case 'longtext':
705  $metadata[$name] = $this->faker()->text($this->faker()->numberBetween(500, 1000));
706  break;
707 
708  case 'text':
709  $metadata[$name] = $this->faker()->sentence;
710  break;
711 
712  case 'tags':
713  $metadata[$name] = $this->faker()->words(10);
714  break;
715 
716  case 'url':
717  $metadata[$name] = $this->faker()->url;
718  break;
719 
720  case 'email':
721  $metadata[$name] = $this->faker()->email;
722  break;
723 
724  case 'number':
725  $metadata[$name] = $this->faker()->randomNumber();
726  break;
727 
728  case 'date':
729  $metadata[$name] = $this->faker()->unixTime;
730  break;
731 
732  case 'password':
734  break;
735 
736  case 'location':
737  $metadata[$name] = $this->faker()->address;
738  $metadata['geo:lat'] = $this->faker()->latitude;
739  $metadata['geo:long'] = $this->faker()->longitude;
740  break;
741 
742  default:
743  $metadata[$name] = '';
744  break;
745  }
746  break;
747  }
748  }
749 
750  foreach ($metadata as $key => $value) {
751  if (array_key_exists($key, $fields) && $entity instanceof \ElggUser) {
752  $entity->setProfileData($key, $value, $this->getRandomAccessId($entity));
753  } else {
754  $entity->$key = $value;
755  }
756  }
757 
758  return $entity;
759  }
760 
768  public function createIcon(\ElggEntity $entity): bool {
769 
770  $icon_location = $this->faker()->image();
771  if (empty($icon_location)) {
772  return false;
773  }
774 
775  $result = $entity->saveIconFromLocalFile($icon_location);
776 
777  if ($result && $entity instanceof \ElggUser) {
778  $since = $this->create_since;
779  $this->setCreateSince($entity->time_created);
780 
782  'view' => 'river/user/default/profileiconupdate',
783  'action_type' => 'update',
784  'subject_guid' => $entity->guid,
785  'object_guid' => $entity->guid,
786  'posted' => $this->getRandomCreationTimestamp(),
787  ]);
788 
789  $this->create_since = $since;
790  }
791 
792  return $result;
793  }
794 
803  public function createComments(\ElggEntity $entity, $limit = null): int {
804 
805  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity, $limit) {
806  $tries = 0;
807  $success = 0;
808 
809  if ($limit === null) {
810  $limit = $this->faker()->numberBetween(1, 20);
811  }
812 
813  $since = $this->create_since;
814  $this->setCreateSince($entity->time_created);
815 
816  while ($tries < $limit) {
817  $comment = new \ElggComment();
818  $comment->owner_guid = $this->getRandomUser()->guid ?: $entity->owner_guid;
819  $comment->container_guid = $entity->guid;
820  $comment->description = $this->faker()->paragraph;
821  $comment->time_created = $this->getRandomCreationTimestamp();
822 
823  $tries++;
824  if ($comment->save()) {
825  $success++;
826  }
827  }
828 
829  $this->create_since = $since;
830 
831  return $success;
832  });
833  }
834 
843  public function createLikes(\ElggEntity $entity, $limit = null): int {
844 
845  return elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity, $limit) {
846  $success = 0;
847 
848  if ($limit === null) {
849  $limit = $this->faker()->numberBetween(1, 20);
850  }
851 
852  while ($success < $limit) {
853  if ($entity->annotate('likes', true, $entity->access_id, $this->getRandomUser()->guid)) {
854  $success++;
855  }
856  }
857 
858  return $success;
859  });
860  }
861 
871  public function log($msg, $level = LogLevel::NOTICE): void {
872  elgg_log($msg, $level);
873  }
874 }
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:299
Provide images from a local folder for seeding.
Definition: LocalImage.php:10
getRandomGroupVisibility()
Returns random visibility value.
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:18
saveIconFromLocalFile(string $filename, string $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
faker(string $locale= 'en_US')
Returns an instance of faker.
Definition: Seeding.php:48
Thrown when the seeding has exceeded the max attempts for trying to create an .
Elgg registration action.
if(empty($user_guids)) $users
Definition: ban.php:12
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
elgg_generate_password()
Generate a random 12 character clear text password.
Definition: users.php:142
getRandomGroupContentAccessMode()
Returns random content access mode value.
getRandomUsername($name=null)
Generates a unique available and valid username.
Definition: Seeding.php:621
getRandomSubtype()
Returns random unique subtype.
Definition: Seeding.php:92
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:111
elgg_register_user(array $params=[])
Registers a user.
Definition: users.php:162
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
createSite(array $properties=[])
Create a new fake site.
Definition: Seeding.php:497
trait TimeHelpers
Trait to add time helpers.
Definition: TimeHelpers.php:13
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
getRandomCreationTimestamp()
Get a random timestamp between a lower and upper time.
Definition: TimeHelpers.php:54
$email
Definition: change_email.php:7
createLikes(\ElggEntity $entity, $limit=null)
Create likes.
Definition: Seeding.php:843
Database abstraction query builder.
$username
Definition: delete.php:23
$type
Definition: delete.php:22
Could not register a new user for whatever reason.
elgg_create_river_item(array $options=[])
Elgg river.
Definition: river.php:28
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:161
$options
Elgg admin footer.
Definition: footer.php:6
$value
Definition: generic.php:51
$class
Definition: summary.php:44
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
getDomain()
Get site domain.
Definition: Seeding.php:63
const ELGG_HIDE_DISABLED_ENTITIES
Definition: constants.php:133
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:254
elgg_entity_exists(int $guid)
Does an entity exist?
Definition: entities.php:88
const ELGG_IGNORE_ACCESS
elgg_call() flags
Definition: constants.php:130
if(!$entity instanceof\ElggUser) $fields
Definition: profile.php:14
$limit
Definition: pagination.php:28
const ACCESS_PRIVATE
Definition: constants.php:10
trait GroupHelpers
Group helpers for seeding.
$entity
Definition: reset.php:8
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:132
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:67
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:504
const CONTENT_ACCESS_MODE_UNRESTRICTED
Definition: ElggGroup.php:15
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
getRandomUser(array $exclude=[], bool $allow_create=true)
Returns random fake user.
Definition: Seeding.php:510
$user
Definition: ban.php:7
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
$container
Definition: delete.php:24
createComments(\ElggEntity $entity, $limit=null)
Create comments/replies.
Definition: Seeding.php:803
elgg_get_site_entity()
Get the current site entity.
Definition: entities.php:98
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
if(!$entity instanceof\ElggEntity) if(!$entity->canComment()) $comment
Definition: save.php:42
createUser(array $properties=[], array $options=[])
Create a new fake user.
Definition: Seeding.php:106
if(elgg_extract('required', $vars)) if(elgg_extract('disabled', $vars)) $field
Definition: field.php:38
createIcon(\ElggEntity $entity)
Create an icon for an entity.
Definition: Seeding.php:768
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
Adds an annotation to an entity.
Definition: ElggEntity.php:757
Extends QueryBuilder with ORDER BY clauses.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:58
createObject(array $properties=[], array $options=[])
Create a new fake object.
Definition: Seeding.php:383
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
getRandomEmail($base=null)
Generate a random valid email.
Definition: Seeding.php:655
setCreateSince($since= 'now')
Set a time for entities to be created after.
Definition: TimeHelpers.php:33
$metadata
Output annotation metadata.
Definition: metadata.php:9
$domain
Definition: layout.php:32
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
const ACCESS_PUBLIC
Definition: constants.php:12
getRandomAccessId(\ElggUser $user=null,\ElggEntity $container=null)
Get random access id.
Definition: Seeding.php:606
$qb
Definition: queue.php:11
createGroup(array $properties=[], array $options=[])
Create a new fake group.
Definition: Seeding.php:241
getRandomGroupMembership()
Returns random membership mode.
getEmailDomain()
Get valid domain for emails.
Definition: Seeding.php:72
getRandomGroup(array $exclude=[], bool $allow_create=true)
Returns random fake group.
Definition: Seeding.php:558
populateMetadata(\ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.
Definition: Seeding.php:688