/** * Associate user with the project. Owner is automatically assigned by newProject calling this method. * This method also creates the git repository and assigns basic configuration */ public function joinProject($pid) { if ($this->_uid == false) { throw new Exception(NO_USER); } $data = array('pid' => $pid, 'uid' => $this->_uid); $result = $this->_db->insert('user_project', $data); //returns the number of rows inserted if ($result == 1) { //select the project as the active project once the required db entry exists $this->selectProject($pid); $git = new Git(); if ($this->active->owner == $this->_uid) { if (file_exists($this->getPath() . $this->_userPath)) { throw new Exception('User directory in project folder already exists'); } if (!mkdir($this->getPath() . $this->_userPath)) { throw new Exception('Unable to create a user directory in the project folder'); } //===== GIT INIT ===== $git->initRepo($this->_userName, $this->_userEmail); } else { //clone should crete the user directory as it is required to clone to new dir //===== GIT CLONE ===== $git->cloneRepo($this->_userName, $this->_userEmail, $this->active->owner, $this->_uid); } } }
} break; case 'init': if (isset($_GET['path'])) { if ($git->init(getWorkspacePath($_GET['path']))) { echo '{"status":"success","message":"Initialized empty Git repository!"}'; } else { echo '{"status":"error","message":"' . $git->result . '!"}'; } } else { echo '{"status":"error","message":"Missing parameter!"}'; } break; case 'clone': if (isset($_GET['path']) && isset($_GET['repo'])) { echo $git->cloneRepo(getWorkspacePath($_GET['path']), $_GET['repo']); } else { echo '{"status":"error","message":"Missing parameter!"}'; } break; case 'status': if (isset($_GET['path'])) { $result = $git->status(getWorkspacePath($_GET['path'])); if ($result === false) { echo '{"status":"error","message":"Failed to get status!"}'; } else { echo '{"status":"success","data":' . json_encode($result) . '}'; } } else { echo '{"status":"error","message":"Missing parameter!"}'; }