diff --git a/CHANGELOG.md b/CHANGELOG.md index acbf738..5ba77f3 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. -## 1.0.0 - 2021-09-15 +## 4.0.0-beta.1 - 2022-09-02 n +n ### Added - Initial release diff --git a/README.md b/README.md index c5f049c..da075f8 100755 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ A plugin to generate editable short urls from entries -![Screenshot](resources/img/plugin-logo.png) +![Shortlink](resources/img/shortlink-banner.png) ## Requirements -This plugin requires Craft CMS 3.0.0-beta.23 or later. +This plugin requires Craft CMS 4.0.0 or later. ## Installation @@ -24,6 +24,6 @@ To install the plugin, follow these instructions. ## craft-shortlink Overview -Currently in alpha, do not use in production environments +Currently in beta, do not use in production environments Brought to you by [Percipio](https://percipio.london) diff --git a/resources/img/shortlink-banner.png b/resources/img/shortlink-banner.png new file mode 100644 index 0000000..9f13653 Binary files /dev/null and b/resources/img/shortlink-banner.png differ diff --git a/src/controllers/SettingsController.php b/src/controllers/SettingsController.php index 9f38f36..f4d01b6 100644 --- a/src/controllers/SettingsController.php +++ b/src/controllers/SettingsController.php @@ -146,16 +146,16 @@ public function actionCustomShortlinksSave(): Response $request = Craft::$app->getRequest(); $shortlinkId = $request->getBodyParam('shortlinkId'); + $shortlink = ShortlinkElement::findOne($shortlinkId); - if ($shortlinkId) { - $shortlink = ShortlinkElement::findOne($shortlinkId); - } else { + if (is_null($shortlink)) { $shortlink = new ShortlinkElement(); } $shortlink->shortlinkUri = $request->getBodyParam('shortlinkUri') ?? null; $shortlink->destination = $request->getBodyParam('destination') ?? null; $shortlink->httpCode = $request->getBodyParam('httpCode') ?? null; + $shortlink->isCustom = true; $success = Craft::$app->getElements()->saveElement($shortlink); diff --git a/src/elements/ShortlinkElement.php b/src/elements/ShortlinkElement.php index 1e0b4d0..b309931 100644 --- a/src/elements/ShortlinkElement.php +++ b/src/elements/ShortlinkElement.php @@ -30,6 +30,7 @@ class ShortlinkElement extends Element public ?string $httpCode = null; public ?string $hitCount = null; public ?DateTime $lastUsed = null; + public ?bool $isCustom = false; public string $shortlinkStatus = self::STATUS_ACTIVE; // Static Methods @@ -114,8 +115,13 @@ public function getStatus(): ?string public function afterSave(bool $isNew): void { try { - $record = ShortlinkRecord::findOne(['ownerId' => $this->ownerId]); - Craft::warning("SHORTLINK: fetching shortlink routes for owner ". $this->ownerId); + $record = null; + + if (!$this->isCustom) { + $record = ShortlinkRecord::findOne(['ownerId' => $this->ownerId]); + } elseif(!$isNew) { + $record = ShortlinkRecord::findOne($this->id); + } if (!$record) { $record = new ShortlinkRecord();