Skip to content

Commit

Permalink
Item10990: try to refuse to ask MongoDB about a web with same spellin…
Browse files Browse the repository at this point in the history
…g but different case

git-svn-id: http://svn.foswiki.org/trunk/MongoDBPlugin@12186 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Jul 20, 2011
1 parent 45cbb0a commit 443bbd9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Foswiki/Plugins/MongoDBPlugin.pm
Expand Up @@ -185,6 +185,11 @@ sub updateWebCache {

my $query = Foswiki::Func::getCgiQuery();
my $session = $Foswiki::Plugins::SESSION;

if (not getMongoDB()->databaseNameSafeToUse($web)) {
print STDERR "ERROR: sorry, $web cannot be cached to MongoDB as there is another web with the same spelling, but different case already cached\n";
return "ERROR: sorry, $web cannot be cached to MongoDB as there is another web with the same spelling, but different case already cached\n";
}

#we need to deactivate any listeners :/ () at least stop the loadTopic one from triggering
$session->{store}
Expand Down
27 changes: 27 additions & 0 deletions lib/Foswiki/Plugins/MongoDBPlugin/DB.pm
Expand Up @@ -125,6 +125,12 @@ sub query {
sub update {
my $self = shift;
my $web = shift;

if (not $self->databaseNameSafeToUse($web)) {
print STDERR "ERROR: sorry, $web cannot be cached to MongoDB as there is another web with the same spelling, but different case already cached\n";
return;
}

my $collectionName = shift;
my $address = shift;
my $hash = shift;
Expand Down Expand Up @@ -310,6 +316,11 @@ sub updateSystemJS {
my $functionname = shift;
my $sourcecode = shift;

if (not $self->databaseNameSafeToUse($web)) {
print STDERR "ERROR: sorry, $web cannot be cached to MongoDB as there is another web with the same spelling, but different case already cached\n";
return;
}

my $collection = $self->_getCollection( $web, 'system.js' );

use MongoDB::Code;
Expand Down Expand Up @@ -351,6 +362,22 @@ sub databaseExists {
return;
}

#MongoDB appears to fail when same spelling different case us used for database/collection names
sub databaseNameSafeToUse {
my $self = shift;
my $web = shift;

my $name = $self->getDatabaseName($web);

my $connection = $self->_connect();
my @dbs = $connection->database_names;
foreach my $db_name (@dbs) {
return 1 if ( $name eq $db_name );
return if ( lc($name) eq lc($db_name) );
}
return 1;
}

sub _getDatabase {
my $self = shift;
my $web = shift;
Expand Down
3 changes: 3 additions & 0 deletions lib/Foswiki/Plugins/MongoDBPlugin/Listener.pm
Expand Up @@ -187,6 +187,9 @@ sub loadTopic {
not $Foswiki::cfg{Store}{Listeners}
{'Foswiki::Plugins::MongoDBPlugin::Listener'} );

#fail faster.
return unless (Foswiki::Plugins::MongoDBPlugin::getMongoDB->databaseExists($_[1]->{_web}));

if (
( defined( $_[2] ) ) and #topic versioning in mongodb
(
Expand Down

0 comments on commit 443bbd9

Please sign in to comment.