<?php

namespace Plugli\Linksy\SearchAndReplace\Helpers;

use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Migrations as StandardMigrations;
use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Option;

class Migrations
{
    public static function has_migrations() {
        return count((new StandardMigrations(LINKSYAI_SAR_PLUGIN_DIR . '/inc/migrations', Option::get(LINKSYAI_SAR_OPTION_DATABASE_VERSION, 0)))->get()) > 0;
    }

    public static function create_tables()
    {
        // handle database migrations
        $db_version = Option::get(LINKSYAI_SAR_OPTION_DATABASE_VERSION, 0);

        $migrations = new StandardMigrations(LINKSYAI_SAR_PLUGIN_DIR . '/inc/migrations', $db_version);

        if ($migrations->create()) {
            Option::set(LINKSYAI_SAR_OPTION_DATABASE_VERSION, $migrations->getCurrentVersion(), true);
        }
    }
}
