Skillpedia
واجهات API والخوادم (backend)8.1k · #12584

webiny-cms-bulk-actions

ما الذي تفعله

ترشد هذه المهارة ذكاءك عند إضافة إجراء جماعي إلى قائمة محتوى CMS في Webiny، مثل تطبيق خصم على إدخالات كثيرة. وهي لمطورين يحتاجون إلى تغيير إدخالات كثيرة دفعة واحدة.

متى تستخدمها

  • ✓عندما تريد زرًا في قائمة إدخالات CMS يغيّر إدخالات كثيرة دفعة واحدة.
  • ✓عندما يجب أن يعمل التغيير الجماعي كمهمة خلفية عبر مجموعات كبيرة من الإدخالات.
  • ✓عندما تحتاج الإجراءات الجماعية إلى تصفية الإدخالات حسب حقل مخصص.

رابط المهارة

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/cms-bulk-actions/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/cms-bulk-actions/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أضف إجراءً جماعيًا إلى قائمة المنتجات يطبّق خصمًا على كل الإدخالات المحددة.”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تشرح المهارة صنف إجراء جماعي بخطوتين: الأولى تحدد الإدخالات التي تُحمَّل، والثانية تغيّر كل إدخال. ثم ينشئ Webiny مهام الخلفية وmutation تلقائيًا، ويشغّلها زر في الإدارة.

المحتوى التقني (ملف SKILL.md الأصلي)

النص الأصلي من المؤلف، مباشرة من GitHub.

Custom Headless CMS bulk actions

TL;DR

A bulk action is a class implementing EntriesBulkAction.Interface with two methods — loadData (which entries) and processData (what to do to each). Register it with export default EntriesBulkAction.createImplementation({...}) via <Api.Extension src>. For every registered bulk action, Webiny automatically generates a list background task, a process background task, and a GraphQL mutation. On the Admin side, add a ContentEntryListConfig.Browser.BulkAction button that calls BulkActionFeature's useCase.execute({ model, action, where, data }).

Available from Webiny 6.5.0 (webiny/api/cms/entry).

Backend — the bulk action

// extensions/myBulkAction/api/MyBulkAction.ts
import {
  EntriesBulkAction,
  ListLatestEntriesUseCase,
  UpdateEntryUseCase
} from "webiny/api/cms/entry";

class MyBulkActionImpl implements EntriesBulkAction.Interface {
  // PascalCased into the task ids + GraphQL enum value, so "applyDiscount" →
  // tasks hcmsBulk(List|Process)ApplyDiscountEntries and frontend action "ApplyDiscount".
  readonly name = "applyDiscount";
  // Optional: restrict which models get the mutation/button.
  readonly modelIds = ["product"];
  // Optional: entries processed per batch (defaults to the configured batchSize).
  // readonly batchSize = 50;

  constructor(
    private listEntries: ListLatestEntriesUseCase.Interface,
    private updateEntry: UpdateEntryUseCase.Interface
  ) {}

  // Runs in the "list" task, with pagination (params.where/search/after/limit).
  async loadData(model, params) {
    const result = await this.listEntries.execute(model, params);
    return result.value; // { entries, meta }
  }

  // Runs in the "process" task, once per entry, in batches.
  async processData(model, params) {
    // params.id is a revision id ("<entryId>#0001"); params.data carries whatever the
    // Admin action sent.
    // ...update / transform the entry here...
  }
}

export default EntriesBulkAction.createImplementation({
  implementation: MyBulkActionImpl,
  dependencies: [ListLatestEntriesUseCase, UpdateEntryUseCase]
});

loadData/processData are the background-task body. You never write scheduling, batching, retry, or timeout-resume code — the tasks system provides all of it. Webiny generates hcmsBulkList<Name>Entries, hcmsBulkProcess<Name>Entries, and the mutation bulkAction<SingularApiName>(action: <Name>, ...).

Convergence — the #1 gotcha

The engine calls loadData repeatedly until it returns zero entries — after each processing round it re-lists to check for more work. If loadData keeps returning the same entries, the task never converges: it re-processes them until it hits maxIterations and fails. So the filter MUST exclude already-processed entries.

  • State-transition actions converge naturally: Publish filters status_not: "published" and processData publishes; the next list is smaller. Built-in actions rely on this.
  • Actions with no natural "done" state need a marker:
    • A boolean flag: loadData excludes flag = true; processData sets it. Simple, but blocks re-running until you reset the flag.
    • A per-run token (re-runnable): the Admin action generates a fresh runId per click and filters "not stamped with this run"; processData stamps the entry with runId. The run converges once everything is stamped, but the next click uses a new token, so the same entries are eligible again — no manual reset.

Where filters — two layers, two formats

The bulk-action list path talks to storage directly, bypassing the GraphQL where-transform. Mind the difference:

  • GraphQL where (what the Admin action sends, typed as <Model>ListWhereInput): system fields are top-level (id_in, status_not, savedOn_lt, …); custom fields are nested under values — where: { values: { onSale_not: true } }. A dotted key like "values.onSale_not" is rejected by the typed input.
  • Storage where (what loadData passes to the list use case): custom fields are flat dotted — { "values.onSale_not": true }; system fields stay top-level. A bare onSale_not throws There is no field with the fieldId "onSale".

So if the Admin action sends a custom-field filter, flatten it in loadData:

async loadData(model, params) {
    const where = { ...params.where };
    if (where.values && typeof where.values === "object") {
       
الأسئلة الشائعة

أي إصدار من Webiny مطلوب؟

تذكر المهارة أن الإجراءات الجماعية متاحة من الإصدار 6.5.0 من Webiny.

من يحدد الإدخالات التي تتغير؟

خطوة loadData تحدد الإدخالات، وخطوة processData تغيّر كل واحد منها.

هل تغطي زر الإدارة؟

نعم. تشرح المهارة زر الإدارة الذي يستدعي الإجراء الجماعي.

التفاصيل

الوصف الأصلي من المؤلف

Authoring a custom Headless CMS bulk action (EntriesBulkAction) that Webiny runs as a background task, plus the Admin-side button that triggers it. Use this skill when the developer wants to add a bulk action to the content-entry list (e.g. apply a discount, generate content, bulk-transform entries), understand loadData/processData, make the task converge, filter by custom fields, or trigger the action from the Admin UI. Requires Webiny 6.5.0 or newer.

repo: webiny/webiny-js

الشعبية

نجوم GitHub
8.1k
الترتيب
#12584
الترخيص
—
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة