48 public function faker($locale =
'en_US') {
49 if (!isset($this->
faker)) {
50 $this->
faker = Factory::create($locale);
75 $email =
"noreply@{$this->getDomain()}";
80 if (
sizeof(explode(
'.',
$domain)) <= 1) {
157 $user->removeAdmin();
163 $user->ban(
'Banned by seeder');
172 $user->setValidationStatus((
bool)
$metadata[
'validated'],
'seeder');
174 if (!
$user->isValidated()) {
175 $user->disable(
'seeder invalidation');
178 unset($metadata[
'username']);
179 unset($metadata[
'password']);
180 unset($metadata[
'name']);
181 unset($metadata[
'email']);
182 unset($metadata[
'banned']);
183 unset($metadata[
'admin']);
184 unset($metadata[
'validated']);
186 $user->setNotificationSetting(
'email',
false);
187 $user->setNotificationSetting(
'site',
true);
195 $this->
log(
"Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
204 $this->
log(
"User creation failed with message {$e->getMessage()} [attributes: $attr_log]");
213 while (!
$user instanceof \
ElggUser && $attempts < $this->MAX_ATTEMPTS) {
247 $properties[
'__faker'] =
true;
249 if (!isset($properties[
'time_created'])) {
253 if (!isset($properties[
'access_id'])) {
257 if (!isset($properties[
'content_access_mode'])) {
261 if (!isset($properties[
'membership'])) {
265 if (empty($properties[
'name'])) {
266 $properties[
'name'] = $this->
faker()->sentence();
269 if (empty($properties[
'description'])) {
270 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
273 if (!isset($properties[
'owner_guid'])) {
283 $properties[
'owner_guid'] =
$user->guid;
290 if (!isset($properties[
'container_guid'])) {
291 $properties[
'container_guid'] = $properties[
'owner_guid'];
298 if (empty($properties[
'subtype'])) {
299 $properties[
'subtype'] =
'group';
305 foreach ($tool_options as $group_option) {
306 $prop_name = $group_option->mapMetadataName();
307 $prop_value = $group_option->mapMetadataValue();
308 $properties[$prop_name] = $prop_value;
311 if ($this->
faker()->
boolean(20)) {
312 $properties[
'featured_group'] =
'yes';
315 $group = new \ElggGroup();
321 $group->setSubtype(
$value);
332 if (!$group->save()) {
337 $acl = $group->getOwnedAccessCollection(
'group_acl');
339 $group->access_id = $acl->id;
344 $group->join(
get_entity($properties[
'owner_guid']));
347 'view' =>
'river/group/create',
348 'action_type' =>
'create',
349 'subject_guid' => $properties[
'owner_guid'],
350 'object_guid' => $group->guid,
351 'target_guid' => $properties[
'container_guid'],
352 'posted' => $group->time_created,
355 $this->
log(
"Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
363 while (!$group instanceof \
ElggGroup && $attempts < $this->MAX_ATTEMPTS) {
393 $properties[
'__faker'] =
true;
395 if (!isset($properties[
'time_created'])) {
399 if (empty($properties[
'title'])) {
400 $properties[
'title'] = $this->
faker()->sentence();
403 if (empty($properties[
'description'])) {
404 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
407 if (empty($properties[
'subtype'])) {
411 if (empty($properties[
'tags'])) {
412 $properties[
'tags'] = $this->
faker()->words(10);
415 if (!isset($properties[
'owner_guid'])) {
425 $properties[
'owner_guid'] =
$user->guid;
432 if (!isset($properties[
'container_guid'])) {
433 $properties[
'container_guid'] = $properties[
'owner_guid'];
440 if (!isset($properties[
'access_id'])) {
473 $type_str =
elgg_echo(
"item:object:{$object->getSubtype()}");
475 $this->
log(
"Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
490 throw new MaxAttemptsException(
"Unable to create an object after {$attempts} seeding attempts");
518 public function getRandomUser(array $exclude = [],
bool $allow_create =
true) {
526 'metadata_names' => [
'__faker'],
542 $profile_fields_config =
_elgg_services()->fields->get(
'user',
'user');
543 $profile_fields = [];
544 foreach ($profile_fields_config as
$field) {
545 $profile_fields[$field[
'name']] = $field[
'#type'];
550 'profile_fields' => $profile_fields,
571 'metadata_names' => [
'__faker'],
581 if (!empty($groups)) {
586 $profile_fields_config =
_elgg_services()->fields->get(
'group',
'group');
587 $profile_fields = [];
588 foreach ($profile_fields_config as
$field) {
589 $profile_fields[$field[
'name']] = $field[
'#type'];
598 '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)) {
782 $icon_location = $this->
faker()->image();
783 if (empty($icon_location)) {
790 $since = $this->create_since;
794 'view' =>
'river/user/default/profileiconupdate',
795 'action_type' =>
'update',
796 'subject_guid' => $entity->guid,
797 'object_guid' => $entity->guid,
798 'posted' => $this->getRandomCreationTimestamp(),
801 $this->create_since = $since;
825 $since = $this->create_since;
831 $comment->container_guid = $entity->guid;
841 $this->create_since = $since;
864 while ($success <
$limit) {
865 if ($entity->
annotate(
'likes',
true, $entity->access_id, $this->getRandomUser()->guid)) {
883 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.
$params
Saves global plugin settings.
get_user($guid)
Get a user object from a GUID.
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
trait TimeHelpers
Trait to add time helpers.
createUser(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake user.
getRandomCreationTimestamp()
Get a random timestamp between a lower and upper time.
createLikes(\ElggEntity $entity, $limit=null)
Create likes.
Database abstraction query builder.
elgg_entity_exists($guid)
Does an entity exist?
Could not register a new user for whatever reason.
if($pagination &&($position== 'after'||$position== 'both')) $limit
elgg_create_river_item(array $options=[])
Elgg river.
elgg_strtolower()
Wrapper function for mb_strtolower().
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
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
const ELGG_IGNORE_ACCESS
elgg_call() flags
if(!$entity instanceof\ElggUser) $fields
trait GroupHelpers
Group helpers for seeding.
const ELGG_SHOW_DISABLED_ENTITIES
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.
elgg_get_entity_class($type, $subtype)
Return the class name registered as a constructor for an entity of a given type and subtype...
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.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
createIcon(\ElggEntity $entity)
Create an icon for 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.
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.
createSite(array $attributes=[], array $metadata=[])
Create a new fake site.
annotate($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type="")
Adds an annotation to an entity.
_elgg_services()
Get the global service provider.
faker($locale= 'en_US')
Returns an instance of faker.
getRandomAccessId(\ElggUser $user=null,\ElggEntity $container=null)
Get random access id.
$attributes
Elgg AJAX loader.
getRandomGroupMembership()
Returns random membership mode.
getEmailDomain()
Get valid domain for emails.
createObject(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake object.
getRandomGroup(array $exclude=[], bool $allow_create=true)
Returns random fake group.
get_entity($guid)
Loads and returns an entity object from a guid.
createGroup(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake group.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=[])
Saves icons using a local file as the source.
populateMetadata(\ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.