summaryrefslogtreecommitdiff
path: root/bucky2/bin/move-file
diff options
context:
space:
mode:
Diffstat (limited to 'bucky2/bin/move-file')
-rwxr-xr-xbucky2/bin/move-file38
1 files changed, 30 insertions, 8 deletions
diff --git a/bucky2/bin/move-file b/bucky2/bin/move-file
index bd6dc48..7bfec85 100755
--- a/bucky2/bin/move-file
+++ b/bucky2/bin/move-file
@@ -4,15 +4,37 @@ use lib "../lib";
use Bucky;
if (scalar(@ARGV) < 2) {
- print "usage: move-file thread-id comment-id\n";
+ print "usage: move-file thread-id file-ids\n";
exit(1);
}
-my $bucky = new Bucky;
-$bucky->db->update_by_id('file', {
- "id" => $ARGV[1],
- "record" => {
- "thread" => $ARGV[0]
- }
-});
+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
+ }
+ });
+}
+