<?php
/**
* iF.SVNAdmin
* Copyright (c) 2010 by Manuel Freiholz
* http://www.insanefactory.com/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
*/
namespace svnadmin\providers
{
class RepositoryViewProvider implements \svnadmin\core\interfaces\IRepositoryViewProvider
{
// Public members.
// The directory where all the repositories takes place.
public $svnParentPath = NULL;
// Private members.
private $m_svnclient = NULL;
private $m_init_done = false;
private static $m_instance = NULL;
/**
* Gets the singelton instance of this object.
*
* @return \svnadmin\providers\RepositoryViewProvider
*/
public static function getInstance()
{
if( self::$m_instance == NULL )
{
self::$m_instance = new RepositoryViewProvider;
}
return self::$m_instance;
}
////////////////////////////////////////////////////////////////////////////
// IInit implementations
////////////////////////////////////////////////////////////////////////////
public function init()
{
if( !$this->m_init_done )
{
global $appEngine;
$this->svnParentPath = $appEngine->getConfig()->getValue("Repositories:svnclient", "SVNParentPath");
$this->m_init_done = true;
$this->m_svnclient = new \IF_SVNClientC();
return $this->m_svnclient->init($appEngine->getConfig()->getValue("Repositories:svnclient", "SvnExecutable"));
}
return true;
}
////////////////////////////////////////////////////////////////////////////
// IViewProvider
////////////////////////////////////////////////////////////////////////////
public function isUpdateable()
{ // Nothing to do here...
return false;
}
public function update()
{ // Nothing to do here...
return false;
}
////////////////////////////////////////////////////////////////////////////
// IRepositoryViewProvider
////////////////////////////////////////////////////////////////////////////
public function getRepositories()
{
$repoList = array();
if (!file_exists($this->svnParentPath))
throw new \Exception("The repository parent path doesn't exists: " . $this->svnParentPath);
$hd = opendir( $this->svnParentPath );
while( ($file = readdir($hd)) !== false )
{
$invalid = strpos( $file, "." );
if( $invalid !== FALSE && $invalid == 0 )
{
continue;
}
if( is_dir( $this->svnParentPath . "/" . $file ) )
{
$o = new \svnadmin\core\entities\Repository();
$o->name = $file;
$o->path = "/";
array_push( $repoList, $o );
}
}
closedir( $hd );
return $repoList;
}
public function listPath( $oRepository, $relativePath )
{
// Absolute path to the repository.
$repo = $this->svnParentPath;
$repo.= "/";
$repo.= $oRepository->name;
if ($relativePath == "/")
$relativePath = "";
// Append the relative path.
$uri = $repo."/".$relativePath;
$ret = array();
// Get the file list.
$svn_entry_list = $this->m_svnclient->svn_list($uri);
if ($svn_entry_list === null)
return $ret;
if (empty($svn_entry_list->entries))
return $ret;
foreach ($svn_entry_list->entries as $entry)
{
$oRP = new \svnadmin\core\entities\RepositoryPath();
$oRP->parent = $relativePath;
$oRP->name = $entry->name;
$oRP->type = ($entry->isdir ? 0 : 1);
$oRP->author = $entry->author;
$oRP->revision = $entry->rev;
$oRP->date = $entry->date;
$ret[] = $oRP;
}
return $ret;
}
} // class end
} // namespace end
?>