Physikerwelt has submitted this change and it was merged.
Change subject: Add setup for IBM DB2 driver
......................................................................
Add setup for IBM DB2 driver
* simple script that sets up IBM DB2 driver (for testing)
* rename $wgMWSUrl -> $wgMathSearchMWSUrl
Change-Id: I546a4e95c777b4e96c0de69448c21561f7e12ffd
---
M MathEngineMws.php
M MathQueryObject.php
M MathSearch.php
M maintenance/db2test.php
A maintenance/ibm_driver.sh
5 files changed, 78 insertions(+), 35 deletions(-)
Approvals:
Physikerwelt: Verified; Looks good to me, approved
diff --git a/MathEngineMws.php b/MathEngineMws.php
index d6ed303..0a2b66c 100644
--- a/MathEngineMws.php
+++ b/MathEngineMws.php
@@ -52,18 +52,18 @@
* @return boolean
*/
function postQuery() {
- global $wgMWSUrl, $wgMathDebug;
+ global $wgMathSearchMWSUrl, $wgMathDebug;
$numProcess = 30000;
$tmp = str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $this->getQuery()->getCQuery() );
$mwsExpr = str_replace( "m:", "", $tmp );
wfDebugLog( 'mathsearch', 'MWS query:' . $mwsExpr );
- $res = Http::post( $wgMWSUrl, array( "postData" => $mwsExpr,
"timeout" => 60 ) );
+ $res = Http::post( $wgMathSearchMWSUrl, array( "postData" =>
$mwsExpr, "timeout" => 60 ) );
if ( $res == false ) {
if ( function_exists( 'curl_init' ) ) {
$handle = curl_init();
$options = array(
- CURLOPT_URL => $wgMWSUrl,
+ CURLOPT_URL => $wgMathSearchMWSUrl,
CURLOPT_CUSTOMREQUEST => 'POST', // GET
POST PUT PATCH DELETE HEAD OPTIONS
);
// TODO: Figure out how not to write the error
in a message and not in top of the output page
@@ -72,13 +72,13 @@
} else {
$details = "curl is not installed.";
}
- wfDebugLog( "MathSearch", "Nothing retreived from
$wgMWSUrl. Check if mwsd is running. Error:" .
+ wfDebugLog( "MathSearch", "Nothing retreived from
$wgMathSearchMWSUrl. Check if mwsd is running. Error:" .
var_export( $details, true ) );
return false;
}
$xres = new SimpleXMLElement( $res );
$this->size = (int) $xres["total"];
- wfDebugLog( "MathSearch", $this->size . " results retreived
from $wgMWSUrl." );
+ wfDebugLog( "MathSearch", $this->size . " results retreived
from $wgMathSearchMWSUrl." );
if ($this->size == 0) {
return true;
}
@@ -89,10 +89,10 @@
ini_set( 'memory_limit', '256M' );
for ( $i = $numProcess; $i <= $this->size; $i +=
$numProcess ) {
$query = str_replace( "limitmin=\"0\" ",
"limitmin=\"$i\" ", $mwsExpr );
- $res = Http::post( $wgMWSUrl, array( "postData"
=> $query, "timeout" => 60 ) );
+ $res = Http::post( $wgMathSearchMWSUrl, array(
"postData" => $query, "timeout" => 60 ) );
wfDebugLog( 'mathsearch', 'MWS query:' . $query
);
if ( $res == false ) {
- wfDebugLog( "MathSearch", "Nothing
retreived from $wgMWSUrl. check if mwsd is running there" );
+ wfDebugLog( "MathSearch", "Nothing
retreived from $wgMathSearchMWSUrl. check if mwsd is running there" );
return false;
}
$xres = new SimpleXMLElement( $res );
diff --git a/MathQueryObject.php b/MathQueryObject.php
index 59c8d8a..b1bfe7a 100644
--- a/MathQueryObject.php
+++ b/MathQueryObject.php
@@ -242,18 +242,18 @@
* @return boolean
*/
function postQuery() {
- global $wgMWSUrl, $wgMathDebug;
+ global $wgMathSearchMWSUrl, $wgMathDebug;
$numProcess = 30000;
$tmp = str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $this->getCQuery() );
$mwsExpr = str_replace( "m:", "", $tmp );
wfDebugLog( 'mathsearch', 'MWS query:' . $mwsExpr );
- $res = Http::post( $wgMWSUrl, array( "postData" => $mwsExpr,
"timeout" => 60 ) );
+ $res = Http::post( $wgMathSearchMWSUrl, array( "postData" =>
$mwsExpr, "timeout" => 60 ) );
if ( $res == false ) {
if ( function_exists( 'curl_init' ) ) {
$handle = curl_init();
$options = array(
- CURLOPT_URL => $wgMWSUrl,
+ CURLOPT_URL => $wgMathSearchMWSUrl,
CURLOPT_CUSTOMREQUEST => 'POST', // GET
POST PUT PATCH DELETE HEAD OPTIONS
);
// TODO: Figure out how not to write the error
in a message and not in top of the output page
@@ -262,7 +262,7 @@
} else {
$details = "curl is not installed.";
}
- wfDebugLog( "MathSearch", "Nothing retreived from
$wgMWSUrl. Check if mwsd is running. Error:" .
+ wfDebugLog( "MathSearch", "Nothing retreived from
$wgMathSearchMWSUrl. Check if mwsd is running. Error:" .
var_export( $details, true ) );
return false;
}
@@ -272,7 +272,7 @@
$out->addWikiText( '<source lang="xml">' . $res .
'</source>' );
}
$this->numMathResults = (int) $xres["total"];
- wfDebugLog( "MathSearch", $this->numMathResults . " results
retreived from $wgMWSUrl." );
+ wfDebugLog( "MathSearch", $this->numMathResults . " results
retreived from $wgMathSearchMWSUrl." );
if ( $this->numMathResults == 0 )
return true;
$this->relevantMathMap = array();
@@ -282,10 +282,10 @@
ini_set( 'memory_limit', '256M' );
for ( $i = $numProcess; $i <= $this->numMathResults; $i
+= $numProcess ) {
$query = str_replace( "limitmin=\"0\" ",
"limitmin=\"$i\" ", $mwsExpr );
- $res = Http::post( $wgMWSUrl, array( "postData"
=> $query, "timeout" => 60 ) );
+ $res = Http::post( $wgMathSearchMWSUrl, array(
"postData" => $query, "timeout" => 60 ) );
wfDebugLog( 'mathsearch', 'MWS query:' . $query
);
if ( $res == false ) {
- wfDebugLog( "MathSearch", "Nothing
retreived from $wgMWSUrl. check if mwsd is running there" );
+ wfDebugLog( "MathSearch", "Nothing
retreived from $wgMathSearchMWSUrl. check if mwsd is running there" );
return false;
}
$xres = new SimpleXMLElement( $res );
diff --git a/MathSearch.php b/MathSearch.php
index 4afc702..744cdfd 100644
--- a/MathSearch.php
+++ b/MathSearch.php
@@ -27,8 +27,10 @@
'descriptionmsg' => 'mathsearch-desc',
'version' => '0.1.0',
);
-
-$wgMWSUrl = 'http://localhost:9090/';
+/** @var String the IBM DB connection string*/
+$wgMathSearchDB2ConnStr = false;
+/** @var String URL of MathWebSearch instance */
+$wgMathSearchMWSUrl = 'http://localhost:9090/';
$dir = dirname( __FILE__ ) . '/';
$wgAutoloadClasses['MathSearchHooks'] = $dir . 'MathSearch.hooks.php';
diff --git a/maintenance/db2test.php b/maintenance/db2test.php
index a013fc6..5cbc3de 100644
--- a/maintenance/db2test.php
+++ b/maintenance/db2test.php
@@ -1,22 +1,37 @@
<?php
-echo "basic test if db2 is setup correctly and the sample database is
installed! \n";
-echo "enter db2 (db2inst1)-password\n";
-$f = fopen( 'php://stdin', 'r' );
-$passwd = fgets( $f ) ;
-try {
- $connection = new PDO("ibm:SAMPLE", "db2inst1", $passwd, array(
- PDO::ATTR_PERSISTENT => TRUE,
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
- );
-}
-catch (Exception $e) {
- echo($e->getMessage());
-}
-$result = $connection->query('SELECT firstnme, lastname FROM employee');
-if (!$result) {
- print "<p>Could not retrieve employee list: " . $connection->errorMsg().
"</p>";
-}
-while ($row = $result->fetch()) {
- print "<p>Name:". $row[0]. $row[1]."</p>";
+
+require_once( dirname(__FILE__) . '/../../../maintenance/Maintenance.php' );
+
+class db2Test extends Maintenance {
+
+ public function execute() {
+
+ global $wgMathSearchDB2ConnStr;
+ if ($wgMathSearchDB2ConnStr !== false) {
+ $conn = db2_connect($wgMathSearchDB2ConnStr, '', '');
+
+ if ($conn) {
+ echo "Connection succeeded.";
+ db2_close($conn);
+ } else {
+ echo "Connection failed.";
+ }
+ } else {
+ $message = <<<'EOT'
+Add something like that to LocalSettings.php
+$database = 'SAMPLE';
+$user = 'db2inst1';
+$password = 'ibmdb2';
+$hostname = 'localhost';
+$port = 50000;
+$wgMathSearchDB2ConnStr = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
+ "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
+EOT;
+ echo $message;
+ }
+ }
+
}
+$maintClass = "db2Test";
+require_once( RUN_MAINTENANCE_IF_MAIN );
diff --git a/maintenance/ibm_driver.sh b/maintenance/ibm_driver.sh
new file mode 100755
index 0000000..097860a
--- /dev/null
+++ b/maintenance/ibm_driver.sh
@@ -0,0 +1,26 @@
+#/bin/bash
+echo "Warning: Experimental don't use in any kind of production environment."
+echo "Make sure that you have downloaded and extracted the"
+echo "Data Server Driver Package (dsdriver) to /vagrant/ibm/dsdriver"
+echo "For vagrant you need to chose IBM Data Server Driver Package (Linux
AMD64 and Intel EM64T)"
+echo "Are the drivers downloaded and extracted?"
+select yn in "Yes" "No"
+do
+ case $yn in
+ Yes ) break;;
+ No ) exit;;
+ esac
+done
+sudo apt-get install php-pear ksh zip -y
+sudo mkdir /opt/ibm -p
+sudo cp -r /vagrant/ibm/dsdriver /opt/ibm/dsdriver
+sudo chmod 755 /opt/ibm/dsdriver/installDSDriver
+sudo /opt/ibm/dsdriver/installDSDriver || true
+export IBM_DB2_HOME=/opt/ibm/dsdriver
+echo "; configuration for php db2 module" | sudo tee /etc/php5/conf.d/db2.ini
+sudo pear config-set php_ini /etc/php5/conf.d/db2.ini
+sudo pecl config-set php_ini /etc/php5/conf.d/db2.ini
+printf "/opt/ibm/dsdriver" | sudo pecl install ibm_db2
+sudo service apache2 restart
+echo "end of install script"
+echo "run php db2test.php to test your connection"
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/110885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I546a4e95c777b4e96c0de69448c21561f7e12ffd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits