/** * Get recent activity for a repository * * @param Repository $repository * @param int $from_days_before * @return array */ function getRecentActivity($repository, $from_days_before = 15) { $from = new DateTimeValue($from_days_before - 1 . ' days ago'); $last_commit = $repository->getLastcommit(); $beginning_of_day = $from->beginningOfDay(); $max_commits = Commits::count(array("parent_id = ? AND created_on >= ? GROUP BY DAY(created_on) ORDER BY row_count DESC LIMIT 1", $repository->getId(), $beginning_of_day)); $from_days_before--; for ($i = $from_days_before; $i >= 0; $i--) { $date = new DateTimeValue($i . 'days ago'); $this_date_beginning = $date->beginningOfDay(); $this_date_end = $date->endOfDay(); $commits_count = Commits::count(array("parent_id = ? AND created_on >= ? AND created_on <= ?", $repository->getId(), $this_date_beginning, $this_date_end)); $activity[$i]['commits'] = $commits_count; $activity[$i]['created_on'] = date('F d, Y', $date->getTimestamp()); $activity[$i]['percentage'] = round($commits_count * 100 / $max_commits); } return $activity; }
/** * View commit history of selected repository * * @param null * @return void */ function history() { if (!$this->active_repository->canView($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $this->wireframe->addPageAction(lang('Browse repository'), $this->active_repository->getBrowseUrl(), null); if ($this->active_repository->canEdit($this->logged_user) || $this->active_repository->getCreatedById() == $this->logged_user->getId()) { $this->wireframe->addPageAction(lang('Update'), $this->active_repository->getUpdateUrl(), null, array('id' => 'repository_ajax_update')); } $per_page = 20; $page = intval(array_var($_GET, 'page')) > 0 ? array_var($_GET, 'page') : 1; $commits_count_params = array("parent_id = ?", $this->active_repository->getId()); $filter_by_author = $this->request->get('filter_by_author'); if (!is_null($filter_by_author)) { $commits_count_params['created_by_name'] = $filter_by_author; } // if list($commits, $pagination) = Commits::paginateByRepository($this->active_repository, $page, $per_page, $filter_by_author); if (is_foreachable($commits)) { foreach ($commits as $commit) { $commit->total_paths = count($commit->getPaths()); $commit->setPaths($this->repository_engine->groupPaths($commit->getPaths())); } // foreach if (!is_null($filter_by_author)) { $filter_by_author = array(); $filter_by_author['user_object'] = $commits['0']->getAuthor(); $filter_by_author['user_name'] = $commits['0']->getCreatedbyName(); } // if } // if $commits = group_by_date($commits, $this->logged_user); $this->smarty->assign(array('filter_by_author' => $filter_by_author, 'commits' => $commits, 'pagination' => $pagination, 'project' => $this->active_project, 'total_commits' => Commits::count($commits_count_params))); }
/** * 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)); }