@param bool $force Set TRUE if you need to get the open entity manager
even if the current entity manager is closed

@return EntityManager
337838
private function getEntityManager($force = false)
    {
        /** @var EntityManager $em */
        $em = $this->doctrine->getManagerForClass($this->entityClass);
        if ($force) {
            if (!$em->isOpen()) {
                $this->resetEntityManager();
                $em = $this->doctrine->getManagerForClass($this->entityClass);
            } else {
                /**
                 * ensure that the transaction is fully rolled back
                 * in case if a nested transaction is rolled back but the entity manager is not closed
                 * this may happen if the EntityManager::rollback() method is called
                 * without the call of EntityManager::close() method
                 * @link http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/transactions-and-concurrency.html#exception-handling
                 */
                $connection = $em->getConnection();
                if ($connection->getTransactionNestingLevel() > 0 && $connection->isRollbackOnly()) {
                    while ($connection->getTransactionNestingLevel() > 0) {
                        $connection->rollBack();
                    }
                }
            }
        }

        return $em;
    }
991462
public function check($force = false)
    {
        /*
         * Already know about updates, never retry.
         */
        $oldCount = Parameter::get('system::update.count');
        if ($oldCount > 0) {
            return $oldCount;
        }

        /*
         * Retry period not passed, skipping.
         */
        if (!$force
            && ($retryTimestamp = Parameter::get('system::update.retry'))
            && Carbon::createFromTimeStamp($retryTimestamp)->isFuture()
        ) {
            return $oldCount;
        }

        try {
            $result = $this->requestUpdateList();
            $newCount = array_get($result, 'update', 0);
        }
        catch (Exception $ex) {
            $newCount = 0;
        }

        /*
         * Remember update count, set retry date
         */
        Parameter::set('system::update.count', $newCount);
        Parameter::set('system::update.retry', Carbon::now()->addHours(24)->timestamp);

        return $newCount;
    }
718245
public function squash($force = false) {
        if ($this->cache !== null && !$force) return $this->cache;
        if ($this->parent) {
            return $this->cache = array_merge($this->parent->squash($force), $this->data);
        } else {
            return $this->cache = $this->data;
        }
    }
1174075
public function getUpdates($force = FALSE) {
		if (!$force) {
			$result = $this->cache->get('updates');
			if ($result) {
				return $result;
			}
		}

		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		$timestamp = parent::timestamp();
		$result = parent::post(
			'/all_updates',
			array(
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			)
		);

		if (!empty($result->updates_response)) {
			$this->auth_token = $result->updates_response->auth_token;
			$this->cache->set('updates', $result->updates_response);
			return $result->updates_response;
		}

		return $result;
	}
444289
public static function createEditorRole($force = false)
    {
        if(!$force) {
            if(Permission::exists('global', 'editor')) {
                return false;
            }
        }

        return self::createRole(
            'Editor', true, [[
            'app' => 'global',
            'key' => 'editor'
            ]]
        );
    }
845692
public function toggle(string $class, ?bool $force = null): bool
    {
        if ($force === null) {
            $classes = $this->getClasses();

            if (in_array($class, $classes, true)) {
                $this->remove($class);

                return false;
            }

            $this->add($class);

            return true;
        }

        if ($force === true) {
            $this->add($class);

            return true;
        }

        $this->remove($class);

        return false;
    }
121931
public function getLowFF(bool $force = false): int
    {
        if ($force || $this->isOver32()) {
            return 0xFFFFFFFF;
        }
        return $this->getLow32();
    }
839581
public function remove(string $name, bool $force = false)
    {
        return $this->curl->delete($this->base_url.'/'.$name.'?'.http_build_query([
                    'force' => $force,
                ]
            )
        );
    }
225960
public static function load($force = false) 
    {
        // already loaded
        if (!$force && self::$_loaded) {
            return false;
        }
        self::_resolveDefaultPath();

        $files = glob(realpath(self::$_path)."/*.php");
        foreach ($files as $file) {
            Log::log("loading factory from $file ...");
            include_once $file;
        }
        self::$_loaded = true;
        return self::$_loaded;
    }
327486
public function collect($force = false)
    {
        $active = $this->getPersistence()->get(self::class);
        if (!$active || $force) {
            $action = new GetActiveDeliveryExecution();
            $this->propagate($action);
            $active = $action->getNumberOfActiveActions();
            $this->getPersistence()->set(self::class, $active, $this->getOption(self::OPTION_TTL));
        }
        return $active;


    }
528844
public function getServices($force = false)
    {
        if ($this->nb_messaging_service_list === null) {
            $this->nb_messaging_service_list = new CNabuMessagingServiceList();
        }

        if ($this->nb_messaging_service_list->isEmpty() || $force) {
            $this->nb_messaging_service_list->clear();
            $this->nb_messaging_service_list->merge(CNabuMessagingService::getAllMessagingServices($this));
            $this->nb_messaging_service_list->iterate(function($key, CNabuMessagingService $nb_service) {
                $nb_service->setMessaging($this);
                return true;
            });
        }

        return $this->nb_messaging_service_list;
    }
353267
public function getMessagings($force = false)
    {
        if ($this->nb_messaging_list->isEmpty() || $force) {
            $this->nb_messaging_list->clear();
            $this->nb_messaging_list->merge(CNabuMessaging::getAllMessagings($this));
        }

        return $this->nb_messaging_list->getItems();
    }
1206477
protected function resetLang($force = false)
    {
        if ($this->autoResetLang || $force) {
            $this->lang = null;
        }

        return $this;
    }
122187
public function findAllToRefreshToken(bool $force = false)
    {
        $query = $this->newQuery();

        return $force ? $query->get() : $query->whereNull('token')->get();
    }
1003591
public function persist($force = false) {
        global $DB;

        if (!$this->dirty && !$force) {
            return $this;
        }

        if ($this->id) {
            $record = $this->to_record();
            $DB->update_record('tool_usertours_steps', $record);
        } else {
            $this->calculate_sortorder();
            $record = $this->to_record();
            unset($record->id);
            $this->id = $DB->insert_record('tool_usertours_steps', $record);
            $this->get_tour()->reset_step_sortorder();
        }

        $this->reload();

        // Notify of a change to the step configuration.
        // This must be done separately to tour change notifications.
        cache::notify_step_change($this->get_tourid());

        // Notify the cache that a tour has changed.
        // Tours are only stored in the cache if there are steps.
        // If there step count has changed for some reason, this will change the potential cache results.
        cache::notify_tour_change();

        return $this;
    }
1194647
public function getNaturalLanguages(bool $force = false) : CNabuLanguageList
    {
        $nb_natural = new CNabuLanguageList();
        $this->getLanguages($force)->iterate(function ($key, CNabuLanguage $nb_language) use ($nb_natural) {
            if ($nb_language->isNaturalLanguage()) {
                $nb_natural->addItem($nb_language);
            }
            return true;
        });

        return $nb_natural;
    }
384627
public function read($force = false)
	{
		// initialize the session
		$this->data = array();
		$this->keys = array();
		$this->flash = array();
		$this->record = null;

		// get the session cookie
		$cookie = $this->_get_cookie();

		// if a cookie was present, find the session record
		if ($cookie and ! $force and isset($cookie[0]))
		{
			// read the session record
			$this->record = \DB::select()->where('session_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

			// record found?
			if ($this->record->count())
			{
				$payload = $this->_unserialize($this->record->get('payload'));
			}
			else
			{
				// try to find the session on previous id
				$this->record = \DB::select()->where('previous_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

				// record found?
				if ($this->record->count())
				{
					$payload = $this->_unserialize($this->record->get('payload'));
				}
				else
				{
					// cookie present, but session record missing. force creation of a new session
					logger('DEBUG', 'Error: Session cookie with ID "'.$cookie[0].'" present but corresponding record is missing');
					return $this->read(true);
				}
			}

			if ( ! isset($payload[0]) or ! is_array($payload[0]))
			{
				logger('DEBUG', 'Error: not a valid db session payload!');
			}
			elseif ($payload[0]['updated'] + $this->config['expiration_time'] <= $this->time->get_timestamp())
			{
				logger('DEBUG', 'Error: session id has expired!');
			}
			elseif ($this->config['match_ip'] and $payload[0]['ip_hash'] !== md5(\Input::ip().\Input::real_ip()))
			{
				logger('DEBUG', 'Error: IP address in the session doesn\'t match this requests source IP!');
			}
			elseif ($this->config['match_ua'] and $payload[0]['user_agent'] !== \Input::user_agent())
			{
				logger('DEBUG', 'Error: User agent in the session doesn\'t match the browsers user agent string!');
			}
			else
			{
				// session is valid, retrieve the payload
				if (isset($payload[0]) and is_array($payload[0])) $this->keys  = $payload[0];
				if (isset($payload[1]) and is_array($payload[1])) $this->data  = $payload[1];
				if (isset($payload[2]) and is_array($payload[2])) $this->flash = $payload[2];
			}
		}

		return parent::read();
	}