change default template creation

This commit is contained in:
FreddleSpl0it 2022-11-16 15:29:39 +01:00
parent 3ebd801b3d
commit f52ab69a5b

View File

@ -3,7 +3,7 @@ function init_db_schema() {
try { try {
global $pdo; global $pdo;
$db_version = "10112022_1146"; $db_version = "16112022_1325";
$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));
@ -1366,30 +1366,36 @@ function init_db_schema() {
"acl_app_passwds" => 1, "acl_app_passwds" => 1,
) )
); );
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`) $stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
SELECT :type, :template, :attributes FROM `templates`
WHERE NOT EXISTS (
SELECT `template` FROM `templates` WHERE `template` = :template2 AND `type` = :type2
) LIMIT 1;");
$stmt->execute(array( $stmt->execute(array(
":type" => "domain", ":type" => "domain",
":type2" => "domain", ":template" => $default_domain_template["template"]
":template" => $default_domain_template["template"],
":template2" => $default_mailbox_template["template"],
":attributes" => json_encode($default_domain_template["attributes"])
)); ));
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`) $row = $stmt->fetch(PDO::FETCH_ASSOC);
SELECT :type, :template, :attributes FROM `templates` if (empty($row)){
WHERE NOT EXISTS ( $stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
SELECT `template` FROM `templates` WHERE `template` = :template2 AND `type` = :type2 VALUES (:type, :template, :attributes)");
) LIMIT 1;"); $stmt->execute(array(
":type" => "domain",
":template" => $default_domain_template["template"],
":attributes" => json_encode($default_domain_template["attributes"])
));
}
$stmt = $pdo->prepare("SELECT id FROM `templates` WHERE `type` = :type AND `template` = :template");
$stmt->execute(array( $stmt->execute(array(
":type" => "mailbox", ":type" => "mailbox",
":type2" => "mailbox", ":template" => $default_mailbox_template["template"]
":template" => $default_mailbox_template["template"],
":template2" => $default_mailbox_template["template"],
":attributes" => json_encode($default_mailbox_template["attributes"])
)); ));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (empty($row)){
$stmt = $pdo->prepare("INSERT INTO `templates` (`type`, `template`, `attributes`)
VALUES (:type, :template, :attributes)");
$stmt->execute(array(
":type" => "mailbox",
":template" => $default_mailbox_template["template"],
":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;