Using Ninja on PHP 7.4

Try setting this in the .env file

PHANTOMJS_KEY='a-demo-key-with-low-quota-per-ip-address'

I’m sorry, I don’t know what that means. What .env file?

Also, I upgraded the old Ninja and see migration.
On v5 I to just ignore the error to continue, but then also got an error when I try to test the webserver. The log says:

[2020-09-27 14:02:31] production.INFO: array (
‘message’ => ‘count(): Parameter must be an array or an object that implements Countable’,
‘action’ => ‘SetupController::checkMail()’,
)

There is a .env file in the root folder of the project

Are you using the latest v5 release?

I am using version 5.0.17.

Updating the .env did seem to work.

Given that I’m using that, do I need to get a new key for PhantomJS?

I was able to install Ninja v5 and login. I started the migration process on the old version, and ran into a few issues, (folder permissions, etc.). but resolved those. The migration says it has run. But now I can not log into the new v5 Installation after running the migration. I receive a red “XMLHttpRequest error” on the login screen. On another browser it shows a “500: Server Error” message on the login screen.

In the laravel.log the last message was:

production.INFO: POST - https://invoice.bh-online.org/api/v1/login: 52 queries - 0.4978928565979

The second to last error message was:

production.ERROR: Argument 1 passed to App\Transformers\CompanyUserTransformer::transform() must be an instance of App\Models\CompanyUser, null given, called in /data/www/live/ninja5/vendor/league/fractal/src/Scope.php on line 407 {"userId":1,"exception":"[object] (TypeError(code: 0): Argument 1 passed to App\\Transformers\\CompanyUserTransformer::transform() must be an instance of App\\Models\\CompanyUser, null given, called in /data/www/live/ninja5/vendor/league/fractal/src/Scope.php on line 407 at /data/www/live/ninja5/app/Transformers/CompanyUserTransformer.php:46)

Thanks for your help.

Just FYI after I changed the .env file and then ran the “Test PDF” button it says success and then opens a new window which leads to a “500 | Server Error” message. The page it tried opening was: invoice-bh.online.org/storage/test.pdf

… in the /ninja5/storage/app folder I do see a test.pdf file that was created at the same time that I tried running the test, so it looks like it did create a PDF, but the domain invoice.bh-online.org is pointed at the /ninja5/public/ folder, so I’m guessing that is why I’m getting the 500 error. I checked the PDF and it is valid.

Also, I was able to fix the mail issue – that was my fault, I had the AWS email server set incorrectly, so that has been resolved.

hi @cfullerbhope-org

  1. In regards to the PDF links not working please try the following
php artisan storage:link
php artisan optimize
  1. When you attempted the migration, did you have the most up to date versions of both the V4 and V5 apps?
  1. I ran the artisan tool(s).

  2. Yes. They are on separate machines / IP addresses. The old server is on version 4.5.19 and the new server has 5.0.17

  3. Now when I try to log into the new server (5.0.17) I am getting a new error: “Error: please check that Invoice Ninja v5 is installed on the server” on the log in screen when trying to log in. I don’t see anything new in the laravel.log

Thanks!

The third error indicates that the URL may be wrong.

You can test the URL by entering it into a browser looking something like this

http://your.url.com/api/v1/ping

Using that, I am getting:

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

Ok, so it looks like the underlyling error isn’t being exposed because APP_DEBUG is set to FALSE in your .env file

To understand why it is failing, you’ll need to set APP_DEBUG=TRUE in the .env file and then run php artisan optimize once that is done try logging in again, you’ll see the error in your logs.

Please note, you don’t want to run your app in DEBUG=TRUE for too long. so make sure you flick this back to FALSE afterwards.

I tried changing the APP_DEBUG=TRUE and ran artisan optimize and am getting the same results.

The only entry into the log file is:

production.INFO: GET - https://invoice.bh-online.org/api/v1/ping: 0 queries - 0.014193058013916

It looks like it is a DB connection error, your user/password combination is throwing a MySQL error.

Is there somewhere other than the .env file that would store the mySQL credentials, because what it is in the .env file is correct.

I decided to scrap it and start over. And unfortunately, I’m getting the same result. Here is a step by step explanation of what I did to start over:

  • Deleted v5 database and recreated a blank database

  • Removed the ninja 5 folder and recreated it from the download

  • Changed the .env file to include: PHANTOMJS_KEY=‘a-demo-key-with-low-quota-per-ip-address’

  • Ran: sudo php artisan storage:link

  • Ran: sudo php artisan optimize

  • Opened the website domain.org/setup

  • Completed the setup screens all of the tests were successful. I’m using the same username/password combo that I use for the old version.

  • Signed into the new V5.0.17 version. No company set up just blank data, but log in worked.

  • Opened the old v4.5.19 and went to Settings:Account Management:Start Migration

  • Used “Self-hosted” option. Entered the domain for the new v5 install, used the same username/password for both, selected the only company by ID. (Not selecting “Force migration”)

  • The old server works for quite a while (~5 mins) and then returns a message: “Migration has started. We’ll update you with status, on your company e-mail.”. (This was more than an hour ago, and I still haven’t received any emails).

  • Now when I try to log into the new V5 server I receive a “500:Server Error”

  • Last two errors in storage/logs/laravel.log are:

    • production.ERROR: Argument 1 passed to App\Transformers\CompanyUserTransformer::transform() must be an instance of App\Models\CompanyUser, null given, called in /data/www/live/ninja5/vendor/league/fractal/src/Scope.php on line 407 {“userId”:1,“exception”:"[object] (TypeError(code: 0): Argument 1 passed to App\Transformers\CompanyUserTransformer::transform() must be an instance of App\Models\CompanyUser, null given, called in /data/www/live/ninja5/vendor/league/fractal/src/Scope.php on line 407 at /data/www/live/ninja5/app/Transformers/CompanyUserTransformer.php:46)
    • production.INFO: POST - https://***.org/api/v1/login: 52 queries - 0.49500489234924
  • I changed the .env file to turn on debuging: APP_DEBUG=true

  • Tried logging in again from browser. Still get the “500: Server Error” message on the login screen. Same error messages in storage/logs/laravel.log

  • Tried to go to domain.org/api/v1/ping and the response I receive is: {“message”:“Invalid token”,“errors”:{}}

  • A new entry was put into the storage/logs/laravel.log:

    • production.INFO: GET - https://***.org/api/v1/ping: 0 queries - 0.012839078903198
  • I checked the .env file, and the database username and password are correct to connect to the new database that was setup for V5.

@cfullerbhope-org thanks for this detailed response.

When the migration commences there is a bunch of logs written inside the V5 installation ie importing clients, importing quotes… it should finish with a message like

Completed🚀🚀🚀🚀🚀 at 

It sounds like the migration isn’t completing leaving the system in an unusable state.

So I turned app_debug=true on the old V4.5.19 prior to going through migration. I received the following error message in the laravel.log on the old version:

production.ERROR: ErrorException [0] : /var/www/tools/ninja/storage/framework/views/2dda033f1f1cc1b5912a4fbf9e6449082afd9145.php [Line 4] => Array to string conversion (View: /var/www/tools/ninja/resources/views/migration/includes/errors.blade.php) (View: /var/www/tools/ninja/resources/views/migration/includes/errors.blade.php) {“context”:“PHP”,“user_id”:1,“account_id”:1,“user_name”:“Curtis Fuller”,“method”:“GET”,“user_agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36”,“locale”:“en”,“ip”:“35.141.98.216”,“count”:2,“is_console”:“no”,“is_api”:“no”,“db_server”:“mysql”,“url”:“migration/auth”} []

I am not sure what to try next with that error.

I did receive a lot longer error log in the browser. I printed it and have posted it to DropBox, it can be accessed here: https://www.dropbox.com/s/s2xchogx8b3skog/ninja-error.pdf?dl=0 (Only available for the next two days).

What should I try next?

@cfullerbhope-org

the DB Connection error is the common theme here, there is something with your DB connection that is causing the failure

SQLSTATE[HY000] [1045] Access denied for user
‘ninja5_app’@‘10.0.0.245’ (

I have started over again, removed everything and changed the database user / password to the admin account and that seems to have helped. Apparently the database user must be the same between the two installations as well. Also, I had to select the “Force Migration” option on the v4.5.19 migration tool to get it to work.

I am now able to get into v5. All of the clients are listed, and their total due. However, there is no “Invoice” listed in the menu, and I can’t find any way of listing the actual invoices. When I switch back to the original “Unititled” business that was added during installation, invoices are listed there.

In the Laravel.log file during the migration an error was logged:

production.ERROR: Division by zero {"userId":1,"exception":"[object] (ErrorException(code: 0): Division by zero at /data/www/live/ninja5/app/Helpers/Invoice/InvoiceItemSum.php:233)

I looked back at the old database and we do have some invoices with either Amt $0 or Qty 0 which could have made the subtotal $0, which could have caused the divide by zero error on that line of the code.

Could this error have caused the invoice option to not be available in V5? Is there anything I can do to restore it?

I tried running php artistan optimize as well as php artisan ninja:check-data and they did not fix, but the later did create many errors which were: “balances do not match Invoice Amount”

Also, I don’t know if I’m missing it, but I can’t find a way to log out of V5.

Thank you!

After analyzing some of the errors and looking at the code, I was able to make two code changes to finally get the migration to work.

I changed /app/Helpers/Invoice/InvoiceItemSum.php line 233 from:

$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)); 

to:

$amount = ( $this->sub_total > 0 ) ? $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / $this->sub_total)) : 0;

And then I changed /app/Utils/Traits/MakesInvoiceValues.php line 216

$data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_invoice').'</a>', 'label' => ctrans('texts.view_invoice')];

to:

if(is_object($invitation)) { $data['$view_link'] = ['value' => '<a href="'.$invitation->getLink().'">'.ctrans('texts.view_invoice').'</a>', 'label' => ctrans('texts.view_invoice')]; } else { $data['$view_link'] = ['value' => Null, 'label' => ctrans('texts.view_invoice')];  }

(The second change was because it was trying to do this on Null for something that wasn’t loaded correctly).

I then had to go in to Settings and account management, and then click on the “Modules” tab and turn on invoices and reoccurring invoices.

I am now having a problem that it will not generate the PDF invoices, but I’ll search the forum for others and if I can’t find anything I’ll start a new thread.

1 Like

@cfullerbhope-org

Thanks for the update! Yes, the div/0 looks like a bug picked up on your migration, i’ll add this into the backlog for fixes.

In regards to the PDF, does your system have NPM/Node installed? The most common issue we see in regards to PDF generation is either permissions issues, or NPM/puppeteer not installed correctly on the system, we do have a section for this in the install guide here:

https://invoiceninja.github.io/selfhost.html#pdfs-not-generating-timeouts

Regarding the PDF generation, I started new topic just for that issue since this one was getting long: Generating a PDF.

I’ll respond to your NPM/Node suggestion their.