5 * Batch API callbacks for the linkchecker module.
9 * Batch: Scan nodes for links.
11 function _linkchecker_batch_import_nodes($node_types = array()) {
12 // Get all active {node}.nid's.
13 $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));
15 $operations = array();
16 foreach ($result as $row) {
17 $operations[] = array('_linkchecker_batch_node_import_op', array($row->nid));
20 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
21 'finished' => '_linkchecker_batch_node_import_finished',
22 'operations' => $operations,
23 'title' => t('Scanning for links'),
30 * Batch operation: Scan one by one node for links.
32 function _linkchecker_batch_node_import_op($nid, &$context) {
33 // Load the node and scan for links.
34 $node = node_load($nid, NULL, TRUE);
35 _linkchecker_add_node_links($node);
37 // Store results for post-processing in the finished callback.
38 $context['results'][] = $node->nid;
39 $context['message'] = t('Content: @title', array('@title' => $node->title));
43 * Output node batch result messages.
45 * @param bool $success
46 * If scan completed successfully or not.
48 * Number of nodes scanned.
49 * @param array $operations
50 * Array of functions called.
52 function _linkchecker_batch_node_import_finished($success, $results, $operations) {
54 $message = format_plural(count($results), 'One node has been scanned.', '@count nodes have been scanned.');
57 $message = t('Scanning for links in content has failed with an error.');
59 drupal_set_message($message);
63 * Batch: Scan comments for links.
65 function _linkchecker_batch_import_comments($node_types = array()) {
66 // Get all active {comment}.cid's.
67 $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));
69 $operations = array();
70 foreach ($result as $row) {
71 $operations[] = array('_linkchecker_batch_comments_import_op', array($row->cid));
74 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
75 'finished' => '_linkchecker_batch_comments_import_finished',
76 'operations' => $operations,
77 'title' => t('Scanning for links'),
84 * Batch operation: Scan one by one comment for links.
86 function _linkchecker_batch_comments_import_op($cid, &$context) {
87 // Load the comment and scan for links.
88 $comment = comment_load($cid);
89 _linkchecker_add_comment_links($comment);
91 // Store results for post-processing in the finished callback.
92 $context['results'][] = $comment->cid;
93 $context['message'] = t('Comment: @title', array('@title' => $comment->subject));
97 * Output comment batch result messages.
99 * @param bool $success
100 * If scan completed successfully or not.
101 * @param int $results
102 * Number of comments scanned.
103 * @param array $operations
104 * Array of functions called.
106 function _linkchecker_batch_comments_import_finished($success, $results, $operations) {
108 $message = format_plural(count($results), 'One comment has been scanned.', '@count comments have been scanned.');
111 $message = t('Scanning for links in comments have failed with an error.');
113 drupal_set_message($message);
117 * Batch: Scan blocks for links.
119 function _linkchecker_batch_import_block_custom() {
120 // Get all {block_custom}.bid's as block module suxxx and has no usable hooks.
121 $result = db_query('SELECT bid FROM {block_custom} ORDER BY bid');
123 $operations = array();
124 foreach ($result as $row) {
125 $operations[] = array('_linkchecker_batch_import_block_custom_op', array($row->bid));
128 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
129 'finished' => '_linkchecker_batch_block_custom_import_finished',
130 'operations' => $operations,
131 'title' => t('Scanning for links'),
138 * Batch operation: Scan one by one block for links.
140 function _linkchecker_batch_import_block_custom_op($bid, &$context) {
141 // Load the custom block and scan for links.
142 $block_custom = linkchecker_block_custom_block_get($bid);
143 _linkchecker_add_block_custom_links($block_custom, $block_custom->delta);
145 // Store some result for post-processing in the finished callback.
146 $context['results'][] = $block_custom->delta;
147 $context['message'] = t('Block: @title', array('@title' => $block_custom->info));
151 * Output block batch result messages.
153 * @param bool $success
154 * If scan completed successfully or not.
155 * @param int $results
156 * Number of blocks scanned.
157 * @param array $operations
158 * Array of functions called.
160 function _linkchecker_batch_block_custom_import_finished($success, $results, $operations) {
162 $message = format_plural(count($results), 'One block has been scanned.', '@count blocks have been scanned.');
165 $message = t('Scanning for links in blocks have failed with an error.');
167 drupal_set_message($message);
171 * Recurring scans of a single node via batch API.
174 * The unique node id to scan for links.
175 * @param int $missing_links_count
176 * The number of links not yet added to linkchecker_links table. By this
177 * number the re-scan rounds are calulated.
180 * The batch task definition.
182 function _linkchecker_batch_import_single_node($nid, $missing_links_count) {
183 $operations = array();
184 for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
185 $operations[] = array('_linkchecker_batch_single_node_import_op', array($nid));
188 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
189 'finished' => '_linkchecker_batch_single_node_import_finished',
190 'operations' => $operations,
191 'title' => t('Scanning for links'),
192 'progress_message' => t('Remaining @remaining of @total scans.'),
199 * Run single node link extraction.
203 * @param array $context
204 * Batch context array.
206 function _linkchecker_batch_single_node_import_op($nid, &$context) {
207 // Load the node and scan for links.
208 $node = node_load($nid, NULL, TRUE);
209 _linkchecker_add_node_links($node, TRUE);
211 // Store results for post-processing in the finished callback.
212 $context['results'][] = $node->nid;
213 $context['message'] = t('Content: @title', array('@title' => $node->title));
217 * Output single node batch result messages.
219 * @param bool $success
220 * If scan completed successfully or not.
221 * @param int $results
222 * How often the node has been scanned.
223 * @param array $operations
224 * Array of functions called.
226 function _linkchecker_batch_single_node_import_finished($success, $results, $operations) {
228 $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]));
231 $message = t('Recurring scanning for links in node @nid has failed with an error.', array('@nid' => $results[0]));
233 drupal_set_message($message);
237 * Recurring scans of a single comment via batch API.
240 * The unique comment id to scan for links.
241 * @param int $missing_links_count
242 * The number of links not yet added to linkchecker_links table. By this
243 * number the re-scan rounds are calulated.
246 * The batch task definition.
248 function _linkchecker_batch_import_single_comment($cid, $missing_links_count) {
249 $operations = array();
250 for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
251 $operations[] = array('_linkchecker_batch_single_comment_import_op', array($cid));
254 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
255 'finished' => '_linkchecker_batch_single_comment_import_finished',
256 'operations' => $operations,
257 'title' => t('Scanning for links'),
258 'progress_message' => t('Remaining @remaining of @total scans.'),
265 * Run single comment link extraction.
269 * @param array $context
270 * Batch context array.
272 function _linkchecker_batch_single_comment_import_op($cid, &$context) {
273 $comment = comment_load($cid);
274 _linkchecker_add_comment_links($comment, TRUE);
276 // Store results for post-processing in the finished callback.
277 $context['results'][] = $comment->cid;
278 $context['message'] = t('Comment: @title', array('@title' => $comment->subject));
282 * Output single comment batch result messages.
284 * @param bool $success
285 * If scan completed successfully or not.
286 * @param int $results
287 * How often the comment has been scanned.
288 * @param array $operations
289 * Array of functions called.
291 function _linkchecker_batch_single_comment_import_finished($success, $results, $operations) {
293 $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]));
296 $message = t('Recurring scanning for links in comment @cid has failed with an error.', array('@cid' => $results[0]));
298 drupal_set_message($message);
302 * Recurring scans of a single block via batch API.
305 * The unique block id to scan for links.
306 * @param int $missing_links_count
307 * The number of links not yet added to linkchecker_links table. By this
308 * number the re-scan rounds are calulated.
311 * The batch task definition.
313 function _linkchecker_batch_import_single_block_custom($bid, $missing_links_count) {
314 $operations = array();
315 for ($i = 0; $i <= $missing_links_count; $i = $i + LINKCHECKER_SCAN_MAX_LINKS_PER_RUN) {
316 $operations[] = array('_linkchecker_batch_single_block_custom_import_op', array($bid));
319 'file' => drupal_get_path('module', 'linkchecker') . '/linkchecker.batch.inc',
320 'finished' => '_linkchecker_batch_single_block_custom_import_finished',
321 'operations' => $operations,
322 'title' => t('Scanning for links'),
323 'progress_message' => t('Remaining @remaining of @total scans.'),
330 * Run single block link extraction.
334 * @param array $context
335 * Batch context array.
337 function _linkchecker_batch_single_block_custom_import_op($bid, &$context) {
338 // Load the custom block and scan for links.
339 $block_custom = linkchecker_block_custom_block_get($bid);
340 _linkchecker_add_block_custom_links($block_custom, $block_custom->delta, TRUE);
342 // Store some result for post-processing in the finished callback.
343 $context['results'][] = $block_custom->delta;
344 $context['message'] = t('Block: @title', array('@title' => $block_custom->info));
348 * Output single block batch result messages.
350 * @param bool $success
351 * If scan completed successfully or not.
352 * @param int $results
353 * How often the block has been scanned.
354 * @param array $operations
355 * Array of functions called.
357 function _linkchecker_batch_single_block_custom_import_finished($success, $results, $operations) {
359 $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]));
362 $message = t('Recurring scanning for links in block @bid has failed with an error.', array('@bid' => $results[0]));
364 drupal_set_message($message);