contao / manager-bundle

[READ-ONLY] Contao Manager Bundle
GNU Lesser General Public License v3.0
17 stars 10 forks source link

contao-console does not work under Windows #25

Closed fritzmg closed 7 years ago

fritzmg commented 7 years ago

When installing the managed edition via composer create-project or when simply directly calling

php vendor/bin/contao-console contao:install

you will only get an output like this:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../contao/manager-bundle/bin" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m "$dir");
fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/contao-console" "$@"

under Windows.

The same problem also happened with the (old) build method of the Contao Manager, see https://community.contao.org/de/showthread.php?65512-Composer-Nutzung-vereinfachen&p=431181&viewfull=1#post431181

There the problem could be circumvented by using …/pharpiler.bat instead of php …/pharpiler. However, no batch file exists for contao-console.

See also https://community.contao.org/de/showthread.php?66201-Contao-4-3-mit-Composer-und-einem-RockSolid-Theme-installieren-schl%C3%A4gt-fehl

leofeyer commented 7 years ago

Does #15 solve this issue?

fritzmg commented 7 years ago

I totally forgot about #15, but I think this would only solve the problem after using composer create-project or composer install or composer update. Using php vendor/bin/contao-console contao:install directly would still not work under Windows.

aschempp commented 7 years ago

Is the problem fixed if you do not prepend with php?

fritzmg commented 7 years ago

It seems to have been fixed by Contao 4.3.8 (#15 ?) anyway :).

php vendor/bin/contao-console contao:install

works now.

e.g. it gives the following output:


 Added/updated the system/initialize.php file.
aschempp commented 7 years ago

Well #15 has not been merged, so maybe it was a change in Composer…?

fritzmg commented 7 years ago

Hm, I see.

I don't think this has anything to do with the Composer? vendor/bin/contao-console does not seem to use anything from Composer. I am not sure why it works all of a sudden.

aschempp commented 7 years ago

It sure is from Composer! The binaries are registered in the composer.json (see https://getcomposer.org/doc/articles/vendor-binaries.md) and apparently Composer creates a strange .bat file on Windows.

fritzmg commented 7 years ago

But this file is not generated by me - it's already in the download archive of the managed edition from contao.org.

aschempp commented 7 years ago

Well your initial description says your running composer create-project. The ZIP is probably why it works now…

fritzmg commented 7 years ago

Aaah, right - I only tested the download archive now, not the manage-edition installed via create-project. I'll test again later with create-project.

fritzmg commented 7 years ago

Indeed, when using

composer create-project contao/managed-edition

the console command

php vendor/bin/contao-console …

will not work, as described in the initial post. When downloading the managed edition from contao.org, it will work (since the script was not generated as a batch script by Composer there, as @aschempp described).

I can confirm that #15 fixes the issue of the errorneous output directly after every composer operation (update, install and create-project for instance). And other than that, you simply have to use

vendor/bin/contao-console …

instead of

php vendor/bin/contao-console …

when on Windows. This could simply be documented.

m-vo commented 7 years ago

After my last composer update (4.3.10) this reapeared again. To test what changed I added the packages that got updated one after another as conflicting but even after removing all the problem persists.

Console output for composer operations (when ScriptHandler::initializeApplication() gets called):

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../contao/manager-bundle/bin" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

[...]

The above gets output once for each of the following lines in initializeApplication():

static::addWebEntryPoints($event);

static::executeCommand('cache:clear', $event);
static::executeCommand('assets:install --symlink --relative', $event);

static::executeCommand('contao:install', $event);
static::executeCommand('contao:symlinks', $event);

What has changed? Calling the commands directly via the command line does work.

fritzmg commented 7 years ago

@m-vo see https://github.com/contao/manager-bundle/pull/15

The PR has been merged into the develop branch and will be released with Contao 4.4.0. Until then, you have to manually execute the post update scripts with

vendor/bin/contao-console …
leofeyer commented 7 years ago

If you can confirm that #15 fixes the issue on Windows, we can back port the changes to the 4.3 branch.

fritzmg commented 7 years ago

I confirmed it too (see https://github.com/contao/manager-bundle/issues/25#issuecomment-297016269).

m-vo commented 7 years ago

Yep, https://github.com/contao/manager-bundle/pull/15 solves the problem. But I wonder why it worked before?

Ainschy commented 6 years ago

Bitte noch mal unter Windows anschauen, der Fehler taucht wieder auf. Contao 4.4.24 / PHP 7.1.7 / Contao Manager 1.0.4

E:\MAMP_2018\htdocs_eb>php vendor\bin\contao-console cache:warmup dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../contao/manager-bundle/bin" && pwd) if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then # We are in Cgywin using Windows php, so the path must be translated dir=$(cygpath -m "$dir"); fi "${dir}/contao-console" "$@"

aschempp commented 6 years ago

Der Contao Manager führt eigentlich keinen Befehl unter vendor\bin\contao-console mehr aus, hast du das selber gestartet?

Ainschy commented 6 years ago

Ja, den hab ich selbst über Konsole gestartet. Ist aber nur ein Beispiel da ich z.B. die Zugangsdaten für app_dev setzten wollte und die gleiche Meldung bekam.

Im Contao Manager werden absolute Pfade in Anführungszeichen verwendet, damit läuft er unter Windows.

aschempp commented 6 years ago

Nein, das Script funktioniert so einfach nicht auf Windows. Der Manager verwendet seit der Änderung direkt das Binary unter vendor/contao/manager-bundle/bin/contao-console, da Composer ein Alias für die Windows Shell erzeugt. Somit => kein Problem des Managers 😉

fritzmg commented 6 years ago

@Ainschy du musst vendor/bin/contao-console verwenden, also ohne php (das führt die vendor/bin/contao-console.bat aus).

Ainschy commented 6 years ago

Danke @fritzmg hab ich nicht gesehen, das der PHP Aufruf weggelassen werden muss.

zonky2 commented 6 years ago

unter Windows muss der Aufruf dann so aussehen: vendor\bin\contao-console ...

ansonsten wird der Befehl "vendor" gesucht...