Skip to content

Instantly share code, notes, and snippets.

@kalabiyau
Created April 7, 2011 08:57
Show Gist options
  • Save kalabiyau/907371 to your computer and use it in GitHub Desktop.
Save kalabiyau/907371 to your computer and use it in GitHub Desktop.
desc 'albums load to DB'
task :albumload => :environment do
require 'i18n'
yamlhash=YAML.load(File.open('albums.yml').read)
connect = Mysql2::Client.new(:host => 'localhost', :username=>'hc45_cms', :password=>'', :database=>'hc45_cms')
connect.query("delete from cms_module_gallery where fileid>61")
connect.query("delete from cms_module_gallery_props where fileid>61")
# connect.query("delete from cms_module_news_fieldvals where news_id>27")
# src = '/home/achernikov/Desktop/hc45.ru'
dst = '/home/achernikov/Dropbox/dev/hc45.ru/uploads/images/Gallery'
id=connect.query("Select MAX(fileid) from cms_module_gallery").first.values.first
yamlhash.each do |y|
date=y["date"].to_date
title=connect.escape(y["name"])
albumname= I18n.transliterate(y["name"]).gsub(' ', '_').gsub('-','').gsub('__','_').gsub(/"|'|,|!/,'')
gallfolder = dst+'/'+albumname
connect.query("INSERT into cms_module_gallery (fileid,filename,filepath,filedate,fileorder,active,defaultfile, galleryid, title, comment) VALUES ('#{id+1}','#{albumname+'/'}','','#{date}',0, 1, 0, 1,'#{title}','')")
connect.query("INSERT into cms_module_gallery_props (fileid,templateid,hideparentlink) VALUES ('#{id+1}',7,1)")
puts gallfolder
FileUtils.rmdir(gallfolder) if Dir.exists?(gallfolder)
FileUtils.mkdir(gallfolder)
id+=1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment