[BUGFIX] Use proper path to install cli binary 71/60371/7
authorHelmut Hummel <typo3@helhum.io>
Thu, 4 Apr 2019 14:41:05 +0000 (16:41 +0200)
committerTobi Kretschmann <tobi@tobishome.de>
Thu, 11 Apr 2019 07:18:34 +0000 (09:18 +0200)
The cli binary path is changed to be located in TYPO3_PATH_WEB
instead of TYPO3_PATH_ROOT.

Releases: 9.5, master
Resolves: #88088
Change-Id: I96587254d121149b58f35b0abb0084a89a31b0c7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60371
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
typo3/sysext/core/Classes/Composer/CliEntryPoint.php [new file with mode: 0644]
typo3/sysext/core/Classes/Composer/InstallerScripts.php

diff --git a/typo3/sysext/core/Classes/Composer/CliEntryPoint.php b/typo3/sysext/core/Classes/Composer/CliEntryPoint.php
new file mode 100644 (file)
index 0000000..9da28e5
--- /dev/null
@@ -0,0 +1,69 @@
+<?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 as FilesystemUtility;
+use Symfony\Component\Filesystem\Filesystem;
+use TYPO3\CMS\Composer\Plugin\Config;
+use TYPO3\CMS\Composer\Plugin\Core\InstallerScript;
+
+class CliEntryPoint implements InstallerScript
+{
+    /**
+     * Absolute path to entry script source
+     *
+     * @var string
+     */
+    private $source;
+
+    /**
+     * The target file relative to the web directory
+     *
+     * @var string
+     */
+    private $target;
+
+    public function __construct(string $source, string $target)
+    {
+        $this->source = $source;
+        $this->target = $target;
+    }
+
+    public function run(Event $event): bool
+    {
+        $composer = $event->getComposer();
+        $filesystemUtility = new FilesystemUtility();
+        $filesystem = new Filesystem();
+        $pluginConfig = Config::load($composer);
+
+        $entryPointContent = file_get_contents($this->source);
+        $targetFile = $pluginConfig->get('root-dir') . '/' . $this->target;
+        $autoloadFile = $composer->getConfig()->get('vendor-dir') . '/autoload.php';
+
+        $entryPointContent = preg_replace(
+            '/__DIR__ . \'[^\']*\'/',
+            $filesystemUtility->findShortestPathCode($targetFile, $autoloadFile),
+            $entryPointContent
+        );
+
+        $filesystemUtility->ensureDirectoryExists(dirname($targetFile));
+        $filesystem->dumpFile($targetFile, $entryPointContent);
+        $filesystem->chmod($targetFile, 0755);
+
+        return $filesystem->exists($targetFile);
+    }
+}
index f13852f..e8ad74c 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Core\Composer;
  */
 
 use Composer\Script\Event;
-use TYPO3\CMS\Composer\Plugin\Core\InstallerScripts\EntryPoint;
 use TYPO3\CMS\Composer\Plugin\Core\InstallerScriptsRegistration;
 use TYPO3\CMS\Composer\Plugin\Core\ScriptDispatcher;
 
@@ -35,32 +34,6 @@ class InstallerScripts implements InstallerScriptsRegistration
         $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);
-
-                    $composer = $event->getComposer();
-                    $pluginConfig = \TYPO3\CMS\Composer\Plugin\Config::load($composer);
-
-                    $targetFile = $pluginConfig->get('web-dir') . '/' . $this->target;
-
-                    @chmod($targetFile, 0755);
-
-                    return true;
-                }
-            }
-        );
+        $scriptDispatcher->addInstallerScript(new CliEntryPoint($source, $target));
     }
 }