Skip to content

Commit

Permalink
Merge pull request #6 from venveo/fix/broken-env
Browse files Browse the repository at this point in the history
Fix broken env parsing for pdftotext
  • Loading branch information
Mosnar authored Oct 27, 2020
2 parents 421c4ad + 8b0c686 commit 9008237
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Document Search Changelog

## 1.0.3 - 2020-10-27
### Fixed
- Fix environment variable for pdftotext path not working (#5)

## 1.0.2 - 2019-11-09
### Changed
- Loosen version constraints on dependencies
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "venveo/craft-documentsearch",
"description": "Extract the contents of text documents and add to Craft's search index",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected function settingsHtml(): string
[
'settings' => $this->getSettings(),
'binaries' => [
'pdftotext' => is_file($this->getSettings()->pdfToTextExecutable)
'pdftotext' => is_file(Craft::parseEnv($this->getSettings()->pdfToTextExecutable))
]
]
);
Expand Down
15 changes: 13 additions & 2 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace venveo\documentsearch\models;

use craft\base\Model;
use craft\behaviors\EnvAttributeParserBehavior;

/**
* @author Venveo
Expand All @@ -23,8 +24,18 @@ class Settings extends Model
public $maximumDocumentSize = 1024 * 4;
public $indexVolumes = [];

// Public Methods
// =========================================================================

public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['parser'] = [
'class' => EnvAttributeParserBehavior::class,
'attributes' => [
'pdfToTextExecutable'
],
];
return $behaviors;
}

/**
* @inheritdoc
Expand Down
2 changes: 1 addition & 1 deletion src/services/DocumentContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,6 @@ public function extractContentFromPDF($filepath): string
Craft::info('Extracting PDF content from: '.$filepath, __METHOD__);
// change directory to guarantee writable directory
chdir(Craft::$app->path->getAssetsPath().DIRECTORY_SEPARATOR);
return Pdf::getText($filepath, Plugin::$plugin->getSettings()->pdfToTextExecutable);
return Pdf::getText($filepath, Craft::parseEnv(Plugin::$plugin->getSettings()->pdfToTextExecutable));
}
}

0 comments on commit 9008237

Please sign in to comment.