Compare commits
2
Commits
bc63ebdb15
...
8659715132
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8659715132 | ||
|
|
701bc3bb8b |
@@ -43,6 +43,49 @@ function connectToMySQL($returnErrors = false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Motor de almacenamiento para las tablas que crea el CMS.
|
||||
*
|
||||
* InnoDB da recuperacion ante caida (MyISAM se corrompe con un apagon o un OOM
|
||||
* y hay que repararlo a mano) y bloqueo por fila. Pero en servidores antiguos
|
||||
* no es seguro: MariaDB 5.5 (hay un servidor de produccion con 5.5.68) no
|
||||
* admite FULLTEXT en InnoDB, limita los indices a 767 bytes y usa filas
|
||||
* COMPACT. Por eso el motor se decide por la version del servidor, igual que
|
||||
* mysqlStrictMode decide el modo SQL:
|
||||
*
|
||||
* MariaDB >= 10.2 o MySQL >= 5.7 -> InnoDB (Barracuda/DYNAMIC por defecto)
|
||||
* cualquier otro o desconocido -> MyISAM (lo de siempre)
|
||||
*
|
||||
* No cambia que INSERT se aceptan: el CMS conecta en modo estricto
|
||||
* (mysqlStrictMode / TRADITIONAL en Db.php) y en un INSERT de una fila eso
|
||||
* rechaza lo mismo con los dos motores. Ver docs/motor-innodb.md (repo Forge).
|
||||
*/
|
||||
function acaiTableEngine() {
|
||||
static $engine = null;
|
||||
if ($engine === null) {
|
||||
$engine = acaiEngineForServerVersion(mysql_get_server_info());
|
||||
}
|
||||
return $engine;
|
||||
}
|
||||
|
||||
/** Decision pura, separada para poder probarla sin servidor. */
|
||||
function acaiEngineForServerVersion($serverInfo) {
|
||||
$info = trim((string) $serverInfo);
|
||||
// Clientes antiguos ven MariaDB 10+ como "5.5.5-10.6.25-MariaDB": el
|
||||
// "5.5.5-" es un disfraz de compatibilidad, la version real va detras.
|
||||
if (preg_match('/^5\.5\.5-(\d+\.\d+(?:\.\d+)?)/', $info, $m)) {
|
||||
$version = $m[1];
|
||||
$isMariaDb = true;
|
||||
} elseif (preg_match('/^(\d+\.\d+(?:\.\d+)?)/', $info, $m)) {
|
||||
$version = $m[1];
|
||||
$isMariaDb = stripos($info, 'mariadb') !== false;
|
||||
} else {
|
||||
return 'MyISAM';
|
||||
}
|
||||
$minimo = $isMariaDb ? '10.2' : '5.7';
|
||||
return version_compare($version, $minimo, '>=') ? 'InnoDB' : 'MyISAM';
|
||||
}
|
||||
|
||||
function mysqlStrictMode($strictMode) {
|
||||
$currentVersion = preg_replace("/[^0-9\.]/", "", mysql_get_server_info());
|
||||
$isMySql5 = version_compare($currentVersion, '5.0.0', '>=');
|
||||
@@ -74,12 +117,9 @@ function createMissingSchemaTablesAndFields() {
|
||||
$mysqlTableName = $TABLE_PREFIX . $tableName;
|
||||
if (!in_array($mysqlTableName, $mysqlTables)) {
|
||||
notice("Creating MySQL table for schema table: $tableName<br/>\n");
|
||||
// InnoDB (antes MyISAM): las tablas nuevas nacen con recuperacion
|
||||
// ante caida y bloqueo por fila. No cambia que INSERT se aceptan:
|
||||
// el CMS conecta en modo estricto (mysqlStrictMode / TRADITIONAL
|
||||
// en Db.php) y en un INSERT de una fila eso rechaza lo mismo con
|
||||
// MyISAM que con InnoDB. Ver docs/motor-innodb.md del repo Forge.
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($mysqlTableName)."` (num int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (num)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
||||
// Motor segun el servidor (ver acaiTableEngine): InnoDB donde lo
|
||||
// soporta bien, MyISAM en los antiguos.
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($mysqlTableName)."` (num int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (num)) ENGINE=".acaiTableEngine()." DEFAULT CHARSET=utf8mb4;");
|
||||
if (!$result) { alert("Error creating MySQL table: $mysqlTableName<br/>\MySQL error was: ". htmlspecialchars(mysql_error()) . "\n"); }
|
||||
}
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ function addTablePlugin($path,$file) {
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($tableNameWithPrefix)."` (
|
||||
num int(10) unsigned NOT NULL auto_increment,
|
||||
PRIMARY KEY (num)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
) ENGINE=".acaiTableEngine()." DEFAULT CHARSET=utf8;");
|
||||
if (!$result) {
|
||||
print "Error creating MySQL table.\n\nMySQL error was: ". htmlspecialchars(mysql_error()) . "\n";
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user