Delete attachment from the AR or Analysis

        The attachment will be only deleted if it is not further referenced by
        another AR/Analysis.
974409
def delete_attachment(self, attachment):
        

        # Get the holding parent of this attachment
        parent = None
        if attachment.getLinkedRequests():
            # Holding parent is an AR
            parent = attachment.getRequest()
        elif attachment.getLinkedAnalyses():
            # Holding parent is an Analysis
            parent = attachment.getAnalysis()

        if parent is None:
            logger.warn(
                "Attachment {} is nowhere assigned. This should never happen!"
                .format(repr(attachment)))
            return False

        # Get the other attachments of the holding parent
        attachments = parent.getAttachment()

        # New attachments to set
        if attachment in attachments:
            attachments.remove(attachment)

        # Set the attachments w/o the current attachments
        parent.setAttachment(attachments)

        retain = False

        # Attachment is referenced by another Analysis
        if attachment.getLinkedAnalyses():
            holder = attachment.getAnalysis()
            logger.info("Attachment {} referenced by {} -> RETAIN"
                        .format(repr(attachment), repr(holder)))
            retain = True

        # Attachment is referenced by another AR
        if attachment.getLinkedRequests():
            holder = attachment.getRequest()
            logger.info("Attachment {} referenced by {} -> RETAIN"
                        .format(repr(attachment), repr(holder)))
            retain = True

        # Delete attachment finally
        if retain is False:
            client = api.get_parent(attachment)
            client.manage_delObjects([attachment.getId(), ])
858709
@Override
	public void removeByAssetCategoryId(long assetCategoryId) {
		for (CPRuleAssetCategoryRel cpRuleAssetCategoryRel : findByAssetCategoryId(
				assetCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(cpRuleAssetCategoryRel);
		}
	}
587925
function(){
    var gl = this.gl;
    gl.deleteFramebuffer( this.fbo );
    
    for (var i = 0; i < this.attachmentsList.length; i++) {
      this.attachmentsList[i].dispose();
    }
    this.attachmentsList = null;
    this.attachments     = null;

    this.valid = false;
    this.fbo   = null;
    this.gl    = null;
  }
938183
def delete_asset(self):
        
        headers, data = self._requester.requestJsonAndCheck(
            "DELETE",
            self.url
        )
        return True
733434
public function delete() {
        global $DB;

        $this->delete_attachments();
        $this->remove_associations();

        // Get record to pass onto the event.
        $record = $DB->get_record('post', array('id' => $this->id));
        $DB->delete_records('post', array('id' => $this->id));
        core_tag_tag::remove_all_item_tags('core', 'post', $this->id);

        $event = \core\event\blog_entry_deleted::create(array(
            'objectid'      => $this->id,
            'relateduserid' => $this->userid
            ));
        $event->add_record_snapshot("post", $record);
        $event->set_blog_entry($this);
        $event->trigger();
    }
55552
def after_retract(duplicate_analysis):
    
    # Rename the analysis to make way for it's successor.
    # Support multiple retractions by renaming to *-0, *-1, etc
    parent = duplicate_analysis.aq_parent
    keyword = duplicate_analysis.getKeyword()
    analyses = filter(lambda an: an.getKeyword() == keyword,
                      parent.objectValues("DuplicateAnalysis"))

    # Rename the retracted duplicate
    # https://docs.plone.org/develop/plone/content/rename.html
    # _verifyObjectPaste permission check must be cancelled
    parent._verifyObjectPaste = str
    retracted_id = '{}-{}'.format(keyword, len(analyses))
    # Make sure all persistent objects have _p_jar attribute
    transaction.savepoint(optimistic=True)
    parent.manage_renameObject(duplicate_analysis.getId(), retracted_id)
    delattr(parent, '_verifyObjectPaste')

    # Find out the slot position of the duplicate in the worksheet
    worksheet = duplicate_analysis.getWorksheet()
    if not worksheet:
        logger.warn("Duplicate {} has been retracted, but without worksheet"
                    .format(duplicate_analysis.getId()))
        return

    dest_slot = worksheet.get_slot_position_for(duplicate_analysis)
    if not dest_slot:
        logger.warn("Duplicate {} has been retracted, but not found in any"
                    "slot of worksheet {}"
                    .format(duplicate_analysis.getId(), worksheet.getId()))
        return

    # Create a copy (retest) of the duplicate and assign to worksheet
    ref_gid = duplicate_analysis.getReferenceAnalysesGroupID()
    retest = _createObjectByType("DuplicateAnalysis", worksheet, tmpID())
    copy_analysis_field_values(duplicate_analysis, retest)
    retest.setAnalysis(duplicate_analysis.getAnalysis())
    retest.setRetestOf(duplicate_analysis)
    retest.setReferenceAnalysesGroupID(ref_gid)
    retest.setResult(duplicate_analysis.getResult())
    worksheet.addToLayout(retest, dest_slot)
    worksheet.setAnalyses(worksheet.getAnalyses() + [retest, ])

    # Reindex
    retest.reindexObject(idxs=["getAnalyst", "getWorksheetUID", "isRetest",
                               "getReferenceAnalysesGroupID"])
    worksheet.reindexObject(idxs=["getAnalysesUIDs"])

    # Try to rollback the worksheet to prevent inconsistencies
    doActionFor(worksheet, "rollback_to_open")
1000513
public void remove() {

    if (context == null) {
      throw new IllegalStateException("link with href=" + getHref() + " can not be removed, because it's not part of a HAL resource tree");
    }

    // iterate over all links grouped by relation (because for removal we need to know the relation)
    ListMultimap<String, Link> allLinks = context.getLinks();
    for (String relation : allLinks.keySet()) {
      List<Link> links = allLinks.get(relation);

      // use an indexed for-loop, because we need to know the index to properly remove the link
      for (int i = 0; i < links.size(); i++) {
        if (links.get(i).getModel() == model) {
          context.removeLink(relation, i);
          context = null;
          return;
        }
      }
    }

    throw new IllegalStateException("the last known context resource of link with href=" + getHref() + " no longer contains this link");
  }
688774
def flush(self):
        
        annotation = self.get_annotation()
        if annotation.get(ATTACHMENTS_STORAGE) is not None:
            del annotation[ATTACHMENTS_STORAGE]
885223
public static boolean deleteAttachment(Attachment attachment) {
        File attachmentFile = new File(getResultsDirectory(), attachment.getSource());
        return attachmentFile.exists() && attachmentFile.canWrite() && attachmentFile.delete();
    }
540569
def user_can_delete_attachments(self):
        
        context = self.context
        user = api.get_current_user()
        if not self.is_ar_editable():
            return False
        return (self.user_can_add_attachments() and
                not user.allowed(context, ["Client"])) or \
            self.user_can_update_attachments()
1274475
public function delete()
	{
		$asset = Model::oneByName($this->getAssetName());

		if ($asset->get('id'))
		{
			if (!$asset->destroy())
			{
				return false;
			}
		}

		return true;
	}
750930
def shot_remove_asset(self, *args, **kwargs):
        
        if not self.cur_shot:
            return
        i = self.shot_asset_treev.currentIndex()
        item = i.internalPointer()
        if item:
            asset = item.internal_data()
            if not isinstance(asset, djadapter.models.Asset):
                return
            log.debug("Removing asset %s.", asset.name)
            item.set_parent(None)
            self.cur_shot.assets.remove(asset)
873384
public function delete()
    {
        if (!$this->isNewRecord) {
            $item = Yii::$app->authManager->getRole($this->name);
            if ($item) {
                Yii::$app->authManager->remove($item);
            }
        }
    }
566981
function remove(req, res, next) {
  var params = {
    appId: req.params.id
  };

  forms.deleteAppReferences(req.connectionOptions, params, formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
1180661
def delete(self):
        
        if self.dynamic_version_of is None:
            self._delete_dynamic_versions()
        else:
            super(DynamicFieldMixin, self).delete()
            self._inventory.srem(self.dynamic_part)
1292535
function skip() {
    rimraf(file, function() {})
    delete f.versions[v]
    if (f._attachments)
      delete f._attachments[file]
    need.splice(need.indexOf(v), 1)
    maybeDone(null)
  }
1309548
def remove(self):
        
        with self.__lock:
            absolute_file_path = self.__file_path
            #logging.debug("DELETE data file %s", absolute_file_path)
            if os.path.isfile(absolute_file_path):
                os.remove(absolute_file_path)