Now linkchecker_scan_nodetypes store all enabled content type in a single array, so difficult to use features to manage it per individual content type.

Similar as diff_form_node_type_form_alter, we can move the enabled content type from admin/config/content/linkchecker to admin/structure/types/manage/*, so replace linkchecker_scan_nodetypes as linkchecker_scan_node_* per content type.

All similar 3rd party modules patch with same idea as this issue:

CommentFileSizeAuthor
#51 Issue-2060243-by-hswong3i-hass-Split-linkcheckerscan.patch18.01 KBhass
#45 2060243-node-type-scanning.43.patch19.35 KBhass
#43 2060243-node-type-scanning.43.patch19.35 KBlarowlan
#43 interdiff.txt974 byteslarowlan
#42 2060243-node-type-scanning.41.patch19.34 KBlarowlan
#42 interdiff.txt2.59 KBlarowlan
#35 Issue-2060243-by-hswong3i-hass-Split-linkcheckerscan.patch16.71 KBhass
#32 linkchecker-scan_node-2060243-32.patch18.82 KBhswong3i
#29 linkchecker-scan_node-2060243-29.patch18.18 KBhswong3i
#28 Issue-2060243-by-hass-Split-linkcheckerscannodetypes.patch17.83 KBhass
#27 Issue-2060243-by-hass-Split-linkcheckerscannodetypes.patch16.82 KBhass
#24 linkchecker-scan_node-2060243-24.patch19.97 KBhswong3i
#20 Issue-2060243-by-hass-Split-linkcheckerscannodetypes.patch17.6 KBhass
#18 linkchecker-scan_node-2060243-18.patch20.37 KBhswong3i
#16 linkchecker-scan_node-2060243-15.patch18.7 KBhswong3i
#15 linkchecker-scan_node-2060243-15.patch0 byteshswong3i
#11 linkchecker-scan_node-2060243-10.patch12.65 KBhswong3i
#7 linkchecker-scan_node-2060243-7.patch15.55 KBhswong3i
#5 linkchecker-scan_node-2060243-5.patch12.85 KBhswong3i
#1 linkchecker-scan_node-2060243-2.patch12.04 KBhswong3i
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hswong3i’s picture

Status: Active » Needs review
FileSize
12.04 KB

Patch via 7.x-1.x, changes include:

  • Move enabled content type configuration to admin/structure/types/manage/*
  • Replace use of _linkchecker_scan_nodetype() as variable_get(), simply
  • Remove _linkchecker_scan_nodetype(), because no longer useful
  • Add _linkchecker_scan_node_types(), so return all enabled content types in array
  • Include hook_update() implementation
hass’s picture

That sounds very useful. Where have you moved the batch scan that fires if you enabled a content type for scanning?

hswong3i’s picture

Honestly, patch from #1 now skip the fire of batch_set(_linkchecker_batch_import_nodes($node_types)) because I guess we can do so manually by clicking the re-scan button (BTW, it change the original logic, design and implementation...).

My suggestion is to fire that individually after linkchecker_form_node_type_form_alter(), add a submit hook to do so. Any idea?

hass’s picture

Status: Needs review » Needs work

But we need to fire it. Beginners will not understand it and I also do not like to scan manually, too. This must be changed.

hswong3i’s picture

Status: Needs work » Needs review
FileSize
12.85 KB

Add a custom submit handler for node type form, so once submit it will check *that* content type only ;-)

hass’s picture

+++ b/linkchecker.moduleundefined
@@ -950,6 +950,49 @@ function linkchecker_form_alter(&$form, &$form_state, $form_id) {
+  if ($linkchecker_scan_node > variable_get('linkchecker_scan_node_' . $type)) {

Why has variable_get() no default? That may be a problem if it has never set.

I guess we also need to add a hook_node_type_delete() to delete the variable or we have stale variables as node_type_get_names() in hook_uninstall() will not return deleted node types.

Aside, why not using hook_node_type_insert/update() for the batch? May be easier than the submit handler.

hswong3i’s picture

Why has variable_get() no default? That may be a problem if it has never set.

Typo, fixed.

I guess we also need to add a hook_node_type_delete() to delete the variable or we have stale variables as node_type_get_names() in hook_uninstall() will not return deleted node types.

Add with hook_node_type_delete().

Aside, why not using hook_node_type_insert/update() for the batch? May be easier than the submit handler.

Now replaced as hook_node_type_insert/update().

Additional changes goes to 2nd part of patch file by git format-patch, please kindly review ;-)

hass’s picture

+++ b/linkchecker.moduleundefined
@@ -950,6 +950,49 @@ function linkchecker_form_alter(&$form, &$form_state, $form_id) {
+    // Add the submit handler to fire the batch scan if enabled a content type
+    //for scanning.
+    $form += array('#submit' => array());
+    if (!in_array('linkchecker_form_node_type_form_submit', $form['#submit'])) {
+      array_unshift($form['#submit'], 'linkchecker_form_node_type_form_submit');
+    }
+  }
+}
+
+/**
+ * Custom submit handler for node type form.
+ */
+function linkchecker_form_node_type_form_submit($form, &$form_state) {
+  $type = $form_state['values']['type'];
+  $linkchecker_scan_node = $form_state['values']['linkchecker_scan_node'];
+
+  if ($linkchecker_scan_node > variable_get('linkchecker_scan_node_' . $type)) {
+    module_load_include('inc', 'linkchecker', 'linkchecker.batch');
+    batch_set(_linkchecker_batch_import_nodes(array($type)));
+  }
+
+  variable_set('linkchecker_scan_node_' . $type, $linkchecker_scan_node);

No longer needed, isn't it?

+++ b/linkchecker.moduleundefined
@@ -817,6 +817,33 @@ function _linkchecker_status_handling(&$response, $link) {
+ * Implements hook_node_type_insert().
+ */
+function linkchecker_node_type_insert($info) {
+  if (variable_get('linkchecker_scan_node_' . $info->type, FALSE)) {
+    module_load_include('inc', 'linkchecker', 'linkchecker.batch');
+    batch_set(_linkchecker_batch_import_nodes(array($info->type)));
+  }
+}
+
+/**
+ * Implements hook_node_type_update().
+ */
+function linkchecker_node_type_update($info) {
+  if (variable_get('linkchecker_scan_node_' . $info->type, FALSE)) {
+    module_load_include('inc', 'linkchecker', 'linkchecker.batch');
+    batch_set(_linkchecker_batch_import_nodes(array($info->type)));
+  }
+}

Let's try not duplicating code. Just call the update function from the insert. Aside - calling it on insert makes not so much sense as there is no content yet... I believe we can remove the insert completely. and we should not re-run it with every update. Only if the setting has been changed to enabled.

+++ b/linkchecker.moduleundefined
@@ -965,32 +992,10 @@ function linkchecker_form_node_type_form_alter(&$form, $form_state) {
-
-    // Add the submit handler to fire the batch scan if enabled a content type
-    //for scanning.
-    $form += array('#submit' => array());
-    if (!in_array('linkchecker_form_node_type_form_submit', $form['#submit'])) {
-      array_unshift($form['#submit'], 'linkchecker_form_node_type_form_submit');
-    }
   }
 }
 
 /**
- * Custom submit handler for node type form.
- */
-function linkchecker_form_node_type_form_submit($form, &$form_state) {
-  $type = $form_state['values']['type'];
-  $linkchecker_scan_node = $form_state['values']['linkchecker_scan_node'];
-
-  if ($linkchecker_scan_node > variable_get('linkchecker_scan_node_' . $type)) {
-    module_load_include('inc', 'linkchecker', 'linkchecker.batch');
-    batch_set(_linkchecker_batch_import_nodes(array($type)));
-  }
-
-  variable_set('linkchecker_scan_node_' . $type, $linkchecker_scan_node);
-}
-
-/**

?

hswong3i’s picture

and we should not re-run it with every update. Only if the setting has been changed to enabled.

Most likely not possible if we are using hook_node_type_update(), because the variable pass in *already* updated as new version before goes into hook_node_type_update(), so may not have the idea about *change*?

hass’s picture

variable_get('linkchecker_scan_node_' . $type, $linkchecker_scan_node); in update hook and compare with the form value and set it afterwards... aside the save of the variable seems missing in the node type update hook.

hswong3i’s picture

Remove linkchecker_node_type_insert(), reformat patch.

hass’s picture

Why not moving the comment scan checkbox to the node type, too? So we have all settings together.

hswong3i’s picture

But currently linkchecker_scan_comments control on/off of ALL comment scan for ALL enabled content types; and if a content type already disable link checking, _linkchecker_batch_import_comments() will not trigger for corresponding comment link checking, too.

I guess unless we detail split the comment scan options into per content type, or else may be over design for this issue (originally request: linkchecker_scan_nodetypes handle all content type in single array so not features export per content type friendly)?

hass’s picture

I believe keeping the settings splitted is a usability fail. It looks really confusing to me that one setting is inside content type and the other in linkchecker setting, but both are about the content type. Your patch is a good usability improvement for sure, but if we change this now, we should keep both together.

hswong3i’s picture

Complete changes since #11 can be found from https://github.com/pantarei/drupal-linkchecker/commit/9dadd54852f91d9d44..., include:

  • Add vertical tab summaries for content type form
  • Split single global linkchecker_scan_comments into per content type linkchecker_scan_comment_*, also move it into content type form
  • (Logic change) Remove fire of batch scan after form submittion
  • (UI/UX improvement) Show "Maintenance" fieldset by default, also move it to top of configuration page so capture end-user focus for manual link scan
hswong3i’s picture

hass’s picture

Please do not change Maintenance. A user should normally not use it. There are only rare exceptions.

hswong3i’s picture

@hass:

Complete changeset goes to https://github.com/pantarei/drupal-linkchecker/commit/6f8a289e0c86687e35..., include:

  • Restore "Maintenance" fieldset as original
  • Simplify function calls as linkchecker_scan_node_types() and linkchecker_scan_comment_types()
  • Add simple help message at configuration page so inform end-user to enable link checking on content type or comment at admin/structure/types

Up to this point I have already consolidate all similar 3rd party modules patch with same idea into this issue (and even the most complete version here, thank you very much for your comment which make it more mature):

Final patch attached already applied to DruStack for more than a week, and perfectly handle my initial request on this issue with numbers of client's project:

Now linkchecker_scan_nodetypes store all enabled content type in a single array, so difficult to use features to manage it per individual content type.

Please feel free to improve this issue according to overall project design concern (which always a weakness for a contributor besides original author), and it is my pleasure to remove the manual patch within distribution once changes goes into mainstream. Thank you very much and looking for any good news ;-)

Regards,
Edison Wong

hass’s picture

Great patch. Thanks a lot for this. I'm missing the already discussed batch scan in the code once the _node_type_form_alter() form is submitted. Maybe I missed it, but it seems not there. If I remember correctly you had it inside in past!?

What do you think about static caching of the arrays in linkchecker_scan_node_types() and linkchecker_scan_comment_types()?

hass’s picture

Status: Needs review » Needs work
FileSize
17.6 KB

Changes:

  • Added a note to changelog
  • Renamed the JS file to linkchecker-node-form.js like comment-node-form.js
  • Removed the weights from fields in hook_form_node_type_form_alter(). No idea what the reason for this was.
  • Changed wording on some translatable strings.
  • Added a 'Disabled' status to vertical bar if all checkboxes are disabled.
  • Minor code style changes and additions.
  • Moved the new help into general fieldset description.
  • FIXED: linkchecker_modules_disabled() has a linkchecker_scan_comments leftover. This also shows that there is a problem if linkchecker_scan_comment_types() will always return data if the comment module is disabled. However we may need to add a module_exists('comment') check to linkchecker_scan_comment_types().

Bugs:

  • A content type save does not fire a batch scan of the content type. This is required if the settings have been changed from disabled to enabled, otherwise not.
hass’s picture

Issue summary: View changes

Add more reference links

hass’s picture

hass’s picture

hass’s picture

@hswong3i: Are you able to finish the patch, please?

hswong3i’s picture

@hass: Sorry that recently I am focusing on TWBS R&D so may not able to complete with this issue debug yet...

BTW, at least I give a re-roll of your patch via latest GIT, and will apply to drustack_seo.make now. Therefore all of my clients use case will benefit with this patch and able to figure out how to fix it ;-)

P.S. Soon I will handle another client project R&D and MUST use linkchecker for that, will come back ASAP~~

hass’s picture

#20 was against latest dev.

hswong3i’s picture

But I do face a .rej during git apply so just simply re-roll it without any changes.

hass’s picture

There are lot of differences to mine.

hass’s picture

Missed the new JS file in last patch

hswong3i’s picture

FileSize
18.18 KB

Patch from #28 reroll via latest dev with minor cleanup.

hswong3i’s picture

Status: Needs work » Needs review
hass’s picture

Status: Needs review » Needs work
// Add custom submit handler to custom block delete form.
       $form['#submit'][] = 'linkchecker_block_custom_delete_form_submit';
       break;

has been removed. This is a new bug and not a cleanup.

The bug in #20 is not fixed.

Will you fix the remaining bugs or should be won't fix now?

hswong3i’s picture

Status: Needs work » Needs review
FileSize
18.82 KB

@hass: refer to your comment on #28 and #29 patched result, I found that Add custom submit handler to custom block delete form. not appear in #29 patch file just because of different patch file format. There should be no new bug nor changes introduced.

Patch re-roll via latest 7.x-1.x changes.

hass’s picture

Priority: Normal » Critical

Marking this critical to make sure this goes in soon and before we start porting to D8.

hass’s picture

Status: Needs review » Needs work

The patch does not apply.

hass’s picture

hass’s picture

Status: Needs review » Needs work
+++ b/linkchecker.admin.inc
@@ -311,30 +291,6 @@
-
-  // Re-scan items, if node types or comment or custom block selection has been
-  // changed.
-  $additional_nodetypes_selected = array_diff($form_state['values']['linkchecker_scan_nodetypes'], $form['settings']['linkchecker_scan_nodetypes']['#default_value']);
-  if (!empty($additional_nodetypes_selected) || $form_state['values']['linkchecker_scan_comments'] > $form['settings']['linkchecker_scan_comments']['#default_value']) {
-    $node_types = array_keys(array_filter($form_state['values']['linkchecker_scan_nodetypes']));
-
-    // If one or more node types have been selected.
-    if (!empty($node_types)) {
-      module_load_include('inc', 'linkchecker', 'linkchecker.batch');
-      batch_set(_linkchecker_batch_import_nodes($node_types));
-
-      // If comment scanning of node types has been selected.
-      if ($form_state['values']['linkchecker_scan_comments'] > $form['settings']['linkchecker_scan_comments']['#default_value']) {
-        batch_set(_linkchecker_batch_import_comments($node_types));
-      }
-    }
-  }
-
-  // If block scanning has been selected.
-  if ($form_state['values']['linkchecker_scan_blocks'] > $form['settings']['linkchecker_scan_blocks']['#default_value']) {
-    module_load_include('inc', 'linkchecker', 'linkchecker.batch');
-    batch_set(_linkchecker_batch_import_block_custom());
-  }

This suxx so much. This part is missing in the patch.

larowlan’s picture

Just confirming that #36 is all that remains here?

hass’s picture

Yes, as I know.

larowlan’s picture

thanks

larowlan’s picture

So the approach here would be to just re scan when a content-type had its setting turned on?

hass’s picture

Yes. If we do not scan the content type - only links from new content would be checked.

larowlan’s picture

Added back block hunk, as that is unchanged.

Added in submit handler for node form to trigger batch scanning on the one node-type on submit.

larowlan’s picture

The last submitted patch, 42: 2060243-node-type-scanning.41.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 45: 2060243-node-type-scanning.43.patch, failed testing.

The last submitted patch, 45: 2060243-node-type-scanning.43.patch, failed testing.

The last submitted patch, 45: 2060243-node-type-scanning.43.patch, failed testing.

The last submitted patch, 45: 2060243-node-type-scanning.43.patch, failed testing.

The last submitted patch, 45: 2060243-node-type-scanning.43.patch, failed testing.

  • hass committed 99b1746 on 7.x-1.x
    Issue #2060243 by hswong3i, hass: Split linkchecker_scan_nodetypes as...
hass’s picture

Status: Needs review » Fixed

  • hass committed 99b1746 on 8.x-1.x
    Issue #2060243 by hswong3i, hass: Split linkchecker_scan_nodetypes as...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.