Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Issue in writing a plugin to do ticket auto assignment

Hi team,

We were building a plugin for OsTicket for doing auto assignment. We create a signal::connect on ticket model created and when we call $ticket->assignToStaff its throwing the below error:

"PHP message: PHP Fatal error:  Call to a member function addNote() on null in /var/www/html/osticket/include/class.ticket.php on line 2635"

It works fine when we write the logic in class.ticket.php. What could be the reason? Any fix can be done to do this? 

plugin.php : 

require_once(INCLUDE_DIR .'class.signal.php');
function bootstrap() {
Signal::connect('model.created', array($this, 'doAutoAssign'), 'Ticket');
}

function doAutoAssign($ticket) {
$ticket->assignToStaff(<staffid>, "SYSTEM (Random assignment)", $alert=true);
}

Tagged:

Comments

  • moderator note: This is not a Troubleshooting and Problem thread.  Moved to Mods and Customizations.

    I'm pretty sure that what this "Call to a member function addNote() on null in " is saying is that the value of what is being passed to addNote is null, and should not be.
  • edited November 2017
    Hmm i think the issue is that you're connecting to the model.created signal rather than ticket.created.

    model.created is used when generating SQL queries by the looks of it.

    I used ticket.created in my loadbalancer plugin that i recall didn't get this error: https://github.com/Micke1101/OSTicket-plugin-loadbalancer/blob/master/loadbalancer.php
  • @Micke1101

    Beautiful! That worked!! thanks so much for quick reply! :)
  • I've completed the plugin and have put up in github. Let me know what you think :) 


    Thanks


  • Looks nice mate!
  • edited April 26
    Tested this on an Ubuntu 16.04 box running osTicket 1.10.1 and the tickets are created but doesnt seem to auto-assign.

    Does this run on a cron or something? Or should it auto-assign upon Ticket creation?


    However, your fix is brilliant; I applied the same tweak to another auto-assignment plugin and it fixed it!

    This one; it was mentioned in another post on here somewhere:


    If you modify the "spreader.php" file on line 25 to what you said, "i think the issue is that you're connecting to the model.created signal rather than ticket.created."

    It completely fixes the following error I was receiving and makes the plugin work and has round-robin functioning perfectly. I'll post the error in a separate post cause I'm running out of characters :P

  • edited April 26
    This was the error for spreader.php plugin:


    status=bounced (Command died with status 255: "/var/www/osticket/upload/api/pipe.php". Command output: PHP Fatal error:  Call to a member function addNote() on null in /var/www/osticket/upload/include/class.ticket.php 
    on line 2635 PHP Stack trace: 
    PHP   1. {main}() /var/www/osticket/upload/api/pipe.php:0 
    PHP   2. PipeApiController::process() /var/www/osticket/upload/api/pipe.php:26 
    PHP   3. TicketApiController->processEmail() /var/www/osticket/upload/include/api.tickets.php:222 
    PHP   4. TicketApiController->createTicket() /var/www/osticket/upload/include/api.tickets.php:178 
    PHP   5. Ticket::create() /var/www/osticket/upload/include/api.tickets.php:132 
    PHP   6. Ticket->save() /var/www/osticket/upload/include/class.ticket.php:3373 
    PHP   7. VerySimpleModel->save() /var/www/osticket/upload/include/class.ticket.php:2740 
    PHP   8. Signal::send() /var/www/osticket/upload/include/class.orm.php:619 
    PHP   9. call_user_func_array:{/var/www/osticket/upload/include/class.signal.php:98}() /var/www/osticket/upload/include/class.signal.php:98 
    PHP  10. SpreaderPlugin::spreadTicket() /var/www/osticket/upload/include/class.signal.php:98 
    PHP  11. Ticket->assignToStaff() /var/www/osticket/upload/include/plugins/osticket-spreader/spreader.php:56 
    PHP  12. Ticket->onAssign() /var/www/osticket/upload/include/class.ticket.php:2145 
    PHP  13. Ticket->logNote() /var/www/osticket/upload/include/class.ticket.php:1727 
    PHP  14. Ticket->postNote() /var/www/osticket/upload/include/class.ticket.php:2611 )
Sign In or Register to comment.