定制 cambis/silverstripe-pruner 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cambis/silverstripe-pruner

最新稳定版本:v0.5.0

Composer 安装命令:

composer require cambis/silverstripe-pruner

包简介

A simple developer utility to clear database tables.

关键字:

README 文档

README

A simple developer utility to clear database tables. This module provides a configurable task that truncates database tables inside of a transaction.

Prerequisites 🦺

php ^7.4 || ^8.0
silverstripe/framework ^4.0 || ^5.0

Installation 👷‍♀️

Install via composer.

composer require --dev cambis/silverstripe-pruner

Configuration 🚧

Create a configuration file.

---
Name: app_pruner
---
Cambis\SilverstripePruner\Task\PruneSelectedORMTablesTask:
  # List the fqn names of the DataObjects you want to truncate
  truncated_classes:
    - My\Record\To\Truncate
  # Any extra tables such as those from silverstripe/versioned etc.
  truncated_tables:
    - Truncate_Live
    - Truncate_Versions
  # Defaults to false, add this line if you want to run the task in a production environment
  can_run_in_production: true

You can also dynamically update the truncated tables using an extension hook. This library provides traits to with the hook method definitions.

<?php

namespace App\Extension;

use Cambis\SilverstripePruner\Concern\UpdateTruncatedClasses;
use Cambis\SilverstripePruner\Concern\UpdateTruncatedTables;
use Cambis\SilverstripePruner\Task\PruneSelectedORMTablesTask;
use SilverStripe\Core\Extension;

/**
 * @extends Extension<PruneSelectedORMTablesTask>
 */
final class MyPrunerExtension extends Extension
{
    use UpdateTruncatedClasses;
    use UpdateTruncatedTables;

    protected function updateTruncatedClasses(array &$truncatedClasses): void
    {
        $truncatedClasses[] = \My\Record\To\Truncate::class;
    }

    protected function updateTruncatedTables(array &$truncatedTables): void
    {
        $truncatedTables[] = 'Truncate_Live';
        $truncatedTables[] = 'Truncate_Versions';
    }
}

Usage 🏃🏃🏃

vendor/bin/sake dev/tasks/prune-selected-orm-tables confirm=1

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-13