I want to share this weird problem I found.
I upgrade form 1.10 to 1.1, The environment is:
- Bitnami virtual machine
- OS: Debian
- PHP: 5.6.38
- MySql: 5.6.41
Eventually I get a 500 error when creating a new ticket. I think I tracked the bug. You can repeat the error:
1 - Create a new ticket
2 - Delete the ticket
3 - Restart Server
4 - Create a new ticket: you should get the error
I believe this happen because MySql resets the auto-inc when the server is turned on again. When the ticket is deleted, it is removed from the ost_ticket, but the data in ost_thread is still there. When the server is reinitialized the MySql will reuse the deleted ticket ID, but this will be duplicated in the object_id in the ost_thread table and show an error. If you refresh the page it will succeeded.
This is not an issue if you have the server running full time. I use osticket inside a virtual machine and turn it on/off everyday.
The error is:
Fatal error: Uncaught exception 'ObjectNotUnique' with message 'One object was expected; however multiple objects in the database matched the query. In fact, there are 2 matching objects.1' in /opt/bitnami/apache2/htdocs/osticket2017/include/class.orm.php:1355 Stack trace: #0 /opt/bitnami/apache2/htdocs/osticket2017/include/class.orm.php(606): QuerySet->one() #1 /opt/bitnami/apache2/htdocs/osticket2017/include/class.thread.php(3038): VerySimpleModel::lookup(Array) #2 /opt/bitnami/apache2/htdocs/osticket2017/include/class.orm.php(381): ObjectThread::lookup(Array) #3 /opt/bitnami/apache2/htdocs/osticket2017/include/class.orm.php(417): VerySimpleModel->get('thread', NULL) #4 /opt/bitnami/apache2/htdocs/osticket2017/include/class.ticket.php(803): VerySimpleModel->__get('thread') #5 /opt/bitnami/apache2/htdocs/osticket2017/include/class.ticket.php(3030): Ticket->getThread() #6 /opt/bitnami/apache2/htdocs/osticket2017/include/class.ticket.php(3878): Ticket->logEvent('created', NULL, Object(StaffSession)) #7 /opt/bitnami/apache2/htdocs/osticket2017/include/class.ticket.php(4103): Ticket::create(Array, Array, 'staff', false) #8 /opt/bitnami/apache2/htdocs/osticket2017/scp/tickets.php(399): Ticket::open(Array, Array) #9 {main} thrown in /opt/bitnami/apache2/htdocs/osticket2017/include/class.orm.php on line 1355
The 2 objects:
QuerySet Object ( [model] => TicketThread [constraints] => Array ( [0] => Q Object ( [constraints] => Array ( [object_type] => T [object_id] => 234 ) [negated] => 0 [ored] => 0 ) ) [path_constraints] => Array ( ) [ordering] => Array ( ) [limit] => [offset] => 0 [related] => Array ( ) [values] => Array ( ) [defer] => Array ( ) [aggregated] => [annotations] => Array ( ) [extra] => Array ( ) [distinct] => Array ( ) [lock] => [chain] => Array ( ) [options] => Array ( ) [iter] => 1 [compiler] => MySqlCompiler [query] => MySqlExecutor Object ( [stmt] => [fields] => Array ( ) [sql] => SELECT A1. FROM ost_thread
A1 WHERE A1.object_type
= :1 AND A1.object_id
= :2 [params] => Array ( [0] => T [1] => 234 ) [map] => [unbuffered] => [types] => Array ( [0] => 3 [1] => 3 [2] => 254 [3] => 252 [4] => 12 [5] => 12 [6] => 12 ) ) [count] => [total] => [iterator] => ModelResultSet Object ( [inner:protected] => CallbackSimpleIterator Object ( [current] => TicketThread Object ( [counts] => [object] => [entries] => [collaborators] => [participants] => [ht] => Array ( [id] => 263 [object_id] => 234 [object_type] => T [extra] => [lastresponse] => [lastmessage] => [created] => 2019-05-23 16:08:59 ) [dirty] => Array ( ) [new] => [deleted] => [deferred] => Array ( ) ) [eoi] => 1 [callback] => Closure Object ( [static] => Array ( [func] => Array ( [0] => MySqlExecutor Object ( [stmt] => [fields] => Array ( ) [sql] => SELECT A1. FROM ost_thread
A1 WHERE A1.object_type
= :1 AND A1.object_id
= :2 [params] => Array ( [0] => T [1] => 234 ) [map] => [unbuffered] => [types] => Array ( [0] => 3 [1] => 3 [2] => 254 [3] => 252 [4] => 12 [5] => 12 [6] => 12 ) ) [1] => getArray ) [cache] => ) [this] => ModelInstanceManager Object ( [model] => TicketThread [map] => [resource] => MySqlExecutor Object ( [stmt] => [fields] => Array ( ) [sql] => SELECT A1.* FROM ost_thread
A1 WHERE A1.object_type
= :1 AND A1.object_id
= :2 [params] => Array ( [0] => T [1] => 234 ) [map] => [unbuffered] => [types] => Array ( [0] => 3 [1] => 3 [2] => 254 [3] => 252 [4] => 12 [5] => 12 [6] => 12 ) ) [annnotations] => [defer] => Array ( ) [annotations] => Array ( ) ) ) [key] => 1 ) [eoi:protected] => 1 [storage:protected] => Array ( [0] => TicketThread Object ( [counts] => [object] => [entries] => [collaborators] => [participants] => [ht] => Array ( [id] => 262 [object_id] => 234 [object_type] => T [extra] => [lastresponse] => [lastmessage] => 2019-05-23 15:54:47 [created] => 2019-05-23 15:54:47 ) [dirty] => Array ( ) [new] => [deleted] => [deferred] => Array ( ) ) [1] => TicketThread Object ( [counts] => [object] => [entries] => [collaborators] => [_participants] => [ht] => Array ( [id] => 263 [object_id] => 234 [object_type] => T [extra] => [lastresponse] => [lastmessage] => [created] => 2019-05-23 16:08:59 ) [dirty] => Array ( ) [new] => [deleted] => [deferred] => Array ( ) ) ) ) )
Table ost_ticket.
Table ost_thread: duplicated object_id=234
I don't know how to solve this. I think that upgrading to the mySQL > 8 may fix that, I read the auto_inc in mySQL is solved. I don't recall I having this issue on osticket 1.10.