b2evolution PHP Cross Reference Blogging Systems

Source: /inc/cron/jobs/_activate_account_reminder.job.php - 87 lines - 5004 bytes - Text - Print

Description: This file implements the account activation email reminder cron job

   1  <?php
   2  /**

   3   * This file implements the account activation email reminder cron job

   4   *

   5   * @author attila: Attila Simo

   6   *

   7   * @version $Id: $

   8   */
   9  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  10  
  11  global $DB, $UserSettings, $Settings;
  12  
  13  global $servertimenow, $baseurl, $secure_htsrv_url, $activate_account_reminder_config, $activate_account_reminder_threshold;
  14  
  15  if( $Settings->get( 'validation_process' ) != 'easy' )
  16  {
  17      $result_message = sprintf( T_( 'With secure activation process sending reminder emails is not permitted!' ) );
  18      return 2; /* error */
  19  }
  20  
  21  if( empty( $UserSettings ) )
  22  { // initialize UserSettings, because in CLI mode is not initialized yet
  23      load_class( 'users/model/_usersettings.class.php', 'UserSettings' );
  24      $UserSettings = new UserSettings();
  25  }
  26  
  27  // Only users with "new", "emailchanged" OR "deactivated" statuses may receive activation reminders

  28  // This will be a precondition to get less users from db, but this will be checked again with check_status() in the send_easy_validate_emails() function

  29  $status_condition = '( user_status = "new" OR user_status = "emailchanged" OR user_status = "deactivated" )';
  30  
  31  // Set configuration details from $activate_account_reminder_config array

  32  $number_of_max_reminders = ( count( $activate_account_reminder_config ) - 1 );
  33  if( $number_of_max_reminders < 1 )
  34  { // The config array is wrong, it must have at least two elements
  35      $result_message = sprintf( T_('The job advanced configuration is wrong, can\'t send reminders!') );
  36      return 3; /* error */
  37  }
  38  $reminder_date = date2mysql( $servertimenow - $activate_account_reminder_config[0] );
  39  $reminder_delay_conditions = array( '( ( last_sent.uset_value IS NULL OR last_sent.uset_value < '.$DB->quote( $reminder_date ).' ) AND ( reminder_sent.uset_value IS NULL OR reminder_sent.uset_value = "0" ) )' );
  40  for( $i = 1; $i < $number_of_max_reminders; $i++ )
  41  {
  42      $reminder_date = date2mysql( $servertimenow - $activate_account_reminder_config[$i] );
  43      $reminder_delay_conditions[] = '( last_sent.uset_value < '.$DB->quote( $reminder_date ).' AND reminder_sent.uset_value = '.$DB->quote( $i ).' )';
  44  }
  45  $failed_activation_threshold = $activate_account_reminder_config[$number_of_max_reminders];
  46  
  47  $SQL = new SQL();
  48  $SQL->SELECT( 'T_users.*' );
  49  $SQL->FROM( 'T_users' );
  50  // join UserSettings

  51  $SQL->FROM_add( 'LEFT JOIN T_users__usersettings last_sent ON last_sent.uset_user_ID = user_ID AND last_sent.uset_name = "last_activation_email"' );
  52  $SQL->FROM_add( 'LEFT JOIN T_users__usersettings notif_setting ON notif_setting.uset_user_ID = user_ID AND notif_setting.uset_name = "send_activation_reminder"' );
  53  $SQL->FROM_add( 'LEFT JOIN T_users__usersettings reminder_sent ON reminder_sent.uset_user_ID = user_ID AND reminder_sent.uset_name = "activation_reminder_count"' );
  54  // check that user status is 'new' or 'emailchanged' or 'deactivated', and send reminders only for these users.

  55  $SQL->WHERE( $status_condition );
  56  // check if user has an email address

  57  $SQL->WHERE_and( 'LENGTH(TRIM(user_email)) > 0' );
  58  // check that user email is not blocked

  59  $SQL->WHERE_and( 'user_email NOT IN ( SELECT emblk_address FROM T_email__blocked WHERE '.get_mail_blocked_condition().' )' );
  60  // check that user was created more than x ( = confugred activate account reminder threshold ) seconds ago!

  61  $threshold_date = date2mysql( $servertimenow - $activate_account_reminder_threshold );
  62  $SQL->WHERE_and( 'user_created_datetime < '.$DB->quote( $threshold_date ) );
  63  // check how many reminders was sent to the user and when => send reminders only if required

  64  $SQL->WHERE_and( implode( ' OR ', $reminder_delay_conditions ) );
  65  // check if user wants to recevice activation reminder or not

  66  $SQL->WHERE_and( 'notif_setting.uset_value IS NULL OR notif_setting.uset_value <> '.$DB->quote( '0' ) );
  67  
  68  $UserCache = & get_UserCache();
  69  $UserCache->clear();
  70  // load all users to reminded into the UserCache

  71  $UserCache->load_by_sql( $SQL );
  72  
  73  // Send activation reminder to every user loaded into the UserCache ( there are only not activated users )

  74  $reminder_sent = send_easy_validate_emails( $UserCache->get_ID_array() );
  75  
  76  // Set failed activation status for all users who didn't receive activation reminder or account validation email in the last seven days,

  77  // and user was created more then a week, and have received at least one activation email.

  78  $failed_activation_date = date2mysql( $servertimenow - $failed_activation_threshold );
  79  $DB->query( 'UPDATE T_users
  80          LEFT JOIN T_users__usersettings ON uset_user_ID = user_ID
  81          SET user_status = "failedactivation"
  82          WHERE ( uset_name = "last_activation_email" AND uset_value IS NOT NULL AND uset_value < '.$DB->quote( $failed_activation_date ).' )
  83              AND ( user_created_datetime < '.$DB->quote( $failed_activation_date ).' ) AND '.$status_condition );
  84  
  85  $result_message = sprintf( T_( '%d account activation reminder emails were sent!' ), $reminder_sent );
  86  return 1; /* ok */
  87  ?>

title

Description

title

Description

title

Description

title

title

Body