class UserSyncBatch in CRM Core 8.3
Same name and namespace in other branches
- 8 modules/crm_core_user_sync/src/UserSyncBatch.php \Drupal\crm_core_user_sync\UserSyncBatch
Methods for running the ConfigImporter in a batch.
@package Drupal\crm_core_user_sync
Hierarchy
- class \Drupal\crm_core_user_sync\UserSyncBatch
Expanded class hierarchy of UserSyncBatch
1 file declares its use of UserSyncBatch
- SettingsForm.php in modules/
crm_core_user_sync/ src/ Form/ SettingsForm.php
File
- modules/
crm_core_user_sync/ src/ UserSyncBatch.php, line 10
Namespace
Drupal\crm_core_user_syncView source
class UserSyncBatch {
/**
* Batch operation callback.
*/
public static function progress(&$context) {
$userStorage = \Drupal::entityTypeManager()
->getStorage('user');
if (empty($context['sandbox'])) {
$max = $userStorage
->getQuery()
->condition('uid', 1, '>')
->count()
->execute();
$context['sandbox']['max'] = $max;
$context['sandbox']['progress'] = 0;
$context['results']['synced'] = 0;
$context['sandbox']['last_uid'] = 1;
}
$limit = 20;
$uids = $userStorage
->getQuery()
->sort('uid')
->condition('uid', $context['sandbox']['last_uid'], '>')
->range(0, $limit)
->execute();
$accounts = $userStorage
->loadMultiple($uids);
foreach ($accounts as $account) {
if (\Drupal::service('crm_core_user_sync.relation')
->relate($account)) {
$context['results']['synced']++;
}
$context['sandbox']['last_uid'] = $account
->id();
$context['sandbox']['progress']++;
}
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}
/**
* Batch finished callback.
*/
public static function finished($success, $results, $operations) {
\Drupal::messenger()
->addMessage(t('@count users have been associated with contacts.', [
'@count' => $results['synced'],
]));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserSyncBatch:: |
public static | function | Batch finished callback. | |
UserSyncBatch:: |
public static | function | Batch operation callback. |