Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / linkchecker / linkchecker.batch.inc
index b8af795c9eae9dcce3f42de1e62c667b1b5c8bcb..bc8709c81ce6e1b1f5eb29a8ae9828759e3ac86f 100644 (file)
@@ -5,23 +5,25 @@
  * Batch API callbacks for the linkchecker module.
  */
 
+use \Drupal\node\Entity\Node;
+
 /**
  * Batch: Scan nodes for links.
  */
-function _linkchecker_batch_import_nodes($node_types = array()) {
+function _linkchecker_batch_import_nodes($node_types = []) {
   // Get all active {node}.nid's.
-  $result = db_query('SELECT n.nid FROM {node} n WHERE n.status = :status AND n.type IN (:types) ORDER BY n.nid', array(':status' => 1, ':types' => $node_types));
+  $result = db_query('SELECT n.nid FROM {node} n WHERE n.status = :status AND n.type IN (:types) ORDER BY n.nid', [':status' => 1, ':types' => $node_types]);
 
-  $operations = array();
+  $operations = [];
   foreach ($result as $row) {
-    $operations[] = array('_linkchecker_batch_node_import_op', array($row->nid));
+    $operations[] = ['_linkchecker_batch_node_import_op', [$row->nid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_node_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
-  );
+  ];
 
   return $batch;
 }
@@ -31,12 +33,12 @@ function _linkchecker_batch_import_nodes($node_types = array()) {
  */
 function _linkchecker_batch_node_import_op($nid, &$context) {
   // Load the node and scan for links.
-  $node = node_load($nid, NULL, TRUE);
+  $node = Node::load($nid);
   _linkchecker_add_node_links($node);
 
   // Store results for post-processing in the finished callback.
   $context['results'][] = $node->nid;
-  $context['message'] = t('Content: @title', array('@title' => $node->title));
+  $context['message'] = t('Content: @title', ['@title' => $node->title]);
 }
 
 /**
@@ -49,9 +51,9 @@ function _linkchecker_batch_node_import_op($nid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_node_import_finished($success, $results, $operations) {
+function _linkchecker_batch_node_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'One node has been scanned.', '@count nodes have been scanned.');
+    $message = \Drupal::translation()->formatPlural(count($results), 'One node has been scanned.', '@count nodes have been scanned.');
   }
   else {
     $message = t('Scanning for links in content has failed with an error.');
@@ -62,20 +64,20 @@ function _linkchecker_batch_node_import_finished($success, $results, $operations
 /**
  * Batch: Scan comments for links.
  */
-function _linkchecker_batch_import_comments($node_types = array()) {
+function _linkchecker_batch_import_comments($node_types = []) {
   // Get all active {comment}.cid's.
-  $result = db_query('SELECT c.cid FROM {comment} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = :cstatus AND n.status = :nstatus AND n.type IN (:types) ORDER BY c.cid', array(':cstatus' => COMMENT_PUBLISHED, ':nstatus' => 1, ':types' => $node_types));
+  $result = db_query('SELECT c.cid FROM {comment} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = :cstatus AND n.status = :nstatus AND n.type IN (:types) ORDER BY c.cid', [':cstatus' => COMMENT_PUBLISHED, ':nstatus' => 1, ':types' => $node_types]);
 
-  $operations = array();
+  $operations = [];
   foreach ($result as $row) {
-    $operations[] = array('_linkchecker_batch_comments_import_op', array($row->cid));
+    $operations[] = ['_linkchecker_batch_comments_import_op', [$row->cid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_comments_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
-  );
+  ];
 
   return $batch;
 }
@@ -90,7 +92,7 @@ function _linkchecker_batch_comments_import_op($cid, &$context) {
 
   // Store results for post-processing in the finished callback.
   $context['results'][] = $comment->cid;
-  $context['message'] = t('Comment: @title', array('@title' => $comment->subject));
+  $context['message'] = t('Comment: @title', ['@title' => $comment->subject]);
 }
 
 /**
@@ -103,9 +105,9 @@ function _linkchecker_batch_comments_import_op($cid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_comments_import_finished($success, $results, $operations) {
+function _linkchecker_batch_comments_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'One comment has been scanned.', '@count comments have been scanned.');
+    $message = \Drupal::translation()->formatPlural(count($results), 'One comment has been scanned.', '@count comments have been scanned.');
   }
   else {
     $message = t('Scanning for links in comments have failed with an error.');
@@ -120,16 +122,16 @@ function _linkchecker_batch_import_block_custom() {
   // Get all {block_custom}.bid's as block module suxxx and has no usable hooks.
   $result = db_query('SELECT bid FROM {block_custom} ORDER BY bid');
 
-  $operations = array();
+  $operations = [];
   foreach ($result as $row) {
-    $operations[] = array('_linkchecker_batch_import_block_custom_op', array($row->bid));
+    $operations[] = ['_linkchecker_batch_import_block_custom_op', [$row->bid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_block_custom_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
-  );
+  ];
 
   return $batch;
 }
@@ -144,7 +146,7 @@ function _linkchecker_batch_import_block_custom_op($bid, &$context) {
 
   // Store some result for post-processing in the finished callback.
   $context['results'][] = $block_custom->delta;
-  $context['message'] = t('Block: @title', array('@title' => $block_custom->info));
+  $context['message'] = t('Block: @title', ['@title' => $block_custom->info]);
 }
 
 /**
@@ -157,9 +159,9 @@ function _linkchecker_batch_import_block_custom_op($bid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_block_custom_import_finished($success, $results, $operations) {
+function _linkchecker_batch_block_custom_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'One block has been scanned.', '@count blocks have been scanned.');
+    $message = \Drupal::translation()->formatPlural(count($results), 'One block has been scanned.', '@count blocks have been scanned.');
   }
   else {
     $message = t('Scanning for links in blocks have failed with an error.');
@@ -180,17 +182,17 @@ function _linkchecker_batch_block_custom_import_finished($success, $results, $op
  *   The batch task definition.
  */
 function _linkchecker_batch_import_single_node($nid, $missing_links_count) {
-  $operations = array();
+  $operations = [];
   for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
-    $operations[] = array('_linkchecker_batch_single_node_import_op', array($nid));
+    $operations[] = ['_linkchecker_batch_single_node_import_op', [$nid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_single_node_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
     'progress_message' => t('Remaining @remaining of @total scans.'),
-  );
+  ];
 
   return $batch;
 }
@@ -203,14 +205,14 @@ function _linkchecker_batch_import_single_node($nid, $missing_links_count) {
  * @param array $context
  *   Batch context array.
  */
-function _linkchecker_batch_single_node_import_op($nid, &$context) {
+function _linkchecker_batch_single_node_import_op($nid, array &$context) {
   // Load the node and scan for links.
   $node = node_load($nid, NULL, TRUE);
   _linkchecker_add_node_links($node, TRUE);
 
   // Store results for post-processing in the finished callback.
   $context['results'][] = $node->nid;
-  $context['message'] = t('Content: @title', array('@title' => $node->title));
+  $context['message'] = t('Content: @title', ['@title' => $node->title]);
 }
 
 /**
@@ -223,12 +225,12 @@ function _linkchecker_batch_single_node_import_op($nid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_single_node_import_finished($success, $results, $operations) {
+function _linkchecker_batch_single_node_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'Node @nid has been re-scanned once to collect all links.', 'Node @nid has been re-scanned @count times to collect all links.', array('@nid' => $results[0]));
+    $message = \Drupal::translation()->formatPlural(count($results), 'Node @nid has been re-scanned once to collect all links.', 'Node @nid has been re-scanned @count times to collect all links.', ['@nid' => $results[0]]);
   }
   else {
-    $message = t('Recurring scanning for links in node @nid has failed with an error.', array('@nid' => $results[0]));
+    $message = t('Recurring scanning for links in node @nid has failed with an error.', ['@nid' => $results[0]]);
   }
   drupal_set_message($message);
 }
@@ -246,17 +248,17 @@ function _linkchecker_batch_single_node_import_finished($success, $results, $ope
  *   The batch task definition.
  */
 function _linkchecker_batch_import_single_comment($cid, $missing_links_count) {
-  $operations = array();
+  $operations = [];
   for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
-    $operations[] = array('_linkchecker_batch_single_comment_import_op', array($cid));
+    $operations[] = ['_linkchecker_batch_single_comment_import_op', [$cid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_single_comment_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
     'progress_message' => t('Remaining @remaining of @total scans.'),
-  );
+  ];
 
   return $batch;
 }
@@ -269,13 +271,13 @@ function _linkchecker_batch_import_single_comment($cid, $missing_links_count) {
  * @param array $context
  *   Batch context array.
  */
-function _linkchecker_batch_single_comment_import_op($cid, &$context) {
+function _linkchecker_batch_single_comment_import_op($cid, array &$context) {
   $comment = comment_load($cid);
   _linkchecker_add_comment_links($comment, TRUE);
 
   // Store results for post-processing in the finished callback.
   $context['results'][] = $comment->cid;
-  $context['message'] = t('Comment: @title', array('@title' => $comment->subject));
+  $context['message'] = t('Comment: @title', ['@title' => $comment->subject]);
 }
 
 /**
@@ -288,12 +290,12 @@ function _linkchecker_batch_single_comment_import_op($cid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_single_comment_import_finished($success, $results, $operations) {
+function _linkchecker_batch_single_comment_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'Comment @cid has been re-scanned once to collect all links.', 'Comment @cid has been re-scanned @count times to collect all links.', array('@cid' => $results[0]));
+    $message = \Drupal::translation()->formatPlural(count($results), 'Comment @cid has been re-scanned once to collect all links.', 'Comment @cid has been re-scanned @count times to collect all links.', ['@cid' => $results[0]]);
   }
   else {
-    $message = t('Recurring scanning for links in comment @cid has failed with an error.', array('@cid' => $results[0]));
+    $message = t('Recurring scanning for links in comment @cid has failed with an error.', ['@cid' => $results[0]]);
   }
   drupal_set_message($message);
 }
@@ -311,17 +313,17 @@ function _linkchecker_batch_single_comment_import_finished($success, $results, $
  *   The batch task definition.
  */
 function _linkchecker_batch_import_single_block_custom($bid, $missing_links_count) {
-  $operations = array();
+  $operations = [];
   for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
-    $operations[] = array('_linkchecker_batch_single_block_custom_import_op', array($bid));
+    $operations[] = ['_linkchecker_batch_single_block_custom_import_op', [$bid]];
   }
-  $batch = array(
+  $batch = [
     'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
     'finished' => '_linkchecker_batch_single_block_custom_import_finished',
     'operations' => $operations,
     'title' => t('Scanning for links'),
     'progress_message' => t('Remaining @remaining of @total scans.'),
-  );
+  ];
 
   return $batch;
 }
@@ -334,14 +336,14 @@ function _linkchecker_batch_import_single_block_custom($bid, $missing_links_coun
  * @param array $context
  *   Batch context array.
  */
-function _linkchecker_batch_single_block_custom_import_op($bid, &$context) {
+function _linkchecker_batch_single_block_custom_import_op($bid, array &$context) {
   // Load the custom block and scan for links.
   $block_custom = linkchecker_block_custom_block_get($bid);
   _linkchecker_add_block_custom_links($block_custom, $block_custom->delta, TRUE);
 
   // Store some result for post-processing in the finished callback.
   $context['results'][] = $block_custom->delta;
-  $context['message'] = t('Block: @title', array('@title' => $block_custom->info));
+  $context['message'] = t('Block: @title', ['@title' => $block_custom->info]);
 }
 
 /**
@@ -354,12 +356,12 @@ function _linkchecker_batch_single_block_custom_import_op($bid, &$context) {
  * @param array $operations
  *   Array of functions called.
  */
-function _linkchecker_batch_single_block_custom_import_finished($success, $results, $operations) {
+function _linkchecker_batch_single_block_custom_import_finished($success, $results, array $operations) {
   if ($success) {
-    $message = format_plural(count($results), 'Block @bid has been re-scanned once to collect all links.', 'Block @bid has been re-scanned @count times to collect all links.', array('@bid' => $results[0]));
+    $message = \Drupal::translation()->formatPlural(count($results), 'Block @bid has been re-scanned once to collect all links.', 'Block @bid has been re-scanned @count times to collect all links.', ['@bid' => $results[0]]);
   }
   else {
-    $message = t('Recurring scanning for links in block @bid has failed with an error.', array('@bid' => $results[0]));
+    $message = t('Recurring scanning for links in block @bid has failed with an error.', ['@bid' => $results[0]]);
   }
   drupal_set_message($message);
 }