class SocialProfileFieldsBatch in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.2 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.3 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.4 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.5 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.6 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 8.7 modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 10.3.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 10.0.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 10.1.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
- 10.2.x modules/social_features/social_profile/modules/social_profile_fields/src/SocialProfileFieldsBatch.php \Drupal\social_profile_fields\SocialProfileFieldsBatch
Class SocialProfileFieldsBatch.
Empty profile fields in batch.
@package Drupal\social_profile_fields
Hierarchy
- class \Drupal\social_profile_fields\SocialProfileFieldsBatch
Expanded class hierarchy of SocialProfileFieldsBatch
File
- modules/
social_features/ social_profile/ modules/ social_profile_fields/ src/ SocialProfileFieldsBatch.php, line 16
Namespace
Drupal\social_profile_fieldsView source
class SocialProfileFieldsBatch {
/**
* Perform the flush.
*
* @param array $pids
* Profile id's.
* @param array $fields
* An array of fields to empty.
* @param array $context
* The context of the flush.
*/
public static function performFlush(array $pids, array $fields, array &$context) {
$message = 'Flushing profile data...';
$results = [];
foreach ($pids as $pid) {
$profile = Profile::load($pid);
foreach ($fields as $field_name) {
// Check if the field exists.
if ($profile
->hasField($field_name)) {
// Empty the field.
$profile
->set($field_name, '');
}
}
// Save the profile.
$results[] = $profile
->save();
// Oh and also clear the profile cache while we're at it.
Cache::invalidateTags([
'profile:' . $profile
->id(),
]);
}
$context['message'] = $message;
$context['results'] = $results;
}
/**
* Message when done.
*
* @param bool $success
* If the operation was a success.
* @param array $results
* The amount of items done.
* @param string $operations
* The operation performed.
*/
public static function performFlushFinishedCallback($success, array $results, $operations) {
// The 'success' parameter means no fatal PHP errors were detected. All
// other error management should be handled using 'results'.
if ($success) {
$message = \Drupal::translation()
->formatPlural(count($results), 'One profile flushed.', '@count profiles flushed.');
$indexes = Index::loadMultiple([
'social_all',
'social_users',
]);
/** @var \Drupal\search_api\Entity\Index $index */
foreach ($indexes as $index) {
// If the search index is on and items are not indexed immediately, the
// index also needs to be flushed and re-indexed.
if ($index !== NULL && $index
->status() && !$index
->getOption('index_directly')) {
$index
->clear();
$index
->reindex();
}
}
}
else {
$message = t('Whoops... something went wrong!');
}
drupal_set_message($message);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialProfileFieldsBatch:: |
public static | function | Perform the flush. | |
SocialProfileFieldsBatch:: |
public static | function | Message when done. |