diff --git a/db/migrations/5.4.12_add_missing_log_actions.php b/db/migrations/5.4.12_add_missing_log_actions.php new file mode 100644 index 0000000000000000000000000000000000000000..0a821997df0e88bfc6f4746468243d07c752d042 --- /dev/null +++ b/db/migrations/5.4.12_add_missing_log_actions.php @@ -0,0 +1,52 @@ +<?php + +final class AddMissingLogActions extends Migration +{ + public function description() + { + return 'add missing log-actions'; + } + + public function up() + { + DBManager::get()->exec(" + INSERT IGNORE INTO `log_actions` + SET `action_id` = MD5('USER_LOCK'), + `name` = 'USER_LOCK', + `description` = 'Nutzer wird gesperrt', + `info_template` = '%user sperrt %user(%affected) (%info)', + `active` = '1', + `expires` = '0' + "); + + DBManager::get()->exec(" + INSERT IGNORE INTO `log_actions` + SET `action_id` = MD5('FILE_DELETE'), + `name` = 'FILE_DELETE', + `description` = 'Nutzer löscht Datei', + `info_template` = '%user löscht Datei %info (File-Id: %affected)', + `active` = '1', + `expires` = '0' + "); + DBManager::get()->exec(" + INSERT IGNORE INTO `log_actions` + SET `action_id` = MD5('FOLDER_DELETE'), + `name` = 'FOLDER_DELETE', + `description` = 'Nutzer löscht Ordner', + `info_template` = '%user löscht Datei %info (Folder-Id: %affected)', + `active` = '1', + `expires` = '0' + "); + } + + public function down() + { + $actions = ['USER_LOCK', 'FILE_DELETE', 'FOLDER_DELETE']; + + DBManager::get()->execute( + "DELETE `log_events` FROM `log_events` JOIN `log_actions` USING (`action_id`) WHERE `name` IN (?)", + [$actions] + ); + DBManager::get()->execute("DELETE FROM `log_actions` WHERE `name` IN (?)", [$actions]); + } +} diff --git a/lib/models/FileRef.php b/lib/models/FileRef.php index f440d50e30ea85e4a4cb45c48044d7c60a18da4b..fe878a840f2e2ee5b0dbb33c0cf7a0bccb8f3163 100644 --- a/lib/models/FileRef.php +++ b/lib/models/FileRef.php @@ -67,6 +67,7 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange $config['registered_callbacks']['after_delete'][] = 'cbRemoveFileIfOrphaned'; $config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedbackElements'; + $config['registered_callbacks']['before_delete'][] = 'cbLogDeleteFileRef'; $config['registered_callbacks']['before_store'][] = 'cbMakeUniqueFilename'; parent::configure($config); @@ -76,6 +77,17 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange protected $download_url; public $path_to_blob; + + public function cbLogDeleteFileRef() + { + StudipLog::log('FILE_DELETE', + $this->id, + null, + sprintf( + $this->name + ) + ); + } /** * 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 d1d778a75d54f4bd7a1a868da92eeb32addc7fe6..9faa76a7541e136461b2438106b9d350552c1f45 100644 --- a/lib/models/Folder.php +++ b/lib/models/Folder.php @@ -76,6 +76,7 @@ class Folder extends SimpleORMap implements FeedbackRange $config['registered_callbacks']['before_store'][] = 'cbMakeUniqueName'; $config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedbackElements'; + $config['registered_callbacks']['before_delete'][] = 'cbLogDeleteFolder'; $config['additional_fields']['is_empty']['get'] = function ($folder) { return count($folder->file_refs) + count($folder->subfolders) === 0; @@ -84,6 +85,16 @@ class Folder extends SimpleORMap implements FeedbackRange parent::configure($config); } + protected function cbLogDeleteFolder() + { + StudipLog::log('FOLDER_DELETE', + $this->id, + null, + sprintf( + $this->name + ) + ); + } /** * Creates a top folder (root directory) for a Stud.IP object given by range_id and range_type. * diff --git a/lib/models/User.class.php b/lib/models/User.class.php index 5f10a7e870e887d1e297fc7c1c532fe2448fee8a..47ad6f63d7850571851847a1f3d5c5e3dfb1362d 100644 --- a/lib/models/User.class.php +++ b/lib/models/User.class.php @@ -207,6 +207,7 @@ class User extends AuthUserMd5 implements Range, PrivacyObject $config['registered_callbacks']['after_delete'][] = 'cbRemoveFeedback'; $config['registered_callbacks']['before_store'][] = 'cbClearCaches'; + $config['registered_callbacks']['before_store'][] = 'cbStudipLog'; $info = new UserInfo(); $info_meta = $info->getTableMetadata(); @@ -224,6 +225,25 @@ class User extends AuthUserMd5 implements Range, PrivacyObject parent::configure($config); } + /** + * @param $type string type of callback + */ + protected function cbStudipLog($type) + { + if ($type == 'before_store' && !$this->isNew()) { + if ($this->isFieldDirty('locked') && $this->isFieldDirty('lock_comment') && (int)$this->locked === 1) { + StudipLog::log('USER_LOCK', + $this->user_id, + null, + sprintf( + 'Kommentar: %s', + $this->lock_comment + ) + ); + } + } + } + /** * Returns the currently authenticated user. *