Skip to content

Commit

Permalink
create a database truncation script (#73)
Browse files Browse the repository at this point in the history
* It truncates the existing entries in the nothing private database.
* It increments the number saved in visitors.txt by the number of deleted rows
  • Loading branch information
quadratrund authored and gautamkrishnar committed Oct 3, 2019
1 parent fafe03e commit 42ade06
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
cypress/videos/
cypress/screenshots/
docker/data
db_server/visitors.txt
1 change: 1 addition & 0 deletions db_server/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Nothing private Server files

* [cron.db](cron.php) truncates the database and updates the visitors.txt file
* [safedb.php](safedb.php) contains the backend code written in PHP to process the database.
* [db.sql](db.sql) contains database schema definition.
* [forgetme.php](forgetme.php) is used to delete the user's fingerprint data from the database.
Expand Down
15 changes: 15 additions & 0 deletions db_server/cron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require_once __DIR__ . '/connection.php';

$stmt = $mysqli->prepare('SELECT count(*) cnt FROM browsertab');
$stmt->execute();
$stmt->bind_result($count_from_db);
$stmt->fetch();
$stmt->free_result();

$visitors_file_name = __DIR__ . '/visitors.txt';
$count_from_file = (int)@file_get_contents($visitors_file_name);
file_put_contents($visitors_file_name, $count_from_db + $count_from_file);

$stmt = $mysqli->prepare('TRUNCATE TABLE browsertab');
$stmt->execute();

0 comments on commit 42ade06

Please sign in to comment.