cleanup.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <?php
  2. return [
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Cleanup Module Configuration
  6. |--------------------------------------------------------------------------
  7. |
  8. | 这里是 Cleanup 模块的配置文件,包含了模块的各种设置选项
  9. |
  10. */
  11. /*
  12. |--------------------------------------------------------------------------
  13. | 基础配置
  14. |--------------------------------------------------------------------------
  15. */
  16. 'enabled' => env('CLEANUP_ENABLED', true),
  17. 'debug' => env('CLEANUP_DEBUG', false),
  18. 'timezone' => env('CLEANUP_TIMEZONE', 'Asia/Shanghai'),
  19. /*
  20. |--------------------------------------------------------------------------
  21. | 数据库配置
  22. |--------------------------------------------------------------------------
  23. */
  24. 'database' => [
  25. // 表前缀
  26. 'table_prefix' => env('CLEANUP_TABLE_PREFIX', 'kku_'),
  27. // 扫描的数据库连接
  28. 'connection' => env('CLEANUP_DB_CONNECTION', 'mysql'),
  29. // 批处理大小
  30. 'batch_size' => [
  31. 'default' => env('CLEANUP_BATCH_SIZE', 1000),
  32. 'min' => 100,
  33. 'max' => 10000,
  34. ],
  35. // 查询超时时间(秒)
  36. 'query_timeout' => env('CLEANUP_QUERY_TIMEOUT', 300),
  37. ],
  38. /*
  39. |--------------------------------------------------------------------------
  40. | 备份配置
  41. |--------------------------------------------------------------------------
  42. */
  43. 'backup' => [
  44. // 默认备份类型:1=数据库, 2=SQL文件, 3=JSON文件, 4=CSV文件
  45. 'default_type' => env('CLEANUP_BACKUP_TYPE', 1),
  46. // 默认压缩类型:1=无压缩, 2=GZIP, 3=ZIP
  47. 'default_compression' => env('CLEANUP_BACKUP_COMPRESSION', 2),
  48. // 备份存储路径
  49. 'storage_path' => env('CLEANUP_BACKUP_PATH', storage_path('app/cleanup/backups')),
  50. // 备份保留天数
  51. 'retention_days' => env('CLEANUP_BACKUP_RETENTION', 30),
  52. // 是否包含表结构
  53. 'include_structure' => env('CLEANUP_BACKUP_STRUCTURE', true),
  54. // 单个备份文件最大大小(MB)
  55. 'max_file_size_mb' => env('CLEANUP_BACKUP_MAX_SIZE', 500),
  56. // 备份文件命名格式
  57. 'filename_format' => 'backup_{plan_name}_{timestamp}',
  58. // 备份验证
  59. 'verify_backup' => env('CLEANUP_BACKUP_VERIFY', true),
  60. ],
  61. /*
  62. |--------------------------------------------------------------------------
  63. | 执行配置
  64. |--------------------------------------------------------------------------
  65. */
  66. 'execution' => [
  67. // 最大并发任务数
  68. 'max_concurrent_tasks' => env('CLEANUP_MAX_CONCURRENT', 3),
  69. // 任务执行超时时间(秒)
  70. 'task_timeout' => env('CLEANUP_TASK_TIMEOUT', 3600),
  71. // 是否启用预览模式
  72. 'enable_preview' => env('CLEANUP_ENABLE_PREVIEW', true),
  73. // 是否启用确认步骤
  74. 'require_confirmation' => env('CLEANUP_REQUIRE_CONFIRMATION', true),
  75. // 执行前是否自动备份
  76. 'auto_backup' => env('CLEANUP_AUTO_BACKUP', true),
  77. // 内存限制(MB)
  78. 'memory_limit_mb' => env('CLEANUP_MEMORY_LIMIT', 512),
  79. // 进度更新间隔(秒)
  80. 'progress_update_interval' => env('CLEANUP_PROGRESS_INTERVAL', 5),
  81. ],
  82. /*
  83. |--------------------------------------------------------------------------
  84. | 日志配置
  85. |--------------------------------------------------------------------------
  86. */
  87. 'logging' => [
  88. // 是否启用详细日志
  89. 'detailed_logging' => env('CLEANUP_DETAILED_LOG', true),
  90. // 日志保留天数
  91. 'retention_days' => env('CLEANUP_LOG_RETENTION', 30),
  92. // 日志级别
  93. 'level' => env('CLEANUP_LOG_LEVEL', 'info'),
  94. // 日志文件路径
  95. 'file_path' => env('CLEANUP_LOG_PATH', storage_path('logs/cleanup.log')),
  96. // 是否记录SQL语句
  97. 'log_sql' => env('CLEANUP_LOG_SQL', false),
  98. ],
  99. /*
  100. |--------------------------------------------------------------------------
  101. | 安全配置
  102. |--------------------------------------------------------------------------
  103. */
  104. 'security' => [
  105. // 受保护的表(永远不会被清理)
  106. 'protected_tables' => [
  107. 'kku_users',
  108. 'kku_user_profiles',
  109. 'kku_configs',
  110. 'kku_system_configs',
  111. 'kku_permissions',
  112. 'kku_roles',
  113. 'migrations',
  114. ],
  115. // 受保护的模块
  116. 'protected_modules' => [
  117. 'User',
  118. 'Permission',
  119. 'Config',
  120. 'System',
  121. ],
  122. // 受保护的数据分类
  123. 'protected_categories' => [
  124. 5, // 配置数据
  125. ],
  126. // 是否启用IP白名单
  127. 'enable_ip_whitelist' => env('CLEANUP_IP_WHITELIST', false),
  128. // IP白名单
  129. 'ip_whitelist' => explode(',', env('CLEANUP_ALLOWED_IPS', '127.0.0.1')),
  130. // 是否需要管理员权限
  131. 'require_admin' => env('CLEANUP_REQUIRE_ADMIN', true),
  132. ],
  133. /*
  134. |--------------------------------------------------------------------------
  135. | 性能配置
  136. |--------------------------------------------------------------------------
  137. */
  138. 'performance' => [
  139. // 是否启用查询缓存
  140. 'enable_query_cache' => env('CLEANUP_QUERY_CACHE', true),
  141. // 缓存TTL(秒)
  142. 'cache_ttl' => env('CLEANUP_CACHE_TTL', 3600),
  143. // 是否启用表统计缓存
  144. 'enable_stats_cache' => env('CLEANUP_STATS_CACHE', true),
  145. // 统计缓存TTL(秒)
  146. 'stats_cache_ttl' => env('CLEANUP_STATS_CACHE_TTL', 1800),
  147. // 是否启用分页
  148. 'enable_pagination' => env('CLEANUP_PAGINATION', true),
  149. // 分页大小
  150. 'page_size' => env('CLEANUP_PAGE_SIZE', 50),
  151. ],
  152. /*
  153. |--------------------------------------------------------------------------
  154. | 通知配置
  155. |--------------------------------------------------------------------------
  156. */
  157. 'notifications' => [
  158. // 是否启用通知
  159. 'enabled' => env('CLEANUP_NOTIFICATIONS', true),
  160. // 通知渠道
  161. 'channels' => [
  162. 'mail' => env('CLEANUP_NOTIFY_MAIL', true),
  163. 'database' => env('CLEANUP_NOTIFY_DB', true),
  164. 'slack' => env('CLEANUP_NOTIFY_SLACK', false),
  165. ],
  166. // 邮件通知配置
  167. 'mail' => [
  168. 'to' => explode(',', env('CLEANUP_MAIL_TO', 'admin@example.com')),
  169. 'subject_prefix' => env('CLEANUP_MAIL_PREFIX', '[Cleanup]'),
  170. ],
  171. // Slack通知配置
  172. 'slack' => [
  173. 'webhook_url' => env('CLEANUP_SLACK_WEBHOOK'),
  174. 'channel' => env('CLEANUP_SLACK_CHANNEL', '#cleanup'),
  175. 'username' => env('CLEANUP_SLACK_USERNAME', 'Cleanup Bot'),
  176. ],
  177. // 通知事件
  178. 'events' => [
  179. 'task_completed' => true,
  180. 'task_failed' => true,
  181. 'backup_completed' => true,
  182. 'backup_failed' => true,
  183. 'large_cleanup' => true, // 大量数据清理时通知
  184. ],
  185. // 大量数据阈值
  186. 'large_cleanup_threshold' => env('CLEANUP_LARGE_THRESHOLD', 100000),
  187. ],
  188. /*
  189. |--------------------------------------------------------------------------
  190. | 默认清理配置
  191. |--------------------------------------------------------------------------
  192. */
  193. 'defaults' => [
  194. // 数据分类的默认配置
  195. 'categories' => [
  196. 1 => [ // 用户数据
  197. 'cleanup_type' => 3, // 按时间删除
  198. 'priority' => 100,
  199. 'batch_size' => 1000,
  200. 'is_enabled' => false,
  201. 'backup_enabled' => true,
  202. 'conditions' => [
  203. 'time_field' => 'created_at',
  204. 'time_value' => 90,
  205. 'time_unit' => 'days',
  206. ],
  207. ],
  208. 2 => [ // 日志数据
  209. 'cleanup_type' => 3, // 按时间删除
  210. 'priority' => 200,
  211. 'batch_size' => 5000,
  212. 'is_enabled' => true,
  213. 'backup_enabled' => false,
  214. 'conditions' => [
  215. 'time_field' => 'created_at',
  216. 'time_value' => 30,
  217. 'time_unit' => 'days',
  218. ],
  219. ],
  220. 3 => [ // 交易数据
  221. 'cleanup_type' => 3, // 按时间删除
  222. 'priority' => 150,
  223. 'batch_size' => 1000,
  224. 'is_enabled' => false,
  225. 'backup_enabled' => true,
  226. 'conditions' => [
  227. 'time_field' => 'created_at',
  228. 'time_value' => 365,
  229. 'time_unit' => 'days',
  230. ],
  231. ],
  232. 4 => [ // 缓存数据
  233. 'cleanup_type' => 1, // 清空表
  234. 'priority' => 400,
  235. 'batch_size' => 10000,
  236. 'is_enabled' => true,
  237. 'backup_enabled' => false,
  238. 'conditions' => null,
  239. ],
  240. 5 => [ // 配置数据
  241. 'cleanup_type' => 5, // 按条件删除
  242. 'priority' => 999,
  243. 'batch_size' => 100,
  244. 'is_enabled' => false,
  245. 'backup_enabled' => true,
  246. 'conditions' => null,
  247. ],
  248. ],
  249. ],
  250. /*
  251. |--------------------------------------------------------------------------
  252. | 监控配置
  253. |--------------------------------------------------------------------------
  254. */
  255. 'monitoring' => [
  256. // 是否启用监控
  257. 'enabled' => env('CLEANUP_MONITORING', true),
  258. // 监控间隔(秒)
  259. 'interval' => env('CLEANUP_MONITOR_INTERVAL', 60),
  260. // 健康检查
  261. 'health_check' => [
  262. 'max_running_tasks' => 5,
  263. 'max_failed_tasks_24h' => 10,
  264. 'max_expired_backups' => 50,
  265. ],
  266. // 性能指标
  267. 'metrics' => [
  268. 'track_execution_time' => true,
  269. 'track_memory_usage' => true,
  270. 'track_disk_usage' => true,
  271. ],
  272. ],
  273. /*
  274. |--------------------------------------------------------------------------
  275. | API配置
  276. |--------------------------------------------------------------------------
  277. */
  278. 'api' => [
  279. // API版本
  280. 'version' => 'v1',
  281. // API前缀
  282. 'prefix' => 'api/cleanup',
  283. // 是否启用API认证
  284. 'auth_required' => env('CLEANUP_API_AUTH', true),
  285. // API限流
  286. 'rate_limit' => [
  287. 'enabled' => env('CLEANUP_API_RATE_LIMIT', true),
  288. 'max_attempts' => env('CLEANUP_API_MAX_ATTEMPTS', 60),
  289. 'decay_minutes' => env('CLEANUP_API_DECAY_MINUTES', 1),
  290. ],
  291. ],
  292. ];