[TASK] Remove creation of _cli_scheduler in BE 56/51256/2
authorBenni Mack <benni@typo3.org>
Tue, 10 Jan 2017 23:35:45 +0000 (00:35 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 10 Jan 2017 23:45:06 +0000 (00:45 +0100)
The _cli_scheduler backend user was necessary before the
introduction of the unified "_cli_" user for all CLI processes.

The scheduler module had an info and functionality to
create such a user which is not needed anymore and
can safely be removed.

Resolves: #79264
Releases: master
Change-Id: Ie2472869b9db1fc9dcb4add9fae6be63722156c6
Reviewed-on: https://review.typo3.org/51256
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Resources/Private/Language/locallang.xlf
typo3/sysext/scheduler/Resources/Private/Templates/Backend/SchedulerModule/CheckScreen.html

index 2a799cc..d9a7140 100644 (file)
@@ -20,17 +20,12 @@ use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Template\ModuleTemplate;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Database\ConnectionPool;
-use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
-use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
-use TYPO3\CMS\Saltedpasswords\Salt\SaltFactory;
-use TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility;
 use TYPO3\CMS\Scheduler\Task\AbstractTask;
 
 /**
@@ -319,85 +314,6 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
     }
 
     /**
-     * This method checks the status of the '_cli_scheduler' user
-     * It will differentiate between a non-existing user and an existing,
-     * but disabled user (as per enable fields)
-     *
-     * @return int -1 if user doesn't exist, 0 if user exists but is not enabled, 1 if user exists and is enabled
-     */
-    protected function checkSchedulerUser()
-    {
-        $schedulerUserStatus = -1;
-        // Check if user exists at all
-        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
-        $queryBuilder->getRestrictions()
-            ->removeAll()
-            ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
-
-        $cliUserExists = (int)$queryBuilder->count('*')
-            ->from('be_users')
-            ->where(
-                $queryBuilder->expr()->eq(
-                    'username',
-                    $queryBuilder->createNamedParameter('_cli_scheduler', \PDO::PARAM_STR)
-                ),
-                $queryBuilder->expr()->eq('admin', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
-            )
-            ->execute()
-            ->fetchColumn();
-
-        if ($cliUserExists !== 0) {
-            $schedulerUserStatus = 0;
-            // Check if user exists and is enabled
-            $queryBuilder->setRestrictions(GeneralUtility::makeInstance(DefaultRestrictionContainer::class));
-            $cliUserExistsAndEnabled = (int)$queryBuilder->execute()->fetchColumn();
-            if ($cliUserExistsAndEnabled !== 0) {
-                $schedulerUserStatus = 1;
-            }
-        }
-        return $schedulerUserStatus;
-    }
-
-    /**
-     * This method creates the "cli_scheduler" BE user if it doesn't exist
-     *
-     * @return void
-     */
-    protected function createSchedulerUser()
-    {
-        // Check _cli_scheduler user status
-        $checkUser = $this->checkSchedulerUser();
-        // Prepare default message
-        $message = $this->getLanguageService()->getLL('msg.userExists');
-        $severity = FlashMessage::WARNING;
-        // If the user does not exist, try creating it
-        if ($checkUser == -1) {
-            // Prepare necessary data for _cli_scheduler user creation
-            $password = StringUtility::getUniqueId('scheduler');
-            if (SaltedPasswordsUtility::isUsageEnabled()) {
-                $objInstanceSaltedPW = SaltFactory::getSaltingInstance();
-                $password = $objInstanceSaltedPW->getHashedPassword($password);
-            }
-            $data = ['be_users' => ['NEW' => ['username' => '_cli_scheduler', 'password' => $password, 'pid' => 0]]];
-            /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */
-            $dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
-            $dataHandler->start($data, []);
-            $dataHandler->process_datamap();
-            // Check if a new uid was indeed generated (i.e. a new record was created)
-            // (counting DataHandler errors doesn't work as some failures don't report errors)
-            $numberOfNewIDs = count($dataHandler->substNEWwithIDs);
-            if ($numberOfNewIDs === 1) {
-                $message = $this->getLanguageService()->getLL('msg.userCreated');
-                $severity = FlashMessage::OK;
-            } else {
-                $message = $this->getLanguageService()->getLL('msg.userNotCreated');
-                $severity = FlashMessage::ERROR;
-            }
-        }
-        $this->addMessage($message, $severity);
-    }
-
-    /**
      * This method displays the result of a number of checks
      * on whether the Scheduler is ready to run or running properly
      *
@@ -407,11 +323,6 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
     {
         $this->view->setTemplatePathAndFilename($this->backendTemplatePath . 'CheckScreen.html');
 
-        // First, check if _cli_scheduler user creation was requested
-        if ($this->CMD === 'user') {
-            $this->createSchedulerUser();
-        }
-
         // Display information about last automated run, as stored in the system registry
         /** @var $registry \TYPO3\CMS\Core\Registry */
         $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
@@ -440,22 +351,6 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
         $this->view->assign('lastRunMessage', $message);
         $this->view->assign('lastRunSeverity', $severity);
 
-        // Check CLI user
-        $checkUser = $this->checkSchedulerUser();
-        if ($checkUser == -1) {
-            $link = $this->moduleUri . '&SET[function]=check&CMD=user';
-            $message = sprintf($this->getLanguageService()->getLL('msg.schedulerUserMissing'), htmlspecialchars($link));
-            $severity = InfoboxViewHelper::STATE_ERROR;
-        } elseif ($checkUser == 0) {
-            $message = $this->getLanguageService()->getLL('msg.schedulerUserFoundButDisabled');
-            $severity = InfoboxViewHelper::STATE_WARNING;
-        } else {
-            $message = $this->getLanguageService()->getLL('msg.schedulerUserFound');
-            $severity = InfoboxViewHelper::STATE_OK;
-        }
-        $this->view->assign('cliUserMessage', $message);
-        $this->view->assign('cliUserSeverity', $severity);
-
         // Check if CLI script is executable or not
         $script = PATH_typo3 . 'cli_dispatch.phpsh';
         $this->view->assign('script', $script);
index 722fc00..5d1a411 100644 (file)
@@ -27,9 +27,6 @@
                        <trans-unit id="hdg.lastRun">
                                <source>Last run</source>
                        </trans-unit>
-                       <trans-unit id="hdg.schedulerUser">
-                               <source>TYPO3 Scheduler backend user</source>
-                       </trans-unit>
                        <trans-unit id="label.automatically">
                                <source>automatically</source>
                        </trans-unit>
                        <trans-unit id="msg.schedulerSetupCheck">
                                <source>This screen checks if the requisites for running the Scheduler as a cron job are fulfilled. It also displays information about the last run of the Scheduler.</source>
                        </trans-unit>
-                       <trans-unit id="msg.schedulerUser">
-                               <source>The backend user "_cli_scheduler" is used by the CLI-script to log into TYPO3. This user may not have administrator privileges. The user's password is not important but should be set to a secure value for security reasons.</source>
-                       </trans-unit>
-                       <trans-unit id="msg.schedulerUserFound">
-                               <source>The backend user "_cli_scheduler" was found.</source>
-                       </trans-unit>
-                       <trans-unit id="msg.schedulerUserFoundButDisabled">
-                               <source>The backend user "_cli_scheduler" exists but is currently disabled.</source>
-                       </trans-unit>
-                       <trans-unit id="msg.schedulerUserMissing">
-                               <source>The backend user "_cli_scheduler" was not found.&lt;br/&gt;&lt;br/&gt; &lt;a href="%s" class="btn btn-danger" title="Click to create the missing user"&gt;Create the user now&lt;/a&gt;</source>
-                       </trans-unit>
                        <trans-unit id="msg.serverTime">
                                <source>Current server time is %s.</source>
                        </trans-unit>
                        <trans-unit id="msg.updateError">
                                <source>The task could not be updated.</source>
                        </trans-unit>
-                       <trans-unit id="msg.userCreated">
-                               <source>The "_cli_scheduler" user was created successfully.</source>
-                       </trans-unit>
-                       <trans-unit id="msg.userExists">
-                               <source>The "_cli_scheduler" user already exists. It was not created.</source>
-                       </trans-unit>
-                       <trans-unit id="msg.userNotCreated">
-                               <source>The creation of the "_cli_scheduler" user failed.</source>
-                       </trans-unit>
                        <trans-unit id="msg.selectionOfNonExistingDatabaseTables">
                                <source>Some of the selected database tables do not exist. Please select only valid tables.</source>
                        </trans-unit>
index a189b82..47b9d74 100644 (file)
@@ -4,11 +4,6 @@
 
 <f:be.infobox  title="{f:translate(key: 'hdg.lastRun')}" message="{lastRunMessage}" state="{lastRunSeverity}" />
 
-<f:be.infobox  title="{f:translate(key: 'hdg.schedulerUser')}" state="{cliUserSeverity}">
-       <p><f:translate key="msg.schedulerUser" /></p>
-       <f:format.raw>{cliUserMessage}</f:format.raw>
-</f:be.infobox>
-
 <f:be.infobox title="{f:translate(key: 'hdg.cliScript')}" state="{isExecutableSeverity}">
        <p>{f:translate(key: 'msg.cliScript', arguments: '{0: script}') -> f:format.raw()}</p>
        {isExecutableMessage}