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);
     }
 }
Example #2
0
 /**
  * Export a package
  *
  * $params['pod'] string Pod Type IDs to export
  * $params['template'] string Template IDs to export
  * $params['podpage'] string Pod Page IDs to export
  * $params['helper'] string Helper IDs to export
  *
  * @param array $params An associative array of parameters
  *
  * @return array|bool
  *
  * @since 1.9.0
  * @deprecated 2.0
  */
 public function export_package($params)
 {
     if (class_exists('Pods_Migrate_Packages')) {
         return Pods_Migrate_Packages::export($params);
     }
     return false;
 }
 /**
  * Deploy a package
  *
  * @since 0.3.0 ?
  *
  * @param array $params Pods_Migrate_Packages::export() params
  */
 private static function do_deploy($params)
 {
     $fail = false;
     $data = Pods_Migrate_Packages::export($params);
     $url = trailingslashit(self::$remote_url) . 'pods-components?package';
     $url = Pods_Deploy_Auth::add_to_url(self::$public_key, self::$token, $url);
     $response = wp_remote_post($url, array('method' => 'POST', 'body' => $data, 'timeout' => self::$timeout));
     $pod_name = '';
     $pod_list = array();
     foreach ($params as $param) {
         if (is_array($param)) {
             $pod_list = array_merge(array_flip($param), $pod_list);
         } else {
             array_push($pod_list, self::pod_name($param));
         }
     }
     $pod_name = pods_serial_comma($pod_list);
     if (self::check_return($response)) {
         echo self::output_message(__(sprintf('Package deployed successfully for %1s :)', $pod_name), 'pods-deploy'), $url);
         if (!$fail) {
             echo self::output_message(__('Deployment complete :)', 'pods-deploy'), $url);
         } else {
             echo self::output_message(__('Deployment completed with mixed results :|', 'pods-deploy'), $url, true, false);
         }
     } else {
         echo self::output_message(__(sprintf('Package could not be deployed for %1s:(', $pod_name), 'pods-deploy'), $url, true, false);
         var_dump($response);
     }
 }