You are here

function drd_server_server_svn_status in Drupal Remote Dashboard Server 6

Same name and namespace in other branches
  1. 7 drd_server.server.inc \drd_server_server_svn_status()
1 string reference to 'drd_server_server_svn_status'
drd_server_xmlrpc in ./drd_server.module
Implementation of hook_xmlrpc().

File

./drd_server.server.inc, line 66

Code

function drd_server_server_svn_status($sid, $svn_user, $svn_password, $force_external = FALSE) {
  $user = drd_server_load_user($sid);
  if (is_string($user)) {
    return drd_server_error($user);
  }
  if (function_exists('set_time_limit')) {
    @set_time_limit(0);
  }
  $status = array();
  if (function_exists('svn_status') && $force_external === FALSE) {
    svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, $svn_user);
    svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, $svn_password);
    $main = svn_status(DRUPAL_ROOT, SVN_NON_RECURSIVE + SVN_ALL);
    $mod_local = svn_status(DRUPAL_ROOT);
    $revision = $main[0]['revision'];
    foreach ($mod_local as $line) {
      if (is_dir($line['path']) && strpos('._', substr(basename($line['path']), 0, 1)) >= 0) {

        //ignore .DAV, .svn, _svn, etc. directory names
      }
      else {
        $status[] = array(
          'file_path' => $line['path'],
          'file_revision' => $line['revision'],
          'file_status' => $line['text_status'],
          'file_out_of_date' => $line['text_status'] != SVN_WC_STATUS_NORMAL || $line['repos_text_status'] != SVN_WC_STATUS_NORMAL,
        );
      }
    }
    $status[] = array(
      'info' => 'SVN status collected by PHP function',
    );
  }
  else {
    $cmd = "svn status -u " . DRUPAL_ROOT . " --username {$svn_user} --password {$svn_password}";
    $result = explode(':', exec($cmd, $output, $cmd_status));
    if ($cmd_status) {
      $cmd = "/usr/bin/" . $cmd;
      $result = explode(':', exec($cmd, $output, $cmd_status));
    }
    $revision = sizeof($result) > 1 ? trim($result[1]) : t('Unknown');
    $next_line_conflict = FALSE;
    array_pop($output);
    foreach ($output as $line) {
      if (!$next_line_conflict) {
        $file_status = substr($line, 0, 7);
        $file_out_of_date = substr($line, 8, 1);
        $line = trim(substr($line, 9));
        $pos = strpos($line, ' ');
        $file_revision = trim(substr($line, 0, $pos));
        $file_path = trim(substr($line, $pos));
        $next_line_conflict = substr($file_status, 6) == 'C';
        $status[] = array(
          'file_path' => $file_path,
          'file_revision' => $file_revision,
          'file_status' => $file_status,
          'file_out_of_date' => $file_out_of_date == '*',
        );
      }
      else {

        //ToDo: add conflict info to previous record
        $next_line_conflict = FALSE;
      }
    }
    $status[] = array(
      'info' => 'SVN status collected by commandline tool',
    );
  }
  return drd_server_result('server.svn.status', array(
    $revision,
    $status,
  ));
}