Files
WooNooW/includes/Api/Routes.php
dwindown debe42f4e1 feat: Implement activity log system
##  Activity Log System - Complete

### Backend Implementation

**1. Database Table**
- `ActivityLogTable.php` - Table creation and management
- Auto-creates on plugin init
- Indexed for performance (user_id, action, object, created_at)

**2. Logger Class**
- `Logger.php` - Main logging functionality
- `log()` - Log activities
- `get_activities()` - Query with filters
- `get_stats()` - Activity statistics
- `cleanup()` - Delete old logs

**3. REST API**
- `ActivityLogController.php` - REST endpoints
- GET `/activity-log` - List activities
- POST `/activity-log` - Create activity
- GET `/activity-log/stats` - Get statistics

### Features

**Logging:**
- User ID and name
- Action type (order.created, product.updated, etc.)
- Object type and ID
- Object name (auto-resolved)
- Description
- Metadata (JSON)
- IP address
- User agent
- Timestamp

**Querying:**
- Pagination
- Filter by action, object, user, date
- Search by description, object name, user name
- Sort by date (newest first)

**Statistics:**
- Total activities
- By action (top 10)
- By user (top 10)
- Date range filtering

### Activity Types

**Orders:**
- order.created, order.updated, order.status_changed
- order.payment_completed, order.refunded, order.deleted

**Products:**
- product.created, product.updated
- product.stock_changed, product.deleted

**Customers:**
- customer.created, customer.updated, customer.deleted

**Notifications:**
- notification.sent, notification.failed, notification.clicked

**Settings:**
- settings.updated, channel.toggled, event.toggled

### Integration

- Registered in Bootstrap
- REST API routes registered
- Ready for WooCommerce hooks
- Ready for frontend UI

---

**Next:** Frontend UI + WooCommerce hooks
2025-11-11 17:52:03 +07:00

95 lines
3.5 KiB
PHP

<?php
namespace WooNooW\Api;
use WP_REST_Request;
use WP_REST_Response;
use WooNooW\Api\CheckoutController;
use WooNooW\Api\OrdersController;
use WooNooW\Api\AnalyticsController;
use WooNooW\Api\AuthController;
use WooNooW\API\PaymentsController;
use WooNooW\API\StoreController;
use WooNooW\Api\ShippingController;
use WooNooW\Api\TaxController;
use WooNooW\Api\PickupLocationsController;
use WooNooW\Api\EmailController;
use WooNooW\API\DeveloperController;
use WooNooW\API\SystemController;
use WooNooW\Api\NotificationsController;
use WooNooW\Api\ActivityLogController;
class Routes {
public static function init() {
// Initialize controllers (register action hooks)
OrdersController::init();
add_action('rest_api_init', function () {
$namespace = 'woonoow/v1';
// Auth endpoints (public - no permission check)
register_rest_route( $namespace, '/auth/login', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'login' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/logout', [
'methods' => 'POST',
'callback' => [ AuthController::class, 'logout' ],
'permission_callback' => '__return_true',
] );
register_rest_route( $namespace, '/auth/check', [
'methods' => 'GET',
'callback' => [ AuthController::class, 'check' ],
'permission_callback' => '__return_true',
] );
// Defer to controllers to register their endpoints
CheckoutController::register();
OrdersController::register();
AnalyticsController::register_routes();
// Payments controller
$payments_controller = new PaymentsController();
$payments_controller->register_routes();
// Store controller
$store_controller = new StoreController();
$store_controller->register_routes();
// Shipping controller
$shipping_controller = new ShippingController();
$shipping_controller->register_routes();
// Tax controller
$tax_controller = new TaxController();
$tax_controller->register_routes();
// Pickup locations controller
$pickup_controller = new PickupLocationsController();
$pickup_controller->register_routes();
// Email controller
$email_controller = new EmailController();
$email_controller->register_routes();
// Developer controller
$developer_controller = new DeveloperController();
$developer_controller->register_routes();
// System controller
$system_controller = new SystemController();
$system_controller->register_routes();
// Notifications controller
$notifications_controller = new NotificationsController();
$notifications_controller->register_routes();
// Activity Log controller
$activity_log_controller = new ActivityLogController();
$activity_log_controller->register_routes();
});
}
}