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

Oai-Pmh make directory if does not exist #504

Merged
merged 2 commits into from
Nov 18, 2019

Conversation

bondjimbond
Copy link
Collaborator

Github issue: (#503)

What does this Pull Request do?

Checks if directory exists before creating the XML file. If it doesn't, create the directory first.

What's new?

In some cases, the OAI endpoint will include a directory in the record ID representing the set. MIK fails if the directory does not already exist. Now we write it.

How should this be tested?

Use the attached file (change txt to ini). Note failure to produce metadata until this branch is checked out. (The failure to produce the files is another issue.)
mru_oai.txt

Interested parties

@mjordan @MarcusBarnes

@bondjimbond
Copy link
Collaborator Author

This PR addresses #503.

@bondjimbond
Copy link
Collaborator Author

@MarcusBarnes Any thoughts on this? It's working for me.

@bondjimbond
Copy link
Collaborator Author

I added a new filegetter here too, just to make it possible to extract the file from a MODS record. I can remove this commit if it's out of scope for the PR.

@MarcusBarnes
Copy link
Owner

@bondjimbond It's better for when searching the issue history to have the filegetter in a separate PR.

@bondjimbond
Copy link
Collaborator Author

OK, filegetter removed.

@@ -72,6 +72,14 @@ public function writePackages($metadata, $pages, $record_id)

$normalized_record_id = $this->normalizeFilename($record_id);
$metadata_file_path = $output_path . $normalized_record_id . '.xml';

$subdirectory = explode("/", $normalized_record_id);
$subdirectory_path = $output_path . $subdirectory[0];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any documentation as to what is an appropriate $normalized_record_id? Here the assumption seems to be that the ID has a structure like "some_subdirectory_string/some_string". Is "another_directory_string/some_subdirectory/some_string" also a possibility for this variable? Is the forward slash also a reasonable assumption based on the standard or is a backslash also OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the assumption seems to be that the ID has a structure like "some_subdirectory_string/some_string". Is "another_directory_string/some_subdirectory/some_string" also a possibility for this variable?

I haven't a clue, to be honest - I'm just dealing with the kinds of records I'm seeing in the wild.

If a second slash in the record ID is a possibility, perhaps a foreach loop would be a way to get at them all? Except will have to think about how the mkdir commands will work.

Is the forward slash also a reasonable assumption based on the standard or is a backslash also OK?

I think we are safe in assuming that forward slashes are standard; we don't really see backslashes on the web as far as I know. (And if it ever does come up we could create a new PR to address it.)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the normalized_record_id is just a normal string like 'myfavouriteid' , then the code change would now create a directory.
$normalized_record_id = '1234';
$subdirectory = explode('/', $normalized_record_id)
$subdirectory[0] will be 1234.

Maybe a solution to your use case is to create a new local Oaimphp.php class that deals with the specific use-case you're seeing and we can add this class if others are also encountering normalized_record_id that require creating subdirectories. In your case, you'd update the writer class in the MIK configuration file and make sure you update the class name of your copy of the Oai-Pmh writer class. Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's an obvious thing I missed!

I think it's best if this can all be done in the same class; you don't know you're going to hit this problem until it comes up.

I propose the following:

  • Wrap the new code in an IF statement IF ($normalized_record_id CONTAINS "/")
  • Loop through the subdirectory array to create whatever number of subdirectories are necessary
  • Continue as normal

This way we won't create subdirectories when they aren't needed, and do create all the ones we need. Does that make sense?

@mjordan mjordan merged commit 7180255 into MarcusBarnes:master Nov 18, 2019
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

Successfully merging this pull request may close these issues.

None yet

3 participants