Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 /**
  * Pings the Solr server using search_solr config
  *
  * @return true|string Returns true if all good or an error string.
  */
 public function is_server_ready()
 {
     $configured = $this->is_server_configured();
     if ($configured !== true) {
         return $configured;
     }
     // Check that the schema is already set up.
     try {
         $schema = new \search_solr\schema();
         $schema->validate_setup();
     } catch (\moodle_exception $e) {
         return $e->getMessage();
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Pings the Solr server using search_solr config
  *
  * @return true|string Returns true if all good or an error string.
  */
 public function is_server_ready()
 {
     if (empty($this->config->server_hostname) || empty($this->config->indexname)) {
         return 'No solr configuration found';
     }
     if (!($this->client = $this->get_search_client(false))) {
         return get_string('engineserverstatus', 'search');
     }
     try {
         @$this->client->ping();
     } catch (\SolrClientException $ex) {
         return 'Solr client error: ' . $ex->getMessage();
     } catch (\SolrServerException $ex) {
         return 'Solr server error: ' . $ex->getMessage();
     }
     // Check that setup schema has already run.
     try {
         $schema = new \search_solr\schema();
         $schema->validate_setup();
     } catch (\moodle_exception $e) {
         return $e->getMessage();
     }
     return true;
 }
Ejemplo n.º 5
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);
Ejemplo n.º 6
0
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * 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());
$schema = new \search_solr\schema();
$schema->setup();
$url = new moodle_url('/admin/settings.php', array('section' => 'manageglobalsearch'));
redirect($url, get_string('setupok', 'search_solr'), 4);