Addon repo is copied to /extend/addon/ when admin presses install. Addon repos can be removed via GUI.

This commit is contained in:
Andrew Manning 2016-05-08 20:30:00 -04:00
parent 174484a51c
commit d714cd76dd
2 changed files with 110 additions and 7 deletions

View File

@ -43,6 +43,14 @@ class Admin extends \Zotlabs\Web\Controller {
$this->admin_page_plugins_post('addrepo'); $this->admin_page_plugins_post('addrepo');
break; break;
} }
if (argc() > 2 && argv(2) === 'installrepo') {
$this->admin_page_plugins_post('installrepo');
break;
}
if (argc() > 2 && argv(2) === 'removerepo') {
$this->admin_page_plugins_post('removerepo');
break;
}
if (argc() > 2 && if (argc() > 2 &&
is_file("addon/" . argv(2) . "/" . argv(2) . ".php")){ is_file("addon/" . argv(2) . "/" . argv(2) . ".php")){
@include_once("addon/" . argv(2) . "/" . argv(2) . ".php"); @include_once("addon/" . argv(2) . "/" . argv(2) . ".php");
@ -1706,6 +1714,57 @@ class Admin extends \Zotlabs\Web\Controller {
function admin_page_plugins_post($action) { function admin_page_plugins_post($action) {
switch($action) { switch($action) {
case 'removerepo':
if(array_key_exists('repoName', $_REQUEST)) {
$repoName = $_REQUEST['repoName'];
} else {
json_return_and_die(array('message' => 'No repo name provided.', 'success' => false));
}
$repoDir = __DIR__ . '/../../store/git/sys/extend/addon/'.$repoName;
if(!is_dir($repoDir)) {
json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false));
}
// TODO: remove directory and unlink /addon/files
if(rrmdir($repoDir)) {
json_return_and_die(array('message' => 'Repo deleted.', 'success' => true));
} else {
json_return_and_die(array('message' => 'Error deleting addon repo.', 'success' => false));
}
case 'installrepo':
require_once('library/markdown.php');
if(array_key_exists('repoURL',$_REQUEST)) {
require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies
$repoURL = $_REQUEST['repoURL'];
$extendDir = __DIR__ . '/../../store/git/sys/extend';
$addonDir = $extendDir.'/addon';
if(!file_exists($extendDir)) {
if(!mkdir($extendDir, 0770, true)) {
logger('Error creating extend folder: ' . $extendDir);
json_return_and_die(array('message' => 'Error creating extend folder: ' . $extendDir, 'success' => false));
} else {
if(!symlink(__DIR__ . '/../../extend/addon', $addonDir)) {
logger('Error creating symlink to addon folder: ' . $addonDir);
json_return_and_die(array('message' => 'Error creating symlink to addon folder: ' . $addonDir, 'success' => false));
}
}
}
$repoName = null;
if(array_key_exists('repoName',$_REQUEST)) {
$repoName = $_REQUEST['repoName'];
} else {
$repoName = GitRepo::getRepoNameFromURL($repoURL);
}
if(!$repoName) {
logger('Invalid git repo');
json_return_and_die(array('message' => 'Invalid git repo', 'success' => false));
}
$repoDir = $addonDir.'/'.$repoName;
$tempAddonDir = __DIR__ . '/../../store/git/sys/temp/' . $repoName;
rename($tempAddonDir, $repoDir);
$git = new GitRepo('sys', $repoURL, false, $repoName, $repoDir);
$repo = $git->probeRepo();
json_return_and_die(array('repo'=> $repo, 'message' => '', 'success' => true));
}
case 'addrepo': case 'addrepo':
require_once('library/markdown.php'); require_once('library/markdown.php');
if(array_key_exists('repoURL',$_REQUEST)) { if(array_key_exists('repoURL',$_REQUEST)) {
@ -1713,6 +1772,7 @@ class Admin extends \Zotlabs\Web\Controller {
$repoURL = $_REQUEST['repoURL']; $repoURL = $_REQUEST['repoURL'];
$extendDir = __DIR__ . '/../../store/git/sys/extend'; $extendDir = __DIR__ . '/../../store/git/sys/extend';
$addonDir = $extendDir.'/addon'; $addonDir = $extendDir.'/addon';
$tempAddonDir = __DIR__ . '/../../store/git/sys/temp';
if(!file_exists($extendDir)) { if(!file_exists($extendDir)) {
if(!mkdir($extendDir, 0770, true)) { if(!mkdir($extendDir, 0770, true)) {
logger('Error creating extend folder: ' . $extendDir); logger('Error creating extend folder: ' . $extendDir);
@ -1735,7 +1795,7 @@ class Admin extends \Zotlabs\Web\Controller {
logger('Invalid git repo'); logger('Invalid git repo');
json_return_and_die(array('message' => 'Invalid git repo', 'success' => false)); json_return_and_die(array('message' => 'Invalid git repo', 'success' => false));
} }
$repoDir = $addonDir.'/'.$repoName; $repoDir = $tempAddonDir.'/'.$repoName;
// clone the repo if new automatically // clone the repo if new automatically
$git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir); $git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir);

View File

@ -50,8 +50,6 @@
{{$newRepoModal}} {{$newRepoModal}}
<script> <script>
$("#generic-modal-ok-{{$id}}").click(installAddonRepo());
function adminPluginsAddRepo() { function adminPluginsAddRepo() {
var repoURL = $('#id_repoURL').val(); var repoURL = $('#id_repoURL').val();
var repoName = $('#id_repoName').val(); var repoName = $('#id_repoName').val();
@ -67,6 +65,9 @@
modalBody.append('<h4>Branches</h4><p>'+JSON.stringify(response.repo.branches)+'</p>'); modalBody.append('<h4>Branches</h4><p>'+JSON.stringify(response.repo.branches)+'</p>');
modalBody.append('<h4>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>'); modalBody.append('<h4>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>');
$('.modal-dialog').width('80%'); $('.modal-dialog').width('80%');
$("#generic-modal-ok-{{$newRepoModalID}}").click(function () {
installAddonRepo();
});
$('#generic-modal-{{$newRepoModalID}}').modal(); $('#generic-modal-{{$newRepoModalID}}').modal();
} else { } else {
window.console.log('Error adding repo :' + response['message']); window.console.log('Error adding repo :' + response['message']);
@ -78,17 +79,59 @@
function installAddonRepo() { function installAddonRepo() {
// TODO: Link store/git/sys/reponame to /extend/addon/ and run util/add_addon_repo script // TODO: Link store/git/sys/reponame to /extend/addon/ and run util/add_addon_repo script
var repoURL = $('#id_repoURL').val();
var repoName = $('#id_repoName').val();
$.post(
"/admin/plugins/installrepo", {repoURL: repoURL, repoName: repoName},
function(response) {
if (response.success) {
$('#generic-modal-title-{{$newRepoModalID}}').html('Addon repo installed');
var modalBody = $('#generic-modal-body-{{$newRepoModalID}}');
modalBody.html('<h2>Repo Info</h2><p>Message: ' + response.message + '</p>');
modalBody.append('<h4>Branches</h4><p>'+JSON.stringify(response.repo.branches)+'</p>');
modalBody.append('<h4>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>');
$('.modal-dialog').width('80%');
//$("#generic-modal-cancel-{{$newRepoModalID}}").hide();
$("#generic-modal-ok-{{$newRepoModalID}}").html('OK');
$("#generic-modal-ok-{{$newRepoModalID}}").off('click');
$("#generic-modal-ok-{{$newRepoModalID}}").click(function () {
$('#generic-modal-{{$newRepoModalID}}').modal('hide');
location.reload();
});
$('#generic-modal-{{$newRepoModalID}}').modal();
} else {
window.console.log('Error installing repo :' + response['message']);
}
return false;
},
'json');
} }
function updateAddonRepo(repoName) { function updateAddonRepo(repoName) {
window.console.log('updateAddonRepo; ' + repoName); window.console.log('updateAddonRep:; ' + repoName);
// TODO: Update an existing repo // TODO: Update an existing repo
} }
function switchAddonRepoBranch(repoName) { function switchAddonRepoBranch(repoName) {
window.console.log('switchAddonRepoBranch; ' + repoName); window.console.log('switchAddonRepoBranch: ' + repoName);
// TODO: Discover the available branches and create an interface to switch between them // TODO: Discover the available branches and create an interface to switch between them
} }
function removeAddonRepo(repoName) { function removeAddonRepo(repoName) {
window.console.log('removeAddonRepo; ' + repoName); window.console.log('removeAddonRepo: ' + repoName);
// TODO: Unlink the addons and delete the addon repo // TODO: Unlink the addons and delete the addon repo
if(confirm('Are you sure you want to remove the addon repo ' + repoName + '?')) {
$.post(
"/admin/plugins/removerepo", {repoName: repoName},
function(response) {
if (response.success) {
window.console.log('Addon repo'+repoName+'successfully removed :' + response['message']);
} else {
window.console.log('Error installing repo :' + response['message']);
}
return false;
},
'json');
//alert('Deleted');
}
} }
</script> </script>