HEX
Server: Apache
System: Linux outside 5.4.8_Algonet_ZeroMAC_0.9.4.8 #6 SMP Mon Feb 3 20:36:07 CET 2020 x86_64
User: server (1002)
PHP: 8.3.20
Disabled: exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
Upload Files
File: /home/muoapartman/www/wp-content/plugins/getwid/includes/version-control.php
<?php

namespace Getwid;

class VersionControl {

    /** @var string */
    protected $pluginVersion = '';

    /** @var string */
    protected $dbVersion = '';

    /** @var bool */
    protected $needUpgrade = false;

    public function __construct(){

		$settings = getwid()->settings();

        $this->pluginVersion = $settings->getVersion();

        $this->checkVersion();
        $this->addActions();
    }

    protected function checkVersion()
    {
        $this->dbVersion = $this->getCurrentDatabaseVersion();

        if (version_compare($this->pluginVersion, $this->dbVersion, '>')) {
            $this->needUpgrade = true;
        }
    }

    protected function addActions()
    {
        if ($this->needUpgrade) {
            add_action('init', [$this, 'upgrade']);
        }
    }

    public function upgrade()
    {
        // Nothing to do at the moment
        $this->afterUpgrade();
    }

    protected function afterUpgrade()
    {
        $this->setCurrentDatabaseVersion($this->pluginVersion);

        if (version_compare($this->pluginVersion, $this->dbVersion, '!=')) {
            $this->addVersionToHistory($this->pluginVersion);
        }
    }

    protected function getCurrentDatabaseVersion()
    {
        return get_option('getwid_db_version', '0.0.0');
    }

    protected function setCurrentDatabaseVersion($version)
    {
        update_option('getwid_db_version', $version);
    }

    protected function addVersionToHistory($version)
    {
        $versionHistory = get_option('getwid_db_version_history', []);

        if (!in_array($version, $versionHistory)) {
            $versionHistory[] = $version;
            update_option('getwid_db_version_history', $versionHistory);
        }
    }
}