任何人都可以提供這方面的一些想法?基本上,我正在構建的模塊有一個表單(按照function_email_solicitors_compose),在提交時,我們顯然會路由到form_emails_solicitors_compose_submit。在這裏我定義了批處理批處理,batch_set爲上述批處理。 drupal文檔說,如果從form_submit中調用batch_process(),則不需要運行batch_process(),但是我嘗試過使用和不使用它。所有的測試都表明,它可以定義批次,但永遠不會比這更進一步。 email_solicitors_batch_iteration從不運行。有任何想法嗎?Drupal 6批處理不執行
作爲信息的一個附加位,batch_get然後返回如下:
Array ( [sets] => Array ( [0] => Array ( [sandbox] => Array ( ) [results] => Array ( ) [success] => [title] => Emailing. [operations] => Array ( [0] => Array ( [0] =>
email_solicitors_batch_iteration [1] =>數組 ( [0] => [1] => )
) ) [finished] => my_finished_callback [init_message] => Initializing.<br/> [progress_message] => Remaining
@total的剩餘部分。 [error_message] =>發生了錯誤 。 [總] => 1 )
) )
代碼:
function email_solicitors_compose(){
$form['email_solicitors_subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#description' => t('Enter the subject of your email'),
'#default_value' => 'Subject',
'#size' => 30
);
$form['email_solicitors_message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#description' => t('Write your message here. <strong>Please note that we will automatically add "Dear #name", which will be personalised to the solicitor.</strong>'),
'#default_value' => '',
);
$form['email_solicitors_submit'] = array(
'#type' => 'submit',
'#title' => t('Submit'),
'#description' => t('Sumbit this form.'),
'#default_value' => 'Submit',
);
return $form;
}//function email_solicitors_compose
function email_solicitors_compose_submit($form_state)
{
$batch = array(
'title' => t('Sending emails to solicitors'),
'operations' => array(
array('email_solicitors_batch_iteration', array())
),
'finished' => 'email_solicitors_batch_finished', //run this when we're finished
'init_message' => t('Preparing to send emails'), //initialisation message
'progress_message' => t('Sent @current out of @total messages.'),
'error_message' => t('Sorry, something went wrong when sending emails.'),
);// create batch array
$info=print_r($batch,TRUE);
drupal_set_message($info);
batch_set($batch);
batch_process();
}//function email_solicitors_compose_submit
function email_solicitors_batch_iteration(&$context)
{
// Initialize sandbox the first time through.
if (!isset($context['sandbox']['progress'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['current_user_id'] = 0;
$context['sandbox']['max'] = db_result(db_query('SELECT COUNT(DISTINCT field_solicitor_email_value) FROM content_type_solicitor'));
}
$comment="On item ".$context['sandbox']['progress'];
drupal_set_message ($comment);
}//function email_solicitors_batch_iteration
function email_solicitors_batch_finished (&$context)
{
die ('woohoo we finished');
}