<?php

namespace KupShop\MailerLiteBundle;

use KupShop\KupShopBundle\Util\Compat\ServiceContainer;

class MailerLiteUpgrade extends \UpgradeNew
{
    public function check_MailerLiteVersion()
    {
        $settings = \Settings::getDefault();
        if (isset($settings['mailerlite']) && !empty($settings['mailerlite']['api_key'])) {
            $cur_version = (empty($settings['mailerlite']['version']) ? 0 : $settings['mailerlite']['version']);
            if ($cur_version < MailerLite::VERSION) {
                return true;
            }
        }

        return false;
    }

    /** Upgrade MailerLite fields */
    public function upgrade_MailerLiteVersion()
    {
        $mailerlite = ServiceContainer::getService(MailerLite::class);
        $upgrade = $mailerlite->upgradeCustomFields();
        if (isset($mailerlite->upgrade_message)) {
            print_r($mailerlite->upgrade_message);
        }
        if ($upgrade) {
            $this->upgradeOK();
        }
    }
}
