Skip to content

Instantly share code, notes, and snippets.

@staabm
Created June 1, 2020 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staabm/76ca687d18d6d668b938bbe4da07cbcf to your computer and use it in GitHub Desktop.
Save staabm/76ca687d18d6d668b938bbe4da07cbcf to your computer and use it in GitHub Desktop.
redaxo example console command
$ git diff --staged
diff --git a/redaxo/src/addons/project/lib/user_export.php b/redaxo/src/addons/project/lib/user_export.php
new file mode 100644
index 000000000..26a85625e
--- /dev/null
+++ b/redaxo/src/addons/project/lib/user_export.php
@@ -0,0 +1,25 @@
+<?php
+
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class rex_project_user_export_command extends rex_console_command {
+ protected function configure()
+ {
+ $this
+ ->setDescription('Export redaxo backend usernames as CSV');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $users = rex_sql::factory();
+ $users->setQuery('SELECT id, login FROM '. rex::getTable('user'));
+ foreach($users as $user) {
+ $output->writeln($user->getValue('id').','. $user->getValue('login'));
+ }
+ $io = $this->getStyle($input, $output);
+
+ $io->success('Successfully exported '. $users->getRows() . ' users.');
+ return 0;
+ }
+}
diff --git a/redaxo/src/addons/project/package.yml b/redaxo/src/addons/project/package.yml
index 48beefbe3..9cfd98fde 100644
--- a/redaxo/src/addons/project/package.yml
+++ b/redaxo/src/addons/project/package.yml
@@ -3,6 +3,9 @@ version: dev
author: Project Admin
supportpage: www.redaxo.org/de/forum/
+console_commands:
+ project:user_export: rex_project_user_export_command
+
# Load project addon late to be sure that
# - all other addons are booted before
# - the fragments from project addon are always "winning" over other fragment dirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment