ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilLDAPCronSynchronization Class Reference
+ Inheritance diagram for ilLDAPCronSynchronization:
+ Collaboration diagram for ilLDAPCronSynchronization:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 
 hasFlexibleSchedule ()
 
 run ()
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?CronJobScheduleType $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?CronJobScheduleType $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Private Member Functions

 deactivateUsers (ilLDAPServer $server, array $a_ldap_users)
 Deactivate users that are disabled in LDAP. More...
 

Private Attributes

ilLanguage $lng
 
ilLogger $logger
 
ilCronManager $cronManager
 
int $counter = 0
 

Additional Inherited Members

- Protected Attributes inherited from ilCronJob
CronJobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilLDAPCronSynchronization::__construct ( )

Definition at line 35 of file class.ilLDAPCronSynchronization.php.

References $DIC, ILIAS\Repository\lng(), and ILIAS\Repository\logger().

36  {
37  global $DIC;
38 
39  $this->logger = $DIC->logger()->auth();
40  $this->cronManager = $DIC->cron()->manager();
41  $this->lng = $DIC->language();
42  $this->lng->loadLanguageModule('ldap');
43  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addToExternalSettingsForm()

ilLDAPCronSynchronization::addToExternalSettingsForm ( int  $a_form_id,
array &  $a_fields,
bool  $a_is_active 
)

Definition at line 162 of file class.ilLDAPCronSynchronization.php.

References ilAdministrationSettingsFormHandler\FORM_LDAP, ILIAS\Repository\lng(), and ilAdministrationSettingsFormHandler\VALUE_BOOL.

162  : void
163  {
165  $a_fields["ldap_user_sync_cron"] = [$a_is_active ?
166  $this->lng->txt("enabled") :
167  $this->lng->txt("disabled"),
169  }
170  }
+ Here is the call graph for this function:

◆ deactivateUsers()

ilLDAPCronSynchronization::deactivateUsers ( ilLDAPServer  $server,
array  $a_ldap_users 
)
private

Deactivate users that are disabled in LDAP.

Definition at line 143 of file class.ilLDAPCronSynchronization.php.

References ilObjUser\_getExternalAccountsByAuthMode(), ilObjUser\_toggleActiveStatusOfUsers(), ilLDAPServer\getAuthenticationMappingKey(), and ILIAS\Repository\logger().

Referenced by run().

143  : void
144  {
145  $inactive = [];
146 
147  foreach (ilObjUser::_getExternalAccountsByAuthMode($server->getAuthenticationMappingKey(), true) as $usr_id => $external_account) {
148  if (!array_key_exists($external_account, $a_ldap_users)) {
149  $inactive[] = $usr_id;
150  }
151  }
152  if (count($inactive)) {
153  ilObjUser::_toggleActiveStatusOfUsers($inactive, false);
154  $this->logger->info('LDAP: Found ' . count($inactive) . ' inactive users.');
155 
156  $this->counter++;
157  } else {
158  $this->logger->info('LDAP: No inactive users found');
159  }
160  }
static _getExternalAccountsByAuthMode(string $a_auth_mode, bool $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
static _toggleActiveStatusOfUsers(array $a_usr_ids, bool $a_status)
getAuthenticationMappingKey()
Get authentication mapping key Default is ldap.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilLDAPCronSynchronization::getDefaultScheduleType ( )

Definition at line 60 of file class.ilLDAPCronSynchronization.php.

61  {
62  return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
63  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ getDefaultScheduleValue()

ilLDAPCronSynchronization::getDefaultScheduleValue ( )

Definition at line 65 of file class.ilLDAPCronSynchronization.php.

65  : ?int
66  {
67  return null;
68  }

◆ getDescription()

ilLDAPCronSynchronization::getDescription ( )

Definition at line 55 of file class.ilLDAPCronSynchronization.php.

References ILIAS\Repository\lng().

55  : string
56  {
57  return $this->lng->txt("ldap_user_sync_cron_info");
58  }
+ Here is the call graph for this function:

◆ getId()

ilLDAPCronSynchronization::getId ( )

Definition at line 45 of file class.ilLDAPCronSynchronization.php.

Referenced by run().

45  : string
46  {
47  return "ldap_sync";
48  }
+ Here is the caller graph for this function:

◆ getTitle()

ilLDAPCronSynchronization::getTitle ( )

Definition at line 50 of file class.ilLDAPCronSynchronization.php.

References ILIAS\Repository\lng().

50  : string
51  {
52  return $this->lng->txt('ldap_user_sync_cron');
53  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilLDAPCronSynchronization::hasAutoActivation ( )

Definition at line 70 of file class.ilLDAPCronSynchronization.php.

70  : bool
71  {
72  return false;
73  }

◆ hasFlexibleSchedule()

ilLDAPCronSynchronization::hasFlexibleSchedule ( )

Definition at line 75 of file class.ilLDAPCronSynchronization.php.

75  : bool
76  {
77  return false;
78  }

◆ run()

ilLDAPCronSynchronization::run ( )

Definition at line 80 of file class.ilLDAPCronSynchronization.php.

References $messages, ilLDAPServer\_getCronServerIds(), ilUserCreationContext\CONTEXT_LDAP, deactivateUsers(), getId(), ilUserCreationContext\getInstance(), ILIAS\Repository\logger(), ilCronJobResult\STATUS_NO_ACTION, and ilCronJobResult\STATUS_OK.

81  {
83 
84  $messages = array();
85  foreach (ilLDAPServer::_getCronServerIds() as $server_id) {
86  try {
87  $current_server = new ilLDAPServer($server_id);
88  $current_server->doConnectionCheck();
89  $this->logger->info("LDAP: starting user synchronization for " . $current_server->getName());
90 
91  $ldap_query = new ilLDAPQuery($current_server);
92  $ldap_query->bind();
93 
94  if (is_array($users = $ldap_query->fetchUsers())) {
95  // Deactivate ldap users that are not in the list
96  $this->deactivateUsers($current_server, $users);
97  }
98 
99  if (count($users)) {
101 
102  $offset = 0;
103  $limit = 500;
104  while ($user_sliced = array_slice($users, $offset, $limit, true)) {
105  $this->logger->info("LDAP: Starting update/creation of users ...");
106  $this->logger->info("LDAP: Offset: " . $offset);
107  $ldap_to_ilias = new ilLDAPAttributeToUser($current_server);
108  $ldap_to_ilias->setNewUserAuthMode($current_server->getAuthenticationMappingKey());
109  $ldap_to_ilias->setUserData($user_sliced);
110  $ldap_to_ilias->refresh();
111  $this->logger->info("LDAP: Finished update/creation");
112 
113  $offset += $limit;
114 
115  $this->cronManager->ping($this->getId());
116  }
117  $this->counter++;
118  } else {
119  $this->logger->info("LDAP: No users for update/create. Aborting.");
120  }
121  } catch (ilLDAPQueryException $exc) {
122  $mess = $exc->getMessage();
123  $this->logger->info($mess);
124 
125  $messages[] = $mess;
126  }
127  }
128 
129  if ($this->counter) {
130  $status = ilCronJobResult::STATUS_OK;
131  }
132  $result = new ilCronJobResult();
133  if (count($messages)) {
134  $result->setMessage(implode("\n", $messages));
135  }
136  $result->setStatus($status);
137  return $result;
138  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
final const STATUS_NO_ACTION
static _getCronServerIds()
Get list of acticve servers with option 'SyncCron'.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deactivateUsers(ilLDAPServer $server, array $a_ldap_users)
Deactivate users that are disabled in LDAP.
+ Here is the call graph for this function:

Field Documentation

◆ $counter

int ilLDAPCronSynchronization::$counter = 0
private

Definition at line 33 of file class.ilLDAPCronSynchronization.php.

◆ $cronManager

ilCronManager ilLDAPCronSynchronization::$cronManager
private

Definition at line 31 of file class.ilLDAPCronSynchronization.php.

◆ $lng

ilLanguage ilLDAPCronSynchronization::$lng
private

Definition at line 29 of file class.ilLDAPCronSynchronization.php.

◆ $logger

ilLogger ilLDAPCronSynchronization::$logger
private

Definition at line 30 of file class.ilLDAPCronSynchronization.php.


The documentation for this class was generated from the following file: