Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 66bc049f rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

Merge pull request #6922 from cmrd-senya/6547-adoption

Refactored photo extraction
parents 59fb227d 2a2b604a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -113,6 +113,7 @@ before. ...@@ -113,6 +113,7 @@ before.
* Redesigned the landing page and added dedicated notes for podmins [#6268](https://github.com/diaspora/diaspora/pull/6268) * Redesigned the landing page and added dedicated notes for podmins [#6268](https://github.com/diaspora/diaspora/pull/6268)
* Moved the entire federation implementation into its own gem. 🎉 [#6873](https://github.com/diaspora/diaspora/pull/6873) * Moved the entire federation implementation into its own gem. 🎉 [#6873](https://github.com/diaspora/diaspora/pull/6873)
* Remove `StatusMessage#raw_message` [#6921](https://github.com/diaspora/diaspora/pull/6921) * Remove `StatusMessage#raw_message` [#6921](https://github.com/diaspora/diaspora/pull/6921)
* Extract photo export into a service class [#6922](https://github.com/diaspora/diaspora/pull/6922)
## Bug fixes ## Bug fixes
* Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852) * Destroy Participation when removing interactions with a post [#5852](https://github.com/diaspora/diaspora/pull/5852)
......
...@@ -324,34 +324,7 @@ class User < ActiveRecord::Base ...@@ -324,34 +324,7 @@ class User < ActiveRecord::Base
end end
def perform_export_photos! def perform_export_photos!
temp_zip = Tempfile.new([username, '_photos.zip']) PhotoExporter.new(self).perform
begin
Zip::OutputStream.open(temp_zip.path) do |zos|
photos.each do |photo|
begin
photo_file = photo.unprocessed_image.file
if photo_file
photo_data = photo_file.read
zos.put_next_entry(photo.remote_photo_name)
zos.print(photo_data)
else
logger.info "Export photos error: No file for #{photo.remote_photo_name} not found"
end
rescue Errno::ENOENT
logger.info "Export photos error: #{photo.unprocessed_image.file.path} not found"
end
end
end
ensure
temp_zip.close
end
begin
update exported_photos_file: temp_zip, exported_photos_at: Time.zone.now if temp_zip.present?
ensure
restore_attributes if invalid? || temp_zip.present?
update exporting_photos: false
end
end end
######### Mailer ####################### ######### Mailer #######################
......
class PhotoExporter
attr_reader :user
def initialize(user)
@user = user
end
def perform
temp_zip = Tempfile.new([user.username, "_photos.zip"])
begin
Zip::OutputStream.open(temp_zip.path) do |zip_output_stream|
user.photos.each do |photo|
export_photo(zip_output_stream, photo)
end
end
ensure
temp_zip.close
end
update_exported_photos_at(temp_zip)
end
private
def export_photo(zip_output_stream, photo)
photo_file = photo.unprocessed_image.file
if photo_file
photo_data = photo_file.read
zip_output_stream.put_next_entry(photo.remote_photo_name)
zip_output_stream.print(photo_data)
else
user.logger.info "Export photos error: No file for #{photo.remote_photo_name} not found"
end
rescue Errno::ENOENT
user.logger.info "Export photos error: #{photo.unprocessed_image.file.path} not found"
end
def update_exported_photos_at(temp_zip)
user.update exported_photos_file: temp_zip, exported_photos_at: Time.zone.now
ensure
user.restore_attributes if user.invalid?
user.update exporting_photos: false
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter