File tree 2 files changed +9
-4
lines changed
Filter options
2 files changed +9
-4
lines changed
Original file line number Diff line number Diff line change @@ -1248,7 +1248,9 @@ public function getTable() {
1248
1248
$ table = $ this ->setTable ;
1249
1249
} else {
1250
1250
$ name = $ this ->settings ['name ' ];
1251
- if (!strlen ($ name )) throw new WireException ("Field 'name' is required " );
1251
+ $ length = strlen ($ name );
1252
+ if (!$ length ) throw new WireException ("Field 'name' is required " );
1253
+ if ($ length > 58 ) $ name = substr ($ name , 0 , 58 ); // 'field_' + 58 = 64 max
1252
1254
$ table = self ::tablePrefix . $ name ;
1253
1255
}
1254
1256
if (self ::$ lowercaseTables ) $ table = strtolower ($ table );
@@ -1265,6 +1267,7 @@ public function getTable() {
1265
1267
*/
1266
1268
public function setTable ($ table = null ) {
1267
1269
$ table = empty ($ table ) ? '' : $ this ->wire ()->sanitizer ->fieldName ($ table );
1270
+ if (strlen ($ table ) > 64 ) $ table = substr ($ table , 0 , 64 );
1268
1271
$ this ->setTable = $ table ;
1269
1272
}
1270
1273
Original file line number Diff line number Diff line change @@ -388,12 +388,14 @@ public function ___save(Saveable $item) {
388
388
// even if only the case has changed.
389
389
$ schema = $ item ->type ->getDatabaseSchema ($ item );
390
390
if (!empty ($ schema )) {
391
- foreach (array ($ table , "tmp_ $ table " ) as $ t ) {
391
+ list (,$ tmpTable ) = explode (Field::tablePrefix, $ table , 2 );
392
+ $ tmpTable = "tempf_ $ tmpTable " ;
393
+ foreach (array ($ table , $ tmpTable ) as $ t ) {
392
394
if (!$ database ->tableExists ($ t )) continue ;
393
395
throw new WireException ("Cannot rename to ' $ item ->name ' because table ` $ table` already exists " );
394
396
}
395
- $ database ->exec ("RENAME TABLE ` $ prevTable` TO `tmp_ $ table ` " ); // QA
396
- $ database ->exec ("RENAME TABLE `tmp_ $ table ` TO ` $ table` " ); // QA
397
+ $ database ->exec ("RENAME TABLE ` $ prevTable` TO ` $ tmpTable ` " ); // QA
398
+ $ database ->exec ("RENAME TABLE ` $ tmpTable ` TO ` $ table` " ); // QA
397
399
}
398
400
$ item ->prevTable = '' ;
399
401
}
You can’t perform that action at this time.
0 commit comments