/**
  * 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;
     }
 }
 /**
  * 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);
 }
 /**
  * Import data added by a third-party.
  */
 public function import_custom_data()
 {
     foreach ($this->batch->get_custom_data() as $addon => $data) {
         do_action('sme_import_' . $addon, $data, $this->batch);
     }
 }
 /**
  * Render table of deleted posts.
  */
 public function render(Batch $batch)
 {
     /**
      * @var Custom_DAO $custom_dao
      */
     $custom_dao = Helper_Factory::get_instance()->get_dao('Custom');
     // Get deleted posts.
     $deleted_posts = $custom_dao->get_deleted_posts();
     // No deleted posts exists.
     if (empty($deleted_posts)) {
         return;
     }
     // Deleted posts previously scheduled to be synced to production.
     $selected_posts = $batch->get_custom_data($this->extension);
     if (!$selected_posts) {
         $selected_posts = array();
     }
     $selected_posts = array_map(function ($post) {
         return $post['id'];
     }, $selected_posts);
     $deleted_posts = array_map(function ($post) use($selected_posts) {
         $post['checked'] = in_array($post['id'], $selected_posts) ? 'checked="checked"' : '';
         return $post;
     }, $deleted_posts);
     $data = array('deleted_posts' => $deleted_posts);
     $this->template->render('delete-post', $data);
 }