<?php
namespace Claromentis\Setup\Db;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] = (@$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] ?: array()) + array("_b21ec8d7fad482f6736bdae3a" . "4b12f9a" => base64_decode("bWlncmF0aW9u" . "cw=="), "d" . "b" => base64_decode("Z" . "G" . "I" . "="), "_a591754a8ddcdb" . "da9c80f1db4d911" . "e14" => base64_decode("aXNfbnVsb" . "A=="));
use Claromentis\Core\DAL\Db;
use Claromentis\Setup\Logger;
use Claromentis\Setup\SetupFacade;
use Claromentis\Setup\Util;
use Claromentis\Setup\Db\Migrations;
use Psr\Log\LoggerInterface;







class SchemaFacade
{
    
    
    
    
    protected $db;
    
    
    
    
    protected $schema;
    
    
    
    
    protected $rollup;
    
    
    
    
    protected $partial;
    
    
    
    
    
    
    protected $setup_facade;
    
    
    
    
    protected $logger;
    
    
    
    
    protected $persistence;
    
    
    
    
    
    
    
    
    
    public function __construct($db, $app_code, $_4825e032d19ebe3edee32a6a54c7afd2, $_d3a4df576cec8d467e29e06a95ac4009)
    {
        $this->db = $db;
        $this->logger = new Logger();
        $this->persistence = $_d3a4df576cec8d467e29e06a95ac4009;
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_a591754a8ddcd" . "bda9c80f1db4d9" . "11e14"]($this->persistence)) {
            $this->persistence = new Migrations\PersistenceDatabase($app_code, $this->db, $this->logger);
        }
        $_dc9ec269884b7d92cba431fcfbfe3904 = Util::GetAppInitPath($_4825e032d19ebe3edee32a6a54c7afd2);
        $this->schema = new Migrations\Schema($_dc9ec269884b7d92cba431fcfbfe3904, $this->persistence);
        $this->rollup = new Migrations\Rollup($_dc9ec269884b7d92cba431fcfbfe3904, $this->persistence);
        $this->partial = new Migrations\Partial($_dc9ec269884b7d92cba431fcfbfe3904, $this->persistence);
        $_54fa8523f2845872533bfb14523f79ed = array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_b21ec8d7fad482f673" . "6bdae3a4b12f9a"] => $this, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["d" . "b"] => $this->db);
        $this->schema->SetEnvironment($_54fa8523f2845872533bfb14523f79ed);
        $this->rollup->SetEnvironment($_54fa8523f2845872533bfb14523f79ed);
        $this->setup_facade = new SetupFacade($this->db);
        $this->setup_facade->setLogger($this->logger);
        $_54fa8523f2845872533bfb14523f79ed = array($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_b21ec8d7" . "fad482f67" . "36bdae3a4" . "b12f9a"] => $this->setup_facade, $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["d" . "b"] => $this->db);
        $this->partial->SetEnvironment($_54fa8523f2845872533bfb14523f79ed);
        $this->setLogger($this->logger);
    }
    
    
    
    
    
    
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
        $this->schema->setLogger($this->logger);
        $this->rollup->setLogger($this->logger);
        $this->partial->setLogger($this->logger);
        $this->setup_facade->setLogger($this->logger);
    }
    
    
    
    
    
    
    public function Install()
    {
        $this->db->DisableTokenCheck();
        try {
            $this->schema->Install();
            $this->rollup->Up();
            
            
            $this->partial->Up();
        } catch (\Exception $e) {
            $this->db->EnableTokenCheck();
            throw $e;
        }
        $this->db->EnableTokenCheck();
    }
    
    
    
    
    
    
    public function Update()
    {
        $this->db->DisableTokenCheck();
        try {
            $this->schema->Update();
            $this->rollup->Up();
            $this->partial->Up();
        } catch (\Exception $e) {
            $this->db->EnableTokenCheck();
            throw $e;
        }
        $this->db->EnableTokenCheck();
    }
    
    
    
    
    
    
    
    
    public function Run($file_name, $code)
    {
        $this->partial->Run($file_name, $code);
    }
    
    
    
    
    
    
    public function GetVersion()
    {
        return $this->persistence->GetVersion();
    }
    
    
    
    
    
    
    public function SetVersion($_c80a67ccfaf6579232efc354d30eb275)
    {
        $this->persistence->SetVersion($_c80a67ccfaf6579232efc354d30eb275);
    }
    
    
    
    
    
    
    
    
    
    
    public function CheckValid($_d5ebf376f635c188ec65813608e6ece5)
    {
    }
}