Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Courses) add cli to reassgin default group to course members as p…
Browse files Browse the repository at this point in the history
…rimarygroup
  • Loading branch information
paulmhh committed Aug 16, 2021
1 parent 22b7604 commit 0461819
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tine20/Courses/Frontend/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,36 @@ class Courses_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
*/
protected $_help = array(
);


public function resetCoursesMembersPrimaryGroups()
{
$this->_checkAdminRight();

$groupCtrl = Tinebase_Group::getInstance();
$defaultGroup = $groupCtrl->getDefaultGroup();
$userCtrl = Tinebase_User::getInstance();

foreach (Courses_Controller_Course::getInstance()->getAll() as $course) {
try {
if (!$course->group_id || $groupCtrl->getGroupById($course->group_id)) {
continue;
}
} catch (Tinebase_Exception_Record_NotDefined $ternd) {
continue;
}

/** @var Tinebase_Model_FullUser $user */
foreach ($userCtrl->getMultiple($groupCtrl->getGroupMembers($course->group_id),
Tinebase_Model_FullUser::class) as $user) {
if ($user->accountPrimaryGroup === $course->group_id) {
$groupCtrl->addGroupMember($defaultGroup->getId(), $user->getId());
$user->accountPrimaryGroup = $defaultGroup->getId();
$userCtrl->updateUser($user);
}
}
}
}

/**
* set all courses to internet = FILTERED
*
Expand Down

0 comments on commit 0461819

Please sign in to comment.