Handle deleting a block.
@return boolean true if anything was done. False if not.
774319
public function process_url_delete() {
        global $CFG, $PAGE, $OUTPUT;

        $blockid = optional_param('bui_deleteid', null, PARAM_INT);
        $confirmdelete = optional_param('bui_confirm', null, PARAM_INT);

        if (!$blockid) {
            return false;
        }

        require_sesskey();
        $block = $this->page->blocks->find_instance($blockid);
        if (!$this->user_can_delete_block($block)) {
            throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('deleteablock'));
        }

        if (!$confirmdelete) {
            $deletepage = new moodle_page();
            $deletepage->set_pagelayout('admin');
            $deletepage->blocks->show_only_fake_blocks(true);
            $deletepage->set_course($this->page->course);
            $deletepage->set_context($this->page->context);
            if ($this->page->cm) {
                $deletepage->set_cm($this->page->cm);
            }

            $deleteurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring());
            $deleteurlparams = $this->page->url->params();
            $deletepage->set_url($deleteurlbase, $deleteurlparams);
            $deletepage->set_block_actions_done();
            // At this point we are either going to redirect, or display the form, so
            // overwrite global $PAGE ready for this. (Formslib refers to it.)
            $PAGE = $deletepage;
            //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that too
            $output = $deletepage->get_renderer('core');
            $OUTPUT = $output;

            $site = get_site();
            $blocktitle = $block->get_title();
            $strdeletecheck = get_string('deletecheck', 'block', $blocktitle);
            $message = get_string('deleteblockcheck', 'block', $blocktitle);

            // If the block is being shown in sub contexts display a warning.
            if ($block->instance->showinsubcontexts == 1) {
                $parentcontext = context::instance_by_id($block->instance->parentcontextid);
                $systemcontext = context_system::instance();
                $messagestring = new stdClass();
                $messagestring->location = $parentcontext->get_context_name();

                // Checking for blocks that may have visibility on the front page and pages added on that.
                if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) {
                    $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block');
                } else {
                    $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext);
                    $messagestring->pagetype = $block->instance->pagetypepattern;
                    if (isset($pagetypes[$block->instance->pagetypepattern])) {
                        $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern];
                    }
                }

                $message = get_string('deleteblockwarning', 'block', $messagestring);
            }

            $PAGE->navbar->add($strdeletecheck);
            $PAGE->set_title($blocktitle . ': ' . $strdeletecheck);
            $PAGE->set_heading($site->fullname);
            echo $OUTPUT->header();
            $confirmurl = new moodle_url($deletepage->url, array('sesskey' => sesskey(), 'bui_deleteid' => $block->instance->id, 'bui_confirm' => 1));
            $cancelurl = new moodle_url($deletepage->url);
            $yesbutton = new single_button($confirmurl, get_string('yes'));
            $nobutton = new single_button($cancelurl, get_string('no'));
            echo $OUTPUT->confirm($message, $yesbutton, $nobutton);
            echo $OUTPUT->footer();
            // Make sure that nothing else happens after we have displayed this form.
            exit;
        } else {
            blocks_delete_instance($block->instance);
            // bui_deleteid and bui_confirm should not be in the PAGE url.
            $this->page->ensure_param_not_in_url('bui_deleteid');
            $this->page->ensure_param_not_in_url('bui_confirm');
            return true;
        }
    }
920985
final public function delete() {
	
		if (!$this->getId()) return FALSE;
		
		// trigger a custom function before deletion
		$this->beforeDelete();
		
		$class = get_called_class();
		
		// build the SQL where line
		$where = ' WHERE ' . implode(' AND ', $this->getSqlKeyConditions());
		
		$query = 'DELETE FROM `' . $class::TABLE_NAME . '`' . $where . ' LIMIT 1';
		$res = $this->db->exec($query, $this->getSqlKeyValues());
		
		// list properties to not remove
		$activeRecordsProperties = array('db', 'loadedFromDb', 'typeList', 'errors');
		
		// unset all properties
		foreach ($this as $key => $value) {
			if (!in_array($key, $activeRecordsProperties)) {
				unset($this->$key);
			}
		}
		
		$this->loadedFromDb = FALSE;
		
		// trigger a custom function after deletion
		$this->afterDelete();

		return (bool)$res;
		
	}
841381
public function destroy(BlockRequest $request, Block $block)
    {
        try {

            $block->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('block::block.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('block/block'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('block/block/' . $block->getRouteKey()))
                ->redirect();
        }

    }
1223790
public function eventBeforeDelete()
    {
        // delete all attached sub blocks
        $this->deleteAllSubBlocks($this->id);
        //save block data for afterDeleteEvent
        $this->_olds = $this->getOldAttributes();
        // verify if the block exists or not
        $class = ($this->block) ? $this->block->getNameForLog() : '[class has been removed from the filesystem]';
        // log event
        Log::add(3, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'delete', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $class], 'cms_nav_item_page_block_item', $this->id);
    }
678781
public function delete()
	{
		if ( ! $this->is_loaded() ) return false;

		$error = wp_delete_post( $this->attributes['ID'], $this->forceDelete );

		return $error !== false;
	}
884215
public function delete()
	{
		// Can't delete what doesn't exist
		if (!$this->exists())
		{
			return true;
		}

		// Remove record from the database
		if (!$this->_tbl->delete())
		{
			$this->setError($this->_tbl->getError());
			return false;
		}

		// Hey, no errors!
		return true;
	}
535608
protected function handleDELETE()
    {
        $force = $this->request->getParameterAsBool('force', false);
        $noCheck = $this->request->getParameterAsBool('no_check', false);
        $contentOnly = $this->request->getParameterAsBool('content_only', false);

        if (empty($this->folderPath)) {
            // delete just folders and files from the container
            if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
                $result = $this->deleteFolderContent($content, '', $force);
            } else {
                throw new BadRequestException('No resources given for delete.');
            }
        } else {
            if (empty($this->filePath)) {
                // delete directory of files and the directory itself
                // multi-file or folder delete via post data
                if (!empty($content = ResourcesWrapper::unwrapResources($this->request->getPayloadData()))) {
                    $result = $this->deleteFolderContent($content, $this->folderPath, $force);
                } else {
                    $this->driver->deleteFolder($this->container, $this->folderPath, $force, $contentOnly);
                    $result = ['name' => basename($this->folderPath), 'path' => $this->folderPath];
                }
            } else {
                // delete file from permanent storage
                $this->driver->deleteFile($this->container, $this->filePath, $noCheck);
                $result = ['name' => basename($this->filePath), 'path' => $this->filePath];
            }
        }

        return ResponseFactory::create(ResourcesWrapper::cleanResources($result));
    }
754319
public function delete()
    {
        if (isset($this->onDelete)) {
            return call_user_func($this->onDelete, $this);
        }

        return $this->query->delete();
    }
1325144
protected function deleteBlocks()
    {
        $blocks = $this->blockRepository->retrieveContentsBySlotName($this->slot->getSlotName());
        if (count($blocks) <= 0) {
            return null;
        }
        try {
            $result = null;

            $this->blockRepository->startTransaction();
            foreach ($blocks as $block) {
                $result = $this->blockRepository
                            ->setRepositoryObject($block)
                            ->delete();

                if(!$result) break;
            }

            if ($result) {
                $this->blockRepository->commit();
            } else {
                $this->blockRepository->rollBack();
            }

            return $result;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
1149571
public function endBlock()
    {
        if (!$this->openBlocks) {
            throw new RuntimeException('No block started.');
        }

        $name  = array_pop($this->openBlocks);
        $value = ob_get_clean();

        if ($this->blocks[$name] === null) {
            $this->blocks[$name] = $value;
        }

        return $this->blocks[$name];
    }
1355354
public function delete(): bool
    {
        if (! $this->exists())
        {
            return false;
        }

        $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE ' . $this->getKeyName() . ' = :key';
        $query = DB::getConnection()->prepare($sql);

        return $query->execute(['key' => $this->getKey()]);
    }
1161051
public function delete()
    {
        if (!$this->allow_delete) {
            throw $this->exception('Deleting is not allowed');
        }

        $m = $this->model;
        if (!$m->loaded()) {
            throw $this->exception('Cowardly refusing to delete all records');
        }

        $m->delete();

        return true;
    }
586683
public function actionCleanup()
    {
        $delete = [];
        $this->output("Blocks to delete:");
        foreach (Block::find()->all() as $block) {
            if (!$block->getFileExists()) {
                $this->outputInfo("{$block->class} (id: {$block->id}) used {$block->usageCount} times.");
                $delete[] = $block;
            }
        }
        
        if (!empty($delete) && $this->confirm('Are you sure to delete those blocks with its content? This can not be undone!')) {
            foreach ($delete as $deleteBlock) {
                if ($deleteBlock->delete()) {
                    $this->outputSuccess('Deleted ' . $deleteBlock->class);
                } else {
                    $this->outputError('Error while deleting ' . $deleteBlock->class);
                }
            }
            
            return $this->outputSuccess("Clean has been finished successful.");
        } elseif (empty($delete)) {
            return $this->outputSuccess("Nothing to cleanup.");
        }
        
        return $this->outputError("Abort by user.");
    }
654388
public function delete()
    {
        $result = false;
        
        if ($this->beforeDelete()) {
            $this->updateAttributes(static::internalUpdateValues());
            $result = true;
            $this->afterDelete();
        }
        
        return $result;
    }
11471
public function delete()
    {
        if (isset($this->onDelete)) {
            return call_user_func($this->onDelete, $this);
        }

        $this->forceDelete();
    }
1271174
public function delete()
    {
        $this->getLogger()->info('Deleting dayPart ID ' . $this->dayPartId);
        $this->doDelete('/daypart/' . $this->dayPartId);
        
        return true;
    }
67309
public function handle()
    {
        $this->rebuild = !empty($this->input->getOption('rebuild'));

        $this->tables = $this->getTablesFromMWBFile();
        if ($this->tables === false) {
            return false;
        }

        $this->getAppJson();

        $this->spec = $this->getAPISpecFromOASFile();
        if ($this->spec === null) {
            return false;
        }

        $success = $this->validateAPIDefinition();
        if (!$success) {
            return false;
        }

        $this->databaseService = new DatabaseService($this->config, $this->files);
        $this->databaseService->resetDatabase();

        $this->generateFromDefinitions();
        $this->generateControllers();
        $this->generateRequests();
        $this->insertRoutes();
        $this->styleCode();

        $this->databaseService->dropDatabase();

        return true;
    }