Skip to content

Commit

Permalink
Add support for Silverstripe 5
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispenny committed Feb 26, 2023
1 parent 2bae9f6 commit 3026eb4
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 146 deletions.
13 changes: 5 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,19 @@
},
{
"name": "Chris Penny",
"email": "cpenny@silverstripe.com"
"email": "chris.penny@gmail.com"
}
],
"support": {
"issues": "http://github.com/ichaber/silverstripe-swiftype/issues"
},
"require": {
"php": "^7.4 || ^8.0",
"silverstripe/vendor-plugin": "^1.6",
"silverstripe/framework": "^4",
"silverstripe/cms": "^4",
"guzzlehttp/guzzle": "^7",
"guzzlehttp/psr7": "^2"
"php": "^8.1",
"silverstripe/cms": "^5",
"guzzlehttp/guzzle": "^7.5"
},
"require-dev": {
"silverstripe/recipe-testing": "^2"
"silverstripe/recipe-testing": "^3"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 1 addition & 4 deletions src/Extensions/SwiftypeSiteConfigFieldsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
class SwiftypeSiteConfigFieldsExtension extends DataExtension
{
/**
* @var array $db
*/
private static $db = [
private static array $db = [
'SwiftypeEnabled' => 'Boolean',
'SwiftypeAccessKey' => 'Varchar(255)',
'SwiftypeAPIKey' => 'Varchar(255)',
Expand Down
4 changes: 1 addition & 3 deletions src/Extensions/SwiftypeSiteTreeCrawlerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ class SwiftypeSiteTreeCrawlerExtension extends SiteTreeExtension
* Urls to crawl
*
* array keyed by getOwnerKey
*
* @var array
*/
private $urlsToCrawl = [];
private array $urlsToCrawl = [];

public function setUrlsToCrawl(array $urls)
{
Expand Down
15 changes: 3 additions & 12 deletions src/MetaTags/SwiftypeMetaTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@ abstract class SwiftypeMetaTag implements SwiftypeMetaTagInterface
{
use Configurable;

/**
* @var string|null
*/
protected $name;
protected ?string $name;

/**
* @var string|null
*/
protected $fieldName;
protected ?string $fieldName;

/**
* @var string|null
*/
protected $fieldType;
protected ?string $fieldType;

public function getMetaTagString(DataObject $dataObject): ?string
{
Expand Down
15 changes: 3 additions & 12 deletions src/MetaTags/SwiftypeMetaTagDescription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

class SwiftypeMetaTagDescription extends SwiftypeMetaTag
{
/**
* @var string
*/
protected $name = 'description';
protected ?string $name = 'description';

/**
* @var string
*/
protected $fieldName = 'MetaDescription';
protected ?string $fieldName = 'MetaDescription';

/**
* @var string
*/
protected $fieldType = 'text';
protected ?string $fieldType = 'text';
}
15 changes: 3 additions & 12 deletions src/MetaTags/SwiftypeMetaTagPublishedAt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

class SwiftypeMetaTagPublishedAt extends SwiftypeMetaTag
{
/**
* @var string
*/
protected $name = 'published_at';
protected ?string $name = 'published_at';

/**
* @var string
*/
protected $fieldName = 'LastEdited';
protected ?string $fieldName = 'LastEdited';

/**
* @var string
*/
protected $fieldType = 'date';
protected ?string $fieldType = 'date';
}
15 changes: 3 additions & 12 deletions src/MetaTags/SwiftypeMetaTagTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

class SwiftypeMetaTagTitle extends SwiftypeMetaTag
{
/**
* @var string
*/
protected $name = 'title';
protected ?string $name = 'title';

/**
* @var string
*/
protected $fieldName = 'Title';
protected ?string $fieldName = 'Title';

/**
* @var string
*/
protected $fieldType = 'string';
protected ?string $fieldType = 'string';
}
15 changes: 3 additions & 12 deletions src/MetaTags/SwiftypeMetaTagURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@

class SwiftypeMetaTagURL extends SwiftypeMetaTag
{
/**
* @var string
*/
protected $name = 'url';
protected ?string $name = 'url';

/**
* @var string|null
*/
protected $fieldName = 'Link';
protected ?string $fieldName = 'Link';

/**
* @var string
*/
protected $fieldType = 'enum';
protected ?string $fieldType = 'enum';
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBHTMLText;

/**
* Class SwiftypeMetaTagContentExtensionTest
*
* @package Ichaber\SSSwiftype\Tests\Extensions
*/
class SwiftypeMetaTagContentExtensionTest extends SapphireTest
{
/**
Expand All @@ -41,7 +36,7 @@ public function setUp(): void
*/
public function testMetaTagOutput(): void
{
Config::inst()->update(
Config::modify()->set(
SwiftypeSiteTree::class,
'swiftype_meta_tag_classes',
[
Expand All @@ -60,7 +55,7 @@ public function testMetaTagOutput(): void
$mock = file_get_contents(__DIR__ . '/../Mock/TagsOutput.html');
$mock = trim(preg_replace("/\s+/S", '', $mock));

// Remove formatting from output output
// Remove formatting from output
$output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue()));

$this->assertEquals($mock, $output);
Expand All @@ -84,7 +79,7 @@ public function testMetaTagsReturnsConfiguredTags(): void
{
$page = new SwiftypeSiteTree();
$page->MetaDescription = 'My description';
$page->config()->update('swiftype_meta_tag_classes', [
$page->config()->set('swiftype_meta_tag_classes', [
SwiftypeMetaTagDescription::class
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;

/**
* Class SwiftypeMetaTagContentExtensionTest
*
* @package Ichaber\SSSwiftype\Tests\Extensions
*/
class SwiftypeSiteTreeCrawlerExtensionTest extends SapphireTest
{
/**
Expand All @@ -37,7 +32,7 @@ public function setUp(): void
public function testUrlsToCrawlPublished(): void
{
// Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test
Config::inst()->update(
Config::modify()->set(
SwiftypeSiteTreeCrawlerExtension::class,
'clear_cache_disabled',
true
Expand All @@ -51,7 +46,7 @@ public function testUrlsToCrawlPublished(): void
$key = str_replace('\\', '', $page->ClassName . $page->ID);

$expectedUrls = [
'localhost/page1/',
'localhost/page1',
];
$urls = [];

Expand Down Expand Up @@ -81,7 +76,7 @@ public function testUrlsToCrawlPublished(): void
public function testUrlsToCrawlUnpublished(): void
{
// Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test
Config::inst()->update(
Config::modify()->set(
SwiftypeSiteTreeCrawlerExtension::class,
'clear_cache_disabled',
true
Expand All @@ -100,7 +95,7 @@ public function testUrlsToCrawlUnpublished(): void
$page->doUnpublish();

$expectedUrls = [
'localhost/page2/',
'localhost/page2',
];
$urls = [];

Expand Down Expand Up @@ -130,7 +125,7 @@ public function testUrlsToCrawlUnpublished(): void
public function testUrlsToCrawlSegmentChanged(): void
{
// Set our config to not clear caches after un/publish, so that we can easily fetch the Urls for our test
Config::inst()->update(
Config::modify()->set(
SwiftypeSiteTreeCrawlerExtension::class,
'clear_cache_disabled',
true
Expand All @@ -153,8 +148,8 @@ public function testUrlsToCrawlSegmentChanged(): void

// We expect two Urls now. One from before the segment change, and one from after it
$expectedUrls = [
'localhost/page3/',
'localhost/page3changed/',
'localhost/page3',
'localhost/page3changed',
];
$urls = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use SilverStripe\Dev\TestOnly;

/**
* Class SwiftypeSiteTree
*
* @package Ichaber\SSSwiftype\Tests\Fake
* @mixin SwiftypeMetaTagContentExtension
* @mixin SwiftypeSiteTreeCrawlerExtension
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;

/**
* Class SwiftypeMetaTagPublishedAtTest
*
* @package Ichaber\SSSwiftype\Tests\MetaTags
*/
class SwiftypeMetaTagPublishedAtTest extends SapphireTest
{
/**
Expand All @@ -36,8 +31,8 @@ public function setUp(): void
*/
public function testMetaTagOutput(): void
{
Config::inst()->update(SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [SwiftypeMetaTagPublishedAt::class]);
Config::inst()->update(SwiftypeMetaTagPublishedAt::class, 'date_format', 'YYYY-MM-dd');
Config::modify()->set(SwiftypeSiteTree::class, 'swiftype_meta_tag_classes', [SwiftypeMetaTagPublishedAt::class]);
Config::modify()->set(SwiftypeMetaTagPublishedAt::class, 'date_format', 'YYYY-MM-dd');

/** @var SwiftypeSiteTree $page */
$page = $this->objFromFixture(SwiftypeSiteTree::class, 'page1');
Expand All @@ -48,7 +43,7 @@ public function testMetaTagOutput(): void
$mock = str_replace('http://', '', $mock);
$mock = str_replace('https://', '', $mock);

// Remove formatting from output output
// Remove formatting from output
$output = trim(preg_replace("/\s+/S", '', $page->getSwiftypeMetaTags()->getValue()));
$output = str_replace('http://', '', $output);
$output = str_replace('https://', '', $output);
Expand Down
Loading

0 comments on commit 3026eb4

Please sign in to comment.