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

Allow to place and n98-magerun2.phar directly in a Magento installation without --root-dir option #1305

Closed
kanevbg opened this issue Sep 26, 2023 · 14 comments
Milestone

Comments

@kanevbg
Copy link

kanevbg commented Sep 26, 2023

Magento version: 2.4.6
magerun version: 7.1.0

Command used:

php81 -c ~/deps/shared/php-cli.ini -d memory_limit=-1 ~/deps/current/bin/n98-magerun2.phar db:query "SHOW TABLES;" -v

Exception trace:

at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Util/Console/Helper/DatabaseHelper.php:74
 N98\Util\Console\Helper\DatabaseHelper->detectDbSettings() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Magento/Command/Database/AbstractDatabaseCommand.php:63
 N98\Magento\Command\Database\AbstractDatabaseCommand->detectDbSettings() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Magento/Command/Database/QueryCommand.php:72
 N98\Magento\Command\Database\QueryCommand->execute() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/vendor/symfony/console/Command/Command.php:298
 Symfony\Component\Console\Command\Command->run() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Magento/Command/AbstractMagentoCommand.php:249
 N98\Magento\Command\AbstractMagentoCommand->run() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/vendor/symfony/console/Application.php:1058
 Symfony\Component\Console\Application->doRunCommand() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/vendor/symfony/console/Application.php:301
 Symfony\Component\Console\Application->doRun() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Magento/Application.php:254
 N98\Magento\Application->doRun() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/vendor/symfony/console/Application.php:171
 Symfony\Component\Console\Application->run() at phar:///home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar/src/N98/Magento/Application.php:363
 N98\Magento\Application->run() at /home/project/deps/releases/6a70878_1695663999/bin/n98-magerun2.phar:8

db:query [--connection CONNECTION] [--only-command] [--] [<query>]

related part of env.php:

<?php
return [
	// .......
    'db' => [
		'table_prefix' => '',
        'connection' => [
            'default' => [
                'host' => '127.0.0.1:3307',
                'dbname' => 'project',
                'username' => 'project',
                'password' => '***********',
                'model' => 'mysql4',
                'engine' => 'innodb',
                'initStatements' => 'SET NAMES utf8mb3;',
                'active' => '1',
                'driver_options' => [
                    1014 => false
                ],
                'profiler' => [
                    'class' => 'Magento\\Framework\\DB\\Profiler',
                    'enabled' => true
                ]
            ]
		]
    ],
	// ......
];

PS: there is "TODO" comment at src/N98/Util/Console/Helper/DatabaseHelper.php:71, which may be related:
image

@cmuench
Copy link
Member

cmuench commented Sep 27, 2023

@kanevbg Can you check if the sys:info works?

@kanevbg
Copy link
Author

kanevbg commented Sep 27, 2023

@cmuench

php81 -c ~/deps/shared/php-cli.ini -d memory_limit=-1 ~/deps/current/bin/n98-magerun2.phar sys:info -v
In AbstractMagentoCommand.php line 166:
                                                          
  [Symfony\Component\Console\Exception\RuntimeException]  
  Magento folder could not be detected

@cmuench
Copy link
Member

cmuench commented Sep 27, 2023

@Could it be that your current working directory is not in the shop project?
If yes, then try to set the root path with the --root-dir option.

@kanevbg
Copy link
Author

kanevbg commented Sep 27, 2023

Yes, it is. The suggested CLI option solves the main issue, but please consider it work around, as it's causing bad UX. It will help me and thank you for being active on the issue. Here is the output:

php81 -c ~/deps/shared/php-cli.ini -d memory_limit=-1 ~/deps/current/bin/n98-magerun2.phar sys:info --root-dir ~/deps/current/ -v
**Magento Core Commands cannot be loaded. Please verify if "bin/magento" is running.**
Run with -vvv option to see the error output.
Only n98-magerun2 commands are available until the issue is fixed.

                              
  Magento System Information  
                              
.... specifics here ....

I marked as bold the message above, which is likely a second issue with the concrete work-around.

@cmuench
Copy link
Member

cmuench commented Sep 27, 2023

@kanevbg that's how it's supposed to work. If you are inside the shop it's finding the shop root.
If you are outside the shop, then you can define the root. The tool can work with several installations on your machine. If you have always one installation a solution is to define a bash alias with the root-dir option set.

Also you can make the phar file executable and move it to e.g. /usr/local/bin/n98-magerun2.phar (depending on the $PATH variable).
Then you can execute the phar from everywhere without a complex call like in your example.

@kanevbg
Copy link
Author

kanevbg commented Sep 27, 2023

Would not you like to work like bin/magento?

@cmuench
Copy link
Member

cmuench commented Sep 27, 2023

@kanevbg n98-magerun2 can execute bin/magento command but provide own features.
What's missing?

@kanevbg
Copy link
Author

kanevbg commented Sep 28, 2023

I mean that if for bin/magento is possible to locate the DOC_ROOT of Magento:

[project@srv03 ~]$ php81 -c ~/deps/shared/php-cli.ini -d memory_limit=-1 ~/deps/current/bin/magento app:config:status
Config files are up to date.

than it will be practical for us to have the same capability for bin/n98-magerun2.phar.
The --doc-root argument can still be available.
And one more suggestion - when there is issue with finding the document root, than the tool can advertise it's --doc-root option to achieve better UX.

@cmuench
Copy link
Member

cmuench commented Sep 28, 2023

@kanevbg I created a small video which demonstrates the idea behind the tool.
https://www.youtube.com/watch?v=Ob608NnIEKA

@kanevbg
Copy link
Author

kanevbg commented Sep 28, 2023

I see your point being that it's a global install, but that's not required, right?
If I put it at bin directory of Magento 2 installation, it will be practical to be able to find the root without requiring me to add --root-dir.
Thanks for your time.

@cmuench
Copy link
Member

cmuench commented Sep 28, 2023

OK. I understand your point here.
Let's see if we can support that. There is also a logic which checks for sub-directories.
List of directories is defined by config (can be extended)

detect:

I have to check if that can conflict.

@cmuench cmuench changed the title RuntimeException: DB settings was not found in app/etc/env.php file Allow to place and n98-magerun2.phar directly in a Magento installation without --root-dir option Sep 28, 2023
@cmuench
Copy link
Member

cmuench commented Sep 28, 2023

@kanevbg I did some experiments and created a PR as draft.
This logic has to be tested very well, because it's changing the behavior.

You can download the phar file (inside the zip) with the changed logic if you want to test:

https://nightly.link/netz98/n98-magerun2/actions/artifacts/952569521.zip

@kanevbg
Copy link
Author

kanevbg commented Oct 25, 2023

@cmuench sorry for the late response. I confirmed that the build you provided works as expected.

@cmuench
Copy link
Member

cmuench commented Dec 16, 2023

@kanevbg we will deploy that with the upcoming 7.3.0 release.

@cmuench cmuench closed this as completed Dec 16, 2023
@cmuench cmuench added this to the 7.3.0 milestone Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants