forked from Cavemanon/cavepaintings
Database driver constants
This commit is contained in:
@@ -201,14 +201,14 @@ class AdminPage extends Extension
|
||||
$database = $matches['dbname'];
|
||||
|
||||
switch ($software) {
|
||||
case 'mysql':
|
||||
case Database::MYSQL_DRIVER:
|
||||
$cmd = "mysqldump -h$hostname -u$username -p$password $database";
|
||||
break;
|
||||
case 'pgsql':
|
||||
case Database::PGSQL_DRIVER:
|
||||
putenv("PGPASSWORD=$password");
|
||||
$cmd = "pg_dump -h $hostname -U $username $database";
|
||||
break;
|
||||
case 'sqlite':
|
||||
case Database::SQLITE_DRIVER:
|
||||
$cmd = "sqlite3 $database .dump";
|
||||
break;
|
||||
default:
|
||||
@@ -257,7 +257,7 @@ class AdminPage extends Extension
|
||||
//TODO: Update score_log (Having an optional ID column for score_log would be nice..)
|
||||
preg_match("#^(?P<proto>\w+)\:(?:user=(?P<user>\w+)(?:;|$)|password=(?P<password>\w*)(?:;|$)|host=(?P<host>[\w\.\-]+)(?:;|$)|dbname=(?P<dbname>[\w_]+)(?:;|$))+#", DATABASE_DSN, $matches);
|
||||
|
||||
if ($matches['proto'] == "mysql") {
|
||||
if ($matches['proto'] == Database::MYSQL_DRIVER) {
|
||||
$tables = $database->get_col("SELECT TABLE_NAME
|
||||
FROM information_schema.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = :db
|
||||
@@ -280,9 +280,9 @@ class AdminPage extends Extension
|
||||
$i++;
|
||||
}
|
||||
$database->execute("ALTER TABLE images AUTO_INCREMENT=".(count($ids) + 1));
|
||||
} elseif ($matches['proto'] == "pgsql") {
|
||||
} elseif ($matches['proto'] == Database::PGSQL_DRIVER) {
|
||||
//TODO: Make this work with PostgreSQL
|
||||
} elseif ($matches['proto'] == "sqlite") {
|
||||
} elseif ($matches['proto'] == Database::SQLITE_DRIVER) {
|
||||
//TODO: Make this work with SQLite
|
||||
}
|
||||
return true;
|
||||
|
@@ -45,7 +45,7 @@ class AdminPageTheme extends Themelet
|
||||
$html .= $this->button("Download all images", "download_all_images", false);
|
||||
}
|
||||
$html .= $this->button("Download database contents", "database_dump", false);
|
||||
if ($database->get_driver_name() == "mysql") {
|
||||
if ($database->get_driver_name() == Database::MYSQL_DRIVER) {
|
||||
$html .= $this->button("Reset image IDs", "reset_image_ids", true);
|
||||
}
|
||||
$page->add_block(new Block("Misc Admin Tools", $html));
|
||||
|
@@ -480,14 +480,14 @@ class CommentList extends Extension
|
||||
global $config, $database;
|
||||
|
||||
// sqlite fails at intervals
|
||||
if ($database->get_driver_name() === "sqlite") {
|
||||
if ($database->get_driver_name() === Database::SQLITE_DRIVER) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$window = int_escape($config->get_int('comment_window'));
|
||||
$max = int_escape($config->get_int('comment_limit'));
|
||||
|
||||
if ($database->get_driver_name() == "mysql") {
|
||||
if ($database->get_driver_name() == Database::MYSQL_DRIVER) {
|
||||
$window_sql = "interval $window minute";
|
||||
} else {
|
||||
$window_sql = "interval '$window minute'";
|
||||
|
@@ -157,7 +157,7 @@ class IndexTest extends ShimmiePHPUnitTestCase
|
||||
|
||||
global $database;
|
||||
$db = $database->get_driver_name();
|
||||
if ($db == "pgsql" || $db == "sqlite") {
|
||||
if ($db == Database::PGSQL_DRIVER || $db == Database::SQLITE_DRIVER) {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
|
@@ -235,7 +235,7 @@ class IPBan extends Extension
|
||||
{
|
||||
global $config, $database;
|
||||
|
||||
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
|
||||
$prefix = ($database->get_driver_name() == Database::SQLITE_DRIVER ? "bans." : "");
|
||||
|
||||
$bans = $this->get_active_bans();
|
||||
|
||||
|
@@ -16,7 +16,7 @@ class IPBanTheme extends Themelet
|
||||
{
|
||||
global $database, $user;
|
||||
$h_bans = "";
|
||||
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
|
||||
$prefix = ($database->get_driver_name() == Database::SQLITE_DRIVER ? "bans." : "");
|
||||
foreach ($bans as $ban) {
|
||||
$end_human = date('Y-m-d', $ban[$prefix.'end_timestamp']);
|
||||
$h_bans .= "
|
||||
|
@@ -68,7 +68,7 @@ class LogDatabase extends Extension
|
||||
$args["module"] = $_GET["module"];
|
||||
}
|
||||
if (!empty($_GET["user"])) {
|
||||
if ($database->get_driver_name() == "pgsql") {
|
||||
if ($database->get_driver_name() == Database::PGSQL_DRIVER) {
|
||||
if (preg_match("#\d+\.\d+\.\d+\.\d+(/\d+)?#", $_GET["user"])) {
|
||||
$wheres[] = "(username = :user1 OR text(address) = :user2)";
|
||||
$args["user1"] = $_GET["user"];
|
||||
|
@@ -37,7 +37,7 @@ class RatingSetEvent extends Event
|
||||
|
||||
class Ratings extends Extension
|
||||
{
|
||||
protected $db_support = ['mysql','pgsql']; // ?
|
||||
protected $db_support = [Database::MYSQL_DRIVER,Database::PGSQL_DRIVER];
|
||||
|
||||
public function get_priority(): int
|
||||
{
|
||||
@@ -331,10 +331,10 @@ class Ratings extends Extension
|
||||
if ($config->get_int("ext_ratings2_version") < 3) {
|
||||
$database->Execute("UPDATE images SET rating = 'u' WHERE rating is null");
|
||||
switch ($database->get_driver_name()) {
|
||||
case "mysql":
|
||||
case Database::MYSQL_DRIVER:
|
||||
$database->Execute("ALTER TABLE images CHANGE rating rating CHAR(1) NOT NULL DEFAULT 'u'");
|
||||
break;
|
||||
case "pgsql":
|
||||
case Database::PGSQL_DRIVER:
|
||||
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET DEFAULT 'u'");
|
||||
$database->Execute("ALTER TABLE images ALTER COLUMN rating SET NOT NULL");
|
||||
break;
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
class Relationships extends Extension
|
||||
{
|
||||
protected $db_support = ['mysql', 'pgsql'];
|
||||
protected $db_support = [Database::MYSQL_DRIVER, Database::PGSQL_DRIVER];
|
||||
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
|
@@ -9,7 +9,7 @@
|
||||
|
||||
class RSS_Comments extends Extension
|
||||
{
|
||||
protected $db_support = ['mysql', 'sqlite']; // pgsql has no UNIX_TIMESTAMP
|
||||
protected $db_support = [Database::MYSQL_DRIVER, Database::SQLITE_DRIVER]; // pgsql has no UNIX_TIMESTAMP
|
||||
|
||||
public function onPostListBuilding(PostListBuildingEvent $event)
|
||||
{
|
||||
|
@@ -19,7 +19,7 @@ if ( // kill these glitched requests immediately
|
||||
|
||||
class Rule34 extends Extension
|
||||
{
|
||||
protected $db_support = ['pgsql']; # Only PG has the NOTIFY pubsub system
|
||||
protected $db_support = [Database::PGSQL_DRIVER]; # Only PG has the NOTIFY pubsub system
|
||||
|
||||
public function onImageDeletion(ImageDeletionEvent $event)
|
||||
{
|
||||
|
@@ -19,7 +19,7 @@ class Rule34Theme extends Themelet
|
||||
{
|
||||
global $database, $user;
|
||||
$h_bans = "";
|
||||
$prefix = ($database->get_driver_name() == "sqlite" ? "bans." : "");
|
||||
$prefix = ($database->get_driver_name() == Database::SQLITE_DRIVER ? "bans." : "");
|
||||
foreach ($bans as $ban) {
|
||||
$h_bans .= "
|
||||
<tr>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
class Tips extends Extension
|
||||
{
|
||||
protected $db_support = ['mysql', 'sqlite']; // rand() ?
|
||||
protected $db_support = [Database::MYSQL_DRIVER, Database::SQLITE_DRIVER]; // rand() ?
|
||||
|
||||
public function onInitExt(InitExtEvent $event)
|
||||
{
|
||||
|
@@ -44,7 +44,7 @@ class Upgrade extends Extension
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 9);
|
||||
|
||||
if ($database->get_driver_name() == 'mysql') {
|
||||
if ($database->get_driver_name() == Database::MYSQL_DRIVER) {
|
||||
$tables = $database->get_col("SHOW TABLES");
|
||||
foreach ($tables as $table) {
|
||||
log_info("upgrade", "converting $table to innodb");
|
||||
@@ -84,7 +84,7 @@ class Upgrade extends Extension
|
||||
$config->set_bool("in_upgrade", true);
|
||||
$config->set_int("db_version", 12);
|
||||
|
||||
if ($database->get_driver_name() == 'pgsql') {
|
||||
if ($database->get_driver_name() == Database::PGSQL_DRIVER) {
|
||||
log_info("upgrade", "Changing ext column to VARCHAR");
|
||||
$database->execute("ALTER TABLE images ALTER COLUMN ext SET DATA TYPE VARCHAR(4)");
|
||||
}
|
||||
@@ -101,9 +101,9 @@ class Upgrade extends Extension
|
||||
$config->set_int("db_version", 13);
|
||||
|
||||
log_info("upgrade", "Changing password column to VARCHAR(250)");
|
||||
if ($database->get_driver_name() == 'pgsql') {
|
||||
if ($database->get_driver_name() == Database::PGSQL_DRIVER) {
|
||||
$database->execute("ALTER TABLE users ALTER COLUMN pass SET DATA TYPE VARCHAR(250)");
|
||||
} elseif ($database->get_driver_name() == 'mysql') {
|
||||
} elseif ($database->get_driver_name() == Database::MYSQL_DRIVER) {
|
||||
$database->execute("ALTER TABLE users CHANGE pass pass VARCHAR(250)");
|
||||
}
|
||||
|
||||
@@ -116,11 +116,11 @@ class Upgrade extends Extension
|
||||
$config->set_int("db_version", 14);
|
||||
|
||||
log_info("upgrade", "Changing tag column to VARCHAR(255)");
|
||||
if ($database->get_driver_name() == 'pgsql') {
|
||||
if ($database->get_driver_name() == Database::PGSQL_DRIVER) {
|
||||
$database->execute('ALTER TABLE tags ALTER COLUMN tag SET DATA TYPE VARCHAR(255)');
|
||||
$database->execute('ALTER TABLE aliases ALTER COLUMN oldtag SET DATA TYPE VARCHAR(255)');
|
||||
$database->execute('ALTER TABLE aliases ALTER COLUMN newtag SET DATA TYPE VARCHAR(255)');
|
||||
} elseif ($database->get_driver_name() == 'mysql') {
|
||||
} elseif ($database->get_driver_name() == Database::MYSQL_DRIVER) {
|
||||
$database->execute('ALTER TABLE tags MODIFY COLUMN tag VARCHAR(255) NOT NULL');
|
||||
$database->execute('ALTER TABLE aliases MODIFY COLUMN oldtag VARCHAR(255) NOT NULL');
|
||||
$database->execute('ALTER TABLE aliases MODIFY COLUMN newtag VARCHAR(255) NOT NULL');
|
||||
|
Reference in New Issue
Block a user