In order to upgrade CiviCRM for WordPress from the command line on a remote server, I just installed wp-cli following the instructions at https://wp-cli.org/.
Warning: file_get_contents(/home/myhome/www/wp-content/plugins/civicrm/wp-cli//civicrm.settings.php): failed to open stream: No such file or directory in /home/myhome/www/wp-content/plugins/civicrm/wp-cli/civicrm.php on line 946The upgrade process involves - 1. Backing up current CiviCRM code as => /home/myhome/www/../backup/plugins/20220412055134/civicrm2. Backing up database as => /home/myhome/www/../backup/plugins/20220412055134/civicrm.sql3. Unpacking tarfile to => /home/myhome/www/wp-content/plugins/4. Executing civicrm/upgrade?reset=1 just as a browser would.Do you really want to continue? [y/n] ySuccess: 1. Code backed up.mysqldump: Got error: 2002: "Can't connect to MySQL server on 'myftpuser-001.privatesql' (115)" when trying to connect
I have been told this happens because the configuration file necessary to access the database is no more there when you try to backup the database.
If that is true, a possible solution would be to change the order of the operations: first backup the database, and then backup the code.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
@PierreF Thanks for the report. I've been looking at this today and, as @kcristiano did, can confirm that the upgrade command is broken. It looks to me as though the restore command is also likely to be broken.
One of the reasons the command fails is that the WP-CLI script predates the change of location for civicrm.settings.php from the CiviCRM plugin directory to the wp-content/uploads/civicrm directory and the command doesn't properly take this change of location into account.
I also agree with @kcristiano that the WP-CLI script should be given its own repo and be made into a separate plugin since it seems inherently fragile to perform operations as drastic as the restore and upgrade from within the plugin being modified.
There's also the strange conundrum that any fixes for the upgrade command will only be available in future versions of CiviCRM and therefore unavailable to the versions being upgraded. A separate plugin would solve this.
I know this doesn't fix the problem for you @PierreF but at least the scope of the issue is hopefully clearer.
@haystack : I saw there is no feedback here. I supposed the issue is not fixed. Am I the only one interested in upgrading civicrm from the command line? I wonder how can I trigger something to fix this issue.
I am not sure if you are the only one interested, but I had wanted (quite a while ago) for upgrade to trigger the download and then upgrade. The work to do this was more time than I had so I moved to a git workflow for the files and used a bash script to do all the work.
It is on my to-do list to get the wp-cli cv commands updated to match the native cv commands, but time has not made this possible.
@PierreF This repo https://github.com/christianwach/cli-tools-for-civicrm has the latest update script. @haystack has been working on it. I've recently tested update-db and it's working well. The upgrade script would need some work and it would include a call the wp cv sql-dump so we could do a backup.
I'd suggest looking at the plugin in this ticket as a place to start working on the changes that can then be merged back to core.
@kcristiano I saw the new code to update the database on the github repository, but my problem is to upgrade the civicrm module itself. I didn't find that in the new code.
@PierreF Before you spend what I can assure you will be quite a lot of time porting cv upgrade to wp civicrm upgrade, I feel I should make you aware of a few important caveats.
I would highly recommend looking at how I have recently ported cv install to wp civicrm install. It is a complicated and time-consuming process because the existing wp civicrm code:
did not have parity of functionality with cv
did not do proper error checking, and
did not make proper use of the WordPress and WP-CLI environment.
The new install command fixes most (if not all) of these previous shortcomings, though it still needs thorough testing.
Any code must also pass civilint tests because it will be ported to the CiviCRM-WordPress plugin. There's an .editorconfig file which your IDE should respect, but civilint is far more than "space-indenting instead of tab-indenting." It's worth a look at the CiviCRM docs, or follow the style of the code in the wp civicrm install command.
I would totally understand if you prefer not to take on such a huge task - be assured that I will port the code in due course. There are other ways to help out - testing the new code is by far the most important job that I do not have time for - so if you fancy giving that a go, then that would be greatly appreciated!
The new install command fixes most (if not all) of these previous shortcomings, though it still needs thorough testing.
As can be seen from the inline comments, I've left a trail of issues which I haven't yet resolved. Many of them are marked with TODO: so if you fancy something a little less heavy, that could be a place to start.
My intention was not to port cv upgrade to wp civicrm upgrade but to fix the existing command wp civicrm upgrade in order to work by changing the order
1. Backing up current CiviCRM code as => /home/myhome/www/../backup/plugins/20220412055134/civicrm2. Backing up database as => /home/myhome/www/../backup/plugins/20220412055134/civicrm.sql3. Unpacking tarfile to => /home/myhome/www/wp-content/plugins/4. Executing civicrm/upgrade?reset=1 just as a browser would.
into
1. Backing up database as => /home/myhome/www/../backup/plugins/20220412055134/civicrm.sql2. Backing up current CiviCRM code as => /home/myhome/www/../backup/plugins/20220412055134/civicrm3. Unpacking tarfile to => /home/myhome/www/wp-content/plugins/4. Executing civicrm/upgrade?reset=1 just as a browser would.
My intuition is that the backup operation of the code, marked originally as 1 above, is just renaming a directory which makes it impossible to access to the necessary files for the backup operation of the database marked as 2. I still have to verify if this is the case. My intuition can be wrong. Perhaps you know.
But porting cv upgrade to wp civicrm upgrade exceeds my skills and my availability in matters of time, I am sorry.
@PierreF Thanks for your review - I'm exactly not sure what's wrong with the existing command, but looking at your original post, I'm not sure that your syntax is correct. Have you tried this instead:
EDIT: Oh, scrap that - I do see problems with the existing command regardless of how you call it. However, your original syntax should look more like the above.
Warning: file_get_contents(/home/dmlekkv/www/wp-content/plugins/civicrm/wp-cli//civicrm.settings.php): failed to open stream: No such file or directory in /home/dmlekkv/www/wp-content/plugins/civicrm/wp-cli/civicrm.php on line 948The upgrade process involves:1. Backing up current CiviCRM code as => /homez.1619/dmlekkv/www/../backup/plugins/20230206151410/civicrm2. Backing up database as => /homez.1619/dmlekkv/www/../backup/plugins/20230206151410/civicrm.sql3. Unpacking tarfile to => /home/dmlekkv/www/wp-content/plugins/4. Executing "civicrm/upgrade?reset=1" just as a browser would.Do you really want to continue? [y/n] ySuccess: 1. Code backed up.mysqldump: Got error: 2002: "Can't connect to MySQL server on 'fp275524-001.privatesql' (115)" when trying to connect
After that, all the menu entries referring to CiviCRM disappeared from the website. So, my version of the script is really broken.
Luckily, I could restore CiviCRM by executing my backup/restore plugin UpdraftPlus first to delete old directories and then to restore the plugins.
Once you have the wp civicrm command replaced with the new one, you'll find each command extensively documented. Try wp help civicrm <command>, wp help civicrm core <command>, wp help civicrm db <command> etc for details.
I installed the plugin cli-tools-for-civicrm and the corresponding Must Use plugin. I removed the wp-cli.phar command I downloaded earlier and its alias wp, which was probably the bad guy. My doubt is now: there is no more wp executable on the host. I don't find any wp executable in the cli-tools-for-civicrm package. I don't find anything about this in the docs. Or did I have to keep the wp command itself hoping that only the subcommand wp civicrm would be updated?
The plugin isn't a replacement for WP-CLI itself - it simply replaces the commands supplied in the CiviCRM plugin with its own commands. You should definitely install WP-CLI again otherwise you can't run any wp <command>s.
I start to understand. I reinstalled wp. The only method that worked for me to get wp using the new set of subcommands, was to edit wp-config.php. I still have issues because several of the wp civicrm commands need to issue HTTPS requests, which are blocked on my server. I probably will have to bypass this with a proxy.
@PierreF I'm closing this because Command Line Tools for CiviCRM fixes the problem and the relevant code will be ported to CiviCRM-WordPress in due course. Thanks for reporting the issue.