[!!!][TASK] Use symfony console for reference index update 85/46685/7
authorWouter Wolters <typo3@wouterwolters.nl>
Mon, 15 Feb 2016 21:24:23 +0000 (22:24 +0100)
committerSusanne Moog <typo3@susannemoog.de>
Thu, 31 Mar 2016 14:35:59 +0000 (16:35 +0200)
The reference index is migrated to be called as a symfony console command, using the
CLI binary via typo3/sysext/core/bin/typo3 referenceindex:update.

The "old" way with the CLI Key is removed.

Resolves: #75324
Releases: master
Change-Id: I9f40c78a1a1ba66fc72f962fe46f906fa1f54c0f
Reviewed-on: https://review.typo3.org/46685
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
typo3/sysext/backend/Classes/Command/ReferenceIndexUpdateCommand.php [new file with mode: 0644]
typo3/sysext/backend/Configuration/Commands.php
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/core/Documentation/Changelog/master/Breaking-75324-ReferenceIndexCLICommandChanged.rst [new file with mode: 0644]
typo3/sysext/lowlevel/Classes/View/DatabaseIntegrityView.php
typo3/sysext/lowlevel/Resources/Private/Language/locallang.xlf
typo3/sysext/lowlevel/Resources/Private/Templates/Backend/ReferenceIndex.html
typo3/sysext/lowlevel/ext_localconf.php

diff --git a/typo3/sysext/backend/Classes/Command/ReferenceIndexUpdateCommand.php b/typo3/sysext/backend/Classes/Command/ReferenceIndexUpdateCommand.php
new file mode 100644 (file)
index 0000000..7a59633
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+namespace TYPO3\CMS\Backend\Command;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+use TYPO3\CMS\Core\Database\ReferenceIndex;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Core function to check/update the Reference Index
+ */
+class ReferenceIndexUpdateCommand extends Command
+{
+
+    /**
+     * Configure the command by defining the name, options and arguments
+     */
+    public function configure()
+    {
+        $this->setDescription('Update the reference index of TYPO3')
+            ->addOption(
+                'check',
+                'c',
+                InputOption::VALUE_NONE,
+                'Only check the reference index of TYPO3'
+            );
+    }
+
+    /**
+     * Executes the command for adding or removing the lock file
+     *
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     * @return void
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $isTestOnly = $input->getOption('check');
+        $isSilent = $output->getVerbosity() !== OutputInterface::VERBOSITY_QUIET;
+
+        /** @var ReferenceIndex $referenceIndex */
+        $referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
+        $referenceIndex->updateIndex($isTestOnly, $isSilent);
+    }
+}
index 26b541b..ef445b8 100644 (file)
@@ -14,5 +14,9 @@ return [
     ],
     'backend:unlock' => [
         'class' => \TYPO3\CMS\Backend\Command\LockBackendCommand::class
+    ],
+    'referenceindex:update' => [
+        'class' => \TYPO3\CMS\Backend\Command\ReferenceIndexUpdateCommand::class,
+        'user' => '_cli_lowlevel'
     ]
 ];
index b92fddf..1ab054d 100644 (file)
@@ -1139,7 +1139,7 @@ class ReferenceIndex
         $tableNames = array();
         $recCount = 0;
         $tableCount = 0;
-        $headerContent = $testOnly ? 'Reference Index being TESTED (nothing written, use "--refindex update" to update)' : 'Reference Index being Updated';
+        $headerContent = $testOnly ? 'Reference Index being TESTED (nothing written, remove the "--check" argument)' : 'Reference Index being Updated';
         if ($cli_echo) {
             echo '*******************************************' . LF . $headerContent . LF . '*******************************************' . LF;
         }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-75324-ReferenceIndexCLICommandChanged.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-75324-ReferenceIndexCLICommandChanged.rst
new file mode 100644 (file)
index 0000000..6db5490
--- /dev/null
@@ -0,0 +1,45 @@
+=====================================================
+Breaking: #75324 - ReferenceIndex CLI command changed
+=====================================================
+
+Description
+===========
+
+The Reference Index Updater Command Line command has been changed to use a Symfony Command.
+
+To update the reference index on non-composer-mode installations is now called on the command line via 
+``typo3/sysext/core/bin/typo3 softreference:index``. To just check the reference index, the option ``-c``(alternatively the property "check" can be used) is used like this ``typo3/sysext/core/bin/typo3 softreference:index -c``
+
+For installations set up via composer, the typo3 CLI binary is available in the "bin/" directory directly inside the
+project root.
+
+The command can be used like this:
+
+.. code-block:: sh
+
+       # update the reference index
+       bin/typo3 softreference:index
+       # check the reference index
+       bin/typo3 softreference:index -c
+       bin/typo3 softreference:index --check
+
+The additional option --silent does not output anything when running the CLI command.
+
+
+Impact
+======
+
+Calling the command via the old syntax ``typo3/cli_dispatch.phpsh lowlevel refindex`` will not work anymore.
+
+
+Affected Installations
+======================
+
+Any existing installation upgrading to TYPO3 v8 with a (e.g. cron) CLI script, running the reference index update via
+the ``typo3/cli_dispatch.phpsh``.
+
+
+Migration
+=========
+
+Change the CLI scripts inside your installation to the new binary path.
\ No newline at end of file
index 6d8be94..23fe6a4 100644 (file)
@@ -27,6 +27,7 @@ use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Integrity\DatabaseIntegrityCheck;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 
 /**
@@ -312,9 +313,9 @@ class DatabaseIntegrityView extends BaseScriptClass
      */
     public function func_refindex()
     {
-        $this->view->assign('PATH_typo3', PATH_typo3);
         $this->view->assign('ReadmeLink', ExtensionManagementUtility::extRelPath('lowlevel') . 'README.rst');
         $this->view->assign('ReadmeLocation', ExtensionManagementUtility::extPath('lowlevel', 'README.rst'));
+        $this->view->assign('binaryPath', ExtensionManagementUtility::extPath('core', 'bin/typo3'));
 
         if (GeneralUtility::_GP('_update') || GeneralUtility::_GP('_check')) {
             $testOnly = (bool)GeneralUtility::_GP('_check');
index 8f9ef31..963f1cb 100644 (file)
                        <trans-unit id="checkScript_check_description">
                                <source>To check the reference index use</source>
                        </trans-unit>
-                       <trans-unit id="checkScript_check_example">
-                               <source>php /path/to/your/typo3/cli_dispatch.phpsh lowlevel_refindex -c</source>
-                       </trans-unit>
                        <trans-unit id="checkScript_update_description">
                                <source>To update the reference index use</source>
                        </trans-unit>
-                       <trans-unit id="checkScript_update_example">
-                               <source>php /path/to/your/typo3/cli_dispatch.phpsh lowlevel_refindex -e</source>
-                       </trans-unit>
-                       <trans-unit id="checkScript_more">
-                               <source>Make sure that a BE user with the name _cli_lowlevel exists. For more details see: /path/to/your/typo3/sysext/lowlevel/HOWTO_clean_up_TYPO3_installations.txt or /path/to/your/typo3/sysext/lowlevel/README.rst (since TYPO3 7 LTS).</source>
-                       </trans-unit>
                        <trans-unit id="checkScript_information">
                                <source>If you run these commands from the command line, make sure that a BE user with the name _cli_lowlevel exists.</source>
                        </trans-unit>
index 1b77d13..8436da8 100644 (file)
 
 <h3>{f:translate(key:'checkScript_check_description')}</h3>
 <p>
-       <code>php {PATH_typo3}cli_dispatch.phpsh lowlevel_refindex -c</code>
+       <code>php {binaryPath} referenceindex:update -c</code>
 </p>
 
 <h3>{f:translate(key:'checkScript_update_description')}</h3>
 <p>
-       <code>php {PATH_typo3}cli_dispatch.phpsh lowlevel_refindex -e</code>
+       <code>php {binaryPath} referenceindex:update</code>
 </p>
 
 <f:be.infobox state="-1" message="{f:translate(key:'checkScript_information')}" />
index 9fd21ba..107a570 100644 (file)
@@ -3,26 +3,6 @@ defined('TYPO3_MODE') or die();
 
 if (TYPO3_MODE === 'BE') {
     // Setting up scripts that can be run from the cli_dispatch.phpsh script.
-    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_refindex'] = array(
-        function () {
-            // Call the functionality
-            if (in_array('-e', $_SERVER['argv']) || in_array('-c', $_SERVER['argv'])) {
-                $testOnly = in_array('-c', $_SERVER['argv']);
-                $refIndexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
-                list($headerContent, $bodyContent) = $refIndexObj->updateIndex($testOnly, !in_array('-s', $_SERVER['argv']));
-                $bodyContent = str_replace('##LF##', LF, $bodyContent);
-            } else {
-                echo '
-                       Options:
-                       -c = Check refindex
-                       -e = Update refindex
-                       -s = Silent
-                       ';
-                die;
-            }
-        },
-        '_CLI_lowlevel'
-    );
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['lowlevel_cleaner'] = array(
         function () {
             $cleanerObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Lowlevel\CleanerCommand::class);