47     public function faker(
string $locale = 
'en_US'): \Faker\Generator {
 
   49             $this->
faker = Factory::create($locale);
 
   52         $this->faker->addProvider(
new LocalImage($this->faker));
 
   74             $email = 
"noreply@{$this->getDomain()}";
 
   79         if (count(explode(
'.', 
$domain)) <= 1) {
 
   92         return substr(sha1(microtime() . rand()), 0, 25);
 
  106         $create = function () use ($properties, 
$options) {
 
  107             $properties[
'__faker'] = 
true;
 
  109             if (empty($properties[
'password'])) {
 
  113             if (empty($properties[
'name'])) {
 
  114                 $properties[
'name'] = $this->
faker()->name;
 
  117             if (empty($properties[
'username'])) {
 
  121             if (empty($properties[
'email'])) {
 
  122                 $properties[
'email'] = $this->
getRandomEmail($properties[
'username']);
 
  125             if (empty($properties[
'subtype'])) {
 
  126                 $properties[
'subtype'] = 
'user';
 
  143                 if (!isset($properties[
'time_created'])) {
 
  147                 if (!empty($properties[
'time_created'])) {
 
  148                     $user->time_created = $properties[
'time_created'];
 
  151                 if (isset($properties[
'admin'])) {
 
  152                     if ($properties[
'admin']) {
 
  155                         $user->removeAdmin();
 
  159                 if (isset($properties[
'banned'])) {
 
  160                     if ($properties[
'banned']) {
 
  161                         $user->ban(
'Banned by seeder');
 
  167                 if (!isset($properties[
'validated'])) {
 
  168                     $properties[
'validated'] = $this->
faker()->boolean(80);
 
  171                 $user->setValidationStatus((
bool) $properties[
'validated'], 
'seeder');
 
  173                 if (!
$user->isValidated()) {
 
  174                     $user->disable(
'seeder invalidation');
 
  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']);
 
  185                 $user->setNotificationSetting(
'email', 
false);
 
  186                 $user->setNotificationSetting(
'site', 
true);
 
  194                 $this->
log(
"Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
 
  202                 $attr_log = print_r($properties, 
true);
 
  203                 $this->
log(
"User creation failed with message {$e->getMessage()} [properties: $attr_log]");
 
  212             while (!
$user instanceof \
ElggUser && $attempts < $this->MAX_ATTEMPTS) {
 
  217                 } 
catch (\Exception $ex) {
 
  223                 throw new MaxAttemptsException(
"Unable to create a user after {$attempts} seeding attempts");
 
  241         $create = function () use ($properties, 
$options) {
 
  242             $properties[
'__faker'] = 
true;
 
  244             if (!isset($properties[
'time_created'])) {
 
  248             if (!isset($properties[
'access_id'])) {
 
  252             if (!isset($properties[
'content_access_mode'])) {
 
  256             if (!isset($properties[
'membership'])) {
 
  260             if (empty($properties[
'name'])) {
 
  261                 $properties[
'name'] = $this->
faker()->sentence();
 
  264             if (empty($properties[
'description'])) {
 
  265                 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
 
  268             if (!isset($properties[
'owner_guid'])) {
 
  278                 $properties[
'owner_guid'] = 
$user->guid;
 
  285             if (!isset($properties[
'container_guid'])) {
 
  286                 $properties[
'container_guid'] = $properties[
'owner_guid'];
 
  293             if (empty($properties[
'subtype'])) {
 
  294                 $properties[
'subtype'] = 
'group';
 
  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;
 
  306             if ($this->
faker()->
boolean(20)) {
 
  307                 $properties[
'featured_group'] = 
'yes';
 
  310             $group = new \ElggGroup();
 
  332                 $acl = 
$group->getOwnedAccessCollection(
'group_acl');
 
  334                     $group->access_id = $acl->id;
 
  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,
 
  350             $this->
log(
"Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
 
  358             while (!
$group instanceof \
ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
 
  365                 throw new MaxAttemptsException(
"Unable to create a group after {$attempts} seeding attempts");
 
  382         $default_properties = [
 
  384             'description' => true,
 
  387         $properties = array_merge($default_properties, $properties);
 
  389         $create = 
function () use ($properties, 
$options) {
 
  390             $properties[
'__faker'] = 
true;
 
  392             if (!isset($properties[
'time_created'])) {
 
  396             if ($properties[
'title'] === 
true) {
 
  397                 $properties[
'title'] = $this->faker()->sentence();
 
  398             } 
elseif ($properties[
'title'] === 
false) {
 
  399                 unset($properties[
'title']);
 
  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']);
 
  408             if (empty($properties[
'subtype'])) {
 
  412             if ($properties[
'tags'] === 
true) {
 
  413                 $properties[
'tags'] = $this->
faker()->words(10);
 
  414             } 
elseif ($properties[
'tags'] === 
false) {
 
  415                 unset($properties[
'tags']);
 
  418             if (!isset($properties[
'owner_guid'])) {
 
  428                 $properties[
'owner_guid'] = 
$user->guid;
 
  435             if (!isset($properties[
'container_guid'])) {
 
  436                 $properties[
'container_guid'] = $properties[
'owner_guid'];
 
  443             if (!isset($properties[
'access_id'])) {
 
  476             $type_str = 
elgg_echo(
"item:object:{$object->getSubtype()}");
 
  478             $this->
log(
"Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
 
  493                 throw new MaxAttemptsException(
"Unable to create an object after {$attempts} seeding attempts");
 
  520     public function getRandomUser(array $exclude = [], 
bool $allow_create = 
true) {
 
  528                 'metadata_names' => [
'__faker'],
 
  544             $profile_fields_config = 
_elgg_services()->fields->get(
'user', 
'user');
 
  545             $profile_fields = [];
 
  546             foreach ($profile_fields_config as 
$field) {
 
  553                 'profile_fields' => $profile_fields,
 
  574             'metadata_names' => [
'__faker'],
 
  584         if (!empty($groups)) {
 
  589             $profile_fields_config = 
_elgg_services()->fields->get(
'group', 
'group');
 
  590             $profile_fields = [];
 
  591             foreach ($profile_fields_config as 
$field) {
 
  600                 'profile_fields' => $profile_fields,
 
  621         return array_rand($access_array, 1);
 
  633         $make = 
function(
$name = 
null)  {
 
  638             return implode(
'.', preg_split(
'/\W/', 
$name));
 
  667         $make = 
function($base = 
null) {
 
  672         $validate = 
function(
$email) {
 
  682         while (!$validate(
$email)) {
 
  780         $icon_location = $this->
faker()->image();
 
  781         if (empty($icon_location)) {
 
  788             $since = $this->create_since;
 
  792                 'view' => 
'river/user/default/profileiconupdate',
 
  793                 'action_type' => 
'update',
 
  794                 'subject_guid' => 
$entity->guid,
 
  795                 'object_guid' => 
$entity->guid,
 
  796                 'posted' => $this->getRandomCreationTimestamp(),
 
  799             $this->create_since = $since;
 
  824                 $limit = $this->faker()->numberBetween(1, 20);
 
  827             $since = $this->create_since;
 
  832                 $comment->owner_guid = $this->getRandomUser()->guid ?: 
$entity->owner_guid;
 
  834                 $comment->description = $this->faker()->paragraph;
 
  836                 $comment->access_id = $entity->access_id;
 
  844             $this->create_since = $since;
 
  868                 $limit = $this->faker()->numberBetween(1, 20);
 
  871             while ($success < 
$limit) {
 
  889     public function log($msg, $level = LogLevel::NOTICE): void {
 
log($level, $message, array $context=[])
Log a message.
getEmailDomain()
Get valid domain for emails.
faker(string $locale='en_US')
Returns an instance of faker.
createUser(array $properties=[], array $options=[])
Create a new fake user.
createSite(array $properties=[])
Create a new fake site.
getRandomSubtype()
Returns random unique subtype.
trait Seeding
Seeding trait Can be used to easily create new random users, groups and objects in the database.
getRandomAccessId(?\ElggUser $user=null, ?\ElggEntity $container=null)
Get random access id.
createComments(\ElggEntity $entity, $limit=null)
Create comments/replies.
getRandomGroup(array $exclude=[], bool $allow_create=true)
Returns random fake group.
createObject(array $properties=[], array $options=[])
Create a new fake object.
createIcon(\ElggEntity $entity)
Create an icon for an entity.
getRandomEmail($base=null)
Generate a random valid email.
createGroup(array $properties=[], array $options=[])
Create a new fake group.
createLikes(\ElggEntity $entity, $limit=null)
Create likes.
getRandomUsername($name=null)
Generates a unique available and valid username.
getDomain()
Get site domain.
getRandomUser(array $exclude=[], bool $allow_create=true)
Returns random fake user.
populateMetadata(\ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.
$fields
Save the configuration of the security.txt contents.
if(! $user||! $user->canDelete()) $name
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'=>[],]
foreach( $paths as $path)
if(empty($user_guids)) $users
save()
Save this data to the appropriate database table.bool
const CONTENT_ACCESS_MODE_UNRESTRICTED
A collection of unique items.
Extends QueryBuilder with ORDER BY clauses.
Database abstraction query builder.
Provide images from a local folder for seeding.
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
const ELGG_HIDE_DISABLED_ENTITIES
const ELGG_SHOW_DISABLED_ENTITIES
const ELGG_VALUE_INTEGER
Value types.
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
if($email instanceof \Elgg\Email) $object
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
_elgg_services()
Get the global service provider.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
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.
elgg_register_user(array $params=[])
Registers a user.
elgg_generate_password()
Generate a random 12 character clear text password.
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
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.
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.
elgg_get_site_entity()
Get the current site entity.
elgg_entity_has_capability(string $type, string $subtype, string $capability, bool $default=false)
Checks if a capability is enabled for a specified type/subtype.
elgg_entity_exists(int $guid)
Does an entity exist?
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
elgg_strtolower()
Wrapper function for mb_strtolower().
trait GroupHelpers
Group helpers for seeding.
getRandomGroupVisibility()
Returns random visibility value.
setCreateSince($since='now')
Set a time for entities to be created after.
getRandomCreationTimestamp()
Get a random timestamp between a lower and upper time.
getRandomGroupContentAccessMode()
Returns random content access mode value.
trait TimeHelpers
Trait to add time helpers.
getRandomGroupMembership()
Returns random membership mode.
if(!elgg_get_config('trash_enabled')) $group
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
elgg_create_river_item(array $options=[])
Elgg river.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.