PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
← All changes | includes/games/schema.php +36 -23 0.9.81.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Games schema.
3 + * OpenStation — Games schema.
4 4 *
5 5 * Two custom tables back the game system:
6 6 *
7 7 * - `_desktop_mode_game_scores` — one row per finished game run.
@@ -18,22 +18,35 @@
18 18 *
19 19 * `state` columns are VARCHAR rather than ENUM, matching the
20 20 * folder-shares table (house style — dbDelta and ENUM don't mix).
21 21 *
22 - * @package WPDesktopMode
22 + * @package OpenStation
23 23 */
24 24
25 25 defined( 'ABSPATH' ) || exit;
26 26
27 -define( 'DESKTOP_MODE_GAMES_SCHEMA_VERSION', '1' );
28 -define( 'DESKTOP_MODE_GAMES_SCHEMA_OPTION', 'desktop_mode_games_schema_version' );
27 +define( 'OPENSTATION_GAMES_SCHEMA_VERSION', '1' );
28 +/**
29 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
30 + * persisted or externally-visible identifier, so renaming it would
31 + * orphan data already written by live installs (or break a live
32 + * URL). The mismatch between this constant's name and its value is
33 + * deliberate — it is NOT a half-finished rename.
34 + */
35 +define( 'OPENSTATION_GAMES_SCHEMA_OPTION', 'desktop_mode_games_schema_version' );
29 36
30 37 /**
31 38 * Returns the per-table names with the active prefix applied.
32 39 *
40 + * The `desktop_mode_` segment is the pre-rebrand spelling and is frozen:
41 + * these are real tables holding real rows on live installs. Renaming
42 + * them silently creates a second, empty set and every score and
43 + * challenge disappears. The mismatch against the `openstation_*`
44 + * function name is deliberate.
45 + *
33 46 * @return array{ scores: string, challenges: string }
34 47 */
35 -function desktop_mode_games_table_names() {
48 +function openstation_games_table_names() {
36 49 global $wpdb;
37 50 return array(
38 51 'scores' => $wpdb->prefix . 'desktop_mode_game_scores',
39 52 'challenges' => $wpdb->prefix . 'desktop_mode_game_challenges',
@@ -45,14 +58,14 @@
45 58 * on `admin_init` / `rest_api_init` / `init` (gated by a
46 59 * version-option mismatch) so a manual file-copy install still ends
47 60 * up with the tables.
48 61 */
49 -function desktop_mode_games_install_schema() {
62 +function openstation_games_install_schema() {
50 63 global $wpdb;
51 64
52 65 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
53 66
54 - $tables = desktop_mode_games_table_names();
67 + $tables = openstation_games_table_names();
55 68 $charset_collate = $wpdb->get_charset_collate();
56 69
57 70 $scores_sql = "CREATE TABLE {$tables['scores']} (
58 71 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
@@ -94,12 +107,12 @@
94 107 // Belt-and-suspenders: dbDelta's DESCRIBE-based table detection has
95 108 // documented failure modes (see the files schema for the full
96 109 // rationale) — verify both tables physically exist and CREATE them
97 110 // explicitly when not.
98 - desktop_mode_games_ensure_table( $tables['scores'], $scores_sql );
99 - desktop_mode_games_ensure_table( $tables['challenges'], $challenges_sql );
111 + openstation_games_ensure_table( $tables['scores'], $scores_sql );
112 + openstation_games_ensure_table( $tables['challenges'], $challenges_sql );
100 113
101 - update_option( DESKTOP_MODE_GAMES_SCHEMA_OPTION, DESKTOP_MODE_GAMES_SCHEMA_VERSION );
114 + update_option( OPENSTATION_GAMES_SCHEMA_OPTION, OPENSTATION_GAMES_SCHEMA_VERSION );
102 115
103 116 /**
104 117 * Fires after the games schema is installed / migrated.
105 118 *
@@ -104,9 +117,9 @@
104 117 * Fires after the games schema is installed / migrated.
105 118 *
106 119 * @param string $version The version that was installed.
107 120 */
108 - do_action( 'desktop_mode_games_schema_installed', DESKTOP_MODE_GAMES_SCHEMA_VERSION );
121 + do_action( 'openstation_games_schema_installed', OPENSTATION_GAMES_SCHEMA_VERSION );
109 122 }
110 123
111 124 /**
112 125 * Create a table via `CREATE TABLE IF NOT EXISTS` when
@@ -118,15 +131,15 @@
118 131 *
119 132 * @param string $table Fully-prefixed table name.
120 133 * @param string $sql The dbDelta CREATE TABLE statement for it.
121 134 */
122 -function desktop_mode_games_ensure_table( $table, $sql ) {
135 +function openstation_games_ensure_table( $table, $sql ) {
123 136 global $wpdb;
124 137
125 138 $exists = (int) $wpdb->get_var(
126 139 $wpdb->prepare(
127 - "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES
128 - WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s",
140 + 'SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES
141 + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = %s',
129 142 $table
130 143 )
131 144 );
132 145 if ( 0 < $exists ) {
@@ -143,22 +156,22 @@
143 156 * Lazy migrator — runs when the stored schema version doesn't match
144 157 * the constant. Idempotent: `dbDelta` itself is a no-op when the
145 158 * tables already match.
146 159 */
147 -function desktop_mode_games_maybe_install_schema() {
148 - $installed = get_option( DESKTOP_MODE_GAMES_SCHEMA_OPTION, '' );
149 - if ( $installed === DESKTOP_MODE_GAMES_SCHEMA_VERSION ) {
160 +function openstation_games_maybe_install_schema() {
161 + $installed = get_option( OPENSTATION_GAMES_SCHEMA_OPTION, '' );
162 + if ( OPENSTATION_GAMES_SCHEMA_VERSION === $installed ) {
150 163 return;
151 164 }
152 - desktop_mode_games_install_schema();
165 + openstation_games_install_schema();
153 166 }
154 -add_action( 'admin_init', 'desktop_mode_games_maybe_install_schema' );
167 +add_action( 'admin_init', 'openstation_games_maybe_install_schema' );
155 168 // REST + Heartbeat requests never fire `admin_init` — without these a
156 169 // session hitting the scores endpoint before any admin page load
157 170 // would query missing tables.
158 -add_action( 'rest_api_init', 'desktop_mode_games_maybe_install_schema' );
159 -add_action( 'init', 'desktop_mode_games_maybe_install_schema', 1 );
160 -register_activation_hook( DESKTOP_MODE_FILE, 'desktop_mode_games_install_schema' );
171 +add_action( 'rest_api_init', 'openstation_games_maybe_install_schema' );
172 +add_action( 'init', 'openstation_games_maybe_install_schema', 1 );
173 +register_activation_hook( OPENSTATION_FILE, 'openstation_games_install_schema' );
161 174
162 175 /**
163 176 * Current epoch-ms timestamp. Centralized so the store and the
164 177 * Heartbeat channel stay in lock-step.
@@ -164,7 +177,7 @@
164 177 * Heartbeat channel stay in lock-step.
165 178 *
166 179 * @return int
167 180 */
168 -function desktop_mode_games_now_ms() {
181 +function openstation_games_now_ms() {
169 182 return (int) round( microtime( true ) * 1000 );
170 183 }