diff options
| author | Jules Laplace <carbon@melanarchy.org> | 2013-12-23 17:56:45 -0600 |
|---|---|---|
| committer | Jules Laplace <carbon@melanarchy.org> | 2013-12-23 17:56:45 -0600 |
| commit | 6f8676aae207c3b631643a526890f813e973194c (patch) | |
| tree | c5428dbdb8eff209cbb979c466969ba5317f8e99 /bucky2 | |
| parent | b8dd26303f26dd583ef79b42e17e89f8cb76bacc (diff) | |
bucky2 db update, script to fix bad file move
Diffstat (limited to 'bucky2')
| -rw-r--r-- | bucky2/bin/.gitignore | 2 | ||||
| -rw-r--r-- | bucky2/bin/fix-files | 45 | ||||
| -rw-r--r-- | bucky2/cgi-bin/.gitignore | 3 | ||||
| -rw-r--r-- | bucky2/lib/Bucky/DB.pm | 21 |
4 files changed, 71 insertions, 0 deletions
diff --git a/bucky2/bin/.gitignore b/bucky2/bin/.gitignore new file mode 100644 index 0000000..121012a --- /dev/null +++ b/bucky2/bin/.gitignore @@ -0,0 +1,2 @@ +gross.db + diff --git a/bucky2/bin/fix-files b/bucky2/bin/fix-files new file mode 100644 index 0000000..3ef693a --- /dev/null +++ b/bucky2/bin/fix-files @@ -0,0 +1,45 @@ +#!/usr/bin/perl +use strict; +use lib "../lib"; +use Bucky; + +my $bucky = new Bucky; +my $file_list = $bucky->db->select("file", {'thread = 2833 AND id > 16186 LIMIT 20'}); +my $file_map = {}; +foreach my $f (@$file_list) { + $file_map->{ $f->{'filename'} } = $f->{'id'}; +} + +my $base = "/var/www/vhosts/carbonpictures.com/bucky/data/"; +opendir(DIR, $base) or die $!; +my @dirs = readdir(DIR); +closedir(DIR); + +print scalar @dirs; + +foreach my $thread_id (@dirs) { + my $dir = $base . $thread_id; + + next unless (-d $dir && $thread_id !~ /^\./); + + opendir (THREAD, $dir); + my @local_files = readdir(THREAD); + closedir (THREAD); + + foreach my $filename (@local_files) { + next unless exists($file_map->{$filename}); + + my $file_id = $file_map->{$filename}; + + $bucky->db->update('file', { + "criteria" => { + "id" => $file_id + }, + "record" => { + "thread" => $thread_id + } + }); + } +} + + diff --git a/bucky2/cgi-bin/.gitignore b/bucky2/cgi-bin/.gitignore new file mode 100644 index 0000000..93485cb --- /dev/null +++ b/bucky2/cgi-bin/.gitignore @@ -0,0 +1,3 @@ +gross.db +gross.db.1 + diff --git a/bucky2/lib/Bucky/DB.pm b/bucky2/lib/Bucky/DB.pm index bca92b7..9690f40 100644 --- a/bucky2/lib/Bucky/DB.pm +++ b/bucky2/lib/Bucky/DB.pm @@ -39,6 +39,26 @@ sub insert } sub update { + my ($self, $type, $opt) = @_; + my $criteria = $opt->{'criteria'}; + my $record = $opt->{'record'}; + + $type = $DB_LOOKUP->{$type}; + return unless $type && ref($record) eq "HASH" && scalar keys %$record; + my $key_values = []; + foreach my $key (keys %$record) + { + push @$key_values, $key . "=" . $self->quote($record->{$key}); + } + my $key_value_string = join ",", @$key_values; + return unless length $key_value_string; + + my $criteria_string = $self->criteria($criteria); + return unless length $criteria_string; + + my $sql = "UPDATE $type SET $key_value_string WHERE $criteria_string"; + + $self->execute($sql); } sub select { @@ -103,6 +123,7 @@ sub execute my ($self, $sql) = @_; my $sth = $self->dbh->prepare($sql); $sth->execute; + return $sth; } sub quote |
