Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource File Import failing #481

Closed
vinny75 opened this issue Sep 10, 2018 · 4 comments
Closed

Resource File Import failing #481

vinny75 opened this issue Sep 10, 2018 · 4 comments
Labels
bug This is a bug (not an enhancement)

Comments

@vinny75
Copy link
Contributor

vinny75 commented Sep 10, 2018

The File Import in the Resource module is failing with the following error:

[Mon Sep 10 09:08:47.778171 2018] [:error] [pid 1540] PHP Fatal error: Uncaught exception 'Exception' with message 'There was a problem with the database: Field 'resourceID' doesn't have a default value' in /var/www/html/coral3/resources/admin/classes/common/DBService.php:52
Stack trace:
#0 /var/www/html/coral3/resources/admin/classes/common/DBService.php(91): DBService->checkForError()
1 /var/www/html/coral3/resources/admin/classes/common/DatabaseObject.php(245): DBService->processQuery('INSERT INTO `Re...')
2 /var/www/html/coral3/resources/import.php(595): DatabaseObject->save()
3 {main}
thrown in /var/www/html/coral3/resources/admin/classes/common/DBService.php on line 52, referer: /coral3/resources/import.php

I traced it back to line 575, "if (isset($proceed)) {" which was added in merge #244
If I set $proceed to true before this line, the import works as expected.

@nkuitse
Copy link
Contributor

nkuitse commented Nov 6, 2018

If $proceed is false (or undefined, same thing) then a logic flaw results in this error message. See lines 569-595 (indents squashed for clarity):

569 // Let's insert data
570 if (isset($proceed)) {
571 $resource->createLoginID = $loginID;
572 $resource->createDate = date( 'Y-m-d' );
573 $resource->updateLoginID = '';
574 $resource->updateDate = date('Y-m-d');
575 $resource->titleText = isset($data[$resourceTitleColumn]) ? trim($data[$resourceTitleColumn]) : '';
576 $resource->descriptionText = isset($data[$resourceDescColumn]) ? trim($data[$resourceDescColumn]) : '';
577 $resource->resourceURL = isset($data[$resourceURLColumn]) ? trim($data[$resourceURLColumn]) : '';
578 $resource->resourceAltURL = isset($data[$resourceAltURLColumn]) ? trim($data[$resourceAltURLColumn]) : '';
579 $resource->resourceTypeID = isset($resourceTypeID) ? $resourceTypeID : '';
580 $resource->resourceFormatID = isset($resourceFormatID) ? $resourceFormatID : '';
581 $resource->statusID = 1;
582 $resource->save();
583 if (isset($isbnIssn_values))
584 {
585 $resource->setIsbnOrIssn($isbnIssn_values);
586 }
587 array_push($resourceIDs, $resource->resourceID);
588 }
589 $inserted++;
590
591 $resourceAcquisition = new ResourceAcquisition();
592 $resourceAcquisition->resourceID = $resource->resourceID;
593 $resourceAcquisition->subscriptionStartDate = date('Y-m-d');
594 $resourceAcquisition->subscriptionEndDate = date('Y-m-d');
595 $resourceAcquisition->save();

If $proceed is set, $resource->save() is called and $resource->resourceID() becomes defined, so the call to $resourceAcquisition->save() succeeds. But if $proceed is not set, $resource->save() is not called and $resource->resourceID() remains undefined; but $resourceAcquisition->save() is still called, and fails due to the (perfectly sensible) NOT NULL constraint on the resourceID column in the ResourceAcquisition table.

My guess is that lines 591-595 need to be moved into the if-block, i.e., between lines 587 and 588. However, there may be more to this than I realize.

@nkuitse
Copy link
Contributor

nkuitse commented Nov 6, 2018

Here's a patch that makes it so that all $foo->save() calls occur only when $proceed is true.
resource-import-patch.txt

@nkuitse
Copy link
Contributor

nkuitse commented Nov 6, 2018

Sorry, that was wrong; some $foo->save calls will occur whether $proceed is true or not: (1) New ResourceType, AcquisitionType, ResourceFormat, and GeneralSubject objects are saved; (2) Some parent resource stuff is saved -- I don't understand this code.

@veggiematts
Copy link
Contributor

There is indeed a problem.
Test plan to reproduce the problem:

MariaDB [coral_resources_prod]> select max(resourceAcquisitionID) from ResourceAcquisition;
+----------------------------+
| max(resourceAcquisitionID) |
+----------------------------+
|                       6964 |
+----------------------------+

Start an import, until the preview page ("n resources will be imported" messages) but do not import.

MariaDB [coral_resources_prod]> select max(resourceAcquisitionID) from ResourceAcquisition;
+----------------------------+
| max(resourceAcquisitionID) |
+----------------------------+
|                       6966 |
+----------------------------+

@veggiematts veggiematts added the bug This is a bug (not an enhancement) label Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug (not an enhancement)
Projects
None yet
Development

No branches or pull requests

3 participants