Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions settings/Config.Example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ ffmpeg_max_threads = 8
; Movie generation queue
movie_queue = "api_movie"

[database]
; Table names for the movies, screenshots, and client_states tables. Override
; these if those tables live under different names in your database (e.g. a
; shared database, or a per-instance naming scheme). Defaults shown; leaving
; them unset keeps the canonical names, so no change is required for a normal
; install. Every query in the API resolves the table through these values.
db_table_movies = "movies"
db_table_screenshots = "screenshots"
db_table_client_states = "client_states"

[statistics]
; Whether basic usage statistics should be collected by Helioviewer.org.
; Currently the information collected is very basic and does not include
Expand Down
13 changes: 13 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ private function _setAdditionalParams() {
define('HV_LOG_DIR', HV_ROOT_DIR . '/../log');
define('HV_CACHE_URL', HV_WEB_ROOT_URL . '/cache');

// Database table names. Overridable from Config.ini (db_table_movies,
// db_table_screenshots, db_table_client_states); default to the
// canonical names so existing deployments need no config change.
if ( !defined('HV_DB_TABLE_MOVIES') ) {
define('HV_DB_TABLE_MOVIES', 'movies');
}
if ( !defined('HV_DB_TABLE_SCREENSHOTS') ) {
define('HV_DB_TABLE_SCREENSHOTS', 'screenshots');
}
if ( !defined('HV_DB_TABLE_CLIENT_STATES') ) {
define('HV_DB_TABLE_CLIENT_STATES', 'client_states');
}

// 1 au in meters (http://maia.usno.navy.mil/NSFA/IAU2009_consts.html)
define('HV_CONSTANT_AU', 149597870700);
// Solar radius in arc-seconds at 1 au
Expand Down
10 changes: 5 additions & 5 deletions src/Database/ClientState.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function upsert(array $state): string
$state_json = json_encode($state);
$state_key = hash('sha256',$state_json);

$create_sql = "REPLACE INTO client_states(id, state) VALUES ('%s','%s')";
$create_sql = "REPLACE INTO " . HV_DB_TABLE_CLIENT_STATES . "(id, state) VALUES ('%s','%s')";
$create_state_sql = sprintf($create_sql, $state_key, $this->link->real_escape_string($state_json));

// intentionally let exception thrown
Expand All @@ -40,7 +40,7 @@ public function upsert(array $state): string
*/
public function find(string $state_key): ?array
{
$find_sql = "SELECT * FROM client_states WHERE id = '%s' LIMIT 1";
$find_sql = "SELECT * FROM " . HV_DB_TABLE_CLIENT_STATES . " WHERE id = '%s' LIMIT 1";

$find_state_sql = sprintf($find_sql, $this->link->real_escape_string($state_key));

Expand All @@ -66,7 +66,7 @@ public function find(string $state_key): ?array
*/
public function all(int $limit = 100): ?array
{
$all_sql = "SELECT * FROM client_states LIMIT $limit";
$all_sql = "SELECT * FROM " . HV_DB_TABLE_CLIENT_STATES . " LIMIT $limit";

$query_result = $this->query($all_sql);

Expand All @@ -85,7 +85,7 @@ public function all(int $limit = 100): ?array
*/
public function update(string $state_key, array $state): bool
{
$find_sql = "SELECT * FROM client_states WHERE id = '%s' LIMIT 1";
$find_sql = "SELECT * FROM " . HV_DB_TABLE_CLIENT_STATES . " WHERE id = '%s' LIMIT 1";

$find_state_sql = sprintf($find_sql, $this->link->real_escape_string($state_key));

Expand All @@ -96,7 +96,7 @@ public function update(string $state_key, array $state): bool
return false;
}

$update_sql = "UPDATE client_states SET state = '%s' WHERE id = '%s'";
$update_sql = "UPDATE " . HV_DB_TABLE_CLIENT_STATES . " SET state = '%s' WHERE id = '%s'";

$update_state_sql = sprintf($update_sql, $this->link->real_escape_string(json_encode($state)), $this->link->real_escape_string($state_key));

Expand Down
12 changes: 6 additions & 6 deletions src/Database/ImgIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function insertScreenshot($date, $imageScale, $roi, $watermark, $layers,


$sql = sprintf(
"INSERT INTO screenshots "
"INSERT INTO " . HV_DB_TABLE_SCREENSHOTS . " "
. "SET "
. "id " . " = NULL, "
. "timestamp " . " = CURRENT_TIMESTAMP, "
Expand Down Expand Up @@ -137,7 +137,7 @@ public function getMovieInformation($movieId) {

$sql = sprintf(
"SELECT movies.*, movieFormats.movieId, movieFormats.format, movieFormats.status, movieFormats.procTime, movieFormats.modified, ST_AsText(regionOfInterest) AS roi "
. "FROM movies "
. "FROM " . HV_DB_TABLE_MOVIES . " movies "
. "LEFT JOIN "
. "movieFormats ON movies.id = movieFormats.movieId "
. "WHERE "
Expand Down Expand Up @@ -169,7 +169,7 @@ public function storeMovieProperties($movieId, $startDate, $endDate,
$this->_dbConnect();

$sql = sprintf(
"UPDATE movies "
"UPDATE " . HV_DB_TABLE_MOVIES . " "
. "SET "
. "startDate " . " ='%s', "
. "endDate " . " ='%s', "
Expand Down Expand Up @@ -217,7 +217,7 @@ public function finishedBuildingMovieFrames($movieId, $buildTimeStart,
$this->_dbConnect();

$sql = sprintf(
"UPDATE movies "
"UPDATE " . HV_DB_TABLE_MOVIES . " "
. "SET "
. "buildTimeStart='%s', "
. "buildTimeEnd='%s' "
Expand Down Expand Up @@ -350,7 +350,7 @@ public function getScreenshot($screenshotId) {

$sql = sprintf(
"SELECT * "
. "FROM screenshots "
. "FROM " . HV_DB_TABLE_SCREENSHOTS . " "
. "WHERE id = %d "
. "LIMIT 1;",
(int)$screenshotId
Expand Down Expand Up @@ -1631,7 +1631,7 @@ public function getScreenshotMetadata($screenshotId) {
$this->_dbConnect();

$sql = sprintf('SELECT *, ST_AsText(regionOfInterest) as roi ' .
'FROM screenshots WHERE id=%d LIMIT 1;',
'FROM ' . HV_DB_TABLE_SCREENSHOTS . ' WHERE id=%d LIMIT 1;',
(int)$screenshotId
);
try {
Expand Down
10 changes: 5 additions & 5 deletions src/Database/MovieDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function insertMovie($startTime, $endTime, $reqObservationDate, $imageSca
$old_events_labels_bool = false;

$sql = sprintf(
'INSERT INTO movies '
'INSERT INTO ' . HV_DB_TABLE_MOVIES . ' '
. 'SET '
. 'id ' . ' = NULL, '
. 'timestamp ' . ' = CURRENT_TIMESTAMP, '
Expand Down Expand Up @@ -282,7 +282,7 @@ public function getMovieStatistics($n=100) {
. 'queueNum, '
. 'TIMESTAMPDIFF(SECOND, buildTimeStart, buildTimeEnd) '
. 'AS time '
. 'FROM movies '
. 'FROM ' . HV_DB_TABLE_MOVIES . ' '
. 'WHERE '
. 'TIMESTAMPDIFF(SECOND, buildTimeStart, buildTimeEnd) '
. '> 0 '
Expand Down Expand Up @@ -360,7 +360,7 @@ public function getSharedVideos($num, $skip, $since, $force=false) {
. 'youtube.keywords, youtube.shared, movies.imageScale, movies.dataSourceString, movies.eventSourceString, '
. 'movies.movieLength, movies.width, movies.height, movies.startDate, movies.endDate '
. 'FROM youtube '
. 'LEFT JOIN movies '
. 'LEFT JOIN ' . HV_DB_TABLE_MOVIES . ' movies '
. 'ON movies.id = youtube.movieId '
. 'WHERE '
. 'youtube.shared>0 AND '
Expand Down Expand Up @@ -427,7 +427,7 @@ public function getSharedVideosByTime($num, $skip, $date) {
. 'youtube.keywords, youtube.thumbnail, youtube.shared, youtube.checked, movies.imageScale, movies.dataSourceString, movies.eventSourceString, '
. 'movies.movieLength, movies.width, movies.height, movies.startDate, movies.endDate, ST_AsText(regionOfInterest) as roi '
. 'FROM youtube '
. 'LEFT JOIN movies '
. 'LEFT JOIN ' . HV_DB_TABLE_MOVIES . ' movies '
. 'ON movies.id = youtube.movieId '
. 'WHERE '
. 'youtube.shared>0 AND '
Expand Down Expand Up @@ -493,7 +493,7 @@ public function getMovieMetadata($movieId) {
$this->_dbConnect();

$sql = sprintf('SELECT *, ST_AsText(regionOfInterest) as roi '
. 'FROM movies WHERE movies.id=%d LIMIT 1;',
. 'FROM ' . HV_DB_TABLE_MOVIES . ' movies WHERE movies.id=%d LIMIT 1;',
(int)$movieId
);
try {
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu

$sqlScreenshots = sprintf(
"SELECT dataSourceString "
. "FROM movies "
. "FROM " . HV_DB_TABLE_MOVIES . " "
. "WHERE "
. "timestamp BETWEEN '%s' AND '%s' ;",
$this->_dbConnection->link->real_escape_string($dateStartStr),
Expand Down Expand Up @@ -655,7 +655,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu

$sqlScreenshots = sprintf(
"SELECT dataSourceString "
. "FROM screenshots "
. "FROM " . HV_DB_TABLE_SCREENSHOTS . " "
. "WHERE "
. "timestamp BETWEEN '%s' AND '%s' ;",
$this->_dbConnection->link->real_escape_string($dateStartStr),
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/database/ClientStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testItShouldCreateClientState(): void
// just a precaution to clean database after we are done
$this->createdIds[] = $client_state->upsert($state);

$count_sql = sprintf("SELECT COUNT(*) FROM client_states WHERE id = '%s'", hash('sha256', json_encode($state)));
$count_sql = sprintf("SELECT COUNT(*) FROM " . HV_DB_TABLE_CLIENT_STATES . " WHERE id = '%s'", hash('sha256', json_encode($state)));

$result = $client_state->query($count_sql);

Expand All @@ -49,7 +49,7 @@ public function testItShouldOnlyCreateDBInstancePerClientState(): void
$client_state->upsert($state);
$client_state->upsert($state);

$count_sql = sprintf("SELECT COUNT(*) FROM client_states WHERE id = '%s'", hash('sha256', json_encode($state)));
$count_sql = sprintf("SELECT COUNT(*) FROM " . HV_DB_TABLE_CLIENT_STATES . " WHERE id = '%s'", hash('sha256', json_encode($state)));

$result = $client_state->query($count_sql);

Expand Down Expand Up @@ -103,7 +103,7 @@ public function testItShouldNotFindNonExistingStates(): void
public function tearDown(): void
{
$client_state = new ClientState();
$client_state->query(sprintf("DELETE FROM client_states WHERE id in ('%s') LIMIT %d", join("','", $this->createdIds), count($this->createdIds)));
$client_state->query(sprintf("DELETE FROM " . HV_DB_TABLE_CLIENT_STATES . " WHERE id in ('%s') LIMIT %d", join("','", $this->createdIds), count($this->createdIds)));
}


Expand Down
Loading