Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Make typo3cms more robust and linkable #155

Merged
merged 1 commit into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ before_install:

before_script:
- composer require typo3/cms=$TYPO3_VERSION
- export PATH_WEB=".Build/Web"
- export TYPO3_PATH_WEB="$PWD/.Build/Web"

script:
- >
echo;
echo "Running unit tests";
TYPO3_PATH_WEB="$PATH_WEB" .Build/bin/phpunit -c .Build/vendor/typo3/cms/typo3/sysext/core/Build/UnitTests.xml Tests/Unit/
.Build/bin/phpunit -c .Build/vendor/typo3/cms/typo3/sysext/core/Build/UnitTests.xml Tests/Unit/
- >
echo;
echo "Running php lint";
find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null \;

# Basic functional tests - all commands should exit with 0
- ./typo3cms help && [ ! -f "$PATH_WEB/typo3conf/PackageStates.php" ]
- ./typo3cms help && [ ! -f "$TYPO3_PATH_WEB/typo3conf/PackageStates.php" ]
- ./typo3cms install:setup --non-interactive --database-user-name="root" --database-host-name="localhost" --database-port="3306" --database-name="travis_test" --admin-user-name="admin" --admin-password="password" --site-name="Travis Install"
- ./typo3cms help
- ./typo3cms backend:lock
Expand All @@ -73,11 +73,11 @@ script:
- ./typo3cms configuration:show BE/installToolPassword
- ./typo3cms configuration:showLocal BE/installToolPassword
- ./typo3cms configuration:showActive BE/installToolPassword
- ./typo3cms configuration:set BE/installToolPassword foobar && grep installToolPassword $PATH_WEB/typo3conf/LocalConfiguration.php | grep foobar
- ./typo3cms configuration:remove BE/installToolPassword --force && grep -qv installToolPassword $PATH_WEB/typo3conf/LocalConfiguration.php
- ./typo3cms configuration:set BE/installToolPassword blablupp && grep installToolPassword $PATH_WEB/typo3conf/LocalConfiguration.php | grep blablupp
- rm -f $PATH_WEB/typo3conf/PackageStates.php && ./typo3cms install:generatepackagestates && [ -f "$PATH_WEB/typo3conf/PackageStates.php" ]
- rm $PATH_WEB/typo3temp/index.html && ./typo3cms install:fixfolderstructure && [ -f "$PATH_WEB/typo3temp/index.html" ]
- ./typo3cms configuration:set BE/installToolPassword foobar && grep installToolPassword $TYPO3_PATH_WEB/typo3conf/LocalConfiguration.php | grep foobar
- ./typo3cms configuration:remove BE/installToolPassword --force && grep -qv installToolPassword $TYPO3_PATH_WEB/typo3conf/LocalConfiguration.php
- ./typo3cms configuration:set BE/installToolPassword blablupp && grep installToolPassword $TYPO3_PATH_WEB/typo3conf/LocalConfiguration.php | grep blablupp
- rm -f $TYPO3_PATH_WEB/typo3conf/PackageStates.php && ./typo3cms install:generatepackagestates && [ -f "$TYPO3_PATH_WEB/typo3conf/PackageStates.php" ]
- rm $TYPO3_PATH_WEB/typo3temp/index.html && ./typo3cms install:fixfolderstructure && [ -f "$TYPO3_PATH_WEB/typo3temp/index.html" ]

after_script:
- >
Expand Down
27 changes: 23 additions & 4 deletions Classes/Composer/InstallerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static function setupConsole(ScriptEvent $event, $calledFromPlugin = fals
$config = self::getConfig($event);
$installDir = self::getInstallDir($config);
$webDir = self::getWebDir($config);
$relativeWebDir = substr($webDir, strlen($installDir) + 1);
$filesystem = new Filesystem();

// Special treatment if we are root package (for development and testing)
Expand All @@ -60,9 +59,21 @@ public static function setupConsole(ScriptEvent $event, $calledFromPlugin = fals
$filesystem->symlink($installDir, $consoleDir);
}
}

$scriptName = self::isWindowsOs() ? 'typo3cms.bat' : 'typo3cms';
$success = self::safeCopy($webDir . '/' . self::BINARY_PATH . $scriptName, $installDir . '/' . $scriptName, $relativeWebDir);
if (self::isWindowsOs()) {
$scriptName = 'typo3cms.bat';
$success = self::safeCopy($webDir . '/' . self::BINARY_PATH . $scriptName, $webDir . '/' . $scriptName);
} else {
$scriptName = 'typo3cms';
$targetPath = $installDir . '/' . $scriptName;
if (file_exists($targetPath) && self::isTypo3CmsBinary($targetPath)) {
$success = @unlink($targetPath);
} else {
$success = true;
}
if ($success) {
$filesystem->symlink($webDir . '/' . self::BINARY_PATH . $scriptName, $targetPath, false);
}
}
if (!$success) {
$event->getIO()->write('<error>' . sprintf(self::COPY_FAILED_MESSAGE_TITLE, $scriptName, $installDir) . '</error>');
$event->getIO()->write('<error>' . sprintf(self::COPY_FAILED_MESSAGE, $scriptName) . '</error>');
Expand Down Expand Up @@ -128,6 +139,14 @@ protected static function safeCopy($fullSourcePath, $fullTargetPath, $relativeWe
return $success;
}

protected static function isTypo3CmsBinary($fullTargetPath)
{
if (is_link($fullTargetPath) || strpos(file_get_contents($fullTargetPath), 'typo3cms.php') !== false) {
return true;
}
return false;
}

/**
* Returns true if PHP runs on Windows OS
*
Expand Down
43 changes: 6 additions & 37 deletions Scripts/typo3cms
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
#!/usr/bin/env php
<?php
// Exit early if php requirement is not satisfied.
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
echo 'This version of TYPO3 Console requires PHP 5.5.0 or above!' . PHP_EOL;
if (defined('PHP_BINARY')) {
echo 'Your PHP binary is located at: "' . PHP_BINARY . '",' . PHP_EOL;
echo 'but its version is only: ' . PHP_VERSION . PHP_EOL;
} else {
echo 'Your PHP version is: ' . PHP_VERSION . PHP_EOL;

}
echo PHP_EOL . 'Please specify a suitable PHP cli binary before the typo3cms binary like that:' . PHP_EOL;
echo '/path/to/php55-latest ' . $_SERVER['argv'][0] . PHP_EOL;
exit(1);
}

if ('{$relative-web-dir}' === '{$relative' . '-web-dir}') {
echo 'This script has been copied manually (or by a copy command in a composer script section) and will not work!' . PHP_EOL;
echo 'Please rely on the plugin or the TYPO3 extension manager to copy the script automatically and remove manual copy commands from your composer script section!' . PHP_EOL;
exit(1);
}

if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . __DIR__ . '/{$relative-web-dir}');
}
putenv('TYPO3_PATH_WEB=' . rtrim(getenv('TYPO3_PATH_WEB'), '\\/'));

/**
* Load main entry script or exit with error
*/
if (file_exists(getenv('TYPO3_PATH_WEB') . '/typo3conf/ext/typo3_console/Scripts/typo3cms.php')) {
require getenv('TYPO3_PATH_WEB') . '/typo3conf/ext/typo3_console/Scripts/typo3cms.php';
} else {
echo 'Could not find typo3cms.php, make sure your path is within a TYPO3 installation'
. PHP_EOL
. 'and/or EXT:typo3_console is installed with extension manager or with the composer script.'
. PHP_EOL;
exit(1);
if (file_exists(__DIR__ . '/typo3cms.php')) {
require __DIR__ . '/typo3cms.php';
} elseif (file_exists(__DIR__ . '/typo3conf/ext/typo3_console/Scripts/typo3cms.php')) {
require __DIR__ . '/typo3conf/ext/typo3_console/Scripts/typo3cms.php';
}
echo 'Could not find console! Make sure typo3cms binary is up to date!' . PHP_EOL;
exit(1);
30 changes: 23 additions & 7 deletions Scripts/typo3cms.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
<?php
call_user_func(function () {
// The following checks are safeguards to identify issues with outdated typo3cms binaries
// Check again if php requirement is satisfied.
// Exit early if php requirement is not satisfied.
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
echo 'This version of TYPO3 Console requires PHP 5.5.0 or above!' . PHP_EOL;
if (defined('PHP_BINARY')) {
echo 'Your PHP binary is located at: "' . PHP_BINARY . '",' . PHP_EOL;
echo 'but its version is only: ' . PHP_VERSION . PHP_EOL;
} else {
echo 'Your PHP version is: ' . PHP_VERSION . PHP_EOL;
}
echo PHP_EOL . 'Please specify a suitable PHP cli binary before the typo3cms binary like that:' . PHP_EOL;
echo '/path/to/php55-latest ' . $_SERVER['argv'][0] . PHP_EOL;
exit(1);
}
// Check again if path is set correctly.

if (getenv('TYPO3_PATH_WEB')) {
// In case we are symlinked (like for travis tests),
// we need to accept the location from the outside to find the autoload.php
$typo3Root = getenv('TYPO3_PATH_WEB');
} else {
// Not symlinked (hopefully), so we can assume the docroot from the location of this file
$typo3Root = __DIR__ . '/../../../..';
}

$classLoader = require_once realpath($typo3Root . '/typo3') . '/../vendor/autoload.php';

if (!getenv('TYPO3_PATH_WEB')) {
echo 'Could not find TYPO3 installation root path! Make sure TYPO3_PATH_WEB environment variable is set correctly and your typo3cms binary is up to date!' . PHP_EOL;
exit(1);
// Fallback to binary location in document root, if the plugin was not available (non composer mode)
putenv('TYPO3_PATH_WEB=' . $typo3Root);
}

define('PATH_site', strtr(getenv('TYPO3_PATH_WEB'), '\\', '/') . '/');
define('PATH_thisScript', realpath(PATH_site . 'typo3/cli_dispatch.phpsh'));

$classLoader = require_once realpath(PATH_site . 'typo3/../') . '/vendor/autoload.php';

require __DIR__ . '/../Classes/Core/ConsoleBootstrap.php';
$bootstrap = new \Helhum\Typo3Console\Core\ConsoleBootstrap(getenv('TYPO3_CONTEXT') ?: 'Production');
$bootstrap->run($classLoader);
Expand Down