heimrichhannot/contao-versions

轻松在 contao 中创建版本,防止实体被从 fromTable 名称中删除。也可在前端使用。

2.4.1 2023-10-24 12:03 UTC

This package is auto-updated.

Last update: 2024-09-24 14:02:17 UTC


README

此扩展包通过持久性表选项和帮助方法增强了 contao 版本实体。

特性

  • fromTable 名称添加到 huh_versions.persistent_tables 中,以便在 tl_version 永久或自定义时间范围内持久保存。
  • 使用 VersionModel 查找 tl_version 模型

注册持久性表

要使给定 fromTable 的实体持久,请将表名添加到项目配置中的 huh_versions.persistent_tables(典型 config/config.yml)。

# config/config.yml
huh_versions:
  persistent_tables:
    - tl_my_custom_entity
    - tl_keep_forever

创建新的版本条目

您可以使用 VersionControl 服务而不是直接使用版本类。

use Contao\FrontendUser;
use Contao\Versions;
use HeimrichHannot\VersionsBundle\Version\VersionControl;

class MyCustomEntity 
{
    /** @var VersionControl */
    private $versionControl;

    protected function createVersion(int $id, FrontendUser $member): void
    {
        // Simple call
        $this->versionControl->createVersion('tl_my_custom_entity', $id);
        
        // Pass additional options
        $this->versionControl->createVersion('tl_my_custom_entity', $id, [
            'hideUser' => false,
            'additionalData' => [
                'memberid' => $member->id,
                'memberusername' => $member->username,
                'username' => 'FrontendUser',
                'userid' => 0,
            ],
            'instance' => new Versions('tl_my_custom_entity', $id),
        ]);
    }
}

VersionControl::createVersion 选项

  • hideUser: (bool) 不将用户添加到版本日志条目。默认 false
  • additionalData: (array|null) 传递应在日志条目中存储的数据。数组键必须是现有数据库列名。默认 null
  • instance: (Version|null)传递一个自定义的 Versions 实例而不是默认实例。默认 null

配置参考

# Default configuration for extension with alias: "huh_versions"
huh_versions:

  # Set table names that should be persist within tl_versions.
  persistent_tables:

    # Examples:
    - tl_content
    - tl_my_custom_entity

  # Set the time period persistent table versions should be kept in version table. Set to 0 for forever.
  persistent_version_period: ~ # Example: 7776000