major mysql cleanup
git-svn-id: http://yolanda.mister-muffin.de/svn@134 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
066eb3d961
commit
b6cac05c7b
9 changed files with 56 additions and 111 deletions
|
@ -29,16 +29,14 @@ if($query->param('id'))
|
||||||
if($rowcount > 0)
|
if($rowcount > 0)
|
||||||
{
|
{
|
||||||
#video is in database - increase referercount
|
#video is in database - increase referercount
|
||||||
$sth = $dbh->prepare(qq{update referer set count=count+1 where videoid = ? and referer = ? }) or die $dbh->errstr;
|
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? },
|
||||||
$sth->execute($query->param('id'), $referer) or die $dbh->errstr;
|
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#add new referer
|
#add new referer
|
||||||
$sth = $dbh->prepare(qq{insert into referer (videoid, referer) values (?, ?) }) or die $dbh->errstr;
|
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) },
|
||||||
$sth->execute($query->param('id'), $referer) or die $dbh->errstr;
|
undef, $query->param('id'), $referer) or die $dbh->errstr;
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,16 +44,14 @@ if($query->param('id'))
|
||||||
if($query->param('view'))
|
if($query->param('view'))
|
||||||
{
|
{
|
||||||
#seems we only want to watch it - update viewcount
|
#seems we only want to watch it - update viewcount
|
||||||
$sth = $dbh->prepare(qq{update videos set viewcount=viewcount+1 where id = ? });
|
$dbh->do(qq{update videos set viewcount=viewcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||||
$sth->execute($query->param('id'));
|
|
||||||
|
|
||||||
print $query->header(-type=>'application/ogg');
|
print $query->header(-type=>'application/ogg');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#video is being downloaded - update downloadcount
|
#video is being downloaded - update downloadcount
|
||||||
$sth = $dbh->prepare(qq{update videos set downloadcount=downloadcount+1 where id = ? });
|
$dbh->do(qq{update videos set downloadcount=downloadcount+1 where id = ? }, undef, $query->param('id')) or die $dbh->errstr;
|
||||||
$sth->execute($query->param('id'));
|
|
||||||
|
|
||||||
print $query->header(-type=>'application/x-download',
|
print $query->header(-type=>'application/x-download',
|
||||||
-attachment=>$title.".ogv");
|
-attachment=>$title.".ogv");
|
||||||
|
@ -68,9 +64,9 @@ if($query->param('id'))
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#there is no video with this id
|
||||||
%page = ();
|
%page = ();
|
||||||
|
|
||||||
#if a username is associated with session id, username is nonempty
|
|
||||||
$page->{'username'} = get_username_from_sid($session->id);
|
$page->{'username'} = get_username_from_sid($session->id);
|
||||||
$page->{'locale'} = $locale;
|
$page->{'locale'} = $locale;
|
||||||
$page->{'stylesheet'} = $stylesheet;
|
$page->{'stylesheet'} = $stylesheet;
|
||||||
|
|
|
@ -55,34 +55,6 @@ sub get_username_from_sid
|
||||||
return $username;
|
return $username;
|
||||||
}
|
}
|
||||||
|
|
||||||
#return a username from passed id
|
|
||||||
sub get_username_from_id
|
|
||||||
{
|
|
||||||
#get parameters
|
|
||||||
my ($id) = @_;
|
|
||||||
|
|
||||||
#connect to db
|
|
||||||
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
|
||||||
|
|
||||||
#prepare query
|
|
||||||
my $sth = $dbh->prepare(qq{select username from users where id = ?}) or die $dbh->errstr;
|
|
||||||
|
|
||||||
#execute it
|
|
||||||
$sth->execute($id) or die $dbh->errstr;
|
|
||||||
|
|
||||||
#save the resulting username
|
|
||||||
my ($username) = $sth->fetchrow_array();
|
|
||||||
|
|
||||||
#finish query
|
|
||||||
$sth->finish() or die $dbh->errstr;
|
|
||||||
|
|
||||||
#close db
|
|
||||||
$dbh->disconnect() or die $dbh->errstr;
|
|
||||||
|
|
||||||
#return
|
|
||||||
return $username;
|
|
||||||
}
|
|
||||||
|
|
||||||
#return a username from passed session id
|
#return a username from passed session id
|
||||||
sub get_userid_from_sid
|
sub get_userid_from_sid
|
||||||
{
|
{
|
||||||
|
|
|
@ -60,9 +60,7 @@ while(1)
|
||||||
appendlog $id, "invalid stream";
|
appendlog $id, "invalid stream";
|
||||||
|
|
||||||
#write status 2 to uploaded table
|
#write status 2 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
elsif ($info =~ /I\/O error occured/)
|
elsif ($info =~ /I\/O error occured/)
|
||||||
|
@ -70,9 +68,7 @@ while(1)
|
||||||
appendlog $id, "file not found";
|
appendlog $id, "file not found";
|
||||||
|
|
||||||
#write status 3 to uploaded table
|
#write status 3 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 3, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(3, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
|
elsif ($info =~ /Unknown format/ or $info =~ /could not find codec parameters/)
|
||||||
|
@ -80,9 +76,7 @@ while(1)
|
||||||
appendlog $id, "file is no video";
|
appendlog $id, "file is no video";
|
||||||
|
|
||||||
#write status 4 to uploaded table
|
#write status 4 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 4, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(4, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -103,9 +97,7 @@ while(1)
|
||||||
appendlog "$id, video already uploaded: $resultid";
|
appendlog "$id, video already uploaded: $resultid";
|
||||||
|
|
||||||
#write status 5 to uploaded table
|
#write status 5 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 5, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(5, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -121,9 +113,7 @@ while(1)
|
||||||
appendlog $id, "a stream is missing or video is corrupt";
|
appendlog $id, "a stream is missing or video is corrupt";
|
||||||
|
|
||||||
#write status 2 to uploaded table
|
#write status 2 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 2, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(2, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -155,12 +145,11 @@ while(1)
|
||||||
appendlog $id, "file already is ogg-theora/vorbis";
|
appendlog $id, "file already is ogg-theora/vorbis";
|
||||||
|
|
||||||
#add video to videos table
|
#add video to videos table
|
||||||
$sth = $dbh->prepare(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
||||||
subject, contributor, source, language, coverage, rights, license, notice,
|
subject, contributor, source, language, coverage, rights, license, notice,
|
||||||
derivativeworks, sharealike, commercialuse, ?, ?, ?, ?, ?, ?, 0, 0
|
derivativeworks, sharealike, commercialuse, ?, ?, ?, ?, ?, ?, 0, 0
|
||||||
from uploaded where id = ?}) or interrupt $dbh->errstr;
|
from uploaded where id = ?}, undef, $filesize, $duration, $width,
|
||||||
$sth->execute($filesize, $duration, $width, $height, $fps, $sha, $id) or interrupt $dbh->errstr;
|
$height, $fps, $sha, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
|
|
||||||
#move video
|
#move video
|
||||||
move "$gnutube_root/tmp/$id", "$gnutube_root/videos/$id";
|
move "$gnutube_root/tmp/$id", "$gnutube_root/videos/$id";
|
||||||
|
@ -173,21 +162,18 @@ while(1)
|
||||||
appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha;
|
appendlog $id, $audio, $video, $width, $height, $fps, $duration, $sha;
|
||||||
|
|
||||||
#add video to videos table
|
#add video to videos table
|
||||||
$sth = $dbh->prepare(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
$dbh->do(qq{insert into videos select id, title, description, userid, timestamp, creator,
|
||||||
subject, contributor, source, language, coverage, rights, license, notice,
|
subject, contributor, source, language, coverage, rights, license, notice,
|
||||||
derivativeworks, sharealike, commercialuse, ?, ?, ?, ?, ?, ?, 0, 0
|
derivativeworks, sharealike, commercialuse, ?, ?, ?, ?, ?, ?, 0, 0
|
||||||
from uploaded where id = ?}) or interrupt $dbh->errstr;
|
from uploaded where id = ?}, undef, $filesize, $duration, $width,
|
||||||
$sth->execute($filesize, $duration, $width, $height, $fps, $sha, $id) or interrupt $dbh->errstr;
|
$height, $fps, $sha, $id) or interrupt $dbh->errstr;
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
|
|
||||||
#delete temp file
|
#delete temp file
|
||||||
unlink "$gnutube_root/tmp/$id";
|
unlink "$gnutube_root/tmp/$id";
|
||||||
}
|
}
|
||||||
|
|
||||||
#write status 1 to uploaded table
|
#write status 1 to uploaded table
|
||||||
$sth = $dbh->prepare(qq{update uploaded set status = ? where id = ?}) or interrupt $dbh->errstr;
|
$dbh->do(qq{update uploaded set status = ? where id = ?}, undef, 1, $id) or interrupt $dbh->errstr;
|
||||||
$sth->execute(1, $id) or interrupt $dbh->errstr;
|
|
||||||
$sth->finish() or interrupt $dbh->errstr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,7 @@ if($query->param('action'))
|
||||||
if($sth->fetchrow_array())
|
if($sth->fetchrow_array())
|
||||||
{
|
{
|
||||||
#store session id in database
|
#store session id in database
|
||||||
$sth = $dbh->prepare(qq{update users set sid = ? where username = ? });
|
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $query->param('user')) or die $dbh->errstr;
|
||||||
$sth->execute($session->id, $query->param('user'));
|
|
||||||
$sth->finish();
|
|
||||||
print $query->redirect("index.pl?information=information_logged_in");
|
print $query->redirect("index.pl?information=information_logged_in");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -92,16 +90,12 @@ if($query->param('action'))
|
||||||
if($sth->fetchrow_array())
|
if($sth->fetchrow_array())
|
||||||
{
|
{
|
||||||
#store session id in database
|
#store session id in database
|
||||||
$sth = $dbh->prepare(qq{update users set sid = ? where username = ? });
|
$dbh->do(qq{update users set sid = ? where username = ? }, undef, $session->id, $verified_url) or die $dbh->errstr;
|
||||||
$sth->execute($session->id, $verified_url);
|
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#add openid user to dabase
|
#add openid user to dabase
|
||||||
$sth = $dbh->prepare(qq{insert into users (username, sid) values ( ?, ? ) });
|
$dbh->do(qq{insert into users (username, sid) values ( ?, ? ) }, undef, $verified_url, $session->id) or die $dbh->errstr;
|
||||||
$sth->execute($verified_url, $session->id);
|
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print $query->redirect("index.pl?information=information_logged_in");
|
print $query->redirect("index.pl?information=information_logged_in");
|
||||||
|
@ -124,9 +118,7 @@ if($query->param('action'))
|
||||||
{
|
{
|
||||||
#if logout is requested
|
#if logout is requested
|
||||||
#remove sid from database
|
#remove sid from database
|
||||||
$sth = $dbh->prepare(qq{update users set sid = '' where username = ?});
|
$dbh->do(qq{update users set sid = '' where username = ?}, undef, get_username_from_sid($session->id)) or die $dbh->errstr;
|
||||||
$sth->execute(get_username_from_sid($session->id));
|
|
||||||
$sth->finish();
|
|
||||||
$session->delete();
|
$session->delete();
|
||||||
print $session->header();
|
print $session->header();
|
||||||
print "logged out";
|
print "logged out";
|
||||||
|
|
|
@ -14,13 +14,8 @@ if($query->param('user') and $query->param('pass'))
|
||||||
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
my $dbh = DBI->connect("DBI:mysql:$database:$host", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#do query
|
#do query
|
||||||
$sth = $dbh->prepare(qq{insert into users (username, password) values ( ?, password( ? ))}) or die $dbh->errstr;
|
$dbh->de(qq{insert into users (username, password) values ( ?, password( ? ))}, undef,
|
||||||
|
$query->param("user"), $query->param("pass")) or die $dbh->errstr;
|
||||||
#execute it
|
|
||||||
$sth->execute($query->param("user"), $query->param("pass")) or die $dbh->errstr;
|
|
||||||
|
|
||||||
#finish query
|
|
||||||
$sth->finish() or die $dbh->errstr;
|
|
||||||
|
|
||||||
#disconnect db
|
#disconnect db
|
||||||
$dbh->disconnect() or die $dbh->errstr;
|
$dbh->disconnect() or die $dbh->errstr;
|
||||||
|
|
|
@ -25,13 +25,16 @@ if($query->param('query'))
|
||||||
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#prepare query
|
#prepare query
|
||||||
my $sth = $dbh->prepare(qq{select id, title, description, userid, timestamp from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr;
|
my $sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp )
|
||||||
|
from videos as v, users as u
|
||||||
|
where match(v.title, v.description, v.subject) against( ? )
|
||||||
|
and u.id = v.userid }) or die $dbh->errstr;
|
||||||
|
|
||||||
#execute it
|
#execute it
|
||||||
$sth->execute($query->param('query')) or die $dbh->errstr;
|
$sth->execute($query->param('query')) or die $dbh->errstr;
|
||||||
|
|
||||||
#get every returned value
|
#get every returned value
|
||||||
while (my ($id, $title, $description, $userid, $timestamp) = $sth->fetchrow_array())
|
while (my ($id, $title, $description, $username, $timestamp) = $sth->fetchrow_array())
|
||||||
{
|
{
|
||||||
#before code cleanup, this was a really obfuscated array/hash creation
|
#before code cleanup, this was a really obfuscated array/hash creation
|
||||||
push @{ $page->{'results'}->{'result'} },
|
push @{ $page->{'results'}->{'result'} },
|
||||||
|
@ -44,7 +47,7 @@ if($query->param('query'))
|
||||||
'rdf:about' => "./video.pl?title=$title&id=$id",
|
'rdf:about' => "./video.pl?title=$title&id=$id",
|
||||||
'dc:title' => [$title],
|
'dc:title' => [$title],
|
||||||
'dc:date' => [$timestamp],
|
'dc:date' => [$timestamp],
|
||||||
'dc:publisher' => [get_username_from_id($userid)]
|
'dc:publisher' => [$username]
|
||||||
},
|
},
|
||||||
'cc:License' =>
|
'cc:License' =>
|
||||||
{
|
{
|
||||||
|
@ -84,13 +87,15 @@ elsif($query->param('sort'))
|
||||||
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
my $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass) or die $dbh->errstr;
|
||||||
|
|
||||||
#prepare query
|
#prepare query
|
||||||
my $sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ) from videos order by timestamp desc }) or die $dbh->errstr;
|
my $sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp )
|
||||||
|
from videos as v, users as u
|
||||||
|
where u.id = v.userid order by v.timestamp desc}) or die $dbh->errstr;
|
||||||
|
|
||||||
#execute it
|
#execute it
|
||||||
$sth->execute($query->param('query')) or die $dbh->errstr;
|
$sth->execute($query->param('query')) or die $dbh->errstr;
|
||||||
|
|
||||||
#get every returned value
|
#get every returned value
|
||||||
while (my ($id, $title, $description, $userid, $timestamp) = $sth->fetchrow_array())
|
while (my ($id, $title, $description, $username, $timestamp) = $sth->fetchrow_array())
|
||||||
{
|
{
|
||||||
#before code cleanup, this was a really obfuscated array/hash creation
|
#before code cleanup, this was a really obfuscated array/hash creation
|
||||||
push @{ $page->{'results'}->{'result'} },
|
push @{ $page->{'results'}->{'result'} },
|
||||||
|
@ -103,7 +108,7 @@ elsif($query->param('sort'))
|
||||||
'rdf:about' => "./video.pl?title=$title&id=$id",
|
'rdf:about' => "./video.pl?title=$title&id=$id",
|
||||||
'dc:title' => [$title],
|
'dc:title' => [$title],
|
||||||
'dc:date' => [$timestamp],
|
'dc:date' => [$timestamp],
|
||||||
'dc:publisher' => [get_username_from_id($userid)]
|
'dc:publisher' => [$username]
|
||||||
},
|
},
|
||||||
'cc:License' =>
|
'cc:License' =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,7 @@ if($username)
|
||||||
$page->{'xmlns:dc'} = $xmlns_dc;
|
$page->{'xmlns:dc'} = $xmlns_dc;
|
||||||
$page->{'xmlns:cc'} = $xmlns_cc;
|
$page->{'xmlns:cc'} = $xmlns_cc;
|
||||||
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
$page->{'xmlns:rdf'} = $xmlns_rdf;
|
||||||
$page->{uploadform} = [''];
|
$page->{uploadform} = {'page' => '2'};
|
||||||
|
|
||||||
#print xml http header along with session cookie
|
#print xml http header along with session cookie
|
||||||
print $session->header(-type=>'text/xml');
|
print $session->header(-type=>'text/xml');
|
||||||
|
@ -30,7 +30,6 @@ else
|
||||||
{
|
{
|
||||||
%page = ();
|
%page = ();
|
||||||
|
|
||||||
#if a username is associated with session id, username is nonempty
|
|
||||||
$page->{'username'} = get_username_from_sid($session->id);
|
$page->{'username'} = get_username_from_sid($session->id);
|
||||||
$page->{'locale'} = $locale;
|
$page->{'locale'} = $locale;
|
||||||
$page->{'stylesheet'} = $stylesheet;
|
$page->{'stylesheet'} = $stylesheet;
|
||||||
|
|
|
@ -27,13 +27,12 @@ if($userid)
|
||||||
|
|
||||||
#make new entry for video into the databse
|
#make new entry for video into the databse
|
||||||
#FIXME: contributor, rights
|
#FIXME: contributor, rights
|
||||||
my $sth = $dbh->prepare(qq{insert into uploaded (title, description, userid, timestamp,
|
$dbh->do(qq{insert into uploaded (title, description, userid, timestamp,
|
||||||
creator, subject, contributor, source, language, coverage, rights)
|
creator, subject, contributor, source, language, coverage, rights)
|
||||||
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}) or die $dbh->errstr;
|
values ( ?, ?, ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ? )}, undef,
|
||||||
$sth->execute($query->param("DC.Title"), $query->param("DC.Description"), $userid,
|
$query->param("DC.Title"), $query->param("DC.Description"), $userid,
|
||||||
$query->param("DC.Creator"), $query->param("DC.Subject"), '', $query->param("DC.Source"),
|
$query->param("DC.Creator"), $query->param("DC.Subject"), '', $query->param("DC.Source"),
|
||||||
$query->param("DC.Language"), $query->param("DC.Coverage"), '') or die $dbh->errstr;
|
$query->param("DC.Language"), $query->param("DC.Coverage"), '') or die $dbh->errstr;
|
||||||
$sth->finish() or die $dbh->errstr;
|
|
||||||
|
|
||||||
#get the id of the inserted db entry
|
#get the id of the inserted db entry
|
||||||
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
$sth = $dbh->prepare(qq{select last_insert_id() }) or die $dbh->errstr;
|
||||||
|
|
|
@ -35,9 +35,11 @@ if($query->url_param('title') or $query->url_param('id'))
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if no id was passed there has to be a title we search for
|
#if no id was passed there has to be a title we search for
|
||||||
$sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ),
|
$sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||||
creator, subject, contributor, source, language, coverage, rights, license
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
||||||
from videos where title = ? }) or die $dbh->errstr;
|
v.license, filesize, duration, width, height, fps, viewcount,
|
||||||
|
downloadcount
|
||||||
|
from videos as v, users as u where v.title = ? and u.id=v.userid }) or die $dbh->errstr;
|
||||||
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +47,12 @@ if($query->url_param('title') or $query->url_param('id'))
|
||||||
#if there was a title passed, then perform a search
|
#if there was a title passed, then perform a search
|
||||||
if($rowcount == 0 and $query->url_param('title'))
|
if($rowcount == 0 and $query->url_param('title'))
|
||||||
{
|
{
|
||||||
$sth = $dbh->prepare(qq{select id, title, description, userid, from_unixtime( timestamp ),
|
$sth = $dbh->prepare(qq{select v.id, v.title, v.description, u.username, from_unixtime( v.timestamp ),
|
||||||
creator, subject, contributor, source, language, coverage, rights, license
|
v.creator, v.subject, v.contributor, v.source, v.language, v.coverage, v.rights,
|
||||||
from videos where match(title, description, subject) against( ? ) }) or die $dbh->errstr;
|
v.license, filesize, duration, width, height, fps, viewcount,
|
||||||
|
downloadcount
|
||||||
|
from videos as v, users as u where match(v.title, v.description, v.subject) against( ? )
|
||||||
|
and u.id=v.userid }) or die $dbh->errstr;
|
||||||
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
$rowcount = $sth->execute($query->url_param('title')) or die $dbh->errstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,16 +102,12 @@ if($query->url_param('title') or $query->url_param('id'))
|
||||||
if($rowcount > 0)
|
if($rowcount > 0)
|
||||||
{
|
{
|
||||||
#video is in database - increase referercount
|
#video is in database - increase referercount
|
||||||
$sth = $dbh->prepare(qq{update referer set count=count+1 where videoid = ? and referer = ? }) or die $dbh->errstr;
|
$dbh->do(qq{update referer set count=count+1 where videoid = ? and referer = ? }, undef, $id, $referer) or die $dbh->errstr;
|
||||||
$sth->execute($id, $referer) or die $dbh->errstr;
|
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#add new referer
|
#add new referer
|
||||||
$sth = $dbh->prepare(qq{insert into referer (videoid, referer) values (?, ?) }) or die $dbh->errstr;
|
$dbh->do(qq{insert into referer (videoid, referer) values (?, ?) }, undef, $id, $referer) or die $dbh->errstr;
|
||||||
$sth->execute($id, $referer) or die $dbh->errstr;
|
|
||||||
$sth->finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue