/** * Returns a blob for the provided post. * * @param WordPress_GitHub_Sync_Post $post Post to retrieve blob for. * * @return WordPress_GitHub_Sync_Blob */ protected function get_blob_for_post(WordPress_GitHub_Sync_Post $post) { if ($blob = $this->get_blob_by_sha($post->sha())) { return $blob; } if ($blob = $this->get_blob_by_path($post->github_path())) { return $blob; } return $post->to_blob(); }
/** * Manipulates the tree for a given post. * * If remove is true, removes the provided post from the current true. * If false or nothing is provided, adds or updates the tree * with the provided post. * * @param WordPress_GitHub_Sync_Post $post * @param bool $remove */ public function post_to_tree($post, $remove = false) { $match = false; foreach ($this->tree as $index => $blob) { if (!isset($blob->sha)) { continue; } if ($blob->sha === $post->sha()) { unset($this->tree[$index]); $match = true; if (!$remove) { $this->tree[] = $this->new_blob($post, $blob); } else { $this->changed = true; } break; } } if (!$match && !$remove) { $this->tree[] = $this->new_blob($post); $this->changed = true; } }