delete() публичный Метод

Delete records from a table.
public delete ( array | integer $where = [], array | true $options = [] ) : Gdn_Dataset
$where array | integer The where clause to delete or an integer value.
$options array | true An array of options to control the delete. - limit: A limit to the number of records to delete. - reset: Deprecated. Whether or not to reset this SQL statement after the delete. Defaults to false.
Результат Gdn_Dataset Returns the result of the delete.
Пример #1
0
 /**
  * Remove file from filesystem, and clear db entry.
  *
  * @param type $FileID
  * @param type $ForeignID
  * @param type $ForeignType
  * @return boolean
  */
 protected function deleteEditorUploads($MediaID, $ForeignID = '', $ForeignType = '')
 {
     // Save data to database using model with media table
     $Model = new Gdn_Model('Media');
     $Media = (array) $Model->getID($MediaID);
     $IsOwner = !empty($Media['InsertUserID']) && Gdn::session()->UserID == $Media['InsertUserID'];
     // @todo Per-category edit permission would be better, but this global is far simpler to check here.
     // However, this currently matches the permission check in views/attachments.php so keep that in sync.
     $CanDelete = $IsOwner || Gdn::session()->checkPermission('Garden.Moderation.Manage');
     if ($Media && $CanDelete) {
         try {
             if ($Model->delete($MediaID)) {
                 // unlink the images.
                 $path = PATH_UPLOADS . '/' . $Media['Path'];
                 $thumbPath = PATH_UPLOADS . '/' . $Media['ThumbPath'];
                 if (file_exists($path)) {
                     unlink($path);
                 }
                 if (file_exists($thumbPath)) {
                     unlink($thumbPath);
                 }
             }
         } catch (Exception $e) {
             die($e->getMessage());
             return false;
         }
         return true;
     }
     return false;
 }
Пример #2
0
 /**
  * Remove file from filesystem, and clear db entry.
  *
  * @param type $FileID
  * @param type $ForeignID
  * @param type $ForeignType
  * @return boolean
  */
 protected function deleteEditorUploads($MediaID, $ForeignID = '', $ForeignType = '')
 {
     // Save data to database using model with media table
     $Model = new Gdn_Model('Media');
     $Media = (array) $Model->getID($MediaID);
     $IsOwner = !empty($Media['InsertUserID']) && Gdn::session()->UserID == $Media['InsertUserID'];
     // @todo Per-category edit permission would be better, but this global is far simpler to check here.
     // However, this currently matches the permission check in views/attachments.php so keep that in sync.
     $CanDelete = $IsOwner || Gdn::session()->checkPermission('Garden.Moderation.Manage');
     if ($Media && $CanDelete) {
         try {
             if ($Model->delete($MediaID)) {
                 // unlink the images.
                 $path = PATH_UPLOADS . '/' . $Media['Path'];
                 $thumbPath = PATH_UPLOADS . '/' . $Media['ThumbPath'];
                 if (file_exists($path)) {
                     unlink($path);
                 }
                 if (file_exists($thumbPath)) {
                     unlink($thumbPath);
                 }
                 // Clear the cache, if exists.
                 /*$discussionID = '';
                   if ($Media['ForeignTable'] == 'discussion') {
                    $discussionID = $Media['ForeignID'];
                   } elseif ($Media['ForeignTable'] == 'comment') {
                    $commentModel = new CommentModel();
                    $commentRow = $commentModel->getID($Media['ForeignID'], DATASET_TYPE_ARRAY);
                    if ($commentRow) {
                     $discussionID = $commentRow['DiscussionID'];
                    }
                   }
                   if ($discussionID) {
                    $cacheKey = sprintf(self::DISCUSSION_MEDIA_CACHE_KEY, $discussionID);
                    Gdn::cache()->Remove($cacheKey);
                   }*/
             }
         } catch (Exception $e) {
             die($e->getMessage());
             return false;
         }
         return true;
     }
     return false;
 }
Пример #3
0
 /**
  * Delete a message.
  *
  * @param array|int $where The where clause to delete or an integer value.
  * @param array|true $options An array of options to control the delete.
  * @return bool Returns **true** on success or **false** on failure.
  */
 public function delete($where = [], $options = [])
 {
     $result = parent::delete($where, $options);
     self::messages(null);
     return $result;
 }
 /**
  * Delete a message.
  *
  * @param string $Where
  * @param bool $Limit
  * @param bool $ResetData
  */
 public function delete($Where = '', $Limit = false, $ResetData = false)
 {
     parent::delete($Where, $Limit, $ResetData);
     self::messages(null);
 }
Пример #5
0
 /**
  * Delete a screenshot from an addon.
  *
  * @param string $AddonPictureID Picture id to remove.
  * @throws Gdn_UserException No permission to delete this picture.
  */
 public function deletePicture($AddonPictureID = '')
 {
     $AddonPictureModel = new Gdn_Model('AddonPicture');
     $Picture = $AddonPictureModel->getWhere(array('AddonPictureID' => $AddonPictureID))->firstRow();
     $AddonModel = new AddonModel();
     $Addon = $AddonModel->getID($Picture->AddonID);
     $Session = Gdn::session();
     if ($Session->UserID != $Addon['InsertUserID'] && !$Session->checkPermission('Addons.Addon.Manage')) {
         throw permissionException();
     }
     if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('Yes')) {
         if ($Picture) {
             $Upload = new Gdn_Upload();
             $Upload->delete(changeBasename($Picture->File, 'ao%s'));
             $Upload->delete(changeBasename($Picture->File, 'at%s'));
             $AddonPictureModel->delete(array('AddonPictureID' => $AddonPictureID));
         }
         $this->RedirectUrl = url('/addon/' . $Picture->AddonID);
     }
     $this->render('deletepicture');
 }
Пример #6
0
 /**
  * Remove a ban.
  *
  * @param array|int $where The where clause to delete or an integer value.
  * @param array|true $options An array of options to control the delete.
  * @return bool Returns **true** on success or **false** on failure.
  */
 public function delete($where = [], $options = [])
 {
     if (isset($where['BanID'])) {
         $OldBan = $this->getID($where['BanID'], DATASET_TYPE_ARRAY);
     }
     $result = parent::delete($where, $options);
     if (isset($OldBan)) {
         $this->ApplyBan(null, $OldBan);
     }
     return $result;
 }
Пример #7
0
 /**
  * Delete a particular activity item.
  *
  * @param int $ActivityID The unique ID of activity to be deleted.
  * @param array $Options Not used.
  */
 public function deleteID($ActivityID, $Options = array())
 {
     // Get the activity first.
     $Activity = $this->getID($ActivityID);
     if ($Activity) {
         // Log the deletion.
         $Log = val('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));
     }
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function delete($where = [], $options = [])
 {
     if (is_numeric($where)) {
         deprecated('ActivityModel->delete(int)', 'ActivityModel->deleteID(int)');
         $result = $this->deleteID($where, $options);
         return $result;
     } elseif (count($where) === 1 && isset($where['ActivityID'])) {
         return parent::delete($where, $options);
     }
     throw new \BadMethodCallException("ActivityModel->delete() is not supported.", 400);
 }