From ac231914d4048688100f028003ba9626dd3c10ec Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 00:55:57 +0300 Subject: [PATCH 1/2] fix mod condition --- app/controllers/api/projects.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6f2f4f40e3..a4a96b49a5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -100,7 +100,10 @@ App::post('/v1/projects') $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '02:00']; $databases = Config::getParam('pools-database', []); - + $index = array_search('database_db_fra1_self_hosted_0_0', $databases); + if ($index !== false) { + unset($databases[$index]); + } /** * Remove databases from the list that are currently undergoing an backup @@ -124,7 +127,7 @@ App::post('/v1/projects') $databaseOverride = App::getEnv('_APP_DATABASE_OVERRIDE', null); $index = array_search($databaseOverride, $databases); - if ($index) { + if ($index !== false) { $database = $databases[$index]; } else { $database = $databases[array_rand($databases)]; @@ -175,9 +178,9 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - $index = array_search('database_db_fra1_self_hosted_0_0', $databases); - if ($index !== false && ($project->getInternalId() % $mod === 0)) { - $project->setAttribute('database', $databases[$index]); + if ($project->getInternalId() % $mod === 0) { + $database = 'database_db_fra1_self_hosted_0_0'; + $project->setAttribute('database', $database); $dbForConsole->updateDocument('projects', $project); } From a841734d50ee0681ec217eb2a511116de5009a64 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 23 Oct 2023 01:05:10 +0300 Subject: [PATCH 2/2] fix mod condition --- app/controllers/api/projects.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a4a96b49a5..43fbd43b74 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -100,7 +100,8 @@ App::post('/v1/projects') $backups['database_db_fra1_v14x_07'] = ['from' => '00:00', 'to' => '02:00']; $databases = Config::getParam('pools-database', []); - $index = array_search('database_db_fra1_self_hosted_0_0', $databases); + $databaseSelfHosted = 'database_db_fra1_self_hosted_0_0'; + $index = array_search($databaseSelfHosted, $databases); if ($index !== false) { unset($databases[$index]); } @@ -178,9 +179,9 @@ App::post('/v1/projects') * Update database with self-managed db every $mod projects */ $mod = 20; - if ($project->getInternalId() % $mod === 0) { - $database = 'database_db_fra1_self_hosted_0_0'; - $project->setAttribute('database', $database); + $index = in_array($databaseSelfHosted, $databases); + if ($project->getInternalId() % $mod === 0 && $index !== false) { + $project->setAttribute('database', $databaseSelfHosted); $dbForConsole->updateDocument('projects', $project); }