/** * 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; } }
/** * 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'); } }