本文整理汇总了PHP中LogModel::BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP LogModel::BeginTransaction方法的具体用法?PHP LogModel::BeginTransaction怎么用?PHP LogModel::BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogModel
的用法示例。
在下文中一共展示了LogModel::BeginTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Delete a discussion. Update and/or delete all related data.
*
* Events: DeleteDiscussion.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID of discussion to delete.
* @return bool Always returns TRUE.
*/
public function delete($DiscussionID, $Options = array())
{
// Retrieve the users who have bookmarked this discussion.
$BookmarkData = $this->GetBookmarkUsers($DiscussionID);
$Data = $this->SQL->select('*')->from('Discussion')->where('DiscussionID', $DiscussionID)->get()->firstRow(DATASET_TYPE_ARRAY);
$UserID = false;
$CategoryID = false;
if ($Data) {
$UserID = $Data['InsertUserID'];
$CategoryID = $Data['CategoryID'];
}
// Prep and fire event
$this->EventArguments['DiscussionID'] = $DiscussionID;
$this->EventArguments['Discussion'] = $Data;
$this->fireEvent('DeleteDiscussion');
// Execute deletion of discussion and related bits
$this->SQL->delete('Draft', array('DiscussionID' => $DiscussionID));
$Log = val('Log', $Options, true);
$LogOptions = val('LogOptions', $Options, array());
if ($Log === true) {
$Log = 'Delete';
}
LogModel::BeginTransaction();
// Log all of the comment deletes.
$Comments = $this->SQL->getWhere('Comment', array('DiscussionID' => $DiscussionID))->resultArray();
if (count($Comments) > 0 && count($Comments) < 50) {
// A smaller number of comments should just be stored with the record.
$Data['_Data']['Comment'] = $Comments;
LogModel::insert($Log, 'Discussion', $Data, $LogOptions);
} else {
LogModel::insert($Log, 'Discussion', $Data, $LogOptions);
foreach ($Comments as $Comment) {
LogModel::insert($Log, 'Comment', $Comment, $LogOptions);
}
}
LogModel::EndTransaction();
$this->SQL->delete('Comment', array('DiscussionID' => $DiscussionID));
$this->SQL->delete('Discussion', array('DiscussionID' => $DiscussionID));
$this->SQL->delete('UserDiscussion', array('DiscussionID' => $DiscussionID));
$this->UpdateDiscussionCount($CategoryID);
// Get the user's discussion count.
$this->UpdateUserDiscussionCount($UserID);
// Update bookmark counts for users who had bookmarked this discussion
foreach ($BookmarkData->result() as $User) {
$this->SetUserBookmarkCount($User->UserID);
}
return true;
}
示例2: Delete
/**
* Delete a discussion. Update and/or delete all related data.
*
* Events: DeleteDiscussion.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID of discussion to delete.
* @return bool Always returns TRUE.
*/
public function Delete($DiscussionID, $Options = array())
{
// Retrieve the users who have bookmarked this discussion.
$BookmarkData = $this->GetBookmarkUsers($DiscussionID);
$Data = $this->SQL->Select('*')->From('Discussion')->Where('DiscussionID', $DiscussionID)->Get()->FirstRow(DATASET_TYPE_ARRAY);
$UserID = FALSE;
$CategoryID = FALSE;
if ($Data) {
$UserID = $Data['InsertUserID'];
$CategoryID = $Data['CategoryID'];
}
// Prep and fire event
$this->EventArguments['DiscussionID'] = $DiscussionID;
$this->FireEvent('DeleteDiscussion');
// Execute deletion of discussion and related bits
$this->SQL->Delete('Draft', array('DiscussionID' => $DiscussionID));
$Log = GetValue('Log', $Options, TRUE);
$LogOptions = GetValue('LogOptions', $Options, array());
if ($Log === TRUE) {
$Log = 'Delete';
}
LogModel::BeginTransaction();
LogModel::Insert($Log, 'Discussion', $Data, $LogOptions);
// Log all of the comment deletes.
$Comments = $this->SQL->GetWhere('Comment', array('DiscussionID' => $DiscussionID))->ResultArray();
foreach ($Comments as $Comment) {
LogModel::Insert($Log, 'Comment', $Comment, $LogOptions);
}
$this->SQL->Delete('Comment', array('DiscussionID' => $DiscussionID));
$this->SQL->Delete('Discussion', array('DiscussionID' => $DiscussionID));
$this->SQL->Delete('UserDiscussion', array('DiscussionID' => $DiscussionID));
$this->UpdateDiscussionCount($CategoryID);
// Get the user's discussion count
$CountDiscussions = $this->SQL->Select('DiscussionID', 'count', 'CountDiscussions')->From('Discussion')->Where('InsertUserID', $UserID)->Get()->Value('CountDiscussions', 0);
// Save the count to the user table
$this->SQL->Update('User')->Set('CountDiscussions', $CountDiscussions)->Where('UserID', $UserID)->Put();
// Update bookmark counts for users who had bookmarked this discussion
foreach ($BookmarkData->Result() as $User) {
$this->SetUserBookmarkCount($User->UserID);
}
return TRUE;
}