Moved the zmBandwidth option from a cookie to global Configure:: option

In addition I'm no longer passing this option around, instead calling it
where needed.  This _might_ fix #175 as the variable is being set very early on
in bootstrap.php
This commit is contained in:
Kyle Johnson 2013-10-02 08:09:30 -04:00
parent 83c744c7b7
commit e3db6e0edc
6 changed files with 18 additions and 24 deletions

View File

@ -108,3 +108,7 @@ CakeLog::config('error', array(
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
if (! Configure::read('zmBandwidth')) {
Configure::write('zmBandwidth', 'low');
}

View File

@ -39,13 +39,12 @@ class AppController extends Controller {
'Form' => array('className' => 'BoostCake.BoostCakeForm'),
'Paginator' => array('className' => 'BoostCake.BoostCakePaginator'),
);
public $components = array('Cookie', 'Session', 'RequestHandler');
public $components = array('Session', 'RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
$this->loadModel('Config');
$this->loadModel('AppModel');
$this->Cookie->name = 'ZoneMinder';
$configFile = "/usr/local/etc/zm.conf";
$lines = file($configFile);
@ -79,14 +78,6 @@ class AppController extends Controller {
$this->set('zmVersion', $zmVersion);
}
public function beforeRender() {
parent::beforeRender();
if (!$this->Cookie->read('zmBandwidth')) {
$this->Cookie->write('zmBandwidth', 'low', false);
}
$this->set('zmBandwidth', $this->Cookie->read('zmBandwidth'));
}
function extractNamedParams($mandatory, $optional = array()) {
$params = $this->params['named'];

View File

@ -4,16 +4,16 @@ class BandwidthController extends AppController {
public function index() {
if (!empty($this->request->data)) {
$bandwidth = $this->request->data['Bandwidth']['Bandwidth'];
$this->Cookie->write('zmBandwidth', $bandwidth, false);
$this->set('bandwidth', $bandwidth);
if ($this->Cookie->read('zmBandwidth') == $bandwidth) {
Configure::write('zmBandwidth', $bandwidth);
$this->set('bandwidth', $bandwidth);
if (Configure::read('zmBandwidth') == $bandwidth) {
$this->Session->setFlash('Successfully updated bandwidth');
} else {
$this->Session->setFlash('Failed to update bandwidth');
}
} else {
$this->set('bandwidth', $this->Cookie->read('zmBandwidth'));
}
$this->set('bandwidth', Configure::read('zmBandwidth'));
}
}
}

View File

@ -3,13 +3,12 @@
public $helpers = array('Js'=>array('Jquery'));
public function index() {
$zmBandwidth = $this->Cookie->read('zmBandwidth');
$monitoroptions = array('fields' => array('Name', 'Id', 'Function', 'Enabled', 'Sequence', 'Function', 'Width', 'StreamReplayBuffer'), 'order' => 'Sequence ASC', 'recursive' => -1);
$monitors = $this->Monitor->find('all', $monitoroptions);
foreach ($monitors as $key => $value) {
$monitors[$key]['img'] = $this->Monitor->getStreamSrc($value['Monitor']['Id'], $zmBandwidth, $value['Monitor']['StreamReplayBuffer'], $value['Monitor']['Function'], $value['Monitor']['Enabled'], $value['Monitor']['Name'], $value['Monitor']['Width']);
$monitors[$key]['img'] = $this->Monitor->getStreamSrc($value['Monitor']['Id'], $value['Monitor']['StreamReplayBuffer'], $value['Monitor']['Function'], $value['Monitor']['Enabled'], $value['Monitor']['Name'], $value['Monitor']['Width']);
}
$this->set('monitors', $monitors);
}
@ -26,9 +25,8 @@
$this->set('monitor', $monitor);
$zmBandwidth = $this->Cookie->read('zmBandwidth');
$buffer = $monitor['Monitor']['StreamReplayBuffer'];
$this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer, $monitor['Monitor']['Function'], $monitor['Monitor']['Enabled'], $monitor['Monitor']['Name'], $monitor['Monitor']['Width'], false));
$this->set('streamSrc', $this->Monitor->getStreamSrc($id, $buffer, $monitor['Monitor']['Function'], $monitor['Monitor']['Enabled'], $monitor['Monitor']['Name'], $monitor['Monitor']['Width'], false));
}
public function edit($id = null) {

View File

@ -3,7 +3,8 @@ class Config extends AppModel {
public $useTable = 'Config';
public $primaryKey = 'Name';
public function getWebOption($name, $zmBandwidth) {
public function getWebOption($name) {
$zmBandwidth = Configure::read('zmBandwidth');
$name_begin = substr($name, 0, 7);
$name_end = substr($name, 6);
$bandwidth_short = strtoupper($zmBandwidth[0]);

View File

@ -15,14 +15,14 @@
)
);
public function getStreamSrc($id = null, $zmBandwidth, $buffer, $function, $enabled, $name, $width, $scale = true) {
public function getStreamSrc($id = null, $buffer, $function, $enabled, $name, $width, $scale = true) {
$img['id'] = "livestream_$id";
$img['width'] = $width;
$ZM_MPEG_LIVE_FORMAT = Configure::read('ZM_MPEG_LIVE_FORMAT');
$ZM_WEB_STREAM_METHOD = ClassRegistry::init('Config')->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth);
$ZM_WEB_VIDEO_BITRATE = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_BITRATE', $zmBandwidth);
$ZM_WEB_VIDEO_MAXFPS = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_MAXFPS', $zmBandwidth);
$ZM_WEB_STREAM_METHOD = ClassRegistry::init('Config')->getWebOption('ZM_WEB_STREAM_METHOD');
$ZM_WEB_VIDEO_BITRATE = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_BITRATE');
$ZM_WEB_VIDEO_MAXFPS = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_MAXFPS');
$ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT;
if (Configure::read('daemonStatus') && $function != "None" && $enabled) {