aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Module/Admin.php34
-rw-r--r--Zotlabs/Storage/GitRepo.php55
2 files changed, 69 insertions, 20 deletions
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index b4c372f84..c068110a9 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -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')
)
);
@@ -1708,12 +1709,37 @@ class Admin extends \Zotlabs\Web\Controller {
case 'addrepo':
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']);
+ require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies
$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')) {
diff --git a/Zotlabs/Storage/GitRepo.php b/Zotlabs/Storage/GitRepo.php
index de5dd3b19..81356950b 100644
--- a/Zotlabs/Storage/GitRepo.php
+++ b/Zotlabs/Storage/GitRepo.php
@@ -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;