SupportPal Documentation

Upgrading to 2.5 from 2.4

SupportPal 2.5.0 is a major release adding support for PHP 7.3. The new version introduces a embeddable help widget that can be placed on your website, a ticket trash can where deleted tickets are held for 30 days, and automatically adding users to organisations based on their email address.

Contents

Estimated Upgrade Time: 1 Hour.

What's New?

View the 2.5 Release Notes for the new features and improvements in this series.

Upgrading Database

A number of new columns and indexes have been added to the database. Due to these changes, the upgrade script may be slow on large databases. We recommend to make use of the new upgrade CLI command which will run without timeouts.

Development Changes

Model events

The model events system has been updated to fix issues with events fired during database transactions. This may affect your plugin if it makes use of model events and you may need to rewrite the event handling code. We recommend to test your plugin code on 2.5.0 before upgrading, please contact us if you need a free development license.

For example, previously then Ticket::created event ran after the whole ticket had been created and hence all ticket relations (including the ticket message) were available. The Ticket::created event now runs as soon as the ticket is inserted into the ticket table which means relations are no longer accessible. This can result in PHP errors being thrown if improper error checking is in place, for example the following code will now result in an error:

    \App\Modules\Ticket\Models\Ticket::created(function ($ticket) {
        // The lastReply property will now return NULL and this code will result in an exception:
        // Trying to get property 'text' of non-object
        $ticket->lastReply->text;
    });

Ticket Trash

A trash can has been introduced which allows you to view and restore deleted tickets. Any plugins, widgets or reports with SQL queries accessing the ticket table may now return empty results when viewing a deleted ticket. This can lead to PHP errors if there's improper error checking in place.

Please ensure your code functions correctly before upgrading. This means include/exclude trashed tickets as expected, and also works when viewing a trashed ticket in the operator panel. If you need a development license please contact us.

Eloquent Models

If using the Ticket model to build a query like below, tickets in the trash are automatically excluded.

    $tickets = \App\Modules\Ticket\Models\Ticket::where('department_id', 1)->get();

To include trashed tickets, you must specifically call the withTrashed function in your query.

    $tickets = \App\Modules\Ticket\Models\Ticket::withTrashed()->where('department_id', 1)->get();
Model Relations

If you load a ticket via another model this will exclude trashed tickets and now return NULL.

    // Example 1 - eager loading
    $message = \App\Modules\Ticket\Models\Message::with('ticket')->first();
    $message->ticket;

    // Example 2 - lazy loading
    $message = \App\Modules\Ticket\Models\Message::first();
    $message->ticket;

To include trashed tickets we need to use withTrashed:

    // Example 1 - eager loading
    $message = \App\Modules\Ticket\Models\Message::with([ 'ticket' => function ($query) {
        $query->withTrashed();
    } ])->first();
    $message->ticket;

    // Example 2 - lazy loading
    $message = \App\Modules\Ticket\Models\Message::first();
    $message->load([ 'ticket' => function ($query) {
        $query->withTrashed();
    } ]);
    $message->ticket;

Query Builder

If you use the query builder directly (DB facade), then this will include trashed tickets by default.

    // Example 1
    $tickets = \DB::table('ticket')->where('department_id', 1)->get();

    // Example 2
    $messages = = \DB::table('ticket_message')
        ->join('ticket', 'ticket.id', '=', 'ticket_message.ticket_id')
        ->get();

You can exclude trashed tickets by checking if the deleted_at column is NULL.

    // Example 1
    $tickets = \DB::table('ticket')->whereNull('deleted_at')->where('department_id', 1)->get();

    // Example 2
    $messages = = \DB::table('ticket_message')
        ->join('ticket', 'ticket.id', '=', 'ticket_message.ticket_id')
        ->whereNull('ticket.deleted_at')
        ->get();

Other Important Changes