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 8.1 compatibility / createElement Deprecated Warning #13

Closed
ghohmann opened this issue May 8, 2024 · 6 comments · Fixed by #15
Closed

PHP 8.1 compatibility / createElement Deprecated Warning #13

ghohmann opened this issue May 8, 2024 · 6 comments · Fixed by #15
Assignees

Comments

@ghohmann
Copy link

ghohmann commented May 8, 2024

Hi,

the current code base throws a PHP warrning if ?verb=ListMetadataFormats is called:
Deprecated: DOMDocument::createElement(): Passing null to parameter #2 ($value) of type string is deprecated in ./Classes/Response.php on line 64.

The is caused by the function public function addChild() which tries to create an element with an empty string as value. In my understanding this triggers a warning since PHP 8.1.

To create an empty element you can simply omit the value. Quick workaround (Response.php from line 63):

public function addChild($mom_node, $name, $value = '') {
        if (!empty($value)) {
                $added_node = $this->doc->createElement($name, $value);
        } else {
                $added_node = $this->doc->createElement($name);
        }
        $added_node = $mom_node->appendChild($added_node);
        return $added_node;
}

There might be a nicer fix to this, though.

@sebastian-meyer
Copy link
Member

Thank you for pointing this out! I haven't been working with the Simple OAI-PMH Data Provider for a while now, since there is a successor which supersedes this one in most cases.

But nevertheless I tried to fix all deprecation warnings in #15. Would you like to test this before I merge the changes and release a new version?

@ghohmann
Copy link
Author

ghohmann commented May 9, 2024

Thx!

Thank you for pointing this out! I haven't been working with the Simple OAI-PMH Data Provider for a while now, since there is a successor which supersedes this one in most cases.

I already noted the other version of this provider, but wasn't sure if it is activly developed (since there is no readme).
If this is meant to be an successor I think it would be great if it would support both repository options (plain files and database).

But nevertheless I tried to fix all deprecation warnings in #15. Would you like to test this before I merge the changes and release a new version?

Yes. I guess I can test it tomorrow and give you feedback.

@ghohmann
Copy link
Author

Hm, there is a problem with ListRecords&metadataPrefix.

There are no results when using
https://<myOAIserver>/?verb=ListRecords&metadataPrefix=oai_dc
in the default installation.
<error code="noRecordsMatch">The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list.</error>

The given example.xml is set in the files array in line 39 of index.php. It seems to be a problem with how $until is set in line 91. In the case of example.com, $until is not null and of same value as $from. Therefore the expression in line 95 is always FALSE.

@sebastian-meyer
Copy link
Member

Thanks for checking! I think I found the problem and updated the pull request. That should (hopefully) fix it.

@ghohmann
Copy link
Author

Tested it this morning, works like a charm! And all "deprecated" warnings are gone.
Time to merge! :-)

@sebastian-meyer
Copy link
Member

Time to merge! :-)

I merged the changes and made a new release: v1.8

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

Successfully merging a pull request may close this issue.

2 participants