Custom addon repo name option added.
This commit is contained in:
parent
f73a74967e
commit
174484a51c
@ -1356,6 +1356,7 @@ class Admin extends \Zotlabs\Web\Controller {
|
||||
'$post' => 'admin/plugins/addrepo',
|
||||
'$desc' => t('Enter the public git repository URL of the plugin repo.'),
|
||||
'$repoURL' => array('repoURL', t('Plugin repo git URL'), '', ''),
|
||||
'$repoName' => array('repoName', t('Custom repo name'), '', '', t('(optional)')),
|
||||
'$submit' => t('Download Plugin Repo')
|
||||
)
|
||||
);
|
||||
@ -1709,11 +1710,36 @@ class Admin extends \Zotlabs\Web\Controller {
|
||||
require_once('library/markdown.php');
|
||||
if(array_key_exists('repoURL',$_REQUEST)) {
|
||||
require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies
|
||||
logger('Repo URL submitted: ' . $_REQUEST['repoURL']);
|
||||
$repoURL = $_REQUEST['repoURL'];
|
||||
$git = new GitRepo('sys', $repoURL, true);
|
||||
$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'];
|
||||
logger('repoName: ' . $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;
|
||||
// clone the repo if new automatically
|
||||
$git = new GitRepo('sys', $repoURL, true, $repoName, $repoDir);
|
||||
|
||||
$repo = $git->probeRepo($git->path);
|
||||
$repo = $git->probeRepo();
|
||||
$repo['readme'] = $repo['manifest'] = null;
|
||||
foreach ($git->git->tree('master') as $object) {
|
||||
if ($object['type'] == 'blob' && (strtolower($object['file']) === 'readme.md' || strtolower($object['file']) === 'readme')) {
|
||||
|
@ -15,16 +15,39 @@ class GitRepo {
|
||||
|
||||
public $url = null;
|
||||
public $name = null;
|
||||
public $path = null;
|
||||
private $path = null;
|
||||
private $repoID = null;
|
||||
private $channel = null;
|
||||
public $git = null;
|
||||
private $repoBasePath = null;
|
||||
|
||||
function __construct($channel = 'sys', $url = null, $clone = false, $name = null) {
|
||||
function __construct($channel = 'sys', $url = null, $clone = false, $name = null, $path = null) {
|
||||
|
||||
if($channel === 'sys' && ! is_site_admin()) {
|
||||
logger('Only admin can use channel sys');
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->repoBasePath = __DIR__ . '/../../store/git';
|
||||
$this->channel = $channel;
|
||||
$this->git = new PHPGit();
|
||||
|
||||
// Allow custom path for repo in the case of , for example
|
||||
if($path) {
|
||||
//if(mkdir($path, 0770, true)) {
|
||||
$this->path = $path;
|
||||
//} else {
|
||||
// logger('Error creating GitRepo. Path not created.');
|
||||
// return null;
|
||||
//}
|
||||
} else {
|
||||
$this->path = $this->repoBasePath . "/" . $this->channel . "/" . $this->name;
|
||||
}
|
||||
|
||||
if ($this->isValidGitRepoURL($url)) {
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
if ($name) {
|
||||
$this->name = $name;
|
||||
} else {
|
||||
@ -34,14 +57,17 @@ class GitRepo {
|
||||
logger('Error creating GitRepo. No repo name found.');
|
||||
return null;
|
||||
}
|
||||
$this->path = $this->repoBasePath . "/" . $this->channel . "/" . $this->name;
|
||||
if (file_exists($this->path)) {
|
||||
|
||||
if (is_dir($this->path)) {
|
||||
// ignore the $url input if it exists
|
||||
// TODO: Check if the path is either empty or is a valid git repo and error if not
|
||||
$this->git->setRepository($this->path);
|
||||
// TODO: get repo metadata
|
||||
} else if ($url && validate_url($url) && $this->isValidGitRepoURL($url)) {
|
||||
$this->url = $url;
|
||||
$this->repoID = random_string();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->url) {
|
||||
//$this->repoID = random_string();
|
||||
// create the folder and clone the repo at url to that folder if $clone is true
|
||||
if ($clone) {
|
||||
if (mkdir($this->path, 0770, true)) {
|
||||
@ -69,7 +95,7 @@ class GitRepo {
|
||||
}
|
||||
|
||||
public function setRepoPath($directory) {
|
||||
if (file_exists($directory)) {
|
||||
if (is_dir($directory)) {
|
||||
$this->path->$directory;
|
||||
$this->git->setRepository($directory);
|
||||
return true;
|
||||
@ -88,17 +114,14 @@ class GitRepo {
|
||||
}
|
||||
|
||||
public function cloneRepo() {
|
||||
if (validate_url($this->url) && $this->isValidGitRepoURL($this->url) && file_exists($this->path)) {
|
||||
if (validate_url($this->url) && $this->isValidGitRepoURL($this->url) && is_dir($this->path)) {
|
||||
return $this->git->clone($this->url, $this->path);
|
||||
}
|
||||
}
|
||||
|
||||
public static function probeRepo($dir) {
|
||||
if (!file_exists($dir)) {
|
||||
return null;
|
||||
}
|
||||
$git = new PHPGit();
|
||||
$git->setRepository($dir);
|
||||
public function probeRepo() {
|
||||
$git = $this->git;
|
||||
logger('probeRepo path: ' . $this->path);
|
||||
$repo = array();
|
||||
$repo['remote'] = $git->remote();
|
||||
$repo['branches'] = $git->branch(['all' => true]);
|
||||
@ -107,7 +130,7 @@ class GitRepo {
|
||||
}
|
||||
|
||||
public static function isValidGitRepoURL($url) {
|
||||
if (strrpos(parse_url($url, PHP_URL_PATH), '.')) {
|
||||
if (validate_url($url) && strrpos(parse_url($url, PHP_URL_PATH), '.')) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -54,9 +54,10 @@
|
||||
|
||||
function adminPluginsAddRepo() {
|
||||
var repoURL = $('#id_repoURL').val();
|
||||
var repoName = $('#id_repoName').val();
|
||||
$('#chat-rotator').spin('tiny');
|
||||
$.post(
|
||||
"/admin/plugins/addrepo", {repoURL: repoURL},
|
||||
"/admin/plugins/addrepo", {repoURL: repoURL, repoName: repoName},
|
||||
function(response) {
|
||||
$('#chat-rotator').spin(false);
|
||||
if (response.success) {
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
<p class="descriptive-text">{{$desc}}</p>
|
||||
{{include file="field_input.tpl" field=$repoURL}}
|
||||
{{include file="field_input.tpl" field=$repoName}}
|
||||
<div class="btn-group pull-right">
|
||||
<button id="add-plugin-repo-submit" class="btn btn-primary" type="submit" name="submit" onclick="adminPluginsAddRepo(); return false;">{{$submit}}</button>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user