summaryrefslogtreecommitdiff
path: root/bucky2/bin/move-file
blob: 7bfec858ed2012b0308055cbe96ec71103d102a0 (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
#!/usr/bin/perl
use strict;
use lib "../lib";
use Bucky;

if (scalar(@ARGV) < 2) {
  print "usage: move-file thread-id file-ids\n";
  exit(1);
}

our $bucky = new Bucky;
our $thread_id = $ARGV[0];

for (my $i = 1; $i < scalar(@ARGV); $i++) {
  move_file($ARGV[$i]);
}

sub move_file {
  my $file_id = shift;

  my $files = $bucky->db->select('file', { id => $file_id });
  my $file = $files->[0];

  my $path = $ENV{"HOME"} . "/bucky/data/";

  print "moving " . $file->{'filename'} . "\n";

  system("/bin/mkdir", "-p", $path . $thread_id);
  system("/bin/mkdir", "-p", $path . $thread_id . "/.thumb");
  system("/bin/mv", $path . $file->{'thread'} . "/" . $file->{'filename'}, $path . $thread_id);

  $bucky->db->update_by_id('file', {
    "id" => $file_id,
    "record" => {
      "thread" => $thread_id
    }
  });
}