コード例 #1
0
 /**
  * Import postmeta for a specific post.
  *
  * Never call before all posts has been imported! In case you do
  * relationships between post IDs on content stage and production has not
  * been established and import of postmeta will fail!
  *
  * Start by changing content staging post IDs to production IDs.
  *
  * The content staging post ID is used as a key in the post relations
  * array and the production post ID is used as value.
  *
  * @param Post $post
  */
 public function import_post_meta(Post $post)
 {
     $meta = $post->get_meta();
     // Keys in postmeta table containing relationship to another post.
     $keys = $this->batch->get_post_rel_keys();
     // Stage ID of current post.
     $stage_id = $post->get_id();
     // Get the production ID of the current post.
     $prod_id = $this->post_dao->get_id_by_guid($post->get_guid());
     // Post not found on production.
     if (!$prod_id) {
         $message = sprintf('Post not found on production. Stage ID %d, GUID: %s', $stage_id, $prod_id);
         $this->api->add_deploy_message($this->batch->get_id(), $message, 'error');
         return;
     }
     for ($i = 0; $i < count($meta); $i++) {
         // Update post ID to point at the post ID on production.
         $meta[$i]['post_id'] = $prod_id;
         // TODO Remove check for "master"
         if (in_array($meta[$i]['meta_key'], $keys) && !empty($meta[$i]['meta_value']) && $meta[$i]['meta_value'] !== 'master') {
             // Post ID this meta value is referring to.
             $referenced_post_id = $this->post_dao->get_id_by_guid($meta[$i]['meta_value']);
             // Referenced post could not be found.
             if (!$referenced_post_id) {
                 $referenced_post_id = 0;
                 $message = 'Failed updating relationship between posts (blog ID %d). The relationship is defined in the postmeta table. ';
                 $message .= '<ul>';
                 $message .= '<li>Stage ID referencing post: %d</li>';
                 $message .= '<li>Production ID referencing post: %d</li>';
                 $message .= '<li>Key holding referenced post: %s</li>';
                 $message .= '<li>GUID referenced post: %s</li>';
                 $message .= '</ul>';
                 $message = sprintf($message, get_current_blog_id(), $stage_id, $prod_id, $meta[$i]['meta_key'], $meta[$i]['meta_value']);
                 $this->api->add_deploy_message($this->batch->get_id(), $message, 'warning');
             }
             // Update meta value to point at the post ID on production.
             $meta[$i]['meta_value'] = $referenced_post_id;
         }
     }
     $this->postmeta_dao->update_postmeta_by_post($prod_id, $meta);
 }