예제 #1
0
 /**
  * Saves new States for array of Files IDs
  *
  * @param  array $file_ids Array of File IDs
  * @return bool            whether this saved new files
  * @since  0.5.0
  */
 protected function states_by_file_ids($file_ids)
 {
     $changed = false;
     foreach ($file_ids as $file_id) {
         if (!is_integer($file_id)) {
             continue;
         }
         $state_id = wp_save_post_revision($file_id);
         $revisions = wp_get_post_revisions($file_id);
         if (null === $state_id || 0 === $state_id) {
             $prev_revision = array_shift($revisions);
             $state_id = $prev_revision->ID;
             $this->commit_meta['state_ids'][] = $state_id;
             continue;
         }
         $state_meta = array();
         // Removing the latest revision first
         array_shift($revisions);
         if (empty($revisions)) {
             // if not, set status to 'new'
             $state_meta['status'] = 'new';
         } else {
             // if so, set status to 'updated'
             $state_meta['status'] = 'updated';
             // Set prev filename as current gist_id
             $prev_revision = array_shift($revisions);
             $prev_state = $this->commit_query->state_by_id($prev_revision->ID);
             $state_meta['gist_id'] = $prev_state->get_filename();
         }
         update_metadata('post', $state_id, "_wpgp_state_meta", $state_meta);
         $lang_slug = $this->head_query->language_by_post_id($file_id)->get_slug();
         wp_set_object_terms($state_id, $lang_slug, 'wpgp_language', false);
         $this->changed = true;
         $changed = true;
         $this->commit_meta['state_ids'][] = $state_id;
     }
     return $changed;
 }