Upgrading from 2.4.8-3 to 3.1.1-4: Call to a member function getFileId() on null in lib/pkp/classes/submission/PKPSubmissionFileDAO.inc.php

upgrade

#1

Hello everyone,
we came to another issue during our upgrade process from OJS 2.4.8-3 to 3.1.1-4:

PHP Fatal error: Call to a member function getFileId() on null in lib/pkp/classes/submission/PKPSubmissionFileDAO.inc.php on line 1065


PHP Fatal error: Call to a member function getFileId() on null when attempting to upgrade 2.4.8.2 to 3.1.1.4
#2

Hi @GustavoTonini

And when exactly did this error occurred i.e. at which upgrade step (that you see when upgrading via command line)?

Best,
Bozana


#3

Hey @bozana,
the error appears after the start of the step [code: Installer Installer::provideSupplementaryFilesForReview]


#4

Hi @GustavoTonini

Maybe it is the same problem as described here: https://github.com/pkp/pkp-lib/issues/4287
I.e. maybe there are some files/entries in your DB table article_supplementary_files that are not in the table article_files.
Could you maybe run this SQL on your OJS 2 DB to test it:

SELECT a.journal_id, sf.* FROM article_supplementary_files sf, articles a WHERE a.article_id = sf.article_id AND sf.file_id <> 0 AND sf.show_reviewers = 1 AND sf.remote_url IS NULL and sf.file_id not in (select f.file_id from article_files f);

Those entries should then be removed from the DB table article_supplementary_files. Please make a full backup before doing any changes in your DB.

Then you would need to start the upgrade anew, using the clean backup of your OJS 2 installation. Every time an upgrade is run, it has to run on a clean backup (and NOT on the DB, the code and the files that already went through an unsuccessful upgrade).

You can report here how does your result from the SQL above look look, then we can see further…

Best,
Bozana


Unable to upgrade from 2.4.8.1 to 3.1.1.4
#5

Hi @bozana, this query doesn’t return records on my original ojs2 database. I also deleted some records with file_id=0 but the error persists.


#6

Hi @GustavoTonini

Hmmm…
Could you maybe test these two SQLs too:
SELECT sf.* FROM article_supplementary_files sf WHERE sf.show_reviewers = 1
and
SELECT sf.* FROM article_supplementary_files sf WHERE sf.file_id <> 0 AND sf.remote_url IS NULL AND sf.file_id not in (select f.file_id from article_files f)
and provide the results?

Thanks!
Bozana


#7

@bozana,
the second query doesn’t return records.
The results of the first one are at https://arquivos.ufsc.br/f/1fcd9664da/?raw=1

Thanks for your assistance.


#8

Hi @GustavoTonini

I downloaded the file, so you can remove it…
Strange…
If I see it correctly, the function _castToGenre (where the error occurs) is called in the function insertObject in PKPSubmissionFileDAO.inc.php. The insertObject is called when the supp file is copied for the review (stage) here https://github.com/pkp/ojs/blob/ojs-3_1_1-4/classes/install/Upgrade.inc.php#L1491 -> https://github.com/pkp/pkp-lib/blob/ojs-3_1_1-4/classes/file/SubmissionFileManager.inc.php#L185.
But I have no idea why this could be :-
Would it maybe be possible for you to debug it, to print some variables out? – E.g. to see how the variables submissionFile, sourceFile, targetDaoDelegate ad insertedFile look like here https://github.com/pkp/pkp-lib/blob/ojs-3_1_1-4/classes/submission/PKPSubmissionFileDAO.inc.php#L311.
You could for example create a file debug.txt (writable for the web user) in your OJS folder and print the output there, e.g. you could put something like this on that line 311 in PKPSubmissionFileDAO.inc.php:

$file = 'debug.txt';
$current = file_get_contents($file);
$current .= print_r("++++ submissionFile: ++++\n", true);
$current .= print_r($submissionFile, true);
$current .= print_r("++++ sourceFile: ++++\n", true);
$current .= print_r($sourceFile, true);
$current .= print_r("++++ targetDaoDelegate: ++++\n", true);
$current .= print_r($targetDaoDelegate, true);
$current .= print_r("++++ insertedFile: ++++\n", true);
$current .= print_r($insertedFile, true);
file_put_contents($file, $current);

Or use the similar code to make even more outputs throughout those functions…
Then run the upgrade again (on a clean OJS 2 backup) and see what is then in the file debug.txt… especially the last entries…

Hmmm…
Thanks!
Bozana


#9

Hi @GustavoTonini

also if you see some other relevant warnings during the upgrade process, that are displayed on the CLI, e.g. PHP Warning: copy(files/…): failed to open stream: No such file or directory in /lib/pkp/classes/file/FileManager.inc.php on line …, please report them…

Best,
Bozana


#10

Hi @GustavoTonini

Maybe you could also try these two SQLs:
SELECT ra.review_id, ra.submission_id, ra.reviewer_file_id FROM review_assignments ra WHERE ra.reviewer_file_id IS NOT NULL AND ra.reviewer_file_id NOT IN (SELECT file_id FROM article_files)
to see if a reviewer file is missing in the article_files table.

SELECT DISTINCT ra.submission_id, ra.round, af.revision FROM review_assignments ra, article_files af, articles a WHERE (ra.submission_id, ra.round) NOT IN (SELECT rr.submission_id, rr.round FROM review_rounds rr) AND a.article_id = ra.submission_id AND af.article_id = a.article_id AND af.file_id = a.review_file_id AND af.round = ra.round
to see if eventually a review round entry is missing in the DB.

EDIT 1: I do not think this is a problem in your case, but just to be sure: see if all your articles have a section_id entry in the DB table articles. Also if all sections exists:

SELECT a.article_id FROM articles a LEFT JOIN sections s ON (a.section_id = s.section_id) WHERE s.section_id IS NULL

EDIT 2: What you could also do anyway is to investigate and eventually repair those files that have file_id = 0 but also remote_url = NULL. In general remote files (supp files and galleys) will have file_id = 0 but there should be a remote_url there.
(The file_id column occurs in these DB tables:
article_files
article_galleys
article_html_galley_images
article_supplementary_files
issue_files
issue_galleys
notes
signoffs
temporary_files)

Also maybe to double check that all files have an article in DB:

SELECT af.article_id FROM article_files af LEFT JOIN articles a ON (a.article_id = af.article_id) WHERE a.article_id IS NULL

Thanks!
Bozana


#11

@bozana, I hadn’t noticed before, but there is a warning about a failed copy file operation right before the Fatal Error. I will check why this file is not there.

Both two selects you sent in the beggining of the last post return lines here. What could I do about it? Maybe deleting inconsistent records from review_assignments table?

I’ve already fixed everything related to section_id, file_id=0 and inexistent articles in articles_* tables.


#12

@bozana There was some missing files on the files_dir folder. After copying the directory again, the installer passed the “provideSupplementaryFilesForReview” section.


#13

Hi @GustavoTonini

OK, good to hear and know! :slight_smile:
So the upgrade run through successfully, i.e. without warnings/errors?

Thanks!
Bozana


#14

@bozana Unfortunatelly another error occurred: OJS upgrade error "Unknown locale component".


#15

Hi @GustavoTonini

Hmmm… it seems the error message comes from here: https://github.com/pkp/pkp-lib/blob/ojs-stable-3_1_1/classes/i18n/PKPLocale.inc.php#L249. Would it be possible for you to debug and output the variable $component directly before that fatalError function?

Best,
Bozana


#16

Hello @bozana, after debbuging I found that it was caused by NULL values on the column articles.locale. We’ve fixed the locale and the upgrade passed this step.

Thanks.