500: Server Error - after saving - api/v1/companies/

Hi,

After the latest update of InvoiceNinja (running on php v7.4.28) I started to encounter this error after saving settings or changes:

500: Server Error

I checked the /storage/logs and there is only the laravel.log that shows:

[2022-03-08 13:43:03] production.ERROR: Cannot declare class Onboarding, because the name is already in use {“exception”:"[object] (Symfony\Component\ErrorHandler\Error\FatalError(code: 0): Cannot declare class Onboarding, because the name is already in use at /home/user/invoice.mydomain.nl/database/migrations/2021_11_08_131308_onboarding.php:0)
[stacktrace]
#0 {main}
"}

I tried to force update through the GUI but than I get the following error:

XMLHttpRequest error.

If I save something with the webdev tools open in Chrome on the Console or Network tab I get an 500 error for:

  1. Request URL:

https://invoice.mydomain.nl/api/v1/companies/Wpmbk5ezJn?

Any thoughts? Thanks in advance!

Hi,

@david any thoughts?

Update: I decided to update to PHP v8.0 and now these problems are solved. Not sure why, but I’m happy it’s solved.

1 Like

Ok, unfortunately I celebrated a bit too early. Yesterday I had no issues but today the same thing started again.
If I check my chrome web tools output again, I get for the following url: Failed to load resource: the server responded with a status of 500 ()

https://invoice.mydomain.nl/api/v1/companies/Wpmbk5ezJn

If i open that page it says:

{“message”:“Invalid token”,“errors”:{}}

Then if I inspect the console tab again:

POST: https://invoice.mydomain.nl/api/v1/refresh?&first_load=true&include_static=true
main.foss.dart.js?v=5.3.66:61335
PUT: https://invoice.mydomain.nl/api/v1/companies/Wpmbk5ezJn?
main.foss.dart.js?v=5.3.66:61335 500: Server Error

For a moment I thought I would be an issue with the API token?
This is my current output for dev tools / network tab / request headers:

  1. x-api-secret: null
  2. x-api-token: crFy…etc.
  3. x-client-version: 5.0.77
  4. x-requested-with: XMLHttpRequest

And the output of general:

  1. Request URL: https://invoice.mydomain.nl/api/v1/companies/Wpmbk5ezJn?
  2. Request Method: PUT
  3. Status Code: 500

Note; that the following does work:

  1. Request URL: https://invoice.mydomain.nl/api/v1/refresh?current_company=true&updated_at=1646862440&first_load=true
  2. Request Method: POST
  3. Status Code: 200

Would it be an issue with the Request Method? Any help would be highly appreciated. If I can do anything to provide more information, please let me know.

Thank you in advance!

What is the error in the logs when you PUT to the company?

In the root folder of my InvoiceNinja there is error_log which only has this inside:

PHP Notice: Constant PASSWORD_DEFAULT already defined in /home/myuser/invoice.mydomain.nl/update_pass.php on line 17

I didn’t change anything about the default installation through Softaculous on cPanel. (So I didn’t put ‘PUT’ to the company?)

In the /public/ folder the error_log has this inside:

PHP Fatal error: Cannot declare class Onboarding, because the name is already in use in /home/myuser/invoice.mydomain.nl/database/migrations/2021_11_08_131308_onboarding.php on line 0

In the cPanel logfile (/home/user/log/) this is the output:

20.124.24.205 - - [09/Mar/2022:00:43:29 +0100] “GET / HTTP/1.1” 301 244 “-” “python-requests/2.27.1”
20.124.24.205 - - [09/Mar/2022:00:43:30 +0100] “GET / HTTP/1.1” 301 244 “-” “python-requests/2.27.1”
35.232.0.140 - - [09/Mar/2022:08:02:55 +0100] “GET / HTTP/1.1” 301 244 “-” “python-requests/2.27.1”
212.192.241.34 - - [10/Mar/2022:00:37:39 +0100] “GET / HTTP/1.1” 301 244 “-” “python-requests/2.27.1”
212.192.241.34 - - [10/Mar/2022:00:37:55 +0100] “GET /.env HTTP/1.1” 301 248 “-” “python-requests/2.27.1”
35.223.227.96 - - [10/Mar/2022:08:03:49 +0100] “GET / HTTP/1.1” 301 244 “-” “python-requests/2.27.1”

@christopherus

What version of PHP are you using?

php version 8.0.16 (on the server)

(Other software running on different domains is Wordpress only.)

@christopherus

if you could try one thing:

open the file in

database/migrations/2021_11_08_131308_onboarding.php

and replace all the contents with the following please.

<?php

return new class extends Migration
{

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        if (!Schema::hasColumn('accounts', 'is_onboarding'))
        {

            Schema::table('accounts', function (Blueprint $table) {
                $table->boolean('is_onboarding')->default(false);
            });
            
        }


        if (!Schema::hasColumn('accounts', 'onboarding'))
        {

            Schema::table('accounts', function (Blueprint $table) {
                $table->mediumText('onboarding')->nullable();
            });
            
        }

    }
};

I just leave full error log here:

[2022-03-11 00:01:00][990] Processing: App\Jobs\Util\VersionCheck
[2022-03-11 00:01:01][990] Processed:  App\Jobs\Util\VersionCheck
[2022-03-11 00:01:01][995] Processing: App\Jobs\Util\SchedulerCheck
PHP Fatal error:  Cannot declare class Onboarding, because the name is already in use in 
l/database/migrations/2021_11_08_131308_onboarding.php on line 7
   Symfony\Component\ErrorHandler\Error\FatalError 
  Cannot declare class Onboarding, because the name is already in use
  at database/migrations/2021_11_08_131308_onboarding.php:7
      3▕ use Illuminate\Database\Migrations\Migration;
      4▕ use Illuminate\Database\Schema\Blueprint;
      5▕ use Illuminate\Support\Facades\Schema;
      6▕ 
  ➜   7▕ class Onboarding extends Migration
      8▕ {
      9▕     /**
     10▕      * Run the migrations.
     11▕      *
   Whoops\Exception\ErrorException 
  Cannot declare class Onboarding, because the name is already in use
  at database/migrations/2021_11_08_131308_onboarding.php:7
      3▕ use Illuminate\Database\Migrations\Migration;
      4▕ use Illuminate\Database\Schema\Blueprint;
      5▕ use Illuminate\Support\Facades\Schema;
      6▕ 
  ➜   7▕ class Onboarding extends Migration
      8▕ {
      9▕     /**
     10▕      * Run the migrations.
     11▕      *
      e[2m+1 vendor frames e[22m
  2   [internal]:0
      Whoops\Run::handleShutdown()

Thank you @david for your help! I tried, without succes…

@christopherus

What error do you see now?

InvoiceNinja root error_log:

[11-Mar-2022 00:00:09 UTC] PHP Fatal error: Cannot declare class Onboarding, because the name is already in use in /home/user/invoice.mydomain.nl/database/migrations/2021_11_08_131308_onboarding.php on line 7

/public/ error_log:

No changes since last time.

cPanel invoice.mydomain.nl log:

No changes since last time.

cPanel SSL log:

35.223.227.96 - - [10/Mar/2022:08:03:50 +0100] “GET / HTTP/1.1” 200 1661 “-” “python-requests/2.27.1”
31.161.206.85 - - [10/Mar/2022:10:03:06 +0100] “GET /images/emails/forum.png HTTP/2.0” 200 1191 “-” “Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148”
31.161.206.85 - - [10/Mar/2022:10:03:06 +0100] “GET /images/emails/slack.png HTTP/2.0” 200 3215 “-” “Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148”
31.161.206.85 - - [10/Mar/2022:10:03:06 +0100] “GET /images/emails/email.png HTTP/2.0” 200 2298 “-” “Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148”
31.161.206.85 - - [10/Mar/2022:10:03:06 +0100] “GET /public/storage/hm0O9gmZJdMtRpNOvhEbtD0s2TCBV8mx/gvGszeyvmnrvFoGAy1GFnkEe5HR0M1tvguXAxhMV.png HTTP/2.0” 200 12955 “-” “Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148”

Hi.

I’m in a similar situation.
I have deployed Invoice Ninja in a Synology using Web Station, but after the Apache or PHP update the PDF generation using Phantom has stopped working (registered using token).

I do not know how to solve it but I have to generate budgets and invoices.

I think the problem may be in the compiled autoloader, i have tagged a new release which should hopefully resolve this.

Thank you very much @david! I’ll inform you asap after I update through my Softaculous managed installation.

Thank you @david for the quick update. Unfortunately it didn’t solve my problem just yet.
I updated through the UI of InvoiceNinja and after that ran: ‘php artisan optimize’
Both in various browsers and in the MacOSX app (Version 5.0.77 (77)) this problem persists.

Anything else I can do?

Thanks again.

can you try

composer dump
[myuser@premium15 invoice.mydomain.nl]$ composer dump
Generating optimized autoload files
Class Razorpay\Tests\fundTest located in ./vendor/razorpay/razorpay/tests/FundTest.php does not comply with psr-4 autoloading standard. Skipping.
Class Razorpay\Tests\registerNachTest located in ./vendor/razorpay/razorpay/tests/registerNachtest.php does not comply with psr-4 autoloading standard. Skipping.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: coconutcraig/laravel-postmark
Discovered Package: codedge/laravel-selfupdater
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: intervention/image
Discovered Package: invoiceninja/inspector
Discovered Package: laravel/slack-notification-channel
Discovered Package: laravel/socialite
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: livewire/livewire
Discovered Package: nesbot/carbon
Discovered Package: nwidart/laravel-modules
Discovered Package: sentry/sentry-laravel
Discovered Package: turbo124/beacon
Discovered Package: turbo124/laravel-gmail
Discovered Package: webpatser/laravel-countries
Package manifest generated successfully.
Generated optimized autoload files containing 26023 classes
[myuser@premium15 invoice.mydomain.nl]$

Does the app now load? If not, please post the latest error from the log file.