Added initial module manager API, with the capability of adding a module to svn:externals

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63534 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-10-02 20:59:43 +00:00
parent de4664cc10
commit 5478c88583
2 changed files with 108 additions and 0 deletions

View File

@ -20,12 +20,17 @@ class DevelopmentAdmin extends Controller {
$actions = array(
"build" => "Build/rebuild this environment (formerly db/build). Call this whenever you have updated your project sources",
"tests" => "See a list of unit tests to run",
"tests/all" => "Run all tests",
"modules/add" => "Add a module, for example, 'sake dev/modules/add ecommerce'",
"tasks" => "See a list of build tasks to run",
"viewcode" => "Read source code in a literate programming style",
);
// Web mode
if(!Director::is_cli()) {
// This action is sake-only right now.
unset($actions["modules/add"]);
$renderer = new DebugView();
$renderer->writeHeader();
$renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
@ -57,6 +62,10 @@ class DevelopmentAdmin extends Controller {
return new TaskRunner();
}
function modules() {
return new ModuleManager();
}
function build() {
$renderer = new DebugView();
$renderer->writeHeader();

99
dev/ModuleManager.php Normal file
View File

@ -0,0 +1,99 @@
<?php
/**
* This is part of the developer tools, and is responsible for installing and uninstalling modules
*
* Please note that this is experimental and the interface may change in the future.
* Also, it requires that your site is checked into SVN, and that SVN is installed.
*
* For best results, use the "sake" command line tool:
*
* cd /my/project/
* sake dev/modules/add ecommerce
*/
class ModuleManager extends RequestHandlingData {
protected $moduleBase = "http://svn.silverstripe.com/open/modules/";
static $allowed_actions = array(
'add',
);
/**
* Add a module to this project.
* This is designed to be called from sake.
*
* Usage: sake dev/modules/add ecommerce forum/tags/0.1
*/
function add() {
if(isset($_GET['args'])) {
$modules = $_GET['args'];
foreach($modules as $module) {
if(preg_match('/^[a-zA-Z0-9\/_-]+$/', $module)) {
// Default to trunk version of a module
if(strpos($module,'/') === false) $module = "$module/trunk";
$svnURL = $this->moduleBase . $module;
if($this->svnUrlExists($svnURL)) {
$moduleDir = strtok($module,'/');
echo "Linking directory '$moduleDir' to '$svnURL' using svn:externals...";
$this->svnAddExternal(Director::baseFolder(), $moduleDir, $svnURL);
echo "Calling SVN update to get the new code...";
$this->svnUpdate(Director::baseFolder());
echo "Rebuilding...";
// todo: we should be able to call the 'model' of the builder rather than its 'controller'
// it would make it easier to tailor the output
$da = new DevelopmentAdmin();
$da->build();
} else {
echo "Can't find '$svnURL' in SVN";
}
} else {
echo "Bad module '$module'";
}
}
}
}
/**
* Calls svn update
*/
protected function svnUpdate($baseDir) {
$CLI_baseDir = escapeshellarg($baseDir);
`svn update $CLI_baseDir`;
}
/**
* Returns true if the given SVN url exists
*/
protected function svnUrlExists($svnURL) {
$CLI_svnURL = escapeshellarg($svnURL);
$info = `svn info --xml $CLI_svnURL`;
$xmlInfo = new SimpleXmlElement($info);
return $xmlInfo->entry ? true : false;
}
/**
* Add a new entry to the svn externals
*/
protected function svnAddExternal($baseDir, $externalDir, $externalURL) {
$CLI_baseDir = escapeshellarg($baseDir);
$oldExternals = trim(`svn propget svn:externals $CLI_baseDir`);
$newExternals = "$oldExternals\n$externalDir/ $externalURL";
$CLI_newExternals = escapeshellarg($newExternals);
`svn propset svn:externals $CLI_newExternals $CLI_baseDir`;
}
}
?>