Elgg  Version 3.0
DatabaseSeedCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
6 
11 
15  protected function configure() {
16  $this->setName('database:seed')
17  ->addOption('limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of entities to seed')
18  ->addOption('image_folder', null, InputOption::VALUE_OPTIONAL, 'Path to a local folder containing images for seeding')
19  ->setDescription('Seeds the database with fake entities');
20  }
21 
25  protected function command() {
26 
27  if (!class_exists('\Faker\Generator')) {
28  elgg_log('This is a developer tool currently intended for testing purposes only. Please refrain from using it.', 'ERROR');
29 
30  return 1;
31  }
32 
33  set_time_limit(0);
34 
35  if (elgg_is_logged_in()) {
36  elgg_log("Seeds should not be run with a logged in user", 'ERROR');
37 
38  return 2;
39  }
40 
41  _elgg_services()->setValue('mailer', new \Zend\Mail\Transport\InMemory());
42 
43  $limit = $this->option('limit') ? : 20;
44  $image_folder = $this->option('image_folder');
45  if (!empty($image_folder)) {
46  elgg_set_config('seeder_local_image_folder', $image_folder);
47  }
48 
49  try {
50  _elgg_services()->seeder->seed($limit);
51  } catch (\Exception $e) {
52  elgg_log($e->getMessage(), 'ERROR');
53 
54  return $e->getCode() ? : 3;
55  }
56 
57  return 0;
58  }
59 }
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:48
$limit
Definition: userpicker.php:52
elgg_set_config($name, $value)
Set an Elgg configuration value.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:786
Abstract command with some utility methods.
Definition: Command.php:12
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
option($name)
Returns option value.
elgg-cli database:seed [–limit]
Namespace for generating in-memory filesystems.
Definition: InMemory.php:14