1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Stephan Dekker <Stephan@SparklingSoftware.com.au>
5 */
6
7if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
8require_once DOKU_PLUGIN.'action.php';
9require_once(DOKU_PLUGIN.'git/lib/Git.php');
10
11
12class action_plugin_git_commit extends DokuWiki_Action_Plugin {
13
14    var $helper = null;
15
16    function action_plugin_git_commit(){
17        $this->helper =& plugin_load('helper', 'git');
18        if (is_null($this->helper)) {
19            msg('The GIT plugin could not load its helper class', -1);
20            return false;
21        }
22    }
23
24	function register(&$controller) {
25		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_handle');
26    }
27
28	function _handle(&$event, $param) {
29
30        if ($_REQUEST['cmd'] === null) return;
31
32        $commit_message = trim($_POST['CommitMessage']);
33
34        // verify valid values
35        switch (key($_REQUEST['cmd'])) {
36            case 'commit_current' :
37                if ($this->commit($commit_message) === false) return;
38                break;
39            case 'commit_submit' :
40                $this->helper->submittChangesForApproval();
41                break;
42        }
43  	}
44
45    function commit($commit_message)
46    {
47        try
48        {
49            global $conf;
50            $this->getConf('');
51
52            $git_exe_path = $conf['plugin']['git']['git_exe_path'];
53            $datapath = $conf['savedir'];
54
55            $repo = new GitRepo($datapath);
56            $repo->git_path = $git_exe_path;
57            $result = $repo->commit($commit_message);
58
59            $this->helper->resetGitStatusCache('local');
60
61            return true;
62        }
63        catch(Exception $e)
64        {
65            msg($e->getMessage());
66            return false;
67        }
68    }
69
70}