Skip to content

Instantly share code, notes, and snippets.

@jrast
Created March 30, 2012 21:36
Show Gist options
  • Save jrast/2255310 to your computer and use it in GitHub Desktop.
Save jrast/2255310 to your computer and use it in GitHub Desktop.
Silverstripe Tasks with templated email
<!-- This is located at /paht/project/themes/jotoedi/Email/Anmeldungen.ss -->
<h1>Anmeldungen für die nächsten Touren</h1>
<% control Touren %>
<h2>$TourName</h2>
<% end_control %>
// ....
function process() {
$dateInWords = '+ 3 week 2 days';
$dateInOneWeek = date('Y-m-d', strtotime($dateInWords));
echo 'Touren zwischen Heute ('.date('d.m.Y').') und dem ' . date('d.m.Y', strtotime($dateInWords)) . ":\n";
$touren = DataObject::get(
'Tour',
"StartDatum < '" . $dateInOneWeek . "' AND StartDatum > NOW()",
'StartDatum ASC'
);
$data = array(
'Touren' => $touren
);
$email = new Email('[email protected]', '[email protected]', 'JO-Tödi: Tourenanmeldungen', '');
$email->setTemplate('Anmeldungen');
$email->populateTemplate($data);
if($email->send())
echo "E-Mail versendet!\n";
else
echo "E-Mail konnte nicht gesendet werden!\n";
}
// ...
@jrast
Copy link
Author

jrast commented Mar 30, 2012

If i run this task from command line, i get this error:

ERROR [User Warning]: None of these templates can be found in theme 'jotoedi': Anmeldungen.ss IN GET /AnmeldungenTask

@jrast
Copy link
Author

jrast commented Mar 30, 2012

Problem Solved!

The Problem is caused by the different manifest files CLI and WEB use!
So you have to run this:

php /path/project/sapphire/cli-script.php AnmeldungenTask flush=1

to generate the new manifest files for the cli script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment