فهرست منبع

Update Admin\Install page

Add dsn for PostgreSQL.
Update prefix reserved.
Change the check for the existence of the users table, because in PostgreSQL a query error aborts the execution of queries in this transaction.
Visman 3 سال پیش
والد
کامیت
66aff84a88
3فایلهای تغییر یافته به همراه18 افزوده شده و 14 حذف شده
  1. 16 12
      app/Models/Pages/Admin/Install.php
  2. 1 1
      app/lang/en/admin_install.po
  3. 1 1
      app/lang/ru/admin_install.po

+ 16 - 12
app/Models/Pages/Admin/Install.php

@@ -457,8 +457,8 @@ class Install extends Admin
             if (! \preg_match('%^[a-z][a-z\d_]*$%i', $prefix)) {
                 $v->addError('Table prefix error');
             } elseif (
-                'sqlite' === $v->dbtype
-                && 'sqlite_' === \strtolower($prefix)
+                'sqlite_' === \strtolower($prefix)
+                || 'pg_' === \strtolower($prefix)
             ) {
                 $v->addError('Prefix reserved');
             }
@@ -474,7 +474,7 @@ class Install extends Admin
     {
         $this->c->DB_USERNAME = $v->dbuser;
         $this->c->DB_PASSWORD = $v->dbpass;
-        $this->c->DB_PREFIX   = \is_string($v->dbprefix) ? $v->dbprefix : '';
+        $this->c->DB_PREFIX   = $v->dbprefix;
         $dbtype               = $v->dbtype;
         $dbname               = $v->dbname;
 
@@ -502,6 +502,16 @@ class Install extends Admin
             case 'sqlite':
                 break;
             case 'pgsql':
+                if (\preg_match('%^([^:]+):(\d+)$%', $dbhost, $matches)) {
+                    $host = $matches[1];
+                    $port = $matches[2];
+                } else {
+                    $host = $dbhost;
+                    $port = '5432';
+                }
+
+                $this->c->DB_DSN = "pgsql:host={$host} port={$port} dbname={$dbname} options='--client_encoding=UTF8'";
+
                 break;
             default:
                 //????
@@ -520,16 +530,10 @@ class Install extends Admin
         }
 
         // проверка наличия таблицы пользователей в БД
-        try {
-            $stmt = $this->c->DB->query('SELECT 1 FROM ::users LIMIT 1');
-
-            if (! empty($stmt->fetch())) {
-                $v->addError(['Existing table error', $v->dbprefix, $v->dbname]);
+        if ($this->c->DB->tableExists('users')) {
+            $v->addError(['Existing table error', $v->dbprefix, $v->dbname]);
 
-                return $dbhost;
-            }
-        } catch (PDOException $e) {
-            // все отлично, таблица пользователей не найдена
+            return $dbhost;
         }
 
         // база MySQL, кодировка базы отличается от UTF-8 (4 байта)

+ 1 - 1
app/lang/en/admin_install.po

@@ -151,7 +151,7 @@ msgid "Table prefix error"
 msgstr "The table prefix '%s' does not match the format."
 
 msgid "Prefix reserved"
-msgstr "The table prefix 'sqlite_' is reserved for use by the SQLite engine."
+msgstr "The 'sqlite_' and 'pg_' prefixes are reserved. Please choose a different prefix."
 
 msgid "Existing table error"
 msgstr "A table called '%1$susers' is already present in the database '%2$s'. This could mean that ForkBB is already installed or that another piece of software is installed and is occupying one or more of the table names ForkBB requires. If you want to install multiple copies of ForkBB in the same database, you must choose a different table prefix."

+ 1 - 1
app/lang/ru/admin_install.po

@@ -151,7 +151,7 @@ msgid "Table prefix error"
 msgstr "Префикс '%s' не соответсвует формату."
 
 msgid "Prefix reserved"
-msgstr "Префикс 'sqlite_' зарезрвирован для SQLite."
+msgstr "Префиксы 'sqlite_' и 'pg_' зарезервированы. Выберите другой префикс."
 
 msgid "Existing table error"
 msgstr "Таблица '%1$susers' уже существует в базе '%2$s'. Это может означать, что ForkBB был установлен в данную базу или другой программный пакет занимает таблицы, требуемые для работы ForkBB. Если вы хотите установить несколько копий форума в одну базу, выбирайте разные префиксы для них."