Add button to clear schema data

This commit is contained in:
Michael Große
2017-06-16 12:28:10 +02:00
parent 411f7e0a09
commit 79c83e060d
8 changed files with 61 additions and 3 deletions

View File

@ -113,6 +113,23 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin {
}
}
// clear
if($table && $INPUT->bool('clear')) {
if($table != $INPUT->str('confirm_clear')) {
msg($this->getLang('clear_fail'), -1);
} else {
try {
$schema = new Schema($table);
$schema->clear();
msg($this->getLang('clear_ok'), 1);
touch(action_plugin_struct_cache::getSchemaRefreshFile());
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'), true, '&'));
} catch(StructException $e) {
msg(hsc($e->getMessage()), -1);
}
}
}
}
/**
@ -204,12 +221,18 @@ class admin_plugin_struct_schemas extends DokuWiki_Admin_Plugin {
$form->setHiddenField('page', 'struct_schemas');
$form->setHiddenField('table', $schema->getTable());
$form->addFieldsetOpen($this->getLang('btn_delete'));
$form->addHTML($this->locale_xhtml('delete_intro'));
$form->addFieldsetOpen($this->getLang('tab_delete'));
$form->addTextInput('confirm', $this->getLang('del_confirm'));
$form->addButton('delete', $this->getLang('btn_delete'));
$form->addFieldsetClose();
$form->addFieldsetOpen($this->getLang('btn_clear'));
$form->addHTML($this->locale_xhtml('clear_intro'));
$form->addTextInput('confirm_clear', $this->getLang('clear_confirm'));
$form->addButton('clear', $this->getLang('btn_clear'));
$form->addFieldsetClose();
return $form->toHTML();
}

1
lang/de/clear_intro.txt Normal file
View File

@ -0,0 +1 @@
**ACHTUNG:** Hiermit werden **alle** Daten gelöscht, die jemals für dieses Schema gespeichert waren. Es gibt kein Zurück!

1
lang/de/delete_intro.txt Normal file
View File

@ -0,0 +1 @@
**ACHTUNG:** Hiermit wird die Definition des Schemas gelöscht und **alle** Daten, die jemals für dieses Schema gespeichert waren. Es gibt kein Zurück!

View File

@ -18,4 +18,15 @@ $lang['summary'] = 'Struct-Daten geändert';
$lang['export'] = 'Schema als JSON exportieren';
$lang['btn_export'] = 'Exportieren';
$lang['del_confirm'] = 'Namen des Schema zur Bestätigung der Löschung eingeben';
$lang['del_fail'] = 'Die Schemanamen stimmten nicht überein. Schema nicht gelöscht';
$lang['del_ok'] = 'Schema wurde gelöscht';
$lang['btn_delete'] = 'Löschen';
$lang['js']['confirmAssignmentsDelete'] = 'Wollen Sie wirklich die Zuweisung von Schma "{0}" zu Seite/Namensraum "{1}" löschen?';
$lang['clear_confirm'] = 'Namen des Schema zur Bestätigung der Entfernung aller Daten eingeben';
$lang['clear_fail'] = 'Die Schemanamen stimmten nicht überein. Daten wurden nicht entfernt';
$lang['clear_ok'] = 'Die Daten des Schemas wurden entfernt';
$lang['btn_clear'] = 'Leeren';
$lang['tab_delete'] = 'Löschen/Leeren';

1
lang/en/clear_intro.txt Normal file
View File

@ -0,0 +1 @@
**WARNING:** This will clear **all** data that has ever been saved for this schema! There is no going back!

View File

@ -36,9 +36,14 @@ $lang['del_ok'] = 'Schema has been deleted';
$lang['btn_delete'] = 'Delete';
$lang['js']['confirmAssignmentsDelete'] = 'Do you really want to delete the assignment of schema "{0}" to page/namespace "{1}"?';
$lang['clear_confirm'] = 'Enter schema name to confirm clearing all data';
$lang['clear_fail'] = 'Schema names did not match. Data not deleted';
$lang['clear_ok'] = 'Data of schema has been deleted';
$lang['btn_clear'] = 'Clear';
$lang['tab_edit'] = 'Edit Schema';
$lang['tab_export'] = 'Import/Export';
$lang['tab_delete'] = 'Delete';
$lang['tab_delete'] = 'Delete/Clear';
$lang['editor_sort'] = 'Sort';
$lang['editor_label'] = 'Field Name';

View File

@ -252,6 +252,21 @@ class Schema {
$this->ts = 0;
}
/**
* Clear all data of a schema, but retain the schema itself
*/
public function clear() {
if(!$this->id) throw new StructException('can not clear data of unsaved schema');
$this->sqlite->query('BEGIN TRANSACTION');
$sql = 'DELETE FROM ?';
$this->sqlite->query($sql, 'data_' . $this->table);
$this->sqlite->query($sql, 'multi_' . $this->table);
$this->sqlite->query('COMMIT TRANSACTION');
$this->sqlite->query('VACUUM');
}
/**
* @return string
*/

View File

@ -144,6 +144,7 @@
fieldset {
margin-bottom: 1em;
width: 500px;
}
}