diff --git a/packages/playground/data-liberation-static-files-editor/blueprint.json b/packages/playground/data-liberation-static-files-editor/blueprint.json index b05a2498f3..098ae0160f 100644 --- a/packages/playground/data-liberation-static-files-editor/blueprint.json +++ b/packages/playground/data-liberation-static-files-editor/blueprint.json @@ -20,10 +20,6 @@ "step": "activatePlugin", "pluginPath": "z-data-liberation-static-files-editor/plugin.php" }, - { - "step": "activatePlugin", - "pluginPath": "gutenberg/gutenberg.php" - }, { "step": "runPHP", "code": " 'My Notes', 'post_status' => 'publish', 'post_type' => 'page'));" diff --git a/packages/playground/data-liberation-static-files-editor/plugin.php b/packages/playground/data-liberation-static-files-editor/plugin.php index a1f85a242f..e1c45bec3f 100644 --- a/packages/playground/data-liberation-static-files-editor/plugin.php +++ b/packages/playground/data-liberation-static-files-editor/plugin.php @@ -46,17 +46,27 @@ class WP_Static_Files_Editor_Plugin { static private function get_fs() { if(!self::$fs) { $dot_git_path = WP_CONTENT_DIR . '/.static-pages.git'; + if(!is_dir($dot_git_path)) { + mkdir($dot_git_path, 0777, true); + } $local_fs = new WP_Local_Filesystem($dot_git_path); $repo = new WP_Git_Repository($local_fs); $repo->add_remote('origin', GIT_REPO_URL); $repo->set_ref_head('HEAD', 'refs/heads/' . GIT_BRANCH); $repo->set_config_value('user.name', GIT_USER_NAME); $repo->set_config_value('user.email', GIT_USER_EMAIL); + + $client = new WP_Git_Client($repo); + if(false === $client->force_pull()) { + _doing_it_wrong(__METHOD__, 'Failed to pull from remote repository', '1.0.0'); + } + self::$fs = new WP_Git_Filesystem( $repo, [ 'root' => GIT_DIRECTORY_ROOT, 'auto_push' => true, + 'client' => $client, ] ); } @@ -68,6 +78,7 @@ static public function initialize() { register_activation_hook( __FILE__, array(self::class, 'import_static_pages') ); add_action('init', function() { + self::get_fs(); self::register_post_type(); }); @@ -86,7 +97,7 @@ static public function initialize() { $post_id = wp_insert_post(array( 'post_title' => 'My first note', 'post_type' => WP_LOCAL_FILE_POST_TYPE, - 'post_status' => 'draft' + 'post_status' => 'publish' )); } else { $post_id = $posts[0]->ID; @@ -440,7 +451,8 @@ static public function import_static_pages() { $importer = WP_Stream_Importer::create( function () { return new WP_Filesystem_Entity_Reader( - new WP_Local_Filesystem(WP_STATIC_CONTENT_DIR), + self::get_fs(), + // new WP_Local_Filesystem(WP_STATIC_CONTENT_DIR) array( 'post_type' => WP_LOCAL_FILE_POST_TYPE, ) diff --git a/packages/playground/data-liberation-static-files-editor/run.sh b/packages/playground/data-liberation-static-files-editor/run.sh index d90ec0835c..d78b543d41 100644 --- a/packages/playground/data-liberation-static-files-editor/run.sh +++ b/packages/playground/data-liberation-static-files-editor/run.sh @@ -8,6 +8,5 @@ bun --inspect ../cli/src/cli.ts \ --mount=../data-liberation-static-files-editor:/wordpress/wp-content/plugins/z-data-liberation-static-files-editor \ --mount=../data-liberation-markdown:/wordpress/wp-content/plugins/z-data-liberation-markdown \ --mount=../data-liberation:/wordpress/wp-content/plugins/data-liberation \ - --mount=../../../../gutenberg:/wordpress/wp-content/plugins/gutenberg \ --mount=./my-notes/workdir:/wordpress/wp-content/uploads/static-pages \ --blueprint=./blueprint.json diff --git a/packages/playground/data-liberation/src/git/WP_Git_Client.php b/packages/playground/data-liberation/src/git/WP_Git_Client.php index 9a25dcd9bd..a5a5c9c114 100644 --- a/packages/playground/data-liberation/src/git/WP_Git_Client.php +++ b/packages/playground/data-liberation/src/git/WP_Git_Client.php @@ -150,7 +150,11 @@ public function list_objects($ref_hash) { return WP_Git_Pack_Processor::decode($pack_data); } - public function force_pull($branch_name, $path = '/') { + public function force_pull($branch_name=null, $path = '/') { + if(!$branch_name) { + $branch_name = $this->index->get_ref_head('HEAD', ['resolve_ref' => false]); + $branch_name = $this->localize_ref_name($branch_name); + } $path = '/' . ltrim($path, '/'); $remote_refs = $this->fetchRefs('refs/heads/' . $branch_name); $remote_head = $remote_refs['refs/heads/' . $branch_name]; diff --git a/packages/playground/data-liberation/src/git/WP_Git_Repository.php b/packages/playground/data-liberation/src/git/WP_Git_Repository.php index 2856dc8dba..36247484b9 100644 --- a/packages/playground/data-liberation/src/git/WP_Git_Repository.php +++ b/packages/playground/data-liberation/src/git/WP_Git_Repository.php @@ -414,10 +414,7 @@ public function get_ref_head($ref='HEAD', $options=[]) { } $contents = trim($this->fs->read_file($path)); if($options['resolve_ref'] ?? true) { - if(strpos($contents, 'ref: ') === 0) { - $branch = trim(substr($contents, 5)); - return $this->get_ref_head($branch, $options); - } + return $this->get_ref_head($contents, $options); } return $contents; }