Skip to content

Commit

Permalink
Merge branch 'release/4.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 16, 2024
2 parents 836d082 + 24d20df commit cbeb2ee
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 160 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ci
on:
workflow_dispatch:
push:
branches:
- develop
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
ci:
name: ci
uses: studioespresso/.github/.github/workflows/ci.yml@main
with:
craft_version: '4'
jobs: '["ecs", "phpstan"]'
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# COMPOSER
/vendor
composer.lock

# BUILD FILES
/bower_components/*
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.0.5 - 2024-02-16
### Fixed
- Change schema version to fix an issue with migrations from 4.0.0 not being applied correctly.


## 4.0.4 - 2024-02-05
### Fixed
- Fixed an issue where the "Allow sitename to be hidden" option would not work ([#90](https://github.com/studioespresso/craft-seo-fields/issues/90))


## 4.0.3 - 2024-02-05
### Fixed
- Fixed a permissions issue on sites with multiple users and user groups
Expand Down
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-seo-fields",
"description": "Fields for your SEO & OG meta data",
"type": "craft-plugin",
"version": "4.0.4",
"version": "4.0.5",
"keywords": [
"craft",
"cms",
Expand Down Expand Up @@ -31,10 +31,13 @@
"spatie/schema-org": "^3.0.0"
},
"require-dev": {
"codeception/codeception": "^4.0.0",
"vlucas/phpdotenv": "^3.0",
"codeception/module-yii2": "^1.0.0",
"codeception/module-asserts": "^1.0.0"
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main"
},
"scripts": {
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G"
},
"autoload": {
"psr-4": {
Expand All @@ -47,5 +50,11 @@
"hasCpSettings": true,
"hasCpSection": true,
"class": "studioespresso\\seofields\\SeoFields"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
}
}
14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"bugs": {
"url": "https://github.com/janhenckens/craft3-seo-fields/issues"
},

"homepage": "https://github.com/janhenckens/craft3-seo-fields#readme",
"devDependencies": {
"codemirror": "^5.44.0",
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 1
paths:
- src
68 changes: 26 additions & 42 deletions src/SeoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace studioespresso\seofields;

use Craft;
use craft\base\Element;
use craft\base\Plugin;
use craft\elements\Entry;
use craft\events\DefineBehaviorsEvent;
Expand All @@ -34,7 +33,6 @@
use craft\services\UserPermissions;
use craft\utilities\ClearCaches;
use craft\web\ErrorHandler;
use craft\web\twig\variables\CraftVariable;
use craft\web\UrlManager;
use studioespresso\seofields\behaviors\EntrySeoBehavior;
use studioespresso\seofields\events\RegisterSeoElementEvent;
Expand All @@ -48,7 +46,6 @@
use studioespresso\seofields\services\RenderService;
use studioespresso\seofields\services\SchemaService;
use studioespresso\seofields\services\SitemapService;
use studioespresso\seofields\variables\SeoFieldsVariable;
use yii\base\Event;
use yii\base\Exception;
use yii\console\Application as ConsoleApplication;
Expand Down Expand Up @@ -85,7 +82,7 @@ class SeoFields extends Plugin

// Public Properties
// =========================================================================
public string $schemaVersion = "2.0.0";
public string $schemaVersion = "4.0.0";


public const EVENT_SEOFIELDS_REGISTER_ELEMENT = "registerSeoElement";
Expand All @@ -110,7 +107,7 @@ public function init()
$this->controllerNamespace = 'studioespresso\seofields\console\controllers';
}

Craft::$app->view->hook('seo-fields', function (array &$context) {
Craft::$app->view->hook('seo-fields', function(array &$context) {
return $this->renderService->renderMeta($context);
});

Expand All @@ -123,13 +120,11 @@ public function init()
$this->_registerSiteListeners();
$this->_registerCacheOptions();
$this->_registerCustomElements();
$this->_registerTwigVariable();
$this->_registerUrlChangeListeners();

Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function (DefineBehaviorsEvent $event) {
Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
$event->behaviors[$this->id] = EntrySeoBehavior::class;
});

}

public function getCpNavItem(): ?array
Expand Down Expand Up @@ -213,7 +208,7 @@ private function _registerField()
Event::on(
Fields::class,
Fields::EVENT_REGISTER_FIELD_TYPES,
function (RegisterComponentTypesEvent $event) {
function(RegisterComponentTypesEvent $event) {
$event->types[] = SeoField::class;
}
);
Expand All @@ -224,7 +219,7 @@ private function _registerPermissions()
Event::on(
UserPermissions::class,
UserPermissions::EVENT_REGISTER_PERMISSIONS,
function (RegisterUserPermissionsEvent $event) {
function(RegisterUserPermissionsEvent $event) {

// Register our custom permissions
$permissions = [
Expand Down Expand Up @@ -268,7 +263,7 @@ private function _registerFrontendRoutes()
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_SITE_URL_RULES,
function (RegisterUrlRulesEvent $event) {
function(RegisterUrlRulesEvent $event) {
$robots = SeoFields::$plugin->defaultsService->getRobotsForSite(Craft::$app->getSites()->getCurrentSite());
if ($robots) {
$event->rules = array_merge($event->rules, [
Expand All @@ -295,7 +290,7 @@ private function _registerCpRoutes()
Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function (RegisterUrlRulesEvent $event) {
function(RegisterUrlRulesEvent $event) {
// Register our Control Panel routes
$event->rules = array_merge($event->rules, [
'seo-fields' => 'seo-fields/defaults/index',
Expand All @@ -316,7 +311,7 @@ private function _registerCpListeners()
Event::on(
Sites::class,
Sites::EVENT_AFTER_SAVE_SITE,
function (SiteEvent $event) {
function(SiteEvent $event) {
if ($event->isNew) {
SeoFields::$plugin->defaultsService->copyDefaultsForSite($event->site, $event->oldPrimarySiteId);
}
Expand All @@ -326,36 +321,36 @@ function (SiteEvent $event) {
Event::on(
Elements::class,
Elements::EVENT_AFTER_SAVE_ELEMENT,
function (ElementEvent $event) {
function(ElementEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
}
);

Event::on(
Elements::class,
Elements::EVENT_AFTER_DELETE_ELEMENT,
function (ElementEvent $event) {
function(ElementEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCacheForElement($event->element);
}
);

Event::on(
Sections::class,
Sections::EVENT_AFTER_DELETE_SECTION,
function (SectionEvent $event) {
function(SectionEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCaches();
}
);

Event::on(
Sections::class,
Sections::EVENT_AFTER_DELETE_ENTRY_TYPE,
function (EntryTypeEvent $event) {
function(EntryTypeEvent $event) {
SeoFields::$plugin->sitemapSerivce->clearCaches();
}
);

Event::on(Gc::class, Gc::EVENT_RUN, function () {
Event::on(Gc::class, Gc::EVENT_RUN, function() {
try {
$limit = SeoFields::$plugin->getSettings()->notFoundLimit;
if (!is_int($limit)) {
Expand All @@ -379,7 +374,7 @@ private function _registerSiteListeners()
Event::on(
ErrorHandler::class,
ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION,
function (ExceptionEvent $event) {
function(ExceptionEvent $event) {
try {
if ($event->exception instanceof HttpException && $event->exception->statusCode === 404 && Craft::$app->getRequest()->getIsSiteRequest()) {
Craft::debug("404 exception, processing...", __CLASS__);
Expand All @@ -397,35 +392,35 @@ private function _registerUrlChangeListeners()
if (self::getInstance()->getSettings()->createRedirectForUriChange) {
$beforeEvents = [
Elements::EVENT_BEFORE_SAVE_ELEMENT,
Elements::EVENT_BEFORE_UPDATE_SLUG_AND_URI
Elements::EVENT_BEFORE_UPDATE_SLUG_AND_URI,
];

$afterEvents = [
Elements::EVENT_AFTER_SAVE_ELEMENT,
Elements::EVENT_AFTER_UPDATE_SLUG_AND_URI
Elements::EVENT_AFTER_UPDATE_SLUG_AND_URI,
];

foreach ($beforeEvents as $event) {
Event::on(Elements::class, $event, function (ElementEvent $event) {
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if(ElementHelper::isDraftOrRevision($event->element)) {
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
}

if ($shouldCheckSlug && !$event->element->propagating) {
if ($shouldCheckSlug && !$event->element->propagating) {
self::getInstance()->redirectService->trackElementUris($event->element);
}
});
}

foreach ($afterEvents as $event) {
Event::on(Elements::class, $event, function (ElementEvent $event) {
Event::on(Elements::class, $event, function(ElementEvent $event) {
$shouldCheckSlug = true;
if(ElementHelper::isDraftOrRevision($event->element)) {
if (ElementHelper::isDraftOrRevision($event->element)) {
$shouldCheckSlug = false;
}

if ($shouldCheckSlug && !$event->element->propagating) {
if ($shouldCheckSlug && !$event->element->propagating) {
self::getInstance()->redirectService->handleUriChange($event->element);
}
});
Expand All @@ -438,7 +433,7 @@ private function _registerCacheOptions()
Event::on(
ClearCaches::class,
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
function (RegisterCacheOptionsEvent $event) {
function(RegisterCacheOptionsEvent $event) {
// Register our Control Panel routes
$event->options = array_merge(
$event->options, [
Expand All @@ -456,31 +451,20 @@ private function _registerCustomElements()
{
$elements = [];
if (Craft::$app->getPlugins()->isPluginEnabled('calendar')) {
/** @phpstan-ignore-next-line */
$elements[] = \Solspace\Calendar\Elements\Event::class;
}
if (Craft::$app->getPlugins()->isPluginEnabled('commerce')) {
/** @phpstan-ignore-next-line */
$elements[] = \craft\commerce\elements\Product::class;
}

if ($elements) {
Event::on(SeoFields::class, SeoFields::EVENT_SEOFIELDS_REGISTER_ELEMENT,
function (RegisterSeoElementEvent $event) use ($elements) {
function(RegisterSeoElementEvent $event) use ($elements) {
$event->elements = array_merge($event->elements, $elements);
}
);
}
}

private function _registerTwigVariable()
{
Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('schema', SeoFieldsVariable::class);
}
);
}
}
5 changes: 0 additions & 5 deletions src/behaviors/EntrySeoBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace studioespresso\seofields\behaviors;

use Craft;
use craft\elements\Asset;
use craft\elements\db\ElementQuery;
use craft\elements\db\EntryQuery;
use craft\errors\InvalidFieldException;
use craft\helpers\Db;
use yii\base\Behavior;

/**
Expand Down Expand Up @@ -126,5 +122,4 @@ public function getTwitterImage(): Asset|null
{
return $this->twitterImage;
}

}
2 changes: 1 addition & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"fieldHandle" => "seo",
"notFoundLimit" => 10000,
"createRedirectForUriChange" => true,
'schemaOptions' => []
'schemaOptions' => [],
];
1 change: 1 addition & 0 deletions src/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function options($actionId)
case 'fields':
return ['fieldHandle', 'metaTitle', 'metaDescription'];
}
return parent::options($actionId);
}

public function actionEther()
Expand Down
Loading

0 comments on commit cbeb2ee

Please sign in to comment.