PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / renderer / Migrations / TableBlockMigrator.php

TableBlockMigrator.php in Tableberg – Simple Gutenberg Table Block 1.1.5, at renderer/Migrations/TableBlockMigrator.php

56 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Tableberg\Renderer\Migrations;
4
5 class TableBlockMigrator {
6 const CURRENT_VERSION = 3;
7
8 public function migrate($attrs, $block = null) {
9 if (!is_array($attrs)) {
10 return $attrs;
11 }
12
13 $version = $this->get_version($attrs);
14 if ($version >= self::CURRENT_VERSION) {
15 return $attrs;
16 }
17
18 $migrators = $this->get_migrators();
19
20 while ($version < self::CURRENT_VERSION) {
21 if (!isset($migrators[$version])) {
22 return $attrs;
23 }
24
25 $attrs = $migrators[$version]->migrate($attrs, $block);
26 if (!is_array($attrs)) {
27 return $attrs;
28 }
29
30 $version = $this->get_version($attrs);
31 }
32
33 return $attrs;
34 }
35
36 private function get_version($attrs) {
37 if (
38 !is_array($attrs) ||
39 !isset($attrs['version']) ||
40 !is_numeric($attrs['version'])
41 ) {
42 return 0;
43 }
44
45 return (int) $attrs['version'];
46 }
47
48 private function get_migrators() {
49 return [
50 0 => new TableBlockMigratorV0ToV1(),
51 1 => new TableBlockMigratorV1ToV2(),
52 2 => new TableBlockMigratorV2ToV3(),
53 ];
54 }
55 }
56