Skip to content

Commit

Permalink
feat: psr-4 and psr-12
Browse files Browse the repository at this point in the history
fix: restored ss5 compatible queued jobs

fix: restored ss5 compatibility

fix: removed duplicate class import

fix: imported new searchindex full class name

fix: imported new tntsearchhelper full class name
  • Loading branch information
tiller1010 committed Aug 2, 2024
1 parent 9bf25ce commit a766548
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/.github export-ignore
/tests export-ignore
/client/src export-ignore
/.gitattributes export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
/.github export-ignore
/doctum* export-ignore

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
composer.lock
doctum_build
doctum_cache
gh-payload.json
vendor

11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"license": "MIT",
"homepage": "https://github.com/werkbot/silverstripe-module-search",
"require": {
"php": "^8.0",
"silverstripe/cms": "^4",
"silverstripe/framework": "^4",
"php": "^8.0 || ^8.1",
"silverstripe/cms": "^4 || ^5",
"silverstripe/framework": "^4 || ^5",
"teamtnt/tntsearch": "v4.2.1",
"ext-sqlite3": "*",
"symbiote/silverstripe-queuedjobs": "^4.12"
"symbiote/silverstripe-queuedjobs": "^4.12 || ^5.1"
},
"require-dev": {
"code-lts/doctum": "^5.5"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 8 additions & 0 deletions doctum.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return new Doctum\Doctum(__DIR__ . '/src', [
'title' => 'Werkbot Search',
'build_dir' => __DIR__.'/doctum_build',
'cache_dir' => __DIR__.'/doctum_cache',
]);

1 change: 1 addition & 0 deletions src/DatabaseAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataExtension;
use Werkbot\Search\Tasks\SearchIndex;

class DatabaseAdminExtension extends DataExtension
{
Expand Down
4 changes: 2 additions & 2 deletions src/Helpers/TNTSearchHelper.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace Werkbot\Search;
namespace Werkbot\Search\Helpers;

use TeamTNT\TNTSearch\TNTSearch;
use SilverStripe\Core\Environment;

/**/
class TNTSearchHelper
{
/*
Expand Down Expand Up @@ -58,3 +57,4 @@ public function getTNTSearchIndex($create = false)
return $indexer;
}
}

3 changes: 2 additions & 1 deletion src/Jobs/RemoveSearchQueriesJob.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Werkbot\Search;
namespace Werkbot\Search\Jobs;

use SilverStripe\Core\Config\Configurable;
use Symbiote\QueuedJobs\Services\AbstractQueuedJob;
Expand Down Expand Up @@ -68,3 +68,4 @@ public function afterComplete()
QueuedJobService::singleton()->queueJob(new RemoveSearchQueriesJob(), date('Y-m-d', strtotime($queueNextRun)));
}
}

16 changes: 8 additions & 8 deletions src/SearchControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Werkbot\Search;

use SilverStripe\ORM\ArrayList;
use SilverStripe\CMS\Search\SearchForm;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\PaginatedList;
use Werkbot\Search\TNTSearchHelper;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\CMS\Search\SearchForm;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\SiteConfig\SiteConfig;
use TeamTNT\TNTSearch\Exceptions\IndexNotFoundException;
use Werkbot\Search\Helpers\TNTSearchHelper;

class SearchControllerExtension extends DataExtension
{
Expand Down Expand Up @@ -66,7 +66,7 @@ public function SiteSearchForm()
/**
* Process and render search results.
*
* @param array $data The raw request data submitted by user
* @param array $searchdata The raw request data submitted by user
* @param SiteSearchForm $form The form instance that was submitted
* @param HTTPRequest $request Request generated for this action
**/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Werkbot\Search;
namespace Werkbot\Search\SearchQueries;

use SilverStripe\ORM\DB;
use SilverStripe\ORM\ArrayList;
Expand All @@ -15,19 +15,19 @@ public function title()
{
return 'Search Query Report';
}

public function description()
{
$desc = 'Shows search queries';

return $desc;
}

public function sort()
{
return 1;
}

public function records($params = null)
{
if ($params){
Expand Down Expand Up @@ -63,13 +63,13 @@ public function records($params = null)

return $records;
}

public function sourceRecords($params = null)
{
$params = ((isset($_REQUEST['filters'])) ? $_REQUEST['filters'] : null);
return $this->records($params);
}

public function columns()
{
$fields = [
Expand All @@ -86,8 +86,8 @@ public function columns()

return $fields;
}
public function parameterFields()

public function parameterFields()
{
$today = date('Y-m-d');

Expand All @@ -107,3 +107,4 @@ public function parameterFields()
);
}
}

7 changes: 4 additions & 3 deletions src/SearchQueries/SearchQuery.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

namespace Werkbot\Search;
namespace Werkbot\Search\SearchQueries;

use SilverStripe\ORM\DataObject;

class SearchQuery extends DataObject
class SearchQuery extends DataObject
{
private static $singular_name = 'Search Query';
private static $plural_name = 'Search Queries';
private static $table_name = 'SearchQuery';

private static $db = [
'Query' => 'Text',
];
}

44 changes: 31 additions & 13 deletions src/SearchableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

namespace Werkbot\Search;

use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldButtonRow;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
use Symbiote\GridFieldExtensions\GridFieldEditableColumns;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use Werkbot\Search\Helpers\TNTSearchHelper;

class SearchableExtension extends DataExtension
{
Expand All @@ -42,6 +43,7 @@ class SearchableExtension extends DataExtension
"getSearchableTitle" => "Text",
"getSearchableSummary" => 'HTMLText',
];

/**
* updateCMSFields
* Adds the SearchTerms GridField to the CMS tab
Expand Down Expand Up @@ -113,7 +115,7 @@ public function addSearchSettingFields(FieldList &$fields)
* getIndexQuery
* This query is used when building the index
*
* @return string/boolean - FALSE if not set
* @return string|boolean - FALSE if not set
* Example:
SELECT
concat(\"Page_\", SiteTree.ID) AS ID,
Expand Down Expand Up @@ -148,6 +150,7 @@ public function getSearchableID()
{
return $this->owner->ClassName . "_" . $this->owner->ID;
}

/**
* getSearchableTitle
* Returns the title, to be used in search results
Expand All @@ -163,6 +166,7 @@ public function getSearchableTitle()
return $this->owner->Title;
}
}

/**
* getSearchableTitleColumnName
* Returns the name of the Title Column, "Title" is returned if the
Expand All @@ -177,6 +181,7 @@ public function getSearchableTitleColumnName()
return "Title";
}
}

/**
* getSearchableSummary
* Returns the content to be used in search results
Expand All @@ -197,6 +202,7 @@ public function getSearchableSummary()

return $content;
}

/**
* getSearchableContent
* Returns the content to be used when indexing this record
Expand All @@ -221,6 +227,7 @@ public function getSearchableContent()

return $content;
}

/**
* getSearchableSummaryColumnName
* Returns the name of the Summary Column, "Content" is returned if the
Expand All @@ -235,6 +242,7 @@ public function getSearchableSummaryColumnName()
return "Content";
}
}

/**
* insertIndex
*
Expand All @@ -255,6 +263,7 @@ public function insertIndex()
'Content' => $content,
]);
}

/**
* updateIndex
*
Expand All @@ -278,6 +287,7 @@ public function updateIndex()
]
);
}

/**
* deleteIndex
*
Expand All @@ -288,6 +298,7 @@ public function deleteIndex()
$index = TNTSearchHelper::Instance()->getTNTSearchIndex();
$index->delete(ClassInfo::shortName($this->owner->ClassName) . "_" . $this->owner->ID);
}

/**
* onBeforeWrite
*
Expand All @@ -302,6 +313,7 @@ public function onBeforeWrite()
}
parent::onBeforeWrite();
}

/**
* onAfterWrite
*
Expand All @@ -314,6 +326,7 @@ public function onAfterWrite()
}
parent::onAfterWrite();
}

/**
* onBeforePublish
*
Expand All @@ -325,6 +338,7 @@ public function onBeforePublish()
$this->owner->insertIndex();
}
}

/**
* onAfterPublish
*
Expand All @@ -334,6 +348,7 @@ public function onAfterPublish()
{
$this->owner->updateIndex();
}

/**
* onAfterUnpublish
*
Expand All @@ -343,13 +358,16 @@ public function onAfterUnpublish()
{
$this->owner->deleteIndex();
}

/**
* onAfterDelete
*
* @return void
**/
public function onAfterDelete()
{
$this->owner->deleteIndex();
$this->owner->deleteIndex();
}

}

4 changes: 2 additions & 2 deletions src/Tasks/SearchIndex.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Werkbot\Search;
namespace Werkbot\Search\Tasks;

use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DB;
use Werkbot\Search\TNTSearchHelper;
use Werkbot\Search\Helpers\TNTSearchHelper;

class SearchIndex extends BuildTask
{
Expand Down

0 comments on commit a766548

Please sign in to comment.