@@ -30,6 +30,15 @@ public function register(Doku_Event_Handler $controller) {
3030 $ controller ->register_hook ('DOKUWIKI_DONE ' , 'AFTER ' , $ this , 'handle_periodic_pull ' );
3131 }
3232
33+ /**
34+ * Create a GitRepo class instance according to this plugins config.
35+ * If auto determination of git rpos is configured, this method will return null,
36+ * if there is no git repo found.
37+ *
38+ * @access private
39+ * @param string path to the file or directory to be commited (required for auto determination only)
40+ * @return GitRepo instance or null if there is no repo related to fileOrDirPath
41+ */
3342 private function initRepo ($ fileOrDirPath ="" ) {
3443 //set the path to the git binary
3544 $ gitPath = trim ($ this ->getConf ('gitPath ' ));
@@ -39,22 +48,24 @@ private function initRepo($fileOrDirPath="") {
3948
4049 $ isAutoDetermineRepos = $ this ->getConf ('autoDetermineRepos ' );
4150 if ($ isAutoDetermineRepos ) {
51+ if (empty ($ fileOrDirPath )) {
52+ return null ;
53+ }
4254 $ repoPath = is_dir ($ fileOrDirPath ) ? $ fileOrDirPath : dirname ($ fileOrDirPath );
4355 $ repo = new GitRepo ($ repoPath , $ this , false , false );
4456 $ repoPath = $ repo ->get_repo_path ();
57+ if (empty ($ repoPath )) {
58+ return null ;
59+ }
4560 $ repoWorkDir = '' ;
4661 } else {
4762 //get path to the repo root (by default DokuWiki's savedir)
4863 $ repoPath = GitBackedUtil::getEffectivePath ($ this ->getConf ('repoPath ' ));
4964 //init the repo and create a new one if it is not present
5065 io_mkdir_p ($ repoPath );
5166 $ repo = new GitRepo ($ repoPath , $ this , true , true );
52- }
53- //set git working directory (by default DokuWiki's savedir)
54- if ($ isAutoDetermineRepos ) {
55- $ repoWorkDir = '' ;
56- } else {
57- $ repoWorkDir = $ this ->getConf ('repoWorkDir ' );
67+ //set git working directory (by default DokuWiki's savedir)
68+ $ repoWorkDir = trim ($ this ->getConf ('repoWorkDir ' ));
5869 if (!empty ($ repoWorkDir )) {
5970 $ repoWorkDir = GitBackedUtil::getEffectivePath ($ repoWorkDir );
6071 }
@@ -90,7 +101,9 @@ private function commitFile($filePath,$message) {
90101 if (!$ this ->isIgnored ($ filePath )) {
91102 try {
92103 $ repo = $ this ->initRepo ($ filePath );
93-
104+ if (is_null ($ repo )) {
105+ return ;
106+ }
94107 //add the changed file and set the commit message
95108 $ repo ->add ($ filePath );
96109 $ repo ->commit ($ message );
@@ -131,17 +144,19 @@ public function handle_periodic_pull(Doku_Event &$event, $param) {
131144
132145 //if it is time to run a pull request
133146 if ($ lastPull +$ timeToWait < $ now ) {
134- try {
135- $ repo = $ this ->initRepo ();
136-
137- //execute the pull request
138- $ repo ->pull ('origin ' ,$ repo ->active_branch ());
139- } catch (Exception $ e ) {
140- if (!$ this ->isNotifyByEmailOnGitCommandError ()) {
141- throw new Exception ('Git command failed to perform periodic pull: ' .$ e ->getMessage (), 2 , $ e );
142- }
143- return ;
144- }
147+ try {
148+ $ repo = $ this ->initRepo ();
149+ if (is_null ($ repo )) {
150+ return ;
151+ }
152+ //execute the pull request
153+ $ repo ->pull ('origin ' ,$ repo ->active_branch ());
154+ } catch (Exception $ e ) {
155+ if (!$ this ->isNotifyByEmailOnGitCommandError ()) {
156+ throw new Exception ('Git command failed to perform periodic pull: ' .$ e ->getMessage (), 2 , $ e );
157+ }
158+ return ;
159+ }
145160
146161 //save the current time to the file to track the last pull execution
147162 file_put_contents ($ lastPullFile ,serialize (time ()));
0 commit comments