]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/providers/plugin.rb
move reverse queries back to pummelzacken
[chef.git] / cookbooks / wordpress / providers / plugin.rb
1 #
2 # Cookbook Name:: wordpress
3 # Provider:: 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 def whyrun_supported?
21   true
22 end
23
24 use_inline_resources
25
26 action :create do
27   if new_resource.source
28     remote_directory plugin_directory do
29       cookbook "wordpress"
30       source new_resource.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 0755
37     end
38   else
39     plugin_repository = new_resource.repository || default_repository
40
41     if plugin_repository.end_with?(".git")
42       git plugin_directory do
43         action :sync
44         repository plugin_repository
45         revision new_resource.revision
46         user node[:wordpress][:user]
47         group node[:wordpress][:group]
48       end
49     else
50       subversion plugin_directory do
51         action :sync
52         repository plugin_repository
53         user node[:wordpress][:user]
54         group node[:wordpress][:group]
55         ignore_failure plugin_repository.start_with?("http://plugins.svn.wordpress.org/")
56       end
57     end
58   end
59 end
60
61 action :delete do
62   directory plugin_directory do
63     action :delete
64     recursive true
65   end
66 end
67
68 private
69
70 def site_directory
71   node[:wordpress][:sites][new_resource.site][:directory]
72 end
73
74 def plugin_directory
75   "#{site_directory}/wp-content/plugins/#{new_resource.name}"
76 end
77
78 def default_repository
79   version = new_resource.version ||
80             Chef::Wordpress.current_plugin_version(new_resource.name)
81
82   if version =~ /trunk/
83     "http://plugins.svn.wordpress.org/#{new_resource.name}/trunk"
84   else
85     "http://plugins.svn.wordpress.org/#{new_resource.name}/tags/#{version}"
86   end
87 end