PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
← All changes | includes/version-control.php +76 -76 2.0.103.0.2 View file →
@@ -1,76 +1,76 @@
1 -<?php
2 -
3 -namespace Getwid;
4 -
5 -class VersionControl {
6 -
7 - /** @var string */
8 - protected $pluginVersion = '';
9 -
10 - /** @var string */
11 - protected $dbVersion = '';
12 -
13 - /** @var bool */
14 - protected $needUpgrade = false;
15 -
16 - public function __construct(){
17 -
18 - $settings = getwid()->settings();
19 -
20 - $this->pluginVersion = $settings->getVersion();
21 -
22 - $this->checkVersion();
23 - $this->addActions();
24 - }
25 -
26 - protected function checkVersion()
27 - {
28 - $this->dbVersion = $this->getCurrentDatabaseVersion();
29 -
30 - if (version_compare($this->pluginVersion, $this->dbVersion, '>')) {
31 - $this->needUpgrade = true;
32 - }
33 - }
34 -
35 - protected function addActions()
36 - {
37 - if ($this->needUpgrade) {
38 - add_action('init', [$this, 'upgrade']);
39 - }
40 - }
41 -
42 - public function upgrade()
43 - {
44 - // Nothing to do at the moment
45 - $this->afterUpgrade();
46 - }
47 -
48 - protected function afterUpgrade()
49 - {
50 - $this->setCurrentDatabaseVersion($this->pluginVersion);
51 -
52 - if (version_compare($this->pluginVersion, $this->dbVersion, '!=')) {
53 - $this->addVersionToHistory($this->pluginVersion);
54 - }
55 - }
56 -
57 - protected function getCurrentDatabaseVersion()
58 - {
59 - return get_option('getwid_db_version', '0.0.0');
60 - }
61 -
62 - protected function setCurrentDatabaseVersion($version)
63 - {
64 - update_option('getwid_db_version', $version);
65 - }
66 -
67 - protected function addVersionToHistory($version)
68 - {
69 - $versionHistory = get_option('getwid_db_version_history', []);
70 -
71 - if (!in_array($version, $versionHistory)) {
72 - $versionHistory[] = $version;
73 - update_option('getwid_db_version_history', $versionHistory);
74 - }
75 - }
76 -}
1 +<?php
2 +
3 +namespace Getwid;
4 +
5 +class VersionControl {
6 +
7 + /** @var string */
8 + protected $pluginVersion = '';
9 +
10 + /** @var string */
11 + protected $dbVersion = '';
12 +
13 + /** @var bool */
14 + protected $needUpgrade = false;
15 +
16 + public function __construct(){
17 +
18 + $settings = getwid()->settings();
19 +
20 + $this->pluginVersion = $settings->getVersion();
21 +
22 + $this->checkVersion();
23 + $this->addActions();
24 + }
25 +
26 + protected function checkVersion()
27 + {
28 + $this->dbVersion = $this->getCurrentDatabaseVersion();
29 +
30 + if (version_compare($this->pluginVersion, $this->dbVersion, '>')) {
31 + $this->needUpgrade = true;
32 + }
33 + }
34 +
35 + protected function addActions()
36 + {
37 + if ($this->needUpgrade) {
38 + add_action('init', [$this, 'upgrade']);
39 + }
40 + }
41 +
42 + public function upgrade()
43 + {
44 + // Nothing to do at the moment
45 + $this->afterUpgrade();
46 + }
47 +
48 + protected function afterUpgrade()
49 + {
50 + $this->setCurrentDatabaseVersion($this->pluginVersion);
51 +
52 + if (version_compare($this->pluginVersion, $this->dbVersion, '!=')) {
53 + $this->addVersionToHistory($this->pluginVersion);
54 + }
55 + }
56 +
57 + protected function getCurrentDatabaseVersion()
58 + {
59 + return get_option('getwid_db_version', '0.0.0');
60 + }
61 +
62 + protected function setCurrentDatabaseVersion($version)
63 + {
64 + update_option('getwid_db_version', $version);
65 + }
66 +
67 + protected function addVersionToHistory($version)
68 + {
69 + $versionHistory = get_option('getwid_db_version_history', []);
70 +
71 + if (!in_array($version, $versionHistory)) {
72 + $versionHistory[] = $version;
73 + update_option('getwid_db_version_history', $versionHistory);
74 + }
75 + }
76 +}