Beispiel #1
0
function ArchiveCreate($Date, $DateMessage, $db, $Use, $BranchName)
{
    global $freshports_CommitMsgMaxNumOfLinesToShow;
    $commits = new Commits($db);
    $commits->SetBranch($BranchName);
    $NumRows = $commits->Fetch($Date, $User->id);
    #echo '<br>NumRows = ' . $NumRows;
    $HTML = '';
    if ($NumRows == 0) {
        $HTML .= '<TR><TD COLSPAN="3" BGCOLOR="' . BACKGROUND_COLOUR . '" HEIGHT="0">' . "\n";
        $HTML .= '   <FONT COLOR="#FFFFFF"><BIG>' . FormatTime($Date, 0, "D, j M Y") . '</BIG></FONT>' . "\n";
        $HTML .= '</TD></TR>' . "\n\n";
        $HTML .= '<TR><TD>No commits found for that date</TD></TR>';
    }
    unset($ThisCommitLogID);
    require_once $_SERVER['DOCUMENT_ROOT'] . '/../classes/display_commit.php';
    $DisplayCommit = new DisplayCommit($db, $commits->LocalResult);
    $DisplayCommit->SanityTestFailure = true;
    $RetVal = $DisplayCommit->CreateHTML();
    $HTML = $DisplayCommit->HTML;
    return $HTML;
}
 /**
  * View the repository
  *
  */
 function view()
 {
     if ($this->active_repository->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->addBreadcrumb(str_excerpt(clean($this->active_repository->getName()), 10), mobile_access_module_get_view_url($this->active_repository));
     $this->addBreadcrumb(lang('View'));
     $per_page = 20;
     $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1;
     list($commits, $pagination) = Commits::paginateByRepository($this->active_repository, $page, $per_page);
     $commits = group_by_date($commits);
     $this->smarty->assign(array('pagination' => $pagination, 'commits' => $commits, 'pagination_url' => assemble_url('mobile_access_view_repository', array('object_id' => $this->active_repository->getId(), 'project_id' => $this->active_project->getId())), 'page_back_url' => assemble_url('mobile_access_view_project', array('project_id' => $this->active_project->getId()))));
 }
 /**
  * Get all commits related to a project object
  *
  * @param integer $object_id
  * @return array
  */
 function findCommitsByObject($object)
 {
     $parent_object_ids = array();
     $parent_object_ids[] = $object->getId();
     /**
      * Try to find commits related to children objects
      */
     $task_ids = array();
     if (instance_of($object, 'Ticket')) {
         $tasks = db_execute_all("SELECT id FROM " . TABLE_PREFIX . "project_objects WHERE parent_id = " . $object->getid() . " AND `type` = 'Task'");
         if (is_foreachable($tasks)) {
             foreach ($tasks as $task) {
                 $task_ids[] = $task['id'];
             }
             // foreach
         }
         // if
     }
     // if
     $objects_ids = array_merge($parent_object_ids, $task_ids);
     $commit_project_objects = CommitProjectObjects::find(array('conditions' => array("object_id IN(" . implode(',', $objects_ids) . ")"), 'order' => 'repository_id ASC, revision DESC'));
     if (is_foreachable($commit_project_objects)) {
         $commits = array();
         $revisions = array();
         foreach ($commit_project_objects as $commit_project_object) {
             if (!in_array($commit_project_object->getRevision(), $revisions)) {
                 // prevent commits from showing more than once
                 $revisions[] = $commit_project_object->getRevision();
                 $commit = Commits::findByRevision($commit_project_object->getRevision(), Repositories::findById($commit_project_object->getRepositoryId()));
                 if (instance_of($commit, 'Commit')) {
                     $commit->repository = Repositories::findById($commit->getProjectId());
                     $commits[] = $commit;
                 }
                 // if
             }
             // if
         }
         // foreach
         return group_by_date($commits);
     } else {
         return false;
     }
     // if
 }
 /**
  * Compare two revisions of a file
  *
  * @param null
  * @return void
  */
 function compare()
 {
     if (!$this->active_repository->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     // wireframe
     $this->wireframe->addPageAction(lang('Commit history'), $this->active_repository->getHistoryUrl());
     $compare_to = $this->request->get('compare_to');
     $compared = Commits::findByRevision($compare_to, $this->active_repository);
     if (!instance_of($compared, 'Commit')) {
         flash_error('Revision does not exist');
         $this->redirectToReferer($this->active_repository->getFileHistoryUrl($this->active_revision, $this->active_file, $this->request->get('peg')));
     }
     // if
     // path info
     $path_info = $this->repository_engine->getInfo($this->active_file, $this->active_revision, false, $this->request->get('peg'));
     $latest_revision = $path_info['revision'];
     $file_latest_revision = Commits::findByRevision($latest_revision, $this->active_repository);
     if (!instance_of($file_latest_revision, 'Commit')) {
         $file_latest_revision = $this->active_commit;
     }
     // if
     $diff_data = $this->repository_engine->compareToRevision($this->active_file, $compared->getRevision(), $this->active_revision, $this->request->get('peg'));
     $diff_changes = $this->repository_engine->parseDiff($diff_data);
     $this->smarty->assign(array('compared' => $compared, 'diff' => $diff_changes, 'navigation' => $this->repository_engine->linkify($this->active_revision, $this->active_file), 'latest_revision' => $file_latest_revision));
     js_assign('compare_url', $this->active_repository->getFileCompareUrl($this->active_commit, $this->active_file, $this->request->get('peg')));
 }
 /**
  * Replace entries in database with new data from GitHub API
  *
  * This method will query the GitHub API for a list of recent commits.  If the query is
  * successful, the existing commits in the database will be removed and replaced with the
  * updated data.
  *
  * @return boolean Success or failure of the flush
  */
 public function flush()
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://api.github.com/repos/nodejs/node/commits');
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HEADER, true);
     curl_setopt($curl, CURLOPT_VERBOSE, true);
     curl_setopt($curl, CURLOPT_USERAGENT, 'Example PHP Challenge');
     $result = curl_exec($curl);
     $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($httpcode != 200) {
         return false;
     } else {
         $headersize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
         $result = substr($result, $headersize);
         $this->deleteAll();
         $commits = json_decode($result);
         $commits = array_slice($commits, 0, 25);
         foreach ($commits as $commit) {
             $model = new Commits();
             if (!($author = Authors::model()->findByPK($commit->author->id))) {
                 $author = new Authors();
                 $author->id = $commit->author->id;
                 $author->login = $commit->author->login;
                 $author->avatar_url = $commit->author->avatar_url;
                 $author->url = $commit->author->html_url;
                 $author->save();
             }
             if (!($committer = Authors::model()->findByPK($commit->committer->id))) {
                 $committer = new Authors();
                 $committer->id = $commit->committer->id;
                 $committer->login = $commit->committer->login;
                 $committer->avatar_url = $commit->committer->avatar_url;
                 $committer->url = $commit->committer->html_url;
                 $committer->save();
             }
             $model->hash = substr($commit->sha, 0, 6);
             $model->url = $commit->html_url;
             $model->message = $commit->commit->message;
             $model->author_id = $author->id;
             $model->committer_id = $committer->id;
             $model->modified = date('Y-m-d H:i:s');
             $model->save();
         }
         return true;
     }
 }
 /**
  * Send notification to subscribers
  *
  * @param int $logs_count
  */
 function sendToSubscribers($logs_count, &$repository_engine, $params = array(), $exclude = null)
 {
     if (!is_array($params)) {
         $params = array();
     }
     // if
     $params['commit_count'] = $logs_count;
     $params['commits_body'] = "";
     if ($logs_count <= 10) {
         $commits = Commits::find(array('conditions' => "parent_id = '" . $this->getId() . "'", 'order' => 'created_on DESC', 'limit' => $logs_count));
         if (is_foreachable($commits)) {
             foreach ($commits as $key => $commit) {
                 $paths = $commit->getPaths();
                 $params['commits_body'] .= "<hr/>";
                 $params['commits_body'] .= "<p><a href=\"" . $commit->getViewUrl() . "\">" . lang("<b>Commit #:revision</b>", array('revision' => $commit->getRevision(), false)) . '</a> ' . lang('by :author', array('author' => $commit->getAuthor()), false) . "</p>\n";
                 $params['commits_body'] .= nl2br(trim($commit->getMessage())) . "\n";
                 $params['commits_body'] .= $repository_engine->getCommitTemplateBit($paths);
             }
             // foreach
             $params['commits_body'] .= "<hr/>";
         }
         // if
     }
     // if
     parent::sendToSubscribers("source/repository_updated", $params, get_logged_user_id());
 }
 public function actionList()
 {
     $models = Commits::model()->findAll();
     if (empty($models)) {
         $this->_sendResponse(404, 'No records found.  Try flushing the database?');
     } else {
         $rows = array();
         foreach ($models as $model) {
             $row = $model->attributes;
             $row['author'] = $model->author;
             $rows[] = $row;
         }
         $this->_sendResponse(200, CJSON::encode($rows));
     }
 }
 /**
  * Paginate commits by repository
  *
  * @param Repository $repository
  * @param integer $page
  * @param integer $per_page
  * @return array of objects
  */
 function paginateByRepository($repository, $page = 1, $per_page = 10, $filter_by_author = null)
 {
     $conditions = "parent_id = '" . $repository->getId() . "' AND type = 'Commit'";
     if (!is_null($filter_by_author)) {
         $conditions .= " AND created_by_name = '{$filter_by_author}'";
     }
     // if
     return Commits::paginate(array('conditions' => $conditions, 'order' => 'integer_field_1 DESC'), $page, $per_page);
 }
 /**
  * Get log data
  *
  * @param integer $revision_to
  * @param mixed $revision_from
  * @return array
  */
 function getLogs($revision_to, $revision_from = 'HEAD', $logs_per_query = 100)
 {
     // get multiple logs or a single one
     if (!is_null($revision_from)) {
         $r = $revision_from . ':' . $revision_to;
     } else {
         $r = $revision_to;
         $this->triggerred_by_handler = true;
     }
     // if
     $string = 'log -r ' . $r . ' --xml --verbose ' . $this->active_repository->getUrl();
     $this->execute($string);
     $log_data = xml2array(implode("\n", $this->output), 1, array('path', 'logentry'));
     $insert_data = array();
     $i = 1;
     // this is because we get commits from SVN sorted from newest to oldest
     $logs = is_array($log_data['log']['logentry']) ? array_reverse($log_data['log']['logentry']) : array();
     // loop through array of log entries
     foreach ($logs as $key => $log_entry) {
         // prevent duplicate entries in case when there are two separate update processes
         // (like, both scheduled task and aC user triggered the update
         if (Commits::count("parent_id = '" . $this->active_repository->getId() . "' AND integer_field_1 = '" . $log_entry['attr']['revision'] . "'") > 0) {
             continue;
         }
         // if
         $paths = array();
         $k = 0;
         foreach ($log_entry['paths']['path'] as $path) {
             $paths[$k]['path'] = mysql_real_escape_string($path['value']);
             // paths can contain file names with characters that can break the query
             $paths[$k]['action'] = $path['attr']['action'];
             $k++;
         }
         // foreach
         $date = new DateTimeValue($log_entry['date']['value']);
         $log_date = $date->getYear() . "-" . $date->getMonth() . '-' . $date->getDay() . ' ' . $date->getHour() . ':' . $date->getMinute() . ':' . $date->getSecond();
         $commit_message = Commit::analyze_message($log_entry['msg']['value'], $log_entry['author']['value'], $log_entry['attr']['revision'], $this->active_repository, $this->active_project);
         $insert_data[$i][$key] = "('Commit','Source','" . $this->active_project->getId() . "','" . $this->active_repository->getId() . "','Repository','" . mysql_real_escape_string($commit_message) . "','" . $log_entry['attr']['revision'] . "','" . serialize($paths) . "','" . mysql_real_escape_string($log_entry['author']['value']) . "','{$log_date}', '" . STATE_VISIBLE . "', '" . $this->active_repository->getVisibility() . "')";
         $i = count($insert_data[$i]) < $logs_per_query ? $i : $i + 1;
     }
     // foreach
     return array('data' => $insert_data, 'total' => count($logs));
 }