/**
  * Will always execute after any/all migrations have run. The purpose of this is to clean up and to handle any
  * unexpected errors which may occur.
  *
  * @param   Exception|null $e
  */
 public function shutdown(Exception $e = null)
 {
     // Run once.
     if ($this->shutdown) {
         return;
     }
     $this->shutdown = true;
     // Revert back to previous error handling.
     restore_error_handler();
     // If there's an error but no exception, setup an exception now for reporting purposes.
     if ($this->error && !$e) {
         $e = new MigrationException("The migration" . ($this->lastMigrationFile ? " '{$this->lastMigrationFile}.php'" : "") . " terminated unexpectedly.");
     }
     if ($e) {
         // Rollback database changes and notify user.
         DB::getConn()->transactionRollback();
         $this->output("ERROR" . ($e->getCode() != 0 ? " (" . $e->getCode() . ")" : "") . ": " . $e->getMessage());
         $this->output("\nNote: Any database changes have been rolled back.");
         $this->output("\nStack Trace:");
         $this->output($e->getTraceAsString());
         exit(1);
     }
 }