function _social_post_mass_update_batch_process in Open Social 8.5
Same name and namespace in other branches
- 8.9 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 8.3 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 8.4 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 8.6 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 8.7 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 8.8 modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 10.3.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 10.0.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 10.1.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
- 10.2.x modules/social_features/social_post/social_post.admin.inc \_social_post_mass_update_batch_process()
Implements callback_batch_operation().
Executes a batch operation for social_post_mass_update().
Parameters
array $posts: An array of post IDs.
array $updates: Associative array of updates.
string $langcode: The language updates should be applied to. If none is specified all available languages are processed.
bool $load: TRUE if $posts contains an array of post IDs to be loaded, FALSE if it contains fully loaded posts.
array|\ArrayAccess $context: An array of contextual key/values.
1 string reference to '_social_post_mass_update_batch_process'
- social_post_mass_update in modules/
social_features/ social_post/ social_post.admin.inc - Updates all posts in the passed-in array with the passed-in field values.
File
- modules/
social_features/ social_post/ social_post.admin.inc, line 111 - Helper methods for post administration actions.
Code
function _social_post_mass_update_batch_process(array $posts, array $updates, $langcode, $load, &$context) {
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = count($posts);
$context['sandbox']['posts'] = $posts;
}
// Process posts by groups of 5.
$storage = \Drupal::entityTypeManager()
->getStorage('post');
$count = min(5, count($context['sandbox']['posts']));
for ($i = 1; $i <= $count; $i++) {
// For each nid, load the post, reset the values, and save it.
$post = array_shift($context['sandbox']['posts']);
if ($load) {
$post = $storage
->load($post);
}
$post = _social_post_mass_update_helper($post, $updates, $langcode);
// Store result for post-processing in the finished callback.
$context['results'][] = \Drupal::l($post
->label(), $post
->urlInfo());
// Update our progress information.
$context['sandbox']['progress']++;
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}