本文整理汇总了PHP中LogModel::Insert方法的典型用法代码示例。如果您正苦于以下问题:PHP LogModel::Insert方法的具体用法?PHP LogModel::Insert怎么用?PHP LogModel::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogModel
的用法示例。
在下文中一共展示了LogModel::Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: IsSpam
/**
* Check whether or not the record is spam.
* @param string $RecordType By default, this should be one of the following:
* - Comment: A comment.
* - Discussion: A discussion.
* - User: A user registration.
* @param array $Data The record data.
* @param array $Options Options for fine-tuning this method call.
* - Log: Log the record if it is found to be spam.
*/
public static function IsSpam($RecordType, $Data, $Options = array()) {
// Set some information about the user in the data.
TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress());
if ($RecordType == 'User') {
TouchValue('Username', $Data, $Data['Name']);
} else {
TouchValue('Username', $Data, Gdn::Session()->User->Name);
TouchValue('Email', $Data, Gdn::Session()->User->Email);
}
$Sp = self::_Instance();
$Sp->EventArguments['RecordType'] = $RecordType;
$Sp->EventArguments['Data'] = $Data;
$Sp->EventArguments['Options'] = $Options;
$Sp->EventArguments['IsSpam'] = FALSE;
$Sp->FireEvent('CheckSpam');
$Spam = $Sp->EventArguments['IsSpam'];
// Log the spam entry.
if ($Spam && GetValue('Log', $Options, TRUE)) {
LogModel::Insert('Spam', $RecordType, $Data);
}
return $Spam;
}
示例2: IsSpam
/**
* Check whether or not the record is spam.
* @param string $RecordType By default, this should be one of the following:
* - Comment: A comment.
* - Discussion: A discussion.
* - User: A user registration.
* @param array $Data The record data.
* @param array $Options Options for fine-tuning this method call.
* - Log: Log the record if it is found to be spam.
*/
public static function IsSpam($RecordType, $Data, $Options = array())
{
// Set some information about the user in the data.
TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress());
if ($RecordType == 'Registration') {
TouchValue('Username', $Data, $Data['Name']);
} else {
TouchValue('Username', $Data, Gdn::Session()->User->Name);
TouchValue('Email', $Data, Gdn::Session()->User->Email);
}
$Sp = self::_Instance();
$Sp->EventArguments['RecordType'] = $RecordType;
$Sp->EventArguments['Data'] =& $Data;
$Sp->EventArguments['Options'] =& $Options;
$Sp->EventArguments['IsSpam'] = FALSE;
$Sp->FireEvent('CheckSpam');
$Spam = $Sp->EventArguments['IsSpam'];
// Log the spam entry.
if ($Spam && GetValue('Log', $Options, TRUE)) {
$LogOptions = array();
switch ($RecordType) {
case 'Registration':
$LogOptions['GroupBy'] = array('RecordIPAddress');
break;
case 'Comment':
case 'Discussion':
$LogOptions['GroupBy'] = array('RecordID');
break;
}
LogModel::Insert('Spam', $RecordType, $Data, $LogOptions);
}
return $Spam;
}
示例3: IsSpam
/**
* Check whether or not the record is spam.
* @param string $RecordType By default, this should be one of the following:
* - Comment: A comment.
* - Discussion: A discussion.
* - User: A user registration.
* @param array $Data The record data.
* @param array $Options Options for fine-tuning this method call.
* - Log: Log the record if it is found to be spam.
*/
public static function IsSpam($RecordType, $Data, $Options = array())
{
if (self::$Disabled) {
return FALSE;
}
// Set some information about the user in the data.
if ($RecordType == 'Registration') {
TouchValue('Username', $Data, $Data['Name']);
} else {
TouchValue('InsertUserID', $Data, Gdn::Session()->UserID);
$User = Gdn::UserModel()->GetID(GetValue('InsertUserID', $Data), DATASET_TYPE_ARRAY);
if ($User) {
if (GetValue('Verified', $User)) {
// The user has been verified and isn't a spammer.
return FALSE;
}
TouchValue('Username', $Data, $User['Name']);
TouchValue('Email', $Data, $User['Email']);
TouchValue('IPAddress', $Data, $User['LastIPAddress']);
}
}
if (!isset($Data['Body']) && isset($Data['Story'])) {
$Data['Body'] = $Data['Story'];
}
TouchValue('IPAddress', $Data, Gdn::Request()->IpAddress());
$Sp = self::_Instance();
$Sp->EventArguments['RecordType'] = $RecordType;
$Sp->EventArguments['Data'] =& $Data;
$Sp->EventArguments['Options'] =& $Options;
$Sp->EventArguments['IsSpam'] = FALSE;
$Sp->FireEvent('CheckSpam');
$Spam = $Sp->EventArguments['IsSpam'];
// Log the spam entry.
if ($Spam && GetValue('Log', $Options, TRUE)) {
$LogOptions = array();
switch ($RecordType) {
case 'Registration':
$LogOptions['GroupBy'] = array('RecordIPAddress');
break;
case 'Comment':
case 'Discussion':
case 'Activity':
case 'ActivityComment':
$LogOptions['GroupBy'] = array('RecordID');
break;
}
LogModel::Insert('Spam', $RecordType, $Data, $LogOptions);
}
return $Spam;
}
示例4: Delete
/**
* Delete a comment.
*
* This is a hard delete that completely removes it from the database.
* Events: DeleteComment.
*
* @since 2.0.0
* @access public
*
* @param int $CommentID Unique ID of the comment to be deleted.
* @param array $Options Additional options for the delete.
* @param bool Always returns TRUE.
*/
public function Delete($CommentID, $Options = array())
{
$this->EventArguments['CommentID'] = $CommentID;
$Comment = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
if (!$Comment) {
return FALSE;
}
// Decrement the UserDiscussion comment count if the user has seen this comment
$Offset = $this->GetOffset($CommentID);
$this->SQL->Update('UserDiscussion')->Set('CountComments', 'CountComments - 1', FALSE)->Where('DiscussionID', $Comment['DiscussionID'])->Where('CountComments >', $Offset)->Put();
$this->FireEvent('DeleteComment');
// Log the deletion.
$Log = GetValue('Log', $Options, 'Delete');
LogModel::Insert($Log, 'Comment', $Comment);
// Delete the comment.
$this->SQL->Delete('Comment', array('CommentID' => $CommentID));
// Update the comment count
$this->UpdateCommentCount($Comment['DiscussionID']);
// Update the user's comment count
$this->UpdateUser($Comment['InsertUserID']);
// Clear the page cache.
$this->RemovePageCache($Comment['DiscussionID']);
return TRUE;
}
示例5: Save
public function Save($Data, $Preference = FALSE, $Options = array())
{
Trace('ActivityModel->Save()');
$Activity = $Data;
$this->_Touch($Activity);
if ($Activity['ActivityUserID'] == $Activity['NotifyUserID'] && !GetValue('Force', $Options)) {
Trace('Skipping activity because it would notify the user of something they did.');
return;
// don't notify users of something they did.
}
// Check the user's preference.
if ($Preference) {
list($Popup, $Email) = self::NotificationPreference($Preference, $Activity['NotifyUserID'], 'both');
if ($Popup && !$Activity['Notified']) {
$Activity['Notified'] = self::SENT_PENDING;
}
if ($Email && !$Activity['Emailed']) {
$Activity['Emailed'] = self::SENT_PENDING;
}
if (!$Activity['Notified'] && !$Activity['Emailed'] && !GetValue('Force', $Options)) {
Trace("Skipping activity because the user has no preference set.");
return;
}
}
$ActivityType = self::GetActivityType($Activity['ActivityType']);
$ActivityTypeID = ArrayValue('ActivityTypeID', $ActivityType);
if (!$ActivityTypeID) {
Trace("There is no {$ActivityType} activity type.", TRACE_WARNING);
$ActivityType = self::GetActivityType('Default');
$ActivityTypeID = ArrayValue('ActivityTypeID', $ActivityType);
}
$Activity['ActivityTypeID'] = $ActivityTypeID;
$NotificationInc = 0;
if ($Activity['NotifyUserID'] > 0 && $Activity['Notified']) {
$NotificationInc = 1;
}
// Check to see if we are sharing this activity with another one.
if ($CommentActivityID = GetValue('CommentActivityID', $Activity['Data'])) {
$CommentActivity = $this->GetID($CommentActivityID);
$Activity['Data']['CommentNotifyUserID'] = $CommentActivity['NotifyUserID'];
}
// Make sure this activity isn't a duplicate.
if (GetValue('CheckRecord', $Options)) {
// Check to see if this record already notified so we don't notify multiple times.
$Where = ArrayTranslate($Activity, array('NotifyUserID', 'RecordType', 'RecordID'));
$Where['DateUpdated >'] = Gdn_Format::ToDateTime(strtotime('-2 days'));
// index hint
$CheckActivity = $this->SQL->GetWhere('Activity', $Where)->FirstRow();
if ($CheckActivity) {
return FALSE;
}
}
// Check to share the activity.
if (GetValue('Share', $Options)) {
$this->Share($Activity);
}
// Group he activity.
if ($GroupBy = GetValue('GroupBy', $Options)) {
$GroupBy = (array) $GroupBy;
$Where = array();
foreach ($GroupBy as $ColumnName) {
$Where[$ColumnName] = $Activity[$ColumnName];
}
$Where['NotifyUserID'] = $Activity['NotifyUserID'];
// Make sure to only group activities by day.
$Where['DateInserted >'] = Gdn_Format::ToDateTime(strtotime('-1 day'));
// See if there is another activity to group these into.
$GroupActivity = $this->SQL->GetWhere('Activity', $Where)->FirstRow(DATASET_TYPE_ARRAY);
if ($GroupActivity) {
$GroupActivity['Data'] = @unserialize($GroupActivity['Data']);
$Activity = $this->MergeActivities($GroupActivity, $Activity);
$NotificationInc = 0;
}
}
$Delete = FALSE;
if ($Activity['Emailed'] == self::SENT_PENDING) {
$this->Email($Activity);
$Delete = GetValue('_Delete', $Activity);
}
$ActivityData = $Activity['Data'];
if (isset($Activity['Data']) && is_array($Activity['Data'])) {
$Activity['Data'] = serialize($Activity['Data']);
}
$this->DefineSchema();
$Activity = $this->FilterSchema($Activity);
$ActivityID = GetValue('ActivityID', $Activity);
if (!$ActivityID) {
if (!$Delete) {
$this->AddInsertFields($Activity);
TouchValue('DateUpdated', $Activity, $Activity['DateInserted']);
$this->EventArguments['Activity'] =& $Activity;
$this->EventArguments['ActivityID'] = NULL;
$this->FireEvent('BeforeSave');
if (count($this->ValidationResults()) > 0) {
return FALSE;
}
if (GetValue('CheckSpam', $Options)) {
// Check for spam
$Spam = SpamModel::IsSpam('Activity', $Activity);
if ($Spam) {
//.........这里部分代码省略.........
示例6: Delete
/**
* Delete a comment.
*
* This is a hard delete that completely removes it from the database.
* Events: DeleteComment.
*
* @since 2.0.0
* @access public
*
* @param int $CommentID Unique ID of the comment to be deleted.
* @param bool Always returns TRUE.
*/
public function Delete($CommentID) {
$this->EventArguments['CommentID'] = $CommentID;
// Grab the comment to check on it.
$Data = $this->SQL
->Select('c.*, d.LastCommentID, d.DateInserted as DiscussionDateInserted')
->From('Comment c')
->Join('Discussion d', 'c.DiscussionID = d.DiscussionID')
->Where('c.CommentID', $CommentID)
->Get()->FirstRow(DATASET_TYPE_ARRAY);
if ($Data) {
// If this is the last comment, get the one before and update the LastCommentID field
if ($Data['LastCommentID'] == $CommentID) {
$OldData = $this->SQL
->Select('c.CommentID, c.InsertUserID, c.DateInserted')
->From('Comment c')
->Where('c.DiscussionID', $Data['DiscussionID'])
->OrderBy('c.DateInserted', 'desc')
->Limit(1, 1)
->Get()->FirstRow(DATASET_TYPE_ARRAY);
if (is_array($OldData)) {
$this->SQL->Update('Discussion')
->Set('LastCommentID', $OldData['CommentID'])
->Set('LastCommentUserID', $OldData['InsertUserID'])
->Set('DateLastComment', $OldData['DateInserted'])
->Where('DiscussionID', $Data['DiscussionID'])
->Put();
} else { // It was the ONLY comment
$this->SQL->Update('Discussion')
->Set('LastCommentID', NULL)
->Set('LastCommentUserID', NULL)
->Set('DateLastComment', $Data['DateInserted'])
->Where('DiscussionID', $Data['DiscussionID'])
->Put();
}
}
// Decrement the UserDiscussion comment count if the user has seen this comment
$Offset = $this->GetOffset($CommentID);
$this->SQL->Update('UserDiscussion')
->Set('CountComments', 'CountComments - 1', FALSE)
->Where('DiscussionID', $Data['DiscussionID'])
->Where('CountComments >', $Offset)
->Put();
// Decrement the Discussion's Comment Count
$this->SQL->Update('Discussion')
->Set('CountComments', 'CountComments - 1', FALSE)
->Where('DiscussionID', $Data['DiscussionID'])
->Put();
$this->FireEvent('DeleteComment');
// Log the deletion.
unset($Data['LastCommentID'], $Data['DiscussionDateInserted']);
LogModel::Insert('Delete', 'Comment', $Data);
// Delete the comment.
$this->SQL->Delete('Comment', array('CommentID' => $CommentID));
// Update the user's comment count
$this->UpdateUser($Data['InsertUserID']);
}
return TRUE;
}
示例7: 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();
// 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;
}
示例8: DeleteContent
public function DeleteContent($UserID, $Options = array(), $Content = array())
{
$Log = GetValue('Log', $Options);
if ($Log === TRUE) {
$Log = 'Delete';
}
$Result = FALSE;
// Fire an event so applications can remove their associated user data.
$this->EventArguments['UserID'] = $UserID;
$this->EventArguments['Options'] = $Options;
$this->EventArguments['Content'] =& $Content;
$this->FireEvent('BeforeDeleteUser');
$User = $this->GetID($UserID, DATASET_TYPE_ARRAY);
if (!$Log) {
$Content = NULL;
}
// Remove photos
/*$PhotoData = $this->SQL->Select()->From('Photo')->Where('InsertUserID', $UserID)->Get();
foreach ($PhotoData->Result() as $Photo) {
@unlink(PATH_UPLOADS.DS.$Photo->Name);
}
$this->SQL->Delete('Photo', array('InsertUserID' => $UserID));
*/
// Remove invitations
$this->GetDelete('Invitation', array('InsertUserID' => $UserID), $Content);
$this->GetDelete('Invitation', array('AcceptedUserID' => $UserID), $Content);
// Remove activities
$this->GetDelete('Activity', array('InsertUserID' => $UserID), $Content);
// Remove activity comments.
$this->GetDelete('ActivityComment', array('InsertUserID' => $UserID), $Content);
// Clear out information on the user.
$this->SetField($UserID, array('About' => NULL, 'Title' => NULL, 'Location' => NULL));
if ($Log) {
$User['_Data'] = $Content;
unset($Content);
// in case data gets copied
$Result = LogModel::Insert($Log, 'User', $User, GetValue('LogOptions', $Options, array()));
}
return $Result;
}
示例9: DiscussionController_VoteDiscussion_Create
/**
* Increment/decrement discussion scores
*/
public function DiscussionController_VoteDiscussion_Create($Sender)
{
// if (!C('Plugins.Voting.Enabled'))
// return;
$DiscussionID = GetValue(0, $Sender->RequestArgs, 0);
$TransientKey = GetValue(1, $Sender->RequestArgs);
$VoteType = FALSE;
if ($TransientKey == 'voteup' || $TransientKey == 'votedown') {
$VoteType = $TransientKey;
$TransientKey = GetValue(2, $Sender->RequestArgs);
}
$Session = Gdn::Session();
$NewUserVote = 0;
$Total = 0;
if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $DiscussionID > 0) {
$DiscussionModel = new DiscussionModel();
$OldUserVote = $DiscussionModel->GetUserScore($DiscussionID, $Session->UserID);
if ($VoteType == 'voteup') {
$NewUserVote = 1;
} else {
if ($VoteType == 'votedown') {
$NewUserVote = -1;
} else {
$NewUserVote = $OldUserVote == 1 ? -1 : 1;
}
}
$FinalVote = intval($OldUserVote) + intval($NewUserVote);
// Allow admins to vote unlimited.
$AllowVote = $Session->CheckPermission('Garden.Moderation.Manage');
// Only allow users to vote up or down by 1.
if (!$AllowVote) {
$AllowVote = $FinalVote > -2 && $FinalVote < 2;
}
if ($AllowVote) {
$Total = $DiscussionModel->SetUserScore($DiscussionID, $Session->UserID, $FinalVote);
} else {
$Discussion = $DiscussionModel->GetID($DiscussionID);
$Total = GetValue('Score', $Discussion, 0);
$FinalVote = $OldUserVote;
}
// Move the comment into or out of moderation.
if (class_exists('LogModel')) {
$Moderate = FALSE;
if ($Total <= C('Plugins.Voting.ModThreshold1', -10)) {
$LogOptions = array('GroupBy' => array('RecordID'));
// Get the comment row.
if (isset($Discussion)) {
$Data = (array) $Discussion;
} else {
$Data = (array) $DiscussionModel->GetID($DiscussionID);
}
if ($Data) {
// Get the users that voted the comment down.
$OtherUserIDs = $DiscussionModel->SQL->Select('UserID')->From('UserComment')->Where('CommentID', $DiscussionID)->Where('Score <', 0)->Get()->ResultArray();
$OtherUserIDs = array_column($OtherUserIDs, 'UserID');
$LogOptions['OtherUserIDs'] = $OtherUserIDs;
// Add the comment to moderation.
if ($Total > C('Plugins.Voting.ModThreshold2', -20)) {
LogModel::Insert('Moderate', 'Discussion', $Data, $LogOptions);
}
}
$Moderate = TRUE;
}
if ($Total <= C('Plugins.Voting.ModThreshold2', -20)) {
// Remove the comment.
$DiscussionModel->Delete($DiscussionID, array('Log' => 'Moderate'));
$Sender->InformMessage(sprintf(T('The %s has been removed for moderation.'), T('discussion')));
} elseif ($Moderate) {
$Sender->InformMessage(sprintf(T('The %s has been flagged for moderation.'), T('discussion')));
}
}
}
$Sender->DeliveryType(DELIVERY_TYPE_BOOL);
$Sender->SetJson('TotalScore', $Total);
$Sender->SetJson('FinalVote', $FinalVote);
$Sender->Render();
}
示例10: Save
public function Save()
{
if (!$this->Dirty) {
return NULL;
}
$this->EventArguments['ConfigDirty'] =& $this->Dirty;
$this->EventArguments['ConfigNoSave'] = FALSE;
$this->EventArguments['ConfigType'] = $this->Type;
$this->EventArguments['ConfigSource'] = $this->Source;
$this->EventArguments['ConfigData'] = $this->Settings;
$this->FireEvent('BeforeSave');
if ($this->EventArguments['ConfigNoSave']) {
$this->Dirty = FALSE;
return TRUE;
}
// Check for and fire callback if one exists
if ($this->Callback && is_callable($this->Callback)) {
$CallbackOptions = array();
if (!is_array($this->CallbackOptions)) {
$this->CallbackOptions = array();
}
$CallbackOptions = array_merge($CallbackOptions, $this->CallbackOptions, array('ConfigDirty' => $this->Dirty, 'ConfigType' => $this->Type, 'ConfigSource' => $this->Source, 'ConfigData' => $this->Settings, 'SourceObject' => $this));
$ConfigSaved = call_user_func($this->Callback, $CallbackOptions);
if ($ConfigSaved) {
$this->Dirty = FALSE;
return TRUE;
}
}
switch ($this->Type) {
case 'file':
if (empty($this->Source)) {
trigger_error(ErrorMessage('You must specify a file path to be saved.', 'Configuration', 'Save'), E_USER_ERROR);
}
$CheckWrite = $this->Source;
if (!file_exists($CheckWrite)) {
$CheckWrite = dirname($CheckWrite);
}
if (!is_writable($CheckWrite)) {
throw new Exception(sprintf(T("Unable to write to config file '%s' when saving."), $this->Source));
}
$Group = $this->Group;
$Data =& $this->Settings;
ksort($Data);
// Check for the case when the configuration is the group.
if (is_array($Data) && count($Data) == 1 && array_key_exists($Group, $Data)) {
$Data = $Data[$Group];
}
// Do a sanity check on the config save.
if ($this->Source == Gdn::Config()->DefaultPath()) {
// Log root config changes
try {
$LogData = $this->Initial;
$LogData['_New'] = $this->Settings;
LogModel::Insert('Edit', 'Configuration', $LogData);
} catch (Exception $Ex) {
}
if (!isset($Data['Database'])) {
if ($Pm = Gdn::PluginManager()) {
$Pm->EventArguments['Data'] = $Data;
$Pm->EventArguments['Backtrace'] = debug_backtrace();
$Pm->FireEvent('ConfigError');
}
return FALSE;
}
}
// Write config data to string format, ready for saving
$FileContents = Gdn_Configuration::Format($Data, array('VariableName' => $Group, 'WrapPHP' => TRUE, 'ByLine' => TRUE));
if ($FileContents === FALSE) {
trigger_error(ErrorMessage('Failed to define configuration file contents.', 'Configuration', 'Save'), E_USER_ERROR);
}
// Save to cache if we're into that sort of thing
$FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $this->Source);
if ($this->Configuration && $this->Configuration->Caching() && Gdn::Cache()->Type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::Cache()->ActiveEnabled()) {
$CachedConfigData = Gdn::Cache()->Store($FileKey, $Data, array(Gdn_Cache::FEATURE_NOPREFIX => TRUE, Gdn_Cache::FEATURE_EXPIRY => 3600));
}
$TmpFile = tempnam(PATH_CONF, 'config');
$Result = FALSE;
if (file_put_contents($TmpFile, $FileContents) !== FALSE) {
chmod($TmpFile, 0775);
$Result = rename($TmpFile, $this->Source);
}
if ($Result && function_exists('apc_delete_file')) {
// This fixes a bug with some configurations of apc.
@apc_delete_file($this->Source);
}
$this->Dirty = FALSE;
return $Result;
break;
case 'json':
case 'array':
case 'string':
/**
* How would these even save? String config data must be handled by
* an event hook or callback, if at all.
*/
$this->Dirty = FALSE;
return FALSE;
break;
}
}
示例11: 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);
if ($Log) {
LogModel::Insert('Delete', 'Discussion', $Data);
}
// Log all of the comment deletes.
$Comments = $this->SQL->GetWhere('Comment', array('DiscussionID' => $DiscussionID))->ResultArray();
if ($Log || array_key_exists('LogOperation', $Options)) {
foreach ($Comments as $Comment) {
LogModel::Insert(GetValue('LogOperation', $Options, 'Delete'), 'Comment', $Comment);
}
}
$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;
}
示例12: Delete
/**
* Delete a comment.
*
* This is a hard delete that completely removes it from the database.
* Events: DeleteComment.
*
* @since 2.0.0
* @access public
*
* @param int $CommentID Unique ID of the comment to be deleted.
* @param array $Options Additional options for the delete.
* @param bool Always returns TRUE.
*/
public function Delete($CommentID, $Options = array())
{
$this->EventArguments['CommentID'] = $CommentID;
$Comment = $this->GetID($CommentID, DATASET_TYPE_ARRAY);
if (!$Comment) {
return FALSE;
}
$Discussion = $this->SQL->GetWhere('Discussion', array('DiscussionID' => $Comment['DiscussionID']))->FirstRow(DATASET_TYPE_ARRAY);
// Decrement the UserDiscussion comment count if the user has seen this comment
$Offset = $this->GetOffset($CommentID);
$this->SQL->Update('UserDiscussion')->Set('CountComments', 'CountComments - 1', FALSE)->Where('DiscussionID', $Comment['DiscussionID'])->Where('CountComments >', $Offset)->Put();
$this->EventArguments['Discussion'] = $Discussion;
$this->FireEvent('DeleteComment');
// Log the deletion.
$Log = GetValue('Log', $Options, 'Delete');
LogModel::Insert($Log, 'Comment', $Comment, GetValue('LogOptions', $Options, array()));
// Delete the comment.
$this->SQL->Delete('Comment', array('CommentID' => $CommentID));
// Update the comment count
$this->UpdateCommentCount($Discussion, array('Slave' => FALSE));
// Update the user's comment count
$this->UpdateUser($Comment['InsertUserID']);
// Update the category.
$Category = CategoryModel::Categories(GetValue('CategoryID', $Discussion));
if ($Category && $Category['LastCommentID'] == $CommentID) {
$CategoryModel = new CategoryModel();
$CategoryModel->SetRecentPost($Category['CategoryID']);
}
// Clear the page cache.
$this->RemovePageCache($Comment['DiscussionID']);
return TRUE;
}
示例13: Save
/**
* Inserts or updates the discussion via form values.
*
* Events: BeforeSaveDiscussion, AfterSaveDiscussion.
*
* @since 2.0.0
* @access public
*
* @param array $FormPostValues Data sent from the form model.
* @return int $DiscussionID Unique ID of the discussion.
*/
public function Save($FormPostValues) {
$Session = Gdn::Session();
// Define the primary key in this model's table.
$this->DefineSchema();
// Add & apply any extra validation rules:
$this->Validation->ApplyRule('Body', 'Required');
$MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
$this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
$this->Validation->ApplyRule('Body', 'Length');
}
// Get the DiscussionID from the form so we know if we are inserting or updating.
$DiscussionID = ArrayValue('DiscussionID', $FormPostValues, '');
$Insert = $DiscussionID == '' ? TRUE : FALSE;
$this->EventArguments['Insert'] = $Insert;
if ($Insert) {
unset($FormPostValues['DiscussionID']);
// If no categoryid is defined, grab the first available.
if (ArrayValue('CategoryID', $FormPostValues) === FALSE)
$FormPostValues['CategoryID'] = $this->SQL->Get('Category', '', '', 1)->FirstRow()->CategoryID;
$this->AddInsertFields($FormPostValues);
// $FormPostValues['LastCommentUserID'] = $Session->UserID;
$FormPostValues['DateLastComment'] = Gdn_Format::ToDateTime();
}
// Add the update fields because this table's default sort is by DateUpdated (see $this->Get()).
$this->AddUpdateFields($FormPostValues);
// Set checkbox values to zero if they were unchecked
if (ArrayValue('Announce', $FormPostValues, '') === FALSE)
$FormPostValues['Announce'] = 0;
if (ArrayValue('Closed', $FormPostValues, '') === FALSE)
$FormPostValues['Closed'] = 0;
if (ArrayValue('Sink', $FormPostValues, '') === FALSE)
$FormPostValues['Sink'] = 0;
// Prep and fire event
$this->EventArguments['FormPostValues'] = &$FormPostValues;
$this->EventArguments['DiscussionID'] = $DiscussionID;
$this->FireEvent('BeforeSaveDiscussion');
// Validate the form posted values
if ($this->Validate($FormPostValues, $Insert)) {
// If the post is new and it validates, make sure the user isn't spamming
if (!$Insert || !$this->CheckForSpam('Discussion')) {
// Get all fields on the form that relate to the schema
$Fields = $this->Validation->SchemaValidationFields();
// Get DiscussionID if one was sent
$DiscussionID = intval(ArrayValue('DiscussionID', $Fields, 0));
// Remove the primary key from the fields for saving
$Fields = RemoveKeyFromArray($Fields, 'DiscussionID');
$Discussion = FALSE;
$StoredCategoryID = FALSE;
if ($DiscussionID > 0) {
// Updating
$Stored = $this->GetID($DiscussionID);
$LogData = (array)$Stored;
$LogData['_New'] = (array)$Fields;
LogModel::Insert('Edit', 'Discussion', $LogData);
$this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $DiscussionID));
if($Stored->CategoryID != $Fields['CategoryID'])
$StoredCategoryID = $Stored->CategoryID;
} else {
// Inserting
$Fields['Format'] = Gdn::Config('Garden.InputFormatter', '');
// Check for spam.
$Spam = SpamModel::IsSpam('Discussion', $Fields);
if (!$Spam) {
$DiscussionID = $this->SQL->Insert($this->Name, $Fields);
} else {
return SPAM;
}
// Assign the new DiscussionID to the comment before saving
$FormPostValues['IsNewDiscussion'] = TRUE;
//.........这里部分代码省略.........
示例14: _LogChange
protected function _LogChange($NewData = NULL, $OldData = NULL)
{
if ($NewData === NULL) {
$NewData = $this->_SaveData;
}
if ($OldData === NULL) {
$OldData = $this->_SaveDataBak;
}
$Data = $OldData;
$Data['_New'] = $NewData;
// Log the change.
try {
LogModel::Insert('Edit', 'Configuration', $Data);
} catch (Exception $Ex) {
}
}
示例15: Delete
/**
* Delete a particular activity item.
*
* @since 2.0.0
* @access public
* @param int $ActivityID Unique ID of acitivity to be deleted.
*/
public function Delete($ActivityID, $Options = array())
{
// Get the activity first.
$Activity = $this->GetID($ActivityID);
if ($Activity) {
// Log the deletion.
$Log = GetValue('Log', $Options);
if ($Log) {
LogModel::Insert($Log, 'Activity', $Activity);
}
// Delete comments on the activity item
$this->SQL->Delete('ActivityComment', array('ActivityID' => $ActivityID));
// Delete the activity item
parent::Delete(array('ActivityID' => $ActivityID));
}
}