Code Duplication    Length = 13-22 lines in 2 locations

dev/TaskRunner.php 1 location

@@ 18-30 (lines=13) @@
15
		'runTask',
16
	);
17
18
	public function init() {
19
		parent::init();
20
21
		$isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test());
22
		$canAccess = (
23
			Director::isDev()
24
			// We need to ensure that DevelopmentAdminTest can simulate permission failures when running
25
			// "dev/tasks" from CLI.
26
			|| (Director::is_cli() && !$isRunningTests)
27
			|| Permission::check("ADMIN")
28
		);
29
		if(!$canAccess) return Security::permissionFailure($this);
30
	}
31
32
	public function index() {
33
		$tasks = $this->getTasks();

model/DatabaseAdmin.php 1 location

@@ 24-45 (lines=22) @@
21
		'import'
22
	);
23
24
	public function init() {
25
		parent::init();
26
27
		// We allow access to this controller regardless of live-status or ADMIN permission only
28
		// if on CLI or with the database not ready. The latter makes it less errorprone to do an
29
		// initial schema build without requiring a default-admin login.
30
		// Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
31
		$isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test());
32
		$canAccess = (
33
			Director::isDev()
34
			|| !Security::database_is_ready()
35
			// We need to ensure that DevelopmentAdminTest can simulate permission failures when running
36
			// "dev/tests" from CLI.
37
			|| (Director::is_cli() && !$isRunningTests)
38
			|| Permission::check("ADMIN")
39
		);
40
		if(!$canAccess) {
41
			return Security::permissionFailure($this,
42
				"This page is secured and you need administrator rights to access it. " .
43
				"Enter your credentials below and we will send you right along.");
44
		}
45
	}
46
47
	/**
48
	 * Get the data classes, grouped by their root class