From 6f8676aae207c3b631643a526890f813e973194c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 23 Dec 2013 17:56:45 -0600 Subject: bucky2 db update, script to fix bad file move --- bucky2/bin/.gitignore | 2 ++ bucky2/bin/fix-files | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bucky2/bin/.gitignore create mode 100644 bucky2/bin/fix-files (limited to 'bucky2/bin') 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 + } + }); + } +} + + -- cgit v1.2.3-70-g09d2