cleaned up ApiController.php a little bit.
This commit is contained in:
parent
8e8f1b9a58
commit
e9bc0074c0
|
@ -547,26 +547,24 @@ class ApiController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function reloadMetadataGroupAction()
|
public function reloadMetadataGroupAction()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
|
||||||
// extract all file metadata params from the request.
|
// extract all file metadata params from the request.
|
||||||
// The value is a json encoded hash that has all the information related to this action
|
// The value is a json encoded hash that has all the information related to this action
|
||||||
// The key(mdXXX) does not have any meaning as of yet but it could potentially correspond
|
// The key(mdXXX) does not have any meaning as of yet but it could potentially correspond
|
||||||
// to some unique id.
|
// to some unique id.
|
||||||
$responses = array();
|
$request = $this->getRequest();
|
||||||
$dry = $request->getParam('dry') || false;
|
$responses = array();
|
||||||
$params = $request->getParams();
|
$dry = $request->getParam('dry') || false;
|
||||||
|
$params = $request->getParams();
|
||||||
$valid_modes = array('delete_dir', 'delete', 'moved', 'modify', 'create');
|
$valid_modes = array('delete_dir', 'delete', 'moved', 'modify', 'create');
|
||||||
foreach ($request->getParams() as $k => $raw_json) {
|
foreach ($request->getParams() as $k => $raw_json) {
|
||||||
// Valid requests must start with mdXXX where XXX represents at least 1 digit
|
// Valid requests must start with mdXXX where XXX represents at
|
||||||
|
// least 1 digit
|
||||||
if( !preg_match('/^md\d+$/', $k) ) { continue; }
|
if( !preg_match('/^md\d+$/', $k) ) { continue; }
|
||||||
$info_json = json_decode($raw_json, $assoc=true);
|
$info_json = json_decode($raw_json, $assoc = true);
|
||||||
$recorded = $info_json["is_record"];
|
$recorded = $info_json["is_record"];
|
||||||
unset( $info_json["is_record"] );
|
unset( $info_json["is_record"] );
|
||||||
//unset( $info_json["MDATA_KEY_DURATION"] );
|
// Log invalid requests
|
||||||
//unset( $info_json["MDATA_KEY_SAMPLERATE"] );
|
if( !array_key_exists('mode', $info_json) ) {
|
||||||
//unset( $info_json["MDATA_KEY_BITRATE"] );
|
|
||||||
|
|
||||||
if( !array_key_exists('mode', $info_json) ) { // Log invalid requests
|
|
||||||
Logging::info("Received bad request(key=$k), no 'mode' parameter. Bad request is:");
|
Logging::info("Received bad request(key=$k), no 'mode' parameter. Bad request is:");
|
||||||
Logging::info( $info_json );
|
Logging::info( $info_json );
|
||||||
array_push( $responses, array(
|
array_push( $responses, array(
|
||||||
|
@ -574,8 +572,8 @@ class ApiController extends Zend_Controller_Action
|
||||||
'key' => $k));
|
'key' => $k));
|
||||||
continue;
|
continue;
|
||||||
} elseif ( !in_array($info_json['mode'], $valid_modes) ) {
|
} elseif ( !in_array($info_json['mode'], $valid_modes) ) {
|
||||||
// A request still has a chance of being invalid even if it exists but it's validated
|
// A request still has a chance of being invalid even if it
|
||||||
// by $valid_modes array
|
// exists but it's validated by $valid_modes array
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
Logging::info("Received bad request(key=$k). 'mode' parameter was invalid with value: '$mode'. Request:");
|
Logging::info("Received bad request(key=$k). 'mode' parameter was invalid with value: '$mode'. Request:");
|
||||||
Logging::info( $info_json );
|
Logging::info( $info_json );
|
||||||
|
@ -588,14 +586,12 @@ class ApiController extends Zend_Controller_Action
|
||||||
// Removing 'mode' key from $info_json might not be necessary...
|
// Removing 'mode' key from $info_json might not be necessary...
|
||||||
$mode = $info_json['mode'];
|
$mode = $info_json['mode'];
|
||||||
unset( $info_json['mode'] );
|
unset( $info_json['mode'] );
|
||||||
$response = $this->dispatchMetadata($info_json, $mode, $dry_run=$dry);
|
$response = $this->dispatchMetadata($info_json, $mode,
|
||||||
|
$dry_run=$dry);
|
||||||
// We tack on the 'key' back to every request in case the would like to associate
|
// We tack on the 'key' back to every request in case the would like to associate
|
||||||
// his requests with particular responses
|
// his requests with particular responses
|
||||||
$response['key'] = $k;
|
$response['key'] = $k;
|
||||||
array_push($responses, $response);
|
array_push($responses, $response);
|
||||||
// On recorded show requests we do some extra work here. Not sure what it actually is and it
|
|
||||||
// was usually called from the python api client. Now we just call it straight from the controller to
|
|
||||||
// save the http roundtrip
|
|
||||||
}
|
}
|
||||||
die( json_encode($responses) );
|
die( json_encode($responses) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ class UpgradeCommon{
|
||||||
// Backup the config files
|
// Backup the config files
|
||||||
$suffix = date("Ymdhis")."-".UpgradeCommon::VERSION_NUMBER;
|
$suffix = date("Ymdhis")."-".UpgradeCommon::VERSION_NUMBER;
|
||||||
foreach ($configFiles as $conf) {
|
foreach ($configFiles as $conf) {
|
||||||
// do not back up monit cfg
|
// do not back up monit cfg -- ok?? not being done anyway
|
||||||
if (file_exists($conf)) {
|
if (file_exists($conf)) {
|
||||||
echo "Backing up $conf to $conf$suffix.bak".PHP_EOL;
|
echo "Backing up $conf to $conf$suffix.bak".PHP_EOL;
|
||||||
//copy($conf, $conf.$suffix.".bak");
|
//copy($conf, $conf.$suffix.".bak");
|
||||||
|
@ -210,11 +210,11 @@ class UpgradeCommon{
|
||||||
private static function UpdateIniValue($p_filename, $p_property, $p_value)
|
private static function UpdateIniValue($p_filename, $p_property, $p_value)
|
||||||
{
|
{
|
||||||
$lines = file($p_filename);
|
$lines = file($p_filename);
|
||||||
$n=count($lines);
|
$n = count($lines);
|
||||||
foreach ($lines as &$line) {
|
foreach ($lines as &$line) {
|
||||||
if ($line[0] != "#"){
|
if ($line[0] != "#"){
|
||||||
$key_value = explode("=", $line);
|
$key_value = explode("=", $line);
|
||||||
$key = trim($key_value[0]);
|
$key = trim($key_value[0]);
|
||||||
|
|
||||||
if ($key == $p_property){
|
if ($key == $p_property){
|
||||||
$line = "$p_property = $p_value".PHP_EOL;
|
$line = "$p_property = $p_value".PHP_EOL;
|
||||||
|
|
Loading…
Reference in New Issue