diff --git a/src/Tasks/LDAPGroupSyncTask.php b/src/Tasks/LDAPGroupSyncTask.php index 7f79978..6768acb 100644 --- a/src/Tasks/LDAPGroupSyncTask.php +++ b/src/Tasks/LDAPGroupSyncTask.php @@ -6,6 +6,7 @@ use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; use SilverStripe\Dev\BuildTask; +use SilverStripe\Dev\Deprecation; use SilverStripe\LDAP\Services\LDAPService; use SilverStripe\ORM\DB; use SilverStripe\Security\Group; @@ -84,27 +85,31 @@ public function run($request) $group = new Group(); $group->GUID = $data['objectguid']; - $this->log(sprintf( - 'Creating new Group (GUID: %s, sAMAccountName: %s)', - $data['objectguid'], - $data['samaccountname'] - )); + Deprecation::withNoReplacement(function () use ($data) { + $this->log(sprintf( + 'Creating new Group (GUID: %s, sAMAccountName: %s)', + $data['objectguid'], + $data['samaccountname'] + )); + }); $created++; } else { - $this->log(sprintf( - 'Updating existing Group "%s" (ID: %s, GUID: %s, sAMAccountName: %s)', - $group->getTitle(), - $group->ID, - $data['objectguid'], - $data['samaccountname'] - )); + Deprecation::withNoReplacement(function () use ($group, $data) { + $this->log(sprintf( + 'Updating existing Group "%s" (ID: %s, GUID: %s, sAMAccountName: %s)', + $group->getTitle(), + $group->ID, + $data['objectguid'], + $data['samaccountname'] + )); + }); $updated++; } try { $this->ldapService->updateGroupFromLDAP($group, $data); } catch (Exception $e) { - $this->log($e->getMessage()); + Deprecation::withNoReplacement(fn() => $this->log($e->getMessage())); continue; } } @@ -116,11 +121,13 @@ public function run($request) if (!isset($ldapGroups[$record['GUID']])) { $group = Group::get()->byId($record['ID']); - $this->log(sprintf( - 'Removing Group "%s" (GUID: %s) that no longer exists in LDAP.', - $group->Title, - $group->GUID - )); + Deprecation::withNoReplacement(function () use ($group) { + $this->log(sprintf( + 'Removing Group "%s" (GUID: %s) that no longer exists in LDAP.', + $group->Title, + $group->GUID + )); + }); try { // Cascade into mappings, just to clean up behind ourselves. @@ -129,7 +136,7 @@ public function run($request) } $group->delete(); } catch (Exception $e) { - $this->log($e->getMessage()); + Deprecation::withNoReplacement(fn() => $this->log($e->getMessage())); continue; } @@ -142,22 +149,26 @@ public function run($request) $end = time() - $start; - $this->log(sprintf( - 'Done. Created %s records. Updated %s records. Deleted %s records. Duration: %s seconds', - $created, - $updated, - $deleted, - round($end ?? 0.0, 0) - )); + Deprecation::withNoReplacement(function () use ($created, $updated, $deleted, $end) { + $this->log(sprintf( + 'Done. Created %s records. Updated %s records. Deleted %s records. Duration: %s seconds', + $created, + $updated, + $deleted, + round($end ?? 0.0, 0) + )); + }); } /** * Sends a message, formatted either for the CLI or browser * * @param string $message + * @deprecated 2.3.0 Will be removed without equivalent functionality to replace it */ protected function log($message) { + Deprecation::notice('2.3.0', 'Will be removed without equivalent functionality to replace it'); $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '
'); } diff --git a/src/Tasks/LDAPMemberSyncOneTask.php b/src/Tasks/LDAPMemberSyncOneTask.php index 02ecf8f..a2c0072 100644 --- a/src/Tasks/LDAPMemberSyncOneTask.php +++ b/src/Tasks/LDAPMemberSyncOneTask.php @@ -4,6 +4,7 @@ use Exception; use SilverStripe\Control\HTTPRequest; +use SilverStripe\Dev\Deprecation; use SilverStripe\LDAP\Services\LDAPService; /** @@ -67,13 +68,15 @@ public function run($request) // If member exists already, we're updating - otherwise we're creating if ($member->exists()) { - $this->log(sprintf( - 'Updating existing Member %s: "%s" (ID: %s, SAM Account Name: %s)', - $user['objectguid'], - $member->getName(), - $member->ID, - $user['samaccountname'] - )); + Deprecation::withNoReplacement(function () use ($user, $member) { + $this->log(sprintf( + 'Updating existing Member %s: "%s" (ID: %s, SAM Account Name: %s)', + $user['objectguid'], + $member->getName(), + $member->ID, + $user['samaccountname'] + )); + }); } else { $this->log(sprintf( 'Creating new Member %s: "%s" (SAM Account Name: %s)', @@ -83,14 +86,16 @@ public function run($request) )); } - $this->log('User data returned from LDAP follows:'); - $this->log(var_export($user)); + Deprecation::withNoReplacement(function () use ($user) { + $this->log('User data returned from LDAP follows:'); + $this->log(var_export($user)); + }); try { $this->ldapService->updateMemberFromLDAP($member, $user); - $this->log('Done!'); + Deprecation::withNoReplacement(fn() => $this->log('Done!')); } catch (Exception $e) { - $this->log($e->getMessage()); + Deprecation::withNoReplacement(fn() => $this->log($e->getMessage())); } } diff --git a/src/Tasks/LDAPMemberSyncTask.php b/src/Tasks/LDAPMemberSyncTask.php index a1dbe47..1f9f2f4 100644 --- a/src/Tasks/LDAPMemberSyncTask.php +++ b/src/Tasks/LDAPMemberSyncTask.php @@ -7,6 +7,7 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\BuildTask; +use SilverStripe\Dev\Deprecation; use SilverStripe\LDAP\Services\LDAPService; use SilverStripe\ORM\DB; use SilverStripe\Security\Member; @@ -82,21 +83,25 @@ public function run($request) // If member exists already, we're updating - otherwise we're creating if ($member->exists()) { $updated++; - $this->log(sprintf( - 'Updating existing Member %s: "%s" (ID: %s, SAM Account Name: %s)', - $data['objectguid'], - $member->getName(), - $member->ID, - $data['samaccountname'] - )); + Deprecation::withNoReplacement(function () use ($data, $member) { + $this->log(sprintf( + 'Updating existing Member %s: "%s" (ID: %s, SAM Account Name: %s)', + $data['objectguid'], + $member->getName(), + $member->ID, + $data['samaccountname'] + )); + }); } else { $created++; - $this->log(sprintf( - 'Creating new Member %s: "%s" (SAM Account Name: %s)', - $data['objectguid'], - $data['cn'], - $data['samaccountname'] - )); + Deprecation::withNoReplacement(function () use ($data) { + $this->log(sprintf( + 'Creating new Member %s: "%s" (SAM Account Name: %s)', + $data['objectguid'], + $data['cn'], + $data['samaccountname'] + )); + }); } // Sync attributes from LDAP to the Member record. This will also write the Member record. @@ -104,7 +109,7 @@ public function run($request) try { $this->ldapService->updateMemberFromLDAP($member, $data); } catch (Exception $e) { - $this->log($e->getMessage()); + Deprecation::withNoReplacement(fn() => $this->log($e->getMessage())); continue; } } @@ -116,16 +121,18 @@ public function run($request) $member = Member::get()->byId($record['ID']); if (!isset($users[$record['GUID']])) { - $this->log(sprintf( - 'Removing Member "%s" (GUID: %s) that no longer exists in LDAP.', - $member->getName(), - $member->GUID - )); + Deprecation::withNoReplacement(function () use ($member) { + $this->log(sprintf( + 'Removing Member "%s" (GUID: %s) that no longer exists in LDAP.', + $member->getName(), + $member->GUID + )); + }); try { $member->delete(); } catch (Exception $e) { - $this->log($e->getMessage()); + Deprecation::withNoReplacement(fn() => $this->log($e->getMessage())); continue; } @@ -138,22 +145,26 @@ public function run($request) $end = time() - $start; - $this->log(sprintf( - 'Done. Created %s records. Updated %s records. Deleted %s records. Duration: %s seconds', - $created, - $updated, - $deleted, - round($end ?? 0.0, 0) - )); + Deprecation::withNoReplacement(function () use ($created, $updated, $deleted, $end) { + $this->log(sprintf( + 'Done. Created %s records. Updated %s records. Deleted %s records. Duration: %s seconds', + $created, + $updated, + $deleted, + round($end ?? 0.0, 0) + )); + }); } /** * Sends a message, formatted either for the CLI or browser * * @param string $message + * @deprecated 2.3.0 Will be removed without equivalent functionality to replace it */ protected function log($message) { + Deprecation::notice('2.3.0', 'Will be removed without equivalent functionality to replace it'); $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '
'); } diff --git a/src/Tasks/LDAPMigrateExistingMembersTask.php b/src/Tasks/LDAPMigrateExistingMembersTask.php index d6ad4ca..0a24520 100644 --- a/src/Tasks/LDAPMigrateExistingMembersTask.php +++ b/src/Tasks/LDAPMigrateExistingMembersTask.php @@ -6,6 +6,7 @@ use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Convert; use SilverStripe\Dev\BuildTask; +use SilverStripe\Dev\Deprecation; use SilverStripe\LDAP\Services\LDAPService; use SilverStripe\Security\Member; @@ -73,26 +74,32 @@ public function run($request) $count++; - $this->log(sprintf( - 'Migrated Member %s (ID: %s, Email: %s)', - $member->getName(), - $member->ID, - $member->Email - )); + Deprecation::withNoReplacement(function () use ($member) { + $this->log(sprintf( + 'Migrated Member %s (ID: %s, Email: %s)', + $member->getName(), + $member->ID, + $member->Email + )); + }); } $end = time() - $start; - $this->log(sprintf('Done. Migrated %s Member records. Duration: %s seconds', $count, round($end ?? 0.0, 0))); + Deprecation::withNoReplacement(function () use ($count, $end) { + $this->log(sprintf('Done. Migrated %s Member records. Duration: %s seconds', $count, round($end ?? 0.0, 0))); + }); } /** * Sends a message, formatted either for the CLI or browser * * @param string $message + * @deprecated 2.3.0 Will be removed without equivalent functionality to replace it */ protected function log($message) { + Deprecation::notice('2.3.0', 'Will be removed without equivalent functionality to replace it'); $message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message; echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '
'); }