Skip to content

Commit

Permalink
Merge branch 'develop-v4' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
michtio committed Sep 2, 2022
2 parents cc55dcf + 64005e2 commit 1c2f994
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Binary file added resources/img/shortlink-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions src/elements/ShortlinkElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1c2f994

Please sign in to comment.