<?php
namespace Claromentis\Search\Indexing;

$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"] ?: array()) + array("_18fbc2e264f213125937238aa" . "9253adb" => base64_decode("aW50OmNvbn" . "RlbnRfc2l6" . "ZQ=="), "_3223635a80773d877dced222faf" . "aaa12" => base64_decode("REVMRVRFIEZST00gaW5kZXhpbmdfZmlsZV9jb250ZW50X2NhY2hlIFdIRVJFIHR5cGUgZXE6c3RyOnR5cGUgQU5EIGRhdGVfYWN" . "jZXNzZWQgPCBpbnQ6ZGF0ZV9hY2Nlc3NlZA=="), "_ca831b25ce7fffea9cf441f762" . "c7d154" => base64_decode("ZmlsZV9leGlzdHM" . "="), "_b3019c54263ff60f4021fa4848" . "a3b052" => base64_decode("IGNhbm5vdCBiZ" . "SByZWFk"), "_71549b9b33809fc358f3ddb0f" . "46a9818" => base64_decode("aGFzaF9m" . "aWxl"), "_80e675e452e77fe1b034dc7692" . "a15a0a" => base64_decode("bWJfc3RybG" . "Vu"), "_c9fafdb89ac4a14064f1aed3254877" . "86" => base64_decode("ZmlsZV9oYXNoIGVxOnN0cjpmaWxlX2hhc2ggQU5EIGZpbGVfc2l6ZSBlcTppbnQ6ZmlsZV9zaXplIEFORCB0eXBl" . "IGVxOnN0cjp0eXBl"), "_c130f072a37" . "6532feea5fff" . "3a290bc68" => base64_decode("ZmlsZV9jb3Vud" . "A=="), "_bc0fa1d0b817036001" . "e189e864a8c44d" => base64_decode("U0VMRUNUIGNvbnRlbnQsIGNvbnRlbnRfc2l6ZSBGUk" . "9NIGluZGV4aW5nX2ZpbGVfY29udGVudF9jYWNoZQ=="), "_6bf19ac66af25b2e2dab6bd" . "4e14c324d" => base64_decode("aXNfZG" . "ly"), "_05e19b06aa8837dd2f828c255c" . "ca103f" => base64_decode("ZmlsZV9zaX" . "plIGVxOmlu" . "dDpmaWxlX3" . "NpemU="), "_7f628626dd1d55c71" . "b1fc0932ffd1d2c" => base64_decode("aXNfYXJy" . "YXk="), "_0179d528f0a8843b697f80bc401e4f2" . "f" => base64_decode("aW50OmRhdGVf" . "YWNjZXNzZWQ="), "_98587fc" . "188f3503" . "70f03d54" . "707c587e" . "1" => base64_decode("aXNfcmVhZGFibG" . "U="), "_6faa416c6a3814bd1d97" . "ae3635c91dfb" => base64_decode("IikgYmVjYXVzZSBpdCBpcyBmbGFnZ2VkIGFzICJpbiBwcm9" . "ncmVzcyIgYnkgYW5vdGhlciBwcm9jZXNz"), "_db24569e8dc181ae4e2a6c57" . "655a0c71" => base64_decode("aW5kZXhpbmdfZmls" . "ZV9jb250ZW50X2Nh" . "Y2hl"), "_eaffc5d7e0ea1c84c4b39f95d2e2" . "fc8d" => base64_decode("c3RyX3JlcGxhY" . "2U="), "_270a61212ed5dbbd25ba8e560c4a06" . "06" => base64_decode("REVMRVRFIEZST00gaW5kZXhpbmdfZmlsZV9jb250ZW50X2NhY2hlIFdIRVJFIGNvbnRlbnRfc2l6ZSA9IC0xIEFORCBkYXR" . "lX2FjY2Vzc2VkIDwgaW50OmRhdGVfc3RhbGU="), "_d2315a066e63ef4e3e6442ad4" . "8874422" => base64_decode("aW50OmZpbG" . "Vfc2l6ZQ=="), "_f30673691778fa3b2144" . "c6244c21bcd5" => base64_decode("QXR0ZW1wdGluZyB0byBpbmRleCBhIGZpbGUgd" . "GhhdCBkb2VzIG5vdCBleGlzdCAtIA=="), "_3bcd3ca738f1" . "7d31344cb3d9e" . "75c46da" => base64_decode("Y29udGVudF9za" . "Xpl"), "_99ec16e3511" . "8578317d9350" . "5cd6a902c" => base64_decode("REVMRVRFIEZST00gaW5kZXhpbmdfZmlsZV9jb250ZW50X2NhY2hlIFdIRVJFIGRhdGVfYWNjZXNzZWQgPCBpbnQ6ZGF0ZV9hY2Nlc3NlZA" . "=="), "_f8fde5af080a3da3" . "e822d62c4a623601" => base64_decode("U0VMRUNUIGNvbnRlbnQsIGNvbnRlbnRfc2l6ZSBGUk9NIGluZGV4aW5nX2ZpbGVfY29udGVudF9jYWNoZSBXSEVSRSBmaWxlX2hhc2ggZXE6c3RyOmZpbGVfaGFzaCBBTkQgZmlsZV9zaXplIGVxOmludDpmaWxlX3NpemUgQU5EIHR5c" . "GUgZXE6c3RyOnR5cGU="), "_6749d9d12bdc55b9cd1fc3cc" . "2564e283" => base64_decode("VVBEQVRFIGluZGV4aW5nX2ZpbGVfY29udGVudF9jYWNoZSBTRVQgZGF0" . "ZV9hY2Nlc3NlZCBlcTppbnQ6ZGF0ZV9hY2Nlc3NlZCBXSEVSRSBmaWxl" . "X2hhc2ggZXE6c3RyOmZpbGVfaGFzaCBBTkQgZmlsZV9zaXplIGVxOmlu" . "dDpmaWxlX3NpemUgQU5EIHR5cGUgZXE6c3RyOnR5cGU="), "_fb36086" . "8fc3dcda" . "e17fc04b" . "bebd98a0" . "b" => base64_decode("Y29udGVudF9zaXplID" . "w+IGludDpmaWxlX3Np" . "emU="), "_9743376cbf55a90b6b036f9" . "20d9963d5" => base64_decode("ZmlsZV9zaXp" . "l"), "_de8a45b6c81e7031d02f8aec1d83d" . "83b" => base64_decode("c3RyOnR5" . "cGU="), "_709d0c6ebe4" . "ec3ca1d87478" . "f08d9c910" => base64_decode("XH" . "Q="), "_e1db5c590ae6f8cfe29fab36" . "323e6fed" => base64_decode("RmlsZ" . "SA="), "_8ab6ddf4208860" . "8c501fcded8995e" . "76c" => base64_decode("IA" . "=="), "_14a77d6af81d7257b277373f71b" . "9c123" => base64_decode("ZmlsZV9oY" . "XNoIGVxOn" . "N0cjpmaWx" . "lX2hhc2g="), "_58cd086d76145f7bb5026" . "7d8aa7a3f8b" => base64_decode("SWdub3JpbmcgcmVxdWVzdCB0byBleHRy" . "YWN0IGNvbnRlbnQgZnJvbSBhIGZpbGUg" . "KCI="), "_e04c1257ba" . "0926a8a812a" . "5eef4802670" => base64_decode("U0VMRUNUIHN1bShmaWxlX3NpemUpIEFTIHRvdGFsX2ZpbGVfc2l6ZSwgc3VtKGNvbnRlbnRfc2l6ZSkgQVMgdG90YWxfY29udGVudF9zaXplLCBjb3VudCgxKSBhcyBlbnRyeV9jb3VudCBGUk9NIGluZGV4aW5nX2ZpbGVfY29udGVudF9jYWNoZSBXSEVSRSB0eXBlIGVxOnN0cjp" . "0eXBl"), "_9aea691cec59f18702048430785b0" . "7c8" => base64_decode("Y3J" . "jMz" . "Jj"), "_4a86ad49f5e2dc8079c1b13f" . "849923d9" => base64_decode("c3RyOmZpbGVf" . "aGFzaA=="), "_fa5e9c9ac40d01a2" . "75f7736e63303130" => base64_decode("XG" . "4="), "_2414c5d338edbf4820dcc3" . "3c3f1b20b8" => base64_decode("Y2xvYjp" . "jb250ZW" . "50"));
use Claromentis\Core\DAL;
use Claromentis\Core\Util\FilesystemUtil;
use Claromentis\Search\Indexing\Exception\RedundantContentExtractionException;
use Claromentis\Search\TextExtractorService;
use Date;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;




class IndexingContentCache implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    
    
    const TEXT_EXTRACTION_RETRY_TIMEOUT = 300;
    protected DAL\Db $db;
    protected TextExtractorService $textExtractorService;
    protected DAL\QueryFactory $queryFactory;
    public function __construct(DAL\Db $db, TextExtractorService $_7ec7e4528c10ada1aeaff1c255ed906a, LoggerInterface $logger, DAL\QueryFactory $_6eca7aef01eba6bc9500824914f3b322)
    {
        $this->db = $db;
        $this->textExtractorService = $_7ec7e4528c10ada1aeaff1c255ed906a;
        $this->setLogger($logger);
        $this->queryFactory = $_6eca7aef01eba6bc9500824914f3b322;
    }
    
    
    
    
    
    
    
    
    
    public function getContent(string $filename, string $type) : ?string
    {
        if ($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_80e675e452e77fe1b034dc" . "7692a15a0a"]($filename) === 0 || $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_6bf19ac66af25b2e2dab6bd4e14c3" . "24d"]($filename) || !$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_ca831b2" . "5ce7fffe" . "a9cf441f" . "762c7d15" . "4"]($filename)) {
            $this->logger->error($GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_f30673691778fa3b2" . "144c6244c21bcd5"] . $filename);
            return null;
        }
        if (!$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_98587fc188f350370f03d54707c58" . "7e1"]($filename)) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_e1db5c590ae6f8" . "cfe29fab36323e6" . "fed"] . $filename . $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_b3019c54263ff60f4021fa4848a3b" . "052"]);
            return null;
        }
        $_72a7209efcd9c803cef80753f412d5cd = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_71549b9b33809fc358f" . "3ddb0f46a9818"]($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_9aea691cec59f18702048430785b" . "07c8"], $filename);
        $size = FilesystemUtil::FileSize($filename);
        $_67a0d624aebcceb0abd5ce56a53ff06f = new Date();
        $_67a0d624aebcceb0abd5ce56a53ff06f = $_67a0d624aebcceb0abd5ce56a53ff06f->getDate(DATE_FORMAT_TIMESTAMP);
        
        
        $_22bbd775d1913a4dedbb1e21efeb02ac = $this->db->query_row($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_f8fde5af0" . "80a3da3e82" . "2d62c4a623" . "601"], $_72a7209efcd9c803cef80753f412d5cd, $size, $type);
        if ($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_7f628626dd1d55c71b" . "1fc0932ffd1d2c"]($_22bbd775d1913a4dedbb1e21efeb02ac)) {
            if ((int) $_22bbd775d1913a4dedbb1e21efeb02ac[1] === -1) {
                throw new RedundantContentExtractionException($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_58cd086d76145f7bb5" . "0267d8aa7a3f8b"] . $filename . $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_6faa416c6a3814bd1d" . "97ae3635c91dfb"]);
            }
            
            
            $this->db->unsafe_query = true;
            $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_6749d9d12bdc55b9cd1fc3cc2564e28" . "3"], $_67a0d624aebcceb0abd5ce56a53ff06f, $_72a7209efcd9c803cef80753f412d5cd, $size, $type);
            return $_22bbd775d1913a4dedbb1e21efeb02ac[0];
        }
        $data = [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_de8a45b6c81e7031d02f8aec1d83d" . "83b"] => $type, $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4a86ad49f5e2dc80" . "79c1b13f849923d9"] => $_72a7209efcd9c803cef80753f412d5cd, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_d2315a066e63ef" . "4e3e6442ad48874" . "422"] => $size, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_0179d528f0a884" . "3b697f80bc401e4" . "f2f"] => $_67a0d624aebcceb0abd5ce56a53ff06f, $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_18fbc2e264f213125" . "937238aa9253adb"] => -1];
        
        
        $this->db->unsafe_query = true;
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_db24569e8dc181ae4" . "e2a6c57655a0c71"], $data));
        
        
        $_4c8189237e0d0b5cd82c06d69613c88e = $this->queryFactory->GetQueryBuilder($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_bc0fa1d0b817036001e" . "189e864a8c44d"]);
        $_4c8189237e0d0b5cd82c06d69613c88e->AddWhereAndClause($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_14a77d6af81d7257b277" . "373f71b9c123"], $_72a7209efcd9c803cef80753f412d5cd);
        $_4c8189237e0d0b5cd82c06d69613c88e->AddWhereAndClause($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_05e19b06aa8837dd2f828c" . "255cca103f"], $size);
        $_4c8189237e0d0b5cd82c06d69613c88e->AddWhereAndClause($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_fb360868fc3dcdae17fc04bbe" . "bd98a0b"], -1);
        $_4c8189237e0d0b5cd82c06d69613c88e->SetLimit(1);
        $_22bbd775d1913a4dedbb1e21efeb02ac = $this->db->query_row($_4c8189237e0d0b5cd82c06d69613c88e->GetQuery());
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_7f628626dd1d55c71" . "b1fc0932ffd1d2c"]($_22bbd775d1913a4dedbb1e21efeb02ac)) {
            
            
            $data[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_2414c5d338edbf4820d" . "cc33c3f1b20b8"]] = $_22bbd775d1913a4dedbb1e21efeb02ac[0];
            $data[$GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_18fbc2e2" . "64f213125" . "937238aa9" . "253adb"]] = $_22bbd775d1913a4dedbb1e21efeb02ac[1];
        } else {
            
            
            $_24ca62b4d01cc6d515dfd0bea4c9d59a = $this->textExtractorService->getText($filename);
            
            
            $_24ca62b4d01cc6d515dfd0bea4c9d59a = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_eaffc5d7e0ea1c84c4b39f95d2e" . "2fc8d"]([$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_709d0c6ebe4ec3ca1d" . "87478f08d9c910"], $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_fa5e9c9ac40d01a2" . "75f7736e63303130"]], $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_8ab6ddf42088608c501fcde" . "d8995e76c"], $_24ca62b4d01cc6d515dfd0bea4c9d59a);
            $data[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_2414c5d338edbf4820dc" . "c33c3f1b20b8"]] = $_24ca62b4d01cc6d515dfd0bea4c9d59a;
            $data[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5" . "36215"]["_18fbc2e264f" . "213125937238" . "aa9253adb"]] = $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_80e675e452e77fe1b034dc7692a15a0" . "a"]($_24ca62b4d01cc6d515dfd0bea4c9d59a);
        }
        $this->db->unsafe_query = true;
        $this->db->query(new DAL\QueryUpdate($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_db24569e8dc181ae4e2a6c57655a" . "0c71"], $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_c9fafdb89ac4a14064f1aed32548" . "7786"], $data));
        return $data[$GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_2414c5d338edbf4820dcc33c3" . "f1b20b8"]];
    }
    public function clearCache(?string $type = null, ?Date $_9787412e818de6e890c62efe6a7ed1a8 = null)
    {
        
        
        if ($_9787412e818de6e890c62efe6a7ed1a8 === null) {
            $_9787412e818de6e890c62efe6a7ed1a8 = new \Date();
        }
        $_23f9ac5d8b8559beb5dca79a30372101 = $_9787412e818de6e890c62efe6a7ed1a8->getDate(DATE_FORMAT_TIMESTAMP);
        $this->db->unsafe_query = true;
        if ($type !== null) {
            $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3223635a80773d877dced222fafa" . "aa12"], $type, $_23f9ac5d8b8559beb5dca79a30372101);
        } else {
            $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_99ec16e3511" . "8578317d9350" . "5cd6a902c"], $_23f9ac5d8b8559beb5dca79a30372101);
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    public function getContentStats(string $type) : array
    {
        [$_d0d367e41bd55d6ada69bf96b1cc11a0, $_b0852420e62f6cf1f53c8bd6b55b5e40, $_8eb1383fa9757d0f9766e832fc33862f] = $this->db->query_row($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_e04c1257ba0926a" . "8a812a5eef480267" . "0"], $type);
        return [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_9743376cbf55a90" . "b6b036f920d9963d" . "5"] => $_d0d367e41bd55d6ada69bf96b1cc11a0 ?: 0, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_3bcd3ca738f" . "17d31344cb3d" . "9e75c46da"] => $_b0852420e62f6cf1f53c8bd6b55b5e40 ?: 0, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["_c130f072a3" . "76532feea5f" . "ff3a290bc68"] => $_8eb1383fa9757d0f9766e832fc33862f ?: 0];
    }
    
    
    
    
    
    
    public function removeStaleEntries() : void
    {
        $_bfa9a51cf765c3ab4f62327167cfc534 = new Date();
        $_bfa9a51cf765c3ab4f62327167cfc534->subtractSeconds(self::TEXT_EXTRACTION_RETRY_TIMEOUT);
        $_bfa9a51cf765c3ab4f62327167cfc534 = $_bfa9a51cf765c3ab4f62327167cfc534->getDate(DATE_FORMAT_TIMESTAMP);
        $this->db->unsafe_query = true;
        $this->db->query($GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_270a61212" . "ed5dbbd25b" . "a8e560c4a0" . "606"], $_bfa9a51cf765c3ab4f62327167cfc534);
    }
}