Beispiel #1
0
	public function processPart($absolute_filename)
	{
		// Retrieve engine configuration data
		$config =& AEFactory::getConfiguration();

		$address	= trim( $config->get('engine.postproc.email.address', '') );
		$subject	= $config->get('engine.postproc.email.subject', '0');

		// Sanity checks
		if(empty($address))
		{
			$this->setError('You have not set up a recipient\'s email address for the backup files');
			return false;
		}

		// Send the file
		$basename = basename($absolute_filename);
		AEUtilLogger::WriteLog(_AE_LOG_INFO, "Preparing to email $basename to $address");
		if(empty($subject)) $subject = JText::_('AKEEBA_DEFAULT_EMAIL_SUBJECT');
		$body = "Emailing $basename";

		AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Subject: $subject");
		AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Body: $body");

		$result = AEPlatform::send_email($address, $subject, $body, $absolute_filename);

		// Return the result
		if($result !== true)
		{
			// An error occured
			$this->setError( $result );
			// Notify that we failed
			return false;
		}
		else
		{
			// Return success
			AEUtilLogger::WriteLog(_AE_LOG_INFO, "Email sent successfully");
			return true;
		}
	}
Beispiel #2
0
	/**
	 * Sends an email to the administrators
	 * @return bool
	 */
	private function mail_administrators()
	{
		$this->setStep('Processing emails to administrators');
		$this->setSubstep('');
		// Skip email for back-end backups
		if(AEPlatform::get_backup_origin() == 'backend' ) return true;

		$must_email = AEPlatform::get_platform_configuration_option('frontend_email_on_finish', 0) != 0;
		if(!$must_email) return true;

		AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Preparing to send e-mail to administrators");

		$email = AEPlatform::get_platform_configuration_option('frontend_email_address', '');
		$email = trim($email);
		if( !empty($email) )
		{
			$emails = array($email);
		}
		else
		{
			$emails = AEPlatform::get_administrator_emails();
		}

		if(!empty($emails))
		{
			// Fetch user's preferences
			$subject = trim(AEPlatform::get_platform_configuration_option('frontend_email_subject',''));
			$body = trim(AEPlatform::get_platform_configuration_option('frontend_email_body',''));

			// Get the statistics
			$statistics =& AEFactory::getStatistics();
			$stat = $statistics->getRecord();
			$parts = AEUtilStatistics::get_all_filenames($stat, false);

			$profile_number = AEPlatform::get_active_profile();
			$profile_name = AEPlatform::get_profile_name($profile_number);
			$parts = AEUtilStatistics::get_all_filenames($stat, false);
			$stat = (object)$stat;
			$num_parts = $stat->multipart;
			if($num_parts == 0) $num_parts = 1; // Non-split archives have a part count of 0
			$parts_list = '';
			if(!empty($parts)) foreach($parts as $file) {
				$parts_list .= "\t".basename($file)."\n";
			}

			// Do we need a default subject?
			if(empty($subject)) {
				// Get the default subject
				$subject = AEPlatform::translate('EMAIL_SUBJECT_OK');
			} else {
				// Post-process the subject
				$subject = AEUtilFilesystem::replace_archive_name_variables($subject);
			}

			// Do we need a default body?
			if(empty($body)) {
				$body = AEPlatform::translate('EMAIL_BODY_OK');
				$info_source = AEPlatform::translate('EMAIL_BODY_INFO');
				$body .= "\n\n" . sprintf($info_source, $profile_number, $num_parts) . "\n\n";
				$body .= $parts_list;
			} else {
				// Post-process the body
				$body = AEUtilFilesystem::replace_archive_name_variables($body);
				$body = str_replace('[PROFILENUMBER]', $profile_number, $body);
				$body = str_replace('[PROFILENAME]', $profile_name, $body);
				$body = str_replace('[PARTCOUNT]', $num_parts, $body);
				$body = str_replace('[FILELIST]', $parts_list, $body);
			}
			// Sometimes $body contains literal \n instead of newlines
			$body = str_replace('\\n',"\n", $body);

			foreach($emails as $email)
			{
				AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "Sending email to $email");
				AEPlatform::send_email($email, $subject, $body);
			}
		}

		return true;
	}