Forum: Typo Is there a way to refresh the resource list?

Posted by Rick Denatale (rdenatale)
on 2010-03-07 20:29
(Received via mailing list)
I finally got around to upgrading my blog from Typo 5.3 to Typo 5.4.3 
today.

It seems to be working pretty well, but I notice that if I go to the
admin > manage > images that only a few of the image files in my
public/files directory seem to have Resource model instances in the
database.

Is there an easy way to rectify this?

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Posted by de Villamil Frédéric (Guest)
on 2010-03-08 00:01
(Received via mailing list)
Hello Rick,

cut / past the code in a rake file (ie populate_resources.rake), store 
it in lib/tasks/ and run rake populate_resources. Should work, but I 
didn't test it.
Regards,
Frédéric

files = File.join("#{RAILS_ROOT}", "public", "files")

Dir.glob("#{files}/*").select do |file|
  resource = Resource.find_by_filename(file.basename)
  next unless resource.nil?

  unless file.content_type
    mime = 'text/plain'
  else
    mime = file.content_type.chomp
  end

  Resource.create(:filename => file.basename, :mime => mime, :created_at 
=> Time.now)
end



Le 7 mars 2010 à 20:29, Rick DeNatale a écrit :

> Rick DeNatale
> 
> Blog: http://talklikeaduck.denhaven2.com/
> Twitter: http://twitter.com/RickDeNatale
> WWR: http://www.workingwithrails.com/person/9021-rick-denatale
> LinkedIn: http://www.linkedin.com/in/rickdenatale
> _______________________________________________
> Typo-list mailing list
> Typo-list@rubyforge.org
> http://rubyforge.org/mailman/listinfo/typo-list

--
Frédéric de Villamil
"What's mine is mine. What's yours is still unsetteled" – Go player 
proverb
frederic@de-villamil.com                        tel: +33 (0)6 62 19 1337
http://t37.net                       Typo : http://typosphere.org
Posted by de Villamil Frédéric (Guest)
on 2010-03-14 10:57
(Received via mailing list)
Le 7 mars 10 à 20:29, Rick DeNatale a écrit :

> I finally got around to upgrading my blog from Typo 5.3 to Typo  
> 5.4.3 today.
>
> It seems to be working pretty well, but I notice that if I go to the
> admin > manage > images that only a few of the image files in my
> public/files directory seem to have Resource model instances in the
> database.
>
> Is there an easy way to rectify this?
>


Hello,

I just needed to refresh my resources, so I fixed my script. You need
the mime-types gem first, then


require 'mime/types'

files = File.join("#{RAILS_ROOT}", "public", "files")

Dir.glob("#{files}/*").select do |file|

  resource = Resource.find_by_filename(File.basename(file))
  next unless resource.nil?

  mime = MIME::Types.type_for(file).to_s.chomp


  Resource.create(:filename => File.basename(file), :mime =>
mime, :created_at => Time.now)
end

--
Frédéric de Villamil
"What's mine is mine. What's yours is still unsetteled" – Go player
proverb
frederic@de-villamil.com                        tel: +33 (0)6 62 19 1337
http://t37.net                       Typo : http://typosphere.org
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.