From 7aea5a869dc2940698e52b3cd989bea20b2bfcf8 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 28 Sep 2017 17:56:17 +1000 Subject: [PATCH] Update files to have upload date... --- src/files.c | 11 ++++-- utils/massupload/massupload.pl | 10 +++-- utils/sql_update/files_sql_update.pl | 58 ++++++++++++++++++++++++++++ utils/ticproc/ticproc.c | 12 ++++-- 4 files changed, 80 insertions(+), 11 deletions(-) create mode 100755 utils/sql_update/files_sql_update.pl diff --git a/src/files.c b/src/files.c index c30e96b..cb7d8de 100644 --- a/src/files.c +++ b/src/files.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "Xmodem/zmodem.h" #include "bbs.h" #include "lua/lua.h" @@ -610,15 +611,16 @@ void upload(struct user_record *user) { "description TEXT," "size INTEGER," "dlcount INTEGER," + "uploaddate INTEGER," "approved INTEGER);"; - char *sql = "INSERT INTO files (filename, description, size, dlcount, approved) VALUES(?, ?, ?, 0, 0)"; + char *sql = "INSERT INTO files (filename, description, size, dlcount, approved, uploaddate) VALUES(?, ?, ?, 0, 0, ?)"; sqlite3 *db; sqlite3_stmt *res; int rc; struct stat s; char *err_msg = NULL; char *description; - + time_t curtime; if (!do_upload(user, conf.file_directories[user->cur_file_dir]->file_subs[user->cur_file_sub]->upload_path)) { s_printf(get_string(211)); @@ -679,6 +681,8 @@ void upload(struct user_record *user) { sqlite3_bind_text(res, 2, description, -1, 0); } sqlite3_bind_int(res, 3, s.st_size); + curtime = time(NULL); + sqlite3_bind_int(res, 4, curtime); } else { dolog("Failed to execute statement: %s", sqlite3_errmsg(db)); sqlite3_finalize(res); @@ -974,7 +978,8 @@ void list_files(struct user_record *user) { } } } - } else { + } + if (strlen(&(files_e[i]->description[j])) > 1) { s_printf(get_string(74)); } } else { diff --git a/utils/massupload/massupload.pl b/utils/massupload/massupload.pl index b17f9e1..282d813 100755 --- a/utils/massupload/massupload.pl +++ b/utils/massupload/massupload.pl @@ -31,7 +31,8 @@ my $stmt = qq(CREATE TABLE IF NOT EXISTS files ( description TEXT, size INTEGER, dlcount INTEGER, - approved INTEGER);); + approved INTEGER, + uploaddate INTEGER);); my $rv = $dbh->do($stmt); my $string; @@ -81,8 +82,9 @@ foreach my $fp (glob("$dir/*")) { print(" not zip file.\n"); } my $size = -s $fp; - $sth = $dbh->prepare('INSERT INTO files (filename, description, size, dlcount, approved) VALUES($1, $2, $3, 0, 1)'); - $sth->execute($fp, $string, $size); + my $curtime = time(); + $sth = $dbh->prepare('INSERT INTO files (filename, description, size, dlcount, approved, uploaddate) VALUES($1, $2, $3, 0, 1, $4)'); + $sth->execute($fp, $string, $size, $curtime); } } -} \ No newline at end of file +} diff --git a/utils/sql_update/files_sql_update.pl b/utils/sql_update/files_sql_update.pl new file mode 100755 index 0000000..d8e8fbe --- /dev/null +++ b/utils/sql_update/files_sql_update.pl @@ -0,0 +1,58 @@ +#!/usr/bin/env perl + +use DBI; + +if (@ARGV < 1) { + print "Usage: ./files_sql_update dbfile.sq3\n"; + exit(0); +} +my $dbfile = $ARGV[0]; + +sub check_exists { + my ($needed) = @_; + + my $dsn = "dbi:SQLite:dbname=$dbfile"; + my $user = ""; + my $password = ""; + my $dbh = DBI->connect($dsn, $user, $password, { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + FetchHashKeyName => 'NAME_lc', + }); + + my $sql = "PRAGMA table_info(users)"; + my $sth = $dbh->prepare($sql); + + my $gotneeded; + + $sth->execute(); + while (my @row = $sth->fetchrow_array) { + if ($row[1] eq $needed) { + $gotneeded = 1; + } + } + + $dbh->disconnect; + return $gotneeded; +} + +if (check_exists("uploaddate") == 0) { + print "Column \"uploaddate\" doesn't exist... adding..\n"; + + my ($needed) = @_; + + my $dsn = "dbi:SQLite:dbname=$dbfile"; + my $user = ""; + my $password = ""; + my $dbh = DBI->connect($dsn, $user, $password, { + PrintError => 0, + RaiseError => 1, + AutoCommit => 1, + FetchHashKeyName => 'NAME_lc', + }); + + my $sql = "ALTER TABLE files ADD COLUMN uploaddate INTEGER DEFAULT 0"; + $dbh->do($sql); + $dbh->disconnect; +} diff --git a/utils/ticproc/ticproc.c b/utils/ticproc/ticproc.c index cf9c903..3ef94dc 100644 --- a/utils/ticproc/ticproc.c +++ b/utils/ticproc/ticproc.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "../../src/inih/ini.h" #include "ticproc.h" #include "crc32.h" @@ -111,10 +112,11 @@ int add_file(struct ticfile_t *ticfile) { "description TEXT," "size INTEGER," "dlcount INTEGER," - "approved INTEGER);"; + "approved INTEGER," + "uploaddate INTEGER);"; char fetch_sql[] = "SELECT Id, filename FROM files"; char delete_sql[] = "DELETE FROM files WHERE Id=?"; - char insert_sql[] = "INSERT INTO files (filename, description, size, dlcount, approved) VALUES(?, ?, ?, 0, 1)"; + char insert_sql[] = "INSERT INTO files (filename, description, size, dlcount, approved, uploaddate) VALUES(?, ?, ?, 0, 1, ?)"; int i; int j; char *fname; @@ -125,7 +127,8 @@ int add_file(struct ticfile_t *ticfile) { char *err_msg = 0; int len; unsigned long crc; - + time_t curtime; + if (ticfile->area == NULL) { return -1; } @@ -295,10 +298,11 @@ int add_file(struct ticfile_t *ticfile) { free(fname); return -1; } + curtime = time(NULL); sqlite3_bind_text(res, 1, dest_filename, -1, 0); sqlite3_bind_text(res, 2, description, -1, 0); sqlite3_bind_int(res, 3, s.st_size); - + sqlite3_bind_int(res, 4, curtime); sqlite3_step(res); sqlite3_finalize(res); sqlite3_close(db);