/**
  * Find taxonomy with the same term ID and taxonomy (type) as for the
  * provided taxonomy. If a match is found, update provided taxonomy with
  * the taxonomy ID we got from database.
  *
  * Useful for comparing a post sent from content staging to production.
  *
  * @param Taxonomy $taxonomy
  *
  * @throws Exception
  */
 public function get_taxonomy_id_by_taxonomy(Taxonomy $taxonomy)
 {
     $term = $taxonomy->get_term();
     // Ensure that the term is set.
     if ($term === null) {
         $message = sprintf('No term found for term_taxonomy_id %d in table %s', $taxonomy->get_id(), $this->wpdb->term_taxonomy);
         throw new Exception($message);
     }
     $query = $this->wpdb->prepare('SELECT term_taxonomy_id FROM ' . $this->get_table() . ' WHERE term_id = %d AND taxonomy = %s', $taxonomy->get_term()->get_id(), $taxonomy->get_taxonomy());
     $row = $this->wpdb->get_row($query, ARRAY_A);
     if (isset($row['term_taxonomy_id'])) {
         $taxonomy->set_id($row['term_taxonomy_id']);
     } else {
         $taxonomy->set_id(null);
     }
 }
 /**
  * Import taxonomy.
  *
  * @param Taxonomy $taxonomy
  */
 public function import_taxonomy(Taxonomy $taxonomy)
 {
     // Get the term.
     $term = $taxonomy->get_term();
     // Import term.
     if ($term !== null) {
         $this->import_term($taxonomy->get_term());
     }
     // If a parent taxonomy exists, import it.
     if ($taxonomy->get_parent() !== null) {
         $this->import_taxonomy($taxonomy->get_parent());
     }
     // Taxonomy ID on production environment.
     try {
         $this->taxonomy_dao->get_taxonomy_id_by_taxonomy($taxonomy);
     } catch (Exception $e) {
         $this->api->add_deploy_message($this->batch->get_id(), $e->getMessage(), 'warning');
     }
     if (!$taxonomy->get_id()) {
         // This taxonomy does not exist on production, create it.
         $this->taxonomy_dao->insert($taxonomy);
     } else {
         // This taxonomy exists on production, update it.
         $this->taxonomy_dao->update_taxonomy($taxonomy);
     }
 }