aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-08 20:30:00 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-08 20:30:00 -0400
commitd714cd76dd4f38f7a04c7f9fbded427d7b06d3a8 (patch)
tree2a7995cca5f0f418abb20fb22d00faebca76310c
parent174484a51cfc99e2194480a7e7513694028eecb3 (diff)
downloadvolse-hubzilla-d714cd76dd4f38f7a04c7f9fbded427d7b06d3a8.tar.gz
volse-hubzilla-d714cd76dd4f38f7a04c7f9fbded427d7b06d3a8.tar.bz2
volse-hubzilla-d714cd76dd4f38f7a04c7f9fbded427d7b06d3a8.zip
Addon repo is copied to /extend/addon/ when admin presses install. Addon repos can be removed via GUI.
-rw-r--r--Zotlabs/Module/Admin.php62
-rwxr-xr-xview/tpl/admin_plugins.tpl55
2 files changed, 110 insertions, 7 deletions
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index c068110a9..404585ccd 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -43,6 +43,14 @@ class Admin extends \Zotlabs\Web\Controller {
$this->admin_page_plugins_post('addrepo');
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 &&
is_file("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) {
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':
require_once('library/markdown.php');
if(array_key_exists('repoURL',$_REQUEST)) {
@@ -1713,6 +1772,7 @@ class Admin extends \Zotlabs\Web\Controller {
$repoURL = $_REQUEST['repoURL'];
$extendDir = __DIR__ . '/../../store/git/sys/extend';
$addonDir = $extendDir.'/addon';
+ $tempAddonDir = __DIR__ . '/../../store/git/sys/temp';
if(!file_exists($extendDir)) {
if(!mkdir($extendDir, 0770, true)) {
logger('Error creating extend folder: ' . $extendDir);
@@ -1735,7 +1795,7 @@ class Admin extends \Zotlabs\Web\Controller {
logger('Invalid git repo');
json_return_and_die(array('message' => 'Invalid git repo', 'success' => false));
}
- $repoDir = $addonDir.'/'.$repoName;
+ $repoDir = $tempAddonDir.'/'.$repoName;
// clone the repo if new automatically
$git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir);
diff --git a/view/tpl/admin_plugins.tpl b/view/tpl/admin_plugins.tpl
index 87d380a01..8ed5fd556 100755
--- a/view/tpl/admin_plugins.tpl
+++ b/view/tpl/admin_plugins.tpl
@@ -50,8 +50,6 @@
{{$newRepoModal}}
<script>
- $("#generic-modal-ok-{{$id}}").click(installAddonRepo());
-
function adminPluginsAddRepo() {
var repoURL = $('#id_repoURL').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>Remotes</h4><p>'+JSON.stringify(response.repo.remote)+'</p>');
$('.modal-dialog').width('80%');
+ $("#generic-modal-ok-{{$newRepoModalID}}").click(function () {
+ installAddonRepo();
+ });
$('#generic-modal-{{$newRepoModalID}}').modal();
} else {
window.console.log('Error adding repo :' + response['message']);
@@ -78,17 +79,59 @@
function installAddonRepo() {
// 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) {
- window.console.log('updateAddonRepo; ' + repoName);
+ window.console.log('updateAddonRep:; ' + repoName);
// TODO: Update an existing repo
}
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
}
function removeAddonRepo(repoName) {
- window.console.log('removeAddonRepo; ' + repoName);
+ window.console.log('removeAddonRepo: ' + repoName);
// 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> \ No newline at end of file