Skip to content

WP_CLI conditional gets repeatedly applied #41

Open

Description

@kadamwhite

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.

Activity

  1. kadamwhite commented on Aug 27, 2019

    @kadamwhite
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions