<?php
namespace Claromentis\Setup\Task;

$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] ?: array()) + array("_76207386048" . "3e6c6934f569" . "8dfd40f63" => base64_decode("UnVubmluZyB1bm" . "luc3RhbGwgc2Ny" . "aXB0"), "_dcf86ccc31af7f6" . "3af36115aa12b1ee" . "7" => base64_decode("Y2hkaX" . "I="), "_8ee8ae7daeff23521c786b245baf11d" . "6" => base64_decode("Tm8gdW5pbnN0YWxsIHNjcmlwdCwgY2FsbGluZyBpbnN0YW" . "xsZXIgd2l0aCBzcGVjaWFsIGRhdGFiYXNlIGxheWVy"), "_d706c160e45bf7434fff82a5976f0" . "e19" => base64_decode("YXJyYX" . "lfa2V5" . "cw=="), "_9342063570b40df20" . "75204394b59df59" => base64_decode("Z2V0" . "Y3dk"), "_a8f3e68" . "b7b1cd9e" . "541fbc83" . "ec833aa9" . "1" => base64_decode("RHJvcHBpbmcgc2NoZ" . "W1h"), "_e608e5b5c4c3" . "4a67ba97ef84c" . "1e16199" => base64_decode("J" . "w" . "=" . "="), "_2d2a59c35e2175c18930e3" . "3b8d554771" => base64_decode("RHJvcHBpbmcgdGFib" . "GUgJw=="));
use Claromentis\Core\DAL\Db;
use Claromentis\Core\DAL\Schema\SchemaDb;
use Claromentis\Setup\Db\SchemaFacade;
use Claromentis\Setup\Logger;
use Psr\Log\LoggerAwareTrait;




class Uninstall
{
    use LoggerAwareTrait;
    
    
    
    
    protected $db;
    
    
    
    
    
    
    protected $application_path;
    
    
    
    
    
    
    
    public function __construct($db, $_4825e032d19ebe3edee32a6a54c7afd2)
    {
        $this->db = $db;
        $this->application_path = $_4825e032d19ebe3edee32a6a54c7afd2;
        $this->setLogger(new Logger());
    }
    
    
    
    
    
    
    
    public function Run($app_code)
    {
        $_3e91a953f0ae44bc853e303c034f9d93 = $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_9342063570b40df2" . "075204394b59df59"]();
        $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_dcf86ccc31af7f" . "63af36115aa12b1" . "ee7"]($this->application_path);
        $this->RunUninstallScript($app_code, $this->db);
        $this->DropSchema($app_code, $this->db);
        $_d3a4df576cec8d467e29e06a95ac4009 = new \Claromentis\Setup\Db\Migrations\PersistenceDatabase($app_code, $this->db, $this->logger);
        $_d3a4df576cec8d467e29e06a95ac4009->Delete();
        $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_dcf86ccc31af7f63af36115aa12b" . "1ee7"]($_3e91a953f0ae44bc853e303c034f9d93);
    }
    
    
    
    
    
    
    
    
    protected function RunUninstallScript($app_code, $_8bf9813aed9bb9b6d29793f34cc5e497)
    {
        $this->logger->info($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_7620738" . "60483e6c" . "6934f569" . "8dfd40f6" . "3"]);
        $_d983f9f1dd6ce3533fdb230ac31d42d2 = new \Claromentis\Setup\Script\Uninstall($this->application_path);
        $_0ab271f12643b1e576aa1bc6db54cb4e = new \Claromentis\Setup\Script\Init($this->application_path);
        if ($_d983f9f1dd6ce3533fdb230ac31d42d2->Exists()) {
            try {
                $_876ca2097b275e704d71e00d36b3e7c5 = new \Claromentis\Setup\SetupFacade($_8bf9813aed9bb9b6d29793f34cc5e497);
                $_876ca2097b275e704d71e00d36b3e7c5->setLogger($this->logger);
                $_d983f9f1dd6ce3533fdb230ac31d42d2->Run($_876ca2097b275e704d71e00d36b3e7c5);
            } catch (\Exception $e) {
                
                
                $this->logger->error($e->getMessage());
            }
        } elseif ($_0ab271f12643b1e576aa1bc6db54cb4e->Exists()) {
            
            
            $this->logger->warning($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8ee8ae7da" . "eff23521c7" . "86b245baf1" . "1d6"]);
            $_323d081d228922f95bfd6f3ca2f078ed = new \Claromentis\Core\DAL\Uninstall\UninstallDb($_8bf9813aed9bb9b6d29793f34cc5e497);
            try {
                $_876ca2097b275e704d71e00d36b3e7c5 = new \Claromentis\Setup\SetupFacade($_323d081d228922f95bfd6f3ca2f078ed);
                $_876ca2097b275e704d71e00d36b3e7c5->SetProperties(array());
                $_0ab271f12643b1e576aa1bc6db54cb4e->Run($_876ca2097b275e704d71e00d36b3e7c5);
            } catch (\Exception $e) {
                
                
                $this->logger->error($e->getMessage());
            }
        }
    }
    
    
    
    
    
    
    
    protected function DropSchema($app_code, $_8bf9813aed9bb9b6d29793f34cc5e497)
    {
        $this->logger->info($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_a8f3e68b7b1cd9e541fb" . "c83ec833aa91"]);
        $_58445071c7cb1e19afa575bbe9f7b6db = new SchemaDb();
        try {
            
            
            $_5fc096a041b2b6628d96b426cebad88d = new \Claromentis\Setup\Db\Migrations\PersistenceTransient($app_code, $this->logger);
            $_c4a29a8f844bd63614b8f4a72c3a10fd = new SchemaFacade($_58445071c7cb1e19afa575bbe9f7b6db, $app_code, $this->application_path, $_5fc096a041b2b6628d96b426cebad88d);
            $_c4a29a8f844bd63614b8f4a72c3a10fd->Install();
        } catch (\Exception $e) {
            $this->logger->error($e->getMessage());
        }
        
        
        $_ba4b312a27a90d0b0e30368938d4213b = $_58445071c7cb1e19afa575bbe9f7b6db->GetTables();
        
        
        foreach ($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_d706c160e45bf7434fff82a5976" . "f0e19"]($_ba4b312a27a90d0b0e30368938d4213b) as $_c81a475ecdc9121925813756400e25f9) {
            $this->logger->info($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_2d2a59c35e2175c18930e33b8d554" . "771"] . $_c81a475ecdc9121925813756400e25f9 . $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_e608e5b5c4c34a67ba97ef8" . "4c1e16199"]);
            $_8bf9813aed9bb9b6d29793f34cc5e497->DropTable($_c81a475ecdc9121925813756400e25f9);
        }
    }
}