mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 01:24:17 +02:00
Allow Disable foreign keys
Allow Disable foreign keys in SQL command
This commit is contained in:
53
plugins/fk-disable.php
Normal file
53
plugins/fk-disable.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Allow Disable foreign keys
|
||||
* @author Andrea Mariani, fasys.it
|
||||
*/
|
||||
class AdminerFkDisable
|
||||
{
|
||||
private function deleteAllBetween($beginning, $end, $string) {
|
||||
$beginningPos = strpos($string, $beginning);
|
||||
$endPos = strpos($string, $end);
|
||||
if ($beginningPos === false || $endPos === false) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
$textToDelete = substr($string, $beginningPos, ($endPos + strlen($end)) - $beginningPos);
|
||||
return $this->deleteAllBetween($beginning, $end, str_replace($textToDelete, '', $string)); // recursion to ensure all occurrences are replaced
|
||||
}
|
||||
|
||||
public function head(){
|
||||
if (!isset($_GET['sql'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = trim($_POST['query']);
|
||||
|
||||
if($_POST['fk_disable']){
|
||||
if($query) {
|
||||
$query = trim($this->deleteAllBetween("-- FK:D0", "-- FK:D1", $query));
|
||||
$_POST['query'] = "-- FK:D0\nSET FOREIGN_KEY_CHECKS=0;\n-- FK:D1\n\n{$query}\n\n-- FK:D0\nSET FOREIGN_KEY_CHECKS=1;\n-- FK:D1";
|
||||
}
|
||||
$fk_disable_checked = ($_POST['fk_disable']) ? 'checked="checked"' : "";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<script<?php echo nonce();?> type="text/javascript">
|
||||
|
||||
function domReady(fn) {
|
||||
document.addEventListener("DOMContentLoaded", fn);
|
||||
if (document.readyState === "interactive" || document.readyState === "complete" ) {
|
||||
fn();
|
||||
}
|
||||
}
|
||||
|
||||
domReady(() => {
|
||||
document.querySelectorAll('#form p')[1].insertAdjacentHTML('beforeend', '<label><input type="checkbox" name="fk_disable" value="1" <?= $fk_disable_checked ?> /><?= h('Disable Foreign Keys') ?></label>')
|
||||
})
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user