Chuyển tới nội dung chính

Activity-Log

Nhật ký hoạt động​

Các hook do nhật ký hoạt động (8.6.0) dùng hoặc thêm vào. Cách ghi / đọc nhật ký xem CMS → Nhật ký hoạt động.

Sửa hoặc bỏ một dòng trước khi ghi​

Trả false để không ghi dòng này (ví dụ tắt bớt sự kiện ồn). $row là mảng cột sắp chèn vào bảng activity_logs.

HookLoại HookPlatformVersion
activity_log_recordfiltercms8.6.0
add_filter('activity_log_record', function ($row, $data) {
if ($row['event'] === 'update' && $row['module'] === 'widget') return false;
return $row;
}, 10, 2);

Sau khi ghi một dòng​

Điểm móc để gửi cảnh báo (email, Telegram…).

HookLoại HookPlatformVersion
activity_log_recordedactioncms8.6.0
add_action('activity_log_recorded', function ($row, $id) {
if ($row['event'] === 'login_failed') { /* ... */ }
}, 10, 2);

Nhãn hiển thị của module​

HookLoại HookPlatformVersion
activity_log_modulesfiltercms8.6.0
add_filter('activity_log_modules', fn($modules) => $modules + ['products' => 'sản phẩm']);

Bảng nhật ký: cột, ô lọc, điều kiện truy vấn​

HookLoại HookPlatformVersion
manage_activity_logs_columnsfiltercms8.6.0
admin_activity_logs_table_form_filterfiltercms8.6.0
admin_activity_logs_table_queryfiltercms8.6.0
$columns = apply_filters('manage_activity_logs_columns', $columns);
$form = apply_filters('admin_activity_logs_table_form_filter', $form, $request);
$query = apply_filters('admin_activity_logs_table_query', $query, $request);

Câu mô tả kiểu cũ (trước 8.6.0, vẫn chạy)​

Nhận câu mô tả dựng sẵn (rỗng khi không tìm được tiêu đề). Trả rỗng = bỏ ghi, trả câu khác = ghi câu đó thay câu dựng sẵn.

HookLoại HookPlatformVersion
admin_activity_logger_create_messagefiltercms7.0.0
admin_activity_logger_update_messagefiltercms7.0.0
admin_activity_logger_{trash,restore,delete}_messagefiltercms7.0.0
admin_activity_logger_{trash,restore,delete}_objectsfiltercms7.0.0
$message = apply_filters('admin_activity_logger_create_message', $message, $id, $module, $request);
$message = apply_filters('admin_activity_logger_delete_message', $message, $object, $module);
$objects = apply_filters('admin_activity_logger_delete_objects', Collection::empty(), $ids, $module);

Hook mới / thêm tham số ở 8.6.0​

Thêm để nhật ký nghe được, plugin cũng dùng được. Tham số mới luôn nằm cuối, listener cũ khai ít tham số hơn vẫn chạy.

add_action mặc định nhận 1 tham số: listener nhiều tham số phải khai số tham số ở đối số thứ 4, ví dụ add_action('admin_system_save', $cb, 10, 2).

HookLoạiPhát ởTham số
skd_login_failedactionAuth::login, Auth::setCurrent, AuthAjax$username, $code (mới): empty_credentials, authenticate_filter, invalid_user_login, incorrect_password, authentication_failed, status_{status}, no_admin_role, crm_member
skd_admin_logoutactionAuthController::logout, trước khi xoá phiên$user
admin_user_login_asactionUserAjax::loginAs, trước khi đổi phiên$user (người được đăng nhập thay), $by (root)
admin_user_login_as_backactionUserAjax::loginAsBackRoot, trước khi trả phiên$user (người đang được đăng nhập thay)
admin_user_profile_savedactionUserAjax::saveProfile$user, $changedFields
admin_user_status_successactionUserAjax::status, bulkStatusarray $users, $status
admin_user_trash_successactionUserAjax::moveTrash, bulkDeletearray $users
save_object_edit_beforeactionFormAdminHelper::update, trước khi ghi$id, $module, $model, $insertData
up_boolean_successactionTableAjax::saveInputBoolean$module, $id, $model, $row, $value (mới)
admin_system_saveactionActionAjax::saveSystem (mọi tab)$tabKey, $request
ajax_menu_create_successactionMenuAjax::add$menu
ajax_menu_del_successactionMenuAjax::delete$id, $menu (mới, lấy trước khi xoá)
ajax_menu_item_save_success / ajax_menu_item_del_successactionMenuAjax$menuId, $item (mới)
plugin_installactionPluginsAjax::install$folder
cms_update_success / cms_update_failedactionUpdateAjax::update$version / $version, $reason
builder_save_successactionBuilderAjax::save (xuất bản, không phải nháp tự lưu)$page, $sectionKeys
builder_delete_successactionBuilderAjax::delete$key
admin_oauth_revokedactionOAuthAjax::revokeFamily$family, $owner
cms_update_success / cms_update_failed

Trình cập nhật chạy trong tiến trình đã nạp mã cũ, nên hai action này chỉ phát từ lần cập nhật sau bản đầu tiên có chúng (cập nhật lên 8.6.0 thì chưa phát, 8.6.0 lên bản kế tiếp mới phát).