| 1 |
<?php |
<?php |
| 2 |
// $Id: apachesolr.install,v 1.1.4.22 2009/11/12 13:14:54 robertDouglass Exp $ |
// $Id: apachesolr.install,v 1.1.4.23 2009/11/13 15:07:26 pwolanin Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
|
* Implementation of hook_requirements(). |
| 11 |
|
*/ |
| 12 |
|
function apachesolr_requirements($phase) { |
| 13 |
|
$requirements = array(); |
| 14 |
|
$file_exists = file_exists(dirname(__FILE__) . '/SolrPhpClient/Apache/Solr/Service.php'); |
| 15 |
|
// Ensure translations don't break at install time |
| 16 |
|
$t = get_t(); |
| 17 |
|
if ($phase == 'runtime' && $file_exists) { |
| 18 |
|
$host = variable_get('apachesolr_host', 'localhost'); |
| 19 |
|
$port = variable_get('apachesolr_port', 8983); |
| 20 |
|
$path = variable_get('apachesolr_path', '/solr'); |
| 21 |
|
$ping = FALSE; |
| 22 |
|
try { |
| 23 |
|
$solr = apachesolr_get_solr(); |
| 24 |
|
$ping = @$solr->ping(variable_get('apachesolr_ping_timeout', 4)); |
| 25 |
|
// If there is no $solr object, there is no server available, so don't continue. |
| 26 |
|
if (!$ping) { |
| 27 |
|
throw new Exception(t('No Solr instance available when checking requirements.')); |
| 28 |
|
} |
| 29 |
|
} |
| 30 |
|
catch (Exception $e) { |
| 31 |
|
watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR); |
| 32 |
|
} |
| 33 |
|
$value = $ping ? $t('Your site has contacted the Apache Solr server.') : $t('Your site was unable to contact the Apache Solr server.'); |
| 34 |
|
$severity = $ping ? REQUIREMENT_OK : REQUIREMENT_ERROR; |
| 35 |
|
$description = theme('item_list', array($t('Host: %host', array('%host' => $host)), |
| 36 |
|
$t('Port: %port', array('%port' => $port)), |
| 37 |
|
$t('Path: %path', array('%path' => $path)))); |
| 38 |
|
$requirements['apachesolr'] = array( |
| 39 |
|
'title' => $t('Apache Solr'), |
| 40 |
|
'value' => $value, |
| 41 |
|
'description' => $description, |
| 42 |
|
'severity' => $severity, |
| 43 |
|
); |
| 44 |
|
} |
| 45 |
|
// All phases |
| 46 |
|
$title = $t('Apache Solr PHP CLient Library'); |
| 47 |
|
if ($file_exists) { |
| 48 |
|
$expected_revision = '$Revision: 22 $'; |
| 49 |
|
require_once 'SolrPhpClient/Apache/Solr/Service.php'; |
| 50 |
|
$revision = defined('Apache_Solr_Service::SVN_REVISION') ? Apache_Solr_Service::SVN_REVISION : ''; |
| 51 |
|
if ($revision == $expected_revision) { |
| 52 |
|
$severity = REQUIREMENT_OK; |
| 53 |
|
$value = $t('Correct version "@expected".', array('@expected' => $expected_revision)); |
| 54 |
|
$description = NULL; |
| 55 |
|
} |
| 56 |
|
else { |
| 57 |
|
$value = $t('Incorrect version "@version". See the instructions in README.txt.', array('@version' => $revision)); |
| 58 |
|
$description = $t('The version of the library in the SolrPhpClient directory is "@version" compared to the expected "@expected"', array('@version' => $revision, '@expected' => $expected_revision)); |
| 59 |
|
$severity = REQUIREMENT_ERROR; |
| 60 |
|
} |
| 61 |
|
$requirements['SolrPhpClient'] = array( |
| 62 |
|
'title' => $title, |
| 63 |
|
'value' => $value, |
| 64 |
|
'description' => $description, |
| 65 |
|
'severity' => $severity, |
| 66 |
|
); |
| 67 |
|
} |
| 68 |
|
else { |
| 69 |
|
$requirements['SolrPhpClient'] = array( |
| 70 |
|
'title' => $title, |
| 71 |
|
'value' => $t('<em>Missing</em>. See the instructions in README.txt'), |
| 72 |
|
'description' => $t('The Solr PHP library must be present in a sub-directory named SolrPhpClient.'), |
| 73 |
|
'severity' => REQUIREMENT_ERROR, |
| 74 |
|
); |
| 75 |
|
} |
| 76 |
|
return $requirements; |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
/** |
| 80 |
* Implementation of hook_install(). |
* Implementation of hook_install(). |
| 81 |
*/ |
*/ |
| 82 |
function apachesolr_install() { |
function apachesolr_install() { |