[BUGFIX] Fix EXT:core/bin/typo3 entry point in composer-mode 31/58531/7
authorBenjamin Franzke <bfr@qbus.de>
Mon, 1 Oct 2018 11:49:03 +0000 (13:49 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Mon, 1 Oct 2018 18:41:01 +0000 (20:41 +0200)
typo3/sysext/core/bin/typo3 does not work in composer mode
currently. Composer-based installations need to use the binary from
the composer "bin-dir", which is fine from a composer-usage point
of view – but hard for documentation.
Additionally the path to "typo3/sysext/core/bin/typo3" is hardcoded
in some places (e.g. scheduler).
We now make sure this binary works in composer mode as well,
using the same entry point strategy as for "typo3/index.php"
and "typo3/install.php".

Change-Id: I400ccd3a2bba4496c5d4ec9482e624cf8270a462
Releases: master
Resolves: #86513
Reviewed-on: https://review.typo3.org/58531
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/.gitattributes
typo3/sysext/core/.gitignore [new file with mode: 0644]
typo3/sysext/core/Classes/Composer/InstallerScripts.php [new file with mode: 0644]
typo3/sysext/core/Resources/Private/Php/cli.php [new file with mode: 0644]
typo3/sysext/core/bin/typo3 [deleted file]

index 434f281..78e2f89 100644 (file)
@@ -1,3 +1,4 @@
 /.gitattributes export-ignore
+/.gitignore export-ignore
 /Resources/Private/TypeScript/ export-ignore
 /Tests/ export-ignore
diff --git a/typo3/sysext/core/.gitignore b/typo3/sysext/core/.gitignore
new file mode 100644 (file)
index 0000000..304f3a8
--- /dev/null
@@ -0,0 +1 @@
+bin/typo3
diff --git a/typo3/sysext/core/Classes/Composer/InstallerScripts.php b/typo3/sysext/core/Classes/Composer/InstallerScripts.php
new file mode 100644 (file)
index 0000000..ee9ba65
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Composer;
+
+/*
+ * This file is part of the TYPO3 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 Composer\Script\Event;
+use Composer\Util\Filesystem;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\EntryPoint;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
+use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
+
+/**
+ * Hook into Composer build to generate TYPO3 cli tool entry script
+ * @internal only used for TYPO3 internally for setting up the installation.
+ */
+class InstallerScripts implements InstallerScriptsRegistration
+{
+    /**
+     * @param Event $event
+     * @param ScriptDispatcher $scriptDispatcher
+     */
+    public static function register(Event $event, ScriptDispatcher $scriptDispatcher)
+    {
+        $source = dirname(__DIR__, 2) . '/Resources/Private/Php/cli.php';
+        $target = 'typo3/sysext/core/bin/typo3';
+
+        $scriptDispatcher->addInstallerScript(
+            // @todo: Add support to `typo3/cms-composer-installers` to create executable entry points
+            new class($source, $target) extends EntryPoint {
+                /** @var string */
+                private $target;
+
+                public function __construct(string $source, string $target)
+                {
+                    parent::__construct($source, $target);
+                    $this->target = $target;
+                }
+
+                public function run(Event $event): bool
+                {
+                    parent::run($event);
+
+                    $filesystem = new Filesystem();
+                    $composer = $event->getComposer();
+                    $pluginConfig = \TYPO3\CMS\Composer\Plugin\Config::load($composer);
+
+                    $targetFile = $pluginConfig->get('web-dir') . '/' . $this->target;
+
+                    @chmod($targetFile, 0755);
+
+                    return true;
+                }
+            }
+        );
+    }
+}
diff --git a/typo3/sysext/core/Resources/Private/Php/cli.php b/typo3/sysext/core/Resources/Private/Php/cli.php
new file mode 100644 (file)
index 0000000..7b9b55e
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env php
+<?php
+/*
+ * 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!
+ */
+
+/**
+ * Command Line Interface module dispatcher
+ * that executes commands
+ */
+call_user_func(function () {
+    $classLoader = require __DIR__ . '/../../../../../../vendor/autoload.php';
+    \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(4, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI);
+    \TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Core\Console\CommandApplication::class)->run();
+});
diff --git a/typo3/sysext/core/bin/typo3 b/typo3/sysext/core/bin/typo3
deleted file mode 100755 (executable)
index f0d2904..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env php
-<?php
-/*
- * 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!
- */
-
-/**
- * Command Line Interface module dispatcher
- * that executes commands
- */
-call_user_func(function() {
-    $classLoader = require __DIR__ . '/../../../../vendor/autoload.php';
-    \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(4, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI);
-    \TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Core\Console\CommandApplication::class)->run();
-});