package JinPluginBaseExtScript; use strict; use base 'JinPluginBase'; sub sql { my $this = shift; my ($query, @param) = @_; my $dbh = $this->dbh or return; my $sth = $dbh->prepare($query) or return $this->failure('error.db_error', $dbh->errstr, $query, join(' ', map { "[$_]" } @param)); $sth->execute(@param) or return $this->failure('error.db_error', $dbh->errstr, $query, join(' ', map { "[$_]" } @param)); $sth; } sub getScriptUID { my $this = shift; my $user = shift; $this->_check_script_uid_table; my $sth = $this->sql("select script_uid from $this->{tblprefix}fantasos_remote_uid_map where fantasos_uid=?", $user->id) or return; scalar $sth->fetchrow_array; } sub fixScriptUID { my $this = shift; my ($user, $script_uid) = @_; $this->_check_script_uid_table; $this->sql("delete from $this->{tblprefix}fantasos_remote_uid_map where fantasos_uid=?", $user->id) or return; if (defined $script_uid) { $this->sql("replace into $this->{tblprefix}fantasos_remote_uid_map set fantasos_uid=?, script_uid=?", $user->id, $script_uid) or return; } return; } sub _check_script_uid_table { my $this = shift; my $sth = $this->sql('show tables like ?', "$this->{tblprefix}fantasos_remote_uid_map") or return; unless ($sth->rows > 0) { $this->sql("
create table $this->{tblprefix}fantasos_remote_uid_map
(
fantasos_uid  int(11) not null, script_uid    varchar(50) not null default '', key(fantasos_uid) ); ") or return; } return; } 1;