diff --git a/typo3/sysext/scheduler/Classes/Example/TestTask.php b/typo3/sysext/scheduler/Classes/Example/TestTask.php
index 0d3d025b8e9303b08b081d3ce756c0703c46a367..4dbdfac1ff8fe13b3785e509741e703468f3651b 100644
--- a/typo3/sysext/scheduler/Classes/Example/TestTask.php
+++ b/typo3/sysext/scheduler/Classes/Example/TestTask.php
@@ -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 {
diff --git a/typo3/sysext/scheduler/Classes/Task/AbstractTask.php b/typo3/sysext/scheduler/Classes/Task/AbstractTask.php
index f14014f1142dd1e8278289ff8d1108b554c9a288..3cc992f216cf27d5cd5feedda2a89bcf240cd89c 100644
--- a/typo3/sysext/scheduler/Classes/Task/AbstractTask.php
+++ b/typo3/sysext/scheduler/Classes/Task/AbstractTask.php
@@ -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