From beca93838424edc4418f4ef2d3a2b586ccd8c410 Mon Sep 17 00:00:00 2001 From: smarcet Date: Wed, 1 Apr 2020 16:22:12 -0300 Subject: [PATCH] Fixed clear db jobs Change-Id: Ie807bce7e7a9b26924c345c4bf76d1f73ada0cf6 Signed-off-by: smarcet --- app/Console/Commands/CleanOAuth2StaleData.php | 12 ++++++- app/Console/Commands/CleanOpenIdStaleData.php | 34 +++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/CleanOAuth2StaleData.php b/app/Console/Commands/CleanOAuth2StaleData.php index 4e7bb8aa..0d31a329 100644 --- a/app/Console/Commands/CleanOAuth2StaleData.php +++ b/app/Console/Commands/CleanOAuth2StaleData.php @@ -12,7 +12,9 @@ * limitations under the License. **/ use Illuminate\Console\Command; +use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; /** * Class CleanOAuth2StaleData @@ -51,6 +53,14 @@ final class CleanOAuth2StaleData extends Command public function handle() { // delete void access tokens - DB::raw("delete from oauth2_access_token where DATE_ADD(created_at, INTERVAL lifetime second) <= UTC_TIMESTAMP();"); + + if (Schema::hasTable('oauth2_access_token')) { + $res = DB::table('oauth2_access_token') + ->whereRaw("DATE_ADD(created_at, INTERVAL lifetime second) <= UTC_TIMESTAMP()") + ->delete(); + + Log::debug(sprintf("CleanOAuth2StaleData::handle %s rows where deleted from oauth2_access_token", $res)); + } + } } \ No newline at end of file diff --git a/app/Console/Commands/CleanOpenIdStaleData.php b/app/Console/Commands/CleanOpenIdStaleData.php index 9d04ffbd..67afc015 100644 --- a/app/Console/Commands/CleanOpenIdStaleData.php +++ b/app/Console/Commands/CleanOpenIdStaleData.php @@ -12,7 +12,9 @@ * limitations under the License. **/ use Illuminate\Console\Command; +use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; /** * Class CleanOpenIdStaleData @@ -53,11 +55,31 @@ final class CleanOpenIdStaleData extends Command $interval = self::IntervalInSeconds; - // delete void associations - DB::raw("delete from openid_associations where DATE_ADD(issued, INTERVAL lifetime second) <= UTC_TIMESTAMP();"); - // delete old exceptions trails - DB::raw("delete from user_exceptions_trail where DATE_ADD(created_at, INTERVAL {$interval} second) <= UTC_TIMESTAMP();"); - // delete old user actions - DB::raw("delete from user_actions where DATE_ADD(created_at, INTERVAL 1 year) <= UTC_TIMESTAMP()"); + if (Schema::hasTable('openid_associations')) { + // delete void associations + $res = DB::table('openid_associations') + ->whereRaw("DATE_ADD(issued, INTERVAL lifetime second) <= UTC_TIMESTAMP()") + ->delete(); + + Log::debug(sprintf("CleanOpenIdStaleData::handle %s rows where deleted from openid_associations", $res)); + } + + if (Schema::hasTable('user_exceptions_trail')) { + // delete old exceptions trails + $res = DB::table('user_exceptions_trail') + ->whereRaw("DATE_ADD(created_at, INTERVAL {$interval} second) <= UTC_TIMESTAMP()") + ->delete(); + + Log::debug(sprintf("CleanOpenIdStaleData::handle %s rows where deleted from user_exceptions_trail", $res)); + } + + if (Schema::hasTable('user_actions')) { + // delete old user actions + $res = DB::table('user_actions') + ->whereRaw("DATE_ADD(created_at, INTERVAL 1 year) <= UTC_TIMESTAMP()") + ->delete(); + + Log::debug(sprintf("CleanOpenIdStaleData::handle %s rows where deleted from user_actions", $res)); + } } } \ No newline at end of file