Example #1
0
 /**
  * Check if we're clear to call the api
  */
 public function locked()
 {
     global $wpghs;
     if (!$this->api->oauth_token() || !$this->api->repository() || $wpghs->push_lock) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Retrieve the saved tree we're building
  * or get the latest tree from the repo
  */
 public function get_tree()
 {
     if (!empty($this->tree)) {
         return;
     }
     $tree = $this->api->last_tree_recursive();
     if (is_wp_error($tree)) {
         WordPress_GitHub_Sync::write_log(__('Failed getting tree with error: ', WordPress_GitHub_Sync::$text_domain) . $tree->get_error_message());
         return;
     }
     $this->tree = $tree;
 }
Example #3
0
 /**
  * The post's sha
  * Cached as post meta, or will make a live call if need be
  *
  * Returns String the sha1 hash
  */
 public function sha()
 {
     $sha = get_post_meta($this->id, '_sha', true);
     // If we've done a full export and we have no sha
     // then we should try a live check to see if it exists
     if (!$sha && 'yes' === get_option('_wpghs_fully_exported')) {
         // @todo could we eliminate this by calling down the full tree and searching it
         $data = $this->api->remote_contents($this);
         if (!is_wp_error($data)) {
             update_post_meta($this->id, '_sha', $data->sha);
             $sha = $data->sha;
         }
     }
     // if the sha still doesn't exist, then it's empty
     if (!$sha) {
         $sha = '';
     }
     return $sha;
 }
Example #4
0
 /**
  * Checks if current position is valid
  *
  * @link http://php.net/manual/en/iterator.valid.php
  * @return boolean true on success, false on failure.
  */
 public function valid()
 {
     global $wpdb;
     while (isset($this->tree[$this->position])) {
         $blob = $this->tree[$this->position];
         // Skip the repo's readme
         if ('readme' === strtolower(substr($blob->path, 0, 6))) {
             WordPress_GitHub_Sync::write_log(__('Skipping README', 'wordpress-github-sync'));
             $this->next();
             continue;
         }
         // If the blob sha already matches a post, then move on
         $id = $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_sha' AND meta_value = '{$blob->sha}'");
         if ($id) {
             WordPress_GitHub_Sync::write_log(sprintf(__('Already synced blob %s', 'wordpress-github-sync'), $blob->path));
             $this->next();
             continue;
         }
         $blob = $this->api->get_blob($blob->sha);
         if (is_wp_error($blob)) {
             WordPress_GitHub_Sync::write_log(sprintf(__('Failed getting blob with error: %s', 'wordpress-github-sync'), $blob->get_error_message()));
             $this->next();
             continue;
         }
         $content = base64_decode($blob->content);
         // If it doesn't have YAML frontmatter, then move on
         if ('---' !== substr($content, 0, 3)) {
             WordPress_GitHub_Sync::write_log(sprintf(__('No front matter on blob %s', 'wordpress-github-sync'), $blob->sha));
             $this->next();
             continue;
         }
         $blob->content = $content;
         $this->current = $blob;
         return true;
     }
     return false;
 }