Beispiel #1
0
 /**
  * 主动输出接口
  * 
  * 功能:解析本地的序列文件向指定的被动输入接口发送数据
  * 
  * 参数:无
  * 返回值:无
  */
 public static function InitiativeOutput()
 {
     //echo microtime()."<br>";
     $loger = new Pft_Log_File('sync');
     //访问权限判断
     if (!Pft_Sync_MessageListManage::interfaceAuth('InitiativeOutput')) {
         //写日志
         $str = '没有访问此接口的权限';
         $loger = new Pft_Log_File('sync');
         $loger->log($str);
         exit;
     }
     //判断是否锁定
     if (Pft_Sync_MessageListManage::isLock('output')) {
         //如果锁定
         exit;
     }
     //锁定接口
     Pft_Sync_MessageListManage::AddLock('output');
     //调用消息序列管理器,获取消息序列
     /*
     $msg = new MSG();
     $msg->openMsgPool();
     while( $msg->getMsg() ){
     	
     }
     */
     //获取所有的SQL消息
     $msgSqlArray = Pft_Sync_MessageListManage::getAllMessageSql();
     $msgSqlValue = array();
     if (is_array($msgSqlArray) && count($msgSqlArray)) {
         foreach ($msgSqlArray as $k => $v) {
             $rev = Pft_Sync_MessageListManage::executeMessageSql($v);
             if ($rev) {
                 //获取外部被动输入接口地址
                 $passiveInputAddress = Pft_Sync_MessageListManage::getPassiveInputInterface('INSIDE_TPM');
                 if ($passiveInputAddress) {
                     //获取地址成功
                     //以post的方式向接口提交数据
                     $data = array('obj' => 'msgSqlValue', 'msgList' => urlencode(serialize($rev)), 'msgSign' => urlencode(serialize($k)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     if (BaseOption::postToHost($passiveInputAddress, $data)) {
                         //成功
                         //删除消息SQL
                         Pft_Sync_MessageListManage::delMessageSql($k);
                     } else {
                         //移动消息SQL
                         Pft_Sync_MessageListManage::moveMsgSql($k);
                     }
                 }
             }
         }
     }
     //消息序列的处理
     //------------外部unknown中的数据处理  start---------------//
     //获取外部被动输入接口地址
     $passiveInputAddress = Pft_Sync_MessageListManage::getPassiveInputInterface('INSIDE_TPM');
     $passiveOutputAddress = Pft_Sync_MessageListManage::getPassiveOutputInterface();
     if ($passiveOutputAddress) {
         //获取外部unknown目录中的数据
         $data = array('msgType' => 'msglist', 'msgListDir' => 'unknown', 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
         $msgList_unknown = BaseOption::postToHost($passiveOutputAddress, $data);
         $msgSign_outsite_unknown = unserialize($msgList_unknown);
         if (is_array($msgSign_outsite_unknown) && count($msgSign_outsite_unknown)) {
             //unknown目录中存在数据
             $msgSignArr = array_keys($msgSign_outsite_unknown);
             //删除本地的消息
             //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr)
             $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
             if ($result) {
                 //删除成功
                 //告诉外部,将序列从unknown中移动到outside
                 $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                 $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                 if ($rev1) {
                 } else {
                     $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                     //解除锁定
                     Pft_Sync_MessageListManage::DelLock('output');
                     exit;
                 }
             } else {
                 $loger->log('删除内部消息序列失败');
                 //解除锁定
                 Pft_Sync_MessageListManage::DelLock('output');
                 exit;
             }
         }
     }
     //------------外部unknown中的数据处理  end---------------//
     //获取所有的消息序列
     $msgListArray = Pft_Sync_MessageListManage::getAllMessageList();
     $msgList_execute = array();
     $num_del = Pft_Sync_MessageListManage::getNumOnceDel();
     //一次删除消息序列的个数
     if (is_array($msgListArray) && count($msgListArray) && $passiveInputAddress) {
         $str = "访问的被动输入接口:" . $passiveInputAddress;
         $loger = new Pft_Log_File('sync');
         $loger->log($str);
         foreach ($msgListArray as $key => $val) {
             foreach ($val as $k => $v) {
                 //--------------------- 数据过滤器  start---------------------//
                 //根据创建消息序列的服务器类型获取过滤器
                 $filterNameList = Pft_Sync_MessageListManage::getMsgListFilter($v['syncServerType']);
                 //调用过滤器过滤数据
                 if (is_array($filterNameList) && count($filterNameList)) {
                     foreach ($filterNameList as $filterName) {
                         $aFilter = Pft_Sync_Filter::filterFactory($filterName);
                         if ($aFilter) {
                             $v = $aFilter->filter($v);
                         }
                     }
                 }
                 //如果字段为空,删除消息序列
                 if (($v['operate'] == 'UPDATE' || $v['operate'] == 'INSERT') && !count($v['cols']) || !count($v)) {
                     //删除序列
                     //Pft_Sync_MessageListManage::delMessageList($key);
                     unset($val[$k]);
                     continue;
                 }
                 //--------------------- 数据过滤器  end---------------------//
                 if (count($msgList_execute) < $num_del - 1) {
                     $msgList_execute[$key] = $val;
                 } else {
                     //满足个数
                     $msgList_execute[$key] = $val;
                     $msgSignArr = array_keys($msgList_execute);
                     //向被动输入接口传数据,移动到未明目录
                     $data = array('obj' => 'file', 'msgList' => urlencode(serialize($msgList_execute)), 'msgListDir' => 'unknown', 'msgSign' => urlencode(serialize('')), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     $rev = BaseOption::postToHost($passiveInputAddress, $data);
                     if ($rev == '1') {
                         //删除
                         //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr)
                         $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
                         if ($result) {
                             //删除成功
                             //以post的方式向接口提交数据
                             $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                             $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                             if ($rev1 == '1') {
                                 //清空数组
                                 $msgList_execute = array();
                             } else {
                                 //移动失败
                                 $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                                 //解除锁定
                                 Pft_Sync_MessageListManage::DelLock('output');
                                 exit;
                             }
                         } else {
                             //删除失败
                             $loger->log('删除内部消息序列失败');
                             //解除锁定
                             Pft_Sync_MessageListManage::DelLock('output');
                             exit;
                         }
                     } else {
                         $loger->log('移动消息序列到unknown目录失败,访问接口:' . $passiveInputAddress);
                         //解除锁定
                         Pft_Sync_MessageListManage::DelLock('output');
                         exit;
                     }
                 }
             }
             /*
             				//--------------------- 数据过滤器  start---------------------//
             				//根据创建消息序列的服务器类型获取过滤器
             				$filterNameList = Pft_Sync_MessageListManage::getMsgListFilter($val['syncServerType']);				
             				//调用过滤器过滤数据				
             				if(is_array($filterNameList) && count($filterNameList))
             				{
             					foreach ( $filterNameList as $filterName )
             					{
             						$aFilter = Pft_Sync_Filter::filterFactory( $filterName );
             						if( $aFilter ){
             							$val = $aFilter->filter( $val );
             						}
             					}
             				}
             				
             				//如果字段为空,删除消息序列
             				if((($val['operate']=='UPDATE'||$val['operate']=='INSERT') && !count($val['cols'])) || !count($val)){
             					//删除序列
             					Pft_Sync_MessageListManage::delMessageList($key);
             					continue;
             				}	
             				//--------------------- 数据过滤器  end---------------------//
             				
             				if (count($msgList_execute)<($num_del-1))
             				{
             					$msgList_execute[$key] = $val;
             				}else
             				{//满足个数
             					$msgList_execute[$key] = $val;
             					$msgSignArr = array_keys($msgList_execute);	
             					//向被动输入接口传数据,移动到未明目录
             					$data = array(
             									'obj' =>'file',
             									'msgList' => urlencode(serialize($msgList_execute)),
             									'msgListDir' => 'unknown',
             									'msgSign' => urlencode(serialize('')),
             									'validatePassword'=>Pft_Sync_MessageListManage::getValidatePassword()
             								);	
             					$rev = BaseOption::postToHost($passiveInputAddress,$data);	
             					if ($rev == '1'){
             						//删除
             						if (Pft_Sync_MessageListManage::delMessageList($msgSignArr))
             						{//删除成功
             							//以post的方式向接口提交数据
             							$data = array(
             											'obj' =>'file',
             											'msgList' => urlencode(serialize('')),
             											'msgListDir' => 'outside',
             											'msgSign' => urlencode(serialize($msgSignArr)),
             											'validatePassword'=>Pft_Sync_MessageListManage::getValidatePassword()
             										);		
             														
             							$rev1 = BaseOption::postToHost($passiveInputAddress,$data);	
             							if ($rev1 == '1'){
             								//清空数组
             								$msgList_execute=array();	
             							}else{//移动失败								
             								$loger->log( '移动消息序列到outside目录失败,访问接口:'.$passiveInputAddress );
             								//解除锁定
             								Pft_Sync_MessageListManage::DelLock('output');
             								exit;
             							}
             						}else
             						{//删除失败
             							$loger->log( '删除内部消息序列失败' );
             							//解除锁定
             							Pft_Sync_MessageListManage::DelLock('output');
             							exit;
             						}
             					}else
             					{
             						$loger->log( '移动消息序列到unknown目录失败,访问接口:'.$passiveInputAddress );
             						//解除锁定
             						Pft_Sync_MessageListManage::DelLock('output');
             						exit;
             					}	
             				}*/
         }
         //最后不满足个数的操作
         if (is_array($msgList_execute) && count($msgList_execute)) {
             $msgSignArr = array_keys($msgList_execute);
             //向被动输入接口传数据,移动到未明目录
             $data = array('obj' => 'file', 'msgList' => urlencode(serialize($msgList_execute)), 'msgListDir' => 'unknown', 'msgSign' => urlencode(serialize('')), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
             $rev = BaseOption::postToHost($passiveInputAddress, $data);
             if ($rev) {
                 //删除
                 //$result = Pft_Sync_MessageListManage::delMessageList($msgSignArr);
                 $result = Pft_Sync_MessageListManage::moveMsglistOld($msgSignArr);
                 if ($result) {
                     //删除成功
                     //以post的方式向接口提交数据
                     $data = array('obj' => 'file', 'msgList' => urlencode(serialize('')), 'msgListDir' => 'outside', 'msgSign' => urlencode(serialize($msgSignArr)), 'validatePassword' => Pft_Sync_MessageListManage::getValidatePassword());
                     $rev1 = BaseOption::postToHost($passiveInputAddress, $data);
                     if ($rev1 == '1') {
                         //清空数组
                         $msgList_execute = array();
                     } else {
                         //移动失败
                         $loger->log('移动消息序列到outside目录失败,访问接口:' . $passiveInputAddress);
                         //解除锁定
                         Pft_Sync_MessageListManage::DelLock('output');
                         exit;
                     }
                 } else {
                     //删除失败
                     $loger->log('删除内部消息序列失败');
                     //解除锁定
                     Pft_Sync_MessageListManage::DelLock('output');
                     exit;
                 }
             } else {
                 $loger->log('移动消息序列到unknown目录失败,访问接口:' . $passiveInputAddress);
                 //解除锁定
                 Pft_Sync_MessageListManage::DelLock('output');
                 exit;
             }
         }
     }
     //解除锁定
     Pft_Sync_MessageListManage::DelLock('output');
     //echo microtime()."<br>";
 }
Beispiel #2
0
 /**
  * 获取运行时间
  *
  * 参数: void
  * 返回: float
  * 作用域: public
  * 日期: 2005-6-8
  */
 function getTimeLimit()
 {
     return BaseOption::getmicrotime() - SYS_TIME_SRART;
 }
Beispiel #3
0
 public function __construct($pathFilename)
 {
     //目录不存在则创建
     if (!is_dir(dirname($pathFilename))) {
         BaseOption::create_dir($pathFilename);
     }
     $this->setFilename($pathFilename);
     $this->_tmpFilename = $pathFilename . ".tmp";
     $this->_fPoint = @fopen($this->_tmpFilename, 'a');
     if (!$this->_fPoint) {
         Watt_Log::addLog('Cannot create file [' . $this->_tmpFilename . ']');
     }
 }
Beispiel #4
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Beispiel #5
0
 /**
  * @desc 对象类具备的增加的基本功能,作为到数据库的转换接口
  *
  * @param String $TableName 表格名称
  * @param Array $res N1/N2
  * @return BOOLEAN
  */
 function copyRow($TableName, $res)
 {
     //		echo "app_add";
     //		var_dump($res);
     //		if (isset($_SESSION['user']['company_data']['company_name']))
     //		{
     //			$system_gongsi = $_SESSION['user']['company_data']['company_name'];
     //		} else
     //		{
     //			$system_gongsi = SYSTEM_GONGSI;
     //		}
     if ($TableName == null) {
         return false;
     } else {
         $sql = 'INSERT INTO ' . $TableName;
     }
     if (is_array($res)) {
         $sqlKeys = null;
         $sqlVals = null;
         foreach ($res as $key => $val) {
             if (is_array($val)) {
                 foreach ($val as $key2 => $val2) {
                     $sqlKeys .= $key . ',';
                     $sqlVals .= $val . ',';
                 }
                 $sqlKeys = BaseOption::subStringByDescCount($sqlKeys);
                 $sqlVals = BaseOption::subStringByDescCount($sqlVals);
                 $sqls = $sql . " (" . $sqlKeys . ") VALUES (" . $sqlVals . ")";
                 if ($this->_query($sqls)) {
                     unset($sqlKeys);
                     unset($sqlVals);
                     unset($sqls);
                 }
             } else {
                 $sqlKeys .= $key . ',';
                 $sqlVals .= "'" . $val . "',";
             }
         }
         if ($sqlKeys != null && $sqlVals != null) {
             $sqlKeys = BaseOption::subStringByDescCount($sqlKeys);
             $sqlVals = BaseOption::subStringByDescCount($sqlVals);
             /**
              * 添加默认值 
              */
             /*if (!array_key_exists('system_gongsi', $res))
             		{
             			$sqlKeys .= ',system_gongsi';
             			$sqlVals .= ",'".$system_gongsi . "'";
             		}*/
             $sqls = $sql . " (" . $sqlKeys . ") VALUES (" . $sqlVals . ")";
             if ($this->execute($sqls)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }