Elgg  Version 4.3
DatabaseUnseedCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
6 
11 
15  protected function configure() {
16  $seeders = _elgg_services()->seeder->getSeederClasses();
17  $types = [];
18  foreach ($seeders as $seed) {
19  $types[] = $seed::getType();
20  }
21 
22  $this->setName('database:unseed')
23  ->setDescription(elgg_echo('cli:database:unseed:description'))
24  ->addOption('type', 't', InputOption::VALUE_OPTIONAL,
25  elgg_echo('cli:database:seed:option:type', [implode('|', $types)])
26  );
27  }
28 
32  protected function command() {
33 
34  if (!class_exists('\Faker\Generator')) {
35  elgg_log(elgg_echo('cli:database:seed:log:error:faker'), 'ERROR');
36  return 1;
37  }
38 
39  set_time_limit(0);
40 
41  _elgg_services()->set('mailer', new \Laminas\Mail\Transport\InMemory());
42 
43  $options = [
44  'type' => $this->option('type'),
45  ];
46 
47  try {
48  _elgg_services()->seeder->unseed($options);
49  } catch (\Exception $e) {
50  elgg_log($e->getMessage(), 'ERROR');
51  return $e->getCode() ? : 3;
52  }
53 
54  return 0;
55  }
56 }
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$options
Elgg admin footer.
Definition: footer.php:6
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
Abstract command with some utility methods.
Definition: Command.php:12
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
option($name)
Returns option value.
Namespace for generating in-memory filesystems.
Definition: InMemory.php:14