From 3fc754e691d5e4af2952dcfb150579dc7f1e17c4 Mon Sep 17 00:00:00 2001
From: solideogloria <39064-solideogloria@users.noreply.drupalcode.org>
Date: Tue, 23 Jul 2024 09:24:01 -0500
Subject: [PATCH 1/3] Add disable_cron setting.

---
 config/install/linkchecker.settings.yml   | 1 +
 config/schema/linkchecker.schema.yml      | 3 +++
 linkchecker.module                        | 3 +++
 src/Form/LinkCheckerAdminSettingsForm.php | 9 ++++++++-
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/config/install/linkchecker.settings.yml b/config/install/linkchecker.settings.yml
index f331143..649a013 100644
--- a/config/install/linkchecker.settings.yml
+++ b/config/install/linkchecker.settings.yml
@@ -26,6 +26,7 @@ check:
   library: core
   interval: 2419200
   useragent: 'Drupal (+http://drupal.org/)'
+  disable_cron: false
 error:
   action_status_code_301: 0
   action_status_code_404: 0
diff --git a/config/schema/linkchecker.schema.yml b/config/schema/linkchecker.schema.yml
index ef877de..357ec2e 100644
--- a/config/schema/linkchecker.schema.yml
+++ b/config/schema/linkchecker.schema.yml
@@ -72,6 +72,9 @@ linkchecker.settings:
         useragent:
           type: string
           label: 'User-Agent'
+        disable_cron:
+          type: boolean
+          label: 'Disable cron processing and queueing'
     error:
       type: mapping
       label: 'Error handling'
diff --git a/linkchecker.module b/linkchecker.module
index 7b305e4..e2b7b88 100644
--- a/linkchecker.module
+++ b/linkchecker.module
@@ -148,6 +148,9 @@ function linkchecker_form_field_config_form_builder($entity_type, FieldConfigInt
  * Implements hook_cron().
  */
 function linkchecker_cron() {
+  if (\Drupal::config('linkchecker.settings')->get('check.disable_cron')) {
+    return;
+  }
   \Drupal::service('linkchecker.extractor_batch')->processEntities();
   \Drupal::service('linkchecker.checker')->queueLinks();
 }
diff --git a/src/Form/LinkCheckerAdminSettingsForm.php b/src/Form/LinkCheckerAdminSettingsForm.php
index f17e666..8dc4d8e 100644
--- a/src/Form/LinkCheckerAdminSettingsForm.php
+++ b/src/Form/LinkCheckerAdminSettingsForm.php
@@ -357,6 +357,12 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
         RfcLogLevel::ERROR => $this->t('Errors only'),
       ],
     ];
+    $form['check']['linkchecker_check_disable_cron'] = [
+      '#default_value' => $config->get('check.disable_cron'),
+      '#type' => 'checkbox',
+      '#title' => $this->t('Disable cron processing and queueing'),
+      '#description' => $this->t('Check this box if you will be queueing and processing links via Drush or some other method. <strong>Enabling this will completely disable automatic link queueing and processing.</strong>'),
+    ];

     $form['error'] = [
       '#type' => 'details',
@@ -388,7 +394,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
       ],
     ];
     if ($this->moduleHandler->moduleExists('dblog') && $this->currentUser->hasPermission('access site reports')) {
-      $form['error']['#description'] = $this->t('If enabled, outdated links in content providing a status
+      $form['error']['#description'] = $this->t('If enabled, outdated links in content providing a status
           <em>Moved Permanently</em> (status code 301) are automatically updated to the most recent URL. If used,
           it is recommended to use a value of <em>three</em> to make sure this is not only a temporarily change.
           This feature trust sites to provide a valid permanent redirect.
@@ -506,6 +512,7 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
       ->set('check.library', $form_state->getValue('linkchecker_check_library'))
       ->set('check.interval', $form_state->getValue('linkchecker_check_interval'))
       ->set('check.useragent', $form_state->getValue('linkchecker_check_useragent'))
+      ->set('check.disable_cron', $form_state->getValue('linkchecker_check_disable_cron'))
       ->set('search_published_contents_only', $form_state->getValue('search_published_contents_only'))
       ->set('error.action_status_code_301', $form_state->getValue('linkchecker_action_status_code_301'))
       ->set('error.action_status_code_404', $form_state->getValue('linkchecker_action_status_code_404'))
--
GitLab


From e837f812bae1c96c6543e0e234373c439ea659f0 Mon Sep 17 00:00:00 2001
From: solideogloria <39064-solideogloria@users.noreply.drupalcode.org>
Date: Tue, 23 Jul 2024 09:24:12 -0500
Subject: [PATCH 2/3] Fixes for admin settings form.

---
 src/Form/LinkCheckerAdminSettingsForm.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/Form/LinkCheckerAdminSettingsForm.php b/src/Form/LinkCheckerAdminSettingsForm.php
index 8dc4d8e..247bd82 100644
--- a/src/Form/LinkCheckerAdminSettingsForm.php
+++ b/src/Form/LinkCheckerAdminSettingsForm.php
@@ -74,6 +74,11 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
    */
   protected $linkCheckerResponseCodes;

+  /**
+   * The module handler.
+   */
+  protected ModuleHandlerInterface $moduleHandler;
+
   /**
    * The current user.
    *
@@ -370,11 +375,12 @@ class LinkCheckerAdminSettingsForm extends ConfigFormBase {
       '#description' => $this->t('Defines error handling and custom actions to be executed if specific HTTP requests are failing.'),
       '#open' => TRUE,
     ];
+    /** @var \Drupal\user\UserInterface|null $linkchecker_default_impersonate_account */
     $linkchecker_default_impersonate_account = $this->userStorage->load(1);
     $form['error']['linkchecker_impersonate_account'] = [
       '#type' => 'textfield',
       '#title' => $this->t('Impersonate user account'),
-      '#description' => $this->t('If below error handling actions are executed they can be impersonated with a custom user account. By default this is user %name, but you are able to assign a custom user to allow easier identification of these automatic revision updates. Make sure you select a user with <em>full</em> permissions on your site or the user may not able to access and save all content.', ['%name' => $linkchecker_default_impersonate_account->getAccountName()]),
+      '#description' => $this->t('If below error handling actions are executed they can be impersonated with a custom user account. By default this is user %name, but you are able to assign a custom user to allow easier identification of these automatic revision updates. Make sure you select a user with <em>full</em> permissions on your site or the user may not able to access and save all content.', ['%name' => $linkchecker_default_impersonate_account?->getAccountName() ?? '[UID 1 not found]']),
       '#size' => 30,
       '#maxlength' => 60,
       '#autocomplete_path' => 'user/autocomplete',
--
GitLab


From 8a44af14b2c61b59d7e5997f08dc382260891477 Mon Sep 17 00:00:00 2001
From: solideogloria <39064-solideogloria@users.noreply.drupalcode.org>
Date: Tue, 23 Jul 2024 09:24:41 -0500
Subject: [PATCH 3/3] Add .gitignore for dev files.

---
 .gitignore | 8 ++++++++
 1 file changed, 8 insertions(+)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..222e7e0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+# Exclude development files.
+.ddev/
+.vscode/
+/vendor/
+/web/
+.editorconfig
+.gitattributes
+phpcs.xml.dist
--
GitLab

