43 public function faker($locale =
'en_US') {
44 if (!isset($this->
faker)) {
45 $this->
faker = Factory::create($locale);
68 $email =
"noreply@{$this->getDomain()}";
73 if (
sizeof(explode(
'.',
$domain)) <= 1) {
85 return substr(sha1(microtime() . rand()), 0, 25);
129 throw new Exception(
"Unable to create new user with attributes: " . print_r(
$attributes,
true));
136 $user->removeAdmin();
142 $user->ban(
'Banned by seeder');
155 $user->setValidationStatus($this->
faker()->
boolean(),
'seeder');
157 $user->setNotificationSetting(
'email',
false);
158 $user->setNotificationSetting(
'site',
true);
165 $this->
log(
"Created new user {$user->getDisplayName()} [guid: {$user->guid}]");
174 $this->
log(
"User creation failed with message {$e->getMessage()} [attributes: $attr_log]");
212 $properties[
'__faker'] =
true;
214 if (!isset($properties[
'access_id'])) {
218 if (!isset($properties[
'content_access_mode'])) {
222 if (!isset($properties[
'membership'])) {
226 if (empty($properties[
'name'])) {
227 $properties[
'name'] = $this->
faker()->sentence();
230 if (empty($properties[
'description'])) {
231 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
234 if (!isset($properties[
'owner_guid'])) {
240 $properties[
'owner_guid'] =
$user->guid;
243 if (!isset($properties[
'container_guid'])) {
244 $properties[
'container_guid'] = $properties[
'owner_guid'];
247 if (empty($properties[
'subtype'])) {
248 $properties[
'subtype'] =
'group';
264 foreach ($tool_options as $group_option) {
265 $prop_name = $group_option->mapMetadataName();
266 $prop_value = $group_option->mapMetadataValue();
267 $properties[$prop_name] = $prop_value;
270 if ($this->
faker()->
boolean(20)) {
271 $properties[
'featured_group'] =
'yes';
285 $acl = $group->getOwnedAccessCollection(
'group_acl');
287 $group->access_id = $acl->id;
292 $group->join(
get_entity($properties[
'owner_guid']));
295 'view' =>
'river/group/create',
296 'action_type' =>
'create',
297 'subject_guid' =>
$owner->guid,
298 'object_guid' => $group->guid,
302 $this->
log(
"Created new group {$group->getDisplayName()} [guid: {$group->guid}]");
334 $properties[
'__faker'] =
true;
336 if (empty($properties[
'title'])) {
337 $properties[
'title'] = $this->
faker()->sentence();
340 if (empty($properties[
'description'])) {
341 $properties[
'description'] = $this->
faker()->text($this->
faker()->numberBetween(500, 1000));
344 if (empty($properties[
'subtype'])) {
348 if (empty($properties[
'tags'])) {
349 $properties[
'tags'] = $this->
faker()->words(10);
352 if (!isset($properties[
'container_guid'])) {
353 if (isset($properties[
'owner_guid'])) {
354 $properties[
'container_guid'] = $properties[
'owner_guid'];
361 $properties[
'container_guid'] =
$container->guid;
370 if (!isset($properties[
'owner_guid'])) {
372 $properties[
'owner_guid'] =
$owner->guid;
380 if (!isset($properties[
'access_id'])) {
402 $type_str =
elgg_echo(
"item:object:{$object->getSubtype()}");
404 $this->
log(
"Created new item in {$type_str} {$object->getDisplayName()} [guid: {$object->guid}]");
448 'metadata_names' => [
'__faker'],
458 return $users ? $users[0] :
false;
474 'metadata_names' => [
'__faker'],
484 return $groups ? $groups[0] :
false;
503 $access_key = array_rand($access_array, 1);
505 return $access_array[$access_key];
517 $make =
function(
$name = null) {
519 return strtolower($this->
faker()->firstName .
'.' . $this->
faker()->lastName);
522 return implode(
'.', preg_split(
'/\W/',
$name));
550 $make =
function($base = null) {
555 $validate =
function(
$email) {
557 elgg()->accounts->assertValidEmail(
$email,
true);
565 while (!$validate(
$email)) {
648 foreach (
$value as $val) {
668 $icon_location = $this->
faker()->image();
669 if (empty($icon_location)) {
677 'view' =>
'river/user/default/profileiconupdate',
678 'action_type' =>
'update',
679 'subject_guid' => $entity->guid,
680 'object_guid' => $entity->guid,
709 $comment->container_guid = $entity->guid;
742 while ($success <
$limit) {
743 if ($entity->
annotate(
'likes',
true, $entity->access_id, $this->getRandomUser()->guid)) {
762 public function log($msg, $level = LogLevel::NOTICE) {
Provide images from a local folder for seeding.
if(!$item instanceof ElggRiverItem) $object
if(!$user||!$user->canDelete()) $name
log($msg, $level=LogLevel::NOTICE)
Log a message.
getRandomUser(array $exclude=[])
Returns random fake user.
$params
Saves global plugin settings.
get_user($guid)
Get a user object from a GUID.
getRandomSubtype()
Returns random unique subtype.
populateMetadata(ElggEntity $entity, array $fields=[], array $metadata=[])
Set random metadata.
deleteAnnotations($name=null)
Deletes all annotations on this object (annotations.entity_guid = $this->guid).
get_write_access_array($user_guid=0, $ignored=0, $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
const ELGG_VALUE_INTEGER
Value types.
Database abstraction query builder.
createIcon(ElggEntity $entity)
Create an icon for an entity.
$guid
Removes an admin notice.
elgg_create_river_item(array $options=[])
Adds an item to the river.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
createObject(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake object.
faker($locale= 'en_US')
Returns an instance of faker.
getDomain()
Get site domain.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
const CONTENT_ACCESS_MODE_UNRESTRICTED
createUser(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake user.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
elgg_get_entity_class($type, $subtype)
Procedural code for creating, loading, and modifying objects.
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
createComments(ElggEntity $entity, $limit=null)
Create comments/replies.
createGroup(array $attributes=[], array $metadata=[], array $options=[])
Create a new fake group.
getRandomUsername($name=null)
Generates a unique available and valid username.
register_user($username, $password, $name, $email, $allow_multiple_emails=false, $subtype=null)
Registers a user, returning false if the username already exists.
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.
createLikes(ElggEntity $entity, $limit=null)
Create likes.
Extends QueryBuilder with ORDER BY clauses.
getRandomGroup(array $exclude=[])
Returns random fake group.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
generate_random_cleartext_password()
Generate a random 12 character clear text password.
createSite(array $attributes=[], array $metadata=[])
Create a new fake site.
getEmailDomain()
Get valid domain for emails.
getRandomAccessId(\ElggUser $user=null, ElggEntity $container=null)
Get random access id.
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.
getRandomEmail($base=null)
Generate a random valid email.
get_entity($guid)
Loads and returns an entity object from a guid.
saveIconFromLocalFile($filename, $type= 'icon', array $coords=[])
Saves icons using a local file as the source.