<?php
namespace Claromentis\Search\Indexing;

$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] ?: array()) + array("_1eb15c2708413546176f34847fda8" . "e91" => base64_decode("U0VMRUNUIHBwLmlkIEZST00gcHViX3BhZ2UgcHAsIG1ldGFkYXRhX3NpbXBsZSBtcyBXSEVSRSBwcC5wcmltYXJ5X3BhZ2VfaWQ9cHAuaWQgQU5EIHBwLmFwcHJvdmVkIT0wIEFORCBwcC5pc19zeXN0ZW09MCBBTkQgc" . "HAuZGVsZXRlZD0wIEFORCAobXMuaW50dmFsIElTIE5VTEwgT1IgbXMuaW50dmFsPTAp"), "_c3fcadb0a258249417981bad11120b1" . "8" => base64_decode("bWUuaWQ9bWw" . "uZWxlbWVudF" . "9pZA=="), "_86568fb689c83820" . "79a26e53d7d05483" => base64_decode("ZGlzYWJsZV9pbmRleG" . "luZw=="), "_0a2f7f3" . "09aa28a8" . "5c093a9f" . "627a5919" . "6" => base64_decode("U0VMRUNUIGlkIEZST00gaGRfaXNzdWUgT1JERVIgQlkgb" . "GFzdF9tb2RpZmllZCBERVND"), "_8f594f00" . "8d2964b21" . "fa653a640" . "f3aa3a" => base64_decode("IEFORCBtbC5uYW1" . "lPXN0cjptZF9uYW" . "1l"), "_5368c2db7ec701e3b2b625000d9265b" . "c" => base64_decode("ZnA" . "="), "_1067685f4970f361dd5833949fc653" . "44" => base64_decode("U0VMRUNUIGQuZG9jX2lkIEZST00gRVJNU19kYXRhIGQsIEVSTVNfbWV0YWRhdGFfbGluayBtbCwgRVJNU19tZXRhZGF0YV9lbGVtZW50IG1lCiAJCQkJCQlXSEVSRSBkLmRlbGV0ZWQ9MCBBTkQgZC5wcmltYXJ5X3ZlcnNpb25faWQ9ZC5pZCBBTkQgKG1lLmludHZhbCBJUyBOV" . "UxMIE9SIG1lLmludHZhbD0wKSBPUkRFUiBCWSBkLmRhdGVfbGFzdF9tb2RpZmllZCBERVND"), "_65aeb17367d25e2f2" . "a697713b93415df" => base64_decode("cHAuaWQ9bXMub2JqZWN0X2lkIEFORCBtcy5hZ2dyZWdhdGlvbj1pbnQ6YWdn" . "X25hbWUgQU5EIG1zLm5hbWU9c3RyOm1ldGFfbmFtZQ=="), "_dd63e9d94ef9f220789ba00287ea881" . "a" => base64_decode("cHA" . "="), "_71e40c4de583d88f939e800151a" . "5bfba" => base64_decode("bW" . "U="), "_5da9a50a900adfa6" . "21d32aaddfecaf7c" => base64_decode("bWR" . "fbm" . "FtZ" . "Q=="), "_df109699" . "b1862763e" . "af2877b85" . "3cc824" => base64_decode("b" . "W" . "w" . "="), "_248529a34d7b8949798ae2ec19" . "ebbaae" => base64_decode("REVMRVRFIEZST00gaW5kZXhpbmdfcXVldWUgV0hFU" . "kUgb2JqZWN0X3R5cGU9c3RyOnR5cGU="), "_c69801a79aed7acdfd8" . "161757e4a3e64" => base64_decode("RG9uJ3Qga25vdyBob3cgdG8gZnVs" . "bHkgcmVpbmRleCBvYmplY3QgdHlw" . "ZSAn"), "_07af7964f51512e67eca70b67f" . "086fce" => base64_decode("Z" . "A" . "=" . "="), "_e608e5b5c4c34" . "a67ba97ef84c1e" . "16199" => base64_decode("Jw=" . "="), "_ad69870f7e4c5f" . "f31b6defc8250a4" . "3e8" => base64_decode("bWwub2JqZWN0X2lkPWQuaWQgQU5EIG1sLmFnZ3Jl" . "Z2F0aW9uPQ=="), "_c23f205df8e5a3d5fb8d6ac6" . "7c437548" => base64_decode("REVMRVRFIEZST00gaW5k" . "ZXhpbmdfcXVldWU="), "_f3f051945df83b7" . "dd5c5771e1bd72eb" . "6" => base64_decode("bWV0YV9" . "uYW1l"), "_9cc6bcc5a89e584f50b4" . "6d91950d836e" => base64_decode("U0VMRUNUIGlkIEZST00g" . "Zm9ydW1fbWVzc2FnZXM="), "_c0dcfe7e28c8482dd75a949a96d5" . "1443" => base64_decode("U0VMRUNUIGlkIEZST00gbmV3cyBXSEVSRSBpc19kcmFmdD" . "0wIEFORCBkZWxldGVkPTAgQU5EIGhlYWRsaW5lPTEgQU5E" . "IHN0YXR1cz0w"), "_a37bd5892319e21" . "3b1beed3bc908a7f" . "9" => base64_decode("YWdnX25hbWU" . "="), "_a58276b2503abd83773d" . "d92c0646d1d0" => base64_decode("UXVldWVGdWx" . "sUmVpbmRleA" . "=="), "_e3ca87fba30" . "fbb75d2d710e" . "07b007808" => base64_decode("cHViX2lzX2luY" . "2x1ZGU="), "_deee962df29bd56bb43e52befa" . "b4d2fb" => base64_decode("IEFORCBuYW1lPXN0cjpt" . "ZF9uYW1l"), "_6edacb78bd55c501" . "5af27c8ac1fcd9af" => base64_decode("bWV0a" . "G9kX2" . "V4aXN" . "0cw=="), "_112f38e7ed" . "d04ccddd9ec" . "d52f2e5bf76" => base64_decode("bWwub2JqZWN0X2lkPWZwLmlkIEFORCBtbC5hZ2dyZWdhd" . "Glvbj0="), "_c2015ddf441ea711" . "f2e2280c7639e382" => base64_decode("U0VMRUNUIGZwLmlkIEZST00gRVJNU19maWxlX3BsYW4gZnAsIEVSTVNfbWV0YWRhdGFfbGluayBtbCwgRVJNU19tZXRhZGF0YV9lbGVtZW50IG1lIFdIR" . "VJFIGZwLmRlbGV0ZWQ9MCBBTkQgKG1lLmludHZhbCBJUyBOVUxMIE9SIG1lLmludHZhbD0wKSBPUkRFUiBCWSBmcC5kYXRlX2xhc3RfbW9kaWZpZWQgRE" . "VTQw=="), "_7e09d700055e6ea9" . "cc6a3e34b08e57be" => base64_decode("bXM" . "="));
use Claromentis\Core\DAL;
use Claromentis\Search\History\Storage as HistoryStorage;
use Claromentis\Search\Indexing\Client\ClientInterface;
use Claromentis\Search\ItemTypeFactory;
use Claromentis\Search\ItemType\Indexing as ITI;
use Exception;
use InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;






class Reindexer implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    
    
    
    protected $database;
    
    
    
    
    protected $type_factory;
    
    
    
    
    protected $indexer;
    
    
    
    
    
    
    
    
    public function __construct(DAL\Db $database, ItemTypeFactory $_a5f0855ed10d21630ebaa8a6df885fec, ClientInterface $_1a77ff0b6c84529b387f144949169560)
    {
        $this->database = $database;
        $this->type_factory = $_a5f0855ed10d21630ebaa8a6df885fec;
        $this->indexer = $_1a77ff0b6c84529b387f144949169560;
    }
    
    
    
    
    
    
    public function ClearQueue(string $type = '')
    {
        $this->database->unsafe_query = true;
        if (!$type) {
            $this->database->query($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_c23f205df8e5a3d5fb8" . "d6ac67c437548"]);
        } else {
            $this->database->query($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_248529a34d7b8949798ae2ec19ebba" . "ae"], $type);
        }
    }
    
    
    
    
    
    
    
    
    
    public function ClearAllIndexes()
    {
        
        
        $this->ClearQueue();
        
        
        $this->indexer->CreateIndex();
        
        
        $_9566fc21bc9c4f8570bbf68597ebd873 = new HistoryStorage();
        $_9566fc21bc9c4f8570bbf68597ebd873->InitMapping($this->indexer);
    }
    
    
    
    
    
    
    public function RemapAllTypes()
    {
        $_17728688d370dbb69c53d9e641c4b0e0 = $this->type_factory->GetAllIndexingTypes();
        foreach ($_17728688d370dbb69c53d9e641c4b0e0 as $type) {
            $this->RemapType($type);
        }
    }
    
    
    
    
    
    public function RemapType(string $type)
    {
        $_a9319060e0ed7dc98a35ea66191cba44 = $this->type_factory->GetIndexingObject($type);
        $_a9319060e0ed7dc98a35ea66191cba44->InitMapping($this->indexer);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function Reindex($type, $reindex = false)
    {
        $_f53d35a1a1e233d98d9ce73d92ab3bb1 = 0;
        switch ($type) {
            case ITI\Document::TYPE_NAME:
                $query = new DAL\Query($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_1067685f4970f361dd5833949fc" . "65344"]);
                $query->addJoinCondition($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_07af7964f51512e67eca" . "70b67f086fce"], $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_df109699b1862763eaf2877b85" . "3cc824"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_ad69870f7e4c5ff31b6de" . "fc8250a43e8"] . AGGREGATION_DATA . $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_8f594f008d2964b21fa653a640" . "f3aa3a"]);
                $query->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_df109699b1862763ea" . "f2877b853cc824"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_71e40c4de583d88f939e800151a5bf" . "ba"], $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_c3fcadb0a258" . "249417981bad1" . "1120b18"]);
                $query->Bind($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_5da9a50a90" . "0adfa621d32" . "aaddfecaf7c"], $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_86568fb689c8382079a26" . "e53d7d05483"]);
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($query);
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $_55d3c75af03093e4e61a38a65c80ff45 = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $_55d3c75af03093e4e61a38a65c80ff45);
                    } else {
                        IndexingQueue::Index($type, $_55d3c75af03093e4e61a38a65c80ff45);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            case ITI\Folder::TYPE_NAME:
                $query = new DAL\Query($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c2015ddf441ea711f2e2280" . "c7639e382"]);
                $query->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_5368c2db7ec701" . "e3b2b625000d926" . "5bc"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_df109699b1862763eaf" . "2877b853cc824"], $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_112f38e7e" . "dd04ccddd9" . "ecd52f2e5b" . "f76"] . AGGREGATION_FOLDER . $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_deee962df29bd56bb43e52befa" . "b4d2fb"]);
                $query->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_df109699b1" . "862763eaf28" . "77b853cc824"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_71e40c4de583d88f939e800151a5" . "bfba"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_c3fcadb0a2582494" . "17981bad11120b18"]);
                $query->Bind($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_5da9a50a" . "900adfa62" . "1d32aaddf" . "ecaf7c"], $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_86568fb68" . "9c8382079a" . "26e53d7d05" . "483"]);
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($query);
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $id = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $id);
                    } else {
                        IndexingQueue::Index($type, $id);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            case ITI\PublishPage::TYPE_NAME:
                $query = new DAL\Query($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_1eb15c2708413546176f34847fd" . "a8e91"]);
                $query->addJoinCondition($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_dd63e9d94ef9f22" . "0789ba00287ea881" . "a"], $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_7e09d700055e6ea9cc6a3" . "e34b08e57be"], $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_65aeb17367d25e2f2" . "a697713b93415df"]);
                $query->Bind($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_a37bd5892319e213b1beed3bc908a7" . "f9"], AGGREGATION_PUB_PAGE);
                $query->Bind($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_f3f051945df83b7dd5c5771e1b" . "d72eb6"], $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_e3ca87fba30fbb75d2d710e" . "07b007808"]);
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($query);
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $id = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $id);
                    } else {
                        IndexingQueue::Index($type, $id);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            case ITI\ICIssue::TYPE_NAME:
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_0a2f7f309" . "aa28a85c09" . "3a9f627a59" . "196"]);
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $id = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $id);
                    } else {
                        IndexingQueue::Index($type, $id);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            case ITI\ForumMessage::TYPE_NAME:
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_9cc6bcc5a89e5" . "84f50b46d91950" . "d836e"]);
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $id = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $id);
                    } else {
                        IndexingQueue::Index($type, $id);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            case ITI\News::TYPE_NAME:
                $_189840d11056515e52402d1412a0b6e4 = $this->database->query($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_c0dcfe7e28c848" . "2dd75a949a96d51" . "443"]);
                
                
                while ($row = $_189840d11056515e52402d1412a0b6e4->fetchRow()) {
                    $id = $row[0];
                    if ($reindex) {
                        IndexingQueue::Reindex($type, $id);
                    } else {
                        IndexingQueue::Index($type, $id);
                    }
                    ++$_f53d35a1a1e233d98d9ce73d92ab3bb1;
                }
                break;
            default:
                $_ed977237a701e8cafc0e971b54b0217d = $this->type_factory->GetIndexingObject($type);
                if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_6edacb78bd5" . "5c5015af27c8" . "ac1fcd9af"]($_ed977237a701e8cafc0e971b54b0217d, $GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_a58276b2503abd83773dd92c" . "0646d1d0"])) {
                    $_f53d35a1a1e233d98d9ce73d92ab3bb1 = $_ed977237a701e8cafc0e971b54b0217d->QueueFullReindex($reindex);
                } else {
                    throw new InvalidArgumentException($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_c69801a7" . "9aed7acdf" . "d8161757e" . "4a3e64"] . $type . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e608e5b5c4c" . "34a67ba97ef8" . "4c1e16199"]);
                }
        }
        return $_f53d35a1a1e233d98d9ce73d92ab3bb1;
    }
}