/** * Impose a given state file onto WordPress. * * ## OPTIONS * * <file> * : State file to impose * * [--regions=<regions>] * : Limit the imposition to one or more regions. * * @subcommand impose */ public function impose($args, $assoc_args) { list($file) = $args; $yaml = $this->load_state_file($file); $this->validate_state_data($yaml); $state_obj = Dictator::get_state_obj($yaml['state'], $yaml); $limited_regions = !empty($assoc_args['regions']) ? explode(',', $assoc_args['regions']) : array(); foreach ($state_obj->get_regions() as $region_obj) { $region_name = $state_obj->get_region_name($region_obj); if ($limited_regions && !in_array($region_name, $limited_regions)) { continue; } if ($region_obj->is_under_accord()) { continue; } WP_CLI::line(sprintf('%s:', $region_name)); // Render the differences for the region $differences = $region_obj->get_differences(); foreach ($differences as $slug => $difference) { $this->show_difference($slug, $difference); $to_impose = \Dictator::array_diff_recursive($difference['dictated'], $difference['current']); $ret = $region_obj->impose($slug, $difference['dictated']); if (is_wp_error($ret)) { WP_CLI::warning($ret->get_error_message()); } } } WP_CLI::success("The Dictator has imposed upon the State of WordPress."); }
/** * Get the differences between the state file and WordPress * * @return array */ public function get_differences() { $result = array('dictated' => $this->get_imposed_data(), 'current' => $this->get_current_data()); if (\Dictator::array_diff_recursive($result['dictated'], $result['current'])) { return array('option' => $result); } else { return array(); } }
/** * Get the difference between the declared taxonomy state and * the actual taxonomy state * * @param string $taxonomy * @param array $taxonomy_data * @return array|false */ protected function get_taxonomy_difference($taxonomy, $taxonomy_data) { $result = array('dictated' => $taxonomy_data, 'current' => array()); $current_data = $this->get_current_data(); if (!isset($current_data[$taxonomy])) { return $result; } $result['current'] = $current_data[$taxonomy]; if (\Dictator::array_diff_recursive($result['dictated'], $result['current'])) { return $result; } else { return false; } }
/** * Get the difference of the site data to the site on the network * * @param string $site_slug * @param array $site_data * @return array|false */ protected function get_site_difference($site_slug, $site_data) { $site_result = array('dictated' => $site_data, 'current' => array()); $sites = $this->get_current_data(); // If there wasn't a matched site, the site must not exist if (empty($sites[$site_slug])) { return $site_result; } $site_result['current'] = $sites[$site_slug]; if (\Dictator::array_diff_recursive($site_result['dictated'], $site_result['current'])) { return $site_result; } else { return false; } }