@@ -106,6 +106,7 @@ async function runCoordinatedEditorProbe(request: Request, env: Env, coordinator
106106 try {
107107 if ( ! lease . pointer ) throw new Error ( "Canonical WordPress must be initialized before running an editor probe." )
108108 const runtime = await getRuntime ( env , lease . pointer , new URL ( request . url ) . origin )
109+ if ( phase === "auto-draft-no-persist" ) patchAutoDraftPersistenceProbe ( runtime . php )
109110 patchEditorProbe ( runtime . php , phase )
110111 const response = toFetchResponse ( request , await runtime . requestHandler . request ( await toPHPRequest ( request ) ) )
111112 await releaseLease ( coordinator , request . url , lease )
@@ -125,6 +126,7 @@ function patchEditorProbe(php: PHP, phase: EditorProbePhase): void {
125126 const markers : Record < EditorProbePhase , string > = {
126127 admin : "require_once __DIR__ . '/admin.php';" ,
127128 "auto-draft" : "$post_ID = $post->ID;" ,
129+ "auto-draft-no-persist" : "$post_ID = $post->ID;" ,
128130 "block-editor" : "require_once ABSPATH . 'wp-admin/admin-footer.php';" ,
129131 }
130132 const marker = markers [ phase ]
@@ -135,6 +137,23 @@ function patchEditorProbe(php: PHP, phase: EditorProbePhase): void {
135137 php . writeFile ( path , new TextEncoder ( ) . encode ( `${ source . slice ( 0 , insertion ) } ${ stop } ${ source . slice ( insertion ) } ` ) )
136138}
137139
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+
138157interface MarkdownManifestFile {
139158 path : string
140159 objectKey : string
0 commit comments