Empty Alert

Robust

Well-known member
So I use the following code:

Code:
                    XenForo_Model_Alert::alert(
                        $user['user_id'],
                        $user['user_id'],
                        $user['username'],
                        'task_completion',
                        $user['user_id'],
                        'completed'
                    );

The user gets the alerts, but they are always empty. When I hover over alerts, it just disappears and shows none, and when I go to show all alerts they're not there, but when it's initially processed (before marking them as 'read') it shows the number beside the "Alert" text.

What's up? Never had this problem with alerts before. It's a custom alert handler, which does this:

(canViewAlert -> true)
Code:
    public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
    {
        return $model->getModelFromCache('Model_Class')->getTasksByTaskIds($contentIds);
    }

That method returns:
Code:
    public function getTasksByTaskIds(array $taskIds)
    {
        return $this->fetchAllKeyed('
            SELECT *
            FROM aupp_task AS task
            WHERE task_id IN ('. $this->_getDb()->quote($taskIds) .')
        ', 'task_id');
    }

A little urgent, so thanks for any help I can get :)
 
Does your template have the correct name? It's getting the data if the alert is at least showing up
 
Does your template have the correct name? It's getting the data if the alert is at least showing up
Template name is:
alert_task_completion_completed

With content:
Code:
{xen:phrase aupp_you_have_just_completed_a_task,
    'taskname={$content.title}',
    'taskpoints={$content.added_points}'}
 
Does your template have the correct name? It's getting the data if the alert is at least showing up
The alert doesn't exact show, btw. It's shown like 1 alert or something, but when I hover over it says "There are no new alerts". It's also not shown on "Show all alerts" - so I don't even see the empty alert box without any data. I just see the number there, which goes away after hover.
 
Here's xf_user_alert table data:
396012b187.png
 
I would guess a content type and content type field hasn't been added and/or no Alert handler code.
 
I am having the same issue right now. Mind sharing how you got around it?
I wish I wrote down what solved it for me. I remember it was something obvious but the last thing I'd think of at the same time. I really just can't remember what I did.

Ensure you have the content type setup and all, that's critical. First thing you need to do. You also need an AlertHandler class for it.
 
I have both content type field and content type setup. (using https://xenforo.com/community/resources/content-type-management.2513/) and have my handler code.

Maybe you guys can spot something I cannot.

Call an alert:
Code:
XenForo_Model_Alert::alert($var['user_id'], 0, "", 'tickets', $var['user_id'], 'new');

AlertHandler:
Code:
class ServUO_shardwatch_AlertHandler_Ticket extends XenForo_AlertHandler_Abstract
{
    public function getContentByIds(array $contentIds, $model, $userId, array $viewingUser)
    {
        return $model->getModelFromCache('ServUO_shardwatch_Model_ticket')->getTicketsByIds($contentIds);
    }
}

Model method:
Code:
  public function getTicketsByIds(array $ticketIds)
  {
      return $this->fetchAllKeyed('
   SELECT *
   FROM xf_servuo_shardwatch_tickets
   WHERE ticket_id IN (' . $this->_getDb()->quote($ticketIds) . ')
', 'ticket_id');
  }

alert_tickets_new template:
Code:
{xen:phrase ServUO_shardwatch_ticketAlert}

phrase:
Code:
You have a new support ticket.
 
When you added the content type and content type field for the alert handler did you delete the contenttypes entry in the data registry?
 
When you added the content type and content type field for the alert handler did you delete the contenttypes entry in the data registry?
You also need to manually rebuild the content type cache if you modify the content type tables outside of the installer/uninstaller.
 
It seems he created he content types through my management add on so it does these things automatically.

Probably worth doing them manually just to be sure though.
 
  • Like
Reactions: Xon
I just had this problem, so I thought I would put the solution for own experience here in case it helps someone else at some point.

Anyway, after a few hours of banging my head against a wall, I realised that........I was stupid, I had previously discovered this many times before in my life, and while it wasn't the complete answer to my problem, I knew it must have something do with my current situation, so I decided to start from the very beginning of creating an add on and under the drop down menu of my add-on, I selected "edit", it was here that took note of my add on id, which was "My_Addon_Id", remember this, because this part is imperative to my solution. So with the id noted freshly in my mind, I then went and checked the xf_content_type table and it was here that my stupidity had flourished, because it was here that I had put "my_addon_id", instead of "My_Addon_Id".

So, if you get stuck, at least make sure your addon id is correct ;)
 
Top Bottom