0

I am using mongodb as the backend for the node_save functionality and I have migrated my custom fields. So for every node save it calls the hook_field_storage_write() . Thus the data is saved in the mysql and then calls the mongodb implementation. This hook inserts the document in mongodb and calls the mongodb_migrate_write_helper. In the function the migrated fields are set with the value of deleted column as 2.

Thus if I have migrated a field 'field_email' from mysql to mongodb the mongodb_migrate_write_helper sets the field_email for the entity as deleted = 2. What does the deleted flag do? Are the rows marked as deleted = 2 deleted in a specific point of time or by some hook calls? . I have seen in many instances in the core modules where deleted is set as 1. Are there any purge scripts that are run at specific points of time for deletion of fields marked as deleted.

function mongodb_migrate_write_helper($entity_type, $entity_id) {
  $migrate_fields = variable_get('mongodb_migrate_fields', array()); // Migrated field names are stored in variable.
  foreach ($migrate_fields as $field_name => $v) {
    $field = field_info_field($field_name);    
    db_update(_field_sql_storage_tablename($field))
      ->fields(array('deleted' => 2))
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $entity_id)
      ->execute();
    }
}

1 Answer 1

3

The deleted column in a field table is:

A boolean indicating whether this data item has been deleted

Therefore the only valid values are 0 and 1. Or, at least, 0 == false, and anything else is equivalent, and == true.

You'd need to ask the module developers for their motivation to be 100% sure why they're bucking the trend there and using '2' instead, but maybe it's some sort of hack to exclude certain records from being queried with WHERE deleted = 1, but still available for WHERE deleted > 0. Not sure though, that's just a guess.

As for what it does: it simply marks a record as deleted, so it won't be included in query results, and can be moved into a deleted data table, from which it's subsequently removed on cron runs.

5
  • Thanks @Clive . Can u please explain the cron script that deletes the data and how its configured and where could I find it?
    – Wordzilla
    Commented Jun 9, 2015 at 13:00
  • There's not a lot of config, it happens in field_cron() so that's the best place to start, then have a read through the code and comments of field_purge_batch() (which does the actual deleting)
    – Clive
    Commented Jun 9, 2015 at 13:17
  • Thanks @Clive. In the field_purge_batch a condition of deleted = 1 is passed meanwhile the mongodb migrate module sets it as deleted = 2. So the fields will not be deleted right in that case?
    – Wordzilla
    Commented Jun 9, 2015 at 13:38
  • Correct - maybe that's why that did it? Not sure, I'm not too familiar with the mongo field module
    – Clive
    Commented Jun 9, 2015 at 14:01
  • Not sure if its a bug as in other core modules they set deleted as 1. Thanks for your help :)
    – Wordzilla
    Commented Jun 9, 2015 at 14:02

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.