Пример #1
0
 /**
  * Search via sphinx (mysql client)
  */
 protected function sphinxSearch($phrase)
 {
     $connection = new CDbConnection(Yii::app()->params['sphinx']['dsn'], Yii::app()->params['sphinx']['user'], Yii::app()->params['sphinx']['pass']);
     $connection->active = true;
     $words = mb_split('[^\\w]+', $phrase);
     $words = array_filter($words);
     // unset empty elements
     $search = implode('|', $words);
     $sphinxIndexes = SphinxService::implodeIndexes();
     $sql = "SELECT * FROM {$sphinxIndexes} WHERE MATCH('{$search}') LIMIT 10000";
     $command = $connection->createCommand($sql);
     return $command->queryColumn();
 }
 function indexing_action()
 {
     $this->view->devOptions = $this->_config->get_admin_options();
     if (!empty($_POST['skip_wizard_indexsation'])) {
         $this->view->success_message = 'Step was skipped.';
         return $this->_next_action('indexing');
     }
     if (!empty($_POST['process_indexing'])) {
         $sphinxService = new SphinxService($this->_config);
         $res = $sphinxService->reindex();
         if (true === $res) {
             $this->view->indexsation_done = true;
             $this->view->success_message = 'Indexing is done successfully!';
             return $this->_next_action('indexing');
         } else {
             $this->view->error_message = $res['err'];
         }
     }
     $this->view->indexsation_done = false;
     $this->view->render('admin/wizard/sphinx_indexsation.phtml');
     exit;
 }
 /**
  * Draw admin page
  *
  */
 function print_admin_page()
 {
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $options = $this->config->get_admin_options();
     $wizard = new WizardController($this->config);
     if (!empty($_POST['start_wizard']) || empty($options['sphinx_conf']) && 'false' == $options['wizard_done']) {
         $this->view->menu = 'wizard';
         $wizard->start_action();
     }
     if (!empty($_GET['menu'])) {
         switch ($_GET['menu']) {
             case 'terms_editor':
                 $terms_editor = new TermsEditorController($this->config);
                 $terms_editor->index_action();
                 $this->view->menu = 'terms_editor';
                 //return;
                 break;
             case 'stats':
                 $stats = new StatsController($this->config);
                 $stats->index_action();
                 $this->view->menu = 'stats';
                 //return;
                 break;
             case 'search_settings':
                 $this->view->menu = 'search_settings';
                 break;
         }
     }
     $sphinxService = new SphinxService($this->config);
     $res = false;
     $error_message = $success_message = '';
     if (!empty($_POST['reindex_sphinx'])) {
         $res = $sphinxService->reindex();
         $success_message = 'Sphinx successfully reindexed.';
     } else {
         if (!empty($_POST['start_sphinx'])) {
             $res = $sphinxService->start();
             $success_message = 'Sphinx successfully started.';
         } elseif (!empty($_POST['stop_sphinx'])) {
             $res = $sphinxService->stop();
             $success_message = 'Sphinx successfully stopped.';
         } elseif (isset($_POST['update_SphinxSearchSettings'])) {
             $this->update_options();
             $success_message = 'Settings updated.';
         }
     }
     if (is_array($res)) {
         $error_message = $res['err'];
     }
     $this->view->assign('index_modify_time', $sphinxService->get_index_modify_time());
     if (!empty($error_message)) {
         $this->view->assign('error_message', $error_message);
     }
     if (!empty($success_message)) {
         $this->view->assign('success_message', $success_message);
     }
     $devOptions = $this->config->get_admin_options();
     //update options
     $this->view->assign('devOptions', $devOptions);
     //load admin panel template
     $this->view->assign('header', 'Sphinx Search for Wordpress');
     $this->view->assign('is_sphinx_path_secure', $this->_isSphinxPathSecure());
     if ('true' != $devOptions['check_stats_table_column_status']) {
         global $table_prefix;
         $this->view->assign('error_message', "{$table_prefix}sph_stats table required an update.<br>\n            Please run the following command in MySQL client to update the table: <br>\n            alter table {$table_prefix}sph_stats add `status` tinyint(1) NOT NULL DEFAULT '0';\n            <br><br>\n            This update will allow to use Sphinx Search for Top/Related and Latest search terms widgets!");
     }
     $this->view->render('admin/layout.phtml');
 }
Пример #4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id)
 {
     $regions = Region::getRegionList();
     $model = new Ad();
     $model->attachEavSet(Category::model()->findByPk($id)->set_id);
     $model->category_id = $id;
     $photo = new Photo();
     if (isset($_POST['Ad'])) {
         $model->attributes = $_POST['Ad'];
         $model->author_id = Yii::app()->user->id;
         $transaction = Yii::app()->db->beginTransaction();
         if ($model->saveWithEavAttributes()) {
             $images = CUploadedFile::getInstancesByName('images');
             if ($images) {
                 $wrongImage = Photo::validateMultiple($images, $model->id);
                 if (!$wrongImage) {
                     foreach ($images as $image) {
                         $photo = new Photo();
                         $photo->image = $image;
                         $photo->name = $photo->image->getName();
                         $photo->ad_id = $model->id;
                         $photo->save(false);
                     }
                     $transaction->commit();
                     $this->redirect(array('view', 'id' => $model->id));
                 } else {
                     $photo = $wrongImage;
                     $transaction->rollback();
                 }
             } else {
                 $transaction->commit();
                 SphinxService::saveAdToRt($model->id);
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model, 'photo' => $photo, 'regions' => $regions));
 }
 function upgrade_table_statistics_in_v3()
 {
     global $wpdb, $table_prefix;
     //check for column status
     $result = $wpdb->get_results("SHOW COLUMNS FROM {$table_prefix}sph_stats");
     if (!$result) {
         echo 'Could not run query: ' . mysql_error();
         exit;
     }
     foreach ($result as $column) {
         if ('status' == $column->Field) {
             $options['check_stats_table_column_status'] = 'true';
             $this->config->update_admin_options($options);
         }
     }
     if ('true' == $options['check_stats_table_column_status']) {
         //set up sphinx for stats in widgest or not
         $wizard = new WizardController($this->config);
         $config_file_name = $this->config->get_option('sphinx_conf');
         $config_file_content = $wizard->_generate_config_file_content();
         $wizard->_save_config($config_file_name, $config_file_content);
         $sphinxService = new SphinxService($this->config);
         $ret = $sphinxService->reindex('stats');
     }
 }
 /**
  * Update Options
  *
  * @param array $options
  */
 function update_admin_options($options = '')
 {
     if (!empty($options)) {
         $this->admin_options = array_merge($this->admin_options, $options);
     }
     if (!empty($this->admin_options['sphinx_conf']) && file_exists($this->admin_options['sphinx_conf'])) {
         $sphinxService = new SphinxService($this);
         $pid_file = $sphinxService->get_searchd_pid_filename($this->admin_options['sphinx_conf']);
         $this->admin_options['sphinx_searchd_pid'] = $pid_file;
     }
     update_option($this->adminOptionsName, $this->admin_options);
 }