Mark a thumbnail as built or not.

@param Connection $connection
@param array $thumbnail
@param bool $built
768294
private function markThumbnailAsBuilt(Connection $connection, array $thumbnail, $built = true)
    {
        $key = $thumbnail;
        unset($key['lockID']);
        unset($key['lockExpires']);
        unset($key['path']);
        unset($key['isBuilt']);
        $connection->update('FileImageThumbnailPaths', ['isBuilt' => $built ? 1 : 0], $key);
    }
1245891
public static function buildByConnection($connection, $isDevMode = false)
    {
        $mappings = self::getXMLMappings();
        $config = Setup::createXMLMetadataConfiguration($mappings, $isDevMode);

        $entityManager = EntityManager::create($connection, $config);
        return new self($entityManager);
    }
389412
private function saveSeed(Connection $connection, string $class): void
    {
        $format = $connection->getSchemaManager()->getDatabasePlatform()->getDateTimeFormatString();
        $now    = (new DateTimeImmutable())->format($format);
        $connection->insert($this->getSeedsTable(), [
            static::SEEDS_COLUMN_CLASS     => $class,
            static::SEEDS_COLUMN_SEEDED_AT => $now,
        ]);
    }
397316
protected function save($connection, $commands)
    {
        $path = \Devil::getPathOf('@app/migrations/' . $connection);
        if (!file_exists($path . '/m_0.php')) $this->createMigrationTable($connection);
        $replace['${time}'] = $time = date('YmdHis');
        $replace['${connection}'] = $connection;
        $replace['${classname}'] = $class = 'm_' . $time;
        $replace['${up_body}'] = implode("\n", $commands['up']);
        $replace['${down_body}'] = implode("\n", array_reverse($commands['down']));
        file_put_contents($path . '/' . $class . '.php', $this->parseTemplate($replace));
    }
16848
private function attemptBuild(File $file, array $thumbnail)
    {
        try {
            // If the file is already built, return early
            if ($this->isBuilt($file, $thumbnail)) {
                return true;
            }

            // Otherwise lets attempt to build it
            if ($dimensions = $this->getDimensions($thumbnail)) {
                list($width, $height, $crop) = $dimensions;
                $type = new CustomThumbnail($width, $height, $thumbnail['path'], $crop);
                $fv = $file->getVersion($thumbnail['fileVersionID']);
                if ($fv->getTypeObject()->supportsThumbnails()) {
                    $fv->generateThumbnail($type);
                    $fv->releaseImagineImage();
                }
            } elseif ($type = Version::getByHandle($thumbnail['thumbnailTypeHandle'])) {
                // This is a predefined thumbnail type, lets just call the version->rescan
                $fv = $file->getVersion($thumbnail['fileVersionID']);

                if ($fv->getTypeObject()->supportsThumbnails()) {
                    $fv->generateThumbnail($type);
                    $fv->releaseImagineImage();
                }
            }
        } catch (\Exception $e) {
            // Catch any exceptions so we don't break the page and return false
            return false;
        }

        return $this->isBuilt($file, $thumbnail);
    }
249351
protected function compileCreateEncoding( $sql, Connection $connection, Blueprint $blueprint )
	{
		if ( isset( $blueprint->charset ) )
		{
			$sql .= ' default character set ' . $blueprint->charset;
		}
		elseif ( !is_null( $charset = $connection->getConfig( 'charset' ) ) )
		{
			$sql .= ' default character set ' . $charset;
		}

		if ( isset( $blueprint->collation ) )
		{
			$sql .= ' collate ' . $blueprint->collation;
		}
		elseif ( !is_null( $collation = $connection->getConfig( 'collation' ) ) )
		{
			$sql .= ' collate ' . $collation;
		}

		return $sql;
	}
1174141
protected function compileCreateTable($blueprint, $command, $connection)
    {
        return sprintf('%s table %s (%s)',
            $blueprint->temporary ? 'create temporary' : 'create',
            $this->wrapTable($blueprint),
            implode(', ', $this->getColumns($blueprint))
        );
    }
53313
protected function checkRequestsPerMinute(Connection $connection)
    {
        $id = $connection->getId();

        if (!isset($this->requests[$id])) {
            $this->requests[$id] = [];
        }

        // Add current token
        $this->requests[$id][] = time();

        // Expire old tokens
        while (reset($this->requests[$id]) < time() - 60) {
            array_shift($this->requests[$id]);
        }

        if (count($this->requests[$id]) > $this->options['requests_per_minute']) {
            $this->limit($connection, 'Requests per minute');
        }
    }
176641
public function getDatabaseMetadata(
        Connection $connection,
        string $databaseName
    ): DatabaseMetadata {
        // Get a list of table names
        $tableNameStatement = $connection
            ->createQueryBuilder()
            ->select([
                'tables.TABLE_NAME AS name'
            ])
            ->from('information_schema.TABLES', 'tables')
            ->where('TABLE_SCHEMA = :schema')
            ->andWhere('TABLE_TYPE = "BASE TABLE"')
            ->setParameter('schema', $databaseName)
            ->execute();

        // Build table metadata
        $tableMetadataList = [];
        while ($tableName = $tableNameStatement->fetchColumn(0)) {
            $tableMetadataList[] = $this->getTableMetadata($connection, $databaseName, $tableName);
        }

        return new DatabaseMetadata($databaseName, $tableMetadataList);
    }
476982
public function removeConnection(Connection $connection): void
    {
        $socket = $connection->getSocket();

        if ($socket->getResource()) {
            $index = $socket->getResourceId();
        } else {
            $index = array_search($connection, $this->connections);
        }

        if (!$index) {
            $this->logger->warning('Could not remove connection: not found');
        }

        unset($this->connections[$index]);
        unset($this->resources[$index]);

        $this->server->notify(
            Server::EVENT_SOCKET_DISCONNECT,
            [$connection->getSocket(), $connection]
        );
    }
258875
protected function releaseConnection(Connection $connection): void
    {
        $ip = $connection->getIp();

        if (!$ip) {
            $this->logger->warning('Cannot release connection');
            return;
        }

        if (!isset($this->ips[$ip])) {
            $this->ips[$ip] = 0;
        } else {
            $this->ips[$ip] = max(0, $this->ips[$ip] - 1);
        }

        unset($this->requests[$connection->getId()]);
    }
825857
protected function createTokensTable(Connection $connection, DatabaseSchemaInterface $schema): void
    {
        $manager = $connection->getSchemaManager();

        $table = new Table($schema->getTokensTable());
        $table->addColumn($schema->getTokensIdentityColumn(), Type::INTEGER)
            ->setNotnull(true)->setAutoincrement(true)->setUnsigned(true);
        $table->addColumn($schema->getTokensIsEnabledColumn(), Type::BOOLEAN)->setNotnull(true)->setDefault(true);
        $table->addColumn($schema->getTokensIsScopeModified(), Type::BOOLEAN)->setNotnull(true)->setDefault(false);
        $table->addColumn($schema->getTokensClientIdentityColumn(), Type::STRING)->setNotnull(true);
        $table->addColumn($schema->getTokensUserIdentityColumn(), Type::INTEGER)->setNotnull(false)->setUnsigned(true);
        $table->addColumn($schema->getTokensRedirectUriColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getTokensCodeColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getTokensTypeColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getTokensValueColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getTokensRefreshColumn(), Type::STRING)->setNotnull(false);
        $table->addColumn($schema->getTokensCodeCreatedAtColumn(), Type::DATETIME)->setNotnull(false);
        $table->addColumn($schema->getTokensValueCreatedAtColumn(), Type::DATETIME)->setNotnull(false);
        $table->addColumn($schema->getTokensRefreshCreatedAtColumn(), Type::DATETIME)->setNotnull(false);
        $table->setPrimaryKey([$schema->getTokensIdentityColumn()]);

        $table->addForeignKeyConstraint(
            $schema->getClientsTable(),
            [$schema->getTokensClientIdentityColumn()],
            [$schema->getClientsIdentityColumn()],
            $this->getOnDeleteCascadeConstraint()
        );

        $usersTable          = $schema->getUsersTable();
        $usersIdentityColumn = $schema->getUsersIdentityColumn();
        if ($usersTable !== null && $usersIdentityColumn !== null) {
            $table->addForeignKeyConstraint(
                $usersTable,
                [$schema->getTokensUserIdentityColumn()],
                [$usersIdentityColumn],
                $this->getOnDeleteCascadeConstraint()
            );
        }

        $manager->dropAndCreateTable($table);
    }
177528
public function onConnect($connection)
    {
        $connection->timeout_timerid = Timer::add(10, function () use ($connection) {
            Worker::log("Register auth timeout (".$connection->getRemoteIp()."). See http://wiki.workerman.net/Error4 for detail");
            $connection->close();
        }, null, false);
    }
940236
public function on($connection)
    {
        $this->setDatabase($connection);
        $this->_connection = null;

        $this->setDatabaseConnection($this->getDatabase());

        return $this;
    }
1325656
public function onSocketConnect($socket, Connection $connection): void
    {
        $this->checkConnections($connection);
        $this->checkConnectionsPerIp($connection);
    }
1103713
public static final void commit(final Connection connection) {
        if (connection == null) {
            return;
        }

        try {
            connection.commit();
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) LOG.warn("Error committing Connection: " + connection, e);
        }
    }
975581
protected function tailLogFile($path, $connection)
    {
        if (is_null($connection)) {
            $this->tailLocalLogs($path);
        } else {
            $this->tailRemoteLogs($path, $connection);
        }
    }