updated to 7.x-1.11

This commit is contained in:
Bachir Soussi Chiadmi
2014-02-07 10:01:18 +01:00
parent a30917d1d2
commit cf03e9ca52
69 changed files with 4629 additions and 1557 deletions
+58 -18
View File
@@ -1,5 +1,10 @@
<?php
/**
* @file
* Contains SearchApiViewsQuery.
*/
/**
* Views query class using a Search API index as the data source.
*/
@@ -180,7 +185,6 @@ class SearchApiViewsQuery extends views_plugin_query {
'#options' => array(),
'#default_value' => $this->options['parse_mode'],
);
$modes = array();
foreach ($this->query->parseModes() as $key => $mode) {
$form['parse_mode']['#options'][$key] = $mode['name'];
if (!empty($mode['description'])) {
@@ -243,16 +247,6 @@ class SearchApiViewsQuery extends views_plugin_query {
$view->init_pager();
$this->pager->query();
// Views passes sometimes NULL and sometimes the integer 0 for "All" in a
// pager. If set to 0 items, a string "0" is passed. Therefore, we unset
// the limit if an empty value OTHER than a string "0" was passed.
if (!$this->limit && $this->limit !== '0') {
$this->limit = NULL;
}
// Set the range. (We always set this, as there might even be an offset if
// all items are shown.)
$this->query->range($this->offset, $this->limit);
// Set the search ID, if it was not already set.
if ($this->query->getOption('search id') == get_class($this->query)) {
$this->query->setOption('search id', 'search_api_views:' . $view->name . ':' . $view->current_display);
@@ -262,6 +256,20 @@ class SearchApiViewsQuery extends views_plugin_query {
if (!empty($this->options['search_api_bypass_access'])) {
$this->query->setOption('search_api_bypass_access', TRUE);
}
// If the View and the Panel conspire to provide an overridden path then
// pass that through as the base path.
if (!empty($this->view->override_path) && strpos(current_path(), $this->view->override_path) !== 0) {
$this->query->setOption('search_api_base_path', $this->view->override_path);
}
}
/**
* {@inheritdoc}
*/
public function alter(&$view) {
parent::alter($view);
drupal_alter('search_api_views_query', $view, $this);
}
/**
@@ -284,7 +292,28 @@ class SearchApiViewsQuery extends views_plugin_query {
return;
}
// Calculate the "skip result count" option, if it wasn't already set to
// FALSE.
$skip_result_count = $this->query->getOption('skip result count', TRUE);
if ($skip_result_count) {
$skip_result_count = !$this->pager->use_count_query() && empty($view->get_total_rows);
$this->query->setOption('skip result count', $skip_result_count);
}
try {
// Trigger pager pre_execute().
$this->pager->pre_execute($this->query);
// Views passes sometimes NULL and sometimes the integer 0 for "All" in a
// pager. If set to 0 items, a string "0" is passed. Therefore, we unset
// the limit if an empty value OTHER than a string "0" was passed.
if (!$this->limit && $this->limit !== '0') {
$this->limit = NULL;
}
// Set the range. (We always set this, as there might even be an offset if
// all items are shown.)
$this->query->range($this->offset, $this->limit);
$start = microtime(TRUE);
// Execute the search.
@@ -292,11 +321,13 @@ class SearchApiViewsQuery extends views_plugin_query {
$this->search_api_results = $results;
// Store the results.
$this->pager->total_items = $view->total_rows = $results['result count'];
if (!empty($this->pager->options['offset'])) {
$this->pager->total_items -= $this->pager->options['offset'];
if (!$skip_result_count) {
$this->pager->total_items = $view->total_rows = $results['result count'];
if (!empty($this->pager->options['offset'])) {
$this->pager->total_items -= $this->pager->options['offset'];
}
$this->pager->update_page_info();
}
$this->pager->update_page_info();
$view->result = array();
if (!empty($results['results'])) {
$this->addResults($results['results'], $view);
@@ -304,6 +335,9 @@ class SearchApiViewsQuery extends views_plugin_query {
// We shouldn't use $results['performance']['complete'] here, since
// extracting the results probably takes considerable time as well.
$view->execute_time = microtime(TRUE) - $start;
// Trigger pager post_execute().
$this->pager->post_execute($view->result);
}
catch (Exception $e) {
$this->errors[] = $e->getMessage();
@@ -317,8 +351,14 @@ class SearchApiViewsQuery extends views_plugin_query {
*
* Used by handlers to flag a fatal error which shouldn't be displayed but
* still lead to the view returning empty and the search not being executed.
*
* @param string|null $msg
* Optionally, a translated, unescaped error message to display.
*/
public function abort() {
public function abort($msg = NULL) {
if ($msg) {
$this->errors[] = $msg;
}
$this->abort = TRUE;
}
@@ -520,9 +560,9 @@ class SearchApiViewsQuery extends views_plugin_query {
// Query interface methods (proxy to $this->query)
//
public function createFilter($conjunction = 'AND') {
public function createFilter($conjunction = 'AND', $tags = array()) {
if (!$this->errors) {
return $this->query->createFilter($conjunction);
return $this->query->createFilter($conjunction, $tags);
}
}