Skip to content

Commit

Permalink
Merge pull request #171 from christianwach/cli-fix
Browse files Browse the repository at this point in the history
Set CMS Root in "civicrm_paths" more reliably
  • Loading branch information
kcristiano authored Nov 25, 2019
2 parents 2f910d9 + 4211178 commit 16629b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
9 changes: 9 additions & 0 deletions civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ public function setup_instance() {
session_start();
}

/*
* AJAX calls do not set the 'cms.root' item, so make sure it is set here so
* the CiviCRM doesn't fall back on flaky directory traversal code.
*/
global $civicrm_paths;
if (empty($civicrm_paths['cms.root']['path'])) {
$civicrm_paths['cms.root']['path'] = untrailingslashit(ABSPATH);
}

// Get classes and instantiate
$this->include_files();

Expand Down
19 changes: 12 additions & 7 deletions wp-cli/civicrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ public function __invoke( $args, $assoc_args ) {
return WP_CLI::error( "Unrecognized command - '$command'" );
}

# if --path is set, save for later use by Civi
global $civicrm_paths;
$wp_cli_config = WP_CLI::get_config();
if (!empty($wp_cli_config['path'])) {
$civicrm_paths['cms.root']['path'] = $wp_cli_config['path'];
}

# run command
return $this->{$command_router[ $command ]}();

Expand Down Expand Up @@ -1331,4 +1324,16 @@ private function unzip( $destination_path, $option = 'zipfile' ) {
WP_CLI::add_command( 'civicrm', 'CiviCRM_Command' );
WP_CLI::add_command( 'cv', 'CiviCRM_Command' );

# Set path early.
WP_CLI::add_hook( 'before_wp_load', function() {

# if --path is set, save for later use by Civi
global $civicrm_paths;
$wp_cli_config = WP_CLI::get_config();
if (!empty($wp_cli_config['path'])) {
$civicrm_paths['cms.root']['path'] = $wp_cli_config['path'];
}

} );

}

0 comments on commit 16629b8

Please sign in to comment.