1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00
This commit is contained in:
Ryan Cramer
2025-01-05 10:54:17 -05:00
parent 00a6baaac9
commit bd5200dfb2
2 changed files with 9 additions and 4 deletions

View File

@@ -1248,7 +1248,9 @@ class Field extends WireData implements Saveable, Exportable {
$table = $this->setTable; $table = $this->setTable;
} else { } else {
$name = $this->settings['name']; $name = $this->settings['name'];
if(!strlen($name)) throw new WireException("Field 'name' is required"); $length = strlen($name);
if(!$length) throw new WireException("Field 'name' is required");
if($length > 58) $name = substr($name, 0, 58); // 'field_' + 58 = 64 max
$table = self::tablePrefix . $name; $table = self::tablePrefix . $name;
} }
if(self::$lowercaseTables) $table = strtolower($table); if(self::$lowercaseTables) $table = strtolower($table);
@@ -1265,6 +1267,7 @@ class Field extends WireData implements Saveable, Exportable {
*/ */
public function setTable($table = null) { public function setTable($table = null) {
$table = empty($table) ? '' : $this->wire()->sanitizer->fieldName($table); $table = empty($table) ? '' : $this->wire()->sanitizer->fieldName($table);
if(strlen($table) > 64) $table = substr($table, 0, 64);
$this->setTable = $table; $this->setTable = $table;
} }

View File

@@ -388,12 +388,14 @@ class Fields extends WireSaveableItems {
// even if only the case has changed. // even if only the case has changed.
$schema = $item->type->getDatabaseSchema($item); $schema = $item->type->getDatabaseSchema($item);
if(!empty($schema)) { if(!empty($schema)) {
foreach(array($table, "tmp_$table") as $t) { list(,$tmpTable) = explode(Field::tablePrefix, $table, 2);
$tmpTable = "tempf_$tmpTable";
foreach(array($table, $tmpTable) as $t) {
if(!$database->tableExists($t)) continue; if(!$database->tableExists($t)) continue;
throw new WireException("Cannot rename to '$item->name' because table `$table` already exists"); throw new WireException("Cannot rename to '$item->name' because table `$table` already exists");
} }
$database->exec("RENAME TABLE `$prevTable` TO `tmp_$table`"); // QA $database->exec("RENAME TABLE `$prevTable` TO `$tmpTable`"); // QA
$database->exec("RENAME TABLE `tmp_$table` TO `$table`"); // QA $database->exec("RENAME TABLE `$tmpTable` TO `$table`"); // QA
} }
$item->prevTable = ''; $item->prevTable = '';
} }