On my website I have a content type called beta and there are an approx of 30k beta nodes containing 40+ GBs of data. I converted my old website to drupal with a lot of needed tricks and techniques around an year ago.

However, I am stuck with a problem. The beta content type has over a dozen cck fields. Many of these fields have repeating data i.e. recurring in several beta nodes. I had earlier planned to use taxonomy and link these cck fields with terms/vocabularies. The pursuit of this goal has led to several problems.

Problems being
I)Out of all the modules I tried there is no module which allows for conversion of a cck 'text field type' in a certain content type to a 'free tagging taxonomy type'. The task would have been extremely simple if it were not so.
II)I think there is no module yet which allows for search data in the database to be used for the purposes of taxonomy. I would be really glad if there were a module which allowed for search index data to be used for taxonomy terms or something like a search engine vocabulary,etc.

Although I can think of few possible ad hoc solutions but it will be appreciable if there were a proper set of rules to follow here.

Comments

canadrian’s picture

Definitely looking for this as well.

dberzon’s picture

Me too..........

asb’s picture

subscribing

CobraMP’s picture

views bulk operations

create the taxonomy and values
filter content type to a single value of the field you want to convert
using vbo set the taxonomy field to that entry
repeat for each value
update all your views to use taxonomy field instead of cck field
then hide the cck field so it no longer gets seen

niccottrell’s picture

@CobraMP - Thanks for the instructions! I'm almost there, however I'm having trouble settings the taxonomy field. Firstly, I'm using the "Content Taxonomy module" which lets me create a field with a given taxonomy (rather than attaching to the whole node). However, the real problem is converted the value of the textfield into a term ID that I can save with node_save. Is there a neat function for taking a vocabulary and a string and returning the tid, inserting the missing term if necessary?

niccottrell’s picture

After many hours, I found a way. field_donor contains a text value, and I wanted save a taxonomy term into a new field_donor2

====

$vid = 25; // vocab ID
$edit = array('vid' => $vid, 'name' => $object->field_donor[0]['value']);
$terms = taxonomy_get_term_by_name($edit['name']);
if (!empty($terms)) {
// term already exists
$tid = $terms[0]->tid;
} else {
// add term and get the tid
$status = taxonomy_save_term($edit);
$tid = $edit['tid'];
}
$object->field_donor2[0]['value'] = $tid;
node_save($object);

===

I hope this helps someone else!

z33k3r’s picture

@CobraMP - So obvious yet so distant when you're not on that thought pattern. Thanks!

alihammad’s picture

Status: Active » Fixed

While going through the old threads I started here, I was so glad to see that this issue was actually RESOLVED although I had found a solution which didn't use the drupal api a while back.

It took 2 major drupal core upgrades and around 2 years but like always DRUPAL community triumphs at giving.

I am marking this as fixed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ingomueller.net’s picture

Issue summary: View changes

Since I just spent some time in making this work in Drupal 7, I want to share my solution. Maybe it helps somebody...

Besides porting it to Drupal 7 API, I adapted above code to find the vocabulary ID automatically and to work with fields with multiple values:

if( !function_exists('convert_text_field_to_term_reference_field') ) {
    function convert_text_field_to_term_reference_field( &$account, $src_field_name, $dst_field_name ) {
        $dst_vocab_name = field_info_field($dst_field_name)['settings']['allowed_values'][0]['vocabulary'];
        $dst_vid = taxonomy_vocabulary_machine_name_load($dst_vocab_name)->vid;
        $src_items = field_get_items('user', $account, $src_field_name);
        if( empty($src_items) ) return;
        $new_values = array();
        foreach( $src_items as $key => $value ) {
            $term_name = $value['value'];
            $terms = taxonomy_get_term_by_name($term_name, $dst_vocab_name);
            if( !empty($terms) ) {
                $term = array_shift($terms);
            } else {
                $term = new stdClass();
                $term->name = $term_name;
                $term->vid = $dst_vid;
                taxonomy_term_save($term);
            }
            $tid = $term->tid;
            $new_values[] = array( 'tid' => $tid );
        }

        $account->{$dst_field_name}['und'] = $new_values;
    }
}

convert_text_field_to_term_reference_field( $account, 'field_multi_text', 'field_multi_term_ref' );
// convert other fields...

Also I needed to figure out how to have this code run on every account. My solution was to create a Rule (with the Rules module) that is triggered "Before saving a user account" and with an "Execute custom PHP code" action with above code. To enable this kind of action, the "PHP filter" module from Drupal core needs to be activated. This converts the text field 'field_multi_text' to the field of term references 'field_multi_term_ref' when I import my users from CSV.

There are still a few assumptions hard coded. Suggestions welcome to improve the code...

ingomueller.net’s picture

I realize now that most (of not all) of what I coded by hand can actually be done by the Rules module out of the box, which would be much cleaner. So don't follow my example...