echo "Successfully deleted {$deletedCount} old API log records\n";
+ return ExitCode::OK;
+ } catch (\Exception $e) {
+ echo "Error during cleanup: " . $e->getMessage() . "\n";
+ return ExitCode::UNSPECIFIED_ERROR;
+ }
+ }
+ /**
+ * Clear old page statistics older than 4 months
+ * @return int Exit code
+ */
+ public function actionClearOldPageStatistics()
+ {
+ echo "Starting cleanup of old page statistics...\n";
+
+ try {
+ $sql = "DELETE FROM public.page_statistics WHERE created_at < NOW() - INTERVAL '4 months'";
+ $command = Yii::$app->db->createCommand($sql);
+
+ echo "Executing SQL: {$command->rawSql}\n";
+
+ $deletedCount = $command->execute();
+
+ echo "Successfully deleted {$deletedCount} old page statistics records\n";
+
return ExitCode::OK;
} catch (\Exception $e) {
echo "Error during cleanup: " . $e->getMessage() . "\n";