Skip to content

Commit

Permalink
chore: handle deprecations from 1.x (#3909)
Browse files Browse the repository at this point in the history
* chore: drop deprecated `post_number_index` column

* chore: remove deprecated `FlagsWillBeDeleted` event

* chore: `Migration::addSettings` can still be needed

* chore: `settings->get` default can still be needed

* chore: deprecated `$default` in `Settings::serializeToForum` extender

* chore: deprecated request `actor` attribute

* chore: already handled

* chore: remove `RecompileFrontendAssets::whenSettingsSaved`

* chore: remove `getReadIds`

* chore: `Model::dateAttribute` extender

* chore: `evented` js util

* chore: `WelcomeHero` js hidden prop

* chore: attributes pushData with relations

* chore: app request options `extract`

* chore: itemlist deprecations

* chore: `search` state

* chore: `getMentionText`

* chore: deprecated non-registered store type

* chore: `Button` title

* chore: `Modal` deprecations

* chore

* chore: deprecated `less` mixins

* Apply fixes from StyleCI

* fix

* fix: phpstan

* fix

* fix

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
SychO9 and StyleCIBot authored Nov 10, 2023
1 parent d01c0e5 commit e2281a2
Show file tree
Hide file tree
Showing 35 changed files with 48 additions and 633 deletions.
2 changes: 1 addition & 1 deletion extensions/embed/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
padding: 15px 15px;

.scrolled & {
.box-shadow(0 2px 6px var(--shadow-color));
box-shadow: 0 2px 6px var(--shadow-color);
}
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/flags/js/src/forum/addFlagsToPosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function () {

const controls = PostControls.destructiveControls(this.attrs.post);

Object.keys(controls.items).forEach((k) => {
Object.keys(controls.toObject()).forEach((k) => {
const attrs = controls.get(k).attrs;

attrs.className = 'Button';
Expand Down
4 changes: 0 additions & 4 deletions extensions/flags/src/Command/DeleteFlagsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Flarum\Flags\Command;

use Flarum\Flags\Event\Deleting;
use Flarum\Flags\Event\FlagsWillBeDeleted;
use Flarum\Post\Post;
use Flarum\Post\PostRepository;
use Illuminate\Events\Dispatcher;
Expand All @@ -31,9 +30,6 @@ public function handle(DeleteFlags $command): Post

$actor->assertCan('viewFlags', $post->discussion);

// Deprecated, removed v2.0
$this->events->dispatch(new FlagsWillBeDeleted($post, $actor, $command->data));

foreach ($post->flags as $flag) {
$this->events->dispatch(new Deleting($flag, $actor, $command->data));
}
Expand Down
27 changes: 0 additions & 27 deletions extensions/flags/src/Event/FlagsWillBeDeleted.php

This file was deleted.

1 change: 0 additions & 1 deletion extensions/mentions/js/src/forum/forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import './components/UserMentionedNotification';
import './fragments/AutocompleteDropdown';
import './fragments/PostQuoteButton';
import './utils/getCleanDisplayName';
import './utils/getMentionText';
import './utils/reply';
import './utils/selectedText';
import './utils/textFormatter';
Expand Down
21 changes: 0 additions & 21 deletions extensions/mentions/js/src/forum/utils/getMentionText.js

This file was deleted.

3 changes: 2 additions & 1 deletion extensions/nicknames/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
->default('flarum-nicknames.set_on_registration', true)
->default('flarum-nicknames.min', 1)
->default('flarum-nicknames.max', 150)
->serializeToForum('displayNameDriver', 'display_name_driver', null, 'username')
->default('display_name_driver', 'username')
->serializeToForum('displayNameDriver', 'display_name_driver')
->serializeToForum('setNicknameOnRegistration', 'flarum-nicknames.set_on_registration', 'boolval')
->serializeToForum('randomizeUsernameOnRegistration', 'flarum-nicknames.random_username', 'boolval'),

Expand Down
7 changes: 3 additions & 4 deletions framework/core/js/src/admin/components/LoadingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import Modal, { IInternalModalAttrs } from '../../common/components/Modal';
export interface ILoadingModalAttrs extends IInternalModalAttrs {}

export default class LoadingModal<ModalAttrs extends ILoadingModalAttrs = ILoadingModalAttrs> extends Modal<ModalAttrs> {
/**
* @inheritdoc
*/
static readonly isDismissible: boolean = false;
protected static readonly isDismissibleViaCloseButton: boolean = false;
protected static readonly isDismissibleViaEscKey: boolean = false;
protected static readonly isDismissibleViaBackdropClick: boolean = false;

className() {
return 'LoadingModal Modal--small';
Expand Down
21 changes: 6 additions & 15 deletions framework/core/js/src/common/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ export type FlarumGenericRoute = RouteItem<any, any, any>;
export interface FlarumRequestOptions<ResponseType> extends Omit<Mithril.RequestOptions<ResponseType>, 'extract'> {
errorHandler?: (error: RequestError) => void;
url: string;
// TODO: [Flarum 2.0] Remove deprecated option
/**
* Manipulate the response text before it is parsed into JSON.
*
* @deprecated Please use `modifyText` instead.
*/
extract?: (responseText: string) => string;
/**
* Manipulate the response text before it is parsed into JSON.
*
Expand Down Expand Up @@ -434,7 +427,7 @@ export default class Application {
}

protected transformRequestOptions<ResponseType>(flarumOptions: FlarumRequestOptions<ResponseType>): InternalFlarumRequestOptions<ResponseType> {
const { background, deserialize, extract, modifyText, ...tmpOptions } = { ...flarumOptions };
const { background, deserialize, modifyText, ...tmpOptions } = { ...flarumOptions };

// Unless specified otherwise, requests should run asynchronously in the
// background, so that they don't prevent redraws from occurring.
Expand All @@ -446,11 +439,6 @@ export default class Application {

const defaultDeserialize = (response: string) => response as ResponseType;

// When extracting the data from the response, we can check the server
// response code and show an error message to the user if something's gone
// awry.
const originalExtract = modifyText || extract;

const options: InternalFlarumRequestOptions<ResponseType> = {
background: background ?? defaultBackground,
deserialize: deserialize ?? defaultDeserialize,
Expand All @@ -474,11 +462,14 @@ export default class Application {
options.method = 'POST';
}

// When extracting the data from the response, we can check the server
// response code and show an error message to the user if something's gone
// awry.
options.extract = (xhr: XMLHttpRequest) => {
let responseText;

if (originalExtract) {
responseText = originalExtract(xhr.responseText);
if (modifyText) {
responseText = modifyText(xhr.responseText);
} else {
responseText = xhr.responseText;
}
Expand Down
5 changes: 0 additions & 5 deletions framework/core/js/src/common/Model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import app from '../common/app';
import { FlarumRequestOptions } from './Application';
import { fireDeprecationWarning } from './helpers/fireDebugWarning';
import Store, { ApiPayloadSingle, ApiResponseSingle, MetaInformation } from './Store';

export interface ModelIdentifier {
Expand Down Expand Up @@ -113,15 +112,11 @@ export default abstract class Model {
if ('attributes' in data) {
this.data.attributes ||= {};

// @deprecated
// Filter out relationships that got in by accident.
for (const key in data.attributes) {
const val = data.attributes[key];
if (val && val instanceof Model) {
fireDeprecationWarning('Providing models as attributes to `Model.pushData()` or `Model.pushAttributes()` is deprecated.', '3249');
delete data.attributes[key];
data.relationships ||= {};
data.relationships[key] = { data: Model.getIdentifier(val) };
}
}

Expand Down
14 changes: 5 additions & 9 deletions framework/core/js/src/common/Store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import app from '../common/app';
import { FlarumRequestOptions } from './Application';
import { fireDeprecationWarning } from './helpers/fireDebugWarning';
import Model, { ModelData, SavedModelData } from './Model';

export interface MetaInformation {
Expand Down Expand Up @@ -100,7 +99,7 @@ export default class Store {
pushPayload<M extends Model | Model[]>(payload: ApiPayload): ApiResponse<FlatArray<M, 1>> {
if (payload.included) payload.included.map(this.pushObject.bind(this));

const models = payload.data instanceof Array ? payload.data.map((o) => this.pushObject(o, false)) : this.pushObject(payload.data, false);
const models = payload.data instanceof Array ? payload.data.map((o) => this.pushObject(o)) : this.pushObject(payload.data);
const result = models as ApiResponse<FlatArray<M, 1>>;

// Attach the original payload to the model that we give back. This is
Expand All @@ -120,14 +119,11 @@ export default class Store {
* registered for this resource type.
*/
pushObject<M extends Model>(data: SavedModelData): M | null;
pushObject<M extends Model>(data: SavedModelData, allowUnregistered: false): M;
pushObject<M extends Model>(data: SavedModelData, allowUnregistered = true): M | null {
pushObject<M extends Model>(data: SavedModelData): M | null {
if (!this.models[data.type]) {
if (!allowUnregistered) {
setTimeout(() =>
fireDeprecationWarning(`Pushing object of type \`${data.type}\` not allowed, as type not yet registered in the store.`, '3206')
);
}
setTimeout(() => {
throw new Error(`Pushing object of type \`${data.type}\` not allowed, as type not yet registered in the store.`);
});

return null;
}
Expand Down
17 changes: 1 addition & 16 deletions framework/core/js/src/common/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ export interface IButtonAttrs extends ComponentAttrs {
* Default: `false`
*/
loading?: boolean;
/**
* **DEPRECATED:** Please use the `aria-label` attribute instead. For tooltips, use
* the `<Tooltip>` component.
*
* Accessible text for the button. This should always be present if the button only
* contains an icon.
*
* The textual content of this attribute is passed to the DOM element as `aria-label`.
*
* @deprecated
*/
title?: string | Mithril.ChildArray;
/**
* Accessible text for the button. This should always be present if the button only
* contains an icon.
Expand Down Expand Up @@ -68,14 +56,11 @@ export interface IButtonAttrs extends ComponentAttrs {
*/
export default class Button<CustomAttrs extends IButtonAttrs = IButtonAttrs> extends Component<CustomAttrs> {
view(vnode: Mithril.VnodeDOM<CustomAttrs, this>) {
let { type, title, 'aria-label': ariaLabel, icon: iconName, disabled, loading, className, class: _class, ...attrs } = this.attrs;
let { type, 'aria-label': ariaLabel, icon: iconName, disabled, loading, className, class: _class, ...attrs } = this.attrs;

// If no `type` attr provided, set to "button"
type ||= 'button';

// Use `title` attribute as `aria-label` if none provided
ariaLabel ||= title;

// If given a translation object, extract the text.
if (typeof ariaLabel === 'object') {
ariaLabel = extractText(ariaLabel);
Expand Down
48 changes: 0 additions & 48 deletions framework/core/js/src/common/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export interface IInternalModalAttrs {
}

export interface IDismissibleOptions {
/**
* @deprecated Check specific individual attributes instead. Will be removed in Flarum 2.0.
*/
isDismissible: boolean;
viaCloseButton: boolean;
viaEscKey: boolean;
viaBackdropClick: boolean;
Expand All @@ -34,14 +30,6 @@ export default abstract class Modal<ModalAttrs extends IInternalModalAttrs = IIn
ModalAttrs,
CustomState
> {
// TODO: [Flarum 2.0] remove `isDismissible` static attribute
/**
* Determine whether or not the modal should be dismissible via an 'x' button.
*
* @deprecated Use the individual `isDismissibleVia...` attributes instead and remove references to this.
*/
static readonly isDismissible: boolean = true;

/**
* Can the model be dismissed with a close button (X)?
*
Expand All @@ -58,18 +46,7 @@ export default abstract class Modal<ModalAttrs extends IInternalModalAttrs = IIn
protected static readonly isDismissibleViaBackdropClick: boolean = true;

static get dismissibleOptions(): IDismissibleOptions {
// If someone sets this to `false`, provide the same behaviour as previous versions of Flarum.
if (!this.isDismissible) {
return {
isDismissible: false,
viaCloseButton: false,
viaEscKey: false,
viaBackdropClick: false,
};
}

return {
isDismissible: true,
viaCloseButton: this.isDismissibleViaCloseButton,
viaEscKey: this.isDismissibleViaEscKey,
viaBackdropClick: this.isDismissibleViaBackdropClick,
Expand All @@ -83,31 +60,6 @@ export default abstract class Modal<ModalAttrs extends IInternalModalAttrs = IIn
*/
alertAttrs: AlertAttrs | null = null;

oninit(vnode: Mithril.Vnode<ModalAttrs, this>) {
super.oninit(vnode);

// TODO: [Flarum 2.0] Remove the code below.
// This code prevents extensions which do not implement all abstract methods of this class from breaking
// the forum frontend. Without it, function calls would would error rather than returning `undefined.`

const missingMethods: string[] = [];

['className', 'title', 'content', 'onsubmit'].forEach((method) => {
if (!(this as any)[method]) {
(this as any)[method] = function (): void {};
missingMethods.push(method);
}
});

if (missingMethods.length > 0) {
fireDebugWarning(
`Modal \`${this.constructor.name}\` does not implement all abstract methods of the Modal super class. Missing methods: ${missingMethods.join(
', '
)}.`
);
}
}

oncreate(vnode: Mithril.VnodeDOM<ModalAttrs, this>) {
super.oncreate(vnode);

Expand Down
Loading

0 comments on commit e2281a2

Please sign in to comment.