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()}";
107 $create =
function () use ($properties,
$options) {
108 $properties[
'__faker'] =
true;
110 if (empty($properties[
'password'])) {
114 if (empty($properties[
'name'])) {
115 $properties[
'name'] = $this->
faker()->name;
118 if (empty($properties[
'username'])) {
122 if (empty($properties[
'email'])) {
123 $properties[
'email'] = $this->
getRandomEmail($properties[
'username']);
126 if (empty($properties[
'subtype'])) {
127 $properties[
'subtype'] =
'user';
144 if (!isset($properties[
'time_created'])) {
148 if (!empty($properties[
'time_created'])) {
149 $user->time_created = $properties[
'time_created'];
152 if (isset($properties[
'admin'])) {
153 if ($properties[
'admin']) {
156 $user->removeAdmin();
160 if (isset($properties[
'banned'])) {
161 if ($properties[
'banned']) {
162 $user->ban(
'Banned by seeder');
168 if (!isset($properties[
'validated'])) {
169 $properties[
'validated'] = $this->
faker()->boolean(80);
172 $user->setValidationStatus((
bool) $properties[
'validated'],
'seeder');
174 if (!
$user->isValidated()) {
175 $user->disable(
'seeder invalidation');
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']);
186 $user->setNotificationSetting(
'email',
false);
187 $user->setNotificationSetting(
'site',
true);
195 $this->
log(
"Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
203 $attr_log = print_r($properties,
true);
204 $this->
log(
"User creation failed with message {$e->getMessage()} [properties: $attr_log]");
213 while (!
$user instanceof \
ElggUser && $attempts < $this->MAX_ATTEMPTS) {
242 $create =
function () use ($properties,
$options) {
243 $properties[
'__faker'] =
true;
245 if (!isset($properties[
'time_created'])) {
249 if (!isset($properties[
'access_id'])) {
253 if (!isset($properties[
'content_access_mode'])) {
257 if (!isset($properties[
'membership'])) {
261 if (empty($properties[
'name'])) {
262 $properties[
'name'] = $this->
faker()->sentence();
265 if (empty($properties[
'description'])) {
266 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
269 if (!isset($properties[
'owner_guid'])) {
279 $properties[
'owner_guid'] =
$user->guid;
286 if (!isset($properties[
'container_guid'])) {
287 $properties[
'container_guid'] = $properties[
'owner_guid'];
294 if (empty($properties[
'subtype'])) {
295 $properties[
'subtype'] =
'group';
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;
307 if ($this->
faker()->
boolean(20)) {
308 $properties[
'featured_group'] =
'yes';
311 $group = new \ElggGroup();
333 $acl =
$group->getOwnedAccessCollection(
'group_acl');
335 $group->access_id = $acl->id;
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,
351 $this->
log(
"Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
359 while (!
$group instanceof \
ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
383 $default_properties = [
385 'description' =>
true,
388 $properties = array_merge($default_properties, $properties);
390 $create =
function () use ($properties,
$options) {
391 $properties[
'__faker'] =
true;
393 if (!isset($properties[
'time_created'])) {
397 if ($properties[
'title'] ===
true) {
398 $properties[
'title'] = $this->
faker()->sentence();
399 }
elseif ($properties[
'title'] ===
false) {
400 unset($properties[
'title']);
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']);
409 if (empty($properties[
'subtype'])) {
413 if ($properties[
'tags'] ===
true) {
414 $properties[
'tags'] = $this->
faker()->words(10);
415 }
elseif ($properties[
'tags'] ===
false) {
416 unset($properties[
'tags']);
419 if (!isset($properties[
'owner_guid'])) {
429 $properties[
'owner_guid'] =
$user->guid;
436 if (!isset($properties[
'container_guid'])) {
437 $properties[
'container_guid'] = $properties[
'owner_guid'];
444 if (!isset($properties[
'access_id'])) {
477 $type_str =
elgg_echo(
"item:object:{$object->getSubtype()}");
479 $this->
log(
"Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
494 throw new MaxAttemptsException(
"Unable to create an object after {$attempts} seeding attempts");
521 public function getRandomUser(array $exclude = [],
bool $allow_create =
true) {
529 'metadata_names' => [
'__faker'],
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'];
554 'profile_fields' => $profile_fields,
575 'metadata_names' => [
'__faker'],
585 if (!empty($groups)) {
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'];
601 'profile_fields' => $profile_fields,
622 return array_rand($access_array, 1);
634 $make =
function(
$name = null) {
668 $make =
function($base = null) {
673 $validate =
function(
$email) {
683 while (!$validate(
$email)) {
781 $icon_location = $this->
faker()->image();
782 if (empty($icon_location)) {
786 $result = $entity->saveIconFromLocalFile($icon_location);
789 $since = $this->create_since;
793 'view' =>
'river/user/default/profileiconupdate',
794 'action_type' =>
'update',
795 'subject_guid' => $entity->guid,
796 'object_guid' => $entity->guid,
797 'posted' => $this->getRandomCreationTimestamp(),
800 $this->create_since = $since;
828 $since = $this->create_since;
834 $comment->container_guid = $entity->guid;
837 $comment->access_id = $entity->access_id;
845 $this->create_since = $since;
872 while ($success <
$limit) {
891 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.
if(!elgg_get_config('trash_enabled')) $group
getSubtype()
Get the entity subtype.
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...
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().
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
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.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
elgg_entity_exists(int $guid)
Does an entity exist?
const ELGG_IGNORE_ACCESS
elgg_call() flags
Base exception of exceptions in the Elgg system.
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
$fields
Save the configuration of the security.txt contents.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
getRandomUser(array $exclude=[], bool $allow_create=true)
Returns random fake user.
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.
getType()
Returns the entity type.
_elgg_services()
Get the global service provider.
elgg_entity_has_capability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
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.