public static function optimizeTables($tables, $force = false)
    {
        $optimize = Config::getInstance()->General['enable_sql_optimize_queries'];

        if (empty($optimize)
            && !$force
        ) {
            return false;
        }

        if (empty($tables)) {
            return false;
        }

        if (!is_array($tables)) {
            $tables = array($tables);
        }

        if (!self::isOptimizeInnoDBSupported()
            && !$force
        ) {
            // filter out all InnoDB tables
            $myisamDbTables = array();
            foreach (self::getTableStatus() as $row) {
                if (strtolower($row['Engine']) == 'myisam'
                    && in_array($row['Name'], $tables)
                ) {
                    $myisamDbTables[] = $row['Name'];
                }
            }

            $tables = $myisamDbTables;
        }

        if (empty($tables)) {
            return false;
        }

        // optimize the tables
        return self::query("OPTIMIZE TABLE " . implode(',', $tables));
    }