/** * The deploy sequence * * @since 0.3.0 ? * * @param $deploy_params */ public static function deploy($deploy_params) { $remote_url = self::$remote_url = pods_v('remote_url', $deploy_params); $public_key = self::$public_key = pods_v('public_key', $deploy_params); $private_key = self::$private_key = pods_v('private_key', $deploy_params); $timeout = self::$timeout = pods_v('timeout', $deploy_params, 60); $deploy_types = self::$deploy_types = pods_v('deploy_types', $deploy_params, self::pod_types()); $token = self::$token = Pods_Deploy_Auth::generate_token($public_key, $private_key); if (!$remote_url || !$public_key || !$private_key) { echo self::output_message(__('Invalid parameters:( You shall not pass! ', 'pods-deploy'), '', false, false); return false; } $deploy_components = self::do_deploy_components(pods_v('components', $deploy_params)); if (false == $deploy_components) { echo self::output_message(__('Components could not be activated on remote site. Deployment aborted.', 'pods-deploy'), '', false, false); return false; } $fail = false; self::$elapsed_time = microtime(true); if (!class_exists('Pods_Migrate_Packages')) { return new WP_Error('pods-deploy-need-packages', __('You must activate the Packages Component on both the site sending and receiving this package.', 'pods-deploy')); } /** * If true, all Pods and Pages, Templates & Helpers will be migrated in one package. * * Means less request, but potentially a much bigger request. * * @param bool $all_at_once * * @since 0.5.0 */ $all_at_once = apply_filters('pods_deploy_deploy_in_one_package', false); // @todo Should this be an option on the form if (!$all_at_once) { foreach ($deploy_types as $type => $type_arr) { foreach ($type_arr as $type_id => $type_name) { self::do_deploy(array($type => array($type_name => $type_id))); } } } else { $flipped_types = array(); foreach ($deploy_types as $type => $type_arr) { $flipped_types[$type] = array_flip($type_arr); } self::do_deploy($flipped_types); } self::do_deploy_relationships($deploy_types); }
public static function deploy($remote_url, $public_key, $private_key) { $fail = false; self::$elapsed_time = microtime(true); if (!class_exists('Pods_Migrate_Packages')) { return new WP_Error('pods-deploy-need-packages', __('You must activate the Packages Component on both the site sending and receiving this package.', 'pods-deploy')); } //@todo add options for these params $params = array('pods' => true, 'templates' => true, 'page' => true, 'helpers' => true); $data = Pods_Migrate_Packages::export($params); $url = trailingslashit($remote_url) . 'pods-components?package'; $request_token = Pods_Deploy_Auth::generate_token($public_key, $private_key); $url = Pods_Deploy_Auth::add_to_url($public_key, $request_token, $url); $data = json_encode($data); $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data)); if (self::check_return($response)) { echo self::output_message(__('Package deployed successfully. ', 'pods-deploy'), $url); $responses = array(); $api = pods_api(); $params['names'] = true; $pod_names = $api->load_pods($params); $pod_names = array_flip($pod_names); $data = Pods_Deploy::get_relationships(); $pods_api_url = trailingslashit($remote_url) . 'pods-api/'; foreach ($pod_names as $pod_name) { $url = $pods_api_url . "{$pod_name}/update_rel"; $url = Pods_Deploy_Auth::add_to_url($public_key, $request_token, $url); $responses[] = $response = wp_remote_post($url, array('method' => 'POST', 'body' => json_encode($data))); if (self::check_return($response)) { echo self::output_message(__(sprintf('Relationships for the %1s Pod were updated.', $pod_name), 'pods-deploy'), $url); } else { $fail = true; echo self::output_message(__(sprintf('Relationships for the %1s Pod were not updated.', $pod_name), 'pods-deploy'), $url); var_dump($response); } } if (!$fail) { echo self::output_message(__('Deployment complete :)', 'pods-deploy')); } else { echo self::output_message(__('Deployment completed with mixed results :|', 'pods-deploy')); } } else { echo self::output_message(__('Package could not be deployed :(', 'pods-deploy')); var_dump($response); } }