diff --git a/features/jetpack-crm.php b/features/jetpack-crm.php index 00c34aa..3b7d55c 100644 --- a/features/jetpack-crm.php +++ b/features/jetpack-crm.php @@ -15,6 +15,8 @@ function () { 'jpcrm' => false, 'jpcrm-build' => false, 'jpcrm-version' => false, + 'jpcrm-populate-crm-data' => false, + 'jpcrm-populate-woo-data' => false, ); add_action( @@ -48,6 +50,16 @@ function ( &$app, $features, $domain ) use ( $defaults ) { } + if ( $features['jpcrm-populate-crm-data'] || $features['jpcrm-populate-woo-data'] ) { + add_jpcrm_sdg(); + if ( $features['jpcrm-populate-crm-data'] ) { + populate_crm_data(); + } + if ( $features['jpcrm-populate-woo-data'] ) { + populate_woo_data(); + } + } + }, 10, 3 @@ -69,6 +81,14 @@ function ( $features, $json_params ) { $features['jpcrm-build'] = $json_params['jpcrm-build']; } + if ( isset( $json_params['jpcrm-populate-crm-data'] ) ) { + $features['jpcrm-populate-crm-data'] = $json_params['jpcrm-populate-crm-data']; + } + + if ( isset( $json_params['jpcrm-populate-woo-data'] ) ) { + $features['jpcrm-populate-woo-data'] = $json_params['jpcrm-populate-woo-data']; + } + return $features; }, 10, @@ -101,11 +121,11 @@ function ( $s ) use ( $cmd ) { } /** - * Installs and activates a specified build of Jetpack CRM from our custom build URL. + * Installs and activates a specified branch of Jetpack CRM from our custom build URL. * - * @param string $build Hash of build to use. + * @param string $branch name of branch to use. */ -function add_jpcrm_from_custom_build( $build ) { +function add_jpcrm_from_custom_build( $branch ) { // phpcs:disable Squiz.PHP.CommentedOutCode.Found @@ -117,11 +137,11 @@ function add_jpcrm_from_custom_build( $build ) { */ // phpcs:enable - $clean_build = str_replace( '/', '_', $build ); + $clean_branch = str_replace( '/', '_', $branch ); // note that this public link is in a public repo $jpcrm_build_base_url = 'https://jetpackcrm-builds.s3.amazonaws.com/builds/'; - $jpcrm_build_url = $jpcrm_build_base_url . 'zero-bs-crm-' . $clean_build . '.zip'; + $jpcrm_build_url = $jpcrm_build_base_url . 'zero-bs-crm-' . $clean_branch . '.zip'; $cmd = "wp plugin install $jpcrm_build_url --activate"; @@ -133,6 +153,50 @@ function ( $s ) use ( $cmd ) { ); } +/** + * Installs and activates Jetpack CRM Sample Data Generator. + */ +function add_jpcrm_sdg() { + $jpcrm_sdg_url = 'https://jetpackcrm-builds.s3.amazonaws.com/jpcrm-sdg/jpcrm-sdg.zip'; + + $cmd = "wp plugin install $jpcrm_sdg_url --activate"; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Populates Jetpack CRM with data from JPCRM SDG. + */ +function populate_crm_data() { + $cmd = 'wp jpcrmsdg --objtype=all'; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + +/** + * Populates Woo with data from JPCRM SDG. + */ +function populate_woo_data() { + $cmd = 'wp jpcrmsdg --objtype=woo'; + + add_filter( + 'jurassic_ninja_feature_command', + function ( $s ) use ( $cmd ) { + return "$s && $cmd"; + } + ); +} + /** * Register a shortcode which renders Jetpack Licensing controls suitable for SpecialOps usage. */ @@ -154,8 +218,30 @@ function () {
  • +
  • +
  • +