/** * Generate connections for a specific connection type. * * @subcommand generate-connections * @synopsis <connection-type> [--items] */ function generate_connections($args, $assoc_args) { list($connection_type) = $args; $ctype = p2p_type($connection_type); if (!$ctype) { WP_CLI::error("'{$connection_type}' is not a registered connection type."); } if (isset($assoc_args['items'])) { foreach (_p2p_extract_post_types($ctype->side) as $ptype) { $assoc_args = array('post_type' => $ptype); WP_CLI::launch('wp post generate' . \WP_CLI\Utils\assoc_args_to_str($assoc_args)); } } $count = $this->_generate_c($ctype); WP_CLI::success("Created {$count} connections."); }
/** * Launch another WP-CLI command using the runtime arguments for the current process * * @param string Command to call * @param array $args Positional arguments to use * @param array $assoc_args Associative arguments to use * @param bool Whether to exit if the command returns an error status * @param bool Whether to return an exit status (default) or detailed execution results * @param array $runtime_args Override one or more global args (path,url,user,allow-root) * * @return int|ProcessRun The command exit status, or a ProcessRun instance */ public static function launch_self($command, $args = array(), $assoc_args = array(), $exit_on_error = true, $return_detailed = false, $runtime_args = array()) { $reused_runtime_args = array('path', 'url', 'user', 'allow-root'); foreach ($reused_runtime_args as $key) { if (isset($runtime_args[$key])) { $assoc_args[$key] = $runtime_args[$key]; } else { if ($value = self::get_runner()->config[$key]) { $assoc_args[$key] = $value; } } } $php_bin = self::get_php_binary(); $script_path = $GLOBALS['argv'][0]; $args = implode(' ', array_map('escapeshellarg', $args)); $assoc_args = \WP_CLI\Utils\assoc_args_to_str($assoc_args); $full_command = "{$php_bin} {$script_path} {$command} {$args} {$assoc_args}"; return self::launch($full_command, $exit_on_error, $return_detailed); }