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; }
/** * 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); }
/** * 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; } }
/** * 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); } }
/** * 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); }
/** * @param Batch $batch */ private function add_users(Batch $batch) { $user_ids = array(); foreach ($batch->get_posts() as $post) { $user_ids[] = $post->get_author(); } $batch->set_users($this->user_dao->find_by_ids($user_ids)); }
/** * Publish multiple posts sent to production. */ public function publish_posts() { foreach ($this->batch->get_posts() as $post) { $this->publish_post($post); } }