Make sure we cleanup on delete.

@return bool|null
@throws \Exception
176815
public function delete()
    {

        // Cleanup the corporation
        $this->alliance_history()->delete();
        $this->assets()->delete();
        $this->blueprints()->delete();
        $this->bookmarks()->delete();
        $this->bookmark_folders()->delete();
        $this->contacts()->delete();
        $this->contact_labels()->delete();
        $this->container_logs()->delete();
        $this->contracts()->delete();
        $this->pocos()->delete();
        $this->divisions()->delete();
        $this->facilities()->delete();
        $this->industry_jobs()->delete();

        // TODO: Mining delete

        $this->issued_medals()->delete();
        $this->killmails()->delete();
        $this->medals()->delete();
        $this->member_limit()->delete();
        $this->member_titles()->delete();
        $this->member_tracking()->delete();
        $this->members()->delete();
        $this->orders()->delete();
        $this->roles()->delete();
        $this->role_history()->delete();
        $this->shareholders()->delete();
        $this->standings()->delete();

        // TODO: Starbases & Structures

        $this->titles()->delete();
        $this->title_roles()->delete();
        $this->wallet_balances()->delete();
        $this->wallet_journal()->delete();
        $this->wallet_transactions()->delete();

        return parent::delete();
    }
337071
public function delete()
    {
        $where = $this->_getWhereQuery();

        /**
         * Execute the DELETE (this may throw an exception)
         */
        $result = $this->_getTable()->delete($where);

        /**
         * Reset all fields to null to indicate that the row is not there
         */
        $this->_data = array_combine(
            array_keys($this->_data),
            array_fill(0, count($this->_data), null)
        );

        return $result;
    }
1012316
public function clean()
    {
        try {
            $result = [
                'result'        => isset($this->cacheInstance) && is_object($this->cacheInstance) ? $this->cacheInstance->clear() : FALSE,
                'commit'        => isset($this->cacheInstance) && is_object($this->cacheInstance) ? $this->cacheInstance->commit() : NULL,
                'getDriverName' => isset($this->cacheInstance) && is_object($this->cacheInstance) ? $this->cacheInstance->getDriverName() : NULL,
                'getStats'      => isset($this->cacheInstance) && is_object($this->cacheInstance) ? $this->cacheInstance->getStats() : NULL,
                'getConfig'     => isset($this->cacheInstance) && is_object($this->cacheInstance) ? $this->cacheInstance->getConfig() : NULL,
            ];
            $this->debug->debug(__FUNCTION__, 'Clear Cache from Handler: ' . json_encode($this->cacheHandle) . ' -> Result: ' . json_encode($result));

            return $result;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return $message;
        }
    }
209569
public function actionClear()
    {
        $cachesInput = func_get_args();

        if (empty($cachesInput)) {
            throw new Exception('You should specify cache components names');
        }

        $caches = $this->findCaches($cachesInput);
        $cachesInfo = [];

        $foundCaches = array_keys($caches);
        $notFoundCaches = array_diff($cachesInput, array_keys($caches));

        if ($notFoundCaches) {
            $this->notifyNotFoundCaches($notFoundCaches);
        }

        if (!$foundCaches) {
            $this->notifyNoCachesFound();
            return ExitCode::OK;
        }

        if (!$this->confirmClear($foundCaches)) {
            return ExitCode::OK;
        }

        foreach ($caches as $name => $class) {
            $cachesInfo[] = [
                'name' => $name,
                'class' => $class,
                'is_flushed' => $this->canBeCleared($class) ? $this->app->get($name)->clear() : false,
            ];
        }

        $this->notifyCleared($cachesInfo);
    }
1022714
public function delete()
    {
        if (is_null($this->getKeyName())) {
            throw new Exception('No primary key defined on model.');
        }

        // If the model doesn't exist, there is nothing to delete so we'll just return
        // immediately and not do anything else. Otherwise, we will continue with a
        // deletion process on the model, firing the proper events, and so forth.
        if (!$this->exists) {
            return;
        }

        if ($this->fireModelEvent('deleting') === false) {
            return false;
        }

        // Here, we'll touch the owning models, verifying these timestamps get updated
        // for the models. This will allow any caching to get broken on the parents
        // by the timestamp. Then we will go ahead and delete the model instance.
        $this->touchOwners();

        $this->performDeleteOnModel();

        $this->exists = false;

        // Once the model has been deleted, we will fire off the deleted event so that
        // the developers may hook into post-delete operations. We will then return
        // a boolean true as the delete is presumably successful on the database.
        $this->fireModelEvent('deleted', false);

        return true;
    }
445835
public function clean()
    {
        try {
            $this->filesystem->deleteDir($this->localPath);
        } catch (\ErrorException $e) {
            // For reasons beyond our control, the actual owner of the directory
            // contents may not be the same as the current user. Therefore we need
            // to catch ErrorException and throw an expected exception with informing
            // the current user.
            throw new FileSystemException($e->getMessage(), $e->getCode(), $e);
        }
    }
81912
public static function doCleanup()
    {
        Service::$log->msg('Cleanup started');
        foreach (self::$cleanupQueue as $cq) {
            Service::$log->msg(sprintf('Removing %s %s', $cq['type'], $cq['path']));

            if (strpos($cq['path'], self::$tempFolder) !== 0) {
                throw new \Exception(sprintf('Path "%s" is not within the defined temp folder location "%s".',
                    $cq['path'], self::$tempFolder));
            }

            if ($cq['type'] == self::TYPE_DIR) {
                system('rm -rf ' . $cq['path']);
            }

            if ($cq['type'] == self::TYPE_FILE) {
                system('rm ' . $cq['path']);
            }
        }

        Service::$log->msg('Cleanup ended');
    }
667260
public static function delete()
    {
        $result = null;

        switch (static::getDriver()) {
            case self::DRIVER_MYSQL:
                $result = new \pwf\components\querybuilder\adapters\MySQL\DeleteBuilder();
                break;
            case self::DRIVER_PG:
                $result = new \pwf\components\querybuilder\adapters\PostgreSQL\DeleteBuilder();
                break;
            default:
                throw new \Exception('Wrong query builder driver');
        }

        return $result;
    }
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));
    }
425848
public function delete(){

        $query= /** @lang text */
            'DELETE FROM '.self::sanitize(static::$table);


        if (!empty($this->whereby)) {

            $query = $query . ' WHERE ' . $this->whereby;
        }

        try {
            $this->exec($query);

            static::$response["status"] = "success";
            static::$response["response"] = 'success';
            static::$response['code'] = 200;
            return static::terminate(static::$response);
        } catch (Exception $e) {
            static::$response["status"] = "error";
            static::$response["response"] = $e->getMessage();
            static::$response['code'] = $e->getCode();
            return static::terminate(static::$response);
        }
    }
1264636
public function delete()
    {
        $status = $this->getMongoCollection()->drop();

        if ($status['ok'] != 1) {
            // check if collection exists
            if ('ns not found' !== $status['errmsg']) {
                // collection exist
                throw new Exception('Error deleting collection ' . $this->getName() . ': ' . $status['errmsg']);
            }
        }

        return $this;
    }
795322
public function remove()
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $clearCache = false;
            if ($this->receiver_status == self::STATUS_NEW) {
                $clearCache = true;
            }
            $deleteParent = null;
            $this->scenario = 'remove';
            if ($this->message->sender_status != Message::STATUS_DELETED) {
                $this->receiver_status = self::STATUS_DELETED;
                if (!$this->save()) {
                    throw new Exception('Message status changing error!');
                }
                if ($clearCache) {
                    Podium::getInstance()->podiumCache->deleteElement('user.newmessages', $this->receiver_id);
                }
                $transaction->commit();
                return true;
            }
            if ($this->message->sender_status == Message::STATUS_DELETED && count($this->message->messageReceivers) == 1) {
                $deleteParent = $this->message;
            }
            if (!$this->delete()) {
                throw new Exception('Message removing error!');
            }
            if ($clearCache) {
                Podium::getInstance()->podiumCache->deleteElement('user.newmessages', $this->receiver_id);
            }
            if ($deleteParent) {
                if (!$deleteParent->delete()) {
                    throw new Exception('Sender message deleting error!');
                }
            }
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), $this->id, __METHOD__);
        }
        return false;
    }
438439
public function cleanup()
    {
        $this->saveState();

        if (null === $this->current_job) {
            $this->logger->debug('received cleanup call on worker ['.$this->id.'], no job is currently processing, exit now', [
                'category' => get_class($this),
                'pm' => $this->process,
            ]);

            $this->exit();

            return null;
        }

        $this->logger->debug('received cleanup call on worker ['.$this->id.'], reschedule current processing job ['.$this->current_job['_id'].']', [
            'category' => get_class($this),
            'pm' => $this->process,
        ]);

        $this->updateJob($this->current_job, JobInterface::STATUS_CANCELED);

        $this->db->{$this->scheduler->getEventQueue()}->insertOne([
            'job' => $this->current_job['_id'],
            'worker' => $this->id,
            'status' => JobInterface::STATUS_CANCELED,
            'timestamp' => new UTCDateTime(),
        ]);

        $options = $this->current_job['options'];
        $options['at'] = 0;

        $result = $this->scheduler->addJob($this->current_job['class'], $this->current_job['data'], $options)->getId();
        $this->exit();

        return $result;
    }
1034143
public function podiumDelete()
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            if (!$this->delete()) {
                throw new Exception('Post deleting error!');
            }
            $wholeThread = false;
            if ($this->thread->postsCount) {
                if (!$this->thread->updateCounters(['posts' => -1])) {
                    throw new Exception('Thread Post counter subtracting error!');
                }
                if (!$this->forum->updateCounters(['posts' => -1])) {
                    throw new Exception('Forum Post counter subtracting error!');
                }
            } else {
                $wholeThread = true;
                if (!$this->thread->delete()) {
                    throw new Exception('Thread deleting error!');
                }
                if (!$this->forum->updateCounters(['posts' => -1, 'threads' => -1])) {
                    throw new Exception('Forum Post and Thread counter subtracting error!');
                }
            }
            $transaction->commit();
            PodiumCache::clearAfter('postDelete');
            Log::info('Post deleted', !empty($this->id) ? $this->id : '', __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
272385
public function delete()
    {
        $this->exitIfModelNotSet();

        $params = [
            'id'    => $this->model->getKey(),
            'type'  => $this->model->getDocumentType(),
            'index' => $this->model->getDocumentIndex(),
        ];

        // check if the document exists before deleting
        if ($this->connection->existsStatement($params)) {
            return $this->connection->deleteStatement($params);
        }

        return true;
    }
651373
public function remove()
    {
        $transaction = static::getDb()->beginTransaction();
        try {
            $clearCache = false;
            if ($this->sender_status == self::STATUS_NEW) {
                $clearCache = true;
            }
            $this->scenario = 'remove';
            if (empty($this->messageReceivers)) {
                if (!$this->delete()) {
                    throw new Exception('Message removing error!');
                }
                if ($clearCache) {
                    Podium::getInstance()->podiumCache->deleteElement('user.newmessages', $this->sender_id);
                }
                $transaction->commit();
                return true;
            }
            $allDeleted = true;
            foreach ($this->messageReceivers as $mr) {
                if ($mr->receiver_status != MessageReceiver::STATUS_DELETED) {
                    $allDeleted = false;
                    break;
                }
            }
            if ($allDeleted) {
                foreach ($this->messageReceivers as $mr) {
                    if (!$mr->delete()) {
                        throw new Exception('Received message removing error!');
                    }
                }
                if (!$this->delete()) {
                    throw new Exception('Message removing error!');
                }
                if ($clearCache) {
                    Podium::getInstance()->podiumCache->deleteElement('user.newmessages', $this->sender_id);
                }
                $transaction->commit();
                return true;
            }
            $this->sender_status = self::STATUS_DELETED;
            if (!$this->save()) {
                throw new Exception('Message status changing error!');
            }
            if ($clearCache) {
                Podium::getInstance()->podiumCache->deleteElement('user.newmessages', $this->sender_id);
            }
            $transaction->commit();
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), $this->id, __METHOD__);
        }
        return false;
    }
310180
public function deletedBecauseEmpty()
    {
        if ($file = $this->getAttributeValue('file')) {
            return false;
        }

        if ($this->exists) {
            $this->delete();
        }

        return true;
    }