0

I have a really annoying typo right through my Drupal install (db table names, modules...you name it it's right through). Ideally I would like to fix the typo and not recreate the content type/modules etc.

The process I have gone through so far:

Find/replace all instances of the typo in the Database using this Script https://gist.github.com/leewoodman/9544808

I then renamed all the tables where the typo occurred using this:

RENAME TABLE field_data_field_accomodation_ref TO field_data_field_accommodation_ref, field_data_field_offer_accomodation TO field_data_field_offer_accommodation, field_revision_field_accomodation_ref TO field_revision_field_accommodation_ref, field_revision_field_offer_accomodation TO field_revision_field_offer_accommodation;

Then I ran this ruby script to replace all instances of the typo in my files/file/folder structure: https://gist.github.com/dvdsgl/4600317

Then I deleted all caches manually in the DB using:

SELECT
  CONCAT('TRUNCATE TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';') AS table_name
FROM information_schema.TABLES
  WHERE TABLE_SCHEMA = 'my-db-name'
    AND TABLE_NAME LIKE 'cache_%'
    AND TABLE_TYPE = 'BASE TABLE'

I am pretty confident I fixed all the typos but I then get an entityreference error.

Am I missing another step here somewhere?

2
  • 1
    Did you change the column names in the field tables as well? e.g. field_offer_accomodation_value would need to change to field_offer_accommodation_value
    – Clive
    Commented Mar 14, 2014 at 13:12
  • no I didn't! good call. I will check that. I can now see why it's probably easier to download the db and do a find replace on the raw mysqlfile. Commented Mar 20, 2014 at 10:07

3 Answers 3

2

It is impossible to tell whether you've missed something without having complete access to your schema. The fact that you get an entityreference error after clearing all caches is not a good sign.

A safer approach to renaming a content type machine name is to recreate the bundle with the correct machine name, and then use Node convert to convert it from the old machine name to the new one.

Node Convert ... gives the ability of converting the node from its current node type to another node type. Also it gives the ability of transfering all the custom CCK field values of the current node type to the destination CCK fields, or discard them. As of 5.x-1.4 you can bulk convert many nodes of the same type, to another one that can be accessed in Administer → Content → Convert Nodes.

It allows both single node a and multiple node conversion. Here is a link to the documentation.

I've used the module for a similar use case as yours, with success.

0

You will have to edit all the entity reference fields that reference that content type or use a changed field name. The quickest way I found to do this is manually.

Here's what I did: in PHPMyAdmin, MySQL Workbench or similar, I ran this query:

SELECT * FROM field_config WHERE type = 'entityreference'

This shows all the entityreference fields configured in the site. I then edited the values of the 'data' column of the appropriate fields, changing the instances of the old content type/field names with that of the new. Note that the text is actually a serialised PHP array, so since the new values are longer, the number in front of each string must be changed to match the real length of the string.

For example, s:12:accomodation will become s:13:accommodation.

You will get a WSOD if you made a mistake, so save a copy of the original data text somewhere (ie., a text editor) to work from in that case.

0

You will at least need to update the two tables "field_config" and "field_config_instance" as they save the field name in the database. But as you can see in the "data" column, there are some serialized datas that also contains the field name.

So I just think it's impossible/really hard to update a field name programmatically. Read Jovean answer for more explanation.

I would suggest to use Gisle solution.

Otherwise, you can also create a new field in your content type, and make a script to loop over all nodes of the content type, and copy the value to the new field. Afterwards delete the old field.

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.