Problem/Motivation
As of #2844979: Index nested attachments (eg. entity reference, paragraphs) - arbitrary level there is an ExtractedText formatter that can be applied to any file field to index arbitrary nestings of file content. This works great, except that the isFileIndexable() function has been copied over from the plugin without being altered to use formatter settings. The result is that these calls don't work properly:
$this->extractor->getExcludedMimes()
$this->extractor->isFileSizeAllowed($file)
$this->extractor->isPrivateFileAllowed($file)
The first 2 bail out or use defaults since there is no configuration set, but the private file setting will always return FALSE. This results in private file fields using this formatter never being indexed.
Proposed resolution
Replicate the 3 settings from the processor plugin on to the formatter and use them to do the validation instead of the processor.
Remaining tasks
- Code
- Test
- Review
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | results_in_private_files_never_being_indexed-2955936-18.patch | 21.11 KB | Yunqiang |
| #18 | interdiff_16-18.txt | 1.78 KB | Yunqiang |
Comments
Comment #2
Yunqiang commentedAs described, duplicate settings in Text extracted formatter and update validation from local settings.
Comment #3
acbramley commentedMissing
$form = parent::settingsForm($form, $form_state);here.This could be simplified with an array_unique().
Looks good in general but there's now a huge amount of duplication between ExtractedText and FilesExtrator. You could refactor the getExcludedMimes, isFileSizeAllowed, and isPrivateFileAllowed functions into a Validator class that takes the settings so both classes could use the Validator and pass it their settings.
Comment #4
izus commented+1 for acbramley's suggestion
Comment #5
Yunqiang commentedReply to #3
Both updated.
Also move reusable functions into a common Validator class.
Comment #6
fenstrat.
Comment #7
acbramley commentedInstead of passing the MimeTypeGuesser in here, you should make this class into a service and inject the MimeTypeGuesser into it.
Then the ExtractedText and FilesExtractor classes can have the validator injected rather than the mime type guesser.
Other than that it's looking great!
Comment #8
fenstratJust a note to @yunqiang when you upload the changes from #7 to set the issue to "Needs review" so that it triggers the testbot.
Comment #9
Yunqiang commentedAs discussed, update the ExtractFileValidator to be a service in Drupal. Both ExtractedText and FilesExtrator inject this service to invoke the validation method. Thanks @acbramley and it's a good pattern.
Comment #10
Yunqiang commentedupdated.
Comment #11
acbramley commented@yunqiang would you mind providing an interdiff between #5 and #9? https://www.drupal.org/documentation/git/interdiff
Comment #12
Yunqiang commented@acbramley, here is the interdiff.
Comment #13
acbramley commentedNeed newlines at the end of these files.
Other than that, this looks good!
Comment #14
Yunqiang commentedAdd new line in both files.
Comment #15
fenstratSome fairly minor nits:
These should be in alphabetical order.
Alphabetical order again.
Should be
\Drupal\search_api_attachments\ExtractFileValidator- needs to be updated in a couple other places too.Needs a doc block summary of what it is.
Stray whitespace.
Stray whitespace.
Comment #16
Yunqiang commentedAll updated.
Thanks Saul/Adam.
Comment #17
acbramley commentedThis namespace now doesn't match the location of the file. Should just be Drupal\search_api_attachments
Comment #18
Yunqiang commentedUpdated.
Comment #19
acbramley commentedComment #20
fenstratThere's some minor PHPCS issues in the patch, but most of them existed before and this is just moving them around.
Would be great to expand the module's test coverage, and get the bot actually running the test, but that's not really the task for this issue.
Marking as RTBC. Thanks @yunqiang!
Comment #22
izus commentedThis is now merged
Thanks all