]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/definitions/wordpress_theme.rb
Convert wordpress_plugin to an LWRP
[chef.git] / cookbooks / wordpress / definitions / wordpress_theme.rb
1 #
2 # Cookbook Name:: wordpress
3 # Definition:: wordpress_theme
4 #
5 # Copyright 2013, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 define :wordpress_theme, :action => [:enable] do
21   name = params[:name]
22   site = params[:site]
23   site_directory = node[:wordpress][:sites][site][:directory]
24   theme_directory = "#{site_directory}/wp-content/themes/#{name}"
25   source = params[:source]
26
27   if source
28     remote_directory theme_directory do
29       cookbook "wordpress"
30       source source
31       owner node[:wordpress][:user]
32       group node[:wordpress][:group]
33       mode 0755
34       files_owner node[:wordpress][:user]
35       files_group node[:wordpress][:group]
36       files_mode 0644
37     end
38   else
39     repository = params[:repository]
40
41     unless repository
42       version = params[:version] || node[:wordpress][:plugins][name][:version]
43       repository = "http://themes.svn.wordpress.org/#{name}/#{version}"
44     end
45
46     if repository =~ /\.git$/
47       git theme_directory do
48         action :sync
49         repository repository
50         revision params[:revision]
51         user node[:wordpress][:user]
52         group node[:wordpress][:group]
53         notifies :reload, "service[apache2]"
54       end
55     else
56       subversion theme_directory do
57         action :sync
58         repository repository
59         user node[:wordpress][:user]
60         group node[:wordpress][:group]
61         ignore_failure repository.start_with?("http://themes.svn.wordpress.org/")
62         notifies :reload, "service[apache2]"
63       end
64     end
65   end
66 end