PluginProbe
Bulk Page Generator – LPagery / trunk
Bulk Page Generator – LPagery vtrunk
2.5.8 2.5.7 1.4.24 1.4.25 1.4.26 1.4.27 1.4.28 1.4.29 1.4.3 1.4.31 1.4.32 1.4.33 1.4.5 1.4.7 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.5 1.5.6 2.0.0 2.0.1 2.0.10 2.0.11 All 154 releases
lpagery / src / controller / UtilityController.php

UtilityController.php in Bulk Page Generator – LPagery trunk, at src/controller/UtilityController.php

130 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace LPagery\controller;
4
5 use LPagery\data\LPageryDao;
6 use LPagery\service\onboarding\OnboardingService;
7 use LPagery\utils\MemoryUtils;
8 use LPagery\utils\Utils;
9
10 /**
11 * Controller for handling utility operations
12 */
13 class UtilityController
14 {
15 private static $instance;
16 private OnboardingService $onboardingService;
17 private LPageryDao $lpageryDao;
18
19 /**
20 * UtilityController constructor.
21 *
22 * @param OnboardingService $onboardingService
23 * @param LPageryDao $lpageryDao
24 */
25 public function __construct(OnboardingService $onboardingService, LPageryDao $lpageryDao)
26 {
27 $this->onboardingService = $onboardingService;
28 $this->lpageryDao = $lpageryDao;
29 }
30
31 /**
32 * Singleton pattern implementation
33 */
34 public static function get_instance(): self
35 {
36 if (null === self::$instance) {
37 self::$instance = new self(
38 OnboardingService::get_instance(),
39 LPageryDao::get_instance()
40 );
41 }
42 return self::$instance;
43 }
44
45 /**
46 * Gets RAM usage
47 *
48 * @return array Memory usage information
49 */
50 public function getRAMUsage(): array
51 {
52 return MemoryUtils::lpagery_get_memory_usage();
53 }
54
55 /**
56 * Gets users for settings
57 *
58 * @return array Array of users with ID and label
59 */
60 public function getUsersForSettings(): array
61 {
62 $users = get_users();
63 return array_map(function ($user) {
64 return [
65 "id" => $user->ID,
66 "label" => $user->display_name . " (" . $user->user_email . ")"
67 ];
68 }, $users);
69 }
70
71 /**
72 * Gets users with processes
73 *
74 * @return array Array of users with processes
75 */
76 public function getUsersWithProcesses(): array
77 {
78 return $this->lpageryDao->lpagery_get_users_with_processes();
79 }
80
81 /**
82 * Creates an onboarding template page
83 *
84 * @return array Result of operation
85 */
86 public function createOnboardingTemplatePage(): array
87 {
88 $page_id = $this->onboardingService->createOnboardingTemplatePage();
89
90 if (!$page_id) {
91 return ["success" => false];
92 }
93
94 return [
95 "success" => true,
96 "page_id" => $page_id
97 ];
98 }
99
100 /**
101 * Gets Google Sheet scheduled data
102 *
103 * @return array Google Sheet scheduled data
104 */
105 public function getGoogleSheetScheduledData(): array
106 {
107 $event = wp_get_scheduled_event('lpagery_sync_google_sheet');
108 $response = [];
109
110 if ($event) {
111 // Next sync timestamp
112 $response['next_sync_timestamp'] = $event->timestamp;
113
114 // Schedule interval (e.g., hourly, daily)
115 $response['schedule_interval'] = $event->schedule;
116
117 // Time until the next sync in human-readable format
118 if ($event->timestamp >= time()) {
119 $response['time_until_next_sync'] = Utils::lpagery_time_ago($event->timestamp);
120 }
121
122 // Memory usage information (limit in bytes)
123 $memory_usage = MemoryUtils::lpagery_get_memory_usage();
124 $response['memory_limit_bytes'] = $memory_usage['limit'];
125 $response['pretty_memory_limit'] = $memory_usage['pretty_limit'];
126 }
127
128 return $response;
129 }
130 }