[BUGFIX] Linkvalidator: Scheduler task not working correctly 80/52780/2
authorThorben Nissen <thorben.nissen@kapp-hamburg.de>
Tue, 25 Apr 2017 07:51:57 +0000 (09:51 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 11 May 2017 15:31:19 +0000 (17:31 +0200)
The scheduler task does not check anything but just returns and does not
send an email. Furthermore it is not possible to enter email address
separated by newlines. Under some conditions it can happen, that result
numbers are added to the last result.

Explode pid list into array in LinkAnalyzer::init and use the array later.
Check if email adresses are comma or newline separated when validating
them when saving the task. Add file link statistic to default email
template. Reset the link statistics before the run to avoid adding it to
the last result numbers.

Resolves: #81000
Releases: master, 8.7
Change-Id: I05a98c9babcb889a83ce2f1ec7c0a2bee5dafede
Reviewed-on: https://review.typo3.org/52780
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php
typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php
typo3/sysext/linkvalidator/Resources/Private/Templates/mailtemplate.html

index f8745a1..b7e28fa 100644 (file)
@@ -37,11 +37,11 @@ class LinkAnalyzer
     protected $searchFields = [];
 
     /**
-     * List of comma separated page uids (rootline downwards)
+     * List of page uids (rootline downwards)
      *
-     * @var string
+     * @var array
      */
-    protected $pidList = '';
+    protected $pids = [];
 
     /**
      * Array of tables and the number of external links they contain
@@ -116,14 +116,14 @@ class LinkAnalyzer
     /**
      * Store all the needed configuration values in class variables
      *
-     * @param array $searchField List of fields in which to search for links
-     * @param string $pid List of comma separated page uids in which to search for links
-     * @param array $tsConfig The currently active TSConfig.
+     * @param array  $searchField List of fields in which to search for links
+     * @param string $pidList     List of comma separated page uids in which to search for links
+     * @param array  $tsConfig    The currently active TSConfig.
      */
-    public function init(array $searchField, $pid, $tsConfig)
+    public function init(array $searchField, $pidList, $tsConfig)
     {
         $this->searchFields = $searchField;
-        $this->pidList = $pid;
+        $this->pids = GeneralUtility::intExplode(',', $pidList, true);
         $this->tsConfig = $tsConfig;
     }
 
@@ -136,8 +136,7 @@ class LinkAnalyzer
     public function getLinkStatistics($checkOptions = [], $considerHidden = false)
     {
         $results = [];
-        $pidList = GeneralUtility::intExplode(',', $this->pidList, true);
-        if (!empty($checkOptions) && !empty($pidList)) {
+        if (!empty($checkOptions) && !empty($this->pids)) {
             $checkKeys = array_keys($checkOptions);
 
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
@@ -148,12 +147,12 @@ class LinkAnalyzer
                     $queryBuilder->expr()->orX(
                         $queryBuilder->expr()->in(
                             'record_pid',
-                            $queryBuilder->createNamedParameter($pidList, Connection::PARAM_INT_ARRAY)
+                            $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
                         ),
                         $queryBuilder->expr()->andX(
                             $queryBuilder->expr()->in(
                                 'record_uid',
-                                $queryBuilder->createNamedParameter($pidList, Connection::PARAM_INT_ARRAY)
+                                $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
                             ),
                             $queryBuilder->expr()->eq(
                                 'table_name',
@@ -192,7 +191,7 @@ class LinkAnalyzer
                     ->where(
                         $queryBuilder->expr()->in(
                             ($table === 'pages' ? 'uid' : 'pid'),
-                            $queryBuilder->createNamedParameter($pidList, Connection::PARAM_INT_ARRAY)
+                            $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
                         )
                     )
                     ->execute();
@@ -420,7 +419,6 @@ class LinkAnalyzer
     public function getLinkCounts($curPage)
     {
         $markerArray = [];
-        $this->pidList = GeneralUtility::intExplode(',', ($this->pidList ?: $curPage), true);
 
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable('tx_linkvalidator_link');
@@ -432,7 +430,7 @@ class LinkAnalyzer
             ->where(
                 $queryBuilder->expr()->in(
                     'record_pid',
-                    $queryBuilder->createNamedParameter($this->pidList, Connection::PARAM_INT_ARRAY)
+                    $queryBuilder->createNamedParameter($this->pids, Connection::PARAM_INT_ARRAY)
                 )
             )
             ->groupBy('link_type')
index 9ec80ef..0573ced 100644 (file)
@@ -281,6 +281,9 @@ class ValidatorTask extends AbstractTask
         $pageList = GeneralUtility::trimExplode(',', $this->page, true);
         $modTs = $this->loadModTsConfig($this->page);
         if (is_array($pageList)) {
+            // reset broken link counts as they were stored in the serialized object
+            $this->oldTotalBrokenLink = 0;
+            $this->totalBrokenLink = 0;
             foreach ($pageList as $page) {
                 $pageSections .= $this->checkPageLinks($page);
             }
index d885fc0..18f3ff1 100644 (file)
@@ -225,7 +225,11 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt
         // @todo which is normally a comma separated string
         $lang = $this->getLanguageService();
         if (!empty($submittedData['linkvalidator']['email'])) {
-            $emailList = GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
+            if (strpos($submittedData['linkvalidator']['email'], ',') !== false) {
+                $emailList = GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
+            } else {
+                $emailList = GeneralUtility::trimExplode(LF, $submittedData['linkvalidator']['email']);
+            }
             foreach ($emailList as $emailAdd) {
                 if (!GeneralUtility::validEmail($emailAdd)) {
                     $isValid = false;
index 8758d71..da3e7a9 100644 (file)
@@ -11,8 +11,9 @@ Total broken links: ###TOTALBROKENLINK### (last report: ###TOTALBROKENLINK_OLD##
  <!-- ###PAGE_SECTION### -->
        Page: ###TITLE###<br />
        All links types: ###BROKENLINKCOUNT###  (last report: ###BROKENLINKCOUNT_OLD###)<br />
-       Internal link: ###DB### (last report: ###DB_OLD###)<br />
-       External link: ###EXTERNAL### (last report: ###EXTERNAL_OLD###)<br />
+       Internal links: ###DB### (last report: ###DB_OLD###)<br />
+       File links: ###FILE### (last report: ###FILE_OLD###)<br />
+       External links: ###EXTERNAL### (last report: ###EXTERNAL_OLD###)<br />
 
  <!-- ###PAGE_SECTION### -->