Commit 183627aa authored by izus's avatar izus
Browse files

Issue #2470553 by izus, Fix DrupalCS.

parent 86de0517
......@@ -185,5 +185,3 @@ SIMPLE USAGE EXAMPLE (media fields content (media entities of type File))
13) Go to admin/config/search/search-api/index/my_index and Index items.
14) Go to /saa and search for any term in the title, body or in the pdf file :)
.ok{
.ok {
border: 5px solid green;
border-radius: 5px;
padding: 5px;
}
.error{
.error {
border: 5px solid red;
border-radius: 5px;
padding: 5px;
......
......@@ -4,6 +4,7 @@
* @file
* Hooks provided by the "Search API attachments" module.
*/
/**
* @addtogroup hooks
* @{
......
......@@ -14,7 +14,7 @@ function search_api_attachments_uninstall() {
}
/**
* Add path configuration for pdftotext_extractor
* Add path configuration for pdftotext_extractor.
*/
function search_api_attachments_update_8001() {
\Drupal::configFactory()
......
......@@ -4,6 +4,7 @@
* @file
* Implement hooks and help functions to delete extracted files cache content.
*/
use Drupal\file\Entity\File;
/**
......@@ -35,7 +36,7 @@ function search_api_attachments_cache_flush() {
/**
* Helper function to delete a file extracted data cache.
*
* @param File $file
* @param \Drupal\file\Entity\File $file
* The file object.
*/
function _search_api_attachments_delete_cache(File $file) {
......
......@@ -4,6 +4,7 @@
* @file
* Adds views hooks.
*/
use Drupal\search_api\Entity\Index;
/**
......@@ -22,7 +23,7 @@ function search_api_attachments_views_data_alter(&$data) {
'title' => t('Exclude search in attachments'),
'help' => 'Excludes searching in attachments',
'id' => 'search_api_attachments_include_search_in_attachments',
]
],
];
}
}
......@@ -24,9 +24,8 @@ class ExtractFileValidator {
/**
* Constructs a new ExtractFileValidator class.
*
* @param MimeTypeGuesserInterface $mimeTypeGuesser
* @param \Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mimeTypeGuesser
* Mime type guesser service.
*
*/
public function __construct(MimeTypeGuesserInterface $mimeTypeGuesser) {
$this->mimeTypeGuesser = $mimeTypeGuesser;
......@@ -71,8 +70,8 @@ class ExtractFileValidator {
*
* @param object $file
* File object.
* @param number $max_filesize
* Max allowed file size
* @param int $max_filesize
* Max allowed file size.
*
* @return bool
* TRUE if the file size does not exceed configured max size.
......@@ -102,7 +101,7 @@ class ExtractFileValidator {
*
* @param object $file
* File object.
* @param boolean $excluded_private
* @param bool $excluded_private
* Boolean value whether exclude private file.
*
* @return bool
......
......@@ -136,7 +136,7 @@ class TextExtractorFormSettings extends ConfigFormBase {
$config = $this->configFactory()->getEditable(static::CONFIGNAME);
// Set the extraction method variable.
$config->set('extraction_method', $extractor_plugin_id);
// Set the preserving cache option
// Set the preserving cache option.
$config->set('preserve_cache', $form_state->getValue('preserve_cache'));
$config->save();
......@@ -146,7 +146,8 @@ class TextExtractorFormSettings extends ConfigFormBase {
$extracted_data = NULL;
try {
$extracted_data = $extractor_plugin->extract($file);
} catch (\Exception $e) {
}
catch (\Exception $e) {
$error = $e->getMessage();
}
$file->delete();
......@@ -200,7 +201,7 @@ class TextExtractorFormSettings extends ConfigFormBase {
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function buildTextExtractorConfigForm(array &$form, FormStateInterface $form_state) {
......@@ -244,7 +245,7 @@ class TextExtractorFormSettings extends ConfigFormBase {
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*/
public function buildTextExtractorTestResultForm(array &$form, FormStateInterface $form_state) {
......@@ -283,7 +284,7 @@ class TextExtractorFormSettings extends ConfigFormBase {
*
* @param array $form
* The form array.
* @param FormStateInterface $form_state
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @return array
......@@ -313,8 +314,8 @@ class TextExtractorFormSettings extends ConfigFormBase {
copy($source, $filepath);
// Create the file object.
$file = File::create([
'uri' => $filepath,
'uid' => $this->currentUser()->id(),
'uri' => $filepath,
'uid' => $this->currentUser()->id(),
]);
$file->save();
}
......
......@@ -193,7 +193,6 @@ class ExtractedText extends FileFormatterBase implements ContainerFactoryPluginI
// Drupal\search_api_attachments\Plugin\search_api\processor\FilesExtractor::isFileIndexable()
// and differs mostly in the signature. Unfortunately it can't be used here
// as it requires second argument of type \Drupal\search_api\Item\ItemInterface.
// File should exist in disc.
$indexable = file_exists($file->getFileUri());
if (!$indexable) {
......@@ -202,7 +201,7 @@ class ExtractedText extends FileFormatterBase implements ContainerFactoryPluginI
// File should have a mime type that is allowed.
$excluded_extensions_array = explode(' ', $this->getSetting('excluded_extensions'));
$all_excluded_mimes = $this->extractFileValidator->getExcludedMimes($excluded_extensions_array);
$indexable = $indexable && !in_array($file->getMimeType(),$all_excluded_mimes);
$indexable = $indexable && !in_array($file->getMimeType(), $all_excluded_mimes);
if (!$indexable) {
return FALSE;
}
......@@ -236,10 +235,10 @@ class ExtractedText extends FileFormatterBase implements ContainerFactoryPluginI
*/
public static function defaultSettings() {
return [
'excluded_extensions' => ExtractFileValidator::DEFAULT_EXCLUDED_EXTENSIONS,
'max_filesize' => '0',
'excluded_private' => TRUE,
] + parent::defaultSettings();
'excluded_extensions' => ExtractFileValidator::DEFAULT_EXCLUDED_EXTENSIONS,
'max_filesize' => '0',
'excluded_private' => TRUE,
] + parent::defaultSettings();
}
/**
......
......@@ -232,8 +232,8 @@ class FilesExtractor extends ProcessorPluginBase implements PluginFormInterface
$fids = $this->limitToAllowedNumber($all_fids);
// Retrieve the files.
$files = $this->entityTypeManager
->getStorage('file')
->loadMultiple($fids);
->getStorage('file')
->loadMultiple($fids);
}
if (!empty($files)) {
$extraction = '';
......@@ -324,12 +324,11 @@ class FilesExtractor extends ProcessorPluginBase implements PluginFormInterface
}
}
/**
* Limit the indexed text to first N bytes.
*
* @param string $extracted_text
* The hole extracted text
* The hole extracted text.
*
* @return string
* The first N bytes of the extracted text that will be indexed and cached.
......@@ -496,14 +495,14 @@ class FilesExtractor extends ProcessorPluginBase implements PluginFormInterface
* @see \Drupal\Core\Plugin\PluginFormInterface::validateConfigurationForm()
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Validate 'number_first_bytes'
// Validate 'number_first_bytes'.
$number_first_bytes = trim($form_state->getValue('number_first_bytes'));
$error = $this->validateSize($number_first_bytes);
if ($error) {
$form_state->setError($form['number_first_bytes'], $this->t('The size limit option must contain a valid value. You may either enter "0" (for no restriction) or a string like "10 KB", "10 MB" or "10 GB".'));
}
// Validate 'max_filesize'
// Validate 'max_filesize'.
$max_filesize = trim($form_state->getValue('max_filesize'));
$error = $this->validateSize($max_filesize);
if ($error) {
......@@ -513,9 +512,11 @@ class FilesExtractor extends ProcessorPluginBase implements PluginFormInterface
/**
* Helper method to validate the size of files' format.
*
* @param string $bytes
* @return boolean
* TRUE if the $bites is of form "N KB", "N MB" or "N GB" where N is integer.
*
* @return bool
* TRUE if the $bites is of form "N KB", "N MB" or "N GB" where N is integer.
*/
public function validateSize($bytes) {
$error = FALSE;
......
......@@ -51,7 +51,7 @@ class PdftotextExtractor extends TextExtractorPluginBase {
}
}
/**
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
......
......@@ -2,7 +2,6 @@
namespace Drupal\search_api_attachments\Plugin\search_api_attachments;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -11,7 +10,6 @@ use Drupal\search_api_attachments\TextExtractorPluginBase;
use Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Drupal\file\Entity\File;
/**
......@@ -80,10 +78,10 @@ class SolrExtractor extends TextExtractorPluginBase {
* Extract the body from XML response.
*/
public static function extractBody($xml_data) {
if (!preg_match(',<body[^>]*>(.*)</body>,sim', $xml_data, $matches)) {
// If the body can't be found return just the text. This will be safe
// and contain any text to index.
return strip_tags($xml_data);
if (!preg_match(',<body[^>]*>(.*)</body>,sim', $xml_data, $matches)) {
// If the body can't be found return just the text. This will be safe
// and contain any text to index.
return strip_tags($xml_data);
}
// Return the full content of the body. Including tags that can optionally
// be used for index weight.
......
......@@ -13,6 +13,9 @@ use Drupal\views\Plugin\views\filter\BooleanOperator;
*/
class SearchApiAttachmentsFilterPlugin extends BooleanOperator {
/**
*
*/
public function query() {
if (!$this->value) {
return;
......
......@@ -94,8 +94,7 @@ Yay!</p>
<p/>
</div>
</body>
</html>'
, '
</html>', '
<div class="page">
<p/>
<p>Congratulations!
......@@ -103,8 +102,9 @@ The extraction seems working!
Yay!</p>
<p/>
</div>
'
',
],
];
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment