<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] ?: array()) + array("_9342063570b40df2075" . "204394b59df59" => base64_decode("Z2V0Y" . "3dk"), "_a591754a8d" . "dcdbda9c80f" . "1db4d911e14" => base64_decode("aXNfbnVsb" . "A=="), "_dcf86ccc31af7f63a" . "f36115aa12b1ee7" => base64_decode("Y2" . "hk" . "aX" . "I="));
use Claromentis\Core\DAL\Interfaces\SchemaInterface;
use Claromentis\Setup\Db\SchemaFacade;
use Claromentis\Setup\Logger;
use Claromentis\Setup\Db\Migrations;
use Claromentis\Setup\Script\Init;
use Claromentis\Setup\SetupFacade;
use Psr\Log\LoggerInterface;






class Install
{
    
    
    
    
    protected $db;
    
    
    
    
    protected $schema;
    
    
    
    
    protected $logger;
    
    
    
    
    protected $persistence;
    
    
    
    
    
    
    protected $application;
    
    
    
    
    
    
    protected $application_path;
    
    
    
    
    protected $properties;
    
    
    
    
    
    
    
    
    
    public function __construct($db, $_2d854c635c08f7a0d7b28391f0fb5bfd, $_4825e032d19ebe3edee32a6a54c7afd2, Migrations\Persistence $_d3a4df576cec8d467e29e06a95ac4009 = null)
    {
        $this->db = $db;
        $this->application = $_2d854c635c08f7a0d7b28391f0fb5bfd;
        $this->application_path = $_4825e032d19ebe3edee32a6a54c7afd2;
        $this->persistence = $_d3a4df576cec8d467e29e06a95ac4009;
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_a591754a8ddc" . "dbda9c80f1db4" . "d911e14"]($this->persistence)) {
            $this->persistence = new Migrations\PersistenceDatabase($_2d854c635c08f7a0d7b28391f0fb5bfd, $this->db);
        }
        $this->schema = new SchemaFacade($this->db, $_2d854c635c08f7a0d7b28391f0fb5bfd, $_4825e032d19ebe3edee32a6a54c7afd2, $_d3a4df576cec8d467e29e06a95ac4009);
        $this->setLogger(new Logger());
    }
    
    
    
    
    
    
    public function getApplicationCode()
    {
        return $this->application;
    }
    
    
    
    
    
    
    public function getApplicationPath()
    {
        return $this->application_path;
    }
    
    
    
    
    
    
    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
        $this->schema->setLogger($this->logger);
        $this->persistence->setLogger($this->logger);
    }
    
    
    
    
    
    
    public function setProperties(array $_809a58dc73011173c031a53c0b40ef0e)
    {
        $this->properties = $_809a58dc73011173c031a53c0b40ef0e;
    }
    
    
    
    
    
    
    public function InstallSchema()
    {
        
        
        $this->schema->Install();
    }
    
    
    
    
    
    
    protected function InitApplication()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_9342063570b40df2075204394" . "b59df59"]();
        $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_dcf86ccc31af7f63af361" . "15aa12b1ee7"]($this->getApplicationPath());
        $_45f9b20d836bf913104678193ccc4814 = new SetupFacade($this->db);
        $_45f9b20d836bf913104678193ccc4814->setLogger($this->logger);
        $_45f9b20d836bf913104678193ccc4814->SetProperties($this->properties);
        $_0ab271f12643b1e576aa1bc6db54cb4e = new Init($this->application_path);
        $_0ab271f12643b1e576aa1bc6db54cb4e->Run($_45f9b20d836bf913104678193ccc4814);
        $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_dcf86ccc31af7f63af" . "36115aa12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    public function Install()
    {
        
        
        $this->InstallSchema();
        
        
        $this->InitApplication();
    }
    
    
    
    
    
    
    public function Update()
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_9342063570b40df2075204394b59" . "df59"]();
        $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_dcf86ccc31af7f" . "63af36115aa12b1" . "ee7"]($this->getApplicationPath());
        
        
        $this->schema->Update();
        $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_dcf86ccc31af7f63af36115a" . "a12b1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    protected function SchemaIsCreated()
    {
        return $this->persistence->GetVersion() !== null;
    }
}