@@ -7,7 +7,7 @@ import { dependenciesTotalSize, init } from "../../../node_modules/@php-wasm/web
77import phpWasmModule from "../../../node_modules/@php-wasm/web-8-5/asyncify/8_5_8/php_8_5.wasm"
88import { CLOUDFLARE_RUNTIME_HEALTH_MARKER , CLOUDFLARE_RUNTIME_HEALTH_SCHEMA , cloudflareRuntimeHealthResponse } from "./health-envelope.js"
99import { leaseRetryDelayMs } from "./lease-retry.js"
10- import { routeWorkerRequest , type EditorProbePhase } from "./request-routing.js"
10+ import { routeWorkerRequest } from "./request-routing.js"
1111import { toFetchResponse , toPHPRequest } from "./request-translation.js"
1212import { deriveWordPressAuthConstants , type WordPressAuthConstant } from "./wordpress-auth.js"
1313import { isWordPressRuntimeFile , wordpressStaticArchivePath , wordpressStaticContentType } from "./wordpress-runtime-corpus.js"
@@ -25,7 +25,7 @@ const PHP_VERSION = "8.5.8"
2525// Browser assets must come from the same immutable WordPress release as the server corpus.
2626const WORDPRESS_ARCHIVE_URL = ( wordpressRuntimeArtifactManifest as WordPressRuntimeArtifactManifest ) . source . url
2727const SQLITE_INTEGRATION_ARCHIVE_URL = "https://github.com/WordPress/sqlite-database-integration/releases/download/v2.2.23/plugin-sqlite-database-integration.zip"
28- const MARKDOWN_DATABASE_INTEGRATION_REVISION = "6244f244f47f99af3261ba0948262cebe79e5a73 "
28+ const MARKDOWN_DATABASE_INTEGRATION_REVISION = "7cf025f2d64aa933d937f1a18a129e278c231783 "
2929const SITE_URL = "https://wp-codebox-runtime.invalid"
3030const DATABASE_PATH = "/wordpress/wp-content/database/.ht.sqlite"
3131const MARKDOWN_ROOT = "/wordpress/wp-content/markdown"
@@ -86,7 +86,6 @@ export default {
8686 const route = routeWorkerRequest ( request )
8787 const coordinator = env . WORDPRESS_STATE . getByName ( "default" )
8888 if ( route . kind === "operator-reset" ) return resetCanonicalWordPress ( request , env , coordinator )
89- if ( route . kind === "editor-probe" ) return runCoordinatedEditorProbe ( request , env , coordinator , route . phase )
9089 if ( route . kind === "probe" ) {
9190 if ( route . phase === "canonical-session" ) return canonicalSessionProbe ( env . WORDPRESS_STATE_BUCKET , await coordinatorCall < { pointer : MarkdownPointer | null } > ( coordinator , request . url , "state" ) )
9291 return runBootProbe ( route . phase , env . WORDPRESS_STATE_BUCKET )
@@ -100,60 +99,6 @@ export default {
10099 } ,
101100}
102101
103- async function runCoordinatedEditorProbe ( request : Request , env : Env , coordinator : DurableObjectStub , phase : EditorProbePhase ) : Promise < Response > {
104- const lease = await acquireLease ( coordinator , request . url )
105- let finalized = false
106- try {
107- if ( ! lease . pointer ) throw new Error ( "Canonical WordPress must be initialized before running an editor probe." )
108- const runtime = await getRuntime ( env , lease . pointer , new URL ( request . url ) . origin )
109- if ( phase === "auto-draft-no-persist" ) patchAutoDraftPersistenceProbe ( runtime . php )
110- patchEditorProbe ( runtime . php , phase )
111- const response = toFetchResponse ( request , await runtime . requestHandler . request ( await toPHPRequest ( request ) ) )
112- await releaseLease ( coordinator , request . url , lease )
113- finalized = true
114- await discardCachedRuntime ( )
115- return response
116- } catch ( error ) {
117- if ( ! finalized ) await abortLease ( coordinator , request . url , lease )
118- await discardCachedRuntime ( )
119- throw error
120- }
121- }
122-
123- function patchEditorProbe ( php : PHP , phase : EditorProbePhase ) : void {
124- const path = "/wordpress/wp-admin/post-new.php"
125- const source = new TextDecoder ( ) . decode ( php . readFileAsBuffer ( path ) )
126- const markers : Record < EditorProbePhase , string > = {
127- admin : "require_once __DIR__ . '/admin.php';" ,
128- "auto-draft" : "$post_ID = $post->ID;" ,
129- "auto-draft-no-persist" : "$post_ID = $post->ID;" ,
130- "block-editor" : "require_once ABSPATH . 'wp-admin/admin-footer.php';" ,
131- }
132- const marker = markers [ phase ]
133- const index = source . indexOf ( marker )
134- if ( index === - 1 || index !== source . lastIndexOf ( marker ) ) throw new Error ( `WordPress editor probe marker is not unique: ${ phase } ` )
135- const stop = `\necho wp_json_encode( array( 'schema' => 'wp-codebox/cloudflare-editor-probe/v1', 'phase' => '${ phase } ', 'memoryBytes' => memory_get_usage( true ), 'peakMemoryBytes' => memory_get_peak_usage( true ) ) );\nreturn;`
136- const insertion = phase === "block-editor" ? index : index + marker . length
137- php . writeFile ( path , new TextEncoder ( ) . encode ( `${ source . slice ( 0 , insertion ) } ${ stop } ${ source . slice ( insertion ) } ` ) )
138- }
139-
140- function patchAutoDraftPersistenceProbe ( php : PHP ) : void {
141- const path = "/wordpress/wp-content/plugins/markdown-database-integration/inc/class-wp-markdown-write-engine.php"
142- const source = new TextDecoder ( ) . decode ( php . readFileAsBuffer ( path ) )
143- const needle = `if ( $id ) {
144- $this->mark_post_dirty( (int) $id );
145- }`
146- const replacement = `if ( $id ) {
147- $rows = $this->driver->query( "SELECT post_status FROM \`{$this->prefix()}posts\` WHERE ID = " . (int) $id );
148- if ( ! is_array( $rows ) || empty( $rows ) || 'auto-draft' !== ( $rows[0]->post_status ?? '' ) ) {
149- $this->mark_post_dirty( (int) $id );
150- }
151- }`
152- const index = source . indexOf ( needle )
153- if ( index === - 1 || index !== source . lastIndexOf ( needle ) ) throw new Error ( "MDI auto-draft persistence probe marker is not unique." )
154- php . writeFile ( path , new TextEncoder ( ) . encode ( `${ source . slice ( 0 , index ) } ${ replacement } ${ source . slice ( index + needle . length ) } ` ) )
155- }
156-
157102interface MarkdownManifestFile {
158103 path : string
159104 objectKey : string
0 commit comments