]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5686 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Jan 2023 09:47:21 +0000 (10:47 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 17 Jan 2023 09:47:21 +0000 (10:47 +0100)
.docker/config/mariadb/logs.cnf
app/Console/Kernel.php
app/Jobs/Maintenance/CleanDownloads.php [new file with mode: 0644]

index 0d659f632200ce2adf13b8c553771f946016e96e..2a54d170edc074513acfa0bbbcf70ec496e4cd54 100644 (file)
@@ -1,8 +1,8 @@
 [mariadb]
 skip-log-error
 
-general_log         = 1
+general_log         = 0
 general_log_file    = /var/log/mysql/queries.log
 
-slow_query_log      = 1
+slow_query_log      = 0
 slow_query_log_file    = /var/log/mysql/slow_queries.log
index 0be0d13be9fcefd0db0d78f7cd4d83dcd1271f4f..3517b01cc4c8e67c6d96d1b974e6822d9761b241 100644 (file)
@@ -28,6 +28,7 @@ class Kernel extends \Cubist\Backpack\Console\Kernel
 
         $schedule->command('cubist:magic:precache')->everyFiveMinutes();
         $schedule->command('job:dispatch ProcessTotals')->everyTwoHours();
+        $schedule->command('job:dispatch Maintenance\\CleanDownloads')->dailyAt('4:00');
         $schedule->command('fluidbook:farm:ping')->everyMinute();
         $schedule->command('fluidbook:player:updatesources')->everyTwoHours();
         $schedule->command('ws:migrate --publications=v2 --documents=missing')->dailyAt('1:00');
diff --git a/app/Jobs/Maintenance/CleanDownloads.php b/app/Jobs/Maintenance/CleanDownloads.php
new file mode 100644 (file)
index 0000000..78cd628
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Jobs\Maintenance;
+
+use App\Jobs\Base;
+use Cubist\Util\Files\Files;
+
+class CleanDownloads extends Base
+{
+    public function handle()
+    {
+        $days = 15;
+        $limit = time() - (3600 * 24 * $days);
+
+        $directoriesToClean = [protected_path('signedexe/')];
+
+        $types = ['elearningmedia', 'elearningpackage', 'quiz', 'fluidbookcollection', 'fluidbookpublication'];
+        foreach ($types as $type) {
+            $directoriesToClean[] = storage_path('app/public/' . $type . '/download/');
+            $directoriesToClean[] = protected_path($type . '/final/');
+        }
+
+        foreach ($directoriesToClean as $path) {
+            if (!file_exists($path) || !is_dir($path)) {
+                continue;
+            }
+            $path = rtrim($path, '/');
+            $it = Files::getDirectoryIterator($path);
+            foreach ($it as $file) {
+                /** @var $file \SplFileInfo */
+                if ($file->isDot()) {
+                    continue;
+                }
+                if ($file->isLink()) {
+                    continue;
+                }
+                if ($file->getMTime() >= $limit) {
+                    continue;
+                }
+                $pathname = $file->getPathname();
+                if ($file->isFile()) {
+                    $type = 'file';
+                    unlink($pathname);
+                } else {
+                    $type = 'dir';
+                    `rm -rf $pathname`;
+                }
+                echo "Deleted $type $pathname\n";
+            }
+        }
+    }
+}