Skip to content
Snippets Groups Projects
Commit 62e4affa authored by David Siegfried's avatar David Siegfried
Browse files

add missing log-actions, closes #2865

Closes #2865

Merge request studip/studip!1945
parent 8e0a7e34
No related branches found
No related tags found
No related merge requests found
<?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]);
}
}
......@@ -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,
......
......@@ -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.
*
......
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment