diff --git a/app/controllers/admin/user.php b/app/controllers/admin/user.php index 37b8b532f040e3bab56d20f73f838e54e7f998e9..b6a40486eab5c094ff86cd2ce996d80eec5d4ed3 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 e41d995ead28a505fa526a17ff4d69b3c2328890..8751436164cf4e0e87af5d68590498968d69a730 100644 --- a/app/views/admin/user/_results.php +++ b/app/views/admin/user/_results.php @@ -22,6 +22,7 @@ </a> </th> <th> </th> + <th><?= _('Matrikelnummer') ?></th> <th <?= $sortby === 'perms' ? 'class="sort' . $order . '"' : '' ?>> <a href="<?= $controller->link_for('admin/user',['sortby' =>'perms', 'order'=> $order ,'toggle' => $sortby === 'perms']) ?>"> <?= _('Status') ?> @@ -99,6 +100,7 @@ ?> <?= tooltipHtmlIcon(htmlReady($tooltxt, true, true)) ?> </td> + <td><?= htmlReady($user->matriculation_number) ?></td> <td><?= $user['perms'] ?></td> <td><?= htmlReady($user->Vorname) ?></td> <td><?= htmlReady($user->nachname) ?></td> diff --git a/app/views/admin/user/edit.php b/app/views/admin/user/edit.php index 9e1241eb449f9c7f8695918eb8a985ad4f76953e..8892d983176a2199ad45c1a2f34064fa72fde0c0 100644 --- a/app/views/admin/user/edit.php +++ b/app/views/admin/user/edit.php @@ -204,6 +204,16 @@ use Studip\Button, Studip\LinkButton; </div> </section> + <section> + <label> + <?= _('Matrikelnummer') ?> + <input class="user_form" type="text" id="matriculation_number" + value="<?= htmlReady($user->matriculation_number) ?>" + <?= StudipAuthAbstract::CheckField('auth_user_md5.matriculation_number', $user->auth_plugin) + || LockRules::check($user->user_id, 'matriculation_number') ? 'readonly' : 'name="matriculation_number"' ?>> + </label> + </section> + <? if (!empty($user_roles)) : ?> <section> diff --git a/app/views/profile/index.php b/app/views/profile/index.php index 29f01197d20ca0371bbcc48cfb35c16a11081284..82a001a48af2c443c14e3a2e9d29858716ad2eae 100644 --- a/app/views/profile/index.php +++ b/app/views/profile/index.php @@ -65,6 +65,8 @@ <? if ($current_user->user_id === $GLOBALS['user']->id) : ?> <dt><?= _('Status') ?>:</dt> <dd><?= htmlReady(ucfirst($current_user['perms'])) ?></dd> + <dt><?= _('Matrikelnummer') ?>:</dt> + <dd><?= htmlReady($current_user['matriculation_number']) ?></dd> <? endif ?> <? if (!empty($shortDatafields)) : ?> diff --git a/cli/Commands/Migrate/MigrateMatrikelnummer.php b/cli/Commands/Migrate/MigrateMatrikelnummer.php new file mode 100644 index 0000000000000000000000000000000000000000..fbad2d8c21233da577c1b5121d5c532d73997dfc --- /dev/null +++ b/cli/Commands/Migrate/MigrateMatrikelnummer.php @@ -0,0 +1,66 @@ +<?php + +namespace Studip\Cli\Commands\Migrate; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class MigrateMatrikelnummer extends Command +{ + protected static $defaultName = 'migrate:matrikelnummer'; + + protected function configure() : void + { + $this->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 bef389ccd7c02fd756b85d48683aa53219e9d2c7..c4addb93b93b92a9d9cc08d011df5acb0c7eeddb 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 0000000000000000000000000000000000000000..4fa078459d9bfd953ac865649e81a41b1bffd592 --- /dev/null +++ b/db/migrations/5.5.6_add_matriculation_number.php @@ -0,0 +1,28 @@ +<?php + + +class AddMatriculationNumber extends Migration +{ + public function description() + { + return 'Add auth_user_md5.matriculation_number'; + } + + protected function up() + { + $db = DBManager::get(); + $db->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 627673d65b6d41c70773808e6251dabf0e19dfc4..21f8f873b1b14f2944e383b08dde3059d234fcf6 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