Skip to content

Commit

Permalink
Item1868: migrate to using DbiContrib, and update Contrib topic
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/JoomlaUsersContrib@4590 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Aug 2, 2009
1 parent 18094e2 commit 84a8418
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 102 deletions.
25 changes: 9 additions & 16 deletions data/System/JoomlaUsersContrib.txt
Expand Up @@ -3,7 +3,7 @@

---+!! JoomlaUsersContrib Contrib Package

*tested with Joomla 1.0.13*
*tested with Joomla 1.0.13 and 1.5*


This Contrib enables you to replace the Foswiki User and Groups system with a read only access to the
Expand All @@ -16,7 +16,7 @@ otherwise user query performance (happens every request) will severely degrade t
*NOTE:* for performance reasons, the Joomla Registered Users group is _not_ brought into the system,
The other groups may cause performance degradation if they have too many members

By selecting JoomlaLogin, Foswiki will also attempt to use the Joomla 'remember me' cookie -
By selecting JoomlaLogin, Foswiki will also attempt (has worked on joomla 1.3, but not reliably) to use the Joomla 'remember me' cookie -
though this requires the Foswiki and Joomla host names to be the same.

<a href="http://wikiring.com/" ><img src="%ATTACHURL%/wikiringlogo.png" style="float: right; padding:30px;" /></a>
Expand All @@ -33,35 +33,28 @@ Settings are in =lib/LocalSite.cfg=. the Foswiki configure script does not curre
* Set STUB = authenticate using the joomla users - disable registration.

---++ Installation Instructions
* Download the ZIP file from the Plugin web (see below)
* Unzip ==%TOPIC%.zip== in your foswiki installation directory. Content:
| *File:* | *Description:* |

* Run ==%TOPIC%_installer.pl== to automatically check and install other modules that this module depends on. You can also do this step manually. Dependencies:
<table border="1"><tr><th>Name</th><th>Version</th><th>Description</th></tr><tr><td align="left">DBIx::SQLEngine</td><td align="left"> &gt;=0.93</td><td align="left">(and its pre-requisites) Extends DBI with High-Level Operations</td></tr><tr><td align="left">DBD::mysql</td><td align="left"> &gt;=3.0000</td><td align="left">(and its pre-requisites) MySQL driver for the Perl5 Database Interface (DBI)</td></tr></table>
%$INSTALL_INSTRUCTIONS%
* set Foswiki::Users::JoomlaUserMapping as your UserMapping in configure's Security section
* set Foswiki::LoginManager::JoomlaLogin as your LoginManager in configure's Security section
* set none as your PasswordManager in configure's Security section
* set the ={AdminGroup}= in the configure security section to one of the Joomla groups (such as =Super Administrator=)
* configure JoomlaUsersContrib from the *User Managers* / *Joomla User Manager* section in configure
* this needs a dbi connection string to your Joomla database, and a valid username and password for it.
* Test if the installation was successful:
* __enter sample here__
* see also [[Sandbox.PluginTest%TOPIC%]]

---++ Contrib Info

| Plugin Author: | Foswiki:Main.SvenDowideit - of [[http://fosiki.com][fosiki.com]] - <img src="%ATTACHURL%/wikiring.png" /> [[http://www.wikiring.com][WikiRing.com]] |
| Copyright: | &copy; 2006-2009, SvenDowideit@fosiki.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Dependencies: | <table border="1"><tr><th>Name</th><th>Version</th><th>Description</th></tr><tr><td align="left">DBIx::SQLEngine</td><td align="left"> &gt;=0.93</td><td align="left">(and its pre-requisites) Extends DBI with High-Level Operations</td></tr><tr><td align="left">DBD::mysql</td><td align="left"> &gt;=3.0000</td><td align="left">(and its pre-requisites) MySQL driver for the Perl5 Database Interface (DBI)</td></tr></table> |
| Version: | 138 |
| License: | GPL 3 ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 1 Aug 2009 | update to work with Joomla 1.3 _and_ 1.5, migrate to the more modern Foswiki:Extensions.DbiContrib |
| Mar 2009 | port to Foswiki |
| Sep 2008 | updated to 4.2.1 mapping, and fixed for Joomla 1.0.13 - where the password salts were changed |
| Nov 2007 | updated to TWiki 4.2, and released |
| 2006 | Initial version (not public) |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
| 2006 | Initial version (not public) |
| Home: | http://foswiki.org/Extensions/%TOPIC% |


-- SvenDowideit@fosiki.com
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/JoomlaUsersContrib/DEPENDENCIES
@@ -1,2 +1,2 @@
DBIx::SQLEngine, >=0.93, CPAN, (and its pre-requisites) Extends DBI with High-Level Operations
Foswiki::Contrib::DbiContrib, >0, perl, Simplifies database communications to Foswiki
DBD::mysql, >=3.0000, CPAN, (and its pre-requisites) MySQL driver for the Perl5 Database Interface (DBI)
113 changes: 28 additions & 85 deletions lib/Foswiki/Users/JoomlaUserMapping.pm
Expand Up @@ -14,31 +14,25 @@
#
# As per the GPL, removal of this notice is prohibited.

#THIS CODE has been hacked too many times to move it between versions of TWiki (yes, TWiki)
#I still have to clean the code up alot. Sven Nov 2007

=begin twiki
=begin pod
---+ package Foswiki::Users::JoomlaUserMapping
canonical user_id == id number of jos_user table
login == username column
=cut

package Foswiki::Users::JoomlaUserMapping;
use base 'Foswiki::UserMapping';

use strict;
use strict;
use Assert;
use Foswiki::UserMapping;
use Foswiki::Users::BaseUserMapping;
use Foswiki::Time;
use Foswiki::ListIterator;
use DBIx::SQLEngine;
use DBD::mysql;
use Foswiki::Contrib::DbiContrib;

use Error qw( :try );

Expand All @@ -61,14 +55,20 @@ sub new {

$this->{JoomlaOnePointFive} = $Foswiki::cfg{Plugins}{JoomlaUser}{JoomlaVersionOnePointFive};

$this->{DB} = new Foswiki::Contrib::DbiContrib( {
dsn => $Foswiki::cfg{Plugins}{JoomlaUser}{DBI_dsn},
dsn_user => $Foswiki::cfg{Plugins}{JoomlaUser}{DBI_username},
dsn_password => $Foswiki::cfg{Plugins}{JoomlaUser}{DBI_password}
} );

$this->{error} = undef;
require Digest::MD5;

$this->{groupCache} = {};
return $this;
}

=begin twiki
=begin pod
---++ ObjectMethod finish()
Break circular references.
Expand All @@ -81,12 +81,13 @@ documentation" of the live fields in the object.

sub finish {
my $this = shift;
undef $this->{JoomlaDB};
$this->{DB}->disconnect();
undef $this->{DB};
$this->SUPER::finish();
return;
}

=begin twiki
=begin pod
---++ ObjectMethod loginTemplateName () -> $templateFile
Expand Down Expand Up @@ -115,7 +116,7 @@ sub supportsRegistration {
return 0; # NO, we don't
}

=begin twiki
=begin pod
---++ ObjectMethod handlesUser ( $cUID, $login, $wikiname) -> $boolean
Expand All @@ -137,7 +138,7 @@ sub handlesUser {
return 0;
}

=begin twiki
=begin pod
---++ ObjectMethod login2cUID ($login, $dontcheck) -> cUID
Expand Down Expand Up @@ -245,14 +246,14 @@ sub getWikiName {
$user_number =~ s/^$this->{mapping_id}//;
my $name;
my $userDataset =
$this->dbSelect( 'select name from jos_users gwn where gwn.id = ?',
$this->{DB}->select( 'select name from jos_users gwn where gwn.id = ?',
$user_number );
if ( exists $$userDataset[0] ) {
$name = $$userDataset[0]{name};
}
else {

#TODO: examine having the mapper returnthe truth, and fakeing guest in the core...
#TODO: examine having the mapper return the truth, and fakeing guest in the core...
#throw Error::Simple(
# 'user_id does not exist: '.$user);
return $Foswiki::cfg{DefaultUserWikiName};
Expand Down Expand Up @@ -298,7 +299,7 @@ sub eachUser {
my @list = ();

#TODO: this needs to be implemented in terms of a DB iterator that only selects partial results
my $userDataset = $this->dbSelect('select id from jos_users');
my $userDataset = $this->{DB}->select('select id from jos_users');
for my $row (@$userDataset) {
push @list, $this->{mapping_id} . $$row{id};
}
Expand Down Expand Up @@ -336,12 +337,12 @@ sub eachGroupMember {
}
my $groupSelectStatement = 'select '.$idRowName.' from jos_core_acl_aro_groups where name = ?';

my $groupIdDataSet = $this->dbSelect(
my $groupIdDataSet = $this->{DB}->select(
$groupSelectStatement,
$groupName );
if ( exists $$groupIdDataSet[0] ) {
my $group = $$groupIdDataSet[0]{$idRowName};
my $groupDataset = $this->dbSelect(
my $groupDataset = $this->{DB}->select(
'select aro_id from jos_core_acl_groups_aro_map where group_id = ?',
$group
);
Expand All @@ -355,7 +356,7 @@ sub eachGroupMember {
for my $row (@$groupDataset) {

#get rows of users in group
my $userDataset = $this->dbSelect(
my $userDataset = $this->{DB}->select(
$userSelectStatement,
$$row{aro_id} );
my $user_id =
Expand Down Expand Up @@ -386,7 +387,7 @@ sub isGroup {
if ($this->{JoomlaOnePointFive}) {
$groupSelectStatement = 'select id from jos_core_acl_aro_groups where name = ?';
}
my $groupIdDataSet = $this->dbSelect($groupSelectStatement, $user );
my $groupIdDataSet = $this->{DB}->select($groupSelectStatement, $user );
if ( exists $$groupIdDataSet[0] ) {

#print STDERR "$user is a GROUP\n";
Expand Down Expand Up @@ -508,7 +509,7 @@ sub findUserByEmail {

if ($email) {
my $dataset =
$this->dbSelect( 'select * from jos_users where email = ?', $email );
$this->{DB}->select( 'select * from jos_users where email = ?', $email );
if ( exists $$dataset[0] ) {
my @userList = ();
for my $row (@$dataset) {
Expand Down Expand Up @@ -547,7 +548,7 @@ sub getEmails {

if ($cUID) {
my $dataset =
$this->dbSelect( 'select * from jos_users where id = ?', $cUID );
$this->{DB}->select( 'select * from jos_users where id = ?', $cUID );
if ( exists $$dataset[0] ) {
return ( $$dataset[0]{email} );
}
Expand Down Expand Up @@ -599,7 +600,7 @@ sub findUserByWikiName {

if ($wikiname) {
my $dataset =
$this->dbSelect( 'select * from jos_users where name = ?',
$this->{DB}->select( 'select * from jos_users where name = ?',
$wikiname );
if ( exists $$dataset[0] ) {
my @userList = ();
Expand Down Expand Up @@ -713,64 +714,6 @@ sub passwordError {
return $this->{error};
}

###############################################################################
#DB access methods

#todo: cache DB connections
sub getJoomlaDB {
my ( $this, $user ) = @_;
ASSERT( $this->isa('Foswiki::Users::JoomlaUserMapping') ) if DEBUG;
my ( $dbi_dsn, $dbi_user, $dbi_passwd ) = (
$Foswiki::cfg{Plugins}{JoomlaUser}{DBI_dsn},
$Foswiki::cfg{Plugins}{JoomlaUser}{DBI_username},
$Foswiki::cfg{Plugins}{JoomlaUser}{DBI_password}
);

#print STDERR "DBIx::SQLEngine->new( $dbi_dsn, $dbi_user, ...)";

unless ( defined( $this->{JoomlaDB} ) ) {

# Foswiki::Func::writeWarning("DBIx::SQLEngine->new( $dbi_dsn, $dbi_user, ...)");
try {
$this->{JoomlaDB} =
DBIx::SQLEngine->new( $dbi_dsn, $dbi_user, $dbi_passwd );
}
catch Error::Simple with {
$this->{error} = $!;
Foswiki::Func::writeWarning(
"ERROR: DBIx::SQLEngine->new( $dbi_dsn, $dbi_user, ...) : $!");
#die 'MYSQL login error (' . $dbi_dsn . ', ' . $dbi_user . ') ' . $!;
};
}
return $this->{JoomlaDB};
}

#returns an ref to an array dataset of rows
#dbSelect(query, @list of params to query)
sub dbSelect {
my $this = shift;
my @query = @_;
my $dataset;

#print STDERR "fetch_select( @query )";

# Foswiki::Func::writeWarning("fetch_select( @query )");
if (@query) {
try {
my $db = $this->getJoomlaDB();
$dataset = $db->fetch_select( sql => [@query] );
}
catch Error::Simple with {
$this->{error} = $!;
print STDERR " ERROR: fetch_select(@query) : $!";
Foswiki::Func::writeWarning("ERROR: fetch_select(@query) : $!");
};
}

# Foswiki::Func::writeWarning("fetch_select => ".@$dataset);
return $dataset;
}

##############################################
#internal methods
# Convert a login name to the corresponding canonical user name. The
Expand All @@ -789,7 +732,7 @@ sub login2canonical {
# use bytes to ignore character encoding
#$login =~ s/([^a-zA-Z0-9])/'_'.sprintf('%02d', ord($1))/ge;
my $userDataset =
$this->dbSelect( 'select * from jos_users where username = ?',
$this->{DB}->select( 'select * from jos_users where username = ?',
$login );
if ( exists $$userDataset[0] ) {
$canonical_id = $$userDataset[0]{id};
Expand Down Expand Up @@ -818,7 +761,7 @@ sub canonical2login {

my $login = $Foswiki::cfg{DefaultUserLogin};
my $userDataset =
$this->dbSelect( 'select username from jos_users c2l where c2l.id = ?',
$this->{DB}->select( 'select username from jos_users c2l where c2l.id = ?',
$user );
if ( exists $$userDataset[0] ) {
$login = $$userDataset[0]{username};
Expand Down Expand Up @@ -860,7 +803,7 @@ sub _getListOfGroups {
unless ( $this->{groupsList} ) {
$this->{groupsList} = [];
my $dataset =
$this->dbSelect('select name from jos_core_acl_aro_groups');
$this->{DB}->select('select name from jos_core_acl_aro_groups');
for my $row (@$dataset) {
my $groupID = $$row{name};
push @{ $this->{groupsList} }, $groupID;
Expand Down Expand Up @@ -898,7 +841,7 @@ sub fetchPass {

if ($user) {
my $dataset =
$this->dbSelect( 'select * from jos_users where username = ?',
$this->{DB}->select( 'select * from jos_users where username = ?',
$user );

#Foswiki::Func::writeWarning("$@$dataset");
Expand Down

0 comments on commit 84a8418

Please sign in to comment.