]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Require postgres 9.3 on poldi and pummelzacken
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/command"
2
3 require "httpclient"
4 require "php_serialize"
5
6 class Chef
7   module Wordpress
8     extend Chef::Mixin::Command
9
10     @api_responses = {}
11     @svn_responses = {}
12
13     class << self
14       def current_version
15         core_version_check["offers"].first["current"]
16       end
17
18       def current_plugin_version(name)
19         if svn_cat("http://plugins.svn.wordpress.org/#{name}/trunk/readme.txt") =~ /Stable tag:\s*([^\s\r]*)[\s\r]*/
20           Regexp.last_match[1]
21         else
22           "trunk"
23         end
24       end
25
26       private
27
28       def core_version_check
29         api_get("http://api.wordpress.org/core/version-check/1.6")
30       end
31
32       def api_get(url)
33         @api_responses[url] ||= ::PHP.unserialize(::HTTPClient.new.get_content(url))
34       end
35
36       def svn_cat(url)
37         unless @svn_responses[url]
38           status, stdout, stderr = output_of_command("svn cat #{url}", {})
39           handle_command_failures(status, "STDOUT: #{stdout}\nSTDERR: #{stderr}", :output_on_failure => true)
40
41           @svn_responses[url] = stdout.force_encoding("UTF-8")
42         end
43
44         @svn_responses[url]
45       end
46     end
47   end
48 end