本文整理汇总了PHP中BackWPup_Job::need_free_memory方法的典型用法代码示例。如果您正苦于以下问题:PHP BackWPup_Job::need_free_memory方法的具体用法?PHP BackWPup_Job::need_free_memory怎么用?PHP BackWPup_Job::need_free_memory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BackWPup_Job
的用法示例。
在下文中一共展示了BackWPup_Job::need_free_memory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: job_run
//.........这里部分代码省略.........
$wxr_post .= "\t\t\t<wp:comment_parent>" . $c->comment_parent . "</wp:comment_parent>\n";
$wxr_post .= "\t\t\t<wp:comment_user_id>" . $c->user_id . "</wp:comment_user_id>\n";
$c_meta = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->commentmeta} WHERE comment_id = %d", $c->comment_ID));
foreach ($c_meta as $meta) {
$wxr_post .= "\t\t\t<wp:commentmeta>\n\t\t\t\t<wp:meta_key>" . $meta->meta_key . "</wp:meta_key>\n\t\t\t\t<wp:meta_value>" . $this->wxr_cdata($meta->meta_value) . "</wp:meta_value>\n\t\t\t</wp:commentmeta>\n";
}
$wxr_post .= "\t\t</wp:comment>\n";
}
$wxr_post .= "\t</item>\n";
$job_object->substeps_done++;
}
$written = file_put_contents($job_object->steps_data[$job_object->step_working]['wpexportfile'], $wxr_post, FILE_APPEND);
if ($written === FALSE) {
$job_object->log(__('WP Export file could not written.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
$job_object->do_restart_time();
}
}
$written = file_put_contents($job_object->steps_data[$job_object->step_working]['wpexportfile'], "</channel>\n</rss>", FILE_APPEND);
if ($written === FALSE) {
$job_object->log(__('WP Export file could not written.', 'backwpup'), E_USER_ERROR);
return FALSE;
}
$job_object->steps_data[$job_object->step_working]['substep'] = 'check';
$job_object->substeps_done++;
$job_object->update_working_data();
$job_object->do_restart_time();
}
remove_filter('wxr_export_skip_postmeta', array($this, 'wxr_filter_postmeta'), 10);
if ($job_object->steps_data[$job_object->step_working]['substep'] == 'check') {
if (extension_loaded('simplexml') && class_exists('DOMDocument')) {
$job_object->log(__('Check WP Export file …', 'backwpup'));
$job_object->need_free_memory(filesize($job_object->steps_data[$job_object->step_working]['wpexportfile']) * 2);
$valid = TRUE;
$internal_errors = libxml_use_internal_errors(TRUE);
$dom = new DOMDocument();
$old_value = NULL;
if (function_exists('libxml_disable_entity_loader')) {
$old_value = libxml_disable_entity_loader(TRUE);
}
$success = $dom->loadXML(file_get_contents($job_object->steps_data[$job_object->step_working]['wpexportfile']));
if (!is_null($old_value)) {
libxml_disable_entity_loader($old_value);
}
if (!$success || isset($dom->doctype)) {
$errors = libxml_get_errors();
$valid = FALSE;
foreach ($errors as $error) {
switch ($error->level) {
case LIBXML_ERR_WARNING:
$job_object->log(E_USER_WARNING, sprintf(__('XML WARNING (%s): %s', 'backwpup'), $error->code, trim($error->message)), $job_object->steps_data[$job_object->step_working]['wpexportfile'], $error->line);
break;
case LIBXML_ERR_ERROR:
$job_object->log(E_USER_WARNING, sprintf(__('XML RECOVERABLE (%s): %s', 'backwpup'), $error->code, trim($error->message)), $job_object->steps_data[$job_object->step_working]['wpexportfile'], $error->line);
break;
case LIBXML_ERR_FATAL:
$job_object->log(E_USER_WARNING, sprintf(__('XML ERROR (%s): %s', 'backwpup'), $error->code, trim($error->message)), $job_object->steps_data[$job_object->step_working]['wpexportfile'], $error->line);
break;
}
}
} else {
$xml = simplexml_import_dom($dom);
unset($dom);
// halt if loading produces an error
if (!$xml) {
示例2: job_run_archive
/**
* @param $job_object
* @return bool
*/
public function job_run_archive(BackWPup_Job $job_object)
{
$job_object->substeps_todo = 1;
$job_object->log(sprintf(__('%d. Try to send backup with email …', 'backwpup'), $job_object->steps_data[$job_object->step_working]['STEP_TRY']), E_USER_NOTICE);
//check file Size
if (!empty($job_object->job['emailefilesize'])) {
if ($job_object->backup_filesize > $job_object->job['emailefilesize'] * 1024 * 1024) {
$job_object->log(__('Backup archive too big to be sent by email!', 'backwpup'), E_USER_ERROR);
$job_object->substeps_done = 1;
return TRUE;
}
}
$job_object->log(sprintf(__('Sending email to %s…', 'backwpup'), $job_object->job['emailaddress']), E_USER_NOTICE);
//get mail settings
$emailmethod = 'mail';
$emailsendmail = '';
$emailhost = '';
$emailhostport = '';
$emailsecure = '';
$emailuser = '';
$emailpass = '';
if (empty($job_object->job['emailmethod'])) {
//do so if i'm the wp_mail to get the settings
global $phpmailer;
// (Re)create it, if it's gone missing
if (!is_object($phpmailer) || !$phpmailer instanceof PHPMailer) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer(true);
}
//only if PHPMailer really used
if (is_object($phpmailer)) {
do_action_ref_array('phpmailer_init', array(&$phpmailer));
//get settings from PHPMailer
$emailmethod = $phpmailer->Mailer;
$emailsendmail = $phpmailer->Sendmail;
$emailhost = $phpmailer->Host;
$emailhostport = $phpmailer->Port;
$emailsecure = $phpmailer->SMTPSecure;
$emailuser = $phpmailer->Username;
$emailpass = $phpmailer->Password;
}
} else {
$emailmethod = $job_object->job['emailmethod'];
$emailsendmail = $job_object->job['emailsendmail'];
$emailhost = $job_object->job['emailhost'];
$emailhostport = $job_object->job['emailhostport'];
$emailsecure = $job_object->job['emailsecure'];
$emailuser = $job_object->job['emailuser'];
$emailpass = BackWPup_Encryption::decrypt($job_object->job['emailpass']);
}
//Generate mail with Swift Mailer
if (!class_exists('Swift', FALSE)) {
require BackWPup::get_plugin_data('plugindir') . '/vendor/SwiftMailer/swift_required.php';
}
if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
try {
//Set Temp dir for mailing
Swift_Preferences::getInstance()->setTempDir(untrailingslashit(BackWPup::get_plugin_data('TEMP')))->setCacheType('disk');
// Create the Transport
if ($emailmethod == 'smtp') {
$transport = Swift_SmtpTransport::newInstance($emailhost, $emailhostport);
$transport->setUsername($emailuser);
$transport->setPassword($emailpass);
if ($emailsecure == 'ssl') {
$transport->setEncryption('ssl');
}
if ($emailsecure == 'tls') {
$transport->setEncryption('tls');
}
} elseif ($emailmethod == 'sendmail') {
$transport = Swift_SendmailTransport::newInstance($emailsendmail);
} else {
$job_object->need_free_memory($job_object->backup_filesize * 8);
$transport = Swift_MailTransport::newInstance();
}
// Create the Mailer using your created Transport
$emailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance(sprintf(__('BackWPup archive from %1$s: %2$s', 'backwpup'), date_i18n('d-M-Y H:i', $job_object->start_time, TRUE), esc_attr($job_object->job['name'])));
$message->setFrom(array($job_object->job['emailsndemail'] => $job_object->job['emailsndemailname']));
$message->setTo(array($job_object->job['emailaddress']));
$message->setBody(sprintf(__('Backup archive: %s', 'backwpup'), $job_object->backup_file), 'text/plain', strtolower(get_bloginfo('charset')));
$message->attach(Swift_Attachment::fromPath($job_object->backup_folder . $job_object->backup_file, $job_object->get_mime_type($job_object->backup_folder . $job_object->backup_file)));
// Send the message
$result = $emailer->send($message);
} catch (Exception $e) {
$job_object->log('Swift Mailer: ' . $e->getMessage(), E_USER_ERROR);
}
if (isset($mbEncoding)) {
mb_internal_encoding($mbEncoding);
}
if (!isset($result) || !$result) {
//.........这里部分代码省略.........