]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/resources/plugin.rb
Rewrite ooc site using leaflet and bring it under chef control
[chef.git] / cookbooks / wordpress / resources / plugin.rb
1 #
2 # Cookbook Name:: wordpress
3 # Resource:: wordpress_plugin
4 #
5 # Copyright 2015, 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 default_action :create
21
22 property :plugin, :kind_of => String, :name_attribute => true
23 property :site, :kind_of => String, :required => true
24 property :source, :kind_of => String
25 property :version, :kind_of => String
26 property :repository, :kind_of => String
27 property :revision, :kind_of => String
28 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
29
30 action :create do
31   if new_resource.source
32     remote_directory plugin_directory do
33       cookbook "wordpress"
34       source new_resource.source
35       owner node[:wordpress][:user]
36       group node[:wordpress][:group]
37       mode 0o755
38       files_owner node[:wordpress][:user]
39       files_group node[:wordpress][:group]
40       files_mode 0o755
41     end
42   else
43     plugin_repository = new_resource.repository || default_repository
44
45     if plugin_repository.end_with?(".git")
46       git plugin_directory do
47         action :sync
48         repository plugin_repository
49         revision new_resource.revision
50         user node[:wordpress][:user]
51         group node[:wordpress][:group]
52       end
53     else
54       subversion plugin_directory do
55         action :sync
56         repository plugin_repository
57         user node[:wordpress][:user]
58         group node[:wordpress][:group]
59         ignore_failure plugin_repository.start_with?("http://plugins.svn.wordpress.org/")
60       end
61     end
62   end
63 end
64
65 action :delete do
66   directory plugin_directory do
67     action :delete
68     recursive true
69   end
70 end
71
72 action_class do
73   def site_directory
74     node[:wordpress][:sites][new_resource.site][:directory]
75   end
76
77   def plugin_directory
78     "#{site_directory}/wp-content/plugins/#{new_resource.plugin}"
79   end
80
81   def default_repository
82     version = new_resource.version ||
83               Chef::Wordpress.current_plugin_version(new_resource.plugin)
84
85     if version =~ /trunk/
86       "http://plugins.svn.wordpress.org/#{new_resource.plugin}/trunk"
87     else
88       "http://plugins.svn.wordpress.org/#{new_resource.plugin}/tags/#{version}"
89     end
90   end
91 end
92
93 def after_created
94   notifies :reload, "service[apache2]" if reload_apache
95 end