drupal_set_message иногда не отображает сообщение - PullRequest
0 голосов
/ 13 июля 2020

Я загружаю файл, чтобы обработать и отобразить сообщение в конце. Однако сообщения, которые drupal_set_message настроены на отображение, иногда отображаются и не отображаются иногда, даже если обработка выполняется успешно в фоновом режиме. Ограничение времени перезагрузки не является проблемой, поскольку оно установлено на несколько минут, а обработка в среднем занимает не более 10-60 секунд. Есть ли способ любой ценой заставить страницу отображать сообщения? Меня беспокоят сообщения drupal_set_messages, последние два сообщения drupal_set_messages в коде. Я даже пробовал использовать drupal_set_message (t ('! Shell_ c', array ('! Shell_ c' => $ shell_command)), 'status'); но проблема сохраняется, когда сообщения drupal_set_message иногда отображаются, а иногда не отображаются, довольно беспорядочно.

//Before this part of the code, there is function to create Menu ($items[])
function g_p_proc_form($form, &$form_state, $values) {
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['filter'] = array (
        "#type" => "fieldset",
        "#title" => t("File Process <BR> "),
        "#collapsible" => TRUE,
    );
  // without this attribute, upload may fail on submit
    $form['#attributes']['enctype'] = 'multipart/form-data';
    $form['filter']['file'] = array(
        // '#title' => t('File processing'),
        '#type'  => 'file',
        '#name' => 'files[]',
        '#description' => t('Select Submit to start processing the file'),
        '#type'  => 'file'),
        '#upload_location' => 'public://',
        '#attributes' => array('multiple' => 'multiple'),
    );
    // echo '<script type="text/javascript">Drupal.behaviors.DSU_batch_report;</script>'; //christ
    if (isset($_SERVER['CONTENT_LENGTH']) && (int) $_SERVER['CONTENT_LENGTH'] > 'size based on my requirements') {
        drupal_set_message(t(" Warning message on file size"));));
        // unset($_SERVER['CONTENT_LENGTH']);
    }


    $form['filter']['submit_upload'] = array(
        '#type'  =>  'submit', 
        '#value' =>  t('Submit'),

    );


    // drupal_set_message(t("in fn"));

    return $form;
}

function g_p_proc_form_submit($form, &$form_state) {
    header(current page)
    try{
        $number_file = count($_FILES['files']['name']);
        $f_name = array();
        for ($i=0; $i<$number_file;$i++)
        {
            $file = file_save_upload($i, array('file_validate_extensions' => array('pdf PDF')), 'public://', FILE_EXISTS_REPLACE);
            $f_name[] = $_FILES['files']['name'][$i]; //[]
        }
            }catch (Exception $error){
        echo 'Exception: ',  $error->getMessage(), "\n";
    }
    $n_f = count($f_name);
    drupal_set_message(t('Number of files to process: !n_f', array('!number_f'=>$n_f)));
    $fn_name = 'g_p';
    $fn_call = $fn_name($f_name);
function g_p($f_name=array()){
    $curr_l = getcwd();
    chdir('My file processing PHP script location ');
    $n_f = count($f_name);
    $shell_command = shell_exec("file_processing_php_script_name.php");
    //header("Location: "Current file processing module menu site"); //Commented out
    drupal_set_message($shell_command); //print_r statements from the file_processing_php_script_name.php
    chdir($curr_l);
}
...