mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 01:34:31 +02:00
Fix issue processwire/processwire-issues#1175
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
* @property string $name Name of field #pw-group-properties
|
||||
* @property string $table Database table used by the field #pw-group-properties
|
||||
* @property string $prevTable Previously database table (if field was renamed) #pw-group-properties
|
||||
* @property string $prevName Previously used name (if field was renamed), 3.0.164+ #pw-group-properties
|
||||
* @property Fieldtype|null $type Fieldtype module that represents the type of this field #pw-group-properties
|
||||
* @property Fieldtype|null $prevFieldtype Previous Fieldtype, if type was changed #pw-group-properties
|
||||
* @property int $flags Bitmask of flags used by this field #pw-group-properties
|
||||
@@ -179,18 +180,26 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
protected $prevTable;
|
||||
|
||||
/**
|
||||
* A specifically set table name by setTable() for override purposes
|
||||
* If the field name changed, this is the previous name
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $setTable = '';
|
||||
protected $prevName = '';
|
||||
|
||||
/**
|
||||
* If the field type changed, this is the previous fieldtype so that it can be changed at save time
|
||||
*
|
||||
*/
|
||||
protected $prevFieldtype;
|
||||
|
||||
/**
|
||||
* A specifically set table name by setTable() for override purposes
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
protected $setTable = '';
|
||||
|
||||
/**
|
||||
* Accessed properties, becomes array when set to true, null when set to false
|
||||
@@ -269,6 +278,9 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
} else if($key == 'prevTable') {
|
||||
$this->prevTable = $value;
|
||||
return $this;
|
||||
} else if($key == 'prevName') {
|
||||
$this->prevName = $value;
|
||||
return $this;
|
||||
} else if($key == 'prevFieldtype') {
|
||||
$this->prevFieldtype = $value;
|
||||
return $this;
|
||||
@@ -389,6 +401,7 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
else if($key == 'editRoles') return $this->editRoles;
|
||||
else if($key == 'table') return $this->getTable();
|
||||
else if($key == 'prevTable') return $this->prevTable;
|
||||
else if($key == 'prevName') return $this->prevName;
|
||||
else if($key == 'prevFieldtype') return $this->prevFieldtype;
|
||||
else if(isset($this->settings[$key])) return $this->settings[$key];
|
||||
else if($key == 'icon') return $this->getIcon(true);
|
||||
@@ -616,7 +629,10 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
throw new WireException("You may not change the name of field '{$this->settings['name']}' because it is a system field.");
|
||||
}
|
||||
$this->trackChange('name');
|
||||
if($this->settings['name']) $this->prevTable = $this->getTable(); // so that Fields can perform a table rename
|
||||
if($this->settings['name']) {
|
||||
$this->prevName = $this->settings['name'];
|
||||
$this->prevTable = $this->getTable(); // so that Fields can perform a table rename
|
||||
}
|
||||
}
|
||||
|
||||
$this->settings['name'] = $name;
|
||||
@@ -1481,6 +1497,7 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
$info['flags'] = $info['flags'] ? "$this->flagsStr ($info[flags])" : "";
|
||||
$info = array_merge($info, parent::__debugInfo());
|
||||
if($this->prevTable) $info['prevTable'] = $this->prevTable;
|
||||
if($this->prevName) $info['prevName'] = $this->prevName;
|
||||
if($this->prevFieldtype) $info['prevFieldtype'] = (string) $this->prevFieldtype;
|
||||
if(!empty($this->trackGets)) $info['trackGets'] = $this->trackGets;
|
||||
if($this->useRoles) {
|
||||
|
@@ -266,9 +266,13 @@ class Fields extends WireSaveableItems {
|
||||
$database->exec("RENAME TABLE `$prevTable` TO `tmp_$table`"); // QA
|
||||
$database->exec("RENAME TABLE `tmp_$table` TO `$table`"); // QA
|
||||
}
|
||||
$item->type->renamedField($item, str_replace(Field::tablePrefix, '', $prevTable));
|
||||
$item->prevTable = '';
|
||||
}
|
||||
|
||||
if(!$isNew && $item->prevName && $item->prevName != $item->name) {
|
||||
$item->type->renamedField($item, $item->prevName);
|
||||
$item->prevName = '';
|
||||
}
|
||||
|
||||
if($item->prevFieldtype && $item->prevFieldtype->name != $item->type->name) {
|
||||
if(!$this->changeFieldtype($item)) {
|
||||
|
@@ -333,14 +333,14 @@ class FieldtypeFieldsetOpen extends Fieldtype {
|
||||
// avoid ending up in infinite loop, since FieldtypeFieldsetClose extends this
|
||||
if($this instanceof FieldtypeFieldsetClose) return;
|
||||
// rename the _END field to match this one
|
||||
$fields = $this->wire('fields');
|
||||
$fields = $this->wire()->fields;
|
||||
$oldName = $prevName . self::fieldsetCloseIdentifier;
|
||||
$newName = $field->name . self::fieldsetCloseIdentifier;
|
||||
$closer = $this->getFieldsetCloseField($field);
|
||||
if(!$closer) {
|
||||
$closer = $fields->get($prevName . self::fieldsetCloseIdentifier);
|
||||
if($closer) {
|
||||
$closer->name = $field->name . self::fieldsetCloseIdentifier;
|
||||
$fields->save($closer);
|
||||
}
|
||||
if(!$closer) $closer = $fields->get($oldName);
|
||||
if($closer && $closer->name != $newName) {
|
||||
$closer->name = $newName;
|
||||
$fields->save($closer);
|
||||
}
|
||||
parent::___renamedField($field, $prevName);
|
||||
}
|
||||
|
Reference in New Issue
Block a user