diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index 4928b63f..7e30d50f 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -245,7 +245,7 @@ class Code extends Controller } } - protected function _edit ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD, $caller = 'file') + private function _edit ($projectid = '', $path = '', $rev = SVN_REVISION_HEAD, $caller = 'file') { $this->load->model ('ProjectModel', 'projects'); $this->load->model ('SubversionModel', 'subversion'); @@ -601,6 +601,266 @@ class Code extends Controller print $status; } + function xhr_edit_revision_message ($projectid = '', $rev = SVN_REVISOIN_HEAD) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "error - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "error - no such project {$projectid}"; + } + else if (!$login['sysadmin?'] && + $this->projects->projectHasMember($projectid, $login['id']) === FALSE) + { + $status = "error - not a member {$login['id']}"; + } + else if ($login['id'] != $this->subversion->getRevProp($projectid, $rev, 'svn:author')) + { + $status = "error - not authored by {$login['id']}"; + } + else + { + $logmsg = $this->input->post('code_edit_revision_message'); + if ($logmsg != $this->subversion->getRevProp ($projectid, $rev, 'svn:log')) + { + $affected_rev = $this->subversion->setRevProp ( + $projectid, $rev, 'svn:log', $logmsg, $login['id']); + if ($affected_rev === FALSE) + { + $status = 'error - ' . $this->subversion->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + else + { + $status = 'ok'; + } + } + } + + print $status; + } + + function xhr_edit_revision_tag ($projectid = '', $rev = SVN_REVISOIN_HEAD) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "error - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "error - no such project {$projectid}"; + } + else if (!$login['sysadmin?'] && + $this->projects->projectHasMember($projectid, $login['id']) === FALSE) + { + $status = "error - not a member {$login['id']}"; + } + //else if ($login['id'] != $this->subversion->getRevProp($projectid, $rev, 'svn:author')) + //{ + // $status = "error - not authored by {$login['id']}"; + //} + else + { + $tag = $this->input->post('code_edit_revision_tag'); + $tag = ($tag === FALSE)? '': trim($tag); + if (empty($tag)) + { + // delete the tag if the value is empty + $affected_rev = $this->subversion->killRevProp ( + $projectid, $rev, CODEPOT_SVN_TAG_PROPERTY, $login['id']); + } + else + { + $affected_rev = $this->subversion->setRevProp ( + $projectid, $rev, CODEPOT_SVN_TAG_PROPERTY, $tag, $login['id']); + } + + if ($affected_rev === FALSE) + { + $status = 'error - ' . $this->subversion->getErrorMessage(); + } + else + { + $status = 'ok'; + } + } + } + + print $status; + } + + function xhr_new_review_comment ($projectid = '', $rev = SVN_REVISOIN_HEAD) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + $this->load->model ('CodeReviewModel', 'code_review'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "error - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "error - no such project {$projectid}"; + } + else if (!$login['sysadmin?'] && + $this->projects->projectHasMember($projectid, $login['id']) === FALSE) + { + $status = "error - not a member {$login['id']}"; + } + else + { + $review_comment = $this->input->post('code_new_review_comment'); + if ($review_comment === FALSE || ($review_comment = trim($review_comment)) == '') + { + $status = 'error - emtpy review comment'; + } + else + { + $review_sno = $this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment); + if ($review_sno === FALSE) + { + $status = 'error - ' . $this->code_review->getErrorMessage(); + } + else + { + $status = 'ok'; + + if (CODEPOT_COMMIT_REVIEW_NOTIFICATION) + { + // TODO: message localization + $email_subject = sprintf ( + 'New review message #%d for r%d by %s in %s', + $review_sno, $rev, $login['id'], $projectid + ); + $email_message = current_url() . "\r\n" . $review_comment; + $this->projects->emailMessageToMembers ( + $projectid, $this->login, $email_subject, $email_message + ); + } + } + } + } + } + + print $status; + } + + function xhr_edit_review_comment ($projectid = '', $rev = SVN_REVISOIN_HEAD) + { + $this->load->model ('ProjectModel', 'projects'); + $this->load->model ('SubversionModel', 'subversion'); + $this->load->model ('CodeReviewModel', 'code_review'); + + $login = $this->login->getUser (); + $revision_saved = -1; + + if ($login['id'] == '') + { + $status = 'error - anonymous user'; + } + else + { + $project = $this->projects->get ($projectid); + if ($project === FALSE) + { + $status = "error - failed to get the project {$projectid}"; + } + else if ($project === NULL) + { + $status = "error - no such project {$projectid}"; + } + else if (!$login['sysadmin?'] && + $this->projects->projectHasMember($projectid, $login['id']) === FALSE) + { + $status = "error - not a member {$login['id']}"; + } + else + { + $review_no = $this->input->post('code_edit_review_no'); + $review_comment = $this->input->post('code_edit_review_comment'); + + if ($review_no === FALSE || !is_numeric($review_no)) + { + $status = 'error - wrong review number'; + } + else if ($review_comment === FALSE || ($review_comment = trim($review_comment)) == '') + { + $status = 'error - empty review comment'; + } + else + { + if ($this->code_review->updateReview ($projectid, $rev, (integer)$review_no, $login['id'], $review_comment, TRUE) === FALSE) + { + $status = 'error - ' . $this->code_review->getErrorMessage(); + } + else + { + $status = 'ok'; + /* + if (CODEPOT_COMMIT_REVIEW_NOTIFICATION) + { + // TODO: message localization + $email_subject = sprintf ( + 'Edited review message #%d for r%d by %s in %s', + $review_sno, $rev, $login['id'], $projectid + ); + $email_message = current_url() . "\r\n" . $review_comment; + $this->projects->emailMessageToMembers ( + $projectid, $this->login, $email_subject, $email_message + ); + }*/ + } + } + } + } + + print $status; + } + + function enjson_save ($projectid = '', $path = '') { $this->load->model ('ProjectModel', 'projects'); @@ -771,147 +1031,6 @@ class Code extends Controller redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); } - $data['popup_error_message'] = ''; - if ($login['id'] != '') - { - $tag = $this->input->post('tag_revision'); - if ($tag !== FALSE) - { - $tag = trim($tag); - if (empty($tag)) - { - // delete the tag if the value is empty - $affected_rev = $this->subversion->killRevProp ( - $projectid, $rev, CODEPOT_SVN_TAG_PROPERTY, $login['id']); - } - else - { - $affected_rev = $this->subversion->setRevProp ( - $projectid, $rev, CODEPOT_SVN_TAG_PROPERTY, $tag, $login['id']); - } - if ($affected_rev === FALSE) - { - $data['popup_error_message'] = 'Cannot tag revision'; - } - else - { - $this->form_validation->_field_data = array(); - } - } - else if ($login['id'] == $this->subversion->getRevProp($projectid, $rev, 'svn:author') && - $this->input->post('edit_log_message')) - { - // the current user must be the author of the revision to be able to - // change the log message. - $this->load->helper ('form'); - $this->load->library ('form_validation'); - - $this->form_validation->set_rules ('edit_log_message', 'Message', 'required|min_length[2]'); - $this->form_validation->set_error_delimiters('',''); - - if ($this->form_validation->run()) - { - $logmsg = $this->input->post('edit_log_message'); - if ($logmsg != $this->subversion->getRevProp ($projectid, $rev, 'svn:log')) - { - $affected_rev = $this->subversion->setRevProp ( - $projectid, $rev, 'svn:log', $logmsg, $login['id']); - if ($affected_rev === FALSE) - { - $data['popup_error_message'] = 'Cannot change revision log message'; - } - else - { - $this->form_validation->_field_data = array(); - } - } - } - else - { - $data['popup_error_message'] = 'Invalid revision log message'; - } - } - else if ($this->input->post('new_review_comment')) - { - $this->load->helper ('form'); - $this->load->library ('form_validation'); - - $this->form_validation->set_rules ('new_review_comment', $this->lang->line('Comment'), 'required|min_length[10]'); - $this->form_validation->set_error_delimiters('',''); - - if ($this->form_validation->run()) - { - $review_comment = $this->input->post('new_review_comment'); - $review_sno = $this->code_review->insertReview ($projectid, $rev, $login['id'], $review_comment); - if ($review_sno === FALSE) - { - $data['popup_error_message'] = 'Cannot add code review comment'; - } - else - { - // this is a hack to clear form data upon success - $this->form_validation->_field_data = array(); - - if (CODEPOT_COMMIT_REVIEW_NOTIFICATION) - { - // TODO: message localization - $email_subject = sprintf ( - 'New review message #%d for r%d by %s in %s', - $review_sno, $rev, $login['id'], $projectid - ); - $email_message = current_url() . "\r\n" . $review_comment; - $this->projects->emailMessageToMembers ( - $projectid, $this->login, $email_subject, $email_message - ); - } - } - } - else - { - $data['popup_error_message'] = 'Invalid review comment'; - } - } - else if ($this->input->post('edit_review_comment_no')) - { - $this->load->helper ('form'); - $this->load->library ('form_validation'); - - // get the comment number without validation. - $comment_no = $this->input->post('edit_review_comment_no'); - if (is_numeric($comment_no)) - { - $comment_field_name = "edit_review_comment_{$comment_no}"; - $this->form_validation->set_rules ($comment_field_name, $this->lang->line('Comment'), 'required|min_length[10]'); - $this->form_validation->set_error_delimiters('',''); - - if ($this->form_validation->run()) - { - // - // TODO: should let sysadmin? to change comments??? - // - $review_comment = $this->input->post($comment_field_name); - if ($this->code_review->updateReview ($projectid, $rev, (integer)$comment_no, $login['id'], $review_comment, TRUE) === FALSE) - { - $data['popup_error_message'] = 'Cannot edit code review comment'; - } - else - { - // this is a hack to clear form data upon success - $this->form_validation->_field_data = array(); - } - } - else - { - $data['popup_error_message'] = 'Invalid review comment'; - } - } - else - { - $data['popup_error_message'] = 'Invalid review comment number'; - } - } - } - $file = $this->subversion->getRevHistory ($projectid, $path, $rev); if ($file === FALSE) { @@ -988,9 +1107,9 @@ class Code extends Controller $prev_props = $p; } } - - $chg['props'] = $props; - $chg['prev_props'] = $prev_props; + + $chg['props'] = $props; + $chg['prev_props'] = $prev_props; //print_r ($props); //print_r ($prev_props); @@ -1016,7 +1135,7 @@ class Code extends Controller } } - function _do_diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD, $full = FALSE) + private function _do_diff ($projectid = '', $path = '', $rev1 = SVN_REVISION_HEAD, $rev2 = SVN_REVISION_HEAD, $full = FALSE) { $this->load->model ('ProjectModel', 'projects'); $this->load->model ('SubversionModel', 'subversion'); @@ -1208,7 +1327,7 @@ class Code extends Controller } } - function _search_code ($project, $login) + private function _search_code ($project, $login) { $this->load->helper ('form'); $this->load->library ('form_validation'); @@ -1306,7 +1425,7 @@ class Code extends Controller } } - function _normalize_path ($path) + private function _normalize_path ($path) { $path = preg_replace('/[\/]+/', '/', $path); if ($path == '/') $path = ''; diff --git a/codepot/src/codepot/models/codereviewmodel.php b/codepot/src/codepot/models/codereviewmodel.php index 9ac07e93..66e6527e 100644 --- a/codepot/src/codepot/models/codereviewmodel.php +++ b/codepot/src/codepot/models/codereviewmodel.php @@ -2,6 +2,13 @@ class CodeReviewModel extends Model { + protected $errmsg = ''; + + function getErrorMessage () + { + return $this->errmsg; + } + function CodeReviewModel () { parent::Model (); @@ -10,28 +17,27 @@ class CodeReviewModel extends Model function getReviews ($projectid, $revision) { - $this->db->trans_start (); + $this->db->trans_begin (); $this->db->where ('projectid', (string)$projectid); $this->db->where ('rev', $revision); $query = $this->db->get ('code_review'); - if ($this->db->trans_status() === FALSE) + if ($this->db->trans_status() === FALSE) { - $this->db->trans_complete (); + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); return FALSE; } $result = $query->result (); - $this->db->trans_complete (); - if ($this->db->trans_status() === FALSE) return FALSE; - + $this->db->trans_commit (); return $result; } function insertReview ($projectid, $revision, $userid, $comment) { // TODO: check if userid can do this.. - $this->db->trans_start (); + $this->db->trans_begin (); $this->db->where ('projectid', $projectid); $this->db->where ('rev', $revision); @@ -39,7 +45,8 @@ class CodeReviewModel extends Model $query = $this->db->get ('code_review'); if ($this->db->trans_status() === FALSE) { - $this->db->trans_complete (); + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); return FALSE; } @@ -57,25 +64,34 @@ class CodeReviewModel extends Model $this->db->set ('createdby', $userid); $this->db->set ('updatedby', $userid); $this->db->insert ('code_review'); - - /*$this->db->set ('createdon', date('Y-m-d H:i:s')); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } + /*$this->db->set ('createdon', date('Y-m-d H:i:s')); $this->db->set ('type', 'code_review'); $this->db->set ('action', 'insert'); $this->db->set ('projectid', $projectid); $this->db->set ('userid', $userid); $this->db->set ('message', "$rev,$sno"); - $this->db->insert ('log');*/ - - $this->db->trans_complete (); - if ($this->db->trans_status() === FALSE) return FALSE; + $this->db->insert ('log'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + }*/ + $this->db->trans_commit (); return $newsno; } function updateReview ($projectid, $revision, $sno, $userid, $comment, $strict = FALSE) { // TODO: check if userid can do this.. - $this->db->trans_start (); + $this->db->trans_begin (); $this->db->where ('projectid', $projectid); $this->db->where ('rev', $revision); @@ -85,39 +101,63 @@ class CodeReviewModel extends Model $this->db->set ('updatedon', date('Y-m-d H:i:s')); $this->db->set ('updatedby', $userid); $this->db->update ('code_review'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } - /*$this->db->set ('createdon', date('Y-m-d H:i:s')); + /*$this->db->set ('createdon', date('Y-m-d H:i:s')); $this->db->set ('type', 'code_review'); $this->db->set ('action', 'insert'); $this->db->set ('projectid', $projectid); $this->db->set ('userid', $userid); $this->db->set ('message', "$rev,$sno"); - $this->db->insert ('log');*/ + $this->db->insert ('log'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + }*/ - $this->db->trans_complete (); - return $this->db->trans_status(); + $this->db->trans_commit (); + return TRUE; } function deleteReview ($projectid, $revision, $sno, $userid) { // TODO: check if userid can do this.. - $this->db->trans_start (); + $this->db->trans_begin(); $this->db->where ('projectid', $projectid); $this->db->where ('rev', $revision); $this->db->where ('sno', $sno); $this->db->delete ('code_review'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } - /*$this->db->set ('createdon', date('Y-m-d H:i:s')); + /*$this->db->set ('createdon', date('Y-m-d H:i:s')); $this->db->set ('type', 'issue'); $this->db->set ('action', 'delete'); $this->db->set ('projectid', $projectid); $this->db->set ('userid', $userid); $this->db->set ('message', "$rev,$sno"); - $this->db->insert ('log');*/ + $this->db->insert ('log'); + if ($this->db->trans_status() === FALSE) + { + $this->errmsg = $this->db->_error_message(); + $this->db->trans_rollback (); + return FALSE; + } */ - $this->db->trans_complete (); - return $this->db->trans_status(); + $this->db->trans_commit (); + return TRUE; } } diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index 51d05ded..30fc2a15 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -19,7 +19,7 @@ class SubversionModel extends Model parent::Model (); } - function _canonical_path($path) + private function _canonical_path($path) { $canonical = preg_replace('|/\.?(?=/)|','',$path); while (($collapsed = preg_replace('|/[^/]+/\.\./|','/',$canonical,1)) !== $canonical) @@ -1231,19 +1231,26 @@ class SubversionModel extends Model function getRevProp ($projectid, $rev, $prop) { $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); - return @svn_revprop_get ($url, $rev, $prop); + + set_error_handler (array ($this, 'capture_error')); + $result = @svn_revprop_get ($url, $rev, $prop); + restore_error_handler (); + return $result; } function setRevProp ($projectid, $rev, $prop, $propval, $user) { $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); + set_error_handler (array ($this, 'capture_error')); + $orguser = @svn_auth_get_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME); @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $user); $result = @svn_revprop_set ($url, $rev, $prop, $propval); - @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $orguser); + + restore_error_handler (); return $result; } @@ -1251,12 +1258,16 @@ class SubversionModel extends Model { $url = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}"); + set_error_handler (array ($this, 'capture_error')); + $orguser = @svn_auth_get_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME); @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $user); $result = @svn_revprop_delete ($url, $rev, $prop); @svn_auth_set_parameter (SVN_AUTH_PARAM_DEFAULT_USERNAME, $orguser); + + restore_error_handler (); return $result; } @@ -1315,7 +1326,9 @@ class SubversionModel extends Model $orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); $workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention + set_error_handler (array ($this, 'capture_error')); $info = @svn_info ($workurl, FALSE, $rev); + restore_error_handler (); if ($info === FALSE || count($info) != 1) { @@ -1323,11 +1336,16 @@ class SubversionModel extends Model // rebuild the URL with a peg revision and retry it. $workurl = "{$orgurl}@{$rev}"; + set_error_handler (array ($this, 'capture_error')); $info = @svn_info ($workurl, FALSE, $rev); + restore_error_handler (); if ($info === FALSE || count($info) != 1) return FALSE; } - return @svn_proplist ($workurl, 0, $rev); + set_error_handler (array ($this, 'capture_error')); + $result = @svn_proplist ($workurl, 0, $rev); + restore_error_handler (); + return $result; } function getProp ($projectid, $path, $rev, $prop) @@ -1335,7 +1353,9 @@ class SubversionModel extends Model $orgurl = 'file://'.$this->_canonical_path(CODEPOT_SVNREPO_DIR."/{$projectid}/{$path}"); $workurl = ($path == '')? $orgurl: "{$orgurl}@"; // trailing @ for collision prevention + set_error_handler (array ($this, 'capture_error')); $info = @svn_info ($workurl, FALSE, $rev); + restore_error_handler (); if ($info === FALSE || count($info) != 1) { @@ -1343,11 +1363,16 @@ class SubversionModel extends Model // rebuild the URL with a peg revision and retry it. $workurl = "{$orgurl}@{$rev}"; + set_error_handler (array ($this, 'capture_error')); $info = @svn_info ($workurl, FALSE, $rev); + restore_error_handler (); if ($info === FALSE || count($info) != 1) return FALSE; } - return @svn_propget ($workurl, $prop, FALSE, $rev); + set_error_handler (array ($this, 'capture_error')); + $result = @svn_propget ($workurl, $prop, FALSE, $rev); + restore_error_handler (); + return $result; } function _cloc_revision_by_lang ($projectid, $path, $rev) diff --git a/codepot/src/codepot/views/code_file.php b/codepot/src/codepot/views/code_file.php index 29208a44..5db2ef38 100644 --- a/codepot/src/codepot/views/code_file.php +++ b/codepot/src/codepot/views/code_file.php @@ -221,7 +221,8 @@ $this->load->view ( // anchor to the revision history at the root directory print anchor ( - "code/revision/{$project->id}/!/{$file['created_rev']}", + //"code/revision/{$project->id}/!/{$file['created_rev']}", + "code/revision/{$project->id}/${xpar}/{$file['created_rev']}", sprintf("%s %s", $this->lang->line('Revision'), $file['created_rev']) ); diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index 844e0855..c27f0577 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -848,7 +848,8 @@ $this->load->view ( // anchor to the revision history at the root directory print anchor ( - "code/revision/{$project->id}/!/{$file['created_rev']}", + //"code/revision/{$project->id}/!/{$file['created_rev']}", + "code/revision/{$project->id}/${hex_headpath}/{$file['created_rev']}", sprintf("%s %s", $this->lang->line('Revision'), $file['created_rev']) ); diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index d33c6fb7..76b2a036 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -21,6 +21,23 @@ +converter->AsciiToHex ('.') . $revreq; + } + + $hex_headpath = $this->converter->AsciiToHex(($headpath == '')? '.': $headpath); + $creole_base = site_url() . "/wiki/show/{$project->id}/"; + $creole_file_base = site_url() . "/wiki/attachment0/{$project->id}/"; +?> + @@ -280,17 +557,6 @@ $history = $file['history'];
+- {$comment_label}
+ - {$preview_label}
+
+ +