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

PHP Error in loadExporterByCode() breaks download of object representations files in CA 2.0 #1557

Closed
amergelCGI opened this issue Apr 9, 2024 · 4 comments

Comments

@amergelCGI
Copy link

amergelCGI commented Apr 9, 2024

In CA 2.0 (dev/php8), a PHP error occurs when trying to download object representations media files.

Fatal error: Uncaught TypeError: ca_data_exporters::exportRecord(): Argument #1 ($exporter_code) must be of type string, array given, called in /var/www/html/collectiveaccess/app/helpers/mediaPluginHelpers.php on line 902 and defined in /var/www/html/collectiveaccess/app/models/ca_data_exporters.php:1148

Stack trace:
#0 /var/www/html/collectiveaccess/app/helpers/mediaPluginHelpers.php(902): ca_data_exporters::exportRecord()
#1 /var/www/html/collectiveaccess/app/helpers/mediaPluginHelpers.php(827): caExportMediaMetadataForRecord()
#2 /var/www/html/collectiveaccess/app/lib/BaseEditorController.php(2548): caEmbedMediaMetadataIntoFile()
#3 /var/www/html/collectiveaccess/app/lib/Controller/RequestDispatcher.php(289): BaseEditorController->DownloadMedia() #4 /var/www/html/collectiveaccess/app/lib/Controller/AppController.php(108): RequestDispatcher->dispatch()
#5 /var/www/html/collectiveaccess/index.php(128): AppController->dispatch()
#6 {main} thrown in /var/www/html/collectiveaccess/app/models/ca_data_exporters.php on line 1148

This is due to an array passed to $ps_exporter_code which is expected to be a string in function loadExporterByCode() in app/models/ca_data_exporters.php.
This caused only a warning in PHP 7 but it became an error since PHP 8.

Here is some debug info that might be helpful:

json representation of $ps_exporter_code:
{"XMP:Title":{"ca_objects.preferred_labels.name":[]},"XMP:Description":{"ca_objects.description":[]},"XMP:Rights":["static:(c) 2011"],"XMP:Creator":{"ca_entities.preferred_labels.displayname":{"delimiter":","}},"XMP:Subjects":{"ca_list_items.preferred_labels.name_plural":{"delimiter":","}}}

Bug
Bug2

@amergelCGI
Copy link
Author

amergelCGI commented May 21, 2024

Issue is still occuring with the latest code. I am not sure what exactly is supposed to be the exporter code. Can it be for example "XMP"?
Currently it seems like the whole mapping is being passed as the exporter code while it probably expects only the prefix of the mapping's keys?

@collectiveaccess
Copy link
Owner

What does your media_metadata.conf file look like?

collectiveaccess added a commit that referenced this issue May 21, 2024
@amergelCGI
Copy link
Author

extract_embedded_exif_georeferencing_to = []
extract_embedded_exif_georeferencing_to_container = {
}

extract_embedded_exif_creation_date_to = [ca_object_representations.media_creation_date]
extract_embedded_exif_creation_date_to_container = {
}

import_mappings = {
	ca_object_representations = {
		__default__ = {
			EXIF:IPTC:CopyrightNotice = {
				ca_object_representations.media_copyright
			},
			EXIF:IPTC:By-line = {
				ca_object_representations.media_author
			},
			EXIF:IPTC:Source = {
				ca_object_representations.media_source
			},
			EXIF:IFD0:Model = {
				ca_object_representations.media_model
			},
			EXIF:ExifIFD:ColorSpace = {
				ca_object_representations.media_color_space
			},
			EXIF:System:FileName = {
				preferred_labels.name
			},
			EXIF:System:FileSize = {
				ca_object_representations.media_file_size
			},
			EXIF:File:ImageWidth = {
				ca_object_representations.media_image_width
			},
			EXIF:File:ImageHeight = {
				ca_object_representations.media_image_height
			},
		}
	}
}

export_mappings = {
	ca_objects = {
		__default__ = {
			XMP:Title = {
				ca_objects.preferred_labels.name = {}
			},
			XMP:Description = {
				ca_objects.description = {}
			},
			
			XMP:Rights = {
				static:(c) 2011
			},
			XMP:Creator = {
				ca_entities.preferred_labels.displayname = {
					delimiter = ", "
				}
			},
			XMP:Subjects = {
				ca_list_items.preferred_labels.name_plural = {
					delimiter = ", "
				}
			}
		}
	}
}

@amergelCGI
Copy link
Author

amergelCGI commented May 22, 2024

Your latest commit fixed my issue,
Thank you for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants