summaryrefslogtreecommitdiff
path: root/search/bin/fix-files
blob: b56d377b7147ec905a9ef3cc32ec66ed77e2e8f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
use strict;
use lib "../lib";
use Bucky;

my $bucky = new Bucky;
my $file_list = $bucky->db->select("file", {'thread = 2833'});
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_by_id('file', {
      "id" => $file_id,
      "record" => {
        "thread" => $thread_id
      }
    });
  }
}