flarum/gdpr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flarum/gdpr

Composer 安装命令:

composer require flarum/gdpr

包简介

Features for GDPR, PII management

README 文档

README

This extension allows users increasing control over their data.

Requirements

  • flarum/core - v2.0 or higher
  • PHP - 8.3 or higher

Installation or update

Install manually with composer:

composer require flarum/gdpr:^2.0.0

Use

All forum users now have a Personal Data section within their account settings page:

image

From here, users may self-service export their data from the forum, or start an erasure request. Erasure requests are queued up for admins/moderators to process. Any unprocessed requests that are still pending after 30 days will be processed automatically using the configured default method (Deletion or Anonymization).

Specifying which queue to use

If your forum runs multiple queues, ie low and high, you may specify which queue jobs for this extension are run on in your skeleton's extend.php file:

Flarum\Gdpr\Jobs\GdprJob::$onQueue = 'low';

return [
    ... your current extenders,
];

For developers

You can easily register a new Data type, remove an existing Data type, or exclude specific columns from the user table during export by leveraging the Flarum\Gdpr\Extend\UserData extender. Ensure that you wrap the GDPR extender in a conditional extend, so that forum owners can choose if they want to enable GDPR functionality or not. This functionality requires flarum/core v2.0 or higher, so that should be set as your extension's minimum requirement.

Registering a new Data Type:

Your data type class should implement the Flarum\Gdpr\Contracts\DataType:

<?php

use Flarum\Gdpr\Extend\UserData;
use Flarum\Extend;

return [
    (new Extend\Conditional())
        ->whenExtensionEnabled('flarum-gdpr', fn () => [
            (new UserData())
                ->addType(Your\Own\DataType::class),

            ... other conditional extenders as required ...
        ]),
];

The implementation you create needs a export method, it will receive a ZipArchive resource. You can use that to add any strings or actual files to the archive. Make sure to properly name the file and always prefix it with your extension slug (flarum-something-filename).

Removing a Data Type:

If for any reason you want to exclude a certain DataType from the export:

use Flarum\Gdpr\Extend\UserData;
use Flarum\Extend;

return [
    (new Extend\Conditional())
        ->whenExtensionEnabled('flarum-gdpr', fn () => [
            (new UserData())
                ->removeType(Your\Own\DataType::class),

            ... other conditional extenders as required ...
        ]),
];

Redacting specific user table columns from exports:

By default, the User data type exports all columns from the users table except id, password, groups, and anonymized. If your extension adds a column to the users table that should not appear in the export (e.g. a sensitive internal token), you can register it via removeUserColumns().

The column's value will be set to null on the in-memory user object before the export ZIP is generated — the column still appears in user.json but with a null value. This is visible in the admin GDPR overview under "User Table Data".

use Flarum\Gdpr\Extend\UserData;

return [
    (new Extend\Conditional())
        ->whenExtensionEnabled('flarum-gdpr', fn () => [
            (new UserData())
                ->removeUserColumns(['column1', 'column2']),

            ... other conditional extenders as required ...
        ]),
];

PII fields and anonymized contexts

What is an "anonymized context"?

Some extensions need to share Flarum data with external systems — for example, publishing events to a message broker, syncing to a search index, or sending webhooks. In these scenarios there are typically two audiences:

  • Full-data consumers — internal systems that are authorised to process PII (e.g. a private analytics pipeline).
  • Anonymized consumers — systems where PII must not appear (e.g. a public event stream, a third-party integration, or any consumer that doesn't need identifying information).

An "anonymized context" is any such output where PII keys must be redacted before the data leaves the application. For example, glowingblue/rabbit-dispatcher publishes Flarum events to RabbitMQ on two exchanges simultaneously: one with full payloads, and one with all PII keys replaced by [redacted]. The PII key list comes from flarum/gdpr so that every registered extension's sensitive fields are automatically covered.

The GDPR admin page ("User Table Data" section) shows which fields are currently registered as PII, giving admins visibility into what will be redacted.

Declaring PII fields on your data type

If your extension stores personally identifiable information, declare which keys are PII by overriding piiFields() on your data type class. This is the preferred approach — the declaration lives alongside your anonymize() logic, and the keys are automatically included in the PII registry as soon as your type is registered.

use Flarum\Gdpr\Data\Type;

class MyData extends Type
{
    public static function piiFields(): array
    {
        return ['custom_field', 'another_pii_field'];
    }

    // ... export(), anonymize(), delete() ...
}
Declaring PII fields without a data type

If your extension stores PII in a field that doesn't belong to any registered data type (e.g. a column on a model you don't export via GDPR), register the keys via the UserData extender instead:

use Flarum\Gdpr\Extend\UserData;

return [
    (new Extend\Conditional())
        ->whenExtensionEnabled('flarum-gdpr', fn () => [
            (new UserData())
                ->addPiiKeysForSerialization(['custom_field', 'another_pii_field']),
        ]),
];
Building an anonymized context (consuming the PII list)

If you are building an extension that serializes Flarum data for an external system and want to support PII redaction, resolve the PII key list from DataProcessor at runtime. Always check whether flarum-gdpr is enabled first and provide your own fallback for when it is not:

use Flarum\Extension\ExtensionManager;
use Flarum\Gdpr\DataProcessor;

$extensions = resolve(ExtensionManager::class);

if ($extensions->isEnabled('flarum-gdpr')) {
    $piiKeys = resolve(DataProcessor::class)->getPiiKeysForSerialization();
} else {
    // Fallback covering common fields — used when flarum/gdpr is not installed.
    $piiKeys = ['email', 'username', 'ip_address', 'last_ip_address'];
}

// Recursively redact PII from your serialized payload before sending externally.
$anonymizedPayload = redactKeys($payload, $piiKeys);

getPiiKeysForSerialization() aggregates fields declared by all registered data types (via piiFields()) plus any extras registered via addPiiKeysForSerialization(). This means every enabled extension that participates in the GDPR registry contributes its PII fields automatically — your consumer code doesn't need to know about them individually.

Flarum extensions

These are the known extensions which offer GDPR data integration with this extension. Don't see a required extension listed? Contact the author to request it

FAQ & Recommendations

  • Generating the zip archive can be pushed to queue functionality. This is exceptionally important on larger communities and with more extensions that work with the gdpr extension to allow data exports.

flarum/gdpr 适用场景与选型建议

flarum/gdpr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.7k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2024 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「export」 「flarum」 「gdpr」 「pii」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 flarum/gdpr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 flarum/gdpr 我们能提供哪些服务?
定制开发 / 二次开发

基于 flarum/gdpr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 31
  • 依赖项目数: 17
  • 推荐数: 2

GitHub 信息

  • Stars: 13
  • Watchers: 5
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-03