mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
47f40ed6bd
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63535 467b73ca-7a2a-4603-9d3b-597d59a354a9
101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?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(!Director::is_cli()) return new HTTPResponse('ModuleManager only currently works in command-line mode.', 403);
|
|
|
|
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`;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|