Caches the migrations internally in a static var for
faster access in subsequent calls

@return boolean true if caching was successful
176754
protected static function cacheMigrations()
	{
		//check if already cached
		if (static::$MIGRATION_CACHE !== null) return true;

		//check if there is a connection
		if (!static::hasDbConnection() || Yii::$app->db->schema->getTableSchema('{{%migration}}') === null) {
			return false;
		}

		//load the data
		static::$MIGRATION_CACHE = [];
		$migrationData = (new Query())
			->select(['version','apply_time'])
			->from('{{%migration}}')
			->orderBy(['apply_time'=>SORT_ASC])
			->all();

		//fill the cache
		foreach ($migrationData as $migration) {
			static::$MIGRATION_CACHE[$migration['version']] = $migration['apply_time'];
		}

		return true;
	}
839010
public function runMigrations()
    {
        $migrations = $this->getMigrationsToRun();
        $ran = [];

        if (empty($migrations)) {
            return $ran;
        }

        foreach ($migrations as $migration) {
            $this->runMigration($migration);
            $ran[] = $migration;
        }

        return $ran;
    }
593387
private function hasPropertiesToCache() {
		if (!isset($this->{__METHOD__})) {
			$this->{__METHOD__} = !!$this->cachedAll();
		}
		return $this->{__METHOD__};
	}
739366
protected function useCache()
    {
        // Should we use a cached version?
        if ($this->cache && $this->cacheExists()) {
            $this->templateOutput = $this->getCache();
            if ($this->templateOutput !== false) {
                return true;
            }
        }
        return false;
    }
987415
public function isCached() {
    $cache = ObjectFactory::getInstance('staticCache');
    return $this->id == self::NO_CACHE ? false :
            $cache->exists(self::getCacheSection($this->type), self::getCacheId($this->id));
  }
701535
public function migrationHasSoftDelete()
    {
        $hasSoftDelete = false;

        foreach ($this->getMigrations() as $migration) {

            if ($this->isCurrentMigration($migration->name) && !$migration->isMigrated()) {
                // At this point we know the migration is the current one
                // and has not been migrated, so ignore it
                continue;
            }

            if ($hasSoftDelete && !$migration->withSoftDelete) {
                // At this point we know that the migration had soft-delete
                // previously, but it was dropped
                $hasSoftDelete = false;
            }
            if ($migration->withSoftDelete) {
                // At this point we know that the migraton has soft-delete
                $hasSoftDelete = true;
            }
        }

        return $hasSoftDelete;
    }
833787
public function load($where)
    {
        $where = self::processWhere($where);

        $old_primary_key = $this->getPrimaryKey();

        $database = self::getDatabase();
        $data = $database->get(static::TABLE, static::COLUMNS, $where);
        if ($data) {
            $this->reset();
            $this->data = $data;
            if ($old_primary_key) {
                $this->managerUpdate($old_primary_key);
            } else {
                $this->managerExport();
            }
            return true;
        }

        return false;
    }
1195366
public function createMigration()
    {
        $migration = $this->laravel->path . '/database/migrations/' . date('Y_m_d_His') . '_drawbridge_migrations_tables.php';
        $view = $this->laravel->make('view')->make('drawbridge::migration')->render();

        if (! file_exists($migration))
        {
            $fs = fopen($migration, 'x');
            if ($fs)
            {
                fwrite($fs, $view);
                fclose($fs);
                return true;
            }
        }

        return false;
    }
978932
public function unsetDone() {
        $migration = $this->getMigration();
        if (!$migration['state']) {
            return true; //alredy undone
        }
        $this->db()->update($this->table, array('state' => false), array('id' => $migration['id']));
    }
436306
public function saveCacheListing() : bool
    {

        if (md5(json_encode($this->entryMetaData)) === $this->md5Sum) {
            return false;
        }

        return $this->engine->set(self::KEY_CACHE_LIST, $this->entryMetaData);
    }
104754
protected function loadFromCacheCache(): bool
    {
        if (file_exists($this->cacheFileName())) {
            $content = @file_get_contents($this->cacheFileName());
            if ($content) {
                TypeRegistry::setTypeMapping(unserialize($content));

                return true;
            }
        }

        return false;
    }
775631
protected static function _initializeCache()
    {
        if ( !static::$_options[CoreSettings::ENABLE_CACHE] )
        {
            return false;
        }

        //  Try memcached
        try
        {
            return static::$_cache = Flexistore::createMemcachedStore( array('host' => 'localhost') );
        }
        catch ( \Exception $_ex )
        {
        }

        //  Try memcache
        try
        {
            return static::$_cache = Flexistore::createMemcacheStore( array('host' => 'localhost') );
        }
        catch ( \Exception $_ex )
        {
        }

        //  Find me a cache path!
        if ( false === ( $_path = static::_getCachePath() ) )
        {
            return false;
        }

        //  Try files
        return static::$_cache = Flexistore::createFileStore( $_path );
    }
962109
protected function createMigration()
    {
        $migrationFile = base_path("/database/migrations") . "/" . date('Y_m_d_His')
            . "_create_settings_table.php";

        $output = $this->laravel->view->make('settings::generators.migration')->render();

        if (!file_exists($migrationFile) && $fs = fopen($migrationFile, 'x')) {
            fwrite($fs, $output);
            fclose($fs);

            return true;
        }

        return false;
    }
318314
public function alreadyUpdated()
    {
        $migrations = $this->getMigrations();
        $dbMigrations = $this->getExecutedMigrations();

        // If the count of migrations and dbMigrations is equal,
        // then the update as already been updated.
        if (count($migrations) == count($dbMigrations)) {
            return true;
        }

        // Continue, the app needs an update
        return false;
    }
783372
public function installMigration()
    {
        $name = $this->getParsedNameInput();

        $migrationDir = base_path() . '/database/migrations/';
        $migrationName = 'create_' . str_plural(snake_case($name)) .'_table.php';
        $migrationStub = new SplFileInfo(__DIR__ . '/../stubs/Model/migration.stub');

        $files = $this->files->allFiles($migrationDir);

        foreach ($files as $file) {
            if(str_contains($file->getFilename(), $migrationName)) {
                $this->putFile($file->getPathname(), $migrationStub);

                return true;
            }
        }

        $path = $migrationDir . date('Y_m_d_His') . '_' . $migrationName;
        $this->putFile($path, $migrationStub);

        return true;
    }
991974
public function update()
	{
		$db = \App::get('db');

		if (empty($db))
		{
			return false;
		}

		if (!is_numeric($this->gidNumber))
		{
			return false;
		}

		if (empty($this->_updatedkeys))
		{
			return true;
		}

		$query = "UPDATE `#__xgroups` SET ";

		$classvars = get_class_vars(__CLASS__);

		$first = true;
		$affected = 0;

		foreach ($classvars as $property => $value)
		{
			if (($property{0} == '_') || in_array($property, self::$_list_keys))
			{
				continue;
			}

			if (!in_array($property, $this->_updatedkeys))
			{
				continue;
			}

			if (!$first)
			{
				$query .= ',';
			}
			else
			{
				$first = false;
			}

			$value = $this->$property;

			if ($value === null)
			{
				$query .= "`$property`=NULL";
			}
			else
			{
				$query .= "`$property`=" . $db->quote($value);
			}
		}

		$query .= " WHERE `gidNumber`=" . $db->quote($this->gidNumber) . ";";

		if (($first != true) && !empty($query))
		{
			$db->setQuery($query);

			$result = $db->query();

			if ($result === false)
			{
				return false;
			}

			$affected = $db->getAffectedRows();
		}

		$aNewUserGroupEnrollments = array();

		foreach (self::$_list_keys as $property)
		{
			if (!in_array($property, $this->_updatedkeys))
			{
				continue;
			}

			$aux_table = "#__xgroups_" . $property;

			$list = $this->$property;

			if (!is_null($list) && !is_array($list))
			{
				$list = array($list);
			}

			$ulist = null;
			$tlist = null;

			foreach ($list as $value)
			{
				if (!is_null($ulist))
				{
					$ulist .= ',';
					$tlist .= ',';
				}

				$ulist .= $db->quote($value);
				$tlist .= '(' . $db->quote($this->gidNumber) . ',' . $db->quote($value) . ')';
			}

			// @FIXME: I don't have a better solution yet. But the next refactoring of this class
			// should eliminate the ability to read the entire member table due to problems with
			// scale on a large (thousands of members) groups. The add function should track the members
			// being added to a group, but would need to be verified to handle adding members
			// already in group. *njk*

			// @FIXME: Not neat, but because all group membership is resaved every time even for single additions
			// there is no nice way to detect only *new* additions without this check. I don't want to
			// fire off an 'onUserGroupEnrollment' event for users unless they are really being enrolled. *drb*

			if (in_array($property, array('members', 'managers')))
			{
				$query = "SELECT uidNumber FROM `#__xgroups_members` WHERE gidNumber=" . $this->gidNumber;
				$db->setQuery($query);

				// compile current list of members in this group
				$aExistingUserMembership = array();

				if (($results = $db->loadAssoc()))
				{
					foreach ($results as $uid)
					{
						$aExistingUserMembership[] = $uid;
					}
				}

				// see who is new, merge with previous additions so we have a complete list after we are done
				$aNewUserGroupEnrollments = array_merge($aNewUserGroupEnrollments, array_diff($list, $aExistingUserMembership));

			}

			if (is_array($list) && count($list) > 0)
			{
				if (in_array($property, array('members', 'managers', 'applicants', 'invitees')))
				{
					$query = "REPLACE INTO $aux_table (gidNumber,uidNumber) VALUES $tlist;";
				}

				$db->setQuery($query);

				if ($db->query())
				{
					$affected += $db->getAffectedRows();
				}
			}

			if (!is_array($list) || count($list) == 0)
			{
				if (in_array($property, array('members', 'managers', 'applicants', 'invitees')))
				{
					$query = "DELETE FROM $aux_table WHERE gidNumber=" . $db->quote($this->gidNumber) . ";";
				}
			}
			else
			{
				if (in_array($property, array('members', 'managers', 'applicants', 'invitees')))
				{
					$query = "DELETE m FROM `#__xgroups_$property` AS m WHERE " . " m.gidNumber=" .
						$db->quote($this->gidNumber) . " AND m.uidNumber NOT IN (" . $ulist . ");";
				}
			}

			$db->setQuery($query);

			if ($db->query())
			{
				$affected += $db->getAffectedRows();
			}
		}

		// After SQL is done and has no errors, fire off onGroupUserEnrolledEvents
		// for every user added to this group
		foreach ($aNewUserGroupEnrollments as $userid)
		{
			\Event::trigger('groups.onGroupUserEnrollment', array($this->gidNumber, $userid));
		}

		if ($affected > 0)
		{
			\Event::trigger('user.onAfterStoreGroup', array($this));
		}

		return true;
	}
133809
public static function cacheFlush()
    {
        foreach ( self::getCategories() as $category ) {
            foreach ( Yii::$app->i18n->languages as $language ) {
                Yii::$app->cache->delete([
                    'yii\i18n\DbMessageSource',
                    $category,
                    $language,
                ]);
            }
        }

        return true;
    }