for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Class LDAPMigrateExistingMembersTask
*
* Migrate existing Member records in SilverStripe into "LDAP Members"
* by matching existing emails with ones that exist in AD.
*/
class LDAPMigrateExistingMembersTask extends BuildTask
You can fix this by adding a namespace to your class:
namespace YourVendor; class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.
{
private static $dependencies = [
$dependencies
This check marks private properties in classes that are never used. Those properties can be removed.
'ldapService' => '%$LDAPService'
];
public function run($request)
$users = $this->ldapService->getUsers(['objectguid', 'mail']);
ldapService
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$start = time();
$count = 0;
foreach ($users as $user) {
// Empty mail attribute for the user, nothing we can do. Skip!
if (empty($user['mail'])) {
continue;
}
$member = Member::get()->where(
sprintf('"Email" = \'%s\' AND "GUID" IS NULL', Convert::raw2sql($user['mail']))
)->first();
if (!($member && $member->exists())) {
// Member was found, migrate them by setting the GUID field
$member->GUID = $user['objectguid'];
$member->write();
$count++;
$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)));
protected function log($message)
$message = sprintf('[%s] ', date('Y-m-d H:i:s')) . $message;
echo Director::is_cli() ? ($message . PHP_EOL) : ($message . '<br>');
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.