[TASK] Use Environment API in scheduler 36/57236/2
authorBenni Mack <benni@typo3.org>
Fri, 15 Jun 2018 15:36:52 +0000 (17:36 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 15:51:14 +0000 (17:51 +0200)
Resolves: #85279
Releases: master
Change-Id: I2d63540be1883fb2faea763d72a875800eae1cfa
Reviewed-on: https://review.typo3.org/57236
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/scheduler/Classes/Example/TestTask.php
typo3/sysext/scheduler/Classes/Task/AbstractTask.php

index 0d3d025..4dbdfac 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Scheduler\Example;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -43,7 +44,7 @@ class TestTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
             // Get execution information
             $exec = $this->getExecution();
             // Get call method
-            if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
+            if (Environment::isCli()) {
                 $calledBy = 'CLI module dispatcher';
                 $site = '-';
             } else {
index f14014f..3cc992f 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Scheduler\Task;
 
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -437,11 +438,6 @@ abstract class AbstractTask implements LoggerAwareInterface
         // (we need to know that number, because it is returned at the end of the method)
         $numExecutions = count($runningExecutions);
         $runningExecutions[$numExecutions] = time();
-        // Define the context in which the script is running
-        $context = 'BE';
-        if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
-            $context = 'CLI';
-        }
         GeneralUtility::makeInstance(ConnectionPool::class)
             ->getConnectionForTable('tx_scheduler_task')
             ->update(
@@ -449,7 +445,8 @@ abstract class AbstractTask implements LoggerAwareInterface
                 [
                     'serialized_executions' => serialize($runningExecutions),
                     'lastexecution_time' => time(),
-                    'lastexecution_context' => $context
+                    // Define the context in which the script is running
+                    'lastexecution_context' => Environment::isCli() ? 'CLI' : 'BE'
                 ],
                 [
                     'uid' => $this->taskUid