38 $this->faker = Factory::create($locale);
40 $this->faker->addProvider(
new LocalImage($this->faker));
47 abstract function seed();
53 abstract function unseed();
84 $attributes[
'email'] =
"{$attributes['username']}@{$this->getDomain()}";
85 if (!filter_var(
$attributes[
'email'], FILTER_VALIDATE_EMAIL)) {
87 $attributes[
'email'] =
"{$attributes['username']}@localhost.com";
100 $user->setNotificationSetting(
'email',
false);
101 $user->setNotificationSetting(
'site',
true);
113 $this->
log(
"Created new user $user->name [guid: $user->guid]");
121 $this->
log($e->getMessage());
140 if (empty(
$metadata[
'content_access_mode'])) {
153 $attributes[
'description'] = $this->faker->text($this->faker->numberBetween(500, 1000));
181 foreach ($tool_options as $group_option) {
182 $option_toggle_name = $group_option->name .
"_enable";
183 $option_default = $group_option->default_on ?
'yes' :
'no';
184 $metadata[$option_toggle_name] = $option_default;
188 if ($this->faker->boolean(20)) {
206 $group->access_id = $group->group_acl;
218 'view' =>
'river/group/create',
219 'action_type' =>
'create',
220 'subject_guid' =>
$owner->guid,
221 'object_guid' => $group->guid,
225 $this->
log(
"Created new group $group->name [guid: $group->guid]");
229 if ($group && $group->guid) {
233 $this->
log($e->getMessage());
253 $attributes[
'description'] = $this->faker->text($this->faker->numberBetween(500, 1000));
257 if ($this->faker->boolean()) {
267 $attributes[
'subtype'] = strtolower($this->faker->word);
271 $metadata[
'tags'] = $this->faker->words(10);
278 'relationship' =>
'member',
280 'inverse_relationship' =>
true,
282 'metadata_names' =>
'__faker',
283 'order_by' =>
'RAND()',
327 $type_str =
elgg_echo(
"item:object:{$object->getSubtype()}");
329 $this->
log(
"Created new item in $type_str $object->title [guid: $object->guid]");
337 $this->
log($e->getMessage());
354 $exclude_in = implode(
',', array_map(
function (
$e) {
360 'metadata_names' => [
'__faker'],
363 "e.guid NOT IN ($exclude_in)",
365 'order_by' =>
'RAND()',
381 $exclude_in = implode(
',', array_map(
function (
$e) {
387 'metadata_names' => [
'__faker'],
390 "e.guid NOT IN ($exclude_in)",
392 'order_by' =>
'RAND()',
395 return $groups ? $groups[0] :
false;
414 $access_key = array_rand($access_array, 1);
416 return $access_array[$access_key];
430 $base_name = iconv(
'UTF-8',
'ASCII//TRANSLIT', $base_name);
431 $blacklist =
'/[\x{0080}-\x{009f}\x{00a0}\x{2000}-\x{200f}\x{2028}-\x{202f}\x{3000}\x{e000}-\x{f8ff}]/u';
464 $base_name = preg_replace($blacklist,
'', $base_name);
465 $base_name = str_replace($blacklist2,
'.', $base_name);
474 $fill = $minlength - strlen($base_name);
483 $base_name =
"$base_name$separator$suffix";
487 while (!$available) {
489 $base_name =
"$base_name$separator$iterator";
498 if ($iterator >= 10) {
500 $base_name = (
new ElggCrypto())->getRandomString(8);
510 return strtolower($base_name);
539 $metadata[
$name] = $this->faker->text($this->faker->numberBetween(500, 1000));
572 $metadata[
'geo:lat'] = $this->faker->latitude;
573 $metadata[
'geo:long'] = $this->faker->longitude;
601 $icon_location = $this->faker->image();
602 if (empty($icon_location)) {
610 'view' =>
'river/user/default/profileiconupdate',
611 'action_type' =>
'update',
612 'subject_guid' => $entity->guid,
613 'object_guid' => $entity->guid,
633 $limit = $this->faker->numberBetween(1, 20);
636 while ($success <
$limit) {
639 $comment->subtype = $entity->
getSubtype() ==
'discussion' ?
'discussion_reply' :
'comment';
641 $comment->container_guid = $entity->guid;
642 $comment->description = $this->faker->paragraph;
666 $limit = $this->faker->numberBetween(1, 20);
669 while ($success <
$limit) {
670 if ($entity->
annotate(
'likes',
true, $entity->access_id, $this->getRandomUser()->guid)) {
685 public function log($msg, $level =
'NOTICE') {
687 if (php_sapi_name() ===
'cli') {
688 $handle = $level ===
'ERROR' ? STDERR : STDOUT;
689 fwrite($handle, $msg . PHP_EOL);
Provide images from a local folder for seeding.
$object
These two snippets demonstrates triggering an event and how to register for that event.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
createIcon(ElggEntity $entity)
Create an icon for an entity.
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
getSubtype()
Get the entity subtype.
getRandomGroup(array $exclude=[])
Returns random fake group.
if($guid==elgg_get_logged_in_user_guid()) $name
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
getRandomUser(array $exclude=[])
Returns random fake user.
getRandomUsername($base_name= 'user')
Generates a unique available and valid username.
validate_username($username)
Simple function which ensures that a username contains only valid characters.
$guid
Removes an admin notice.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=array())
Saves icons using a local file as the source.
createLikes(ElggEntity $entity, $limit=null)
Create likes.
populateMetadata(ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.
register_user($username, $password, $name, $email, $allow_multiple_emails=false)
Registers a user, returning false if the username already exists.
get_user_by_username($username)
Get user by username.
createComments(ElggEntity $entity, $limit=null)
Create comments/replies.
createGroup(array $attributes=[], array $metadata=[])
Create a new faker group.
get_subtype_class($type, $subtype)
Return the class name for a registered type and subtype.
log($msg, $level= 'NOTICE')
Log a message.
getRandomAccessId(\ElggUser $user=null, ElggEntity $container=null)
Get random access id.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $vartype="")
Adds an annotation to an entity.
elgg_create_river_item(array $options=array())
Adds an item to the river.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
const CONTENT_ACCESS_MODE_UNRESTRICTED
if(!is_array($accesslevel)) $profile_fields
get_write_access_array($user_guid=0, $site_guid=0, $flush=false, array $input_params=array())
Returns an array of access permissions that the user is allowed to save content with.
access_get_show_hidden_status()
Return current status of showing disabled entities.
elgg_log($message, $level= 'NOTICE')
Display or log a message.
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
__construct($locale= 'en_US')
Seed constructor.
generate_random_cleartext_password()
Generate a random 12 character clear text password.
elgg_get_entities_from_relationship($options)
Return entities matching a given query joining against a relationship.
unseed()
Removed seeded rows from database.
elgg_set_user_validation_status($user_guid, $status, $method= '')
Set the validation status for a user.
createUser(array $attributes=[], array $metadata=[])
Create a new faker user.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
createObject(array $attributes=[], array $metadata=[])
Create a new faker object.
getDomain()
Get site domain.
get_entity($guid)
Loads and returns an entity object from a guid.