当前位置: 首页>>代码示例>>PHP>>正文


PHP LogModel::_TransactionID方法代码示例

本文整理汇总了PHP中LogModel::_TransactionID方法的典型用法代码示例。如果您正苦于以下问题:PHP LogModel::_TransactionID方法的具体用法?PHP LogModel::_TransactionID怎么用?PHP LogModel::_TransactionID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogModel的用法示例。


在下文中一共展示了LogModel::_TransactionID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insert

 /**
  * Log an operation into the log table.
  *
  * @param string $Operation The operation being performed. This is usually one of:
  *  - Delete: The record has been deleted.
  *  - Edit: The record has been edited.
  *  - Spam: The record has been marked spam.
  *  - Moderate: The record requires moderation.
  *  - Pending: The record needs pre-moderation.
  * @param string $RecordType The type of record being logged. This usually correspond to the tablename of the record.
  * @param array $Data The record data.
  *  - If you are logging just one row then pass the row as an array.
  *  - You can pass an additional _New element to tell the logger what the new data is.
  * @return int The log id.
  */
 public static function insert($Operation, $RecordType, $Data, $Options = array())
 {
     if ($Operation === false) {
         return;
     }
     // Check to see if we are storing two versions of the data.
     if (($InsertUserID = self::_LogValue($Data, 'Log_InsertUserID')) === null) {
         $InsertUserID = Gdn::session()->UserID;
     }
     if (($InsertIPAddress = self::_LogValue($Data, 'Log_InsertIPAddress')) == null) {
         $InsertIPAddress = Gdn::request()->IPAddress();
     }
     // Do some known translations for the parent record ID.
     if (($ParentRecordID = self::_LogValue($Data, 'ParentRecordID')) === null) {
         switch ($RecordType) {
             case 'Activity':
                 $ParentRecordID = self::_LogValue($Data, 'CommentActivityID', 'CommentActivityID');
                 break;
             case 'Comment':
                 $ParentRecordID = self::_LogValue($Data, 'DiscussionID', 'DiscussionID');
                 break;
         }
     }
     // Get the row information from the data or determine it based on the type.
     $LogRow = array('Operation' => $Operation, 'RecordType' => $RecordType, 'RecordID' => self::_LogValue($Data, 'RecordID', $RecordType . 'ID'), 'RecordUserID' => self::_LogValue($Data, 'RecordUserID', 'UpdateUserID', 'InsertUserID'), 'RecordIPAddress' => self::_LogValue($Data, 'RecordIPAddress', 'LastIPAddress', 'InsertIPAddress'), 'RecordDate' => self::_LogValue($Data, 'RecordDate', 'DateUpdated', 'DateInserted'), 'InsertUserID' => $InsertUserID, 'InsertIPAddress' => $InsertIPAddress, 'DateInserted' => Gdn_Format::toDateTime(), 'ParentRecordID' => $ParentRecordID, 'CategoryID' => self::_LogValue($Data, 'CategoryID'), 'OtherUserIDs' => implode(',', val('OtherUserIDs', $Options, array())), 'Data' => serialize($Data));
     if ($LogRow['RecordDate'] == null) {
         $LogRow['RecordDate'] = Gdn_Format::toDateTime();
     }
     $GroupBy = val('GroupBy', $Options);
     // Make sure we aren't grouping by null values.
     if (is_array($GroupBy)) {
         foreach ($GroupBy as $Name) {
             if (val($Name, $LogRow) === null) {
                 $GroupBy = false;
                 break;
             }
         }
     }
     if ($GroupBy) {
         $GroupBy[] = 'Operation';
         $GroupBy[] = 'RecordType';
         // Check to see if there is a record already logged here.
         $Where = array_combine($GroupBy, arrayTranslate($LogRow, $GroupBy));
         $LogRow2 = Gdn::sql()->getWhere('Log', $Where)->firstRow(DATASET_TYPE_ARRAY);
         if ($LogRow2) {
             $LogID = $LogRow2['LogID'];
             $Set = array();
             $Data = array_merge(unserialize($LogRow2['Data']), $Data);
             $OtherUserIDs = explode(',', $LogRow2['OtherUserIDs']);
             if (!is_array($OtherUserIDs)) {
                 $OtherUserIDs = array();
             }
             if (!$LogRow2['InsertUserID']) {
                 $Set['InsertUserID'] = $InsertUserID;
             } elseif ($InsertUserID != $LogRow2['InsertUserID'] && !in_array($InsertUserID, $OtherUserIDs)) {
                 $OtherUserIDs[] = $InsertUserID;
             }
             if (array_key_exists('OtherUserIDs', $Options)) {
                 $OtherUserIDs = array_merge($OtherUserIDs, $Options['OtherUserIDs']);
                 $OtherUserIDs = array_unique($OtherUserIDs);
                 $OtherUserIDs = array_diff($OtherUserIDs, array($InsertUserID));
                 $Count = count($OtherUserIDs) + 1;
             } else {
                 $Count = (int) $LogRow2['CountGroup'] + 1;
             }
             $Set['OtherUserIDs'] = implode(',', $OtherUserIDs);
             $Set['CountGroup'] = $Count;
             $Set['Data'] = serialize($Data);
             $Set['DateUpdated'] = Gdn_Format::toDateTime();
             if (self::$_TransactionID > 0) {
                 $Set['TransactionLogID'] = self::$_TransactionID;
             } elseif (self::$_TransactionID === true) {
                 if ($LogRow2['TransactionLogID']) {
                     self::$_TransactionID = $LogRow2['TransactionLogID'];
                 } else {
                     self::$_TransactionID = $LogID;
                     $Set['TransactionLogID'] = $LogID;
                 }
             }
             Gdn::sql()->put('Log', $Set, array('LogID' => $LogID));
         } else {
             $L = self::_Instance();
             $L->EventArguments['Log'] =& $LogRow;
             $L->fireEvent('BeforeInsert');
             if (self::$_TransactionID > 0) {
//.........这里部分代码省略.........
开发者ID:sitexa,项目名称:vanilla,代码行数:101,代码来源:class.logmodel.php


注:本文中的LogModel::_TransactionID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。