Completed
Push — master ( 41d4aa...7dfe14 )
by Damian
02:52
created

ContentController::init()   D

Complexity

Conditions 17
Paths 10

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 30
rs 4.9807
cc 17
eloc 18
nc 10
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * The most common kind of controller; effectively a controller linked to a {@link DataObject}.
4
 *
5
 * ContentControllers are most useful in the content-focused areas of a site.  This is generally
6
 * the bulk of a site; however, they may be less appropriate in, for example, the user management
7
 * section of an application.
8
 *
9
 * On its own, content controller does very little.  Its constructor is passed a {@link DataObject}
10
 * which is stored in $this->dataRecord.  Any unrecognised method calls, for example, Title()
11
 * and Content(), will be passed along to the data record,
12
 *
13
 * Subclasses of ContentController are generally instantiated by ModelAsController; this will create
14
 * a controller based on the URLSegment action variable, by looking in the SiteTree table.
15
 * 
16
 * @todo Can this be used for anything other than SiteTree controllers?
17
 *
18
 * @package cms
19
 * @subpackage control
20
 */
21
class ContentController extends Controller {
22
23
	protected $dataRecord;
24
25
	private static $extensions = array('OldPageRedirector');
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
26
27
	private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
28
		'successfullyinstalled',
29
		'deleteinstallfiles', // secured through custom code
30
		'LoginForm'
31
	);
32
	
33
	/**
34
	 * The ContentController will take the URLSegment parameter from the URL and use that to look
35
	 * up a SiteTree record.
36
	 */
37
	public function __construct($dataRecord = null) {
38
		if(!$dataRecord) {
39
			$dataRecord = new Page();
40
			if($this->hasMethod("Title")) $dataRecord->Title = $this->Title();
0 ignored issues
show
Documentation Bug introduced by
The method Title does not exist on object<ContentController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
41
			$dataRecord->URLSegment = get_class($this);
42
			$dataRecord->ID = -1;
43
		}
44
		
45
		$this->dataRecord = $dataRecord;
46
47
		parent::__construct();
48
49
		$this->setFailover($this->dataRecord);
0 ignored issues
show
Documentation Bug introduced by
The method setFailover does not exist on object<ContentController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
50
	}
51
	
52
	/**
53
	 * Return the link to this controller, but force the expanded link to be returned so that form methods and
54
	 * similar will function properly.
55
	 *
56
	 * @param string|null $action Action to link to.
57
	 * @return string
58
	 */
59
	public function Link($action = null) {
60
		return $this->data()->Link(($action ? $action : true));
61
	}
62
	
63
	//----------------------------------------------------------------------------------//
64
	// These flexible data methods remove the need for custom code to do simple stuff
65
	
66
	/**
67
	 * Return the children of a given page. The parent reference can either be a page link or an ID.
68
	 *
69
	 * @param string|int $parentRef
70
	 * @return SS_List
71
	 */
72
	public function ChildrenOf($parentRef) {
73
		$parent = SiteTree::get_by_link($parentRef);
74
		
75
		if(!$parent && is_numeric($parentRef)) {
76
			$parent = DataObject::get_by_id('SiteTree', $parentRef);
77
		}
78
		
79
		if($parent) return $parent->Children();
80
	}
81
	
82
	/**
83
	 * @param string $link
84
	 * @return SiteTree
85
	 */
86
	public function Page($link) {
87
		return SiteTree::get_by_link($link);
88
	}
89
90
	public function init() {
91
		parent::init();
92
		
93
		// If we've accessed the homepage as /home/, then we should redirect to /.
94
		if($this->dataRecord && $this->dataRecord instanceof SiteTree
95
			 	&& RootURLController::should_be_on_root($this->dataRecord) && (!isset($this->urlParams['Action']) || !$this->urlParams['Action'] ) 
96
				&& !$_POST && !$_FILES && !$this->redirectedTo() ) {
97
			$getVars = $_GET;
98
			unset($getVars['url']);
99
			if($getVars) $url = "?" . http_build_query($getVars);
100
			else $url = "";
101
			$this->redirect($url, 301);
102
			return;
103
		}
104
		
105
		if($this->dataRecord) $this->dataRecord->extend('contentcontrollerInit', $this);
106
		else singleton('SiteTree')->extend('contentcontrollerInit', $this);
107
108
		if($this->redirectedTo()) return;
109
110
		// Check page permissions
111
		if($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->canView()) {
0 ignored issues
show
Documentation introduced by
The property URLSegment does not exist on object<ContentController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
112
			return Security::permissionFailure($this);
113
		}
114
115
		// Use theme from the site config
116
		if(($config = SiteConfig::current_site_config()) && $config->Theme) {
117
			Config::inst()->update('SSViewer', 'theme', $config->Theme);
118
		}
119
	}
120
	
121
	/**
122
	 * This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to
123
	 * fall over to a child controller in order to provide functionality for nested URLs.
124
	 *
125
	 * @param SS_HTTPRequest $request
126
	 * @param DataModel $model
127
	 * @return SS_HTTPResponse
128
	 * @throws SS_HTTPResponse_Exception
129
	 */
130
	public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
131
		$child  = null;
132
		$action = $request->param('Action');
133
		$this->setDataModel($model);
134
		
135
		// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
136
		// control to a child controller. This allows for the creation of chains of controllers which correspond to a
137
		// nested URL.
138
		if($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) {
139
			// See ModelAdController->getNestedController() for similar logic
140
			if(class_exists('Translatable')) Translatable::disable_locale_filter();
141
			// look for a page with this URLSegment
142
			$child = $this->model->SiteTree->filter(array(
143
				'ParentID' => $this->ID,
0 ignored issues
show
Documentation introduced by
The property ID does not exist on object<ContentController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
144
				'URLSegment' => rawurlencode($action)
145
			))->first();
146
			if(class_exists('Translatable')) Translatable::enable_locale_filter();
147
		}
148
		
149
		// we found a page with this URLSegment.
150
		if($child) {
151
			$request->shiftAllParams();
152
			$request->shift();
153
			
154
			$response = ModelAsController::controller_for($child)->handleRequest($request, $model);
155
		} else {
156
			// If a specific locale is requested, and it doesn't match the page found by URLSegment,
157
			// look for a translation and redirect (see #5001). Only happens on the last child in
158
			// a potentially nested URL chain.
159
			if(class_exists('Translatable')) {
160
				$locale = $request->getVar('locale');
161
				if($locale && i18n::validate_locale($locale) && $this->dataRecord && $this->dataRecord->Locale != $locale) {
162
					$translation = $this->dataRecord->getTranslation($locale);
163
					if($translation) {
164
						$response = new SS_HTTPResponse();
165
						$response->redirect($translation->Link(), 301);
166
						throw new SS_HTTPResponse_Exception($response);
167
					}
168
				}
169
			}
170
			
171
			Director::set_current_page($this->data());
172
173
			try {
174
				$response = parent::handleRequest($request, $model);
0 ignored issues
show
Bug introduced by
It seems like $model defined by parameter $model on line 130 can be null; however, Controller::handleRequest() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
175
176
				Director::set_current_page(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
			} catch(SS_HTTPResponse_Exception $e) {
178
				$this->popCurrent();
179
				
180
				Director::set_current_page(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<SiteTree>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
181
182
				throw $e;
183
			}
184
		}
185
		
186
		return $response;
187
	}
188
	
189
	/**
190
	 * Get the project name
191
	 *
192
	 * @return string
193
	 */
194
	public function project() {
195
		global $project;
196
		return $project;
197
	}
198
	
199
	/**
200
	 * Returns the associated database record
201
	 */
202
	public function data() {
203
		return $this->dataRecord;
204
	}
205
206
	/*--------------------------------------------------------------------------------*/
207
208
	/**
209
	 * Returns a fixed navigation menu of the given level.
210
	 * @param int $level Menu level to return.
211
	 * @return ArrayList
212
	 */
213
	public function getMenu($level = 1) {
214
		if($level == 1) {
215
			$result = SiteTree::get()->filter(array(
216
				"ShowInMenus" => 1,
217
				"ParentID" => 0
218
			));
219
220
		} else {
221
			$parent = $this->data();
222
			$stack = array($parent);
223
			
224
			if($parent) {
225
				while($parent = $parent->Parent) {
226
					array_unshift($stack, $parent);
227
				}
228
			}
229
			
230
			if(isset($stack[$level-2])) $result = $stack[$level-2]->Children();
231
		}
232
233
		$visible = array();
234
235
		// Remove all entries the can not be viewed by the current user
236
		// We might need to create a show in menu permission
237
 		if(isset($result)) {
238
			foreach($result as $page) {
239
				if($page->canView()) {
240
					$visible[] = $page;
241
				}
242
			}
243
		}
244
245
		return new ArrayList($visible);
246
	}
247
248
	public function Menu($level) {
249
		return $this->getMenu($level);
250
	}
251
252
	/**
253
	 * Returns the default log-in form.
254
	 *
255
	 * @todo Check if here should be returned just the default log-in form or
256
	 *       all available log-in forms (also OpenID...)
257
	 */
258
	public function LoginForm() {
259
		return MemberAuthenticator::get_login_form($this);
260
	}
261
262
	public function SilverStripeNavigator() {
263
		$member = Member::currentUser();
264
		$items = '';
265
		$message = '';
266
267
		if(Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {			
268
			if($this->dataRecord) {
269
				Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css');
270
				Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
271
				Requirements::javascript(CMS_DIR . '/javascript/SilverStripeNavigator.js');
272
				
273
				$return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord);
0 ignored issues
show
Unused Code introduced by
$nav is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
274
				$items = $return['items'];
275
				$message = $return['message'];
276
			}
277
278
			if($member) {
279
				$firstname = Convert::raw2xml($member->FirstName);
280
				$surname = Convert::raw2xml($member->Surname);
281
				$logInMessage = _t('ContentController.LOGGEDINAS', 'Logged in as') ." {$firstname} {$surname} - <a href=\"Security/logout\">". _t('ContentController.LOGOUT', 'Log out'). "</a>";
282
			} else {
283
				$logInMessage = sprintf(
284
					'%s - <a href="%s">%s</a>' ,
285
					_t('ContentController.NOTLOGGEDIN', 'Not logged in') ,
286
					Config::inst()->get('Security', 'login_url'),
287
					_t('ContentController.LOGIN', 'Login') ."</a>"
288
				);
289
			}
290
			$viewPageIn = _t('ContentController.VIEWPAGEIN', 'View Page in:');
291
			
292
			return <<<HTML
293
				<div id="SilverStripeNavigator">
294
					<div class="holder">
295
					<div id="logInStatus">
296
						$logInMessage
297
					</div>
298
299
					<div id="switchView" class="bottomTabs">
300
						$viewPageIn 
301
						$items
302
					</div>
303
					</div>
304
				</div>
305
					$message
306
HTML;
307
308
		// On live sites we should still see the archived message
309
		} else {
310
			if($date = Versioned::current_archived_date()) {
311
				Requirements::css(CMS_DIR . '/css/SilverStripeNavigator.css');
312
				$dateObj = Datetime::create($date, null);
0 ignored issues
show
Bug introduced by
The method create() does not exist on DateTime. Did you maybe mean createFromFormat()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
313
				// $dateObj->setVal($date);
314
				return "<div id=\"SilverStripeNavigatorMessage\">". _t('ContentController.ARCHIVEDSITEFROM') ."<br>" . $dateObj->Nice() . "</div>";
315
			}
316
		}
317
	}
318
	
319
	public function SiteConfig() {
320
		if(method_exists($this->dataRecord, 'getSiteConfig')) {
321
			return $this->dataRecord->getSiteConfig();
322
		} else {
323
			return SiteConfig::current_site_config();
324
		}
325
	}
326
327
	/**
328
	 * Returns an RFC1766 compliant locale string, e.g. 'fr-CA'.
329
	 * Inspects the associated {@link dataRecord} for a {@link SiteTree->Locale} value if present,
330
	 * and falls back to {@link Translatable::get_current_locale()} or {@link i18n::default_locale()},
331
	 * depending if Translatable is enabled.
332
	 * 
333
	 * Suitable for insertion into lang= and xml:lang=
334
	 * attributes in HTML or XHTML output.
335
	 * 
336
	 * @return string
337
	 */
338
	public function ContentLocale() {
339
		if($this->dataRecord && $this->dataRecord->hasExtension('Translatable')) {
340
			$locale = $this->dataRecord->Locale;
341
		} elseif(class_exists('Translatable') && SiteTree::has_extension('Translatable')) {
342
			$locale = Translatable::get_current_locale();
343
		} else {
344
			$locale = i18n::get_locale();
345
		}
346
		
347
		return i18n::convert_rfc1766($locale);
348
	}	
349
350
351
	/**
352
	 * Return an SSViewer object to render the template for the current page.
353
	 *
354
	 * @param $action string
355
	 *
356
	 * @return SSViewer
357
	 */
358
	public function getViewer($action) {
359
		// Manually set templates should be dealt with by Controller::getViewer()
360
		if(isset($this->templates[$action]) && $this->templates[$action]
0 ignored issues
show
Documentation introduced by
The property templates does not exist on object<ContentController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
361
			|| (isset($this->templates['index']) && $this->templates['index'])
0 ignored issues
show
Documentation introduced by
The property templates does not exist on object<ContentController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
362
			|| $this->template
0 ignored issues
show
Documentation introduced by
The property template does not exist on object<ContentController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
363
		) {
364
			return parent::getViewer($action);
365
		}
366
367
		// Prepare action for template search
368
		if($action == "index") $action = "";
369
		else $action = '_' . $action;
370
371
		$templates = array_merge(
372
			// Find templates by dataRecord
373
			SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"),
374
			// Next, we need to add templates for all controllers
375
			SSViewer::get_templates_by_class(get_class($this), $action, "Controller"),
376
			// Fail-over to the same for the "index" action
377
			SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"),
378
			SSViewer::get_templates_by_class(get_class($this), "", "Controller")
379
		);
380
381
		return new SSViewer($templates);
382
	}
383
384
385
	/**
386
	 * This action is called by the installation system
387
	 */
388
	public function successfullyinstalled() {
389
		// Return 410 Gone if this site is not actually a fresh installation
390
		if (!file_exists(BASE_PATH . '/install.php')) {
391
			$this->httpError(410);
392
		}
393
		
394
		// TODO Allow this to work when allow_url_fopen=0
395
		if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
396
			$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
397
			@file_get_contents($url);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
398
		}
399
		
400
		global $project;
401
		$data = new ArrayData(array(
402
			'Project' => Convert::raw2xml($project),
403
			'Username' => Convert::raw2xml(Session::get('username')),
404
			'Password' => Convert::raw2xml(Session::get('password')),
405
		));
406
		
407
		return array(
408
			"Title" =>  _t("ContentController.INSTALL_SUCCESS", "Installation Successful!"),
409
			"Content" => $data->renderWith('Install_successfullyinstalled'),
410
		);
411
	}
412
413
	public function deleteinstallfiles() {
414
		if(!Permission::check("ADMIN")) return Security::permissionFailure($this);
415
		
416
		$title = new Varchar("Title");
417
		$content = new HTMLText('Content');
418
419
		// We can't delete index.php as it might be necessary for URL routing without mod_rewrite.
420
		// There's no safe way to detect usage of mod_rewrite across webservers,
421
		// so we have to assume the file is required.
422
		$installfiles = array(
423
			'install.php',
424
			'config-form.css',
425
			'config-form.html',
426
			'index.html'
427
		);
428
429
		$unsuccessful = new ArrayList();
430
		foreach($installfiles as $installfile) {
431
			if(file_exists(BASE_PATH . '/' . $installfile)) {
432
				@unlink(BASE_PATH . '/' . $installfile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
433
			}
434
435
			if(file_exists(BASE_PATH . '/' . $installfile)) {
436
				$unsuccessful->push(new ArrayData(array('File' => $installfile)));
437
			}
438
		}
439
440
		$data = new ArrayData(array(
441
			'Username' => Convert::raw2xml(Session::get('username')),
442
			'Password' => Convert::raw2xml(Session::get('password')),
443
			'UnsuccessfulFiles' => $unsuccessful
444
		));
445
		$content->setValue($data->renderWith('Install_deleteinstallfiles'));
446
447
		return array(
448
			"Title" => $title,
449
			"Content" => $content,
450
		);
451
	}
452
}
453