Update files to have upload date...

This commit is contained in:
Andrew Pamment 2017-09-28 17:56:17 +10:00
parent 01b7ad9481
commit 7aea5a869d
4 changed files with 80 additions and 11 deletions

View File

@ -10,6 +10,7 @@
#include <termios.h>
#include <dirent.h>
#include <fcntl.h>
#include <time.h>
#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 {

View File

@ -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);
}
}
}
}

View File

@ -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;
}

View File

@ -6,6 +6,7 @@
#include <dirent.h>
#include <libgen.h>
#include <ctype.h>
#include <time.h>
#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);