Skip to content

Commit

Permalink
#94 import started, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Feb 19, 2019
1 parent be78960 commit a972644
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions system/importFromGit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
include_once '../system/lib/bootstrapHAX.php';
include_once $HAXCMS->configDirectory . '/config.php';
// test if this is a valid user login
if ($HAXCMS->validateJWT()) {
header('Content-Type: application/json');
if ($HAXCMS->validateRequestToken()) {
$params = $HAXCMS->safePost;
// woohoo we can edit this thing!
// try to load this thing
$gitRepo = new GitRepo();
$path = HAXCMS_ROOT . '/' . $HAXCMS->sitesDirectory . strtolower($params['siteName']);
@$gitRepo->create_new($path, $params['gitRepo'], $path);
// validate the repo is a legit json outline schema backed haxcms site
// @todo should do additional validation but this is smell test for now
if (is_dir($path) && file_exists($path . '/site.json')) {
header('Status: 200');
// now the git repo should exist
$site = $HAXCMS->loadSite(strtolower($params['siteName']));
$schema = $site->manifest;
unset($schema->items);
// main site schema doesn't care about publishing settings
unset($schema->metadata->publishing);
// save it back to the system outline so we can review on the big board
$HAXCMS->outlineSchema->addItem($schema);
$HAXCMS->outlineSchema->save();
print json_encode($schema);
}
else {
header('Status: 500');
print 'GIT REPO COULD NOT BE ESTABLISHED';
}
}
else {
header('Status: 403');
}
exit;
}
?>

0 comments on commit a972644

Please sign in to comment.