Ejemplo n.º 1
0
 /**
  * Checks whether the Subversion project has been modified.
  *
  * @param Xinc_Build_Interface                       $build The running build.
  * @param Xinc_Plugin_Repos_ModificationSet_Svn_Task $task  The configured task
  *
  * @return Xinc_Plugin_Repos_ModificationSet_Result The result of the check.
  */
 public function checkModified(Xinc_Build_Interface $build, Xinc_Plugin_Repos_ModificationSet_Svn_Task $task)
 {
     $result = new Xinc_Plugin_Repos_ModificationSet_Result();
     try {
         $this->task = $task;
         $this->svn = VersionControl_SVN::factory(array('info', 'log', 'status', 'update'), array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC, 'username' => $task->getUsername(), 'password' => $task->getPassword(), 'trustServerCert' => $task->trustServerCert()));
         $strRemoteVersion = $this->getRemoteVersion();
         $strLocalVersion = $this->getLocalVersion();
     } catch (VersionControl_SVN_Exception $e) {
         $build->error('Test of Subversion failed: ' . $e->getMessage());
         $build->setStatus(Xinc_Build_Interface::FAILED);
         $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::ERROR);
         return $result;
     }
     $result->setRemoteRevision($strRemoteVersion);
     $result->setLocalRevision($strLocalVersion);
     if ($strRemoteVersion !== $strLocalVersion) {
         try {
             $this->getModifiedFiles($result);
             $this->getChangeLog($result);
             if ($this->task->doUpdate()) {
                 $this->update($result);
             }
             $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::CHANGED);
         } catch (Exception $e) {
             var_dump($e->getMessage());
             $build->error('Processing SVN failed: ' . $e->getMessage());
             $result->setStatus(Xinc_Plugin_Repos_ModificationSet_AbstractTask::FAILED);
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param  array                        $data
  * @param  string                       $entityType
  * @throws VersionControl_SVN_Exception on error
  */
 public function storeData($data, $entityType)
 {
     parent::storeData($data, $entityType);
     $fileName = $this->_getEntityFilename($entityType);
     $svnStatus = VersionControl_SVN::factory('status');
     $status = $svnStatus->run(array($fileName));
     if (isset($status['target']) and isset($status['target'][0]) and isset($status['target'][0]['entry']) and is_array($status['target'][0]['entry'])) {
         foreach ($status['target'][0]['entry'] as $entry) {
             switch ($entry['wc-status']['item']) {
                 case 'unversioned':
                     $svnAdd = VersionControl_SVN::factory('add');
                     $svnAdd->run(array($fileName));
                 case 'modified':
                 case 'added':
                     $svnCommit = VersionControl_SVN::factory('ci');
                     $svnCommit->run(array($fileName), array('m' => escapeshellarg('current "' . $entityType . '" content')));
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates a VersionControl_SVN class based on $mode
  *
  * @param string The SVN mode to use (info, export, checkout, ...)
  * @throws BuildException
  */
 protected function setup($mode)
 {
     $this->mode = $mode;
     // Set up runtime options. Will be passed to all
     // subclasses.
     $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ASSOC, 'svn_path' => escapeshellarg($this->getSvnPath()));
     // Pass array of subcommands we need to factory
     $this->svn = VersionControl_SVN::factory($mode, $options);
     $this->svn->use_escapeshellcmd = false;
     if (!empty($this->repositoryUrl)) {
         $this->svnArgs = array($this->repositoryUrl);
     } else {
         if (!empty($this->workingCopy)) {
             if (is_dir($this->workingCopy)) {
                 if (in_array(".svn", scandir($this->workingCopy))) {
                     $this->svnArgs = array(escapeshellarg($this->workingCopy));
                 } else {
                     throw new BuildException("'" . $this->workingCopy . "' doesn't seem to be a working copy");
                 }
             } else {
                 if ($mode == 'info') {
                     if (is_file($this->workingCopy)) {
                         $this->svnArgs = array(escapeshellarg($this->workingCopy));
                     } else {
                         throw new BuildException("'" . $this->workingCopy . "' is not a directory nor a file");
                     }
                 } else {
                     throw new BuildException("'" . $this->workingCopy . "' is not a directory");
                 }
             }
         }
     }
 }
 /**
  * Initialize an object wrapper for a Subversion subcommand.
  *
  * @return  mixed   object on success, false on failure
  * @access public
  */
 function init($command, $options)
 {
     // Check for shortcuts for commands
     $shortcuts = VersionControl_SVN::fetchShortcuts();
     if (isset($options['shortcuts']) && is_array($options['shortcuts'])) {
         foreach ($options['shortcuts'] as $key => $val) {
             $shortcuts[strtolower($key)] = $val;
         }
     }
     $cmd = isset($shortcuts[strtolower($command)]) ? $shortcuts[strtolower($command)] : $command;
     $lowercmd = strtolower($cmd);
     $cmd = ucfirst($lowercmd);
     $class = 'VersionControl_SVN_' . $cmd;
     if (include_once realpath(dirname(__FILE__)) . "/SVN/{$cmd}.php") {
         if (class_exists($class)) {
             $obj =& new $class();
             $obj->options = $options;
             $obj->_svn_cmd = $lowercmd;
             $obj->_stack =& PEAR_ErrorStack::singleton('VersionControl_SVN');
             $obj->_stack->setErrorMessageTemplate(VersionControl_SVN::declareErrorMessages());
             $obj->setOptions($options);
             return $obj;
         }
     }
     PEAR_ErrorStack::staticPush('VersionControl_SVN', VERSIONCONTROL_SVN_ERROR_UNKNOWN_CMD, 'error', array('command' => $command, 'options' => $options));
     return false;
 }
Ejemplo n.º 5
0
// $Id$
//
/*
    In this example, we'll get a list of files in a repository, and
    link to their contents.
*/
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require_once 'VersionControl/SVN.php';
// Default options
$base_url = 'https://github.com/pear/VersionControl_SVN/trunk';
$base_add = isset($_GET['base_add']) ? '/' . $_GET['base_add'] : '';
$cmd = isset($_GET['cmd']) ? $_GET['cmd'] : 'list';
try {
    // Create svn object with subcommands we'll want
    $svn = VersionControl_SVN::factory(array('list', 'cat'));
    // A quickie sample of browsing a Subversion repository
    if ($cmd == 'cat') {
        $file = $_GET['file'];
        $source = $svn->cat->run(array($base_url . $base_add . '/' . $file));
        if (substr($file, -4) == '.php') {
            highlight_string($source);
        } else {
            echo "<pre>{$source}</pre>\n";
        }
    } else {
        $list = $svn->list->run(array($base_url));
        foreach ($list['list'][0]['entry'] as $item) {
            if ($item['kind'] != 'file') {
                echo "<a href=\"example1.php?cmd=list&base_add={$base_add}/{$item['name']}\">{$item['name']}</a><br />\n";
            } else {
 /**
  * Creates a VersionControl_SVN class based on $mode
  *
  * @param string The SVN mode to use (info, export, checkout, ...)
  * @throws BuildException
  */
 protected function setup($mode)
 {
     $this->mode = $mode;
     // Set up runtime options. Will be passed to all
     // subclasses.
     $options = array('fetchmode' => $this->fetchMode);
     if ($this->oldVersion) {
         $options['svn_path'] = $this->getSvnPath();
     } else {
         $options['binaryPath'] = $this->getSvnPath();
     }
     // Pass array of subcommands we need to factory
     $this->svn = VersionControl_SVN::factory($mode, $options);
     if (get_parent_class($this->svn) !== 'VersionControl_SVN_Command') {
         $this->oldVersion = true;
         $this->svn->use_escapeshellcmd = false;
     }
     if (!empty($this->repositoryUrl)) {
         $this->svnArgs = array($this->repositoryUrl);
     } else {
         if (!empty($this->workingCopy)) {
             if (is_dir($this->workingCopy)) {
                 $this->svnArgs = array($this->workingCopy);
             } else {
                 if ($mode == 'info') {
                     if (is_file($this->workingCopy)) {
                         $this->svnArgs = array($this->workingCopy);
                     } else {
                         throw new BuildException("'" . $this->workingCopy . "' is not a directory nor a file");
                     }
                 } else {
                     throw new BuildException("'" . $this->workingCopy . "' is not a directory");
                 }
             }
         }
     }
 }
 public function onLoad($param)
 {
     parent::onLoad($param);
     //Catch postback of path change events and handle them!
     if ($this->IsPostBack) {
         $sender = $this->Page->getPostBackTarget();
         if ($sender != null) {
             $sid = $sender->getId();
         } else {
             $sid = "AddPath";
         }
         $path = $this->getViewState('Path', '');
         if ($sid == "AddPath") {
             $path[] = $this->PathHolder->AddPath->getSelectedItem()->getText();
             // Value();
         } else {
             if (strlen($sid) > 3 && substr($sid, 0, 3) == "lev") {
                 $nlevel = $sender->getCommandParameter();
                 $newpath = array();
                 $newpath[] = "/";
                 if ($nlevel > 1) {
                     for ($i = 1; $i < $nlevel; $i++) {
                         $newpath[] = $path[$i];
                     }
                 }
                 $path = $newpath;
             }
         }
         $this->setViewState('Path', $path);
     }
     //Make list of granted rights
     $repositoryid = $_GET['RepositoryID'];
     $results = $this->Module->Database->Execute("SELECT * FROM groupprivileges WHERE repositoryid=" . makeSqlString($repositoryid) . " ORDER BY path, groupid");
     if ($results->RecordCount() > 0) {
         $data = array();
         while (!$results->EOF) {
             $fields = $results->fields;
             $id = $fields['id'];
             $groupname = $this->Module->getGroupname($fields['groupid']);
             $path = $fields['path'];
             /*
              * Access:
              * 0 = no access
              * 1 = r 
              * 2 = w 
              * 3 = rw
              */
             if ($fields['access'] == 1 || $fields['access'] == 3) {
                 $read = "yes";
             } else {
                 $read = "no";
             }
             if ($fields['access'] == 2 || $fields['access'] == 3) {
                 $write = "yes";
             } else {
                 $write = "no";
             }
             $data[] = array('id' => $id, 'groupname' => $groupname, 'path' => $path, 'read' => $read, 'write' => $write);
             $results->MoveNext();
         }
         $results->Close();
         $this->RightsTable->setDataSource($data);
         $this->RightsTable->dataBind();
     }
     //Make a list of groups (users that are created during right-management are NOT shown!!)
     if (!$this->isPostBack()) {
         $groupnames = array();
         $groupresults = $this->Module->Database->Execute("SELECT * FROM groups ORDER BY name");
         while (!$groupresults->EOF) {
             $groupnames[] = $groupresults->fields['name'];
             $groupresults->MoveNext();
         }
         $groupresults->Close();
         $this->GroupSelector->setDataSource($groupnames);
         $this->GroupSelector->databind();
     }
     //Fill place holder
     $path = $this->getViewState('Path', '');
     if (!isset($path) || $path == '') {
         $path = array();
         $path[] = "/";
     }
     $this->setViewState('Path', $path);
     $this->PathHolder->removeBodies();
     $this->PathHolder->removeChildren();
     $sess = $this->Application->getSession();
     //Linkbuttons
     $linkbuttons = array();
     $level = 0;
     foreach ($path as $p) {
         $id = "lev{$level}";
         $lb = $this->PathHolder->createComponent('TLinkButton', $id);
         $lb->setText($p);
         $lb->setCommandName("path");
         $lb->setCommandParameter($level);
         $linkbuttons[] = $lb;
         if ($level > 1) {
             $this->PathHolder->addBody("/");
         }
         $this->PathHolder->addBody($lb);
         $level++;
     }
     $sess->set("linkbuttons", $linkbuttons);
     //retrieve sub paths from repositoty
     require_once "VersionControl/SVN.php";
     require "config.php";
     $svnstack =& PEAR_ErrorStack::singleton('VersionControl_SVN');
     // 2006-02-15 PDurden Check to see if this is a Windows installation
     //if (isset($is_windows) && $is_windows)
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $svn_cmd = getenv("COMSPEC") . " /C " . $svn_cmd;
     }
     // Set up runtime options.
     $options = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY, 'svn_path' => $svn_cmd);
     //Request list class from factory
     $svn = VersionControl_SVN::factory('list', $options);
     // 2006-02-15 PDurden Check to see if this is a Windows installation
     //if (isset($is_windows) && $is_windows)
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $svn->use_escapeshellcmd = false;
     }
     $repositoryid = $_GET['RepositoryID'];
     $repositoryname = $this->Module->getRepositoryname($repositoryid);
     //if (isset($is_windows) && $is_windows)
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         if (substr($svn_repos_loc, 0, 1) != '/') {
             $svn_repos_loc = '/' . $svn_repos_loc;
         }
         $svn_repos_loc = str_replace("\\", "/", $svn_repos_loc);
     }
     $url = "file://{$svn_repos_loc}/{$repositoryname}";
     if (sizeof($path) > 1) {
         foreach ($path as $p) {
             $url .= "/{$p}";
         }
     }
     // 2006-02-16 PDurden - If there's a space in the URL, place it in quotes
     if (strstr($url, " ")) {
         $url = "\"" . $url . "\"";
     }
     $switches = array();
     $switches = array('config_dir' => $svn_config_dir);
     $args = array($url);
     $subfolders = array();
     if ($output = $svn->run($args, $switches)) {
         $subfolders[] = " -choose- ";
         foreach ($output as $entry) {
             if ($entry['type'] == 'D') {
                 $subfolders[] = $entry['name'];
             }
         }
     } else {
         if (count($errs = $svnstack->getErrors())) {
             foreach ($errs as $err) {
                 echo '<br />' . $err['message'] . "<br />\n";
                 echo "Command used: " . $err['params']['cmd'];
             }
             exit(-1);
         }
     }
     if (sizeof($subfolders) > 1) {
         $listbox = $this->PathHolder->createComponent('TListBox', 'AddPath');
         $listbox->setDataSource($subfolders);
         $listbox->dataBind();
         $listbox->setRows(1);
         $listbox->setAutoPostBack(true);
         if ($level > 1) {
             $this->PathHolder->addBody("/");
         }
         $this->PathHolder->addBody($listbox);
         $sess->set("listbox", $listbox);
     } else {
         $sess->clear("listbox");
     }
 }
Ejemplo n.º 8
0
 /**
  * Create a new VersionControl_SVN command object.
  *
  * $options is an array containing multiple options
  * defined by the following associative keys:
  *
  * <code>
  *
  * array(
  *  'username'      => 'Subversion repository login',
  *  'password'      => 'Subversion repository password',
  *  'config-dir'    => 'Path to a Subversion configuration directory',
  *                     // [DEFAULT: null]
  *  'config-option' => 'Set Subversion user configuration',
  *                     // [DEFAULT: null]
  *  'binaryPath'    => 'Path to the svn client binary installed as part of Subversion',
  *                     // [DEFAULT: /usr/local/bin/svn]
  *  'fetchmode'     => Type of returning of run function.
  *                     // [DEFAULT: VERSIONCONTROL_SVN_FETCHMODE_ASSOC]
  * )
  *
  * </code>
  *
  * Example 1.
  * <code>
  * <?php
  * require_once 'VersionControl/SVN.php';
  *
  * $options = array(
  *      'username'   => 'your_login',
  *      'password'   => 'your_password',
  * );
  * 
  * // Run a log command
  * $svn = VersionControl_SVN::factory('log', $options);
  *
  * print_r($svn->run(array('path_to_your_svn'));
  * ?>
  * </code>
  *
  * @param string $command The Subversion command
  * @param array  $options An associative array of option names and
  *                        their values
  *
  * @return mixed A newly created command object or an stdObj with the
  *               command objects set.
  * @throws VersionControl_SVN_Exception Exception if command init fails.
  */
 public static function factory($command, $options = array())
 {
     if (is_string($command) && strtoupper($command) == '__ALL__') {
         unset($command);
         $command = array();
         $command = VersionControl_SVN::fetchCommands();
     }
     if (is_array($command)) {
         $objects = new stdClass();
         foreach ($command as $cmd) {
             $obj = VersionControl_SVN::init($cmd, $options);
             $objects->{$cmd} = $obj;
         }
         return $objects;
     } else {
         $obj = VersionControl_SVN::init($command, $options);
         return $obj;
     }
 }
 protected function importFromSvn($url)
 {
     require_once 'VersionControl/SVN.php';
     $dir = sfConfig::get('sf_cache_dir') . '/svn-' . md5($url);
     $result = VersionControl_SVN::factory('export', array('svn_path' => 'svn'))->run(array($url, $dir));
     return $dir;
 }