FOF30\Database\Installer::hasIndex PHP Method

hasIndex() private method

..)
private hasIndex ( string $tableName, string $indexName ) : boolean
$tableName string The name of the table
$indexName string The name of the index
return boolean
    private function hasIndex($tableName, $indexName)
    {
        static $isMySQL = null;
        static $cache = array();
        if (is_null($isMySQL)) {
            $driverType = $this->db->name;
            $driverType = strtolower($driverType);
            $isMySQL = true;
            if (!strpos($driverType, 'mysql') === 0 && !(substr($driverType, -5) == 'mysql') && !(substr($driverType, -6) == 'mysqli')) {
                $isMySQL = false;
            }
        }
        // Not MySQL? Lie and return true.
        if (!$isMySQL) {
            return true;
        }
        if (!isset($cache[$tableName])) {
            $cache[$tableName] = array();
        }
        if (!isset($cache[$tableName][$indexName])) {
            $cache[$tableName][$indexName] = true;
            try {
                $indices = array();
                $query = 'SHOW INDEXES FROM ' . $this->db->qn($tableName);
                $indexDefinitions = $this->db->setQuery($query)->loadAssocList();
                if (!empty($indexDefinitions) && is_array($indexDefinitions)) {
                    foreach ($indexDefinitions as $def) {
                        $indices[] = $def['Key_name'];
                    }
                    $indices = array_unique($indices);
                }
                $cache[$tableName][$indexName] = in_array($indexName, $indices);
            } catch (\Exception $e) {
                // Ignore errors
            }
        }
        return $cache[$tableName][$indexName];
    }