Handling Endless Recursion in saveEntry? I'm trying to update the expiry field—based on an existing field (in this case classDate)—as soon as an entry is saved.

Based on this answer, the clever recursion code in carlcs' Auto Expire plugin, I was able to get it working with this code:

public function init()
{

craft()-&gt;on('entries.saveEntry', function(Event $event) {
    $entry = $event-&gt;params['entry'];

    if ($entry-&gt;section-&gt;name == "Classes")
    {
        $entry-&gt;expiryDate = $entry-&gt;classDate;

        static $recursionLevel = 0;

        if ($recursionLevel == 0)
         {
            $recursionLevel++;
            $saved =   craft()-&gt;entries-&gt;saveEntry($entry);
         }

    }


});
}


But that seems a little dirty because saveEntry is going to get called again. 

Is there a better way to handle the recursion? Bob's answer here leads me to believe you can call craft()-&gt;elements-&gt;saveElement which won't raise the saveEntry event again but I couldn't get that to work.

What am I missing? Seems too easy...
I'm not sure if it's any less dirty, but another way you could do it would be:

public function init()
{
    craft()-&gt;on('entries.saveEntry', function(Event $event)
    {
        $entry = $event-&gt;params['entry'];

        if ($entry-&gt;section-&gt;name == "Classes")
        {
            craft()-&gt;db-&gt;createCommand()-&gt;update(
                'entries',
                array('expiryDate' =&gt; DateTimeHelper::formatTimeForDb($entry-&gt;classDate)),
                array('id' =&gt; $entry-&gt;id)
            );
        }
    });
}