From 66518ee520fff1c1f440345dfa443e2fb6f1fbb6 Mon Sep 17 00:00:00 2001 From: Moritz Strohm Date: Mon, 13 Nov 2023 09:23:07 +0000 Subject: show "Matrikelnummer" field in admin/user result table, closes #3336 Closes #3336 Merge request studip/studip!2270 --- app/controllers/admin/user.php | 2 +- app/views/admin/user/_results.php | 2 + app/views/admin/user/edit.php | 10 ++++ app/views/profile/index.php | 2 + cli/Commands/Migrate/MigrateMatrikelnummer.php | 66 ++++++++++++++++++++++++ cli/studip | 1 + db/migrations/5.5.6_add_matriculation_number.php | 28 ++++++++++ lib/models/User.class.php | 1 + 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 cli/Commands/Migrate/MigrateMatrikelnummer.php create mode 100644 db/migrations/5.5.6_add_matriculation_number.php diff --git a/app/controllers/admin/user.php b/app/controllers/admin/user.php index 37b8b53..b6a4048 100644 --- a/app/controllers/admin/user.php +++ b/app/controllers/admin/user.php @@ -417,7 +417,7 @@ class Admin_UserController extends AuthenticatedController if (count($editPerms)) { $editUser['auth_user_md5.perms'] = $editPerms[0]; } - foreach (words('Vorname Nachname auth_plugin visible') as $param) { + foreach (['Vorname', 'Nachname', 'matriculation_number', 'auth_plugin', 'visible'] as $param) { if (Request::get($param)) $editUser['auth_user_md5.' . $param] = Request::get($param); } foreach (words('title_front title_rear geschlecht preferred_language') as $param) { diff --git a/app/views/admin/user/_results.php b/app/views/admin/user/_results.php index e41d995..8751436 100644 --- a/app/views/admin/user/_results.php +++ b/app/views/admin/user/_results.php @@ -22,6 +22,7 @@   + > @@ -99,6 +100,7 @@ ?> + matriculation_number) ?> Vorname) ?> nachname) ?> diff --git a/app/views/admin/user/edit.php b/app/views/admin/user/edit.php index 9e1241e..8892d98 100644 --- a/app/views/admin/user/edit.php +++ b/app/views/admin/user/edit.php @@ -204,6 +204,16 @@ use Studip\Button, Studip\LinkButton; +
+ +
+
diff --git a/app/views/profile/index.php b/app/views/profile/index.php index 29f0119..82a001a 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -65,6 +65,8 @@ user_id === $GLOBALS['user']->id) : ?>
:
+
:
+
diff --git a/cli/Commands/Migrate/MigrateMatrikelnummer.php b/cli/Commands/Migrate/MigrateMatrikelnummer.php new file mode 100644 index 0000000..fbad2d8 --- /dev/null +++ b/cli/Commands/Migrate/MigrateMatrikelnummer.php @@ -0,0 +1,66 @@ +setDescription('Migrates the "Matrikelnummer" datafield into the matriculation_number column of the auth_user_md5 table.'); + $this->setHelp('This command migrates the "Matrikelnummer" datafield into the matriculation_number column of the auth_user_md5 table. The ID of the datafield must be provided. The datafield is not deleted in the migration process.'); + $this->addOption('id', 'i', InputOption::VALUE_REQUIRED, 'The ID of the "Matrikelnummer" datafield.', null); + } + + protected function execute(InputInterface $input, OutputInterface $output) : int + { + $datafield_id = $input->getOption('id'); + if (!$datafield_id) { + echo 'No ID for the "Matrikelnummer" datafield has been provided.' . "\n"; + return Command::FAILURE; + } + $datafield = \DataField::find($datafield_id); + if (!$datafield) { + echo 'The datafield could not be found.' . "\n"; + return Command::FAILURE; + } + //Get all entries of the datafield for users and set the + //matriculation_number field: + + $verbose = $input->getOption('verbose'); + + $modifier = function ($entry) use ($verbose) { + if (!$entry->content) { + return; + } + $user = \User::find($entry->range_id); + if (!$user) { + return; + } + $user->matriculation_number = $entry->content; + if ($user->isDirty()) { + $success = $user->store(); + if ($verbose) { + if ($success === false) { + printf('Error updating matriculation number for user %s.', $user->username) . "\n"; + } elseif ($success > 0) { + printf('Matriculation number updated for user %s.', $user->username) . "\n"; + } + } + } + }; + + \DatafieldEntryModel::findEachByDatafield_id( + $modifier, + $datafield->id + ); + + return Command::SUCCESS; + } +} diff --git a/cli/studip b/cli/studip index bef389c..c4addb9 100755 --- a/cli/studip +++ b/cli/studip @@ -38,6 +38,7 @@ $commands = [ Commands\Fix\EndTimeWeeklyRecurredEvents::class, Commands\Fix\IconDimensions::class, Commands\HelpContent\Migrate::class, + Commands\Migrate\MigrateMatrikelnummer::class, Commands\Migrate\MigrateList::class, Commands\Migrate\MigrateStatus::class, Commands\Migrate\Migrate::class, diff --git a/db/migrations/5.5.6_add_matriculation_number.php b/db/migrations/5.5.6_add_matriculation_number.php new file mode 100644 index 0000000..4fa0784 --- /dev/null +++ b/db/migrations/5.5.6_add_matriculation_number.php @@ -0,0 +1,28 @@ +exec( + "ALTER TABLE `auth_user_md5` + ADD COLUMN matriculation_number VARCHAR(255) NULL DEFAULT NULL" + ); + } + + protected function down() + { + $db = DBManager::get(); + $db->exec( + "ALTER TABLE `auth_user_md5` + DROP COLUMN matriculation_number" + ); + } +} diff --git a/lib/models/User.class.php b/lib/models/User.class.php index 627673d..21f8f87 100644 --- a/lib/models/User.class.php +++ b/lib/models/User.class.php @@ -30,6 +30,7 @@ * @property string $vorname database column * @property string $nachname database column * @property string $email database column + * @property string $matriculation_number database column * @property string $validation_key database column * @property string|null $auth_plugin database column * @property int $locked database column -- cgit v1.0