Пример #1
0
 public function setUp()
 {
     $this->resetAfterTest();
     set_config('enableglobalsearch', true);
     if (!function_exists('solr_get_version')) {
         $this->markTestSkipped('Solr extension is not loaded.');
     }
     if (!defined('TEST_SEARCH_SOLR_HOSTNAME') || !defined('TEST_SEARCH_SOLR_INDEXNAME') || !defined('TEST_SEARCH_SOLR_PORT')) {
         $this->markTestSkipped('Solr extension test server not set.');
     }
     set_config('hostname', TEST_SEARCH_SOLR_HOSTNAME, 'search_solr');
     set_config('port', TEST_SEARCH_SOLR_PORT, 'search_solr');
     set_config('indexname', TEST_SEARCH_SOLR_INDEXNAME, 'search_solr');
     if (defined('TEST_SEARCH_SOLR_USERNAME')) {
         set_config('server_username', TEST_SEARCH_SOLR_USERNAME);
     }
     if (defined('TEST_SEARCH_SOLR_PASSWORD')) {
         set_config('server_password', TEST_SEARCH_SOLR_PASSWORD);
     }
     // Inject search solr engine into the testable core search as we need to add the mock
     // search component to it.
     $searchengine = new \search_solr\engine();
     $this->search = testable_core_search::instance($searchengine);
     $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'role_capabilities');
     $this->search->add_search_area($areaid, new core_mocksearch\search\role_capabilities());
     $this->setAdminUser();
     // Cleanup before doing anything on it as the index it is out of this test control.
     $this->search->delete_index();
     // Add moodle fields if they don't exist.
     $schema = new \search_solr\schema();
     $schema->setup(false);
 }
Пример #2
0
 public function setUp()
 {
     $this->resetAfterTest();
     set_config('enableglobalsearch', true);
     if (!function_exists('solr_get_version')) {
         $this->markTestSkipped('Solr extension is not loaded.');
     }
     if (!defined('TEST_SEARCH_SOLR_HOSTNAME') || !defined('TEST_SEARCH_SOLR_INDEXNAME') || !defined('TEST_SEARCH_SOLR_PORT')) {
         $this->markTestSkipped('Solr extension test server not set.');
     }
     set_config('server_hostname', TEST_SEARCH_SOLR_HOSTNAME, 'search_solr');
     set_config('server_port', TEST_SEARCH_SOLR_PORT, 'search_solr');
     set_config('indexname', TEST_SEARCH_SOLR_INDEXNAME, 'search_solr');
     if (defined('TEST_SEARCH_SOLR_USERNAME')) {
         set_config('server_username', TEST_SEARCH_SOLR_USERNAME, 'search_solr');
     }
     if (defined('TEST_SEARCH_SOLR_PASSWORD')) {
         set_config('server_password', TEST_SEARCH_SOLR_PASSWORD, 'search_solr');
     }
     if (defined('TEST_SEARCH_SOLR_SSLCERT')) {
         set_config('secure', true, 'search_solr');
         set_config('ssl_cert', TEST_SEARCH_SOLR_SSLCERT, 'search_solr');
     }
     if (defined('TEST_SEARCH_SOLR_SSLKEY')) {
         set_config('ssl_key', TEST_SEARCH_SOLR_SSLKEY, 'search_solr');
     }
     if (defined('TEST_SEARCH_SOLR_KEYPASSWORD')) {
         set_config('ssl_keypassword', TEST_SEARCH_SOLR_KEYPASSWORD, 'search_solr');
     }
     if (defined('TEST_SEARCH_SOLR_CAINFOCERT')) {
         set_config('ssl_cainfo', TEST_SEARCH_SOLR_CAINFOCERT, 'search_solr');
     }
     set_config('fileindexing', 1, 'search_solr');
     // We are only test indexing small string files, so setting this as low as we can.
     set_config('maxindexfilekb', 1, 'search_solr');
     $this->generator = self::getDataGenerator()->get_plugin_generator('core_search');
     $this->generator->setup();
     // Inject search solr engine into the testable core search as we need to add the mock
     // search component to it.
     $this->engine = new \search_solr\testable_engine();
     $this->search = testable_core_search::instance($this->engine);
     $areaid = \core_search\manager::generate_areaid('core_mocksearch', 'mock_search_area');
     $this->search->add_search_area($areaid, new core_mocksearch\search\mock_search_area());
     $this->setAdminUser();
     // Cleanup before doing anything on it as the index it is out of this test control.
     $this->search->delete_index();
     // Add moodle fields if they don't exist.
     $schema = new \search_solr\schema();
     $schema->setup(false);
 }
Пример #3
0
/**
 * Adds moodle fields to solr schema.
 *
 * Schema REST API write actions are only available from Solr 4.4 onwards.
 *
 * The schema should be managed and mutable to allow this script
 * to add new fields to the schema.
 *
 * @link      https://cwiki.apache.org/confluence/display/solr/Managed+Schema+Definition+in+SolrConfig
 * @package   search_solr
 * @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once __DIR__ . '/../../../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_login(null, false);
require_capability('moodle/site:config', context_system::instance());
$returnurl = new moodle_url('/admin/settings.php', array('section' => 'manageglobalsearch'));
$schema = new \search_solr\schema();
$status = $schema->can_setup_server();
if ($status !== true) {
    $PAGE->set_context(context_system::instance());
    $PAGE->set_url(new moodle_url('/search/engine/solr/setup_schema.php'));
    echo $OUTPUT->header();
    echo $OUTPUT->notification($status, \core\output\notification::NOTIFY_ERROR);
    echo $OUTPUT->box($OUTPUT->action_link($returnurl, get_string('continue')), 'generalbox centerpara');
    echo $OUTPUT->footer();
    exit(1);
}
$schema->setup();
redirect($returnurl, get_string('setupok', 'search_solr'), 4);