Skip to content

Instantly share code, notes, and snippets.

@themightychris
Last active January 27, 2020 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themightychris/d7ac5906d8848128d6006a473a634b34 to your computer and use it in GitHub Desktop.
Save themightychris/d7ac5906d8848128d6006a473a634b34 to your computer and use it in GitHub Desktop.
De-parent an emergence site

Prepare vfs-site projection

Optionally, begin the vfs-site projection branch with a snapshot of the legacy VFS:

emergence-source-http-legacy pull mysite.example.org

# using tree hash output at end of pull command
TREE_HASH=4b825dc642cb6eb9a060e54bf8d69288fbee4904
git commit-tree -m "snapshot mysite.example.org" "${TREE_HASH}"

# using commit hash output at end of commit-tree command
COMMIT_HASH=4b825dc642cb6eb9a060e54bf8d69288fbee4904
git update-ref refs/heads/emergence/vfs-site/v1

Then, project the vfs-site holobranch and commit it to the same branch:

git holo project emergence-vfs-site --commit-to=emergence/vfs-site/v1

Install HTTPie

sudo hab pkg install core/python
sudo hab pkg exec core/python pip install httpie httpie-unixsocket
sudo hab pkg binlink core/python http

Unset parent options in site.json

export SITE_HANDLE="mysitehandle"

# check that CLI works
sudo http \
    GET http+unix://%2Femergence%2Fkernel.sock/sites/${SITE_HANDLE}

# null out parent_hostname and parent_key
sudo http \
    PATCH http+unix://%2Femergence%2Fkernel.sock/sites/${SITE_HANDLE} \
    parent_hostname:=null \
    parent_key:=null

Purge parent cache

in emergence-mysql-shell ${SITE_HANDLE}:

DELETE FROM _e_files WHERE CollectionID IN (SELECT ID FROM _e_file_collections WHERE Site = "Remote");

DELETE FROM _e_file_collections WHERE Site = "Remote";

Import vfs-site branch

Switch site repo to new vfs-site branch:

export SOURCE_NAME="mysourcename"
sudo emergence-git-shell ${SITE_HANDLE} ${SOURCE_NAME}
git fetch --all
git checkout emergence/vfs-site/v1
pwd
exit

Change into that directory and open a PHP shell:

cd "/emergence/sites/${SITE_HANDLE}/site-data/git/${SOURCE_NAME}"
emergence-shell ${SITE_HANDLE}
$collections = array_diff(glob('*'), ['sencha-workspace']);
foreach ($collections as $collection) {
    echo "Importing $collection\n\t";
    echo http_build_query(Emergence_FS::importTree($collection, $collection));
    echo "\n\n";
}

echo NestingBehavior::repairTable(SiteCollection::class, 'PosLeft', 'PosRight')." collections renested\n\n";

Then stop/start PHP to clear all caches and run repair on the VFS, and then stop/start PHP again for good measure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment