function send_notification_email($err, $success, $logs = array(), $notification_email)
 {
     global $logger, $status_array, $backup_job;
     $logger->log_info(__METHOD__, "Begin");
     $utility = new WPBackItUp_Utility($logger);
     if ($success) {
         //Don't send logs on success unless debug is on.
         if (WPBACKITUP__DEBUG !== true) {
             $logs = array();
         }
         $subject = get_bloginfo() . ' - Restore completed successfully.';
         $message = '<b>Your site was restored successfully.</b><br/><br/>';
     } else {
         $subject = get_bloginfo() . ' - Backup did not complete successfully.';
         $message = '<b>Your restore did not complete successfully.</b><br/><br/>';
     }
     $local_datetime = get_date_from_gmt(date('Y-m-d H:i:s', current_time('timestamp')));
     $message .= 'WordPress Site: <a href="' . home_url() . '" target="_blank">' . home_url() . '</a><br/>';
     $message .= 'Restore date: ' . $local_datetime . '<br/>';
     //$message .= 'Completion Code: ' . $backup_job->backup_id .'-'. $processing_minutes .'-' .$processing_seconds .'<br/>';
     $message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
     $message .= '<br/>';
     //Add the completed steps on success
     //		if($success) {
     //			$message .='<b>Steps Completed</b><br/>';
     //
     //			//Add the completed statuses
     //			foreach ($status_array as $status_key => $status_value) {
     //				if ($status_value==2) {
     //					foreach ($status_description as $msg_key => $msg_value) {
     //						if ($status_key==$msg_key) {
     //							$message .=  $msg_value . '<br/>';
     //							break;
     //						}
     //					}
     //				}
     //			}
     //		} else  {
     //			//Error occurred
     //			$message .= '<br/>';
     //			$message .= 'Errors:<br/>' . get_error_message($err);
     //		}
     //		$term='success';
     //		if(!$success)$term='error';
     //		$message .='<br/><br/>Checkout '. $WPBackitup->get_anchor_with_utm('www.wpbackitup.com', '', 'notification+email', $term) .' for info about WP BackItUp and our other products.<br/>';
     if ($notification_email) {
         $utility->send_email($notification_email, $subject, $message, $logs);
     }
     $logger->log_info(__METHOD__, "End");
 }
예제 #2
0
function send_backup_notification_email($err, $success, $logs = array())
{
    global $WPBackitup, $wp_backup, $logger, $status_array, $backup_job;
    $logger->log_info(__METHOD__, "Begin");
    $start_timestamp = $backup_job->get_job_start_time();
    $end_timestamp = $backup_job->get_job_end_time();
    $utility = new WPBackItUp_Utility($logger);
    $seconds = $utility->timestamp_diff_seconds($start_timestamp, $end_timestamp);
    $processing_minutes = round($seconds / 60);
    $processing_seconds = $seconds % 60;
    $status_description = array('preparing' => 'Preparing for backup...Done', 'backupdb' => 'Backing up database...Done', 'infofile' => 'Creating backup information file...Done', 'backup_themes' => 'Backing up themes...Done', 'backup_plugins' => 'Backing up plugins...Done', 'backup_uploads' => 'Backing up uploads...Done', 'backup_other' => 'Backing up miscellaneous files...Done', 'finalize_backup' => 'Finalizing backup...Done', 'validate_backup' => 'Validating backup...Done', 'cleanup' => 'Cleaning up...Done');
    if ($success) {
        //Don't send logs on success unless debug is on.
        if (WPBACKITUP__DEBUG !== true) {
            $logs = array();
        }
        $subject = get_bloginfo() . ' - Backup completed successfully.';
        $message = '<b>Your backup completed successfully.</b><br/><br/>';
    } else {
        $subject = get_bloginfo() . ' - Backup did not complete successfully.';
        $message = '<b>Your backup did not complete successfully.</b><br/><br/>';
    }
    $local_start_datetime = get_date_from_gmt(date('Y-m-d H:i:s', $start_timestamp));
    $local_end_datetime = get_date_from_gmt(date('Y-m-d H:i:s', $end_timestamp));
    $message .= 'WordPress Site: <a href="' . home_url() . '" target="_blank">' . home_url() . '</a><br/>';
    $message .= 'Backup date: ' . $local_start_datetime . '<br/>';
    $message .= 'Number of backups completed with WP BackItUp: ' . $WPBackitup->backup_count() . '<br/>';
    $message .= 'Completion Code: ' . $backup_job->backup_id . '-' . $processing_minutes . '-' . $processing_seconds . '<br/>';
    $message .= 'WP BackItUp Version: ' . WPBACKITUP__VERSION . '<br/>';
    $message .= '<br/>';
    //Add the completed steps on success
    if ($success) {
        $message .= '<b>Steps Completed</b><br/>';
        //Add the completed statuses
        foreach ($status_array as $status_key => $status_value) {
            if ($status_value == 2) {
                foreach ($status_description as $msg_key => $msg_value) {
                    if ($status_key == $msg_key) {
                        $message .= $msg_value . '<br/>';
                        break;
                    }
                }
            }
        }
    } else {
        //Error occurred
        $message .= '<br/>';
        $message .= 'Errors:<br/>' . get_error_message($err);
    }
    $term = 'success';
    if (!$success) {
        $term = 'error';
    }
    $message .= '<br/><br/>Checkout ' . $WPBackitup->get_anchor_with_utm('www.wpbackitup.com', '', 'notification+email', $term) . ' for info about WP BackItUp and our other products.<br/>';
    $notification_email = $WPBackitup->get_option('notification_email');
    if ($notification_email) {
        $utility->send_email($notification_email, $subject, $message, $logs);
    }
    $logger->log_info(__FUNCTION__, "End");
}