2

Currently I am using the date module for drupal 7 and I already have stored data in the existing date field. I want to make changes to the date field by adding "Repeating Dates", but obviously I cannot since I have data in there already. The options I came up with are:

  1. Create a completely new date field for the content type with the additional "Repeating Dates" feature. Then copy all the old dates into the new field (im not sure how to do this easily)

  2. Modify the existing Date field table via phpmyadmin or mysql console.

What is the suggested way to go about updating an existing field that already has data?

1
  • I think I inadvertently answered this on your newer question
    – Clive
    Commented Jul 22, 2013 at 18:35

4 Answers 4

0

You could take a look at this contrib module too https://www.drupal.org/project/entity_recur

2

I got this working by doing the following without having to write any code. Keep in mind im only doing this for the DATE type fields:

example:

my old field: field_eventdate

my new field: field_placeholder

  1. create the same field type with a different name and the options you want.
  2. open up phpmyadmin
  3. goto the table: field_config
  4. search for the new field you created (field_placeholder)
  5. click on the data column blob and download that.
  6. search and edit field_eventdate and upload the file you downloaded which contains the new settings.
  7. do the same exact thing for the table: field_config_instance
  8. now we have to update the table structures of the field to encompass these changes. I first inspected the strucuture of the new field i created and see what the old table was missing. Once you have that down, create the missing columns in the old field that exists in the new field.
  9. Do #8 again but this time for the revisions table. In my case it would be: field_revision_eventdate
  10. delete the field_placeholder via the content type page as you wont need it anymore.

let me know if this worked for anyone else too.

3
  • 1
    Just wanted to say this worked and I love you!!!!!!
    – cwahlfeldt
    Commented Jul 24, 2015 at 19:00
  • i love you too, waffles... ^^ Commented Jul 24, 2015 at 21:33
  • I'm surprised manually editing the data value by hand like that wouldn't cause problems, since it's serialized by PHP.
    – wonder95
    Commented Feb 9, 2018 at 18:34
2

A more secure way than touching the database...

  1. First create your new field with the repeating date, let's call it field_event_date
  2. Then copy everything from the first field (field_date) to your new one

Code:

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', {your_content_type})
  ->addMetaData('account', user_load(1));

$result = $query->execute();
foreach($result['node'] as $nid => $n) {
  $node = node_load($nid);
  $node->field_event_date = $node->field_date;  // Copy one field to another
  node_save($node);
}  
1
  • wouldn't this have issues if you have a large database and it exceeds the php script execution time limit? Commented Jan 27, 2015 at 17:47
1

I went about it by first capturing the original Date field with Features. Then, I created a field like I would like to target (similar to what you'd done with the placeholder) and Features-exported it. I compared the exported code and updated the original field's Feature export code, SQL-dumped the data from the field_data_field_.. table, deleted the original field by Manage Fields screen, feature-reverted to the modified Features export code, and then SQL-imported from my export. voila!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.