X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=cgi-files%2FModules%2FDatabase%2FMySQL5.pm;h=80bc32322b6c7695e7e8ab3b7d13404c262a7a89;hb=f4287e42a5e96cffe70d84a3c659d5be3eab46d5;hp=d04430f7d5e6204a48563e0af1a6c3a44fac13ee;hpb=619a8b2bf4dd5962a191c154966d9467d76325ad;p=kiriwrite%2F.git diff --git a/cgi-files/Modules/Database/MySQL5.pm b/cgi-files/Modules/Database/MySQL5.pm index d04430f..80bc323 100644 --- a/cgi-files/Modules/Database/MySQL5.pm +++ b/cgi-files/Modules/Database/MySQL5.pm @@ -21,17 +21,17 @@ # Define the package (perl module) name. -package Kiriwrite::Database::MySQL; +package Kiriwrite::Database::MySQL5; # Enable strict and use warnings. use strict; use warnings; -use Encode; +use Encode qw(decode_utf8); # Load the following Perl modules. -use DBI; +use DBI qw(:sql_types); # Set the following values. @@ -625,49 +625,6 @@ sub getdblist{ } -sub getseconddatabaseinfo{ -################################################################################# -# getseconddatabaseinfo: Get information about the database that pages will be # -# moved or copied to. # -# # -# Usage: # -# # -# $dbmodule->getseconddatabaseinfo(); # -################################################################################# - - - # Get the database information. - - my $class = shift; - my ($databaseinfo, %databaseinfo); - my ($sqldata, @sqldata); - - $error = ""; - $errorext = ""; - - $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); - $string_handle->execute(); - - @sqldata = $string_handle->fetchrow_array(); - - # Process the database information into a hash. - - %databaseinfo = ( - "DatabaseName" => decode_utf8($sqldata[0]), - "Description" => decode_utf8($sqldata[1]), - "Notes" => decode_utf8($sqldata[2]), - "Categories" => decode_utf8($sqldata[3]), - "Major" => decode_utf8($sqldata[4]), - "Minor" => decode_utf8($sqldata[5]), - "Revision" => decode_utf8($sqldata[6]) - ); - - $string_handle->finish(); - - return %databaseinfo; - -} - sub selectdb{ ################################################################################# # selectdb: Selects the Kiriwrite database. # @@ -708,6 +665,48 @@ sub selectdb{ } +sub getdatabaseinfo{ +################################################################################# +# getdatabaseinfo: Get information about the database. # +# # +# Usage: # +# # +# $dbmodule->getdatabaseinfo(); # +################################################################################# + + # Get the database information. + + $error = ""; + $errorext = ""; + + my $class = shift; + my ($databaseinfo, %databaseinfo); + my ($sqldata, @sqldata); + + $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + @sqldata = $string_handle->fetchrow_array(); + + # Process the database information into a hash. + + %databaseinfo = ( + + "DatabaseName" => decode_utf8($sqldata[0]), + "Description" => decode_utf8($sqldata[1]), + "Notes" => decode_utf8($sqldata[2]), + "Categories" => decode_utf8($sqldata[3]), + "Major" => decode_utf8($sqldata[4]), + "Minor" => decode_utf8($sqldata[5]), + "Revision" => decode_utf8($sqldata[6]) + ); + + $string_handle->finish(); + + return %databaseinfo; + +} + sub selectseconddb{ ################################################################################# # selectseconddb: Selects a second Kiriwrite database for moving and copying # @@ -754,25 +753,27 @@ sub selectseconddb{ } -sub getdatabaseinfo{ +sub getseconddatabaseinfo{ ################################################################################# -# getdatabaseinfo: Get information about the database. # +# getseconddatabaseinfo: Get information about the database that pages will be # +# moved or copied to. # # # # Usage: # # # -# $dbmodule->getdatabaseinfo(); # +# $dbmodule->getseconddatabaseinfo(); # ################################################################################# - # Get the database information. - $error = ""; - $errorext = ""; + # Get the database information. my $class = shift; my ($databaseinfo, %databaseinfo); my ($sqldata, @sqldata); - $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $error = ""; + $errorext = ""; + + $string_handle = $database_handle->prepare('SELECT name, description, notes, categories, kiriwrite_version_major, kiriwrite_version_minor, kiriwrite_version_revision FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($second_database_filename) . '_database_info LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); $string_handle->execute(); @sqldata = $string_handle->fetchrow_array(); @@ -780,7 +781,6 @@ sub getdatabaseinfo{ # Process the database information into a hash. %databaseinfo = ( - "DatabaseName" => decode_utf8($sqldata[0]), "Description" => decode_utf8($sqldata[1]), "Notes" => decode_utf8($sqldata[2]), @@ -1211,7 +1211,7 @@ sub addtemplate{ # # # Usage: # # # -# $dbmodule->addtemplate(); # +# $dbmodule->addtemplate(options); # # # # options Specifies the following options in any order. # # # @@ -1325,58 +1325,6 @@ sub addtemplate{ } -sub deletetemplate{ -################################################################################# -# deletetemplate: Deletes a template from the template database. # -# # -# Usage: # -# # -# $dbmodule->deletetemplate(options); # -# # -# options Specifies the following options in any order. # -# # -# TemplateFilename Specifies the template filename to delete. # -################################################################################# - - $error = ""; - $errorext = ""; - - # Get the data passed to the subroutine. - - my $class = shift; - my ($passedoptions) = @_; - - my @pagedata; - my $template_filename = $passedoptions->{"TemplateFilename"}; - my $template_count = 0; - - # Check if the template exists. - - $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); - $string_handle->execute(); - - while (@pagedata = $string_handle->fetchrow_array()){ - - $template_count++; - - } - - if ($template_count eq 0){ - - # No pages were returned so return an error value. - - $error = "TemplateDoesNotExist"; - return; - - } - - # Delete the template from the template database. - - $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); - $string_handle->execute(); - -} - sub edittemplate{ ################################################################################# # editttemplate: Edits a Kiriwrite template. # @@ -1449,6 +1397,58 @@ sub edittemplate{ } +sub deletetemplate{ +################################################################################# +# deletetemplate: Deletes a template from the template database. # +# # +# Usage: # +# # +# $dbmodule->deletetemplate(options); # +# # +# options Specifies the following options in any order. # +# # +# TemplateFilename Specifies the template filename to delete. # +################################################################################# + + $error = ""; + $errorext = ""; + + # Get the data passed to the subroutine. + + my $class = shift; + my ($passedoptions) = @_; + + my @pagedata; + my $template_filename = $passedoptions->{"TemplateFilename"}; + my $template_count = 0; + + # Check if the template exists. + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\' LIMIT 1') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + while (@pagedata = $string_handle->fetchrow_array()){ + + $template_count++; + + } + + if ($template_count eq 0){ + + # No pages were returned so return an error value. + + $error = "TemplateDoesNotExist"; + return; + + } + + # Delete the template from the template database. + + $string_handle = $database_handle->prepare('DELETE FROM ' . $class->convert($options{"TablePrefix"}) . '_templates WHERE filename = \'' . $class->convert($template_filename) . '\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + +} + ################################################################################# # Page subroutines. # ################################################################################# @@ -1498,6 +1498,8 @@ sub getpageinfo{ # options Specifies the following options in any order. # # # # PageFilename Specifies the page filename to get the page information from. # +# Reduced Specifies if the reduced version of the page information should # +# be retrieved. # ################################################################################# $error = ""; @@ -1514,42 +1516,76 @@ sub getpageinfo{ # Get the page from the database. my $page_filename = $passedoptions->{"PageFilename"}; + my $page_reduced = $passedoptions->{"Reduced"}; - $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); - $string_handle->execute(); + if ($page_reduced eq 1){ - # Check if the page exists in the database. + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); - while (@data_page = $string_handle->fetchrow_array()){ + # Check if the page exists in the database. - # Get the values from the array. + while (@data_page = $string_handle->fetchrow_array()){ - $pagefilename = decode_utf8($data_page[0]); - $pagename = decode_utf8($data_page[1]); - $pagedescription = decode_utf8($data_page[2]); - $pagesection = decode_utf8($data_page[3]); - $pagetemplate = decode_utf8($data_page[4]); - $pagedata = decode_utf8($data_page[5]); - $pagesettings = decode_utf8($data_page[6]); - $pagelastmodified = decode_utf8($data_page[7]); + # Get the values from the array. - # Put the values into the page hash. + $pagefilename = decode_utf8($data_page[0]); + $pagename = decode_utf8($data_page[1]); + $pagedescription = decode_utf8($data_page[2]); + $pagelastmodified = decode_utf8($data_page[3]); - %database_page = ( - "PageFilename" => $pagefilename, - "PageName" => $pagename, - "PageDescription" => $pagedescription, - "PageSection" => $pagesection, - "PageTemplate" => $pagetemplate, - "PageContent" => $pagedata, - "PageSettings" => $pagesettings, - "PageLastModified" => $class->dateconvert($pagelastmodified), - ); + # Put the values into the page hash. - $page_found = 1; + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageLastModified" => $class->dateconvert($pagelastmodified), + ); - } + $page_found = 1; + + } + } else { + + $string_handle = $database_handle->prepare('SELECT filename, pagename, pagedescription, pagesection, pagetemplate, pagedata, pagesettings, lastmodified FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_filename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if the page exists in the database. + + while (@data_page = $string_handle->fetchrow_array()){ + + # Get the values from the array. + + $pagefilename = decode_utf8($data_page[0]); + $pagename = decode_utf8($data_page[1]); + $pagedescription = decode_utf8($data_page[2]); + $pagesection = decode_utf8($data_page[3]); + $pagetemplate = decode_utf8($data_page[4]); + $pagedata = decode_utf8($data_page[5]); + $pagesettings = decode_utf8($data_page[6]); + $pagelastmodified = decode_utf8($data_page[7]); + + # Put the values into the page hash. + + %database_page = ( + "PageFilename" => $pagefilename, + "PageName" => $pagename, + "PageDescription" => $pagedescription, + "PageSection" => $pagesection, + "PageTemplate" => $pagetemplate, + "PageContent" => $pagedata, + "PageSettings" => $pagesettings, + "PageLastModified" => $class->dateconvert($pagelastmodified), + ); + + $page_found = 1; + + } + + } + # Check if the page did exist. if (!$page_found){ @@ -1794,6 +1830,35 @@ sub editpage{ } + # Check if there is a page that already exists with the new + # filename. + + $page_found = 0; + + if ($page_filename ne $page_newfilename){ + + $string_handle = $database_handle->prepare('SELECT filename FROM ' . $class->convert($options{"TablePrefix"}) . '_' . $class->convert($database_filename) . '_database_pages WHERE filename = \'' . $class->convert($page_newfilename) . '\' LIMIT 1') or ( $error = "DatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle->execute(); + + # Check if a page really is using the new filename. + + while (@page_info = $string_handle->fetchrow_array()){ + + # The page information is found. + + $page_found = 1; + + } + + if ($page_found eq 1){ + + $error = "PageAlreadyExists"; + return; + + } + + } + # Get the current date. my ($created_second, $created_minute, $created_hour, $created_day, $created_month, $created_year, $created_weekday, $created_yearday, $created_dst) = localtime; @@ -2072,7 +2137,7 @@ sub connectfilter{ # Check if the template database exists. - $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_filters\'') or ( $error = "TemplateDatabaseError", $errorext = $database_handle->errstr, return ); + $string_handle = $database_handle->prepare('SHOW TABLES LIKE \'' . $class->convert($options{"TablePrefix"}) . '_filters\'') or ( $error = "FilterDatabaseError", $errorext = $database_handle->errstr, return ); $string_handle->execute(); while (@filterdb_check = $string_handle->fetchrow_array()){ @@ -2358,11 +2423,11 @@ sub addfilter{ } - # Check if there were any filters in the filters database. + # Check if there were any filters in the filter database. if (!$filter_count && !$new_id){ - # There were no filters in the filters database so set + # There were no filters in the filter database so set # the new filter identification value to 1. $new_id = 1;