function cronAction() { check_demo(); if (!$this->getDi()->config->get('email_backup_frequency')) { throw new Am_Exception_InternalError("Email Backup feature is disabled at Setup/Configuration -> Advanced"); } $key = $this->getParam('k'); if ($key != $this->getDi()->app->getSiteHash('backup-cron', 10)) { throw new Am_Exception_AccessDenied("Incorrect access key"); } $dat = date('Y_m_d'); $stream = fopen('php://temp', 'w+b'); if (!$stream) { throw new Am_Exception_InternalError("Could not open php://temp stream"); } $bp = new Am_BackupProcessor(); $stream = $bp->run($stream); rewind($stream); $filename = $bp->isGzip() ? "amember-{$dat}.sql.gz" : "amember-{$dat}.sql"; $mimeType = $bp->isGzip() ? 'application/x-gzip' : 'text/sql'; $m = new Am_Mail(); $m->addTo($this->getDi()->config->get('email_backup_address'))->setSubject('Email Backup ' . $dat)->setFrom($this->getDi()->config->get('admin_email')); $m->setBodyText(sprintf("File with backup for %s is attached. Backup was done at %s", $this->getDi()->config->get('root_url'), $this->getDi()->sqlDate)); $m->createAttachment($stream, $mimeType, Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $filename); $m->setPeriodic(Am_Mail::ADMIN_REQUESTED); $m->send(); $this->getDi()->adminLogTable->log('Email backup to ' . $this->getDi()->config->get('email_backup_address')); }
public function batchSend(&$context, Am_BatchProcessor $batch) { if ($this->saved->count_users <= $this->saved->sent_users) { return true; } // we are done; $q = $this->searchUi->query($this->saved->sent_users, 10); $t = new Am_View(); $i = 0; $db = $this->getDi()->db; while ($r = $db->fetchRow($q)) { $r['name'] = $r['name_f'] . ' ' . $r['name_l']; if (!empty($r['user_id'])) { $isUser = true; } else { $isUser = false; } $this->saved->updateQuick(array('last_email' => $r['email'], 'sent_users' => $this->saved->sent_users + 1)); if ($r['email'] == '') { continue; } $subject = $this->getParam('subject'); $body = $this->getParam('body'); // assign variables $tpl = new Am_SimpleTemplate(); $tpl->assignStdVars(); $tpl->user = $r; $subject = $tpl->render($subject); $body = $tpl->render($body); // $m = new Am_Mail(); $m->addUnsubscribeLink($isUser ? Am_Mail::LINK_USER : Am_Mail::LINK_GUEST); $m->addTo($r['email'], $r['name'])->setSubject($subject); //->setFrom($this->getDi()->config->get('admin_email'), $this->getDi()->config->get('site_title') . ' Admin'); if ($this->getParam('format') == 'text') { $m->setBodyText($body); } else { $m->setBodyHtml($body); } $m->setPeriodic(Am_Mail::ADMIN_REQUESTED); $m->addHeader('X-Amember-Queue-Id', $this->_request->getFiltered('queue_id')); foreach ($this->getAttachments() as $at) { $m->addAttachment($at); } try { $m->send(); } catch (Zend_Mail_Exception $e) { trigger_error("Error happened while sending e-mail to {$r['email']} : " . $e->getMessage(), E_USER_WARNING); } } $this->getDi()->db->freeResult($q); if ($this->saved->count_users <= $this->saved->sent_users) { return true; } // we are done; }