Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: handle deprecations from 1.x #3909

Merged
merged 27 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9fcc7a3
chore: drop deprecated `post_number_index` column
SychO9 Oct 23, 2023
44db4ab
chore: remove deprecated `FlagsWillBeDeleted` event
SychO9 Oct 23, 2023
0cb68ce
chore: `Migration::addSettings` can still be needed
SychO9 Oct 23, 2023
162f834
chore: `settings->get` default can still be needed
SychO9 Oct 23, 2023
0adb993
chore: deprecated `$default` in `Settings::serializeToForum` extender
SychO9 Oct 23, 2023
947e641
chore: deprecated request `actor` attribute
SychO9 Oct 23, 2023
969638b
chore: already handled
SychO9 Oct 23, 2023
af2e0c1
chore: remove `RecompileFrontendAssets::whenSettingsSaved`
SychO9 Oct 25, 2023
32e0c67
chore: remove `getReadIds`
SychO9 Oct 25, 2023
48b93cd
chore: `Model::dateAttribute` extender
SychO9 Oct 25, 2023
b838d7c
chore: `evented` js util
SychO9 Oct 25, 2023
ee7c497
chore: `WelcomeHero` js hidden prop
SychO9 Oct 25, 2023
61274d8
chore: attributes pushData with relations
SychO9 Oct 25, 2023
c29aef5
chore: app request options `extract`
SychO9 Oct 25, 2023
d5e5604
chore: itemlist deprecations
SychO9 Oct 25, 2023
f1137b5
chore: `search` state
SychO9 Oct 25, 2023
82fd835
chore: `getMentionText`
SychO9 Oct 25, 2023
baa9d3b
chore: deprecated non-registered store type
SychO9 Oct 25, 2023
bfa02d9
chore: `Button` title
SychO9 Oct 25, 2023
72dd319
chore: `Modal` deprecations
SychO9 Oct 25, 2023
463003a
chore
SychO9 Oct 25, 2023
9d222bd
chore: deprecated `less` mixins
SychO9 Oct 25, 2023
4859c52
Apply fixes from StyleCI
StyleCIBot Oct 25, 2023
fd358ef
fix
SychO9 Oct 25, 2023
15abc0b
fix: phpstan
SychO9 Oct 25, 2023
6ec0d91
fix
SychO9 Oct 25, 2023
ce8a87a
fix
SychO9 Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading