Example #1
0
 protected function doSubscribe()
 {
     $batch = new Am_BatchProcessor(array($this, '_handleAll'), 10);
     $page = $this->grid->getRequest()->getInt('group_context');
     if ($batch->run($page)) {
         echo ___('DONE') . ".";
     } else {
         echo $page * $this->batchCount . ' ' . ___('records processed.');
         echo $this->getAutoClickScript(5, 'input#group-action-continue');
         echo $this->renderContinueForm(___('Continue'), $page);
     }
 }
Example #2
0
 function doWork(&$context, Am_BatchProcessor $batch)
 {
     $pageCount = 5000;
     $q = Am_Di::getInstance()->db->queryResultOnly("\n            SELECT *\n            FROM ?_invoice\n            LIMIT ?d, ?d", (int) $context, $pageCount);
     $count = 0;
     while ($row = Am_Di::getInstance()->db->fetchRow($q)) {
         $count++;
         $invoice = $this->getDi()->invoiceRecord;
         $invoice->fromRow($row);
         $invoice->updateStatus();
         try {
             $invoice->recalculateRebillDate();
         } catch (Am_Exception_InternalError $e) {
         }
         // ignore error about empty period
         $context++;
         if (!$batch->checkLimits()) {
             return;
         }
     }
     if (!$count) {
         return true;
     }
     // finished!
 }
 function doWork(&$context, Am_BatchProcessor $batch)
 {
     $pageCount = 5000;
     $q = Am_Di::getInstance()->db->queryResultOnly("\n            SELECT *\n            FROM ?_invoice\n            LIMIT ?d, ?d", (int) $context, $pageCount);
     $count = 0;
     while ($row = Am_Di::getInstance()->db->fetchRow($q)) {
         $count++;
         $invoice = $this->getDi()->invoiceRecord;
         $invoice->fromRow($row);
         $invoice->updateStatus();
         $context++;
         if (!$batch->checkLimits()) {
             return;
         }
     }
     if (!$count) {
         return true;
     }
     // finished!
 }
Example #4
0
 function stepCopy(Am_BatchProcessor $batch)
 {
     @set_time_limit(600);
     $info = $this->loadRemoteAccess();
     $class = 'Am_FileConnector_' . ucfirst(toCamelCase($info['method']));
     $connector = new $class($info);
     if (!$connector->connect()) {
         $this->outText('Connection error: ' . Am_Controller::escape($connector->getMessage()));
         return false;
     }
     if (!$connector->chdir($info['root'])) {
         $this->outText('Could not chroot to root folder: [' . Am_Controller::escape($info['root']) . ']');
         return false;
     }
     foreach ($this->getSession()->upgrades as $k => $upgrade) {
         if (empty($upgrade->dir)) {
             continue;
         }
         $dir = $upgrade->dir . DIRECTORY_SEPARATOR . 'amember' . DIRECTORY_SEPARATOR;
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::SELF_FIRST);
         foreach ($iterator as $file) {
             if ($file->getFileName() == '.' || $file->getFileName() == '..') {
                 continue;
             }
             if (!strpos($file->getPathName(), $strip = $dir)) {
                 new Am_Exception_InputError(sprintf('Could not strip local root prefix: [%s] from fn [%s]', $strip, $file->getPathName()));
             }
             // path relative to amember root
             $path = substr($file->getPathName(), strlen($strip));
             if ($file->isDir()) {
                 if (!$connector->mkdir($path) && !$connector->ls($path)) {
                     $this->outText('Could not create folder [' . Am_Controller::escape($path) . ']<br />' . $connector->getError());
                     return false;
                 }
                 $this->outText('created folder ' . Am_Controller::escape($path) . "<br />\n");
             } else {
                 if (!$connector->put($file->getPathName(), $path)) {
                     $this->outText('Could not copy file [' . Am_Controller::escape($file->getPathName()) . '] to remote [' . Am_Controller::escape($path) . '] ' . $connector->getError());
                     return false;
                 }
                 $this->outText('copy file ' . Am_Controller::escape($path) . "<br />\n");
             }
         }
         // remove localdirectory and files
         $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($iterator as $file) {
             if ($file->getFileName() == '.' || $file->getFileName() == '..') {
                 continue;
             }
             if ($file->isDir()) {
                 rmdir($file->getPathName());
             } else {
                 unlink($file->getPathName());
             }
         }
         rmdir($dir);
         rmdir($upgrade->dir);
         unset($upgrade->dir);
         if (!$batch->checkLimits()) {
             //                $batch->stop();
             //                return false;
         }
     }
     return true;
 }
 function doDeleteAction()
 {
     $batch = new Am_BatchProcessor(array($this, 'deleteUser'));
     $context = null;
     if (!$batch->run($context)) {
         $this->sendDelRedirect();
     }
     $this->delImportHistory($this->session->params['import-id']);
     $this->session->unsetAll();
     $this->_redirect('admin-import');
 }
Example #6
0
 public function onRebuild(Am_Event_Rebuild $event)
 {
     $batch = new Am_BatchProcessor(array($this, 'batchProcess'), 5);
     $context = $event->getDoneString();
     $this->_rebuildName = $this->getId();
     $this->_sessionId = Zend_Session::getId();
     if ($batch->run($context)) {
         $event->setDone();
         $this->getDi()->storeRebuild->deleteByNameAndSession($this->_rebuildName, $this->_sessionId);
     } else {
         $event->setDoneString($context);
     }
 }
 public function run(&$context)
 {
     $ret = parent::run($context);
     if ($ret) {
         $this->session->unsetAll();
     }
     return $ret;
 }
Example #8
0
 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);
     $i = 0;
     $db = $this->getDi()->db;
     $foundrows = false;
     while ($r = $db->fetchRow($q)) {
         $foundrows = true;
         if (!$batch->checkLimits()) {
             return false;
         }
         $r['name'] = $r['name_f'] . ' ' . $r['name_l'];
         $this->saved->updateQuick(array('last_email' => $r['email'], 'sent_users' => $this->saved->sent_users + 1));
         if ($r['email'] == '') {
             continue;
         }
         $m = $this->getDi()->mail;
         $m->setPeriodic(Am_Mail::ADMIN_REQUESTED);
         $m->addHeader('X-Amember-Queue-Id', $this->_request->getFiltered('queue_id'));
         $m->addUnsubscribeLink(Am_Mail::LINK_USER);
         $m->addTo($r['email'], $r['name']);
         if ($reply_to = $this->getParam('reply_to')) {
             switch ($reply_to) {
                 case 'default':
                     $email = false;
                     break;
                 case 'other':
                     $email = $this->getParam('reply_to_other');
                     $name = null;
                     break;
                 default:
                     preg_match('/^admin-(\\d+)$/', $reply_to, $match);
                     $admin = $this->getDi()->adminTable->load($match[1], false);
                     if ($admin) {
                         $email = $admin->email;
                         $name = $admin->getName();
                     }
                     break;
             }
             if ($email = filter_var($email, FILTER_VALIDATE_EMAIL)) {
                 $m->setReplyTo($email, $name);
             }
         }
         $subject = $this->getParam('subject');
         $body = $this->getParam('body');
         $tpl = new Am_SimpleTemplate();
         $tpl->assignStdVars();
         if (strpos($body, '%user.unsubscribe_link%') !== false || strpos($subject, '%user.unsubscribe_link%') !== false) {
             $r['unsubscribe_link'] = Am_Mail::getUnsubscribeLink($r['email'], Am_Mail::LINK_USER);
         }
         $tpl->user = $r;
         $this->getDi()->hook->call(Am_Event::MAIL_SIMPLE_TEMPLATE_BEFORE_PARSE, array('template' => $tpl, 'body' => $body, 'subject' => $subject, 'mail' => $m, 'request' => $this->getRequest()));
         $subject = $tpl->render($subject);
         $body = $tpl->render($body);
         if ($this->getParam('email_template_layout_id') && ($layout = $this->getDi()->emailTemplateLayoutTable->load($this->getParam('email_template_layout_id', false)))) {
             $tpl->assign('content', $body);
             $body = $tpl->render($layout->layout);
         }
         $m->setSubject($subject);
         if ($this->getParam('format') == 'text') {
             $m->setBodyText($body);
         } else {
             $text = strip_tags($body);
             $html = strpos($body, '<html') === false ? "<html><head><title>{$subject}</title></head><body>{$body}</body></html>" : $body;
             $m->setBodyHtml($html);
             $m->setBodyText($text);
         }
         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 (!$foundrows) {
         return true;
     }
     if ($this->saved->count_users <= $this->saved->sent_users) {
         return true;
     }
     // we are done;
 }
Example #9
0
 function batchProcess(&$context, Am_BatchProcessor $batch)
 {
     $db = $this->getDi()->db;
     $q = $db->queryResultOnly("SELECT * FROM ?_user WHERE user_id > ?d", (int) $context);
     $userTable = $this->getDi()->userTable;
     $newsletterUserSubscriptionTable = $this->getDi()->newsletterUserSubscriptionTable;
     while ($r = $db->fetchRow($q)) {
         $u = $userTable->createRecord($r);
         $context = $r['user_id'];
         $newsletterUserSubscriptionTable->checkSubscriptions($u);
         if (!$batch->checkLimits()) {
             return;
         }
     }
     return true;
 }
Example #10
0
 public function handleAll()
 {
     $batch = new Am_BatchProcessor(array($this, '_handleAll'), 10);
     $context = $this->grid->getRequest()->getParam('group_context', '0-0');
     if ($batch->run($context)) {
         echo $this->renderDone();
     } else {
         list(, $processed) = explode('-', $context);
         echo $processed . " " . ___('records processed.');
         echo $this->getAutoClickScript(3, 'input#group-action-continue');
         echo $this->renderContinueForm(___('Continue'), $context);
     }
 }
 function sendAction()
 {
     if ($this->getParam('back')) {
         return $this->indexAction();
     }
     check_demo();
     if (!$this->saved) {
         $this->createSendSession();
         return $this->sendRedirect();
     }
     $batch = new Am_BatchProcessor(array($this, 'batchSend'), 10);
     $breaked = !$batch->run($this->saved);
     $breaked ? $this->sendRedirect() : $this->sendComplete();
 }
Example #12
0
 function batchProcess(&$context, Am_BatchProcessor $batch)
 {
     $db = $this->getDi()->db;
     $context = $context ? intval($context) : 0;
     $q = $db->queryResultOnly("SELECT DISTINCT subusers_parent_id\n            FROM ?_user\n            WHERE subusers_parent_id > ?d\n            ORDER BY subusers_parent_id", $context);
     $userTable = $this->getDi()->userTable;
     while ($r = $db->fetchRow($q)) {
         $context = $r['subusers_parent_id'];
         if ($u = $userTable->load($context, false)) {
             $this->checkAndUpdate($u);
         }
         if (!$batch->checkLimits()) {
             return;
         }
     }
     return true;
 }
Example #13
0
 public function handleAll()
 {
     $batch = new Am_BatchProcessor(array($this, '_handleAll'), 10);
     $page = $this->grid->getRequest()->getInt('group_page');
     if ($this->isDelete) {
         $page = 0;
     }
     if ($batch->run($page)) {
         echo $this->renderDone();
     } else {
         echo $page * $this->batchCount . " records processed.";
         echo $this->renderConfirmationForm(___("Continue"), $page);
     }
 }
Example #14
0
 public function onRebuild(Am_Event_Rebuild $event)
 {
     $batch = new Am_BatchProcessor(array($this, 'batchProcess'), 5);
     $context = $event->getDoneString();
     $this->_batchStoreId = 'rebuild-' . $this->getId() . '-' . Zend_Session::getId();
     if ($batch->run($context)) {
         $event->setDone();
         $this->getDi()->store->delete($this->_batchStoreId);
     } else {
         $event->setDoneString($context);
     }
 }