|
9 | 9 |
|
10 | 10 | declare( strict_types=1 ); |
11 | 11 |
|
| 12 | +namespace DataMachineCode\Abilities { |
| 13 | + class GitHubAbilities |
| 14 | + { |
| 15 | + } |
| 16 | +} |
| 17 | + |
12 | 18 | namespace { |
13 | 19 | if (! defined('ABSPATH') ) { |
14 | 20 | define('ABSPATH', __DIR__ . '/'); |
@@ -50,6 +56,25 @@ function wp_parse_url( string $url, int $component = -1 ): mixed |
50 | 56 | } |
51 | 57 | } |
52 | 58 |
|
| 59 | + $GLOBALS['dmc_remote_workspace_options'] = array(); |
| 60 | + |
| 61 | + if (! function_exists('get_option') ) { |
| 62 | + function get_option( string $key, mixed $default_value = false ): mixed |
| 63 | + { |
| 64 | + return $GLOBALS['dmc_remote_workspace_options'][ $key ] ?? $default_value; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + if (! function_exists('update_option') ) { |
| 69 | + function update_option( string $key, mixed $value, bool $autoload = true ): bool |
| 70 | + { |
| 71 | + unset($autoload); |
| 72 | + $GLOBALS['dmc_remote_workspace_options'][ $key ] = $value; |
| 73 | + return true; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + include __DIR__ . '/../inc/Workspace/RemoteWorkspaceBackend.php'; |
53 | 78 | include __DIR__ . '/../inc/Bundle/WorkspacePreloadArtifact.php'; |
54 | 79 |
|
55 | 80 | use DataMachineCode\Bundle\WorkspacePreloadArtifact; |
@@ -151,6 +176,38 @@ static function ( array $input ): WP_Error { |
151 | 176 | ); |
152 | 177 | $assert('treats existing checkout as idempotent success', ! is_wp_error($exists) && true === ( $exists['repositories'][0]['already_exists'] ?? false )); |
153 | 178 |
|
| 179 | + $remote_fallback_artifact = new WorkspacePreloadArtifact( |
| 180 | + static function (): WP_Error { |
| 181 | + return new WP_Error( |
| 182 | + 'datamachine_workspace_git_unavailable', |
| 183 | + 'Clone workspace repository cannot run with the current workspace backend.', |
| 184 | + array( 'status' => 500 ) |
| 185 | + ); |
| 186 | + } |
| 187 | + ); |
| 188 | + $remote_fallback = $remote_fallback_artifact->apply_artifact( |
| 189 | + null, |
| 190 | + array( |
| 191 | + 'artifact_type' => WorkspacePreloadArtifact::ARTIFACT_TYPE, |
| 192 | + 'artifact_id' => 'remote-fallback', |
| 193 | + 'payload' => array( |
| 194 | + 'repositories' => array( |
| 195 | + array( |
| 196 | + 'name' => 'static-site-importer', |
| 197 | + 'url' => 'https://github.com/chubes4/static-site-importer.git', |
| 198 | + ), |
| 199 | + ), |
| 200 | + ), |
| 201 | + ) |
| 202 | + ); |
| 203 | + $assert('falls back to remote backend when local git clone is unavailable', ! is_wp_error($remote_fallback) && 'github_api' === ( $remote_fallback['repositories'][0]['result']['backend'] ?? '' )); |
| 204 | + $assert( |
| 205 | + 'remote preload state keeps remote backend active for later tools', |
| 206 | + \DataMachineCode\Workspace\RemoteWorkspaceBackend::has_registered_state() |
| 207 | + && false === \DataMachineCode\Workspace\RemoteWorkspaceBackend::should_handle_for_local_capabilities(true, true) |
| 208 | + && \DataMachineCode\Workspace\RemoteWorkspaceBackend::should_handle() |
| 209 | + ); |
| 210 | + |
154 | 211 | if (array() !== $failures ) { |
155 | 212 | echo "\nFailures:\n"; |
156 | 213 | foreach ( $failures as $failure ) { |
|
0 commit comments