Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -6,7 +6,6 @@
*/
use Drupal\node\NodeInterface;
use Drupal\node\Entity\Node;
/**
* Updates all nodes in the passed-in array with the passed-in field values.
@ -34,10 +33,10 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
// We use batch processing to prevent timeout when updating a large number
// of nodes.
if (count($nodes) > 10) {
$batch = array(
'operations' => array(
array('_node_mass_update_batch_process', array($nodes, $updates, $langcode, $load, $revisions))
),
$batch = [
'operations' => [
['_node_mass_update_batch_process', [$nodes, $updates, $langcode, $load, $revisions]]
],
'finished' => '_node_mass_update_batch_finished',
'title' => t('Processing'),
// We use a single multi-pass operation, so the default
@ -47,16 +46,17 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
// The operations do not live in the .module file, so we need to
// tell the batch engine which file to load before calling them.
'file' => drupal_get_path('module', 'node') . '/node.admin.inc',
);
];
batch_set($batch);
}
else {
$storage = \Drupal::entityTypeManager()->getStorage('node');
if ($load && !$revisions) {
$nodes = Node::loadMultiple($nodes);
$nodes = $storage->loadMultiple($nodes);
}
foreach ($nodes as $node) {
if ($load && $revisions) {
$node = entity_revision_load('node', $node);
$node = $storage->loadRevision($node);
}
_node_mass_update_helper($node, $updates, $langcode);
}
@ -81,7 +81,7 @@ function node_mass_update(array $nodes, array $updates, $langcode = NULL, $load
* @see node_mass_update()
*/
function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode = NULL) {
$langcodes = isset($langcode) ? array($langcode) : array_keys($node->getTranslationLanguages());
$langcodes = isset($langcode) ? [$langcode] : array_keys($node->getTranslationLanguages());
// For efficiency manually save the original node before applying any changes.
$node->original = clone $node;
foreach ($langcodes as $langcode) {
@ -111,7 +111,7 @@ function _node_mass_update_helper(NodeInterface $node, array $updates, $langcode
* @param bool $revisions
* (optional) TRUE if $nodes contains an array of revision IDs instead of
* node IDs. Defaults to FALSE; will be ignored if $load is FALSE.
* @param array|\ArrayAccess $context.
* @param array|\ArrayAccess $context
* An array of contextual key/values.
*/
function _node_mass_update_batch_process(array $nodes, array $updates, $langcode, $load, $revisions, &$context) {
@ -122,13 +122,14 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $langcode
}
// Process nodes by groups of 5.
$storage = \Drupal::entityTypeManager()->getStorage('node');
$count = min(5, count($context['sandbox']['nodes']));
for ($i = 1; $i <= $count; $i++) {
// For each nid, load the node, reset the values, and save it.
$node = array_shift($context['sandbox']['nodes']);
if ($load) {
$node = $revisions ?
entity_revision_load('node', $node) : Node::load($node);
$storage->loadRevision($node) : $storage->load($node);
}
$node = _node_mass_update_helper($node, $updates, $langcode);
@ -168,10 +169,10 @@ function _node_mass_update_batch_finished($success, $results, $operations) {
else {
drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
$message = \Drupal::translation()->formatPlural(count($results), '1 item successfully processed:', '@count items successfully processed:');
$item_list = array(
$item_list = [
'#theme' => 'item_list',
'#items' => $results,
);
];
$message .= drupal_render($item_list);
drupal_set_message($message);
}