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);
     }
 }
 /**
  * Include main UI view and add scope data into it.
  *
  * @since 0.4.0
  *
  * @return bool|string
  */
 function include_view()
 {
     $keys = Pods_Deploy_Auth::get_keys(true);
     $public_remote = pods_v_sanitized('public', $keys, '');
     $private_remote = pods_v_sanitized('private', $keys, '');
     $deploy_active = Pods_Deploy_Auth::deploy_active();
     wp_enqueue_style('pods-wizard');
     if ($deploy_active) {
         $key_gen_submit = __('Disable Deployments', 'pods-deploy');
         $key_gen_header = __('Click to revoke keys and prevent deployments to this site.', 'pods-deploy');
     } else {
         $key_gen_submit = __('Allow Deployments', 'pods-deploy');
         $key_gen_header = __('Click to generate new keys and allow deployments to this site', 'pods-deploy');
     }
     $form_fields = $this->form_fields();
     $data = compact(array('keys', 'public_local', 'private_local', 'public_remote', 'private_remote', 'deploy_active', 'key_gen_submit', 'key_gen_header', 'form_fields'));
     return pods_view(PODS_DEPLOY_DIR . 'ui/main.php', $data);
 }
예제 #3
0
function pods_deploy_deactivate()
{
    include_once PODS_DEPLOY_DIR . 'class-pods-deploy-auth.php';
    Pods_Deploy_Auth::revoke_keys();
    Pods_Deploy_Auth::clear_local_keys();
}
 /**
  * Update components
  *
  * @since 0.3.0 ?
  *
  * @param null $components
  *
  * @return array|bool|WP_Error
  */
 private static function do_deploy_components($components = null)
 {
     if (true === $components) {
         $components = self::active_components();
     }
     if (!is_array($components)) {
         $components = array('migrate-packages' => 'Migrate Packages');
     }
     if (!array_key_exists('migrate-packages', $components)) {
         $components['migrate-packages'] = 'Migrate Packages';
     }
     $url = trailingslashit(self::$remote_url) . 'pods-components';
     $url = Pods_Deploy_Auth::add_to_url(self::$public_key, self::$token, $url);
     $response = wp_remote_post($url, array('method' => 'GET', 'timeout' => self::$timeout));
     if (!self::check_return($response)) {
         echo self::output_message(__('Could not get activate components from remote site:(', 'pod-deploy'), $url, true, false);
         return false;
     } else {
         echo self::output_message(__('Remote site active components determined:)', 'pods-deploy'), $url);
     }
     $remote_components = json_decode(wp_remote_retrieve_body($response));
     if (!is_object($remote_components)) {
         $remote_components = array('migrate-packages');
     }
     $data = array();
     foreach ($components as $component => $label) {
         if (false == pods_v($component, $remote_components)) {
             $data[] = $component;
         }
     }
     if (!empty($data)) {
         $data = array('activate' => $data);
     }
     $response = wp_remote_post($url, array('method' => 'PUT', 'body' => json_encode($data), 'timeout' => self::$timeout));
     if (self::check_return($response)) {
         self::output_message(__('Successfully activated remote components.', 'pods-deploy'), $url);
     } else {
         self::output_message(__('Remote component activation failed.', 'pods-deploy'), $url, true, false);
         return false;
     }
     return $response;
 }
예제 #5
0
<?php

$keys = Pods_Deploy_Auth::get_keys(false);
$public_local = pods_v_sanitized('public', $keys, '');
$private_local = pods_v_sanitized('private', $keys, '');
$keys = Pods_Deploy_Auth::get_keys(true);
$public_remote = pods_v_sanitized('public', $keys, '');
$private_remote = pods_v_sanitized('private', $keys, '');
$deploy_active = Pods_Deploy_Auth::deploy_active();
if ($deploy_active) {
    $key_gen_submit = __('Disable Deployments', 'pods-deploy');
    $key_gen_header = __('Click to revoke keys and prevent deployments to this site.', 'pods-deploy');
} else {
    $key_gen_submit = __('Allow Deployments', 'pods-deploy');
    $key_gen_header = __('Click to generate new keys and allow deployments to this site', 'pods-deploy');
}
?>
<div class="wrap pods-admin">
	<form action="" method="post">

		<div id="icon-pods" class="icon32"><br /></div>

		<?php 
$default = 'deploy';
$tabs = array('deploy' => __('Deploy From This Site', 'pods-deploy'), 'key-gen' => __('Allow Deploying To This Site', 'pods-deploy'));
?>

		<h2 class="nav-tab-wrapper">
			<?php 
foreach ($tabs as $tab => $label) {
    $class = '';
예제 #6
0
/**
 * Allow remote deployments to site if enabled in UI and keys match.
 *
 * @since 0.3.0
 */
function pods_deploy_auth()
{
    if (get_option(Pods_Deploy_Auth::$allow_option_name, true)) {
        include_once PODS_DEPLOY_DIR . 'class-pods-deploy-auth.php';
        return Pods_Deploy_Auth::allow_access();
    }
}