Merge pull request '[I57] MySQL implementation' (#65) from MySQL into main

Reviewed-on: rho_n/hpr_generator#65
This commit is contained in:
Roan Horning 2023-02-12 12:59:13 +00:00
commit a213efa695
26 changed files with 384 additions and 180 deletions

View File

@ -3,12 +3,22 @@ Static web page generator for the Hacker Public Radio website.
## Installation ## Installation
* Clone or download this repository * Clone or download this repository
* Create the sqlite3 database from the files in the _sql directory. The default name for the database file is "hpr.db" and should be located in the root of the project directory. The name and location can be set in the site.cfg file. * With SQLite
* Two sql helper scripts are available to generate an empty database or a database filled with test data. * Create the sqlite3 database from the files in the _sql directory. The default name for the database file is "hpr.db" and should be located in the root of the project directory. The name and location can be set in the site.cfg file.
- For an empty database: `cat Create_Database_Empty.sql | sqlite3 hpr.db` * Two sql helper scripts are available to generate an empty database or a database filled with test data.
- For a database with test data: `cat Create_Database_Test.sql | sqlite3 hpr.db` - For an empty database: `cat Create_Database_Empty.sql | sqlite3 hpr.db`
* SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. Must convert WITH - For a database with test data: `cat Create_Database_Test.sql | sqlite3 hpr.db`
clauses to sub-queries when using earlier versions of SQLite. * SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. Must convert WITH
clauses to sub-queries when using earlier versions of SQLite.
* With MySQL
* Create database hpr_hpr in the MySQL server from HPR dump file.
- ``sudo mysql --host=localhost < hpr.sql``
* Create a user that will be used by the site-generator.
- Suggested username: hpr-generator
- ``CREATE USER 'hpr-generator'@'localhost' IDENTIFIED BY '<password>';``
* Limit the user's privileges to EXECUTE and SELECT
- ``GRANT SELECT ON hpr_hpr.* TO 'hpr-generator'@'localhost';``
- ``GRANT EXECUTE ON `hpr_hpr`.* TO 'hpr-generator'@'localhost';``
* Install the needed Perl modules using preferred method (distribution packages, CPAN, etc.) * Install the needed Perl modules using preferred method (distribution packages, CPAN, etc.)
* GetOpt * GetOpt
* Pod::Usage * Pod::Usage
@ -18,7 +28,7 @@ Static web page generator for the Hacker Public Radio website.
* Template::Plugin::DBI * Template::Plugin::DBI
* DBI * DBI
* Tie::DBI * Tie::DBI
* DBD::SQLite * DBD::SQLite or DBD:mysql
* Date::Calc * Date::Calc
## Usage ## Usage
@ -50,4 +60,3 @@ and add the label "**Feature Request**".
## Authors and acknowledgment ## Authors and acknowledgment
* Roan "Rho`n" Horning * Roan "Rho`n" Horning

View File

@ -35,15 +35,27 @@ This is a site generator for the Hacker Public Radio website based upon the Perl
=head1 INSTALLATION =head1 INSTALLATION
With SQLite
* Create the sqlite3 database from the files in the _sql directory. The default name for the * Create the sqlite3 database from the files in the _sql directory. The default name for the
database file is "hpr.db" and should be located in the root of the project directory. The database file is "hpr.db" and should be located in the root of the project directory. The
name and location can be set in the site.cfg file. name and location can be set in the site.cfg file.
* Two sql helper scripts are available to generate an empty database or a database filled with test data. * Two sql helper scripts are available to generate an empty database or a database filled with test data.
- For an empty database: `cat Create_Database_Empty.sql | sqlite3 hpr.db` - For an empty database: cat Create_Database_Empty.sql | sqlite3 hpr.db
- For a database with test data: `cat Create_Database_Test.sql | sqlite3 hpr.db` - For a database with test data: cat Create_Database_Test.sql | sqlite3 hpr.db
* SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries. Must convert WITH * SQLite v3.8.3 or greater is recommended. CTE WITH clauses are used in some template queries.
clauses to sub-queries when using earlier versions of SQLite. Must convert WITH clauses to sub-queries when using earlier versions of SQLite.
* Install the needed Perl modules using preferred method (distribution packages, CPAN, etc.)
With MySQL
* Create database hpr_hpr in the MySQL server from HPR dump file.
- sudo mysql --host=localhost < hpr.sql
* Create a user that will be used by the site-generator.
- Suggested username: hpr-generator
- CREATE USER 'hpr-generator'@'localhost' IDENTIFIED BY '<password>';
* Limit the user's privileges to EXECUTE and SELECT
- GRANT SELECT ON hpr_hpr.* TO 'hpr-generator'@'localhost';
- GRANT EXECUTE ON `hpr_hpr`.* TO 'hpr-generator'@'localhost';
Install the needed Perl modules using preferred method (distribution packages, CPAN, etc.)
* GetOpt * GetOpt
* Pod::Usage * Pod::Usage
* Config::Std * Config::Std
@ -52,7 +64,7 @@ This is a site generator for the Hacker Public Radio website based upon the Perl
* Template::Plugin::DBI * Template::Plugin::DBI
* DBI * DBI
* Tie::DBI * Tie::DBI
* DBD::SQLite * DBD::SQLite or DBD:mysql
* Date::Calc * Date::Calc
=head1 AUTHOR =head1 AUTHOR
@ -186,6 +198,7 @@ sub get_template_html (\%@) {
PRE_CHOMP => 1, PRE_CHOMP => 1,
POST_CHOMP => 1, POST_CHOMP => 1,
CONSTANTS => { CONSTANTS => {
database => $_[0]{database},
driver => $_[0]{driver}, driver => $_[0]{driver},
user => $_[0]{user}, user => $_[0]{user},
password => $_[0]{password}, password => $_[0]{password},

View File

@ -2,9 +2,10 @@
# with the database. # with the database.
# dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name> # dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name>
[DBI] [DBI]
driver: dbi:SQLite:hpr.db database: mysql
user: driver: dbi:mysql:database=hpr_hpr:hostname=localhost
password: user: hpr-generator
password: zBozqN-Z2zNAz
# Configure the root template page which pulls in the navigation and # Configure the root template page which pulls in the navigation and
# content templates used by each page. An optional baseurl property may # content templates used by each page. An optional baseurl property may
@ -13,6 +14,8 @@ password:
[root_template] [root_template]
content: page.tpl.html content: page.tpl.html
#baseurl: OPTIONAL [i.e. file://<full path to local website directory>] #baseurl: OPTIONAL [i.e. file://<full path to local website directory>]
baseurl: file:///home/roan/Development/hpr/website/hpr_generator/public_html/
media_baseurl: https://archive.org/download/hpr$eps_id/
# Configure the navigation menu and the content templates for each page # Configure the navigation menu and the content templates for each page
# of the site: # of the site:
@ -137,6 +140,7 @@ navigation: navigation-get-shows.tpl.html
content: content-twat_episode.tpl.html content: content-twat_episode.tpl.html
multipage: true multipage: true
filename: eps/twat[id]/index.html filename: eps/twat[id]/index.html
media_baseurl: https://www.hackerpublicradio.org/eps/
[mumble-howto] [mumble-howto]
navigation: navigation-about.tpl.html navigation: navigation-about.tpl.html

View File

@ -1,31 +1,18 @@
<!--% PROCESS 'shared-episode-summary.tpl.html' %--> <!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<!--% PROCESS 'shared-avatar.tpl.html' %--> <!--% PROCESS 'shared-avatar.tpl.html' %-->
<!--% PROCESS 'shared-utils.tpl.html' %--> <!--% PROCESS 'shared-utils.tpl.html' %-->
<!--% PROCESS "queries-correspondent-${constants.database}.tpl.html" %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% query_hpr_show_count = DBI.prepare(' <!--% query_hpr_show_count = DBI.prepare('
SELECT id SELECT id
FROM eps FROM eps
WHERE eps.hostid = ? ') WHERE eps.hostid = ?
')
%--> %-->
<!--% query_hpr_shows = DBI.prepare(' <!--% results_hpr_shows = DBI.prepare(query_hpr_shows)
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE hosts.hostid = ? AND eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC ')
%--> %-->
<!--% hpr_shows_to_count = query_hpr_show_count.execute(id); %--> <!--% hpr_shows_to_count = query_hpr_show_count.execute(id); %-->
<!--% hpr_shows = query_hpr_shows.execute(id); %--> <!--% hpr_shows = results_hpr_shows.execute(id); %-->
<!--% hpr_show_count = 0 %--> <!--% hpr_show_count = 0 %-->
<!--% FOREACH show IN hpr_shows_to_count %--> <!--% FOREACH show IN hpr_shows_to_count %-->
<!--% hpr_show_count = hpr_show_count +1; %--> <!--% hpr_show_count = hpr_show_count +1; %-->
@ -33,8 +20,9 @@
<!--% query_twat_show_count = DBI.prepare(' <!--% query_twat_show_count = DBI.prepare('
SELECT id SELECT id
FROM twat_eps AS \'eps\' FROM twat_eps AS eps
WHERE eps.hostid = ? ') WHERE eps.hostid = ?
')
%--> %-->
<!--% query_twat_shows = DBI.prepare(' <!--% query_twat_shows = DBI.prepare('
SELECT SELECT
@ -51,7 +39,7 @@
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
WHERE hosts.hostid = ? WHERE hosts.hostid = ?
ORDER BY eps.id + 0 DESC ORDER BY eps.id DESC
') ')
%--> %-->
<!--% twat_shows_to_count = query_twat_show_count.execute(id); %--> <!--% twat_shows_to_count = query_twat_show_count.execute(id); %-->

View File

@ -2,57 +2,9 @@
<!--% PROCESS 'shared-avatar.tpl.html' %--> <!--% PROCESS 'shared-avatar.tpl.html' %-->
<!--% PROCESS 'shared-utils.tpl.html' %--> <!--% PROCESS 'shared-utils.tpl.html' %-->
<!--% PROCESS 'shared-listen-now.tpl.html' %--> <!--% PROCESS 'shared-listen-now.tpl.html' %-->
<!--% PROCESS "queries-episode-${constants.database}.tpl.html" %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% query_episodes = DBI.prepare(' <!--% query_episodes = DBI.prepare(query_episode_maxmin)
WITH episode_maxmin AS (
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
FROM eps
WHERE eps.date < date (\'now\', \'+1 days\')
),
episode_date AS (
SELECT eps.date
FROM eps
WHERE eps.id = ?
),
episode_previous AS (
SELECT MAX(id) AS \'previous\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date < episode_date.date
WHERE eps.id > 1
),
episode_next AS (
SELECT MIN(id) AS \'next\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date > episode_date.date
WHERE eps.date < date (\'now\')
),
comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT eps.id, eps.date, eps.title, eps.duration,
eps.summary, eps.notes, eps.explicit, eps.license,
eps.tags, eps.version, eps.downloads, eps.valid,
episode_maxmin.latest, episode_maxmin.earliest,
episode_previous.previous, episode_next.next,
hosts.hostid, hosts.host,
miniseries.name AS \'series\', miniseries.id AS \'seriesid\',
miniseries.description AS \'series_description\',
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
INNER JOIN episode_maxmin ON eps.id = episode_maxmin.id
INNER JOIN episode_previous ON eps.id = episode_previous.id
INNER JOIN episode_next ON eps.id = episode_next.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.id = ?
')
%--> %-->
<!--% episode_result = query_episodes.execute(id, id, id, id, id) %--> <!--% episode_result = query_episodes.execute(id, id, id, id, id) %-->
<!--% FOREACH episode IN episode_result %--> <!--% FOREACH episode IN episode_result %-->

View File

@ -1,4 +1,5 @@
<!--% PROCESS 'shared-episode-summary.tpl.html' %--> <!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<!--% PROCESS "queries-episodes-${constants.database}.tpl.html" %-->
<article> <article>
<header> <header>
<h1>Complete Archive of Shows.</h1> <h1>Complete Archive of Shows.</h1>
@ -7,21 +8,7 @@
</p> </p>
</header> </header>
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH episodes IN DBI.query(' <!--% FOREACH episodes IN DBI.query(query_episodes)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
')
%--> %-->
<!--% show_summary(episodes) %--> <!--% show_summary(episodes) %-->
<!--% END %--> <!--% END %-->
@ -42,7 +29,7 @@
FROM twat_eps as eps FROM twat_eps as eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
ORDER BY eps.id + 0 DESC ORDER BY eps.id DESC
') ')
%--> %-->
<!--% twat_show_summary(twat_episode) %--> <!--% twat_show_summary(twat_episode) %-->

View File

@ -3,6 +3,7 @@
<!--% PROCESS 'shared-listen-now.tpl.html' %--> <!--% PROCESS 'shared-listen-now.tpl.html' %-->
<!--% PROCESS 'shared-call_for_shows.tpl.html' %--> <!--% PROCESS 'shared-call_for_shows.tpl.html' %-->
<!--% INCLUDE 'content-index-announcement.tpl.html' %--> <!--% INCLUDE 'content-index-announcement.tpl.html' %-->
<!--% PROCESS "queries-index-${constants.database}.tpl.html" %-->
<hr> <hr>
<article> <article>
<header> <header>
@ -10,20 +11,7 @@
</header> </header>
<!--% days_till_next_episode = 0 %--> <!--% days_till_next_episode = 0 %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH next_available_episode_result IN DBI.query(' <!--% FOREACH next_available_episode_result IN DBI.query(query_next_available_episode)
WITH next_id AS (SELECT id, id + 1 AS \'id_next\', date as \'last_date\'
FROM eps
WHERE eps.date > date(\'now\')
)
SELECT
MIN (next_id.id_next) AS \'next_id\',
strftime(\'%Y\', MIN (last_date)) AS \'last_year\',
strftime(\'%d\', MIN (last_date)) AS \'last_day\',
strftime(\'%m\', MIN (last_date)) AS \'last_month\'
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
')
%--> %-->
<!--% USE date %--> <!--% USE date %-->
<!--% calc = date.calc %--> <!--% calc = date.calc %-->
@ -46,33 +34,7 @@
<hr> <hr>
<!--% PROCESS 'shared-episode-summary.tpl.html' %--> <!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<h1>Latest Shows</h1> <h1>Latest Shows</h1>
<!--% FOREACH latest_episodes IN DBI.query(' <!--% FOREACH latest_episodes IN DBI.query(query_latest_episodes)
WITH comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
LIMIT 10
')
%--> %-->
<hr> <hr>
<article> <article>
@ -98,22 +60,7 @@
<hr> <hr>
<h1>Previous five weeks</h1> <h1>Previous five weeks</h1>
</header> </header>
<!--% FOREACH last_5_weeks_episodes IN DBI.query(' <!--% FOREACH last_5_weeks_episodes IN DBI.query(query_last_5_weeks_episodes)
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
LIMIT 30 OFFSET 10
')
%--> %-->
<!--% show_summary(last_5_weeks_episodes) %--> <!--% show_summary(last_5_weeks_episodes) %-->
<!--% END %--> <!--% END %-->

View File

@ -38,7 +38,7 @@
INNER JOIN hosts INNER JOIN hosts
ON eps.hostid = hosts.hostid ON eps.hostid = hosts.hostid
WHERE series = ? WHERE series = ?
ORDER BY eps.id + 0 DESC ORDER BY eps.id DESC
') ')
%--> %-->
<!--% show_results = query_shows.execute(id) %--> <!--% show_results = query_shows.execute(id) %-->

View File

@ -7,7 +7,6 @@
WITH episode_maxmin AS ( WITH episode_maxmin AS (
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\' SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
FROM twat_eps AS eps FROM twat_eps AS eps
WHERE eps.date < date (\'now\', \'+1 days\')
), ),
episode_date AS ( episode_date AS (
SELECT eps.date SELECT eps.date
@ -26,7 +25,6 @@
FROM twat_eps AS eps FROM twat_eps AS eps
INNER JOIN episode_date INNER JOIN episode_date
ON eps.date > episode_date.date ON eps.date > episode_date.date
WHERE eps.date < date (\'now\')
) )
SELECT eps.id, eps.date, eps.title, eps.duration, SELECT eps.id, eps.date, eps.title, eps.duration,
eps.summary, eps.notes, eps.explicit, eps.license, eps.summary, eps.notes, eps.explicit, eps.license,

View File

@ -1,8 +1,6 @@
<!--% PROCESS "queries-ids-episode-${constants.database}.tpl.html" %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH episode IN DBI.query( <!--% FOREACH episode IN DBI.query(query_ids_episode) %-->
'select eps.id from eps
where eps.date < date (\'now\', \'+1 days\') '
) %-->
,<!--% episode.id %--> ,<!--% episode.id %-->
<!--% END %--> <!--% END %-->

View File

@ -1,7 +1,6 @@
<!--% USE DBI(constants.driver, constants.user, constants.password) %--> <!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH episode IN DBI.query( <!--% FOREACH episode IN DBI.query(
'select eps.id from twat_eps AS \'eps\' 'select eps.id from twat_eps AS eps'
where eps.date < date (\'now\', \'+1 days\') '
) %--> ) %-->
,<!--% episode.id %--> ,<!--% episode.id %-->
<!--% END %--> <!--% END %-->

View File

@ -0,0 +1,6 @@
<!--% query_call_for_shows = '
SELECT CASE WHEN COUNT(id) < 7 THEN True ELSE False END AS `request_for_shows`
FROM eps
WHERE eps.date > NOW() AND eps.date < DATE_ADD(NOW(), INTERVAL 10 DAY)
'
%-->

View File

@ -0,0 +1,6 @@
<!--% query_call_for_shows = '
SELECT CASE WHEN COUNT(id) < 7 THEN True ELSE False END AS `request_for_shows`
FROM eps
WHERE eps.date > date(\'now\') AND eps.date < date(\'now\', \'+10 days\')
'
%-->

View File

@ -0,0 +1,18 @@
<!--% query_hpr_shows = '
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE hosts.hostid = ? AND eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.id DESC
'
%-->

View File

@ -0,0 +1,18 @@
<!--% query_hpr_shows = '
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE hosts.hostid = ? AND eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
'
%-->

View File

@ -0,0 +1,51 @@
<!--% query_episode_maxmin = '
WITH episode_maxmin AS (
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
FROM eps
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
),
episode_date AS (
SELECT eps.date
FROM eps
WHERE eps.id = ?
),
episode_previous AS (
SELECT MAX(id) AS \'previous\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date < episode_date.date
WHERE eps.id > 1
),
episode_next AS (
SELECT MIN(id) AS \'next\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date > episode_date.date
WHERE eps.date < NOW()
),
comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT eps.id, eps.date, eps.title, eps.duration,
eps.summary, eps.notes, eps.explicit, eps.license,
eps.tags, eps.version, eps.downloads, eps.valid,
episode_maxmin.latest, episode_maxmin.earliest,
episode_previous.previous, episode_next.next,
hosts.hostid, hosts.host,
miniseries.name AS \'series\', miniseries.id AS \'seriesid\',
miniseries.description AS \'series_description\',
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
INNER JOIN episode_maxmin ON eps.id = episode_maxmin.id
INNER JOIN episode_previous ON eps.id = episode_previous.id
INNER JOIN episode_next ON eps.id = episode_next.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.id = ?
'
%-->

View File

@ -0,0 +1,51 @@
<!--% query_episode_maxmin = '
WITH episode_maxmin AS (
SELECT MAX(id) AS \'latest\', MIN(id) AS \'earliest\', ? AS \'id\'
FROM eps
WHERE eps.date < date(\'now\', \'+1 days\')
),
episode_date AS (
SELECT eps.date
FROM eps
WHERE eps.id = ?
),
episode_previous AS (
SELECT MAX(id) AS \'previous\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date < episode_date.date
WHERE eps.id > 1
),
episode_next AS (
SELECT MIN(id) AS \'next\', ? AS \'id\'
FROM eps
INNER JOIN episode_date
ON eps.date > episode_date.date
WHERE eps.date < date(\'now\')
),
comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT eps.id, eps.date, eps.title, eps.duration,
eps.summary, eps.notes, eps.explicit, eps.license,
eps.tags, eps.version, eps.downloads, eps.valid,
episode_maxmin.latest, episode_maxmin.earliest,
episode_previous.previous, episode_next.next,
hosts.hostid, hosts.host,
miniseries.name AS \'series\', miniseries.id AS \'seriesid\',
miniseries.description AS \'series_description\',
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
INNER JOIN episode_maxmin ON eps.id = episode_maxmin.id
INNER JOIN episode_previous ON eps.id = episode_previous.id
INNER JOIN episode_next ON eps.id = episode_next.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.id = ?
'
%-->

View File

@ -0,0 +1,15 @@
<!--% query_episodes = 'SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.id DESC'
%-->

View File

@ -0,0 +1,15 @@
<!--% query_episodes = 'SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC'
%-->

View File

@ -0,0 +1,4 @@
<!--% query_ids_episode = 'select eps.id from eps
where eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY) '
%-->

View File

@ -0,0 +1,4 @@
<!--% query_ids_episode = 'select eps.id from eps
where eps.date < date(\'now\', \'+1 days\')'
%-->

View File

@ -0,0 +1,62 @@
<!--% query_next_available_episode = '
WITH next_id AS (
SELECT id, id + 1 AS \'id_next\', date as \'last_date\'
FROM eps
WHERE eps.date > NOW()
)
SELECT
MIN(next_id.id_next) AS \'next_id\',
DATE_FORMAT(MIN(last_date), \'%Y\') AS \'last_year\',
DATE_FORMAT(MIN(last_date), \'%d\') AS \'last_day\',
DATE_FORMAT(MIN(last_date), \'%m\') AS \'last_month\'
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
'
%-->
<!--% query_latest_episodes = '
WITH comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.id DESC
LIMIT 10
'
%-->
<!--% query_last_5_weeks_episodes = '
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.id DESC
LIMIT 30 OFFSET 10
'
%-->

View File

@ -0,0 +1,62 @@
<!--% query_next_available_episode = '
WITH next_id AS (
SELECT id, id + 1 AS \'id_next\', date as \'last_date\'
FROM eps
WHERE eps.date > date(\'now\')
)
SELECT
MIN(next_id.id_next) AS \'next_id\',
strftime(\'%Y\', MIN (last_date)) AS \'last_year\',
strftime(\'%d\', MIN (last_date)) AS \'last_day\',
strftime(\'%m\', MIN (last_date)) AS \'last_month\'
FROM next_id
LEFT JOIN eps ON next_id.id_next = eps.id
WHERE eps.id IS NULL
'
%-->
<!--% query_latest_episodes = '
WITH comment_tallies AS (
SELECT
eps_id,
COUNT(eps_id) AS eps_tally
FROM comments
GROUP BY eps_id
)
SELECT
eps.id,
eps.explicit,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.notes,
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email,
miniseries.name AS series, miniseries.id AS seriesid,
COALESCE (comment_tallies.eps_tally, 0) AS eps_tally
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
LEFT JOIN comment_tallies ON eps.id = comment_tallies.eps_id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
LIMIT 10
'
%-->
<!--% query_last_5_weeks_episodes = '
SELECT
eps.id,
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.title, eps.summary,
eps.duration, eps.notes, eps.tags,
hosts.hostid,
hosts.host, hosts.email, hosts.local_image,
miniseries.name AS series, miniseries.id AS seriesid
FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\')
ORDER BY eps.id + 0 DESC
LIMIT 30 OFFSET 10
'
%-->

View File

@ -3,7 +3,7 @@
SELECT SELECT
eps.id, eps.id,
eps.explicit, eps.explicit,
strftime(\'%H:%M:%S %d:%m:%Y\', date(eps.date)) AS date, DATE_FORMAT(eps.date, \'%H:%i:%S %d:%m:%Y\') AS \'date\',
eps.license, eps.duration, eps.license, eps.duration,
eps.title, eps.summary, eps.tags, eps.title, eps.summary, eps.tags,
eps.notes, eps.notes,
@ -14,7 +14,7 @@
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\') WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.date DESC ORDER BY eps.date DESC
LIMIT 10 LIMIT 10
') ')

View File

@ -3,7 +3,7 @@
SELECT SELECT
eps.id, eps.id,
eps.explicit, eps.explicit,
strftime(\'%H:%M:%S %d:%m:%Y\', date(eps.date)) AS date, DATE_FORMAT(eps.date, \'%H:%i:%S %d:%m:%Y\') AS \'date\',
eps.license, eps.duration, eps.license, eps.duration,
eps.title, eps.summary, eps.tags, eps.title, eps.summary, eps.tags,
eps.notes, eps.notes,
@ -14,7 +14,7 @@
FROM eps FROM eps
INNER JOIN hosts ON eps.hostid = hosts.hostid INNER JOIN hosts ON eps.hostid = hosts.hostid
INNER JOIN miniseries ON eps.series = miniseries.id INNER JOIN miniseries ON eps.series = miniseries.id
WHERE eps.date < date(\'now\', \'+1 days\') WHERE eps.date < DATE_ADD(NOW(), INTERVAL 1 DAY)
ORDER BY eps.date DESC ORDER BY eps.date DESC
') ')
%--> %-->

View File

@ -1,12 +1,9 @@
<!--% PROCESS 'shared-utils.tpl.html' %--> <!--% PROCESS 'shared-utils.tpl.html' %-->
<!--% PROCESS "queries-call_for_shows-${constants.database}.tpl.html" %-->
<!--% MACRO display_call_for_shows BLOCK %--> <!--% MACRO display_call_for_shows BLOCK %-->
<!--% query_call_for_shows = DBI.prepare(' <!--% result_call_for_shows = DBI.prepare(query_call_for_shows)
SELECT CASE WHEN COUNT(id) < 7 THEN True ELSE False END AS `request_for_shows`
FROM eps
WHERE eps.date > date(\'now\') AND eps.date < date(\'now\', \'+10 days\')
')
%--> %-->
<!--% results_call_for_shows = query_call_for_shows.execute().get_all() %--> <!--% results_call_for_shows = result_call_for_shows.execute().get_all() %-->
<!--% IF results_call_for_shows.0.request_for_shows == 1 %--> <!--% IF results_call_for_shows.0.request_for_shows == 1 %-->
<!--% USE date %--> <!--% USE date %-->
<article> <article>