/** * Overrides the parent to also make sure term-taxonomy counts are up-to-date after * inserting * @param array $field_n_values @see EEM_Base::insert * @return boolean */ public function insert($field_n_values) { $return = parent::insert($field_n_values); if (isset($field_n_values['term_taxonomy_id'])) { $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); } return $return; }
/** * * @param type $id_in_csv * @param type $model_object_data * @param EEM_Base $model * @param type $old_db_to_new_db_mapping * @return array updated $old_db_to_new_db_mapping */ protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { //remove the primary key, if there is one (we don't want it for inserts OR updates) //we'll put it back in if we need it if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { $effective_id = $model_object_data[$model->primary_key_name()]; unset($model_object_data[$model->primary_key_name()]); } else { $effective_id = $model->get_index_primary_key_string($model_object_data); } //the model takes care of validating the CSV's input try { $new_id = $model->insert($model_object_data); if ($new_id) { $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; $this->_total_inserts++; EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data))); } else { $this->_total_insert_errors++; //put the ID used back in there for the error message if ($model->has_primary_key_field()) { $model_object_data[$model->primary_key_name()] = $effective_id; } EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__); } } catch (EE_Error $e) { $this->_total_insert_errors++; if ($model->has_primary_key_field()) { $model_object_data[$model->primary_key_name()] = $effective_id; } EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); } return $old_db_to_new_db_mapping; }