From 366ff0a8b7294a309cab4750e4801e62bb0d144d Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 10 May 2020 17:41:16 +0000 Subject: [PATCH] Check for existance before creation --- update.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/update.php b/update.php index bb733ebc20..3d8721a342 100644 --- a/update.php +++ b/update.php @@ -434,10 +434,12 @@ function update_1347() function pre_update_1348() { - DBA::insert('contact', ['nurl' => '']); - $lastid = DBA::lastInsertId(); - if ($lastid != 0) { - DBA::update('contact', ['id' => 0], ['id' => $lastid]); + if (!DBA::exists('contact', ['id' => 0])) { + DBA::insert('contact', ['nurl' => '']); + $lastid = DBA::lastInsertId(); + if ($lastid != 0) { + DBA::update('contact', ['id' => 0], ['id' => $lastid]); + } } // The tables "permissionset" and "tag" could or could not exist during the update. @@ -453,17 +455,20 @@ function update_1348() { // Insert a permissionset with id=0 // Setting it to -1 and then changing the value to 0 tricks the auto increment - DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); - $lastid = DBA::lastInsertId(); - if ($lastid != 0) { - DBA::update('permissionset', ['id' => 0], ['id' => $lastid]); + if (!DBA::exists('permissionset', ['id' => 0])) { + DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); + $lastid = DBA::lastInsertId(); + if ($lastid != 0) { + DBA::update('permissionset', ['id' => 0], ['id' => $lastid]); + } } - - DBA::insert('tag', ['name' => '']); - $lastid = DBA::lastInsertId(); - if ($lastid != 0) { - DBA::update('tag', ['id' => 0], ['id' => $lastid]); + if (!DBA::exists('tag', ['id' => 0])) { + DBA::insert('tag', ['name' => '']); + $lastid = DBA::lastInsertId(); + if ($lastid != 0) { + DBA::update('tag', ['id' => 0], ['id' => $lastid]); + } } return Update::SUCCESS;