[英]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??我正在尝试确定在 drupal 7 中如何以编程方式判断用户是否在过去 24 小时内更新了他们的个人资料中的自定义字段,但是查看表格我似乎找不到任何包含该信息的字段想法?? 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.
本质上,我需要在每晚运行一次的批处理作业中提取这些信息,并根据 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) 1-首先你应该告诉 drupal ....当用户编辑个人资料页面时做一些事情......(不管是什么......向数据库中插入一些东西......检索一些东西......等等)
/**
* 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)现在我想我们需要做一些查询......首先我们需要创建2个表http://api.drupal.org/api/drupal/modules--system--system.Z8A5DA52ED126447D359E70C057AschemaA8AZ.php/function/hook (此 url 将帮助您创建架构)
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)第一个表将包含你想要跟踪的字段的当前值,所以我认为这个表应该有以下字段(主键、用户 ID、字段名称、字段值)
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)第二个表将包含用户最后一次更新操作的日期,我认为这些字段将如下所示(主键、用户 ID、字段名称、日期)
now lets return to the form submit function现在让我们返回表单提交 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. maged adel 提供了合理的解决方案,但是还有另一种方法:您可以为此目的使用hook_user_update 。 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).
上面提供的解决方案更好,原因有两个:1)您同时拥有 $edit - 输入的值和 $account - 用户帐户值,因此您可以比较并了解正在更新的字段(如果您没有 1 个特定字段去检查)。 2) just 1 hook to implement.
2) 只需 1 个钩子即可实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.