LogModel::restore PHP Method

restore() public method

Restore an entry from the log.
public restore ( array | integer $Log, boolean $DeleteLog = true )
$Log array | integer The log row or the ID of the log row.
$DeleteLog boolean Whether or not to delete the log row after restoring.
    public function restore($Log, $DeleteLog = true)
    {
        if (is_numeric($Log)) {
            // Grab the log.
            $LogID = $Log;
            $Log = $this->getWhere(['LogID' => $LogID]);
            if (!$Log) {
                throw notFoundException('Log');
            }
            $Log = array_pop($Log);
        }
        $this->restoreOne($Log, $DeleteLog);
        // Check for a transaction.
        if ($TransactionID = $Log['TransactionLogID']) {
            $Logs = $this->getWhere(['TransactionLogID' => $TransactionID], '', 'asc', 0, 200);
            foreach ($Logs as $LogRow) {
                if ($LogRow['LogID'] == $Log['LogID']) {
                    continue;
                }
                $this->restoreOne($LogRow, $DeleteLog);
            }
        }
        // Check for child data.
        if (isset($Log['Data']['_Data'])) {
            $Data = $Log['Data']['_Data'];
            foreach ($Data as $RecordType => $Rows) {
                foreach ($Rows as $Row) {
                    $LogRow = array_merge($Log, ['RecordType' => $RecordType, 'Data' => $Row]);
                    if ($RecordType == 'Comment') {
                        $LogRow['ParentRecordID'] = $Row['DiscussionID'];
                    }
                    $this->restoreOne($LogRow, false);
                }
            }
        }
    }

Usage Example

Esempio n. 1
0
 public function notSpam($LogIDs)
 {
     $this->permission(array('Garden.Moderation.Manage', 'Moderation.Spam.Manage'), false);
     if (!$this->Request->isPostBack()) {
         throw permissionException('Javascript');
     }
     $Logs = array();
     // Verify the appropriate users.
     $UserIDs = $this->Form->getFormValue('UserID', array());
     if (!is_array($UserIDs)) {
         $UserIDs = array();
     }
     foreach ($UserIDs as $UserID) {
         Gdn::userModel()->setField($UserID, 'Verified', true);
         $Logs = array_merge($Logs, $this->LogModel->getWhere(array('Operation' => 'Spam', 'RecordUserID' => $UserID)));
     }
     // Grab the logs.
     $Logs = array_merge($Logs, $this->LogModel->getIDs($LogIDs));
     //      try {
     foreach ($Logs as $Log) {
         $this->LogModel->restore($Log);
     }
     //      } catch (Exception $Ex) {
     //         $this->Form->addError($Ex->getMessage());
     //      }
     $this->LogModel->recalculate();
     $this->setData('Complete');
     $this->setData('Count', count($Logs));
     $this->render('Blank', 'Utility');
 }
All Usage Examples Of LogModel::restore