Skip to content

Commit

Permalink
ENHANCEMENT CMS 5 compatibility (#44)
Browse files Browse the repository at this point in the history
* UPDATE composer requirements for CMS 5

* UPDATE type hinting

* UPDATE use statment cleanup

* UPDATE CI configuration

* UPDATE allowed plugins
  • Loading branch information
muskie9 authored Nov 29, 2023
1 parent 5f9a28b commit 7565ca7
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 106 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

services:
mysql:
image: "mysql:5.7"
image: "mysql:8.0"
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD:
Expand All @@ -32,8 +32,8 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.3"
- "7.4"
- "8.1"
- "8.2"

steps:
- name: "Checkout"
Expand Down
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@
],
"license": "BSD-3-Clause",
"require": {
"dynamic/silverstripe-linkable": "^1.0",
"silverstripe/recipe-cms": "^4.2",
"silverstripe/lumberjack": "^2.0",
"symbiote/silverstripe-gridfieldextensions": "^3.0"
"silverstripe/linkfield":"^3.0",
"silverstripe/recipe-cms": "^5.0",
"silverstripe/lumberjack": "^3.0",
"symbiote/silverstripe-gridfieldextensions": "^4.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^3.0",
"phploc/phploc": "^4.0",
"pdepend/pdepend": "^2.5",
"theseer/phpdox": "^0.11.0"
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {
"Dynamic\\RecipeBook\\": "src/",
"Dynamic\\RecipeBook\\Test\\": "tests/"
}
},
"config": {
"allow-plugins": {
"composer/installers": true,
"silverstripe/vendor-plugin": true,
"silverstripe/recipe-plugin": true
},
"process-timeout": 600
},
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
"dev-master": "4.x-dev"
}
},
"minimum-stability": "dev",
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/RecipeCategoryPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RecipeCategoryPageController extends \PageController
* @param HTTPRequest|null $request
* @return PaginatedList
*/
public function paginatedList(HTTPRequest $request = null)
public function paginatedList(HTTPRequest $request = null): PaginatedList
{
if (!$request instanceof HTTPRequest) {
$request = $this->getRequest();
Expand Down
9 changes: 7 additions & 2 deletions src/Controller/RecipeLandingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

namespace Dynamic\RecipeBook\Page;

use SilverStripe\Control\HTTPRequest;
use SilverStripe\ORM\PaginatedList;

class RecipeLandingController extends \PageController
{
public function paginatedList(HTTPRequest $request = null)
/**
* @param HTTPRequest|null $request
* @return PaginatedList
*/
public function paginatedList(HTTPRequest $request = null): PaginatedList
{
if ($request === null) {
$request = $this->request;
Expand All @@ -21,7 +26,7 @@ public function paginatedList(HTTPRequest $request = null)
}

// allow $records to be updated via extension
$this->owner->extend('updatePaginatedList', $records);
$this->extend('updatePaginatedList', $records);

return $records;
}
Expand Down
22 changes: 11 additions & 11 deletions src/Model/RecipeDirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ class RecipeDirection extends DataObject
/**
* @var array
*/
private static $db = [
private static array $db = [
'Title' => 'HTMLText',
'Sort' => 'Int',
];

/**
* @var array
*/
private static $has_one = [
private static array $has_one = [
'Recipe' => RecipePage::class,
];

/**
* @var string
*/
private static $default_sort = 'Sort';
private static string $default_sort = 'Sort';

/**
* @var string
*/
private static $table_name = 'RecipeDirection';
private static string $table_name = 'RecipeDirection';

/**
* @return FieldList
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$recipe = $fields->dataFieldByName('RecipeID');
Expand All @@ -66,9 +66,9 @@ public function getCMSFields()
}

/**
*
* @return void
*/
protected function onBeforeWrite()
protected function onBeforeWrite(): void
{
parent::onBeforeWrite();

Expand All @@ -82,7 +82,7 @@ protected function onBeforeWrite()
* @param array $context
* @return bool
*/
public function canCreate($member = null, $context = [])
public function canCreate($member = null, $context = []): bool
{
return true;
}
Expand All @@ -91,7 +91,7 @@ public function canCreate($member = null, $context = [])
* @param null $member
* @return bool
*/
public function canEdit($member = null)
public function canEdit($member = null): bool
{
return true;
}
Expand All @@ -100,7 +100,7 @@ public function canEdit($member = null)
* @param null $member
* @return bool
*/
public function canDelete($member = null)
public function canDelete($member = null): bool
{
return true;
}
Expand All @@ -109,7 +109,7 @@ public function canDelete($member = null)
* @param null $member
* @return bool
*/
public function canView($member = null)
public function canView($member = null): bool
{
return true;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Model/RecipeIngredient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RecipeIngredient extends DataObject
/**
* @var string
*/
private static $singular_name = 'Recipe Ingredient';
private static string $singular_name = 'Recipe Ingredient';

/**
* @var string
Expand All @@ -31,37 +31,37 @@ class RecipeIngredient extends DataObject
/**
* @var string
*/
private static $description = 'An ingredient used in a Recipe';
private static string $description = 'An ingredient used in a Recipe';

/**
* @var array
*/
private static $db = [
private static array $db = [
'Title' => 'Varchar(255)',
'Sort' => 'Int',
];

/**
* @var array
*/
private static $has_one = [
private static array $has_one = [
'Recipe' => RecipePage::class,
];

/**
* @var string
*/
private static $default_sort = 'Sort';
private static string $default_sort = 'Sort';

/**
* @var string
*/
private static $table_name = 'RecipeIngredient';
private static string $table_name = 'RecipeIngredient';

/**
* @return FieldList
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$recipe = $fields->dataFieldByName('RecipeID');
Expand All @@ -75,9 +75,9 @@ public function getCMSFields()
}

/**
*
* @return void
*/
protected function onBeforeWrite()
protected function onBeforeWrite(): void
{
parent::onBeforeWrite();

Expand All @@ -91,7 +91,7 @@ protected function onBeforeWrite()
* @param array $context
* @return bool
*/
public function canCreate($member = null, $context = [])
public function canCreate($member = null, $context = []): bool
{
return true;
}
Expand All @@ -100,7 +100,7 @@ public function canCreate($member = null, $context = [])
* @param null $member
* @return bool
*/
public function canEdit($member = null)
public function canEdit($member = null): bool
{
return true;
}
Expand All @@ -109,7 +109,7 @@ public function canEdit($member = null)
* @param null $member
* @return bool
*/
public function canDelete($member = null)
public function canDelete($member = null): bool
{
return true;
}
Expand All @@ -118,7 +118,7 @@ public function canDelete($member = null)
* @param null $member
* @return bool
*/
public function canView($member = null)
public function canView($member = null): bool
{
return true;
}
Expand Down
36 changes: 20 additions & 16 deletions src/Page/RecipeCategoryPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,66 @@

namespace Dynamic\RecipeBook\Page;

use SilverStripe\Dev\Debug;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DB;

class RecipeCategoryPage extends \Page
{
/**
* @var string
*/
private static $singular_name = 'Recipe Category';
private static string $singular_name = 'Recipe Category';

/**
* @var string
*/
private static $plural_name = 'Recipe Categories';
private static string $plural_name = 'Recipe Categories';

/**
* @var string
*/
private static $description = 'A category for recipes.';
private static string $description = 'A category for recipes.';

/**
* @var array
*/
private static $db = [
private static array $db = [
'RecipesPerPage' => 'Int',
];

/**
* @var array
*/
private static $belongs_many_many = [
private static array $belongs_many_many = [
'Recipes' => RecipePage::class,
];

/**
* @var array
*/
private static $defaults = [
private static array $defaults = [
'RecipesPerPage' => 9,
];

/**
* @var array
*/
private static $allowed_children = [
private static array $allowed_children = [
RecipeCategoryPage::class,
RecipePage::class,
];

/**
* @var string
*/
private static $table_name = 'RecipeCategoryPage';
private static string $table_name = 'RecipeCategoryPage';

public function getCMSFields()
/**
* @return FieldList
*/
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->addFieldToTab(
Expand All @@ -78,24 +81,25 @@ public function getCMSFields()
return $fields;
}

public function getRecipeList()
/**
* @return DataList
*/
public function getRecipeList(): DataList
{
$categories = RecipeCategoryPage::get()->filter('ParentID', $this->data()->ID)->column('ID');
$categories[] = $this->data()->ID;

$recipes = RecipePage::get()
return RecipePage::get()
->filterAny([
'ParentID' => $categories,
'Categories.ID' => $categories,
]);

return $recipes;
}

/**
* @return \SilverStripe\ORM\DataList
* @return DataList
*/
public function getFeaturedRecipes()
public function getFeaturedRecipes(): DataList
{
$recipes = $this->getRecipeList()
->sort('Weight DESC')
Expand Down
Loading

0 comments on commit 7565ca7

Please sign in to comment.