Git commit made for the page edits when the page is saved.
This commit is contained in:
parent
ab54bf5149
commit
63a97ff6fc
@ -268,9 +268,20 @@ class Wiki extends \Zotlabs\Web\Controller {
|
||||
}
|
||||
$saved = wiki_save_page(array('resource_id' => $resource_id, 'name' => $pagename, 'content' => $content));
|
||||
if($saved['success']) {
|
||||
json_return_and_die(array('success' => true));
|
||||
$ob = \App::get_observer();
|
||||
$commit = wiki_git_commit(array(
|
||||
'commit_msg' => 'Updated ' . $pagename,
|
||||
'resource_id' => $resource_id,
|
||||
'observer' => $ob,
|
||||
'files' => array($pagename)
|
||||
));
|
||||
if($commit['success']) {
|
||||
json_return_and_die(array('message' => 'Wiki git repo commit made', 'success' => true));
|
||||
} else {
|
||||
json_return_and_die(array('message' => 'Error making git commit','success' => false));
|
||||
}
|
||||
} else {
|
||||
json_return_and_die(array('success' => false));
|
||||
json_return_and_die(array('message' => 'Error saving page', 'success' => false));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,6 +128,15 @@ class GitRepo {
|
||||
return $repo;
|
||||
}
|
||||
|
||||
// Commit changes to the repo. Default is to stage all changes and commit everything.
|
||||
public function commit($msg, $options = array()) {
|
||||
try {
|
||||
return $this->git->commit($msg, $options);
|
||||
} catch (\PHPGit\Exception\GitException $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function isValidGitRepoURL($url) {
|
||||
if (validate_url($url) && strrpos(parse_url($url, PHP_URL_PATH), '.')) {
|
||||
return true;
|
||||
|
@ -252,6 +252,43 @@ function wiki_save_page($arr) {
|
||||
} else {
|
||||
return array('message' => 'Page file not writable', 'success' => false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function wiki_git_commit($arr) {
|
||||
$files = ((array_key_exists('files', $arr)) ? $arr['files'] : null);
|
||||
$commit_msg = ((array_key_exists('commit_msg', $arr)) ? $arr['commit_msg'] : 'Repo updated');
|
||||
$resource_id = ((array_key_exists('resource_id', $arr)) ? $arr['resource_id'] : json_return_and_die(array('message' => 'Wiki resource_id required for git commit', 'success' => false)));
|
||||
$observer = ((array_key_exists('observer', $arr)) ? $arr['observer'] : json_return_and_die(array('message' => 'Observer required for git commit', 'success' => false)));
|
||||
$w = wiki_get_wiki($resource_id);
|
||||
if (!$w['path']) {
|
||||
return array('message' => 'Error reading wiki', 'success' => false);
|
||||
}
|
||||
$reponame = ((array_key_exists('title', $w['wiki'])) ? $w['wiki']['title'] : 'repo');
|
||||
if($reponame === '') {
|
||||
$reponame = 'repo';
|
||||
}
|
||||
$git = new GitRepo('sys', null, false, $w['wiki']['title'], $w['path']);
|
||||
try {
|
||||
$git->setIdentity($observer['xchan_name'], $observer['xchan_addr']);
|
||||
if ($files === null) {
|
||||
$options = array('all' => true); // git commit option to include all changes
|
||||
} else {
|
||||
$options = array(); // git commit options
|
||||
foreach ($files as $file) {
|
||||
if (!$git->git->add($file)) { // add specified files to the git repo stage
|
||||
if (!$git->git->reset->hard()) {
|
||||
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file . '. Error resetting git repo.', 'success' => false));
|
||||
}
|
||||
json_return_and_die(array('message' => 'Error adding file to git stage: ' . $file, 'success' => false));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($git->commit($commit_msg, $options)) {
|
||||
json_return_and_die(array('message' => 'Wiki repo commit succeeded', 'success' => true));
|
||||
} else {
|
||||
json_return_and_die(array('message' => 'Wiki repo commit failed', 'success' => false));
|
||||
}
|
||||
} catch (\PHPGit\Exception\GitException $e) {
|
||||
json_return_and_die(array('message' => 'GitRepo error thrown', 'success' => false));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user