aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-05-29 10:18:26 -0400
committerAndrew Manning <tamanning@zoho.com>2016-05-29 10:18:26 -0400
commit63a97ff6fc313372d9cb439a621f12fdecc2fac1 (patch)
treeb77b9e3133def566a34530727a64d3915b2d2aec /include
parentab54bf514921ae3fe0fafcdf154364815ed6375f (diff)
downloadvolse-hubzilla-63a97ff6fc313372d9cb439a621f12fdecc2fac1.tar.gz
volse-hubzilla-63a97ff6fc313372d9cb439a621f12fdecc2fac1.tar.bz2
volse-hubzilla-63a97ff6fc313372d9cb439a621f12fdecc2fac1.zip
Git commit made for the page edits when the page is saved.
Diffstat (limited to 'include')
-rw-r--r--include/wiki.php43
1 files changed, 40 insertions, 3 deletions
diff --git a/include/wiki.php b/include/wiki.php
index e01cc12c3..915478da5 100644
--- a/include/wiki.php
+++ b/include/wiki.php
@@ -251,7 +251,44 @@ function wiki_save_page($arr) {
return array('message' => '', 'success' => true);
} 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);
}
-
-
-} \ No newline at end of file
+ $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));
+ }
+}