Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WP_CLI conditional gets repeatedly applied #41

Open
kadamwhite opened this issue Aug 27, 2019 · 1 comment
Open

WP_CLI conditional gets repeatedly applied #41

kadamwhite opened this issue Aug 27, 2019 · 1 comment

Comments

@kadamwhite
Copy link
Collaborator

kadamwhite commented Aug 27, 2019

Due to the changes in PR #35 which break the wp-settings.php require out into a multi-line if statement, repeated provisioner runs add more and more surrounding if statements. I attempted to play with the file_line configuration for about an hour but couldn't find any combination of flags or changes to the match value that would prevent that.

I then tried replacing that resource with a sed call:

	exec { 'adjust chassis wp-config.php':
		# Replace
		#     require_once( ABSPATH . 'wp-settings.php' );
		# with
		#     if ( ! defined( 'WP_CLI' ) ) {
		#         require_once( ABSPATH . 'wp-settings.php' );
		#     }
		# but only once.
		command => "sed -i 's|^require_once.*ABSPATH.*wp-settings.*|if ( ! defined( 'WP_CLI' ) ) {\n\trequire_once( ABSPATH . '\''wp-settings.php'\'' );\n}|g' /vagrant/wp-config.php",
		path    => ['/bin'],
		user    => 'vagrant',
		before  => Chassis::Wp[ $config['hosts'][0] ],
	}

but that (while it works on the command line) fails in puppet with the error

==> default: Notice: /Stage[main]/Core_dev::Config/Exec[adjust chassis wp-config.php]/returns:
/bin/sed: -e expression #1, char 68: unterminated `s' command

This is annoying, but it's not the end of the world, so I'm going to cut off my troubleshooting and open this issue to revisit instead.

@kadamwhite
Copy link
Collaborator Author

kadamwhite commented Aug 27, 2019

I do not understand why this variant does not work: I'd expect the '^' to ensure that the regex was applied to text starting that line, but intead this does not run on an unmodified wp-config.php.

	# Configure Chassis' wp-config.php per the WP Core Development guide:
	# http://docs.chassis.io/en/latest/guides/#wordpress-core-development
	file_line { 'adjust chassis wp-config.php':
		path               => '/vagrant/wp-config.php',
		append_on_no_match => false,
		multiple           => true,
		line               => "if ( ! defined( 'WP_CLI' ) ) {\n\trequire_once( ABSPATH . 'wp-settings.php' );\n}",
		match              => '^require_once.*ABSPATH.*wp-settings.php',
		# Configure wp-config.php before installing WordPress.
		before             => Chassis::Wp[ $config['hosts'][0] ],
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant