@author Vova Feldman (@svovaf)
@since  2.0.0

@param int|null|bool $network_level_or_blog_id
@param bool          $flush
3662
function clear( $network_level_or_blog_id = null, $flush = false ) {
            if ( ! $this->_is_multisite ||
                 false === $network_level_or_blog_id ||
                 is_null( $network_level_or_blog_id ) ||
                 is_numeric( $network_level_or_blog_id )
            ) {
                $site_options = $this->get_site_options( $network_level_or_blog_id );
                $site_options->clear( $flush );
            }

            if ( $this->_is_multisite &&
                 ( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
            ) {
                $this->_network_options->clear( $flush );
            }
        }
135008
private function updateLevel()
    {
        if (null === $this->output or OutputInterface::VERBOSITY_QUIET === ($verbosity = $this->output->getVerbosity())) {
            return false;
        }

        $this->setLevel(Logger::DEBUG);
        return true;
    }
1172463
function switch_to_blog( $blog_id, FS_Site $install = null ) {
            if ( $blog_id == $this->_context_is_network_or_blog_id ) {
                return;
            }

            switch_to_blog( $blog_id );
            $this->_context_is_network_or_blog_id = $blog_id;

            self::$_accounts->set_site_blog_context( $blog_id );
            $this->_storage->set_site_blog_context( $blog_id );
            $this->_storage->set_network_active( $this->_is_network_active, $this->is_delegated_connection( $blog_id ) );

            $this->_site = is_object( $install ) ?
                $install :
                $this->get_install_by_blog_id( $blog_id );

            $this->_user     = false;
            $this->_licenses = false;
            $this->_license  = null;

            if ( is_object( $this->_site ) ) {
                // Try to fetch user from install.
                $this->_user = self::_get_user_by_id( $this->_site->user_id );

                if ( ! is_object( $this->_user ) &&
                     FS_User::is_valid_id( $this->_storage->prev_user_id )
                ) {
                    // Try to fetch previously saved user.
                    $this->_user = self::_get_user_by_id( $this->_storage->prev_user_id );

                    if ( ! is_object( $this->_user ) ) {
                        // Fallback to network's user.
                        $this->_user = $this->get_network_user();
                    }
                }

                $all_plugin_licenses = self::get_all_licenses( $this->_module_id );

                if ( ! empty( $all_plugin_licenses ) ) {
                    if ( ! FS_Plugin_License::is_valid_id( $this->_site->license_id ) ) {
                        $this->_license = null;
                    } else {
                        $license_found = false;
                        foreach ( $all_plugin_licenses as $license ) {
                            if ( $license->id == $this->_site->license_id ) {
                                // License found.
                                $this->_license = $license;
                                $license_found  = true;
                                break;
                            }
                        }

                        if ( $license_found ) {
                            $this->link_license_2_user( $this->_license->id, $this->_user->id );
                        }
                    }

                    $this->_licenses = $this->get_user_licenses( $this->_user->id );
                }
            }

            unset( $this->_site_api );
            unset( $this->_user_api );
        }
728725
public static function hasLevel(int $level=null) :bool {
		// if we have said level
		return self::$_account ? 
			self::getAccount()->hasLevel($level) : false;
	}
137946
private function getRowLevel(string $id, int $lvl = 0)
    {
        reset($this->child_ids);

        foreach ($this->child_ids as $pid => $data) {
            if (!\in_array($id, $data['children'], true)) {
                continue;
            }
            if (!$pid) {
                return $lvl;
            }
            $lvl += $this->getRowLevel((string)$pid, $lvl++);
            break;
        }

        if ($lvl > $this->_max_level) {
            $this->_max_level = $lvl;
        }

        return $lvl;
    }
1076286
public function markAllAsSeen(NotifiableInterface $notifiable, $flush = false)
    {
        $nns = $this->notifiableNotificationRepository->findAllForNotifiable(
            $this->generateIdentifier($notifiable),
            ClassUtils::getRealClass(get_class($notifiable))
        );
        foreach ($nns as $nn) {
            $nn->setSeen(true);
            $event = new NotificationEvent($nn->getNotification(), $notifiable);
            $this->dispatcher->dispatch(MgiletNotificationEvents::SEEN, $event);
        }
        $this->flush($flush);
    }
562575
public function getNeutralStack($cvID = 'RECENT')
    {
        $result = null;
        $cID = $this->getNeutralStackID();
        if ($cID !== null) {
            $result = static::getByID($cID, $cvID);
        }

        return $result;
    }
652612
public function convertStatus($order, $statusId, $flush = false, $persist = true)
    {
        if ($order instanceof Order) {
            $order = $order->getEntity();
        }

        // get current status
        $currentStatus = $order->getStatus();
        if ($currentStatus) {
            if ($currentStatus instanceof \Massive\Bundle\Purchase\OrderBundle\Api\OrderStatus) {
                $currentStatus = $order->getStatus()->getEntity();
            }

            // if status has not changed, skip
            if ($currentStatus->getId() === $statusId) {
                return;
            }
        }

        // get desired status
        $statusEntity = $this->em
            ->getRepository(self::$orderStatusEntityName)
            ->find($statusId);
        if (!$statusEntity) {
            throw new EntityNotFoundException(self::$orderStatusEntityName, $statusId);
        }

        // ACTIVITY LOG
        $orderActivity = new OrderActivityLog();
        $orderActivity->setOrder($order);
        if ($currentStatus) {
            $orderActivity->setStatusFrom($currentStatus);
        }
        $orderActivity->setStatusTo($statusEntity);
        $orderActivity->setCreated(new \DateTime());
        if ($persist) {
            $this->em->persist($orderActivity);
        }

        // BITMASK
        $currentBitmaskStatus = $order->getBitmaskStatus();
        // if desired status already is in bitmask, remove current state
        // since this is a step back
        if ($currentBitmaskStatus && $currentBitmaskStatus & $statusEntity->getId()) {
            $order->setBitmaskStatus($currentBitmaskStatus & ~$currentStatus->getId());
        } else {
            // else increment bitmask status
            $order->setBitmaskStatus($currentBitmaskStatus | $statusEntity->getId());
        }

        // check if status has changed
        if ($statusId === OrderStatusEntity::STATUS_CREATED) {
            // TODO: re-edit - do some business logic
        }
        $order->setStatus($statusEntity);

        if ($flush === true) {
            $this->em->flush();
        }
    }
900436
public static function log ($message, $level = null) {
		$level = ($level !== null) ? $level : self::$default_level;
		return self::write (self::get_struct ($message, $level));
	}
1309735
public function deleteContent($contentId, $versionId = null)
    {
        // 1. Delete the Content
        if ($versionId === null) {
            $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['_id' => $contentId]]]), $this->contentDocumentTypeIdentifier);
        } else {
            $this->gateway->delete($contentId, $this->contentDocumentTypeIdentifier);
        }

        // 2. Delete all Content's Locations
        $this->gateway->deleteByQuery(json_encode(['query' => ['match' => ['content_id_id' => $contentId]]]), $this->locationDocumentTypeIdentifier);
    }
328310
public function _log($level, $fmt, $allArgs) {
        // The $allArgs variable contains the $fmt string
        array_shift($allArgs);
        $text = vsprintf($fmt, $allArgs);

        $this->_rawLogRecord(array(
            'level' => $level,
            'message' => $text,
        ), $allArgs);

        $this->flushIfNeeded();
        return $text;
    }
666570
public function flush($resetAfterwards = true)
    {
        if ($this->writer instanceof Writers\FlushableInterface) {
            return $this->writer->flush($resetAfterwards);
        } else {
            throw new \Exception('Flushing a non FlushableInterface is not possible');
        }
    }
305468
protected function assertValidQosLevel($level, $fromPacket = true)
    {
        if ($level < 0 || $level > 2) {
            $this->throwException(
                sprintf(
                    'Expected a quality of service level between 0 and 2 but got %d.',
                    $level
                ),
                $fromPacket
            );
        }
    }
717454
public function setLevel(\n2n\log4php\LoggerLevel $level = null) {
		if (isset($level)) {
			parent::setLevel($level);
		} else {
			throw new \n2n\log4php\LoggerException("log4php: Cannot set LoggerRoot level to null.", E_USER_WARNING);
		}
	}
311412
public function flushTraceId($id)
    {
        if (_CLI_) {
            if (isset($this->_traceId[$id])) {
                unset($this->_traceId[$id]);
            }
        }
    }
383843
protected function closeOutputBuffers(int $targetLevel = 0, bool $flush = false): void
    {
        $status = ob_get_status(true);
        $level = \count($status);

        while ($level-- > $targetLevel) {
            $flush ? ob_end_flush() : ob_end_clean();
        }
    }
1056473
public static function verify($categoryId = null, $forumId = null, $threadId = null, $id = null)
    {
        if (!is_numeric($categoryId) || $categoryId < 1
                || !is_numeric($forumId) || $forumId < 1
                || !is_numeric($threadId) || $threadId < 1
                || !is_numeric($id) || $id < 1) {
            return null;
        }
        return static::find()->joinWith(['thread', 'forum' => function ($query) use ($categoryId) {
                $query->joinWith(['category'])->andWhere([Category::tableName() . '.id' => $categoryId]);
            }])->where([
                static::tableName() . '.id' => $id,
                static::tableName() . '.thread_id' => $threadId,
                static::tableName() . '.forum_id' => $forumId,
            ])->limit(1)->one();
    }