'Execute the defined actions on the item.'

def perform_actions(self, item, data):

    ban_info = getattr(item, 'ban_info', {})
    mod_banned = ban_info.get('moderator_banned')
    should_approve = ((item._spam and (not mod_banned)) or (self.reports and item.reported))
    if ((self.action == 'approve') and should_approve):
        approvable_author = ((not data['author']._spam) or self.approve_banned)
        if approvable_author:
            was_removed = item._spam
            admintools.unspam(item, moderator_unbanned=True, unbanner=ACCOUNT.name, train_spam=True, insert=item._spam)
            log_action = None
            if isinstance(item, Link):
                log_action = 'approvelink'
            elif isinstance(item, Comment):
                log_action = 'approvecomment'
            if log_action:
                if self.action_reason:
                    reason = replace_placeholders(self.action_reason, data, self.parent.matches)
                else:
                    reason = ('unspam' if was_removed else 'approved')
                ModAction.create(data['subreddit'], ACCOUNT, log_action, target=item, details=reason)
            g.stats.simple_event('automoderator.approve')
    if (self.action in {'remove', 'spam', 'filter'}):
        spam = (self.action == 'spam')
        keep_in_modqueue = (self.action == 'filter')
        admintools.spam(item, auto=keep_in_modqueue, moderator_banned=True, banner=ACCOUNT.name, train_spam=spam)
        log_action = None
        if isinstance(item, Link):
            log_action = 'removelink'
        elif isinstance(item, Comment):
            log_action = 'removecomment'
            queries.unnotify(item)
        if log_action:
            if self.action_reason:
                reason = replace_placeholders(self.action_reason, data, self.parent.matches)
            else:
                reason = ('spam' if spam else 'remove')
            ModAction.create(data['subreddit'], ACCOUNT, log_action, target=item, details=reason)
        g.stats.simple_event(('automoderator.%s' % self.action))
    if (self.action == 'report'):
        if self.action_reason:
            reason = replace_placeholders(self.action_reason, data, self.parent.matches)
        else:
            reason = None
        Report.new(ACCOUNT, item, reason)
        admintools.report(item)
        g.stats.simple_event('automoderator.report')
    if (self.set_nsfw is not None):
        if (item.over_18 != self.set_nsfw):
            item.over_18 = self.set_nsfw
            item._commit()
            log_details = None
            if (not self.set_nsfw):
                log_details = 'remove'
            ModAction.create(data['subreddit'], ACCOUNT, 'marknsfw', target=item, details=log_details)
            item.update_search_index()
    if (self.set_contest_mode is not None):
        if (item.contest_mode != self.set_contest_mode):
            item.contest_mode = self.set_contest_mode
            item._commit()
    if (self.set_locked is not None):
        if (item.locked != self.set_locked):
            item.locked = self.set_locked
            item._commit()
            log_action = ('lock' if self.set_locked else 'unlock')
            ModAction.create(data['subreddit'], ACCOUNT, log_action, target=item)
    if (self.set_sticky is not None):
        if (item.is_stickied(data['subreddit']) != bool(self.set_sticky)):
            if self.set_sticky:
                if isinstance(self.set_sticky, bool):
                    num = None
                else:
                    num = self.set_sticky
                data['subreddit'].set_sticky(item, ACCOUNT, num)
            else:
                data['subreddit'].remove_sticky(item, ACCOUNT)
    if (self.set_suggested_sort is not None):
        if (not item.suggested_sort):
            item.suggested_sort = self.set_suggested_sort
            item._commit()
            ModAction.create(data['subreddit'], ACCOUNT, action='setsuggestedsort', target=item)
    if self.set_flair:
        can_update_flair = False
        if isinstance(item, Link):
            if (item.flair_text or item.flair_css_class):
                can_update_flair = self.overwrite_flair
            else:
                can_update_flair = True
        elif isinstance(item, Account):
            if data['subreddit'].is_flair(item):
                can_update_flair = self.overwrite_flair
            else:
                can_update_flair = True
        if can_update_flair:
            text = replace_placeholders(self.set_flair['text'], data, self.parent.matches)
            cls = replace_placeholders(self.set_flair['class'], data, self.parent.matches)
            text = text[:64]
            cls = re.sub('[^\\w    -]', '', cls)
            classes = cls.split()[:10]
            classes = [cls[:100] for cls in classes]
            cls = '    '.join(classes)
            if isinstance(item, Link):
                item.set_flair(text, cls)
            elif isinstance(item, Account):
                item.set_flair(data['subreddit'], text, cls)
            g.stats.simple_event('automoderator.set_flair')
