Ejemplo n.º 1
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $inputHandler = new XenForo_Input($data);
     $input = $inputHandler->filter(array('batch' => XenForo_Input::UINT, 'start' => XenForo_Input::UINT, 'extra_data' => XenForo_Input::ARRAY_SIMPLE, 'delay' => XenForo_Input::UNUM, 'content_type' => XenForo_Input::STRING, 'delete_index' => XenForo_Input::UINT));
     if ($input['delay'] >= 0.01) {
         usleep($input['delay'] * 1000000);
     }
     /* @var $searchModel XenForo_Model_Search */
     $searchModel = XenForo_Model::create('XenForo_Model_Search');
     $searchContentTypes = $searchModel->getSearchContentTypes();
     $extraData = $input['extra_data'];
     if (!isset($extraData['content_types']) || !is_array($extraData['content_types'])) {
         if ($input['content_type'] && isset($searchContentTypes[$input['content_type']])) {
             $extraData['content_types'] = array($input['content_type']);
         } else {
             $extraData['content_types'] = array_keys($searchContentTypes);
         }
     }
     if (empty($extraData['current_type'])) {
         $extraData['current_type'] = array_shift($extraData['content_types']);
     }
     if (empty($extraData['type_start'])) {
         $extraData['type_start'] = 0;
     }
     $originalExtraData = $extraData;
     while (!isset($searchContentTypes[$extraData['current_type']])) {
         if (!$extraData['content_types']) {
             return false;
         }
         $extraData['current_type'] = array_shift($extraData['content_types']);
     }
     if ($input['delete_index']) {
         $source = XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler();
         $source->deleteIndex($input['content_type'] ? $input['content_type'] : null);
     }
     $dataHandler = false;
     $searchHandler = $searchContentTypes[$extraData['current_type']];
     if (class_exists($searchHandler)) {
         $dataHandler = XenForo_Search_DataHandler_Abstract::create($searchHandler);
         $indexer = new XenForo_Search_Indexer();
         $indexer->setIsRebuild(true);
         $nextStart = $dataHandler->rebuildIndex($indexer, $extraData['type_start'], $input['batch']);
         $indexer->finalizeRebuildSet();
     } else {
         $nextStart = false;
     }
     if ($nextStart === false) {
         // move on to next type
         $extraData['current_type'] = '';
         $extraData['type_start'] = 0;
     } else {
         $extraData['type_start'] = $nextStart;
     }
     $data = array('batch' => $input['batch'], 'start' => $input['start'] + 1, 'extra_data' => $extraData, 'delay' => $input['delay']);
     $actionPhrase = new XenForo_Phrase('rebuilding');
     $typePhrase = new XenForo_Phrase('search_index');
     $text = $dataHandler ? $dataHandler->getSearchContentTypePhrase() : new XenForo_Phrase($originalExtraData['current_type']);
     $status = sprintf('%s... %s (%s)', $actionPhrase, $typePhrase, "{$text} " . XenForo_Locale::numberFormat($originalExtraData['type_start']));
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Displays a form to do an advanced search.
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionIndex()
 {
     $search = array('child_nodes' => true, 'order' => 'date');
     $searchId = $this->_input->filterSingle('search_id', XenForo_Input::UINT);
     if ($searchId) {
         if ($this->_input->filterSingle('searchform', XenForo_Input::UINT)) {
             $params = $this->_input->filter(array('q' => XenForo_Input::STRING, 't' => XenForo_Input::STRING, 'o' => XenForo_Input::STRING, 'g' => XenForo_Input::UINT, 'c' => XenForo_Input::ARRAY_SIMPLE));
             // allow this to pass through for the search type check later
             $this->_request->setParam('type', $params['t']);
             $users = '';
             if (!empty($params['c']['user'])) {
                 foreach ($this->_getUserModel()->getUsersByIds($params['c']['user']) as $user) {
                     $users .= $user['username'] . ', ';
                 }
                 $users = substr($users, 0, -2);
             }
             if (!empty($params['c']['node'])) {
                 $nodes = array_fill_keys(explode(' ', $params['c']['node']), true);
             } else {
                 $nodes = array();
             }
             if (!empty($params['c']['date'])) {
                 $date = XenForo_Locale::date(intval($params['c']['date']), 'picker');
             } else {
                 $date = '';
             }
             if (!empty($params['c']['user_content'])) {
                 $userContent = $params['c']['user_content'];
             } else {
                 $userContent = '';
             }
             $search = array_merge($search, array('keywords' => $params['q'], 'title_only' => !empty($params['c']['title_only']), 'users' => $users, 'user_content' => $userContent, 'date' => $date, 'nodes' => $nodes, 'child_nodes' => empty($nodes), 'order' => $params['o'], 'group_discussion' => $params['g'], 'existing' => true));
         } else {
             return $this->responseReroute(__CLASS__, 'results');
         }
     }
     if (!XenForo_Visitor::getInstance()->canSearch()) {
         throw $this->getNoPermissionResponseException();
     }
     $nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
     if ($nodeId) {
         $search['nodes'][$nodeId] = true;
     }
     $viewParams = array('supportsRelevance' => XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler()->supportsRelevance(), 'nodes' => $this->_getNodeModel()->getViewableNodeList(null, true), 'search' => empty($search) ? array() : $search);
     $searchType = $this->_input->filterSingle('type', XenForo_Input::STRING);
     if ($searchType) {
         $typeHandler = $this->_getSearchModel()->getSearchDataHandler($searchType);
         if ($typeHandler) {
             $viewParams['searchType'] = $searchType;
             $response = $typeHandler->getSearchFormControllerResponse($this, $this->_input, $viewParams);
             if ($response) {
                 return $response;
             }
         }
     }
     $viewParams['searchType'] = '';
     return $this->responseView('XenForo_ViewPublic_Search_Form', 'search_form', $viewParams);
 }
Ejemplo n.º 3
0
 /**
  * Searches for content by a specific user.
  *
  * @param integer $userId
  * @param integer $maxDate If >0, the only messages older than this will be found
  * @param integer $maxResults
  *
  * @return array Search results: [] => array(content type , id)
  */
 public function searchUser($userId, $maxDate = 0, $maxResults = 0)
 {
     if ($maxResults < 1) {
         $maxResults = XenForo_Application::get('options')->maximumSearchResults;
     }
     $results = $this->_sourceHandler->executeSearchByUserId($userId, $maxDate, $maxResults);
     if ($this->_viewingUser !== false) {
         $results = $this->_searchModel->getViewableSearchResults($results, $this->_viewingUser);
     }
     return $results;
 }
Ejemplo n.º 4
0
 /**
  * Gets recent content for the specified member
  *
  * @return XenForo_ControllerResponse_Abstract
  */
 public function actionRecentContent()
 {
     $userId = $this->_input->filterSingle('user_id', XenForo_Input::UINT);
     $user = $this->getHelper('UserProfile')->assertUserProfileValidAndViewable($userId);
     $results = XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler()->executeSearchByUserId($userId, 0, 15);
     $results = $this->getModelFromCache('XenForo_Model_Search')->getSearchResultsForDisplay($results);
     if (!$results) {
         return $this->responseMessage(new XenForo_Phrase('this_member_does_not_have_any_recent_content'));
     }
     $viewParams = array('user' => $user, 'results' => $results);
     return $this->responseView('XenForo_ViewPublic_Member_RecentContent', 'member_recent_content', $viewParams);
 }
Ejemplo n.º 5
0
 /**
  * When rebuilding, it might be advantageous to bulk update records. This function
  * must be called to ensure that all records are updated together.
  */
 public function finalizeRebuildSet()
 {
     $this->_sourceHandler->finalizeRebuildSet();
 }
Ejemplo n.º 6
0
$input['delete_index'] = $cliHelper->askQuestion(new XenForo_Phrase('delete_index_before_rebuilding') . ' [y/n]');
if ($cliHelper->validateYesNoAnswer($input['delete_index'], $continue)) {
    if ($continue) {
        $input['delete_index'] = 1;
    } else {
        $input['delete_index'] = 0;
    }
}
if ($specialBuildRange) {
    $specialBuildRange = explode('-', $specialBuildRange);
    $specialBuildRange = array_map('intval', $specialBuildRange);
} else {
    $specialBuildRange = array(0, 0);
}
if ($input['delete_index']) {
    $source = XenForo_Search_SourceHandler_Abstract::getDefaultSourceHandler();
    $source->deleteIndex($input['content_type'] ? $input['content_type'] : null);
}
if ($input['content_type']) {
    $searchContentList = array($input['content_type']);
} else {
    $searchContentList = array_keys($searchContentTypes);
}
// ******************
$start = 0;
$batch = 100;
$currentContentType = array_shift($searchContentList);
// ******************
$position = $start;
$lastStart = 0;
while (true) {