Elgg  Version master
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'), \Psr\Log\LogLevel::ERROR);
36  return self::FAILURE;
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(), \Psr\Log\LogLevel::ERROR);
51  return $e->getCode() ?: 3;
52  }
53 
54  return self::SUCCESS;
55  }
56 }
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
Abstract command with some utility methods.
Definition: Command.php:12
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
option($name)
Returns option value.