trendyminds/craft-reporter

一键导出Craft数据为CSV文件

安装次数: 1,824

依赖: 0

建议: 0

安全性: 0

星标: 5

关注者: 5

分支: 3

开放问题: 1

类型:craft-plugin

2.3.0 2024-04-10 14:40 UTC

This package is auto-updated.

Last update: 2024-09-10 15:33:59 UTC


README

📊 一键导出Craft数据为CSV文件!

An example of the reports screen before a user has initiated an export

⚡️ 功能

  • 🏎 报告通过查询批量处理进行处理,使导出运行快速且不会耗尽您的内存限制
  • 🧘 受Element API启发,以简单熟悉的结构创建报告
  • 📦 报告使用资产卷存储,您可以在本地或Amazon S3等基于云的服务上托管报告
  • 🖥 使用php craft reporter/report --handle=myReport通过CLI处理报告,其中myReport是位于config/reporter.php中的reports数组中特定报告的键。

📦 安装

以两种方式之一安装Reporter

🔌 设置

要设置报告,在config/中创建一个reporter.php文件。下面是一个示例配置文件。

示例配置

<?php

use craft\elements\Entry;
use craft\elements\Asset;

return [
    // The name to use throughout the control panel (defaults to "Reporter")
    'displayName' => 'Reports',

    // The asset volume handle where your reports should be saved
    // NOTE: Your reports are publicly accessible if your volume has "Assets in this volume have public URLs" enabled
    'volume' => 'uploads',

    // An optional folder path if you would like to nest the reports in a specific directory
    'folder' => 'resources/reports',

    // An optional batch size to use when processing reports (defaults to 100)
    'batchSize' => 100,

    // An array of reports to produce
    'reports' => [
        'pages' => function () {
            return [
                'name' => 'All Pages',
                'description' => 'A simple export of all the pages on the site.',
                'elementType' => Entry::class,
                'criteria' => [
                    'section' => 'pages'
                ],
                'transformer' => function (Entry $entry) {
                    return [
                        "id" => $entry->id,
                        "title" => $entry->title,
                        "url" => $entry->url,
                    ];
                }
            ];
        },

        'allImages' => function () {
            return [
                'name' => 'Uploaded Images',
                'description' => 'A list of all images uploaded into Craft',
                'elementType' => Asset::class,
                'criteria' => [
                    'kind' => 'image'
                ],
                'transformer' => function (Asset $asset) {
                    // Skip example
                    // Ignore assets that have an even number for an ID
                    if ($asset->id % 2 === 0) {
                        return [];
                    }

                    return [
                        "id" => $asset->id,
                        "title" => $asset->title,
                        "filename" => $asset->filename,
                    ];
                }
            ];
        },
    ]
];

The exports screen that is displayed when you have not exported any reports yet.

🤝 贡献

如果您想为Reporter做出贡献,我们尽量让它变得尽可能简单

  1. 克隆仓库
  2. 运行npm i以安装Node依赖
  3. 运行npm start以开始监视任务
  4. 做出您的更改
  5. 运行npm run build以编译和压缩CSS和JS
  6. 提交PR!