aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Siegfried <david.siegfried@uni-vechta.de>2026-02-27 16:54:19 +0100
committerDavid Siegfried <david.siegfried@uni-vechta.de>2026-02-27 16:54:19 +0100
commitab8c6aee0e3df0565a56fc342c5107904935da2d (patch)
tree40cea85374999b0ecb0c6f6f75b790340c686f5b
parenta4a60be9c7e810d1e0d2ce0b7d4c8bba6ac89afc (diff)
extend file and folder logging, fixes #6251tic-6251
-rw-r--r--db/migrations/6.2.7_extend_file_logging.php68
-rw-r--r--lib/models/FileRef.php41
-rw-r--r--lib/models/Folder.php49
3 files changed, 153 insertions, 5 deletions
diff --git a/db/migrations/6.2.7_extend_file_logging.php b/db/migrations/6.2.7_extend_file_logging.php
new file mode 100644
index 0000000..a56bee2
--- /dev/null
+++ b/db/migrations/6.2.7_extend_file_logging.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * Description of class.
+ * Second line
+ */
+final class ExtendFileLogging extends Migration
+{
+ public function description()
+ {
+ return 'Extends the logging of files during upload and deletion';
+ }
+
+ public function up()
+ {
+ DBManager::get()->exec("UPDATE `log_actions` SET `info_template` = '%user löscht Datei %info (File-Id: %affected Range-Id: %coaffected)' WHERE `name` = 'FILE_DELETE'");
+ DBManager::get()->exec("UPDATE `log_actions` SET `info_template` = '%user löscht Ordner %info (Folder-Id: %affected Range-Id: %coaffected)' WHERE `name` = 'FOLDER_DELETE'");
+
+ DBManager::get()->exec("
+ INSERT IGNORE INTO `log_actions`
+ SET `action_id` = MD5('FILE_UPLOAD'),
+ `name` = 'FILE_UPLOAD',
+ `description` = 'Nutzer lädt Datei hoch',
+ `info_template` = '%user lädt Datei %info hoch (Folder-Id: %affected Range-Id: %coaffected)',
+ `active` = '1',
+ `expires` = '0'
+ ");
+
+ DBManager::get()->exec("
+ INSERT IGNORE INTO `log_actions`
+ SET `action_id` = MD5('FILE_UPDATE'),
+ `name` = 'FILE_UPDATE',
+ `description` = 'Nutzer ändert Datei',
+ `info_template` = '%user ändert Datei %info (Folder-Id: %affected Range-Id: %coaffected)',
+ `active` = '1',
+ `expires` = '0'
+ ");
+
+ DBManager::get()->exec("
+ INSERT IGNORE INTO `log_actions`
+ SET `action_id` = MD5('FOLDER_CREATE'),
+ `name` = 'FOLDER_CREATE',
+ `description` = 'Nutzer legt Ordner an',
+ `info_template` = '%user legt Ordner %info an (Range-Id: %coaffected)',
+ `active` = '1',
+ `expires` = '0'
+ ");
+ DBManager::get()->exec("
+ INSERT IGNORE INTO `log_actions`
+ SET `action_id` = MD5('FOLDER_UPDATE'),
+ `name` = 'FOLDER_UPDATE',
+ `description` = 'Nutzer aktualisiert Ordner',
+ `info_template` = '%user aktualisiert Ordner %info an (Range-Id: %coaffected)',
+ `active` = '1',
+ `expires` = '0'
+ ");
+ }
+
+ public function down()
+ {
+ DBManager::get()->exec("UPDATE `log_actions` SET `info_template` = '%user löscht Datei %info (File-Id: %affected)' WHERE `name` = 'FILE_DELETE'");
+ DBManager::get()->exec("UPDATE `log_actions` SET `info_template` = ' %user löscht Datei %info (Folder-Id: %affected)' WHERE `name` = 'FOLDER_DELETE'");
+ DBManager::get()->exec("DELETE FROM `log_actions` WHERE `name` = 'FILE_UPLOAD'");
+ DBManager::get()->exec("DELETE FROM `log_actions` WHERE `name` = 'FOLDER_CREATE'");
+ DBManager::get()->exec("DELETE FROM `log_actions` WHERE `name` = 'FILE_UPDATE'");
+ DBManager::get()->exec("DELETE FROM `log_actions` WHERE `name` = 'FOLDER_UPDATE'");
+ }
+}
diff --git a/lib/models/FileRef.php b/lib/models/FileRef.php
index 043aec1..0487121 100644
--- a/lib/models/FileRef.php
+++ b/lib/models/FileRef.php
@@ -74,6 +74,8 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange
$config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedbackElements';
$config['registered_callbacks']['before_delete'][] = 'cbLogDeleteFileRef';
$config['registered_callbacks']['before_store'][] = 'cbMakeUniqueFilename';
+ $config['registered_callbacks']['after_store'][] = 'cbLogUpdateFileRef';
+ $config['registered_callbacks']['after_create'][] = 'cbLogCreateFileRef';
parent::configure($config);
}
@@ -82,18 +84,47 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange
protected $download_url;
public $path_to_blob;
+ private function getLogComment(): string
+ {
+ $comment = sprintf(
+ 'Kommentar: %s',
+ $this->name
+ );
+
+ $range_fullname = $this->folder->getRangeFullname();
+
+ if ($range_fullname) {
+ $comment .= " - $range_fullname";
+ }
+ return $comment;
+ }
+
+ public function cbLogUpdateFileRef()
+ {
+ StudipLog::log('FILE_UPDATE',
+ User::findCurrent()->id,
+ $this->folder->range_id,
+ $this->getLogComment()
+ );
+ }
public function cbLogDeleteFileRef()
{
StudipLog::log('FILE_DELETE',
User::findCurrent()->id,
- null,
- sprintf(
- 'Kommentar: %s',
- $this->name
- )
+ $this->folder->range_id,
+ $this->getLogComment()
+ );
+ }
+ public function cbLogCreateFileRef()
+ {
+ StudipLog::log('FILE_UPLOAD',
+ User::findCurrent()->id,
+ $this->folder->range_id,
+ $this->getLogComment()
);
}
+
/**
* This callback is called after deleting a FileRef.
* It removes the File object that is associated with the FileRef,
diff --git a/lib/models/Folder.php b/lib/models/Folder.php
index b3a08f5..f5ac297 100644
--- a/lib/models/Folder.php
+++ b/lib/models/Folder.php
@@ -84,6 +84,8 @@ class Folder extends SimpleORMap implements FeedbackRange
$config['serialized_fields']['data_content'] = JSONArrayObject::class;
$config['registered_callbacks']['before_store'][] = 'cbMakeUniqueName';
+ $config['registered_callbacks']['after_store'][] = 'cbLogUpdateFolder';
+ $config['registered_callbacks']['after_create'][] = 'cbLogCreateFolder';
$config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedbackElements';
$config['registered_callbacks']['before_delete'][] = 'cbLogDeleteFolder';
@@ -94,6 +96,53 @@ class Folder extends SimpleORMap implements FeedbackRange
parent::configure($config);
}
+ public function getRangeFullname(): string
+ {
+ if ($this->user) {
+ return $this->user->getFullname();
+ }
+ if ($this->course) {
+ return $this->course->getFullname();
+ }
+ if ($this->institute) {
+ return $this->institute->getFullname();
+ }
+ return '';
+ }
+
+ public function getLogComment(): string
+ {
+ $comment = sprintf(
+ 'Kommentar: %s',
+ $this->name
+ );
+
+ $range_fullname = $this->getRangeFullname();
+
+ if ($range_fullname) {
+ $comment .= " - $range_fullname";
+ }
+ return $comment;
+ }
+
+ public function cbLogCreateFolder()
+ {
+ StudipLog::log('FOLDER_CREATE',
+ User::findCurrent()->id,
+ $this->range_id,
+ $this->getLogComment()
+ );
+ }
+
+ public function cbLogUpdateFolder()
+ {
+ StudipLog::log('FOLDER_UPDATE',
+ User::findCurrent()->id,
+ $this->range_id,
+ $this->getLogComment()
+ );
+ }
+
protected function cbLogDeleteFolder()
{
StudipLog::log('FOLDER_DELETE',