/** * 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); }
/** * Publish a post sent to production. * * New posts that are sent to production will have a post status of * 'publish'. Since we don't want the post to go public until all data * has been synced from content stage, post status has been changed to * 'draft'. Post status is now changed back to 'publish'. * * @param Post $post */ public function publish_post(Post $post) { $prod_id = $this->post_dao->get_id_by_guid($post->get_guid()); if (!$prod_id) { $msg = sprintf('No post with GUID %s found on production.', $post->get_guid()); $this->api->add_deploy_message($this->batch->get_id(), $msg, 'error'); return; } /* * Trigger an action before changing the post status to give other plug-ins * a chance to act before the post goes public (e.g. cache warm-up). */ do_action('sme_pre_publish_post', $prod_id, get_current_blog_id()); /* * Publish the new post if post status from staging environment is set to * "publish". */ if ($post->get_post_status() == 'publish') { $this->post_dao->update_post_status($prod_id, 'publish'); } }
/** * Find post ID by providing GUID. * * @param string $guid * * @return int */ public function get_post_id_by_guid($guid) { return $this->post_dao->get_id_by_guid($guid); }