Skip to content

Instantly share code, notes, and snippets.

@alroniks
Created February 18, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alroniks/b82eba16efb6db0834f8 to your computer and use it in GitHub Desktop.
Save alroniks/b82eba16efb6db0834f8 to your computer and use it in GitHub Desktop.
Batch Subscriber for Sendex
<?php
$modx->addPackage('sendex', MODX_CORE_PATH . 'components/sendex/model/');
$subscribers = array(
array('Фамилия Имя Отчество' , 'email@mail.ru'),
);
foreach ($subscribers as $s) {
if (!$u = $modx->getObject('modUserProfile', array('email' => $s[1]))) {
$response = $modx->runProcessor('security/user/create', array(
'username' => $s[1],
'email' => $s[1],
'fullname' => $s[0],
'passwordnotifymethod' => 1,
'active' => true
));
}
}
foreach ($subscribers as $s) {
if ($user = $modx->getObject('modUserProfile', array('email' => $s[1]))) {
$newsletter = array('newsletter_id' => 1, 'email' => $s[1], 'user_id' => $user->get('id'));
if (!$subscriber = $modx->getObject('sxSubscriber', $newsletter)) {
$subscriber = $modx->newObject('sxSubscriber');
$subscriber->fromArray($newsletter);
$subscriber->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment