mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Fix issue processwire/processwire-issues#1172
This commit is contained in:
@@ -530,6 +530,25 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
|
|||||||
return parent::___cloneField($field);
|
return parent::___cloneField($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the given field
|
||||||
|
*
|
||||||
|
* @param Field $field Field object
|
||||||
|
* @return bool True on success, false on DB delete failure.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function ___deleteField(Field $field) {
|
||||||
|
$result = parent::___deleteField($field);
|
||||||
|
try {
|
||||||
|
$this->manager->deleteAllOptionsForField($field);
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
$result = false;
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
$this->trackException($e);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook called when field is cloned, to clone the selectable options from old field to new field
|
* Hook called when field is cloned, to clone the selectable options from old field to new field
|
||||||
*
|
*
|
||||||
|
@@ -669,6 +669,26 @@ class SelectableOptionManager extends Wire {
|
|||||||
return $cnt;
|
return $cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all options for given field
|
||||||
|
*
|
||||||
|
* @param Field $field
|
||||||
|
* @return int
|
||||||
|
* @throws WireException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function deleteAllOptionsForField(Field $field) {
|
||||||
|
$database = $this->wire()->database;
|
||||||
|
$table = self::optionsTable;
|
||||||
|
$sql = "DELETE FROM `$table` WHERE fields_id=:fields_id";
|
||||||
|
$query = $database->prepare($sql);
|
||||||
|
$query->bindValue(':fields_id', $field->id, \PDO::PARAM_INT);
|
||||||
|
$query->execute();
|
||||||
|
$cnt = $query->rowCount();
|
||||||
|
$this->message("Deleted $cnt row(s) from table $table", Notice::debug);
|
||||||
|
return $cnt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given option titles for $field
|
* Add the given option titles for $field
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user