コード例 #1
0
 /**
  * Batch has been successfully imported.
  *
  * @param Batch $batch
  */
 public function imported(Batch $batch)
 {
     $links = array();
     $output = '';
     $types = array('page', 'post');
     // Only keep published posts of type $types.
     $posts = array_filter($batch->get_posts(), function (Post $post) use($types) {
         return $post->get_post_status() == 'publish' && in_array($post->get_type(), $types);
     });
     // Create links for each of the posts.
     foreach ($posts as $post) {
         $post_id = $this->post_dao->get_id_by_guid($post->get_guid());
         $links[] = array('link' => get_permalink($post_id), 'title' => $post->get_title());
     }
     $links = apply_filters('sme_imported_post_links', $links);
     foreach ($links as $link) {
         $output .= '<li><a href="' . $link['link'] . '" target="_blank">' . $link['title'] . '</a></li>';
     }
     if ($output !== '') {
         $output = '<ul>' . $output . '</ul>';
         $message = '<h3>Posts deployed to ' . get_bloginfo('name') . ':</h3>' . $output;
         $this->api->add_deploy_message($batch->get_id(), $message, 'info', 102);
     }
     $this->api->add_deploy_message($batch->get_id(), 'Batch has been successfully imported!', 'success', 101);
 }
コード例 #2
0
 public function column_sme_batch_history(Batch $item)
 {
     $str = '';
     if (count($item->get_posts()) > 0) {
         foreach ($item->get_posts() as $post) {
             $str .= '<p>' . $post->get_title() . '</p>';
         }
     }
     return $str;
 }
コード例 #3
0
 /**
  * Verify that a post is ready for deploy.
  *
  * @param Post  $post
  * @param Batch $batch
  */
 public function verify_post(Post $post, Batch $batch)
 {
     /*
      * If more then one post is found when searching posts with a specific
      * GUID, then add an error message. Two or more posts should never share
      * the same GUID.
      */
     try {
         $revision = $this->post_dao->get_by_guid($post->get_guid());
     } catch (Exception $e) {
         $this->api->set_preflight_status($batch->get_id(), 2);
         $this->api->add_preflight_message($batch->get_id(), $e->getMessage(), 'error');
         return;
     }
     // Check if parent post exist on production or in batch.
     if (!$this->parent_post_exists($post, $batch->get_posts())) {
         // Fail pre-flight.
         $this->api->set_preflight_status($batch->get_id(), 2);
         // Admin URL of content stage.
         $admin_url = $batch->get_custom_data('sme_content_stage_admin_url');
         $message = sprintf('Post <a href="%s" target="_blank">%s</a> has a parent post that does not exist on production and is not part of this batch. Include post <a href="%s" target="_blank">%s</a> in this batch to resolve this issue.', $admin_url . 'post.php?post=' . $post->get_id() . '&action=edit', $post->get_title(), $admin_url . 'post.php?post=' . $post->get_parent()->get_id() . '&action=edit', $post->get_parent()->get_title());
         $this->api->add_preflight_message($batch->get_id(), $message, 'error');
         return;
     }
 }
コード例 #4
0
 /**
  * Add diff between stage post and production post.
  *
  * @param Post_Env_Diff $diff
  */
 private function add_post_diff(Post_Env_Diff $diff)
 {
     // Store diff if it does not already exist.
     if (!isset($this->post_diffs[$diff->get_stage_id()])) {
         // Store diff in database.
         add_post_meta($this->batch->get_id(), 'sme_post_diff', $diff->to_array());
         // Store diff in property.
         $this->post_diffs[$diff->get_stage_id()] = $diff;
     }
 }
コード例 #5
0
 /**
  * Pre-flight checks for a specific part of a batch.
  *
  * @param Batch $batch
  * @param string $type
  */
 private function verify_by_type(Batch $batch, $type)
 {
     // The data we want to verify.
     $batch_chunk = array();
     // Get data we want to verify.
     switch ($type) {
         case 'attachments':
             $batch_chunk = $batch->get_attachments();
             break;
         case 'users':
             $batch_chunk = $batch->get_users();
             break;
         case 'posts':
             $batch_chunk = $batch->get_posts();
             break;
     }
     // Verify selected part of batch.
     foreach ($batch_chunk as $item) {
         do_action('sme_verify_' . $type, $item, $batch);
     }
 }
コード例 #6
0
 /**
  * Take content of a batch (attachments, users, post, custom data) and
  * inserted into database.
  *
  * @param Batch $batch
  */
 private function update_batch_content(Batch $batch)
 {
     $content = array('attachments' => $batch->get_attachments(), 'users' => $batch->get_users(), 'posts' => $batch->get_posts(), 'custom_data' => $batch->get_custom_data(), 'post_rel_keys' => $batch->get_post_rel_keys());
     $content = base64_encode(serialize($content));
     update_post_meta($batch->get_id(), '_sme_batch_content', $content);
 }
コード例 #7
0
 /**
  * Get post environment diff object for a batch.
  *
  * @param Batch $batch
  *
  * @return array
  */
 public function get_post_diffs(Batch $batch)
 {
     $objects = array();
     $diffs = get_post_meta($batch->get_id(), 'sme_post_diff');
     if (empty($diffs)) {
         return $objects;
     }
     foreach ($diffs as $diff) {
         $obj = new Post_Env_Diff($diff['stage_id']);
         $obj->set_revision_id($diff['revision_id']);
         $obj->set_prod_id($diff['prod_id']);
         $obj->set_stage_status($diff['stage_status']);
         $obj->set_parent_guid($diff['parent_guid']);
         $objects[$diff['stage_id']] = $obj;
     }
     return $objects;
 }
コード例 #8
0
 /**
  * Generate an import key that can be used in background imports.
  *
  * @param Batch $batch
  *
  * @return string
  *
  * @throws Exception
  */
 public function generate_import_key(Batch $batch)
 {
     if (!$batch->get_id() || !$batch->get_modified_gmt()) {
         throw new Exception('Failed generating batch import key.');
     }
     $key = md5($batch->get_id() . '-' . $batch->get_modified_gmt() . '-' . rand(0, 100000));
     update_post_meta($batch->get_id(), '_sme_import_key', $key);
     return $key;
 }
コード例 #9
0
 /**
  * Add database table base prefix to batch.
  *
  * @param Batch $batch
  */
 private function add_table_prefix(Batch $batch)
 {
     $batch->add_custom_data('sme_table_base_prefix', $this->custom_dao->get_table_base_prefix());
 }
コード例 #10
0
 /**
  * Remove posts that has been deleted on content stage.
  *
  * Runs on production server after batch has been sent from content stage
  * and received by the production server.
  *
  * @param array $posts
  * @param Batch $batch
  */
 public function import($posts, Batch $batch)
 {
     // No posts provided.
     if (empty($posts)) {
         return;
     }
     // String of deleted post IDs.
     $stage_post_ids = array();
     foreach ($posts as $post) {
         if (!isset($post['guid'])) {
             continue;
         }
         $post_id = $this->api->get_post_id_by_guid($post['guid']);
         wp_delete_post($post_id, true);
         if (isset($post['id'])) {
             array_push($stage_post_ids, $post['id']);
         }
     }
     // String of deleted content staging IDs.
     $str = implode(',', $stage_post_ids);
     // Current blog ID.
     $blog_id = get_current_blog_id();
     $message = sprintf('Posts deleted on Content Stage has been removed from Production. <span class="hidden" data-blog-id="%d">%s</span>', $blog_id, $str);
     $this->api->add_deploy_message($batch->get_id(), $message, 'info', 104);
 }
コード例 #11
0
 /**
  * Display checkbox (e.g. for bulk actions). The checkbox should have the
  * value of the batch ID.
  *
  * @param Batch $batch
  *
  * @return string Text to be placed inside the column.
  */
 public function column_cb($batch)
 {
     return sprintf('<input type="checkbox" id="sme_select_batch_%s" class="sme-select-batch" name="%s[]" value="%s"/>', $batch->get_id(), $this->_args['plural'], $batch->get_id());
 }