# tableberg/1.1.0/renderer/Migrations/TableBlockMigrator.php

Tableberg – Simple Gutenberg Table Block, version 1.1.0. 56 lines.

- Page: https://pluginprobe.com/plugins/tableberg/1.1.0/code/renderer/Migrations/TableBlockMigrator.php
- Raw: https://pluginprobe.com/plugins/tableberg/1.1.0/raw/renderer/Migrations/TableBlockMigrator.php
- Modified: 2026-05-18T04:58:48+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tableberg/1.1.0/code/renderer/Migrations/TableBlockMigrator.php#L10-L20`.

```php
<?php

namespace Tableberg\Renderer\Migrations;

class TableBlockMigrator {
    const CURRENT_VERSION = 3;

    public function migrate($attrs, $block = null) {
        if (!is_array($attrs)) {
            return $attrs;
        }

        $version = $this->get_version($attrs);
        if ($version >= self::CURRENT_VERSION) {
            return $attrs;
        }

        $migrators = $this->get_migrators();

        while ($version < self::CURRENT_VERSION) {
            if (!isset($migrators[$version])) {
                return $attrs;
            }

            $attrs = $migrators[$version]->migrate($attrs, $block);
            if (!is_array($attrs)) {
                return $attrs;
            }

            $version = $this->get_version($attrs);
        }

        return $attrs;
    }

    private function get_version($attrs) {
        if (
            !is_array($attrs) ||
            !isset($attrs['version']) ||
            !is_numeric($attrs['version'])
        ) {
            return 0;
        }

        return (int) $attrs['version'];
    }

    private function get_migrators() {
        return [
            0 => new TableBlockMigratorV0ToV1(),
            1 => new TableBlockMigratorV1ToV2(),
            2 => new TableBlockMigratorV2ToV3(),
        ];
    }
}

```
