Local Community

Trouble running WP-CLI db commands trough LocalMain


I think I’ve figured out how to run wp cli commands from a custom Add on:

import { getServiceContainer } from '@getflywheel/local/main';
getServiceContainer().cradle.wpCli.run( ...

Doing things like:
SiteData.getSite(siteId), ['plugin', 'install', 'woocommerce']

But if i try running doing something like:
SiteData.getSite(siteId), ['db', 'import', 'path/to/file/filename.sql']
The response is an error and db is not imported.
Tried simpler command like db clean --yes it also fails.

Tried running the cmd that this thing runs, gives me an error:
Access denied for user 'root'@'localhost' (using password: YES)

Is it not possible to run wp db commands trough this? Any other way of doing a db import?

Using LocalMain.getServiceContainer().cradle.wpCli.run() in a composer based project (like bedrock) where WordPress is in a sub-directory results in Error: This does not seem to be a WordPress installation.

Your CLI example helped me solve a problem I had, thanks for that. Sorry I could not help you solve your own problem :frowning:

1 Like