How to tell if a user has updated a profile field in Drupal 7
I am trying to determine how in drupal 7 I can programmatically tell if a user has updated a custom field in their profile within the past 24 hours however looking through the tables I can't seem to find any field with that information does anyone have any ideas?? Essentially I need to pull this information out during a batch job that run开发者_如何学运维 onces a night and updates other systems based upon the information in drupal. If someone can think of a better way todo this it would be appreciated. thanks for any help you can provide
ok i dont know if its working or not try the following steps
1- first you should tell drupal....when user edit the profile page do something...(whatever the something is ..insert something to database..retrieve something..etc)
/**
* Implementation of hook_form_alter
*/
function newcontent_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'user_profile_form'){
$form['#submit'][] = '_do_something_when_user_save_profile';
}
}
/**
* do something when user save profile
*/
function _do_something_when_user_save_profile($form,$form_state){
// do something
}
now i think we need to do some queries ... first we need to create 2 tables http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_schema/7 (this url will help you to create your schema)
the first table will contain the current value of the field u want track so i think this table should have the following fields (primary key , user id, field name, field value)
the second table will contain the date of the last upated operation the user made i think the fields will be like the following (primary key,user id , field name, date)
now lets return to the form submit function
/**
* do something when user save profile
*/
function _do_something_when_user_save_profile($form,$form_state){
// now i can check in the first table to see
// is the current submitted value for this field = the value in the table
// if its = the table value then the user didn't change any thing now i dont
// need to update the second table
// if the current submitted value != the value in the table then its mean
// that the user have updated this field ...
// now i should insert new value to the second
// table with the current date time and the current field value
}
i hope u under stand me and sorry for my bad english
maged adel provided reasonable solution, however there is one more way of doing this: you can use hook_user_update for this purpose. It's better that solution provided above because of 2 reasons: 1) you have both $edit - entered values and $account - user account values, so you can compare and get know what fields being updated (if you don't have 1 specific field to check). 2) just 1 hook to implement.
精彩评论