Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collect_user_photos.rb « lib - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f91875a0be09922719361cf1b2a949451ce6e600 (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
module PhotoMover
  def self.move_photos(user)
    Dir.chdir Rails.root
    temp_dir = "tmp/exports/#{user.id}"
    FileUtils::mkdir_p temp_dir
    Dir.chdir 'tmp/exports'

    photos = user.visible_posts.where(:author_id => user.person.id, :type => 'Photo')

    photos_dir = "#{user.id}/photos"
    FileUtils::mkdir_p photos_dir

    photos.each do |photo|
      current_photo_location = "#{Rails.root}/public/uploads/images/#{photo.remote_photo_name}"
      new_photo_location = "#{photos_dir}/#{photo.remote_photo_name}"
      FileUtils::cp current_photo_location, new_photo_location
    end

    `tar c #{user.id} > #{user.id}.tar`
    #system("tar", "c", "#{user.id}",">", "#{user.id}.tar")
    FileUtils::rm_r "#{user.id.to_s}/", :secure => true, :force => true

    "#{Rails.root}/#{temp_dir}.tar"
  end
end