/** * 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; } }
/** * Validate the provided state file against each region's schema. * * @param array $yaml Data from the state file */ private function validate_state_data($yaml) { if (empty($yaml['state']) || !Dictator::is_valid_state($yaml['state'])) { WP_CLI::error("Incorrect state."); } $yaml_data = $yaml; unset($yaml_data['state']); $state_obj = Dictator::get_state_obj($yaml['state'], $yaml_data); $has_errors = false; foreach ($state_obj->get_regions() as $region) { $translator = new \Dictator\Translator($region); if (!$translator->is_valid_state_data()) { foreach ($translator->get_state_data_errors() as $error_message) { WP_CLI::warning($error_message); } $has_errors = true; } } if ($has_errors) { WP_CLI::error("State doesn't validate."); } return true; }
<?php /** * Dictator controls the State of WordPress with WP-CLI * * Use wisely. */ if (!defined('WP_CLI') || !WP_CLI) { return; } define('DICTATOR', true); /** * Some files need to be manually loaded */ require_once dirname(__FILE__) . '/autoload.php'; require_once dirname(__FILE__) . '/php/class-dictator.php'; require_once dirname(__FILE__) . '/php/class-dictator-translator.php'; require_once dirname(__FILE__) . '/php/class-dictator-cli-command.php'; Dictator::add_state('network', '\\Dictator\\States\\Network'); Dictator::add_state('site', '\\Dictator\\States\\Site');
/** * 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; } }
/** * Get the schema object for a state * * @param string $name Name of the state * @return object|false */ public static function get_state_schema_obj($name) { if (self::called_statically()) { return Dictator::get_instance()->get_state_schema($name); } if (!isset(self::$instance->states[$name])) { return false; } $state = self::$instance->states[$name]; $schema_file = $state['schema']; if (!file_exists($schema_file)) { $schema_file = dirname(dirname(__FILE__)) . '/schemas/' . $schema_file; } $schema_yaml = spyc_load(file_get_contents($schema_file)); return new MetaYaml($schema_yaml); }