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

CRM-20148 Fix WP-CLI installer #110

Merged
merged 6 commits into from
Apr 20, 2017
Merged

Conversation

agh1
Copy link
Contributor

@agh1 agh1 commented Feb 21, 2017

This pull request looks insane because of the style changes that I ran first because my editor was blowing up with PHP_CodeSniffer errors: wp-cli/civicrm.php was in neither CiviCRM/Drupal style nor WordPress style. This puts it in WordPress style.

The real business in here comes in 5612d6f, with a couple additional things in 72202de, so it would probably be easier to browse through those.

The result works with the following two commands:

  • wp civicrm install --dbhost=localhost --dbname=XXXX --dbpass=XXXX --dbuser=XXXX --site_url=example.com when CiviCRM is extracted in place and already activated in WordPress, and
  • wp civicrm install --dbhost=localhost --dbname=XXXX --dbpass=XXXX --dbuser=XXXX --site_url=example.com --zipfile=/path/to/civicrm-4.7.16-wordpress.zip --require=/somewhere/else/wp-cli/civicrm.php when CiviCRM is not present but the WP-CLI file is at /somewhere/else/wp-cli/civicrm.php.

However, I have only run this on plain vanilla WordPress installs.

It would be nice to have @kcristiano's feedback to make sure it's consistent with setups I'm not aware of and with work he's doing to improve the installation process in WordPress.


It's not happy with the variable name `$crmPath`, but it shouldn't be touched
since it's a global used elsewhere in CiviCRM.  It also doesn't like silencing
errors on running the `wp plugin activate civicrm` command.
@kcristiano
Copy link
Member

@agh1 Thanks for working on this.

I'll do the testing, to confirm the workflow.

I install WP,wp-cli and the civicrm wp-cli script. I tell wp-cli to include the civicrm script and run the install?

I ask as the bundled version won't work until the plugin is activated.

@agh1
Copy link
Contributor Author

agh1 commented Feb 21, 2017

There are two scenarios to work through. Both start with WP and WP-CLI installed.

In the first, download CiviCRM manually, extract it into the plugins directory, and activate the CiviCRM plugin, but don't run the installer. Then try the first command above. WP-CLI should have the CiviCRM commands because the plugin is enabled.

In the second, CiviCRM should not be in your site at all. Somewhere else on your machine you'll need the CiviCRM zip file (specified with --zipfile) and the wp-cli/civicrm.php file (specified with --require).

The problem was that the command looked for the folder with wp-cli/civicrm.php in trying to figure out where to install CiviCRM, and then said, "Holy shit, there's a folder here--we've got to quit!"

To make the first use case work (installing a site that's already in place), I basically removed the check of whether the CiviCRM folder exists. For the second use case (unzip and install), I made the command not assume that the plugin path is where the script is.

@agh1 agh1 changed the title Fix WP-CLI installer CRM-20148 Fix WP-CLI installer Feb 21, 2017
@kcristiano
Copy link
Member

Thanks, I am so used to using the 'yml' config files I didn't see the 'require' command line switch.

Apache 2.4, php 5.6.30 MySQL 5.7 running on a mac.

I am having trouble with the script. The extract works
wp cv install --dbhost=localhost --dbname=cvcli --dbpass=wp --dbuser=wp --site_url=https://cvcli.test --zipfile=~/Downloads/civicrm-4.7.16-wordpress.zip --require=/srv/www/cvcli/wp-content/uploads/wpcli/civicrm.php Extracting zip archive ... Success: Archive unpacked.

But then nothing. CiviCRM is in the proper place wp-content/plugins/civicrm but the install does not kick off.

If I run again:
wp cv install --dbhost=localhost --dbname=cvcli --dbpass=wp --dbuser=wp --site_url=https://cvcli.test --require=/srv/www/cvcli/wp-content/uploads/wpcli/civicrm.php Success: Using installer files found on the site.

The plugin is neither activated nor installed.

If I add activate_plugin( $crmPath . '/civicrm.php' ); at line 363 then the plugin is activated, but the installer does not launch.

Not sure why it's failing for me. Can you share details of your setup?

@agh1
Copy link
Contributor Author

agh1 commented Feb 27, 2017

Strange. I just tried it somewhere new just in case. Here's the complete procedure I used:

Starting with a working Wordpress site on Ubuntu 16.04 with PHP 7 and MariaDB 5.5, I used wget https://github.com/agh1/civicrm-wordpress/raw/84e5e53349b3349d3fb52c5bed4dffad25416e32/wp-cli/civicrm.php to download the wp-cli/civicrm.php file to /srv/www/installtest/civicrm.php, and I downloaded the regular CiviCRM zip file to /srv/www/installtest/civicrm-4.7.16-wordpress.zip. I went inside the site and did sudo -su www-data in order to act as www-data so as not to create files with weird owners. I then ran the following:
wp civicrm install --dbhost=localhost --dbname=installtest --dbpass=MYPASSWORD --dbuser=MYUSER --site_url=installtest.aghstrategies.com --zipfile=/srv/www/installtest/civicrm-4.7.16-wordpress.zip --require=/srv/www/installtest/civicrm.php

I was using the same database and credentials as the WordPress site. There were no civicrm_... tables, and there were no CiviCRM files in the site at all to begin with.

The response was

Extracting zip archive ...
Success: Archive unpacked.
Loading CiviCRM database structure ..
Loading CiviCRM database with required data ..
Success: CiviCRM database loaded successfully.
Generating civicrm settings file ..
Success: Settings file generated: /srv/www/installtest/public_html/wp-content/uploads/civicrm/civicrm.settings.php
Plugin 'civicrm' activated.
Success: Activated 1 of 1 plugins.
Success: CiviCRM installed.

Going into WordPress, the site is working like normal.

# create files dirs
$upload_dir = wp_upload_dir();
$settings_dir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
civicrm_setup( "$settings_dir" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a directory structure of wp-content/uploads/civicrm/civicrm/

I would change to:

$userFilesDir     = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
civicrm_setup( "$userFilesDir" );

We also get a wp-content/uploads/civicrm/files/ directory structure that does not happen in a normal install. While that will work, we should track that down to make the install consistent.

@kcristiano
Copy link
Member

@agh1 Thanks for the feedback. I tested again both on an Ubuntu 16.04 server and locally on a LAMP stack on a Mac.

If the site is http://installtest.dev the install works fine. If the site is https://installtest.dev the install fails.

In addition line 380 civicrm_setup( "$settings_dir" ); creates a directory structure of wp-content/uploads/civicrm/civicrm/

I would change to:

$userFilesDir     = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
civicrm_setup( "$userFilesDir" );

We also get a wp-content/uploads/civicrm/files/ directory structure that does not happen in a normal install. While that will work, we should track that down to make the install consistent.

}
$params = array(
'crmRoot' => $crmPath . '/',
'templateCompileDir' => "{$settings_dir}files/civicrm/templates_c",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'templateCompileDir' => "{$settings_dir}templates_c",

Appears to be proper setting for 4.7

@kcristiano
Copy link
Member

@agh1 so I missed the --ssl=on flag. Works on Ubuntu, still failing on my local Mac install.

I think that this is working to the point we should merge. Previous installer failed hard, this works. @totten @colemanw

@kcristiano
Copy link
Member

@agh1 can you look at the changes suggested and if you agree add to your branch?

@agh1
Copy link
Contributor Author

agh1 commented Apr 7, 2017

At long last I just incorporated the changes @kcristiano suggested, and I tested it with the following two scenarios, both starting with a just-installed WordPress site and no CiviCRM:

Install from activated plugin

  1. wget http://download.civicrm.org/civicrm-4.7.18-wordpress.zip -O /tmp/civicrm-4.7.18-wordpress.zip
  2. unzip /tmp/civicrm-4.7.18-wordpress.zip -d wp-content/plugins/
  3. wp plugin activate civicrm
  4. wp civicrm install --dbhost=localhost --dbname=XXXX --dbpass=XXXX --dbuser=XXXX --site_url=example.com

Install from zipfile and wp-cli/civicrm.php

  1. wget http://download.civicrm.org/civicrm-4.7.18-wordpress.zip -O /tmp/civicrm-4.7.18-wordpress.zip
  2. wget https://raw.githubusercontent.com/agh1/civicrm-wordpress/chicken-egg-install/wp-cli/civicrm.php -O ~/wp-cli-civicrm.php
  3. wp civicrm install --dbhost=localhost --dbname=XXXX --dbpass=XXXX --dbuser=XXXX --site_url=example.com --zipfile=/tmp/civicrm-4.7.18-wordpress.zip --require=~/wp-cli-civicrm.php

@kcristiano
Copy link
Member

Thanks @agh1 I'll run a test as soon as I can and would like to see this in the May release

@kcristiano
Copy link
Member

Retested and works perfectly.

@totten
Copy link
Member

totten commented Apr 20, 2017

If @agh1 and @kcristiano like it, then that'll work for me. ;)

@totten totten merged commit 63009a7 into civicrm:master Apr 20, 2017
jonesinator added a commit to jonesinator/civicrm-wordpress that referenced this pull request Aug 31, 2017
The entity and action were also being parsed as an invalid parameter.
This was fixed by shifting the args array after parsing them.

An unassigned $format variable was being referenced inside of the
default case for the switch statement if the --in option was neither
args nor json. This was fixed by assigning $format to the output of
getOption rather than switching on getOption directly.

The parameter matching regex had spaces added to it in pull request civicrm#110
that caused arguments of the format foo=bar to not be matched correctly,
so no parameters were actually being passed to the underlying api
method. The spaces were removed from the regex and the parsing worked.

Two other regex matches had spaces added to them by pull request civicrm#110
that I have not touched, but they seem suspect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants