Changeset 1157


Ignore:
Timestamp:
Apr 13, 2006, 12:56:55 AM (18 years ago)
Author:
rub
Message:

Issue ID 330:

o Change NBM configuration in order to avoid lose treatment action when occurred timeout
o Add news redirect/repost functions

Reports of svn:1156

Location:
branches/branch-1_6
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_6/admin/include/functions_notification_by_mail.inc.php

    r1116 r1157  
    2828
    2929/* nbm_global_var */
    30 $env_nbm = array();
     30$env_nbm = array
     31          (
     32            'start_time' => get_moment(),
     33            'sendmail_timeout' => (intval(ini_get('max_execution_time')) * $conf['nbm_max_treatment_timeout_percent']),
     34            'is_sendmail_timeout' => false
     35          );
     36
    3137
    3238/*
     
    5662    }
    5763  }
     64}
     65
     66/*
     67 * Check sendmail timeout state
     68 *
     69 * @return true, if it's timeout
     70 */
     71function check_sendmail_timeout()
     72{
     73  global $env_nbm;
     74
     75  $env_nbm['is_sendmail_timeout'] = ((get_moment() - $env_nbm['start_time']) > $env_nbm['sendmail_timeout']);
     76
     77  return $env_nbm['is_sendmail_timeout'];
    5878}
    5979
     
    319339 * check_key list where action will be done
    320340 *
    321  * @return updated data count
     341 * @return check_key lisr treated
    322342 */
    323343function do_subscribe_unsubcribe_notification_by_mail($is_admin_request, $is_subscribe = false, $check_key_list = array())
     
    325345  global $conf, $page, $env_nbm, $conf;
    326346
     347  $check_key_treated = array();
    327348  $updated_data_count = 0;
    328349  $error_on_updated_data_count = 0;
     
    345366    $data_users = get_user_notifications('subscribe', $check_key_list, !$is_subscribe);
    346367
     368    // Prepare message after change language
     369    $msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
     370
    347371    // Begin nbm users environment
    348372    begin_users_env_nbm(true);
     
    350374    foreach ($data_users as $nbm_user)
    351375    {
    352       if (($env_nbm['error_on_mail_count'] + $env_nbm['sent_mail_count']) >= $conf['nbm_max_mails_send'])
     376      if (check_sendmail_timeout())
    353377      {
    354378        // Stop fill list on 'send', if the quota is override
    355         array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send']));
     379        array_push($page['errors'], $msg_break_timeout);
    356380        break;
    357381      }
     382
     383      // Fill return list
     384      array_push($check_key_treated, $nbm_user['check_key']);
    358385
    359386      $do_update = true;
     
    437464  }
    438465
    439   return $updated_data_count;
     466  return $check_key_treated;
    440467}
    441468
     
    445472 * check_key list where action will be done
    446473 *
    447  * @return updated data count
     474 * @return check_key lisr treated
    448475 */
    449476function unsubcribe_notification_by_mail($is_admin_request, $check_key_list = array())
     
    457484 * check_key list where action will be done
    458485 *
    459  * @return updated data count
     486 * @return check_key lisr treated
    460487 */
    461488function subcribe_notification_by_mail($is_admin_request, $check_key_list = array())
  • branches/branch-1_6/admin/notification_by_mail.php

    r1116 r1157  
    4848
    4949// +-----------------------------------------------------------------------+
     50// | Initialization                                                        |
     51// +-----------------------------------------------------------------------+
     52$base_url = get_root_url().'admin.php';
     53
     54// +-----------------------------------------------------------------------+
    5055// | functions                                                             |
    5156// +-----------------------------------------------------------------------+
     57
     58/*
     59 * Do background treatmetn in order to finish to send mails
     60 *
     61 * @param $post_keyname: key of check_key post array
     62 * @param check_key_treated:array of check_key treated
     63 * @return none
     64 */
     65function do_background_treatment($post_keyname, $check_key_treated = array())
     66{
     67  global $env_nbm, $base_url;
     68
     69  if ($env_nbm['is_sendmail_timeout'])
     70  {
     71    if (isset($_POST[$post_keyname]))
     72    {
     73      $post_count = count($_POST[$post_keyname]);
     74      $treated_count = count($check_key_treated);
     75      if ($treated_count != 0)
     76      {
     77        $time_refresh = ceil((get_moment() - $env_nbm['start_time']) * $post_count / $treated_count);
     78      }
     79      else
     80      {
     81        $time_refresh = 10;
     82      }
     83      $_POST[$post_keyname] = array_diff($_POST[$post_keyname], $check_key_treated);
     84      re_post_http($base_url.get_query_string_diff(array()), sprintf(l10n('nbm_background_treatment_redirect'), $time_refresh) , $time_refresh);
     85    }
     86  }
     87
     88}
    5289
    5390/*
     
    79116function insert_new_data_user_mail_notification()
    80117{
    81   global $conf, $page;
     118  global $conf, $page, $env_nbm;
    82119
    83120  // Set null mail_address empty
     
    138175    mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
    139176    // Update field enabled with specific function
    140     do_subscribe_unsubcribe_notification_by_mail
     177    $check_key_treated = do_subscribe_unsubcribe_notification_by_mail
    141178    (
    142179      true,
     
    144181      $check_key_list
    145182    );
     183
     184     // On timeout simulate like tabsheet send
     185    if ($env_nbm['is_sendmail_timeout'])
     186    {
     187      if ($conf['nbm_default_value_user_enabled'])
     188      {
     189        $_POST['trueify'] = 'trueify';
     190        $_POST['cat_false'] = $check_key_list;
     191        do_background_treatment('cat_false', $check_key_treated);
     192      }
     193      else
     194      {
     195        $_POST['falsify'] = 'falsify';
     196        $_POST['cat_true'] = $check_key_list;
     197        do_background_treatment('cat_true', $check_key_treated);
     198      }
     199    }
    146200  }
    147201}
     
    149203/*
    150204 * Send mail for notification to all users
    151  * Return list of "treated/selected" users
     205 * Return list of "selected" users for 'list_to_send'
     206 * Return list of "treated" check_key for 'send'
    152207 */
    153208function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = array(), $customize_mail_content = '')
     
    177232        $datas = array();
    178233
     234        // Prepare message after change language
     235        if ($is_action_send)
     236        {
     237          $msg_break_timeout = l10n('nbm_nbm_break_timeout_send_mail');
     238        }
     239        else
     240        {
     241          $msg_break_timeout = l10n('nbm_break_timeout_list_user');
     242        }
     243
    179244        // Begin nbm users environment
    180245        begin_users_env_nbm($is_action_send);
     
    182247        foreach ($data_users as $nbm_user)
    183248        {
    184           if ((!$is_action_send) and (count($return_list) >= $conf['nbm_max_list_users_to_send']))
     249          if ((!$is_action_send) and check_sendmail_timeout())
    185250          {
    186251            // Stop fill list on 'list_to_send', if the quota is override
    187             array_push($page['infos'], sprintf(l10n('nbm_break_list_user'), $conf['nbm_max_list_users_to_send']));
     252            array_push($page['infos'], $msg_break_timeout);
    188253            break;
    189254          }
    190           if (($is_action_send) and (count($return_list) >= $conf['nbm_max_mails_send']))
     255          if (($is_action_send) and check_sendmail_timeout())
    191256          {
    192257            // Stop fill list on 'send', if the quota is override
    193             array_push($page['errors'], sprintf(l10n('nbm_nbm_break_send_mail'), $conf['nbm_max_mails_send']));
     258            array_push($page['errors'], $msg_break_timeout);
    194259            break;
    195260          }
     
    200265          if ($is_action_send)
    201266          {
     267            // Fill return list of "treated" check_key for 'send'
     268            array_push($return_list, $nbm_user['check_key']);
    202269            $message = '';
    203270
     
    214281            if ($exist_data)
    215282            {
    216               array_push($return_list, $nbm_user);
    217 
    218283              $subject = '['.$conf['gallery_title'].']: '.l10n('nbm_object_news');
    219284              $message .= sprintf(l10n('nbm_content_hello'), $nbm_user['username']).",\n\n";
     
    263328            if (news_exists($nbm_user['last_send'], $dbnow))
    264329            {
     330              // Fill return list of "selected" users for 'list_to_send'
    265331              array_push($return_list, $nbm_user);
    266332            }
     
    296362    {
    297363      // Quick List, don't check news
     364      // Fill return list of "selected" users for 'list_to_send'
    298365      $return_list = $data_users;
    299366    }
    300367  }
     368
     369  // Return list of "selected" users for 'list_to_send'
     370  // Return list of "treated" check_key for 'send'
    301371  return $return_list;
    302372}
     
    384454    if (isset($_POST['falsify']) and isset($_POST['cat_true']))
    385455    {
    386       unsubcribe_notification_by_mail(true, $_POST['cat_true']);
     456      $check_key_treated = unsubcribe_notification_by_mail(true, $_POST['cat_true']);
     457      do_background_treatment('cat_true', $check_key_treated);
    387458    }
    388459    else
    389460    if (isset($_POST['trueify']) and isset($_POST['cat_false']))
    390461    {
    391       subcribe_notification_by_mail(true, $_POST['cat_false']);
     462      $check_key_treated = subcribe_notification_by_mail(true, $_POST['cat_false']);
     463      do_background_treatment('cat_false', $check_key_treated);
    392464    }
    393465    break;
     
    398470    if (isset($_POST['send_submit']) and isset($_POST['send_selection']) and isset($_POST['send_customize_mail_content']))
    399471    {
    400       do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
     472      $check_key_treated = do_action_send_mail_notification('send', $_POST['send_selection'], $_POST['send_customize_mail_content']);
     473      do_background_treatment('send_selection', $check_key_treated);
    401474    }
    402475  }
     
    415488);
    416489
    417 $base_url = get_root_url().'admin.php';
    418 
    419490$template->assign_vars
    420491(
     
    422493  (
    423494    'U_TABSHEET_TITLE' => l10n('nbm_'.$page['mode'].'_mode'),
    424     'U_HELP' => add_url_params(get_root_url().'/popuphelp.php', array('page' => 'notification_by_mail')),
     495    'U_HELP' => add_url_params(get_root_url().'popuphelp.php', array('page' => 'notification_by_mail')),
    425496    'F_ACTION'=> $base_url.get_query_string_diff(array())
    426497  )
  • branches/branch-1_6/include/config_default.inc.php

    r1132 r1157  
    471471$conf['nbm_default_value_user_enabled'] = false;
    472472
    473 // Max user to show on list users to send notification
    474 // Parameter not used if $conf['nbm_list_all_enabled_users_to_send'] is true
    475 $conf['nbm_max_list_users_to_send'] = 100;
    476 
    477473// Search List user to send with quick (List all without check news)
    478474// More quickly but less fun to use
     
    480476
    481477// Max mails sended on one pass
    482 $conf['nbm_max_mails_send'] = 35;
     478$conf['nbm_max_treatment_timeout_percent'] = 0.8;
     479
    483480?>
  • branches/branch-1_6/include/functions.inc.php

    r1131 r1157  
    519519 *
    520520 * @param string $url
     521 * @param string $title_msg
     522 * @param integer $refreh_time
    521523 * @return void
    522524 */
    523 function redirect( $url )
     525function redirect( $url , $msg = '', $refreh_time = 0)
    524526{
    525527  global $user, $template, $lang_info, $conf, $lang, $t2, $page, $debug;
    526528
    527   // $refresh, $url_link and $title are required for creating an automated
     529  // $redirect_msg, $refresh, $url_link and $title are required for creating an automated
    528530  // refresh page in header.tpl
    529   $refresh = 0;
     531  if (!isset($msg) or ($msg == ''))
     532  {
     533    $redirect_msg = l10n('redirect_msg');
     534  }
     535  else
     536  {
     537    $redirect_msg = $msg;
     538  }
     539  $refresh = $refreh_time;
    530540  $url_link = $url;
    531541  $title = 'redirection';
     
    860870  return $available_upgrade_ids;
    861871}
     872
     873/**
     874 * Adaptation of _HTTPRequestToString (http://fr.php.net/urlencode)
     875 *
     876 *
     877 * @return array request to string
     878 */
     879function http_request_to_string($arr_request, $var_name, $separator='&') {
     880   $ret = "";
     881   if (is_array($arr_request)) {
     882       foreach ($arr_request as $key => $value) {
     883           if (is_array($value)) {
     884               if ($var_name) {
     885                   $ret .= http_request_to_string($value, "{$var_name}[{$key}]", $separator);
     886               } else {
     887                   $ret .= http_request_to_string($value, "{$key}", $separator);
     888               }
     889           } else {
     890               if ($var_name) {
     891                   $ret .= "{$var_name}[{$key}]=".urlencode($value)."&";
     892               } else {
     893                   $ret .= "{$key}=".urlencode($value)."&";
     894               }
     895           }
     896       }
     897   }
     898   if (!$var_name) {
     899       $ret = substr($ret,0,-1);
     900   }
     901   return $ret;
     902}
     903
     904/**
     905 * Post request HTTP on backgroung and redirec to selected url
     906 *
     907 * Note : once this function called, the execution doesn't go further
     908 * (presence of an exit() instruction.
     909 *
     910 * @param string $url_redirect
     911 * @param string $redirect_message
     912 * @param integer $redirect_refreh_time
     913 * @return void
     914 */
     915function re_post_http($url_redirect, $redirect_message, $redirect_refreh_time)
     916{
     917  global $conf;
     918
     919  $data_post = http_request_to_string($_POST, '');
     920
     921  $message_post  = "POST ".$_SERVER['PHP_SELF'].html_entity_decode(get_query_string_diff(array()))." HTTP/1.1\r\n";
     922
     923  foreach (array_flip(array_diff(array_flip(apache_request_headers()), array('Content-Type', 'Content-Length'))) as $header_name => $header_value)
     924  {
     925    $message_post .= $header_name.": ".$header_value."\r\n";
     926  }
     927
     928
     929//  $message_post .= "Host: ".$_SERVER['HTTP_HOST']."\r\n";
     930//  $message_post .= "Cookie: ".$conf['session_name']."=".$_COOKIE[$conf['session_name']]."\r\n";
     931  $message_post .= "Content-Type: application/x-www-form-urlencoded\r\n";
     932  $message_post .= "Content-Length: ".strlen($data_post)."\r\n";
     933  $message_post .= "\r\n";
     934  $message_post .= $data_post."\r\n";
     935
     936  $fd = fsockopen($_SERVER['HTTP_HOST'], $_SERVER['SERVER_PORT']);
     937  fputs($fd, $message_post);
     938  fclose($fd);
     939
     940  redirect($url_redirect, $redirect_message, $redirect_refreh_time);
     941  //exit(); done by redirect
     942}
     943
    862944?>
  • branches/branch-1_6/include/page_header.php

    r1120 r1157  
    5858
    5959// refresh
    60 if ( isset( $refresh ) and intval($refresh) >= 0 and isset( $url_link ) )
     60if ( isset( $refresh ) and intval($refresh) >= 0 and isset( $url_link ) and isset( $redirect_msg ) )
    6161{
    6262  $template->assign_vars(
    6363    array(
     64      'U_REDIRECT_MSG' => $redirect_msg,
    6465      'REFRESH_TIME' => $refresh,
    6566      'U_REFRESH' => $url_link
  • branches/branch-1_6/language/en_UK.iso-8859-1/admin.lang.php

    r1129 r1157  
    254254$lang['metadata_iptc'] = 'IPTC';
    255255$lang['name'] = 'name';
    256 $lang['nbm_break_list_user'] = 'List of users to send mail is limited to %d. Others users are not listed.';
     256$lang['nbm_background_treatment_redirect'] = 'Execution time is out, treatment continue on background. Re-display on %d secondes...';
     257$lang['nbm_break_timeout_list_user'] = 'Prepared time for list of users to send mail is limited. Others users are not listed.';
    257258$lang['nbm_col_check_user_send_mail'] = 'To send ?';
    258259$lang['nbm_col_last_send'] = 'Last send';
     
    278279$lang['nbm_msg_n_mails_sent'] = '%d mails were sent.';
    279280$lang['nbm_msg_no_mail_to_send'] = '%d mails were not sent.';
    280 $lang['nbm_nbm_break_send_mail'] = 'Sent mail is limited to %d send by pass. Others mails are skipped.';
     281$lang['nbm_nbm_break_timeout_send_mail'] = 'Time to send mail is limited. Others mails are skipped or sent on background.';
    281282$lang['nbm_no_mail_to_send'] = 'No mail to send.';
    282283$lang['nbm_no_user_available_to_send_L1'] = 'No user are available in order to send mail.';
  • branches/branch-1_6/language/en_UK.iso-8859-1/common.lang.php

    r1125 r1157  
    344344$lang['w_month'] = 'Month';
    345345$lang['yes'] = 'Yes';
     346$lang['redirect_msg'] = 'Redirection...';
    346347?>
  • branches/branch-1_6/language/fr_FR.iso-8859-1/admin.lang.php

    r1152 r1157  
    257257$lang['metadata_iptc'] = 'IPTC';
    258258$lang['name'] = 'nom';
    259 $lang['nbm_break_list_user'] = 'La liste des utilisateurs pour l\'envoi est limitéé à %d. Les autres utilisateurs ne sont pas listés.';
     259$lang['nbm_background_treatment_redirect'] = 'Le temps d\'éxécution étant dépassé, le traitement continue en arrière plan. Ré-affichage dans %d secondes...';
     260$lang['nbm_break_timeout_list_user'] = 'Le temps de préparation de la liste des utilisateurs pour l\'envoi est limité. Les autres utilisateurs ne sont pas listés.';
    260261$lang['nbm_col_check_user_send_mail'] = 'A envoyer ?';
    261262$lang['nbm_col_last_send'] = 'Dernier envoi';
     
    281282$lang['nbm_msg_n_mails_sent'] = '%s mails ont été envoyés.';
    282283$lang['nbm_msg_no_mail_to_send'] = '%s mails n\'ont pas été envoyés.';
    283 $lang['nbm_nbm_break_send_mail'] = 'Les mails envoyés sont limités à %d envois d\'une seule passe. Les autres envois de mail ont été ignorés.';
     284$lang['nbm_nbm_break_timeout_send_mail'] = 'Le temps d\'envoi des mails est limité. Les autres envois de mail ont été ignorés ou vont être envoyés en arrière plan.';
    284285$lang['nbm_no_mail_to_send'] = 'Pas de mail à envoyer.';
    285286$lang['nbm_no_user_available_to_send_L1'] = 'Il n\'y a pas d\'utilisateur à notifier par mail.';
  • branches/branch-1_6/language/fr_FR.iso-8859-1/common.lang.php

    r1125 r1157  
    344344$lang['w_month'] = 'Mois';
    345345$lang['yes'] = 'Oui';
     346$lang['redirect_msg'] = 'Redirection...';
    346347?>
  • branches/branch-1_6/template/yoga/redirect.tpl

    r1052 r1157  
    1 <p>Redirection...</p>
     1<p>{U_REDIRECT_MSG}</p>
    22<p><a href="{U_REFRESH}">{lang:click_to_redirect}</a></p>
Note: See TracChangeset for help on using the changeset viewer.