From 1a365e77dfb8825136626202b1df462731b42060 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 16 Aug 2015 08:22:05 +0200 Subject: Update to MediaWiki 1.25.2 --- .../elastica/lib/Elastica/Index/Settings.php | 318 +++++++++++++++++++++ .../ruflin/elastica/lib/Elastica/Index/Stats.php | 109 +++++++ .../ruflin/elastica/lib/Elastica/Index/Status.php | 144 ++++++++++ 3 files changed, 571 insertions(+) create mode 100644 vendor/ruflin/elastica/lib/Elastica/Index/Settings.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Index/Stats.php create mode 100644 vendor/ruflin/elastica/lib/Elastica/Index/Status.php (limited to 'vendor/ruflin/elastica/lib/Elastica/Index') diff --git a/vendor/ruflin/elastica/lib/Elastica/Index/Settings.php b/vendor/ruflin/elastica/lib/Elastica/Index/Settings.php new file mode 100644 index 00000000..2f2b90c6 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Index/Settings.php @@ -0,0 +1,318 @@ + + * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html + * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html + */ +class Settings +{ + /** + * Response + * + * @var \Elastica\Response Response object + */ + protected $_response = null; + + /** + * Stats info + * + * @var array Stats info + */ + protected $_data = array(); + + /** + * Index + * + * @var \Elastica\Index Index object + */ + protected $_index = null; + + const DEFAULT_REFRESH_INTERVAL = '1s'; + + /** + * Construct + * + * @param \Elastica\Index $index Index object + */ + public function __construct(BaseIndex $index) + { + $this->_index = $index; + } + + /** + * Returns the current settings of the index + * + * If param is set, only specified setting is return. + * 'index.' is added in front of $setting. + * + * @param string $setting OPTIONAL Setting name to return + * @return array|string|null Settings data + * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html + */ + public function get($setting = '') + { + $requestData = $this->request()->getData(); + $data = reset($requestData); + $settings = $data['settings']['index']; + + if (!empty($setting)) { + if (isset($settings[$setting])) { + return $settings[$setting]; + } else { + if (strpos($setting, '.') !== false) { + // translate old dot-notation settings to nested arrays + $keys = explode('.', $setting); + foreach ($keys as $key) { + if (isset($settings[$key])) { + $settings = $settings[$key]; + } else { + return null; + } + } + return $settings; + } + return null; + } + } + + return $settings; + } + + /** + * Sets the number of replicas + * + * @param int $replicas Number of replicas + * @return \Elastica\Response Response object + */ + public function setNumberOfReplicas($replicas) + { + $replicas = (int)$replicas; + + $data = array('number_of_replicas' => $replicas); + + return $this->set($data); + } + + /** + * Sets the index to read only + * + * @param bool $readOnly (default = true) + * @return \Elastica\Response + */ + public function setReadOnly($readOnly = true) + { + return $this->set(array('blocks.read_only' => $readOnly)); + } + + /** + * @return bool + */ + public function getBlocksRead() + { + return (bool)$this->get('blocks.read'); + } + + /** + * @param bool $state OPTIONAL (default = true) + * @return \Elastica\Response + */ + public function setBlocksRead($state = true) + { + $state = $state ? 1 : 0; + + return $this->set(array('blocks.read' => $state)); + } + + /** + * @return bool + */ + public function getBlocksWrite() + { + return (bool)$this->get('blocks.write'); + } + + /** + * @param bool $state OPTIONAL (default = true) + * @return \Elastica\Response + */ + public function setBlocksWrite($state = true) + { + $state = $state ? 1 : 0; + + return $this->set(array('blocks.write' => (int)$state)); + } + + /** + * @return bool + */ + public function getBlocksMetadata() + { + return (bool)$this->get('blocks.metadata'); + } + + /** + * @param bool $state OPTIONAL (default = true) + * @return \Elastica\Response + */ + public function setBlocksMetadata($state = true) + { + $state = $state ? 1 : 0; + + return $this->set(array('blocks.metadata' => (int)$state)); + } + + /** + * Sets the index refresh interval + * + * Value can be for example 3s for 3 seconds or + * 5m for 5 minutes. -1 refreshing is disabled. + * + * @param int $interval Number of seconds + * @return \Elastica\Response Response object + */ + public function setRefreshInterval($interval) + { + return $this->set(array('refresh_interval' => $interval)); + } + + /** + * Returns the refresh interval + * + * If no interval is set, the default interval is returned + * + * @return string Refresh interval + */ + public function getRefreshInterval() + { + $interval = $this->get('refresh_interval'); + + if (empty($interval)) { + $interval = self::DEFAULT_REFRESH_INTERVAL; + } + + return $interval; + } + + /** + * Return merge policy + * + * @return string Merge policy type + */ + public function getMergePolicyType() + { + + return $this->get('merge.policy.type'); + } + + /** + * Sets merge policy + * + * @param string $type Merge policy type + * @return \Elastica\Response Response object + * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html + */ + public function setMergePolicyType($type) + { + $this->getIndex()->close(); + $response = $this->set(array('merge.policy.type' => $type)); + $this->getIndex()->open(); + + return $response; + } + + /** + * Sets the specific merge policies + * + * To have this changes made the index has to be closed and reopened + * + * @param string $key Merge policy key (for ex. expunge_deletes_allowed) + * @param string $value + * @return \Elastica\Response + * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html + */ + public function setMergePolicy($key, $value) + { + $this->getIndex()->close(); + $response = $this->set(array('merge.policy.' . $key => $value)); + $this->getIndex()->open(); + + return $response; + } + + /** + * Returns the specific merge policy value + * + * @param string $key Merge policy key (for ex. expunge_deletes_allowed) + * @return string Refresh interval + * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html + */ + public function getMergePolicy($key) + { + $settings = $this->get(); + if (isset($settings['merge']['policy'][$key])) { + return $settings['merge']['policy'][$key]; + } + return null; + } + + /** + * Can be used to set/update settings + * + * @param array $data Arguments + * @return \Elastica\Response Response object + */ + public function set(array $data) + { + return $this->request($data, Request::PUT); + } + + /** + * Returns the index object + * + * @return \Elastica\Index Index object + */ + public function getIndex() + { + return $this->_index; + } + + /** + * Updates the given settings for the index + * + * With elasticsearch 0.16 the following settings are supported + * - index.term_index_interval + * - index.term_index_divisor + * - index.translog.flush_threshold_ops + * - index.translog.flush_threshold_size + * - index.translog.flush_threshold_period + * - index.refresh_interval + * - index.merge.policy + * - index.auto_expand_replicas + * + * @param array $data OPTIONAL Data array + * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET) + * @return \Elastica\Response Response object + */ + public function request(array $data = array(), $method = Request::GET) + { + $path = '_settings'; + + $data = array('index' => $data); + + return $this->getIndex()->request($path, $method, $data); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Index/Stats.php b/vendor/ruflin/elastica/lib/Elastica/Index/Stats.php new file mode 100644 index 00000000..9312e273 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Index/Stats.php @@ -0,0 +1,109 @@ + + * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-stats.html + */ +class Stats +{ + /** + * Response + * + * @var \Elastica\Response Response object + */ + protected $_response = null; + + /** + * Stats info + * + * @var array Stats info + */ + protected $_data = array(); + + /** + * Index + * + * @var \Elastica\Index Index object + */ + protected $_index = null; + + /** + * Construct + * + * @param \Elastica\Index $index Index object + */ + public function __construct(BaseIndex $index) + { + $this->_index = $index; + $this->refresh(); + } + + /** + * Returns the raw stats info + * + * @return array Stats info + */ + public function getData() + { + return $this->_data; + } + + /** + * Returns the entry in the data array based on the params. + * Various params possible. + * + * @return mixed Data array entry or null if not found + */ + public function get() + { + $data = $this->getData(); + + foreach (func_get_args() as $arg) { + if (isset($data[$arg])) { + $data = $data[$arg]; + } else { + return null; + } + } + + return $data; + } + + /** + * Returns the index object + * + * @return \Elastica\Index Index object + */ + public function getIndex() + { + return $this->_index; + } + + /** + * Returns response object + * + * @return \Elastica\Response Response object + */ + public function getResponse() + { + return $this->_response; + } + + /** + * Reloads all status data of this object + */ + public function refresh() + { + $path = '_stats'; + $this->_response = $this->getIndex()->request($path, Request::GET); + $this->_data = $this->getResponse()->getData(); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Index/Status.php b/vendor/ruflin/elastica/lib/Elastica/Index/Status.php new file mode 100644 index 00000000..6a343025 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Index/Status.php @@ -0,0 +1,144 @@ + + * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-status.html + */ +class Status +{ + /** + * Response + * + * @var \Elastica\Response Response object + */ + protected $_response = null; + + /** + * Stats info + * + * @var array Stats info + */ + protected $_data = array(); + + /** + * Index + * + * @var \Elastica\Index Index object + */ + protected $_index = null; + + /** + * Construct + * + * @param \Elastica\Index $index Index object + */ + public function __construct(BaseIndex $index) + { + $this->_index = $index; + $this->refresh(); + } + + /** + * Returns all status info + * + * @return array Status info + */ + public function getData() + { + return $this->_data; + } + + /** + * Returns the entry in the data array based on the params. + * Various params possible. + * + * @return mixed Data array entry or null if not found + */ + public function get() + { + $data = $this->getData(); + $data = $data['indices'][$this->getIndex()->getName()]; + + foreach (func_get_args() as $arg) { + if (isset($data[$arg])) { + $data = $data[$arg]; + } else { + return null; + } + } + + return $data; + } + + /** + * Returns all index aliases + * + * @return array Aliases + */ + public function getAliases() + { + $responseData = $this->getIndex()->request('_aliases', \Elastica\Request::GET)->getData(); + return array_keys($responseData[$this->getIndex()->getName()]['aliases']); + } + + /** + * Returns all index settings + * + * @return array Index settings + */ + public function getSettings() + { + $responseData = $this->getIndex()->request('_settings', \Elastica\Request::GET)->getData(); + return $responseData[$this->getIndex()->getName()]['settings']; + } + + /** + * Checks if the index has the given alias + * + * @param string $name Alias name + * @return bool + */ + public function hasAlias($name) + { + return in_array($name, $this->getAliases()); + } + + /** + * Returns the index object + * + * @return \Elastica\Index Index object + */ + public function getIndex() + { + return $this->_index; + } + + /** + * Returns response object + * + * @return \Elastica\Response Response object + */ + public function getResponse() + { + return $this->_response; + } + + /** + * Reloads all status data of this object + */ + public function refresh() + { + $path = '_status'; + $this->_response = $this->getIndex()->request($path, Request::GET); + $this->_data = $this->getResponse()->getData(); + } +} -- cgit v1.2.3-54-g00ecf