Drupal 6.1.3의 hook_cron
구현에 문제가 있습니다.Drupal의 profile_save_profile이 hook_cron에서 작동하지 않습니다. 서버의 cron에 의해 실행될 때
아래 스크립트는 예상대로 실행됩니다. 새 구성원에게 환영 문자를 보내고 프로필의 숨겨진 필드를 업데이트하여 문자가 보내 졌음을 나타냅니다. 편지에 오류가 없으며 모든 신입 회원이 차지하고 있습니다.
문제는 마지막 라인 - 프로필 업데이트가 작동하지 않는 것처럼 보입니다. Drupal cron이 'real '서버의 cron.
수동으로 (예 : /admin/reports/status/run-cron
을 통해) cron을 실행하면 프로필 필드가 예상대로 업데이트됩니다.
무엇이 발생했는지에 대한 제안 사항이 있으십니까?
(누군가를 제안하기 때문에, 참고 : 회원 드루팔 이외의 방법으로 참여하고, 야간 드루팔에 업로드 있도록하는 드루팔에 내장 된 환영 편지 (내 생각) 작동하지 않습니다.)
<?php
function foo_cron() {
// Find users who have not received the new member letter,
// and send them a welcome email
// Get users who have not recd a message, as per the profile value setting
$pending_count_sql = "SELECT COUNT(*) FROM {profile_values} v
WHERE (v.value = 0) AND (v.fid = 7)"; //fid 7 is the profile field for profile_intro_email_sent
if (db_result(db_query($pending_count_sql))) {
// Load the message template, since we
// know we have users to feed into it.
$email_template_file = "/home/foo/public_html/drupal/" .
drupal_get_path('module', 'foo') .
"/emails/foo-new-member-email-template.txt";
$email_template_data = file_get_contents($email_template_file);
fclose($email_template_fh);
//We'll just pull the uid, since we have to run user_load anyway
$query = "SELECT v.uid FROM {profile_values} v
WHERE (v.value = 0) AND (v.fid = 7)";
$result = db_query(($query));
// Loop through the uids, loading profiles so as to access string replacement variables
while ($item = db_fetch_object($result)) {
$new_member = user_load($item->uid);
$translation_key = array(
// ... code that generates the string replacement array ...
);
// Compose the email component of the message, and send to user
$email_text = t($email_template_data, $translation_key);
$language = user_preferred_language($new_member); // use member's language preference
$params['subject'] = 'New Member Benefits - Welcome to FOO!';
$params['content-type'] = 'text/plain; charset=UTF-8; format=flowed;';
$params['content'] = $email_text;
drupal_mail('foo', 'welcome_letter', $new_member->mail, $language, $params, '[email protected]');
// Mark the user's profile to indicate that the message was sent
$change = array(
// Rebuild all of the profile fields in this category,
// since they'll be deleted otherwise
'profile_first_name' => $new_member->profile_first_name,
'profile_last_name' => $new_member->profile_last_name,
'profile_intro_email_sent' => 1);
profile_save_profile($change, $new_member, "Membership Data");
}
}
}
완벽 ... 고마워요! – anschauung
감사! 나에게는 같은 질문이있다. – farzan