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

bin/console script must be update to work with composer install #10957

Closed
1 task done
kimtiago opened this issue Mar 13, 2022 · 17 comments · Fixed by #11039
Closed
1 task done

bin/console script must be update to work with composer install #10957

kimtiago opened this issue Mar 13, 2022 · 17 comments · Fixed by #11039
Labels
bug Issues or PR's relating to bugs composer Any bugs or PRs relating to composer essential This must be done to close the milestone regression A bug that broke something in the last release
Milestone

Comments

@kimtiago
Copy link

Mautic Version

4.2.x series

PHP version

7.4

What browsers are you seeing the problem on?

Not relevant

What happened?

I updated my mautic to version 4.2, and everything was ok, but i read about install mautic with composer to work well with marketplace, so i did.
mautic is working, but when trying to use console commands we receive the error in log output
i think its because the folder structure with composer was change

for information, the 'app' folder out of 'docroot' is empty, and i don't know if this folder must have some files

How can we reproduce this issue?

Step 1: Install mautic with composer
Step 2: run any command with console

Relevant log output

PHP Warning:  require_once(/var/www/vhosts/xxxxx/public_html/mautic/bin/../app/autoload.php): failed to open stream: No such file or directory in /var/www/vhosts/xxxxx/public_html/mautic/bin/console on line 21
PHP Fatal error:  require_once(): Failed opening required '/var/www/vhosts/xxxxx/public_html/mautic/bin/../app/autoload.php' (include_path='.:/opt/plesk/php/7.4/share/pear') in /var/www/vhosts/xxxxx/public_html/mautic/bin/console on line 21

Code of Conduct

  • I confirm that I have read and agree to follow this project's Code of Conduct
@kimtiago kimtiago added bug Issues or PR's relating to bugs needs-triage For new issues/PRs that need to be triaged labels Mar 13, 2022
@RCheesley
Copy link
Sponsor Member

RCheesley commented Mar 13, 2022

Adding link to Slack conversation about this: https://mautic.slack.com/archives/C01E8F6T2HM/p1646176681513219 - thanks for making the bug report @kimtiago :)

@nickveenhof @mollux have your team managed to address this issue? It's been reported by a few people now in the community, seemingly a bug in the scaffold setup?

cc @jonathandhn

@RCheesley RCheesley added regression A bug that broke something in the last release composer Any bugs or PRs relating to composer essential This must be done to close the milestone and removed needs-triage For new issues/PRs that need to be triaged labels Mar 13, 2022
@RCheesley RCheesley added this to the 4.2.1 milestone Mar 13, 2022
@jonathandhn
Copy link

jonathandhn commented Mar 13, 2022

A QUICK FIX

I've found some kind of a fix :
if bin/console is edited this way

defined('IN_MAUTIC_CONSOLE') or define('IN_MAUTIC_CONSOLE', 1);
define('MAUTIC_ROOT_DIR', dirname(__DIR__, 1 ));

require_once dirname(__DIR__, 1 ).'/docroot/app/autoload.php';
require_once dirname(__DIR__, 1 ).'/docroot/app/AppKernel.php';

and then docroot/app/autoload.php is edited this way :

$loader = require dirname(__DIR__, 2 ).'/vendor/autoload.php';

You will get a functional console.

TROUBLE SHOOTING

  1. Mautic scaffold stance "The scaffold tool automatically creates the required autoload.php file at the Mautic root as part of the scaffolding operation. This file should not be modified or customized in any way." and I can't figure a way to makes it works.
  2. Then, if I want to provide a patch for scaffold to apply to the console, the docs don't says a word about how to distribute it, it only show how to apply user provided patch, and I can't figure out how to edit the "mautic/recommended-project:^4" in order to provide and apply both a patch and a fix for docroot/app/autoload.php. My thoughts, If we want to distribute a patch, we must add the patch directly for all Mautic install in the core code base (the one downloaded by "mautic/recommended-project:^4"), in order to edit the composer.json asking for the provided patch to be applied. Actually, we still need to find what to do about docroot/app/autoload.php, apply a patch ? Even if the autoload.php is said autogenerated ? "The scaffold tool automatically creates the required autoload.php file at the Mautic root" may imply that the path is generated at the document root of the composer install, before being moved to docroot/ by Mautic scaffold, that can explain the wrong path.
  3. May I say more, I think it may be easier for a lot of peoples to move from something like realpath(DIR.'/..') to something like dirname(DIR, 1 ) in order to makes it easily readable. because /../../../ start to be hard to read.

@RCheesley
Copy link
Sponsor Member

RCheesley commented Mar 13, 2022

Yep, we just need to figure out the most elegant way to get this working for everyone using Composer (and to improve our documentation in this area).

I wasn't sure if you meant how to edit the file on GitHub or just generally? Here is how to make the PR on the recommended-project repo: https://watch.screencastify.com/v/WNfVUWrs1QMBdRAXdN7O

I did a bit of digging in the scaffold and it looks like the actual path for the autoload file is getting determined here: https://github.com/mautic/core-composer-scaffold/blob/833fdb5be95db1767b48d2dc572dac4d0691dbcf/GenerateAutoloadReferenceFile.php#L87 so perhaps this is where we need to tweak?

To make a PR there it's exactly the same process as I outlined in the video above, just with the different repository.

Hope this might give a few leads at least! I am no expert in this though, so defer to the wisdom of @nickveenhof who put together the original implementation based on the Drupal implementation of Composer.

As a side note, I also added some missing detail in this PR to the docs: mautic/mautic-documentation#303 which relates to enabling composer / marketplace in case you have a moment to review it and add an approval so we can get it merged (use Files Changed > Review Changes).

@danharper83
Copy link

I'm also having problems with this, effectively the composer create-project mautic/recommended-project:^4 doesn't work as it's not possible to run cron jobs or a scripted install after that point without manually modifying the above files. After modifying they just get overwritten each time you run composer update etc.

Should this be moved on to the https://github.com/mautic/core-composer-scaffold project?

@jonathandhn
Copy link

jonathandhn commented Mar 16, 2022 via email

@RCheesley RCheesley modified the milestones: 4.2.1, 4.2.2 Mar 28, 2022
@jonathandhn
Copy link

jonathandhn commented Mar 30, 2022

Hi, I've got some news :

Disclaimer : You could try on your own, this is not an approved fix

  1. First Download on your application root folder ( the folder containing your mautic composer project ) :
  1. Then on your application root folder in terminal CLI run the following command :
composer config --json scripts.post-mautic-scaffold-cmd "patch -p1 < 0001-A-patch-fix-for-console-in-composer-context-10957.patch && patch -p1 < 0001-A-patch-fix-for-autoload-in-composer-context-10957.patch && chmod 764 bin/console"

This will both apply the patch on each composer update run, and makes the console usable... Because it's always returning the console chmod to 664 that is not runnable.

Now @RCheesley I don't know what to do to distribute the patch to mautic users (or if the patch is the right way to go).

If the patch is the way to go, we may bundle it in mautic core file, and then update the recommended project 4 to distribute and install it with composer. ( I don't know if it's futur proof as I can't figure out if it may/can mess up the day the mautic core will upgrade the console file ).

EDITED WITH A SECOND PATCH FOR AUTOLOAD

@RCheesley
Copy link
Sponsor Member

Hi @jonathandhn - please take a look at our docs on how to create a pull request for Mautic - that is how we distribute things to Mautic users.

https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests

If you need a hand, please ask in #t-product and we'll be able to help!

@jonathandhn
Copy link

Thanks, the true question is that currently no patch are applied, nor provided by mautic, so I need an advice on where to host the patches in the mautic code base for composer to download theme easily and then I could propose a PR to the https://github.com/mautic/recommended-project to distribute the new composer settings.

@mautibot
Copy link

This issue has been mentioned on Mautic Community Forums. There might be relevant details there:

https://forum.mautic.org/t/console-not-working-after-converting-to-composer-on-4-2/23430/2

@zaharovrd
Copy link

i apply patch, but when i try run cache:clear i get

console.CRITICAL: Error thrown while running command "cache:clear -v". Message: "Failed to clear FilesystemTagAwareAdapter" {"exception":"[object] (Exception(code: 0): Failed to clear FilesystemTagAwareAdapter at /home/master/*************/recommended-project/docroot/app/bundles/CacheBundle/EventListener/CacheClearSubscriber.php:55)","command":"cache:clear -v","message":"Failed to clear FilesystemTagAwareAdapter"}

@PierreAmmeloot
Copy link
Contributor

@zaharovrd I think your issue is this issue : #9928

Pierre

@mautibot
Copy link

This issue has been mentioned on Mautic Community Forums. There might be relevant details there:

https://forum.mautic.org/t/cant-install-mautic-via-composer/23781/1

@olivierlambert
Copy link

Patches applied + running composer update fixed it on my side 👍 Thanks for the patches!

@RCheesley
Copy link
Sponsor Member

Hi folks, we actually have a PR to fix this: #11039

Please test with the latest version (4.2.2) and report back on the PR so we can merge it.

@trianity
Copy link

Hi @RCheesley , I did a fresh composer install of Mautic v.4.2.2 and the install process was correct. The Mautic application installed, running well.
The bin/console was broken without applying @jonathandhn 's patch mentioned above.
Applying the patch the cron jobs with bin/console are running without errors.

@jonathandhn
Copy link

jonathandhn commented Apr 28, 2022 via email

@RCheesley RCheesley modified the milestones: 4.2.2, 4.3 Apr 30, 2022
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If this issue is continuing with the lastest stable version of Mautic, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs composer Any bugs or PRs relating to composer essential This must be done to close the milestone regression A bug that broke something in the last release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants