CheckBackendConnectivityFilter::preFilter()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
eloc 7
c 2
b 1
f 0
nc 3
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
/**
4
 * Checks whether the current backend is connectable. If it is we continue 
5
 * as normal, if not we redirect to the "waiting for WOL" page if a MAC 
6
 * address has been configured for the backend, otherwise we just error out.
7
 *
8
 * @author Sam Stenvall <[email protected]>
9
 * @copyright Copyright &copy; Sam Stenvall 2013-
10
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
11
 */
12
class CheckBackendConnectivityFilter extends CFilter
13
{
14
15
	/**
16
	 * @param CFilterChain $filterChain
17
	 * @return boolean whether to continue the filtering
18
	 * @throws CHttpException if the current backend is not connectable and 
19
	 * cannot be awakened
20
	 */
21
	protected function preFilter($filterChain)
22
	{
23
		/* @var $backend Backend */
24
		$backend = Yii::app()->backendManager->getCurrent();
25
26
		if (!$backend->isConnectable())
27
		{
28
			if ($backend->macAddress)
29
				$filterChain->controller->redirect(array('backend/waitForConnectivity'));
30
			else
31
				throw new CHttpException(500, Yii::t('Backend', 'The current backend is not connectable at the moment'));
32
		}
33
34
		return true;
35
	}
36
37
}
38