Skip to content

Commit

Permalink
Item10734: allow the user to initialise a database when there is no d…
Browse files Browse the repository at this point in the history
…atabase

git-svn-id: http://svn.foswiki.org/trunk/TagsPlugin@11693 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed May 16, 2011
1 parent 1f8189b commit 3ae5c99
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions lib/Foswiki/Plugins/TagsPlugin.pm
Expand Up @@ -57,7 +57,13 @@ sub initPlugin {
{
Foswiki::Func::writeWarning(
"DB schema Version mismatch. Please convert your database.");
return 0;

#TODO: need a more correct error for NO DB INITIALISED yet
#need to allow the user to init, or update the db - so the plugin needs to succeed..
Foswiki::Func::registerRESTHandler( 'initialiseDatabase',
\&initialiseDatabase );
Foswiki::Func::registerRESTHandler( 'convertDatabase', \&convertDatabase );
return 1;
}

Foswiki::Func::registerTagHandler( 'TAGLIST', \&_TAGLIST );
Expand Down Expand Up @@ -722,8 +728,10 @@ sub updateTopicTags {
my $alpha = Foswiki::Func::getRegularExpression('mixedAlphaNum');

#my $capitalized = qr/[$upper][$alpha]+/;
use Foswiki::Plugins::TagsPlugin::Tag;
$text =~
s/[;,\s]([$alpha]*)Category[;,\s]/tagItem($item_type, "$web.$topic", $1, $user_id);tagItem('tag', $1, $web, $user_id);''/geo;
s/[;,\s]([$alpha]+)Category[;,\s]/Foswiki::Plugins::TagsPlugin::Tag::do($item_type, "$web.$topic", $1, $user_id);Foswiki::Plugins::TagsPlugin::Tag::do('tag', $1, $web, $user_id);''/geo;
# Foswiki::Plugins::TagsPlugin::Tag::do( $item_type, "$web.$topic", $tag, Foswiki::Func::getCanonicalUserID("AdminUser") );
}

if ( defined( $Foswiki::cfg{TagsPlugin}{EnableDataForms} )
Expand Down Expand Up @@ -762,6 +770,16 @@ CREATE TABLE IF NOT EXISTS `Items` (
END
my $arrayRef = $db->dbInsert($statement);

$statement = <<'END';
CREATE TABLE IF NOT EXISTS `TagsPlugin_info` (
`name` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=904 DEFAULT CHARSET=latin1;
END
$arrayRef = $db->dbInsert($statement);


$statement = <<'END';
CREATE TABLE IF NOT EXISTS `Users` (
`FoswikicUID` varchar(256) character set ascii NOT NULL,
Expand Down Expand Up @@ -810,6 +828,13 @@ CREATE TABLE IF NOT EXISTS `UserTagStat` (
END
$arrayRef = $db->dbInsert($statement);

#TODO: save the schema version.
# $statement = <<'END';
#UPDATE
#END
# $arrayRef = $db->dbInsert($statement);


#add basic tags
# - each topic is tagged with the web its in (tag type?)
# - import TagMe tags
Expand Down Expand Up @@ -846,6 +871,16 @@ sub convertDatabase {
ALTER TABLE `UserItemTag` ADD COLUMN `public` INT UNSIGNED NOT NULL DEFAULT 0 AFTER `tag_id`;
END
my $arrayRef = $db->dbInsert($statement);

$statement = <<'END';
CREATE TABLE IF NOT EXISTS `TagsPlugin_info` (
`name` varchar(255) NOT NULL,
`value` varchar(255) NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=904 DEFAULT CHARSET=latin1;
END
$arrayRef = $db->dbInsert($statement);

$db->disconnect(); #force a commit

return "ok";
Expand Down

0 comments on commit 3ae5c99

Please sign in to comment.