dbi = $dbi; $this->flash = $flash; $this->relationCleanup = $relationCleanup; } public function __invoke(): void { $selected = $_POST['selected'] ?? []; if (empty($selected)) { $this->response->setRequestStatus(false); $this->response->addJSON('message', __('No column selected.')); return; } $selectedCount = count($selected); if (($_POST['mult_btn'] ?? '') === __('Yes')) { $i = 1; $statement = 'ALTER TABLE ' . Util::backquote($this->table); foreach ($selected as $field) { $this->relationCleanup->column($this->db, $this->table, $field); $statement .= ' DROP ' . Util::backquote($field); $statement .= $i++ === $selectedCount ? ';' : ','; } $this->dbi->selectDb($this->db); $result = $this->dbi->tryQuery($statement); if (! $result) { $message = Message::error($this->dbi->getError()); } } else { $message = Message::success(__('No change')); } if (empty($message)) { $message = Message::success( _ngettext( '%1$d column has been dropped successfully.', '%1$d columns have been dropped successfully.', $selectedCount ) ); $message->addParam($selectedCount); } $this->flash->addMessage($message->isError() ? 'danger' : 'success', $message->getMessage()); $this->redirect('/table/structure', ['db' => $this->db, 'table' => $this->table]); } }