lib/avm/tools/runner/eac_wordpress_base0/data/load.rb in avm-tools-0.6.0 vs lib/avm/tools/runner/eac_wordpress_base0/data/load.rb in avm-tools-0.7.0

- old
+ new

@@ -15,26 +15,41 @@ DOC = <<~DOCUMENT Load utility for EacRailsBase instance. Usage: - __PROGRAM__ <dump-path> + __PROGRAM__ (<dump-path>|--source-instance=<source-instance>) + __PROGRAM__ -h | --help + + Options: + -h --help Show this screen. + -S --source-instance=<source-instance> Informa a instância a ser extraída o dump. DOCUMENT def run return ::Dev::Result.error("Dump \"#{dump_path}\" does not exist") unless ::File.exist?(dump_path) before_load load_dump + fix_web_addresses success("Dump loaded from \"#{dump_path}\"") end def dump_path_uncached - options.fetch('<dump-path>').to_s + return options.fetch('<dump-path>').to_s if options.fetch('<dump-path>').present? + return source_instance_dump_path if options.fetch('--source-instance').present? + + raise "Dump path unknown (Options: #{options})" end + def source_instance_dump_path + ::Avm::Stereotypes::EacWordpressBase0::Instance.by_id( + options.fetch('--source-instance') + ).data_dump + end + def load_dump info "Loading dump \"#{dump_path}\"..." ::EacRubyUtils::Envs.local.command('cat', dump_path).pipe(load_command).execute! end @@ -57,9 +72,18 @@ context(:instance).pg.psql_command_command(sql).execute! end def load_command context(:instance).pg.psql_command.prepend(['gzip', '-d', '@ESC_|']) + end + + def fix_web_addresses + info 'Fixing web addresses...' + run_sql(<<~SQL) + update wp_options + set option_value = '#{context(:instance).read_entry('url')}' + where option_name in ('siteurl', 'home') + SQL end end end end end