Ejemplo n.º 1
0
 public function delete()
 {
     $id = trim($this->input['id']);
     if (!$id) {
         $this->errorOutput('NO_ID');
     }
     //	$filed = 'id, application_id, server_id, node_id, user_id';
     $channel_info = $this->mChannel->get_channel_info_by_id($id);
     if (empty($channel_info)) {
         $this->errorOutput('该频道不存在或已被删除');
     }
     #####整合数据进行权限
     $nodes = $node_id = array();
     foreach ($channel_info as $v) {
         $node_id[] = $v['node_id'];
         $nodes[] = array('title' => $v['name'], 'delete_people' => $this->user['user_name'], 'cid' => $v['id'], 'catid' => $v['node_id'], 'user_id' => $v['user_id'], 'org_id' => $v['org_id'], 'id' => $v['id']);
     }
     if ($node_id) {
         $sql = 'SELECT id,parents FROM ' . DB_PREFIX . 'channel_node WHERE id IN(' . implode(',', $node_id) . ')';
         $query = $this->db->query($sql);
         $node_ids = array();
         while ($row = $this->db->fetch_array($query)) {
             $node_ids[$row['id']] = $row['parents'];
         }
     }
     if (!empty($nodes)) {
         foreach ($nodes as $node) {
             if ($node['catid']) {
                 $node['nodes'][$node['catid']] = $node_ids[$node['catid']];
             }
             $this->verify_content_prms($node);
         }
     }
     #####整合数据进行权限结束
     $server_id = array();
     foreach ($channel_info as $v) {
         $server_id[] = $v['server_id'];
     }
     if (!empty($server_id)) {
         $server_id = implode(',', array_unique($server_id));
         $server_infos = $this->mServerConfig->get_server_config($server_id);
     }
     foreach ($channel_info as $channel) {
         if (!empty($server_infos[$channel['server_id']])) {
             $server_type = $server_infos[$channel['server_id']]['type'];
             $server_host = $server_infos[$channel['server_id']]['host'];
             $server_dir = $server_infos[$channel['server_id']]['input_dir'];
             include_once CUR_CONF_PATH . 'lib/' . $server_type . '.live.php';
             $server = new m2oLive();
             $server->init_env(array('host' => $server_host, 'dir' => $server_dir));
             $server->delete(array('name' => $channel['code'] . '_' . $channel['main_stream_name']));
         }
         $this->mChannel->delete($channel['id']);
         $this->addLogs('删除直播频道', $channel, '', $channel['name'], $channel['id']);
     }
     /*
     $ret_output_tmp = 0;
     
     foreach ($channel_info AS $channel)
     {
     	$server_info = $this->mChannel->get_server_info($server_infos[$channel['server_id']]);
     	
     	
     	$host			= $server_info['host'];
     	$input_dir  	= $server_info['input_dir'];
     	$output_dir 	= $server_info['output_dir'];
     	
     	$live_host		= $server_info['live_host'];
     	$record_host	= $server_info['record_host'];
     	
     	$code	  	 = $channel['code'];
     	$delay  	 = $channel['delay'];
     	$is_control  = $channel['is_control'];
     	$is_live   	 = $channel['is_live'];
     	$is_record   = $channel['is_record'];
     	$type 		 = $server_infos[$channel['server_id']]['type'] ? $server_infos[$channel['server_id']]['type'] : 'wowza';
     	$super_token = $server_infos[$channel['server_id']]['super_token'];
     	
     	//检测流媒体服务器是否正常
     	$function = 'media_server_' . $type;
     	$ret_media_server = $this->$function($server_info, $super_token);
     	
     	if (!$ret_media_server['core_server'])
     	{
     		$this->errorOutput($type . '主控服务器未启动');
     	}
     	
     	if ($live_host && !$ret_media_server['live_server'])
     	{
     		$this->errorOutput($type . '直播服务器未启动');
     	}
     	
     	if ($record_host && !$ret_media_server['record_server'])
     	{
     		$this->errorOutput($type . '录制服务器未启动');
     	}
     	
     	$return = array();
     	if (!empty($channel['channel_stream']))
     	{
     		foreach ($channel['channel_stream'] AS $kk => $channel_stream)
     		{
     			$channel_stream['code']		  = $code;
     			$channel_stream['is_control'] = $is_control;
     			$channel_stream['delay'] 	  = $delay;
     			$channel_stream['is_live']	  = $is_live;
     			$channel_stream['is_record']  = $is_record;
     			
     			//调用流媒体服务器函数
     			$function 	= 'stream_operate_' . $type;
     			$return[$kk] = $this->$function($server_info, $channel_stream, 'delete');
     		}
     	}
     	
     	$flag = 0;
     	foreach ($return AS $v)
     	{
     		if (!$v['ret_output_id'])
     		{
     			$flag = 1;
     		}
     		
     		//直播
     		if ($live_host && !$v['ret_live_output_id'])
     		{
     			$flag = 1;
     		}
     		
     		//录制
     		if ($record_host && !$v['ret_record_output_id'])
     		{
     			$flag = 1;
     		}
     	}
     	
     	if (!$flag)
     	{
     		$tmp_delete = 0;
     		if ($channel['application_id'])
     		{
     			$application_data = array(
     				'action'	=> 'delete',
     				'id'		=> $channel['application_id'],
     			);
     			
     			$ret_application = $this->mLivemms->outputApplicationOperate($host, $output_dir, $application_data);
     			if (!$ret_application['result'])
     			{
     				$tmp_delete = 1;
     				continue;
     			}
     			
     			//直播
     			if ($live_host && $is_live)
     			{
     				$ret_application = $this->mLivemms->outputApplicationOperate($live_host, $output_dir, $application_data);
     				
     				if (!$ret_application['result'])
     				{
     					$tmp_delete = 1;
     					continue;
     				}
     			}
     			
     			//录制
     			if ($record_host && $is_record)
     			{
     				$ret_application = $this->mLivemms->outputApplicationOperate($record_host, $output_dir, $application_data);
     				
     				if (!$ret_application['result'])
     				{
     					$tmp_delete = 1;
     					continue;
     				}
     			}
     		}
     		
     		if (!$tmp_delete)
     		{
     			$ret_delete = $this->mChannel->delete($channel['id']);
     				
     			//记录日志
     			$pre_data = $channel;
     			$this->addLogs('删除直播频道' , $pre_data , '' , $channel['name'] ,$channel['id']);
     		}
     	}
     	else 
     	{
     		$this->errorOutput($channel['name'] . '频道删除失败');
     	}
     }
     */
     //删除播控和串联层
     if ($this->settings['schedule_control_wowza']['is_wowza'] && $channel_info) {
         $host = $this->settings['schedule_control_wowza']['host'];
         $apidir = $this->settings['schedule_control_wowza']['inputdir'];
         foreach ($channel_info as $v) {
             $schedule_control = unserialize($v['schedule_control']);
             //file_put_contents(CACHE_DIR . 'debug.txt', var_export($schedule_control,1));
             if ($schedule_control) {
                 foreach ($schedule_control as $app => $value) {
                     $this->mLivemms->inputStreamOperate($host, $apidir, array('action' => 'delete', 'id' => $value['stream_id']));
                     $this->mLivemms->inputOutputStreamOperate($host, $apidir, array('action' => 'delete', 'id' => $value['output_id']));
                 }
             }
         }
     }
     //同步删除串联的的channel_server
     if ($this->settings['App_schedule'] && $this->settings['schedule_control_wowza']['is_wowza']) {
         require_once ROOT_PATH . 'lib/class/curl.class.php';
         $schedule_api = new curl($this->settings['App_schedule']['host'], $this->settings['App_schedule']['dir']);
         $schedule_api->initPostData();
         $schedule_api->addRequestData('channel_id', $id);
         foreach ($_schedule_control['schedule'] as $key => $val) {
             $schedule_api->addRequestData($key, $val);
         }
         $schedule_api->addRequestData('a', 'cancell_wowza_schedule');
         $is_syn = $schedule_api->request('schedule.php');
         if ($is_syn[0] !== 'success') {
             file_put_contents(CACHE_DIR . 'debug.txt', var_export($is_syn, 1));
         }
     }
     $this->addItem($id);
     $this->output();
 }