Skip to content

Commit

Permalink
Merge pull request #11 from venveo/develop
Browse files Browse the repository at this point in the history
4.0
  • Loading branch information
Mosnar authored Jul 25, 2022
2 parents 9008237 + 6459d3a commit 8b9a089
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 103 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Document Search Changelog

## 4.0.0 - 2022/07/24

### Added
- Added support for MS Office Documents. (.doc, .docx, .xlsx, .pptx, .txt)

### Changed
- Volume settings now store the volume uuid instead of ID - **ensure sure you update your settings**
- Document Search now requires Craft 4

## 1.0.3 - 2020-10-27
### Fixed
- Fix environment variable for pdftotext path not working (#5)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Document Search plugin for Craft CMS 3.1
# Document Search plugin for Craft CMS 4
Extracts keywords and phrases from PDF documents and adds them to Craft CMS' native search index.

**NOTE:**
Expand Down
8 changes: 6 additions & 2 deletions 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.3",
"version": "4.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,7 +22,11 @@
}
],
"require": {
"craftcms/cms": "^3.1.0",
"php": "^8.0.2|^9.0",
"ext-zip": "*",
"ext-dom": "*",
"ext-libxml": "*",
"craftcms/cms": "^4.0.0",
"spatie/pdf-to-text": "^1.1",
"yooper/php-text-analysis": "^1.4",
"voku/stop-words": "^2.0"
Expand Down
12 changes: 4 additions & 8 deletions src/DocumentSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use craft\elements\Asset;
use craft\events\DefineBehaviorsEvent;
use craft\events\RegisterElementSearchableAttributesEvent;
use craft\helpers\App;
use venveo\documentsearch\behaviors\AssetContentBehavior;
use venveo\documentsearch\models\Settings;
use venveo\documentsearch\services\DocumentContentService;
Expand All @@ -34,18 +35,13 @@
*/
class DocumentSearch extends Plugin
{
/**
* @var DocumentSearch
*/
public static $plugin;

/**
* @inheritdoc
*/
public function init()
{
parent::init();
self::$plugin = $this;

if (Craft::$app instanceof ConsoleApplication) {
$this->controllerNamespace = 'venveo\documentsearch\console\controllers';
Expand All @@ -70,22 +66,22 @@ function(DefineBehaviorsEvent $event) {
/**
* @inheritdoc
*/
protected function createSettingsModel()
protected function createSettingsModel(): ?\craft\base\Model
{
return new Settings();
}

/**
* @inheritdoc
*/
protected function settingsHtml(): string
protected function settingsHtml(): ?string
{
return Craft::$app->view->renderTemplate(
'document-search/settings',
[
'settings' => $this->getSettings(),
'binaries' => [
'pdftotext' => is_file(Craft::parseEnv($this->getSettings()->pdfToTextExecutable))
'pdftotext' => is_file(App::parseEnv($this->getSettings()->pdfToTextExecutable))
]
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/behaviors/AssetContentBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function getContentKeywords()
{
/** @var Asset $asset */
$asset = $this->owner;
return Plugin::$plugin->documentContent->getAssetContentKeywords($asset);
return Plugin::getInstance()->documentContent->getAssetContentKeywords($asset);
}
}
4 changes: 2 additions & 2 deletions src/console/controllers/ParseDocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ParseDocumentsController extends Controller
*/
public function actionIndexAll()
{
$volumes = Plugin::$plugin->getSettings()['indexVolumes'];
$volumes = Plugin::getInstance()->getSettings()['indexVolumes'];

/** @var Asset $asset */
$volumeCount = 0;
Expand All @@ -45,7 +45,7 @@ public function actionIndexAll()
Console::startProgress(0, count($assets));
foreach ($assets as $i => $asset) {
try {
Plugin::$plugin->documentContent->getAssetContentKeywords($asset);
Plugin::getInstance()->documentContent->getAssetContentKeywords($asset);
} catch (\Exception $e) {
// $this->stdout('Skipped a file - error: '. $asset->id . PHP_EOL);
Craft::warning('Skipped a file - error: '.$asset->id, 'document-search');
Expand Down
10 changes: 5 additions & 5 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/
class Settings extends Model
{
public $pdfToTextExecutable = '/usr/local/bin/pdftotext';
public $maximumDocumentSize = 1024 * 4;
public $indexVolumes = [];
public ?string $pdfToTextExecutable = '/usr/local/bin/pdftotext';
public int $maximumDocumentSize = 1024 * 4;
public array $indexVolumes = [];


public function behaviors()
public function behaviors(): array
{
$behaviors = parent::behaviors();
$behaviors['parser'] = [
Expand All @@ -40,7 +40,7 @@ public function behaviors()
/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
['pdfToTextExecutable', 'string'],
Expand Down
Loading

0 comments on commit 8b9a089

Please sign in to comment.