dkdeploy-typo3-cms 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rubocop.yml +23 -0
  4. data/.travis.yml +12 -0
  5. data/Berksfile +3 -0
  6. data/Berksfile.lock +66 -0
  7. data/CHANGELOG.md +12 -0
  8. data/CONTRIBUTORS.md +16 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE +7 -0
  11. data/README.md +87 -0
  12. data/Rakefile +1 -0
  13. data/Vagrantfile +62 -0
  14. data/assets/dkdeploy-logo.png +0 -0
  15. data/config/vm/cookbooks/dkdeploy-typo3-cms/metadata.rb +12 -0
  16. data/config/vm/cookbooks/dkdeploy-typo3-cms/recipes/default.rb +71 -0
  17. data/dkdeploy-typo3-cms.gemspec +29 -0
  18. data/features/advanced_typo3.feature +156 -0
  19. data/features/caretaker_key_management.feature +36 -0
  20. data/features/clear_cache_on_rollback.feature +17 -0
  21. data/features/cli.feature +61 -0
  22. data/features/step_definitions/mysql.rb +75 -0
  23. data/features/step_definitions/typo3.rb +16 -0
  24. data/features/support/env.rb +11 -0
  25. data/features/typo3.feature +100 -0
  26. data/features/typoscript_upload_and_merge_config.feature +128 -0
  27. data/features/typoscript_upload_and_merge_pagets.feature +128 -0
  28. data/features/typoscript_upload_and_merge_userts.feature +128 -0
  29. data/features/update_database.feature +23 -0
  30. data/lib/capistrano/dkdeploy/typo3_cms.rb +37 -0
  31. data/lib/dkdeploy/typo3/cms.rb +1 -0
  32. data/lib/dkdeploy/typo3/cms/dsl.rb +27 -0
  33. data/lib/dkdeploy/typo3/cms/helpers/cli.rb +165 -0
  34. data/lib/dkdeploy/typo3/cms/helpers/erb.rb +25 -0
  35. data/lib/dkdeploy/typo3/cms/i18n.rb +111 -0
  36. data/lib/dkdeploy/typo3/cms/tasks/cache.rake +18 -0
  37. data/lib/dkdeploy/typo3/cms/tasks/caretaker_key_management.rake +60 -0
  38. data/lib/dkdeploy/typo3/cms/tasks/cli.rake +45 -0
  39. data/lib/dkdeploy/typo3/cms/tasks/typo3.rake +272 -0
  40. data/lib/dkdeploy/typo3/cms/tasks/typoscript.rake +288 -0
  41. data/lib/dkdeploy/typo3/cms/version.rb +16 -0
  42. data/spec/fixtures/application/Capfile +8 -0
  43. data/spec/fixtures/application/Gemfile +3 -0
  44. data/spec/fixtures/application/config/deploy.rb +8 -0
  45. data/spec/fixtures/application/config/deploy/dev.rb +41 -0
  46. data/spec/fixtures/application/htdocs/.hidden/.gitkeep +0 -0
  47. data/spec/fixtures/application/htdocs/catalog/index.html +1 -0
  48. data/spec/fixtures/application/htdocs/composer.json +24 -0
  49. data/spec/fixtures/application/htdocs/typo3/cli_dispatch.phpsh +2 -0
  50. data/spec/fixtures/application/htdocs/typo3conf/AdditionalConfiguration.php +3 -0
  51. data/spec/fixtures/application/htdocs/typo3conf/LocalConfiguration.php +28 -0
  52. data/spec/fixtures/application/htdocs/typo3conf/PackageStates.php +358 -0
  53. data/spec/fixtures/application/vendor/composer.phar +0 -0
  54. data/spec/fixtures/capistrano/configuration/additional_configuration_for_server.rb +1 -0
  55. data/spec/fixtures/capistrano/configuration/cli_break_after_one_run_in_release_path.rb +14 -0
  56. data/spec/fixtures/capistrano/configuration/cli_break_after_three_runs_in_release_path.rb +14 -0
  57. data/spec/fixtures/capistrano/configuration/cli_test_tasks.rb +19 -0
  58. data/spec/fixtures/capistrano/configuration/cli_test_tasks_with_path.rb +15 -0
  59. data/vendor/AdditionalConfiguration.php.erb +57 -0
  60. data/vendor/create_caretaker_instance_keys.php.erb +18 -0
  61. metadata +222 -0
@@ -0,0 +1,272 @@
1
+ require 'securerandom'
2
+ require 'digest/md5'
3
+ require 'dkdeploy/typo3/cms/dsl'
4
+ require 'dkdeploy/typo3/cms/i18n'
5
+ require 'dkdeploy/helpers/common'
6
+ require 'dkdeploy/interaction_handler/password'
7
+ require 'phpass'
8
+ require 'shellwords'
9
+
10
+ require 'erb'
11
+ require 'dkdeploy/typo3/cms/helpers/erb'
12
+
13
+ include Dkdeploy::Typo3::Cms::Helpers::Erb
14
+ include Dkdeploy::Helpers::Common
15
+ include Dkdeploy::Typo3::DSL
16
+
17
+ namespace :typo3 do
18
+ namespace :cms do
19
+ desc 'Clear typo3temp directory'
20
+ task :clear_typo3temp do
21
+ on release_roles :app do
22
+ info I18n.t('tasks.clear_temp.clear', scope: :dkdeploy)
23
+ execute :rm, '-rf', File.join(release_path, 'typo3temp', '*')
24
+ end
25
+ end
26
+
27
+ desc 'Disable TYPO3 install tool'
28
+ task :disable_install_tool do
29
+ flag = File.join(current_path, 'typo3conf', 'ENABLE_INSTALL_TOOL')
30
+
31
+ on release_roles :app do
32
+ if test "[ -f #{flag} ]"
33
+ info I18n.t('tasks.install_tool.disable', scope: :dkdeploy)
34
+ execute :rm, flag
35
+ end
36
+ end
37
+ end
38
+
39
+ desc 'Enable TYPO3 install tool'
40
+ task :enable_install_tool do
41
+ on release_roles :app do
42
+ info I18n.t('tasks.install_tool.enable', scope: :dkdeploy)
43
+ execute :mkdir, '-p', File.join(current_path, 'typo3conf')
44
+ execute :touch, File.join(current_path, 'typo3conf', 'ENABLE_INSTALL_TOOL')
45
+ end
46
+ end
47
+
48
+ desc 'Create TYPO3 database config file'
49
+ task :create_db_credentials do
50
+ on release_roles(:app), in: :sequence do |server|
51
+ db_settings = read_db_settings_for_context(self)
52
+ if db_settings.nil?
53
+ # No database settings found. Set database settings for current host
54
+ invoke_for_server server, 'db:upload_settings'
55
+ db_settings = read_db_settings_for_context(self)
56
+ end
57
+
58
+ config_file_content = <<CONFIG_FILE_CONTENT
59
+ <?php
60
+ $GLOBALS['TYPO3_CONF_VARS']['DB']['database'] = '#{db_settings.fetch('name')}';
61
+ $GLOBALS['TYPO3_CONF_VARS']['DB']['host'] = '#{db_settings.fetch('host')}';
62
+ $GLOBALS['TYPO3_CONF_VARS']['DB']['username'] = '#{db_settings.fetch('username')}';
63
+ $GLOBALS['TYPO3_CONF_VARS']['DB']['password'] = '#{db_settings.fetch('password')}';
64
+ $GLOBALS['TYPO3_CONF_VARS']['DB']['port'] = #{db_settings.fetch('port')};
65
+ CONFIG_FILE_CONTENT
66
+
67
+ upload! StringIO.new(config_file_content), File.join(shared_path, 'config', "db_settings.#{fetch(:stage)}.php")
68
+ end
69
+ end
70
+
71
+ desc 'Download extension to local workspace'
72
+ task :fetch_extension, :extension do |_, args|
73
+ extension = ask_variable(args, :extension, 'tasks.fetch_extension.extension_name')
74
+ FileUtils.mkdir_p File.join('temp', 'extensions')
75
+ FileUtils.remove_dir File.join('temp', 'extensions', extension), true
76
+ source = File.join(current_path, 'typo3conf', 'ext', extension)
77
+ target = File.join('temp', 'extensions')
78
+
79
+ on primary(:backend) do
80
+ if test "[ -d #{File.join(current_path, 'typo3conf', 'ext', extension)} ]"
81
+ # download to temp
82
+ info I18n.t('tasks.fetch_extension.download', extension: extension, scope: :dkdeploy)
83
+ download! source, target, via: :scp, recursive: true
84
+ else
85
+ error I18n.t('tasks.fetch_extension.extension_not_found', extension: extension, scope: :dkdeploy)
86
+ exit 1
87
+ end
88
+ end
89
+
90
+ run_locally do
91
+ # rsync to htdocs/typo3temp/ext
92
+ info I18n.t('tasks.fetch_extension.rsync', extension: extension, scope: :dkdeploy)
93
+ rsync_excludes = []
94
+ rsync_exclude_directories = %w(.git/ .svn/)
95
+ rsync_exclude_directories.each do |exclude|
96
+ rsync_excludes << '--exclude=' + exclude
97
+ end
98
+ execute :rsync, '-vrS', '--force', '-C', '--delete', rsync_excludes, File.join('temp', 'extensions', extension, '/'), File.join('htdocs', 'typo3conf', 'ext', extension, '/')
99
+ end
100
+ end
101
+
102
+ desc 'Output a generated encryption key'
103
+ task :generate_encryption_key do
104
+ puts SecureRandom.hex(48)
105
+ end
106
+
107
+ desc 'Create encryption key file on server'
108
+ task :create_encryption_key_file, :encryption_key do |_, args|
109
+ encryption_key_file_path = File.join(shared_path, 'config')
110
+ encryption_key_file = File.join(encryption_key_file_path, 'encryption_key.php')
111
+ encryption_key = ask_variable(args, :encryption_key, 'tasks.encryption_key.enter_key') { |question| question.echo = '*' }
112
+ encryption_key.strip!
113
+
114
+ if encryption_key.empty? || encryption_key.length < 8
115
+ abort I18n.t('tasks.encryption_key.validation_error', scope: :dkdeploy)
116
+ end
117
+
118
+ encryption_key_file_content = "<?php $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '#{encryption_key}';"
119
+
120
+ on release_roles :app do ||
121
+ execute :mkdir, '-p', encryption_key_file_path
122
+ upload! StringIO.new(encryption_key_file_content), encryption_key_file
123
+ end
124
+ end
125
+
126
+ desc 'Create install tool password file on server'
127
+ task :create_install_tool_password_file, :password do |_, args|
128
+ install_tool_file_path = File.join(shared_path, 'config')
129
+ install_tool_file = File.join(install_tool_file_path, 'install_tool_password.php')
130
+ password = ask_variable(args, :password, 'tasks.install_tool_password.enter_password') { |question| question.echo = '*' }
131
+ password.strip!
132
+
133
+ if password.empty?
134
+ abort I18n.t('tasks.install_tool_password.validation_error', scope: :dkdeploy)
135
+ end
136
+
137
+ password = Phpass.new.hash password
138
+ password_file_content = "<?php $GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'] = '#{password}';"
139
+
140
+ on release_roles :app do ||
141
+ execute :mkdir, '-p', install_tool_file_path
142
+ upload! StringIO.new(password_file_content), install_tool_file
143
+ end
144
+ end
145
+
146
+ desc 'Add TYPO3 admin backend user'
147
+ task :add_admin_user, :typo3_username, :typo3_password do |_, args|
148
+ remote_db_file_path = File.join(shared_path, 'config')
149
+ remote_db_file = File.join(remote_db_file_path, "be-admin-user-#{fetch(:stage)}.sql")
150
+ typo3_username = ask_variable(args, :typo3_username, 'tasks.db.username')
151
+ typo3_password = ask_variable(args, :typo3_password, 'tasks.db.password') { |question| question.echo = '*' }
152
+ now = Time.now.to_i
153
+
154
+ sql_string = "INSERT INTO be_users (username, password, admin, tstamp, crdate)
155
+ VALUES ('#{typo3_username}', MD5('#{typo3_password}'), 1, #{now}, #{now});"
156
+
157
+ on primary :backend do
158
+ begin
159
+ db_settings = read_db_settings_for_context(self)
160
+ execute :mkdir, '-p', remote_db_file_path
161
+ execute :rm, '-rf', remote_db_file
162
+
163
+ upload! StringIO.new(sql_string), remote_db_file
164
+ execute :mysql,
165
+ "--default-character-set=#{db_settings.fetch('charset')}",
166
+ '-u', db_settings.fetch('username'),
167
+ '-p',
168
+ '-h', db_settings.fetch('host'), '-P', db_settings.fetch('port'), db_settings.fetch('name'),
169
+ '-e', "'source #{remote_db_file}'",
170
+ interaction_handler: Dkdeploy::InteractionHandler::Password.new(db_settings.fetch('password'))
171
+ ensure
172
+ execute :rm, '-rf', remote_db_file
173
+ end
174
+ end
175
+ end
176
+
177
+ desc 'Create configured directories for TYPO3 extensions'
178
+ task :fix_folder_structure do
179
+ typo3_console 'install:fixfolderstructure'
180
+ end
181
+
182
+ desc 'Clear TYPO3 caches'
183
+ task :clear_cache do |task|
184
+ typo3_console 'cache:flush', true
185
+ task.reenable
186
+ end
187
+
188
+ desc 'update_tables'
189
+ task :update_database do
190
+ again = nil
191
+ capture_typo3_console_in_loop 10, 'database:updateschema', 'safe,*.prefix'.shellescape, '--verbose' do |output,_,context|
192
+ context.info output
193
+ again = !output.include?('No schema updates were performed for update types')
194
+ end
195
+
196
+ if again # if again ist true we ran loop 10 times and need to issue a warning
197
+ run_locally do
198
+ warn I18n.t('tasks.typo3.cms.update_database.still_updates_available', scope: :dkdeploy)
199
+ end
200
+ end
201
+ end
202
+
203
+ # Deactivate Task. Wait for https://github.com/TYPO3-Console/typo3_console/pull/288
204
+ # desc 'add_static_db_content'
205
+ # task :add_static_db_content do
206
+ # typo3_console 'database:importstaticdata'
207
+ # end
208
+
209
+ desc 'Update translations for core and extensions (l10n)'
210
+ task :update_translations, :typo3_languages_to_translate do |_, args|
211
+ typo3_languages_to_translate = ask_variable(args, :typo3_languages_to_translate, 'questions.typo3_languages_to_translate')
212
+ typo3_console 'language:update', typo3_languages_to_translate
213
+ end
214
+
215
+ desc 'Remove not needed extensions'
216
+ task :remove_extensions do
217
+ installed_extensions = (capture_typo3_console_in_loop 1, 'extension:list', '--active', '--raw').split("\n")
218
+
219
+ run_locally do
220
+ info installed_extensions.inspect
221
+ if installed_extensions.empty?
222
+ raise I18n.t('tasks.typo3.cms.v6.remove_extensions.no_extension_found', scope: :dkdeploy)
223
+ end
224
+ end
225
+
226
+ on roles :app do
227
+ # Get extensions from typo3conf/ext directory
228
+ remote_list = capture(:ls, '-x', File.join(current_path, 'typo3conf', 'ext')).split
229
+
230
+ extensions_to_remove = (remote_list - installed_extensions)
231
+ unless extensions_to_remove.empty?
232
+ info I18n.t('tasks.typo3.cms.v6.remove_extensions.info', scope: :dkdeploy, removed_extensions: extensions_to_remove.join(', '))
233
+ extensions_to_remove.each do |extension|
234
+ execute :rm, '-rf', "#{release_path}/typo3conf/ext/#{extension}"
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ desc 'Generate AdditionalConfiguration.php.erb for your project'
241
+ task :generate_additional_configuration_template, :additional_configuration_template do |_, args|
242
+ configuration_template = ask_variable(args, :additional_configuration_template, 'questions.additional_configuration_template')
243
+ run_locally do
244
+ if test("[ -f #{configuration_template} ]")
245
+ info I18n.t('tasks.typo3.cms.v6.generate_additional_configuration_template.info', scope: :dkdeploy, local_configuration_template: configuration_template)
246
+ exit 0
247
+ else
248
+ execute :mkdir, '-p', File.dirname(configuration_template)
249
+ File.write configuration_template, File.read(default_template_file)
250
+ end
251
+ end
252
+ end
253
+
254
+ desc 'Sets up the TYPO3 6+ specific configuration for each stage'
255
+ task :setup_additional_configuration, :additional_configuration_template do |_, args|
256
+ configuration_template = ask_variable(args, :additional_configuration_template, 'questions.additional_configuration_template')
257
+ remote_configuration_file = File.join(release_path, 'typo3conf', 'AdditionalConfiguration.php')
258
+ unless File.exist?(configuration_template)
259
+ run_locally do
260
+ raise I18n.t('tasks.typo3.cms.v6.setup_additional_configuration.upload_info', configuration_template: configuration_template, scope: :dkdeploy)
261
+ end
262
+ end
263
+
264
+ on roles :app do |server|
265
+ # Variable "server" need for the template rendering. "server.fetch(:additional_configuration_file)"
266
+ merged_template = ERB.new File.read(configuration_template), nil, '>'
267
+ upload! StringIO.new(merged_template.result(binding)), remote_configuration_file, scp: true
268
+ info I18n.t('tasks.typo3.cms.v6.setup_additional_configuration.upload_info', scope: :dkdeploy, remote_configuration_file: remote_configuration_file)
269
+ end
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,288 @@
1
+ require 'pathname'
2
+ require 'dkdeploy/typo3/cms/i18n'
3
+ require 'dkdeploy/helpers/common'
4
+
5
+ include Dkdeploy::Helpers::Common
6
+
7
+ namespace :typo3 do
8
+ namespace :cms do
9
+ namespace :typoscript do
10
+ desc "Uploads TypoScript config files from local paths prefixed by variable 'copy_source'"
11
+ task :upload_configs, :copy_source, :typoscript_config_paths, :typoscript_config_file do |_, args|
12
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
13
+ paths = ask_array_variable(args, :typoscript_config_paths, 'tasks.typoscript.config_paths') { |question| question.default = '' }
14
+ config_file = ask_variable(args, :typoscript_config_file, 'tasks.typoscript.config_file') { |question| question.default = 'config.txt' }
15
+
16
+ paths.each do |path|
17
+ local_path = File.join(prefix, path)
18
+ local_config_file = File.join(local_path, config_file)
19
+ remote_path = File.join(current_path, path)
20
+ remote_config_file = File.join(remote_path, config_file)
21
+
22
+ unless File.exist? local_config_file
23
+ run_locally do
24
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: local_config_file, scope: :dkdeploy)
25
+ end
26
+ next
27
+ end
28
+
29
+ on release_roles :app do
30
+ execute :mkdir, '-p', remote_path
31
+ info I18n.t('tasks.typoscript.uploading', local_file: local_config_file, remote_file: remote_config_file, scope: :dkdeploy)
32
+ upload! local_config_file, remote_config_file
33
+ info I18n.t('tasks.typoscript.uploaded', local_file: local_config_file, remote_file: remote_config_file, scope: :dkdeploy)
34
+ end
35
+ end
36
+ end
37
+
38
+ desc "Uploads PageTS files from local paths prefixed by variable 'copy_source'"
39
+ task :upload_pagets, :copy_source, :typoscript_pagets_paths, :typoscript_pagets_file do |_, args|
40
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
41
+ paths = ask_array_variable(args, :typoscript_pagets_paths, 'tasks.typoscript.pagets_paths') { |question| question.default = '' }
42
+ pagets_file = ask_variable(args, :typoscript_pagets_file, 'tasks.typoscript.pagets_file') { |question| question.default = 'PageTS.txt' }
43
+
44
+ paths.each do |path|
45
+ local_path = File.join(prefix, path)
46
+ local_pagets_file = File.join(local_path, pagets_file)
47
+ remote_path = File.join(current_path, path)
48
+ remote_pagets_file = File.join(remote_path, pagets_file)
49
+
50
+ unless File.exist? local_pagets_file
51
+ run_locally do
52
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: local_pagets_file, scope: :dkdeploy)
53
+ end
54
+ next
55
+ end
56
+
57
+ on release_roles :app do
58
+ execute :mkdir, '-p', remote_path
59
+ info I18n.t('tasks.typoscript.uploading', local_file: local_pagets_file, remote_file: remote_pagets_file, scope: :dkdeploy)
60
+ upload! local_pagets_file, remote_pagets_file
61
+ info I18n.t('tasks.typoscript.uploaded', local_file: local_pagets_file, remote_file: remote_pagets_file, scope: :dkdeploy)
62
+ end
63
+ end
64
+ end
65
+
66
+ desc "Uploads UserTS files from local paths prefixed by variable 'copy_source'"
67
+ task :upload_userts, :copy_source, :typoscript_userts_paths, :typoscript_userts_file do |_, args|
68
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
69
+ paths = ask_array_variable(args, :typoscript_userts_paths, 'tasks.typoscript.userts_paths') { |question| question.default = '' }
70
+ userts_file = ask_variable(args, :typoscript_userts_file, 'tasks.typoscript.userts_file') { |question| question.default = 'UserTS.txt' }
71
+
72
+ paths.each do |path|
73
+ local_path = File.join(prefix, path)
74
+ local_userts_file = File.join(local_path, userts_file)
75
+ remote_path = File.join(current_path, path)
76
+ remote_userts_file = File.join(remote_path, userts_file)
77
+
78
+ unless File.exist? local_userts_file
79
+ run_locally do
80
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: local_userts_file, scope: :dkdeploy)
81
+ end
82
+ next
83
+ end
84
+
85
+ on release_roles :app do
86
+ execute :mkdir, '-p', remote_path
87
+ info I18n.t('tasks.typoscript.uploading', local_file: local_userts_file, remote_file: remote_userts_file, scope: :dkdeploy)
88
+ upload! local_userts_file, remote_userts_file
89
+ info I18n.t('tasks.typoscript.uploaded', local_file: local_userts_file, remote_file: remote_userts_file, scope: :dkdeploy)
90
+ end
91
+ end
92
+ end
93
+
94
+ desc 'Uploads all config files from given base path'
95
+ task :upload_config_from_base_path, :copy_source, :typoscript_config_base_path, :typoscript_config_file do |_, args|
96
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
97
+ base_path = ask_variable(args, :typoscript_config_base_path, 'tasks.typoscript.typoscript_config_base_path') { |question| question.default = '.' }
98
+ config_file = ask_variable(args, :typoscript_config_file, 'tasks.typoscript.config_file') { |question| question.default = 'config.txt' }
99
+
100
+ config_files = Dir[File.join(prefix, base_path, '**', config_file).to_s].map { |path_for_config_file| Pathname.new(path_for_config_file).relative_path_from(Pathname.new(prefix)).dirname.to_s }
101
+
102
+ next if config_files.empty?
103
+
104
+ set :copy_source, prefix
105
+ set :typoscript_config_paths, config_files
106
+ set :typoscript_config_file, config_file
107
+ invoke 'typo3:cms:typoscript:upload_configs'
108
+ end
109
+
110
+ desc 'Uploads all PageTS files from given base path'
111
+ task :upload_pagets_from_base_path, :copy_source, :typoscript_pagets_base_path, :typoscript_pagets_file do |_, args|
112
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
113
+ base_path = ask_variable(args, :typoscript_pagets_base_path, 'tasks.typoscript.typoscript_pagets_base_path') { |question| question.default = '.' }
114
+ pagets_file = ask_variable(args, :typoscript_pagets_file, 'tasks.typoscript.pagets_file') { |question| question.default = 'PageTS.txt' }
115
+
116
+ pagets_files = Dir[File.join(prefix, base_path, '**', pagets_file).to_s].map { |path_for_pagets_file| Pathname.new(path_for_pagets_file).relative_path_from(Pathname.new(prefix)).dirname.to_s }
117
+ next if pagets_files.empty?
118
+
119
+ set :copy_source, prefix
120
+ set :typoscript_pagets_paths, pagets_files
121
+ set :typoscript_pagets_file, pagets_file
122
+ invoke 'typo3:cms:typoscript:upload_pagets'
123
+ end
124
+
125
+ desc 'Uploads all UserTS files from given base path'
126
+ task 'upload_userts_from_base_path', :copy_source, :typoscript_userts_base_path, :typoscript_userts_file do |_, args|
127
+ prefix = ask_variable(args, :copy_source, 'tasks.typoscript.copy_source') { |question| question.default = 'htdocs' }
128
+ base_path = ask_variable(args, :typoscript_userts_base_path, 'tasks.typoscript.typoscript_userts_base_path') { |question| question.default = '.' }
129
+ userts_file = ask_variable(args, :typoscript_userts_file, 'tasks.typoscript.userts_file') { |question| question.default = 'UserTS.txt' }
130
+
131
+ userts_files = Dir[File.join(prefix, base_path, '**', userts_file).to_s].map { |path_for_userts_file| Pathname.new(path_for_userts_file).relative_path_from(Pathname.new(prefix)).dirname.to_s }
132
+ next if userts_files.empty?
133
+
134
+ set :copy_source, prefix
135
+ set :typoscript_userts_paths, userts_files
136
+ set :typoscript_userts_file, userts_file
137
+ invoke 'typo3:cms:typoscript:upload_userts'
138
+ end
139
+
140
+ desc 'Merge remote TypoScript config files'
141
+ task :merge_configs, :typoscript_config_paths, :typoscript_config_file do |_, args|
142
+ paths = ask_array_variable(args, :typoscript_config_paths, 'tasks.typoscript.config_paths')
143
+ config_file = ask_variable(args, :typoscript_config_file, 'tasks.typoscript.config_file') { |question| question.default = 'config.txt' }
144
+
145
+ paths.each do |path|
146
+ path = File.join(release_path, path)
147
+
148
+ target_config_file_with_stage_name = config_file.split('.').join(".#{fetch(:stage)}.")
149
+ source_config_file = File.join(path, 'Stages', target_config_file_with_stage_name)
150
+ target_config_file = File.join(path, config_file)
151
+
152
+ on release_roles :app do
153
+ unless test "[ -d #{path} ]"
154
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: path, scope: :dkdeploy)
155
+ next
156
+ end
157
+
158
+ unless test "[ -f #{source_config_file} ]"
159
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: source_config_file, scope: :dkdeploy)
160
+ next
161
+ end
162
+
163
+ execute :echo, "''", '>>', target_config_file
164
+ execute :cat, source_config_file, '>>', target_config_file
165
+ info I18n.t('tasks.typoscript.merged', source_file: source_config_file, target_file: target_config_file, scope: :dkdeploy)
166
+ end
167
+ end
168
+ end
169
+
170
+ desc 'Merge remote PageTS files'
171
+ task :merge_pagets, :typoscript_pagets_paths, :typoscript_pagets_file do |_, args|
172
+ paths = ask_array_variable(args, :typoscript_pagets_paths, 'tasks.typoscript.pagets_paths')
173
+ pagets_file = ask_variable(args, :typoscript_pagets_file, 'tasks.typoscript.pagets_file') { |question| question.default = 'PageTS.txt' }
174
+
175
+ paths.each do |path|
176
+ path = File.join(release_path, path)
177
+
178
+ target_pagets_file_with_stage_name = pagets_file.split('.').join(".#{fetch(:stage)}.")
179
+ source_pagets_file = File.join(path, 'Stages', target_pagets_file_with_stage_name)
180
+ target_pagets_file = File.join(path, pagets_file)
181
+
182
+ on release_roles :app do
183
+ unless test "[ -d #{path} ]"
184
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: path, scope: :dkdeploy)
185
+ next
186
+ end
187
+
188
+ unless test "[ -f #{source_pagets_file} ]"
189
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: source_pagets_file, scope: :dkdeploy)
190
+ next
191
+ end
192
+
193
+ execute :echo, "''", '>>', target_pagets_file
194
+ execute :cat, source_pagets_file, '>>', target_pagets_file
195
+ info I18n.t('tasks.typoscript.merged', source_file: source_pagets_file, target_file: target_pagets_file, scope: :dkdeploy)
196
+ end
197
+ end
198
+ end
199
+
200
+ desc 'Merge remote UserTS files'
201
+ task :merge_userts, :typoscript_userts_paths, :typoscript_userts_file do |_, args|
202
+ paths = ask_array_variable(args, :typoscript_userts_paths, 'tasks.typoscript.userts_paths')
203
+ userts_file = ask_variable(args, :typoscript_userts_file, 'tasks.typoscript.userts_file') { |question| question.default = 'UserTS.txt' }
204
+
205
+ paths.each do |path|
206
+ path = File.join(release_path, path)
207
+
208
+ target_userts_file_with_stage_name = userts_file.split('.').join(".#{fetch(:stage)}.")
209
+ source_userts_file = File.join(path, 'Stages', target_userts_file_with_stage_name)
210
+ target_userts_file = File.join(path, userts_file)
211
+
212
+ on release_roles :app do
213
+ unless test "[ -d #{path} ]"
214
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: path, scope: :dkdeploy)
215
+ next
216
+ end
217
+
218
+ unless test "[ -f #{source_userts_file} ]"
219
+ info I18n.t('tasks.typoscript.skipping', file_or_directory: source_userts_file, scope: :dkdeploy)
220
+ next
221
+ end
222
+
223
+ execute :echo, "''", '>>', target_userts_file
224
+ execute :cat, source_userts_file, '>>', target_userts_file
225
+ info I18n.t('tasks.typoscript.merged', source_file: source_userts_file, target_file: target_userts_file, scope: :dkdeploy)
226
+ end
227
+ end
228
+ end
229
+
230
+ desc 'Merge all remote config files for a given base path'
231
+ task :merge_config_in_base_path, :typoscript_config_base_path, :typoscript_config_file do |_, args|
232
+ base_path = ask_variable(args, :typoscript_config_base_path, 'tasks.typoscript.typoscript_config_base_path') { |question| question.default = '.' }
233
+ config_file = ask_variable(args, :typoscript_config_file, 'tasks.typoscript.config_file') { |question| question.default = 'config.txt' }
234
+
235
+ list_of_files = ''
236
+ target_config_file_with_stage_name = config_file.split('.').join(".#{fetch(:stage)}.")
237
+ on primary :app do
238
+ list_of_files = capture :find, File.join(release_path, base_path), '-type f', "-name '#{target_config_file_with_stage_name}'"
239
+ end
240
+
241
+ next if list_of_files.empty?
242
+ config_files = list_of_files.split.map { |file| Pathname.new(file).relative_path_from(Pathname.new(release_path)).dirname.dirname.to_s }
243
+
244
+ set :typoscript_config_paths, config_files
245
+ set :typoscript_config_file, config_file
246
+ invoke 'typo3:cms:typoscript:merge_configs'
247
+ end
248
+
249
+ desc 'Merge all remote PageTS files for a given base path'
250
+ task :merge_pagets_in_base_path, :typoscript_pagets_base_path, :typoscript_pagets_file do |_, args|
251
+ base_path = ask_variable(args, :typoscript_pagets_base_path, 'tasks.typoscript.typoscript_pagets_base_path') { |question| question.default = '.' }
252
+ pagets_file = ask_variable(args, :typoscript_pagets_file, 'tasks.typoscript.pagets_file') { |question| question.default = 'PageTS.txt' }
253
+
254
+ list_of_files = ''
255
+ target_pagets_file_with_stage_name = pagets_file.split('.').join(".#{fetch(:stage)}.")
256
+ on primary :app do
257
+ list_of_files = capture :find, File.join(release_path, base_path), '-type f', "-name '#{target_pagets_file_with_stage_name}'"
258
+ end
259
+
260
+ next if list_of_files.empty?
261
+ pagets_files = list_of_files.split.map { |file| Pathname.new(file).relative_path_from(Pathname.new(release_path)).dirname.dirname.to_s }
262
+
263
+ set :typoscript_pagets_paths, pagets_files
264
+ set :typoscript_pagets_file, pagets_file
265
+ invoke 'typo3:cms:typoscript:merge_pagets'
266
+ end
267
+
268
+ desc 'Merge all remote UserTS files for a given bbase path'
269
+ task :merge_userts_in_base_path, :typoscript_userts_base_path, :typoscript_userts_file do |_, args|
270
+ base_path = ask_variable(args, :typoscript_userts_base_path, 'tasks.typoscript.typoscript_userts_base_path') { |question| question.default = '.' }
271
+ userts_file = ask_variable(args, :typoscript_userts_file, 'tasks.typoscript.userts_file') { |question| question.default = 'UserTS.txt' }
272
+
273
+ list_of_files = ''
274
+ target_userts_file_with_stage_name = userts_file.split('.').join(".#{fetch(:stage)}.")
275
+ on primary :app do
276
+ list_of_files = capture :find, File.join(release_path, base_path), '-type f', "-name '#{target_userts_file_with_stage_name}'"
277
+ end
278
+
279
+ next if list_of_files.empty?
280
+ userts_files = list_of_files.split.map { |file| Pathname.new(file).relative_path_from(Pathname.new(release_path)).dirname.dirname.to_s }
281
+
282
+ set :typoscript_userts_paths, userts_files
283
+ set :typoscript_userts_file, userts_file
284
+ invoke 'typo3:cms:typoscript:merge_userts'
285
+ end
286
+ end
287
+ end
288
+ end