48 public function faker(
string $locale =
'en_US'): \Faker\Generator {
49 if (!isset($this->
faker)) {
50 $this->
faker = Factory::create($locale);
75 $email =
"noreply@{$this->getDomain()}";
108 $create =
function () use ($properties,
$options) {
109 $properties[
'__faker'] =
true;
111 if (empty($properties[
'password'])) {
115 if (empty($properties[
'name'])) {
116 $properties[
'name'] = $this->
faker()->name;
119 if (empty($properties[
'username'])) {
123 if (empty($properties[
'email'])) {
124 $properties[
'email'] = $this->
getRandomEmail($properties[
'username']);
127 if (empty($properties[
'subtype'])) {
128 $properties[
'subtype'] =
'user';
145 if (!isset($properties[
'time_created'])) {
149 if (!empty($properties[
'time_created'])) {
150 $user->time_created = $properties[
'time_created'];
153 if (isset($properties[
'admin'])) {
154 if ($properties[
'admin']) {
157 $user->removeAdmin();
161 if (isset($properties[
'banned'])) {
162 if ($properties[
'banned']) {
163 $user->ban(
'Banned by seeder');
169 if (!isset($properties[
'validated'])) {
170 $properties[
'validated'] = $this->
faker()->boolean(80);
173 $user->setValidationStatus((
bool) $properties[
'validated'],
'seeder');
175 if (!
$user->isValidated()) {
176 $user->disable(
'seeder invalidation');
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']);
187 $user->setNotificationSetting(
'email',
false);
188 $user->setNotificationSetting(
'site',
true);
196 $this->
log(
"Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
204 $attr_log = print_r($properties,
true);
205 $this->
log(
"User creation failed with message {$e->getMessage()} [properties: $attr_log]");
214 while (!
$user instanceof \
ElggUser && $attempts < $this->MAX_ATTEMPTS) {
243 $create =
function () use ($properties,
$options) {
244 $properties[
'__faker'] =
true;
246 if (!isset($properties[
'time_created'])) {
250 if (!isset($properties[
'access_id'])) {
254 if (!isset($properties[
'content_access_mode'])) {
258 if (!isset($properties[
'membership'])) {
262 if (empty($properties[
'name'])) {
263 $properties[
'name'] = $this->
faker()->sentence();
266 if (empty($properties[
'description'])) {
267 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
270 if (!isset($properties[
'owner_guid'])) {
280 $properties[
'owner_guid'] =
$user->guid;
287 if (!isset($properties[
'container_guid'])) {
288 $properties[
'container_guid'] = $properties[
'owner_guid'];
295 if (empty($properties[
'subtype'])) {
296 $properties[
'subtype'] =
'group';
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;
308 if ($this->
faker()->
boolean(20)) {
309 $properties[
'featured_group'] =
'yes';
312 $group = new \ElggGroup();
318 $group->setSubtype(
$value);
329 if (!$group->save()) {
334 $acl = $group->getOwnedAccessCollection(
'group_acl');
336 $group->access_id = $acl->id;
341 $group->join(
get_entity($properties[
'owner_guid']));
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,
352 $this->
log(
"Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
360 while (!$group instanceof \
ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
385 $create =
function () use ($properties,
$options) {
386 $properties[
'__faker'] =
true;
388 if (!isset($properties[
'time_created'])) {
392 if (empty($properties[
'title'])) {
393 $properties[
'title'] = $this->
faker()->sentence();
396 if (empty($properties[
'description'])) {
397 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
400 if (empty($properties[
'subtype'])) {
404 if (empty($properties[
'tags'])) {
405 $properties[
'tags'] = $this->
faker()->words(10);
408 if (!isset($properties[
'owner_guid'])) {
418 $properties[
'owner_guid'] =
$user->guid;
425 if (!isset($properties[
'container_guid'])) {
426 $properties[
'container_guid'] = $properties[
'owner_guid'];
433 if (!isset($properties[
'access_id'])) {
466 $type_str =
elgg_echo(
"item:object:{$object->getSubtype()}");
468 $this->
log(
"Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
483 throw new MaxAttemptsException(
"Unable to create an object after {$attempts} seeding attempts");
510 public function getRandomUser(array $exclude = [],
bool $allow_create =
true) {
518 'metadata_names' => [
'__faker'],
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'];
543 'profile_fields' => $profile_fields,
564 'metadata_names' => [
'__faker'],
574 if (!empty($groups)) {
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'];
590 'profile_fields' => $profile_fields,
611 return array_rand($access_array, 1);
623 $make =
function(
$name = null) {
657 $make =
function($base = null) {
662 $validate =
function(
$email) {
672 while (!$validate(
$email)) {
770 $icon_location = $this->
faker()->image();
771 if (empty($icon_location)) {
778 $since = $this->create_since;
782 'view' =>
'river/user/default/profileiconupdate',
783 'action_type' =>
'update',
784 'subject_guid' => $entity->guid,
785 'object_guid' => $entity->guid,
786 'posted' => $this->getRandomCreationTimestamp(),
789 $this->create_since = $since;
813 $since = $this->create_since;
819 $comment->container_guid = $entity->guid;
829 $this->create_since = $since;
852 while ($success <
$limit) {
853 if ($entity->
annotate(
'likes',
true, $entity->access_id, $this->getRandomUser()->guid)) {
871 public function log($msg, $level = LogLevel::NOTICE):
void {
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Provide images from a local folder for seeding.
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...
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.
Thrown when the seeding has exceeded the max attempts for trying to create an .
Elgg registration action.
if(empty($user_guids)) $users
if(!$user||!$user->canDelete()) $name
elgg_generate_password()
Generate a random 12 character clear text password.
getRandomGroupContentAccessMode()
Returns random content access mode value.
getRandomUsername($name=null)
Generates a unique available and valid username.
getRandomSubtype()
Returns random unique subtype.
const ELGG_VALUE_INTEGER
Value types.
elgg_register_user(array $params=[])
Registers a user.
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
createSite(array $properties=[])
Create a new fake site.
trait TimeHelpers
Trait to add time helpers.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
getRandomCreationTimestamp()
Get a random timestamp between a lower and upper time.
createLikes(\ElggEntity $entity, $limit=null)
Create likes.
Database abstraction query builder.
Could not register a new user for whatever reason.
elgg_create_river_item(array $options=[])
Elgg river.
elgg_strtolower()
Wrapper function for mb_strtolower().
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.
getDomain()
Get site domain.
const ELGG_HIDE_DISABLED_ENTITIES
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_entity_exists(int $guid)
Does an entity exist?
const ELGG_IGNORE_ACCESS
elgg_call() flags
if(!$entity instanceof\ElggUser) $fields
trait GroupHelpers
Group helpers for seeding.
const ELGG_SHOW_DISABLED_ENTITIES
get_entity(int $guid)
Loads and returns an entity object from a guid.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
const CONTENT_ACCESS_MODE_UNRESTRICTED
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
getRandomUser(array $exclude=[], bool $allow_create=true)
Returns random fake user.
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
createComments(\ElggEntity $entity, $limit=null)
Create comments/replies.
elgg_get_site_entity()
Get the current site entity.
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
createUser(array $properties=[], array $options=[])
Create a new fake user.
createIcon(\ElggEntity $entity)
Create an icon for an entity.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
Adds an annotation to an entity.
Extends QueryBuilder with ORDER BY clauses.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
log($level, $message, array $context=[])
Log a message.
createObject(array $properties=[], array $options=[])
Create a new fake object.
if($email instanceof\Elgg\Email) $object
getRandomEmail($base=null)
Generate a random valid email.
setCreateSince($since= 'now')
Set a time for entities to be created after.
_elgg_services()
Get the global service provider.
getRandomAccessId(\ElggUser $user=null,\ElggEntity $container=null)
Get random access id.
createGroup(array $properties=[], array $options=[])
Create a new fake group.
getRandomGroupMembership()
Returns random membership mode.
getEmailDomain()
Get valid domain for emails.
getRandomGroup(array $exclude=[], bool $allow_create=true)
Returns random fake group.
populateMetadata(\ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.