From 6c8ad60e9888fa5625dad2460ca073f93ac1ae0d Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 14 Oct 2014 23:24:40 +0200 Subject: [PATCH] Add database management page --- appinfo/routes.php | 10 +++++++++ controller/guicontroller.php | 35 +++++++++++++++++++++++++++++++ grauphel.css | 7 +++++++ lib/notestorage.php | 30 +++++++++++++++++++++++++++ templates/appnavigation.php | 1 + templates/gui-database.php | 40 ++++++++++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) create mode 100644 templates/gui-database.php diff --git a/appinfo/routes.php b/appinfo/routes.php index 28ba16d..19a4b93 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -73,6 +73,16 @@ $application->registerRoutes( 'name' => 'gui#tokens', 'verb' => 'GET', ), + array( + 'url' => '/database', + 'name' => 'gui#database', + 'verb' => 'GET', + ), + array( + 'url' => '/database', + 'name' => 'gui#databaseReset', + 'verb' => 'POST', + ), array( 'url' => '/tokens/{username}/{tokenKey}', diff --git a/controller/guicontroller.php b/controller/guicontroller.php index 58768f2..6f0a15c 100644 --- a/controller/guicontroller.php +++ b/controller/guicontroller.php @@ -119,6 +119,41 @@ class GuiController extends Controller return $res; } + /** + * Allow the user to clear his database + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function database($reset = null) + { + $res = new TemplateResponse('grauphel', 'gui-database'); + $res->setParams(array('reset' => $reset)); + $this->addNavigation($res, null); + $this->addStats($res); + + return $res; + } + + /** + * Resets the database by deleting all notes and deleting the user's + * sync data. + * + * @NoAdminRequired + */ + public function databaseReset() + { + $reset = false; + if ($_POST['username'] != '' && $_POST['username'] == $this->user->getUid()) { + $notes = $this->getNotes(); + $notes->deleteAll(); + $notes->deleteSyncData(); + $reset = true; + } + + return $this->database($reset); + } + protected function addNavigation(TemplateResponse $res, $selectedRawtag = null) { $nav = new \OCP\Template('grauphel', 'appnavigation', ''); diff --git a/grauphel.css b/grauphel.css index cac269c..6ba1cde 100644 --- a/grauphel.css +++ b/grauphel.css @@ -47,6 +47,13 @@ text-decoration: underline; } +.app-grauphel #app-content .error { + color: red; +} +.app-grauphel #app-content .success { + color: green; +} + .app-grauphel .oauth-authorize { margin: 2ex; text-align: center; diff --git a/lib/notestorage.php b/lib/notestorage.php index c665903..fb68030 100644 --- a/lib/notestorage.php +++ b/lib/notestorage.php @@ -189,6 +189,22 @@ class NoteStorage \OC_DB::executeAudited($sql, $params); } + /** + * Delete synchronization data for the given user. + * + * @param SyncData $syncdata Synchronization data object + * + * @return void + */ + public function deleteSyncData() + { + \OC_DB::executeAudited( + 'DELETE FROM `*PREFIX*grauphel_syncdata`' + . ' WHERE `syncdata_user` = ?', + array($this->username) + ); + } + /** * Load a note from the storage. * @@ -280,6 +296,20 @@ class NoteStorage ); } + /** + * Delete all notes from storage. + * + * @return void + */ + public function deleteAll() + { + \OC_DB::executeAudited( + 'DELETE FROM `*PREFIX*grauphel_notes`' + . ' WHERE `note_user` = ?', + array($this->username) + ); + } + /** * Load notes for the given user in short form. * Optionally only those changed after $since revision diff --git a/templates/appnavigation.php b/templates/appnavigation.php index 8b15238..b0657e1 100644 --- a/templates/appnavigation.php +++ b/templates/appnavigation.php @@ -14,6 +14,7 @@
  • Info and stats
  • Manage access tokens
  • +
  • Manage database
  • diff --git a/templates/gui-database.php b/templates/gui-database.php new file mode 100644 index 0000000..6fc057a --- /dev/null +++ b/templates/gui-database.php @@ -0,0 +1,40 @@ + + + +printPage(); ?> + + + +
    +

    Manage database

    +

    + In case something went seriously wrong during synchronization, you may reset your + database. + It will delete all your notes and the synchronization status - as if you + never synced to this server before. +

    + + printPage(); ?> + +

    Reset database

    + +

    + Database has been reset! +

    + +

    + Database has not been reset! +

    + + +

    + To reset the database, enter your user name and click "reset database": +

    +
    + +

    + + +

    +
    +
    -- 2.30.2