Hi everyone.
I could not find the information out there, so i’m posting.
I am more a front-end guy reaching into back-end now and then, rather than a full-fledget dev.
For a customer we have an iPhone-App that gets fed by MODx-Revolution via apples .plist-XML-derivat.
That includes a List of news and a list of podcast episodes.
We are using push-notifications, so i like to fire some lines of php the moment a new document gets published.
A Plugin should listen for that, ask if its News or Podcast-Category and send the right push-note out.
For Debugging i wanted to send me a mail, instead of developing with the notification system. So i created a new plugin, that sends me an email if fired.
$e = & $modx->Event; // get a reference to the event
$eventName = $e->name;
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,'löööft');
$modx->mail->set(modMail::MAIL_FROM,'[email protected]');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SENDER,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SUBJECT,$eventName);
$modx->mail->address('to','[email protected]');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
}
$modx->mail->reset();
Now, i tried using the OnDocPublished-Event. Did not work.
Tried OnDocFormSave. Did not work.
Tried OnWebPageComplete.
Did work.
Now to my question: How can it be, that a plug-in behaves differently according to the event it listened to?
As i read
here, there are different service types, but i have the feeling of reaching a field of the RTFM, that is really sparingly documented.
Can anybody give me some hints for the right directions?
Much appreciated, thanks!
niklas