[DB] Fix espacing of special db names during upgrade
This commit is contained in:
parent
ca64ff2c0b
commit
38291d123f
@ -3,7 +3,7 @@ function init_db_schema() {
|
|||||||
try {
|
try {
|
||||||
global $pdo;
|
global $pdo;
|
||||||
|
|
||||||
$db_version = "06012023_1924";
|
$db_version = "14022023_1000";
|
||||||
|
|
||||||
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
|
$stmt = $pdo->query("SHOW TABLES LIKE 'versions'");
|
||||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||||
@ -225,22 +225,22 @@ function init_db_schema() {
|
|||||||
),
|
),
|
||||||
"attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
|
"attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
|
||||||
),
|
),
|
||||||
"templates" => array(
|
"templates" => array(
|
||||||
"cols" => array(
|
"cols" => array(
|
||||||
"id" => "INT NOT NULL AUTO_INCREMENT",
|
"id" => "INT NOT NULL AUTO_INCREMENT",
|
||||||
"template" => "VARCHAR(255) NOT NULL",
|
"template" => "VARCHAR(255) NOT NULL",
|
||||||
"type" => "VARCHAR(255) NOT NULL",
|
"type" => "VARCHAR(255) NOT NULL",
|
||||||
"attributes" => "JSON",
|
"attributes" => "JSON",
|
||||||
"created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
|
"created" => "DATETIME(0) NOT NULL DEFAULT NOW(0)",
|
||||||
"modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP"
|
"modified" => "DATETIME ON UPDATE CURRENT_TIMESTAMP"
|
||||||
),
|
),
|
||||||
"keys" => array(
|
"keys" => array(
|
||||||
"primary" => array(
|
"primary" => array(
|
||||||
"" => array("id")
|
"" => array("id")
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
|
"attr" => "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC"
|
||||||
),
|
),
|
||||||
"domain" => array(
|
"domain" => array(
|
||||||
// Todo: Move some attributes to json
|
// Todo: Move some attributes to json
|
||||||
"cols" => array(
|
"cols" => array(
|
||||||
@ -1076,7 +1076,7 @@ function init_db_schema() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Migrate tls_enforce_* options
|
// Migrate tls_enforce_* options
|
||||||
if ($table == 'mailbox') {
|
if ($table == 'mailbox') {
|
||||||
$stmt = $pdo->query("SHOW TABLES LIKE 'mailbox'");
|
$stmt = $pdo->query("SHOW TABLES LIKE 'mailbox'");
|
||||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||||
@ -1096,7 +1096,7 @@ function init_db_schema() {
|
|||||||
$stmt = $pdo->query("SHOW TABLES LIKE '" . $table . "'");
|
$stmt = $pdo->query("SHOW TABLES LIKE '" . $table . "'");
|
||||||
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
$num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC));
|
||||||
if ($num_results != 0) {
|
if ($num_results != 0) {
|
||||||
$stmt = $pdo->prepare("SELECT CONCAT('ALTER TABLE ', `table_schema`, '.', `table_name`, ' DROP FOREIGN KEY ', `constraint_name`, ';') AS `FKEY_DROP` FROM `information_schema`.`table_constraints`
|
$stmt = $pdo->prepare("SELECT CONCAT('ALTER TABLE `', `table_schema`, '`.', `table_name`, ' DROP FOREIGN KEY ', `constraint_name`, ';') AS `FKEY_DROP` FROM `information_schema`.`table_constraints`
|
||||||
WHERE `constraint_type` = 'FOREIGN KEY' AND `table_name` = :table;");
|
WHERE `constraint_type` = 'FOREIGN KEY' AND `table_name` = :table;");
|
||||||
$stmt->execute(array(':table' => $table));
|
$stmt->execute(array(':table' => $table));
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
@ -1322,95 +1322,95 @@ function init_db_schema() {
|
|||||||
// Fix domain_admins
|
// Fix domain_admins
|
||||||
$pdo->query("DELETE FROM `domain_admins` WHERE `domain` = 'ALL';");
|
$pdo->query("DELETE FROM `domain_admins` WHERE `domain` = 'ALL';");
|
||||||
|
|
||||||
// add default templates
|
// add default templates
|
||||||
$default_domain_template = array(
|
$default_domain_template = array(
|
||||||
"template" => "Default",
|
"template" => "Default",
|
||||||
"type" => "domain",
|
"type" => "domain",
|
||||||
"attributes" => array(
|
"attributes" => array(
|
||||||
"tags" => array(),
|
"tags" => array(),
|
||||||
"max_num_aliases_for_domain" => 400,
|
"max_num_aliases_for_domain" => 400,
|
||||||
"max_num_mboxes_for_domain" => 10,
|
"max_num_mboxes_for_domain" => 10,
|
||||||
"def_quota_for_mbox" => 3072 * 1048576,
|
"def_quota_for_mbox" => 3072 * 1048576,
|
||||||
"max_quota_for_mbox" => 10240 * 1048576,
|
"max_quota_for_mbox" => 10240 * 1048576,
|
||||||
"max_quota_for_domain" => 10240 * 1048576,
|
"max_quota_for_domain" => 10240 * 1048576,
|
||||||
"rl_frame" => "s",
|
"rl_frame" => "s",
|
||||||
"rl_value" => "",
|
"rl_value" => "",
|
||||||
"active" => 1,
|
"active" => 1,
|
||||||
"gal" => 1,
|
"gal" => 1,
|
||||||
"backupmx" => 0,
|
"backupmx" => 0,
|
||||||
"relay_all_recipients" => 0,
|
"relay_all_recipients" => 0,
|
||||||
"relay_unknown_only" => 0,
|
"relay_unknown_only" => 0,
|
||||||
"dkim_selector" => "dkim",
|
"dkim_selector" => "dkim",
|
||||||
"key_size" => 2048,
|
"key_size" => 2048,
|
||||||
"max_quota_for_domain" => 10240 * 1048576,
|
"max_quota_for_domain" => 10240 * 1048576,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$default_mailbox_template = array(
|
$default_mailbox_template = array(
|
||||||
"template" => "Default",
|
"template" => "Default",
|
||||||
"type" => "mailbox",
|
"type" => "mailbox",
|
||||||
"attributes" => array(
|
"attributes" => array(
|
||||||
"tags" => array(),
|
"tags" => array(),
|
||||||
"quota" => 0,
|
"quota" => 0,
|
||||||
"quarantine_notification" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_notification']),
|
"quarantine_notification" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_notification']),
|
||||||
"quarantine_category" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_category']),
|
"quarantine_category" => strval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['quarantine_category']),
|
||||||
"rl_frame" => "s",
|
"rl_frame" => "s",
|
||||||
"rl_value" => "",
|
"rl_value" => "",
|
||||||
"force_pw_update" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['force_pw_update']),
|
"force_pw_update" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['force_pw_update']),
|
||||||
"sogo_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sogo_access']),
|
"sogo_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sogo_access']),
|
||||||
"active" => 1,
|
"active" => 1,
|
||||||
"tls_enforce_in" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_in']),
|
"tls_enforce_in" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_in']),
|
||||||
"tls_enforce_out" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_out']),
|
"tls_enforce_out" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['tls_enforce_out']),
|
||||||
"imap_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['imap_access']),
|
"imap_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['imap_access']),
|
||||||
"pop3_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['pop3_access']),
|
"pop3_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['pop3_access']),
|
||||||
"smtp_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['smtp_access']),
|
"smtp_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['smtp_access']),
|
||||||
"sieve_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sieve_access']),
|
"sieve_access" => intval($GLOBALS['MAILBOX_DEFAULT_ATTRIBUTES']['sieve_access']),
|
||||||
"acl_spam_alias" => 1,
|
"acl_spam_alias" => 1,
|
||||||
"acl_tls_policy" => 1,
|
"acl_tls_policy" => 1,
|
||||||
"acl_spam_score" => 1,
|
"acl_spam_score" => 1,
|
||||||
"acl_spam_policy" => 1,
|
"acl_spam_policy" => 1,
|
||||||
"acl_delimiter_action" => 1,
|
"acl_delimiter_action" => 1,
|
||||||
"acl_syncjobs" => 0,
|
"acl_syncjobs" => 0,
|
||||||
"acl_eas_reset" => 1,
|
"acl_eas_reset" => 1,
|
||||||
"acl_sogo_profile_reset" => 0,
|
"acl_sogo_profile_reset" => 0,
|
||||||
"acl_pushover" => 1,
|
"acl_pushover" => 1,
|
||||||
"acl_quarantine" => 1,
|
"acl_quarantine" => 1,
|
||||||
"acl_quarantine_attachments" => 1,
|
"acl_quarantine_attachments" => 1,
|
||||||
"acl_quarantine_notification" => 1,
|
"acl_quarantine_notification" => 1,
|
||||||
"acl_quarantine_category" => 1,
|
"acl_quarantine_category" => 1,
|
||||||
"acl_app_passwds" => 1,
|
"acl_app_passwds" => 1,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
|
$stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
":type" => "domain",
|
":type" => "domain",
|
||||||
":template" => $default_domain_template["template"]
|
":template" => $default_domain_template["template"]
|
||||||
));
|
));
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
if (empty($row)){
|
if (empty($row)){
|
||||||
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
||||||
VALUES (:type, :template, :attributes)");
|
VALUES (:type, :template, :attributes)");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
":type" => "domain",
|
":type" => "domain",
|
||||||
":template" => $default_domain_template["template"],
|
":template" => $default_domain_template["template"],
|
||||||
":attributes" => json_encode($default_domain_template["attributes"])
|
":attributes" => json_encode($default_domain_template["attributes"])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
|
$stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
":type" => "mailbox",
|
":type" => "mailbox",
|
||||||
":template" => $default_mailbox_template["template"]
|
":template" => $default_mailbox_template["template"]
|
||||||
));
|
));
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
if (empty($row)){
|
if (empty($row)){
|
||||||
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
|
||||||
VALUES (:type, :template, :attributes)");
|
VALUES (:type, :template, :attributes)");
|
||||||
$stmt->execute(array(
|
$stmt->execute(array(
|
||||||
":type" => "mailbox",
|
":type" => "mailbox",
|
||||||
":template" => $default_mailbox_template["template"],
|
":template" => $default_mailbox_template["template"],
|
||||||
":attributes" => json_encode($default_mailbox_template["attributes"])
|
":attributes" => json_encode($default_mailbox_template["attributes"])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (php_sapi_name() == "cli") {
|
if (php_sapi_name() == "cli") {
|
||||||
echo "DB initialization completed" . PHP_EOL;
|
echo "DB initialization completed" . PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user