1 <?php
2
3 4 5 6 7 8 9 10
11 class DevelopmentAdmin extends Controller {
12
13 static $url_handlers = array(
14 '' => 'index',
15 '$Action' => '$Action',
16 '$Action//$Action/$ID' => 'handleAction',
17 );
18
19 function init() {
20 parent::init();
21
22
23
24 $canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
25
26
27
28 $requestedDevBuild = (stripos($this->request->getURL(), 'dev/build') === 0 && !Security::database_is_ready());
29
30 if(!$canAccess && !$requestedDevBuild) {
31 return Security::permissionFailure($this);
32 }
33
34
35
36
37 global $_FILE_TO_URL_MAPPING;
38 if(Director::is_cli()) {
39 if(isset($_FILE_TO_URL_MAPPING)) {
40 $fullPath = $testPath = BASE_PATH;
41 while($testPath && $testPath != "/" && !preg_match('/^[A-Z]:\\\\$/', $testPath)) {
42 $matched = false;
43 if(isset($_FILE_TO_URL_MAPPING[$testPath])) {
44 $matched = true;
45 break;
46 }
47 $testPath = dirname($testPath);
48 }
49 if(!$matched) {
50 echo 'Warning: You probably want to define '.
51 'an entry in $_FILE_TO_URL_MAPPING that covers "' . Director::baseFolder() . '"' . "\n";
52 }
53 }
54 else {
55 echo 'Warning: You probably want to define $_FILE_TO_URL_MAPPING in '.
56 'your _ss_environment.php as instructed on the "sake" page of the doc.silverstripe.org wiki' . "\n";
57 }
58 }
59
60 }
61
62 function index() {
63 $actions = array(
64 "build" => "Build/rebuild this environment (formerly db/build). Call this whenever you have updated your project sources",
65 "buildcache" => "Rebuild the static cache, if you're using StaticPublisher",
66 "tests" => "See a list of unit tests to run",
67 "tests/all" => "Run all tests",
68 "tests/startsession" => "Start a test session in your browser (gives you a temporary database with default content)",
69 "tests/endsession" => "Ends a test session",
70 "jstests" => "See a list of JavaScript tests to run",
71 "jstests/all" => "Run all JavaScript tests",
72 "tasks" => "See a list of build tasks to run",
73 "viewcode" => "Read source code in a literate programming style",
74 );
75
76
77 if(!Director::is_cli()) {
78
79 unset($actions["modules/add"]);
80
81 $renderer = new DebugView();
82 $renderer->writeHeader();
83 $renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
84 $base = Director::baseURL();
85
86 echo '<div class="options"><ul>';
87 foreach($actions as $action => $description) {
88 echo "<li><a href=\"{$base}dev/$action\"><b>/dev/$action:</b> $description</a></li>\n";
89 }
90
91 $renderer->writeFooter();
92
93
94 } else {
95 echo "SAPPHIRE DEVELOPMENT TOOLS\n--------------------------\n\n";
96 echo "You can execute any of the following commands:\n\n";
97 foreach($actions as $action => $description) {
98 echo " sake dev/$action: $description\n";
99 }
100 echo "\n\n";
101 }
102 }
103
104 function tests($request) {
105 return new TestRunner();
106 }
107
108 function jstests($request) {
109 return new JSTestRunner();
110 }
111
112 function tasks() {
113 return new TaskRunner();
114 }
115
116 function viewmodel() {
117 return new ModelViewer();
118 }
119
120 function build() {
121 if(Director::is_cli()) {
122 $da = new DatabaseAdmin();
123 $da->build();
124 } else {
125 $renderer = new DebugView();
126 $renderer->writeHeader();
127 $renderer->writeInfo("Environment Builder (formerly db/build)", Director::absoluteBaseURL());
128 echo "<div style=\"margin: 0 2em\">";
129
130 $da = new DatabaseAdmin();
131 $da->build();
132
133 echo "</div>";
134 $renderer->writeFooter();
135 }
136 }
137
138 function reset() {
139 $link = BASE_URL.'/dev/tests/startsession';
140
141 return "<p>The dev/reset feature has been removed. If you are trying to test your site " .
142 "with a clean datababase, we recommend that you use " .
143 "<a href=\"$link\">dev/test/startsession</a> ".
144 "instead.</P>";
145
146 }
147
148 function errors() {
149 Director::redirect("Debug_");
150 }
151
152 function viewcode($request) {
153 return new CodeViewer();
154 }
155 }
156 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-