开启一个协程事务

@param Context $context
请求上下文对象
@return MySql
184829
public function goBegin(Context $context = null)
    {
        $id = $this->bind($context);
        return $this->getDBQueryBuilder($context)->go($id, 'begin');
    }
1119933
public function context($context = null)
    {
        if (is_null($context)) {
            return $this->context;
        }

        $this->context = $context;

        return $this;
    }
1054198
public function getContext()
    {
        if (!isset($this->context)) {
            $request = $this->container->get('request');

            $this->context = new RequestContext();
            $this->context->fromRequest($request);
        }

        return $this->context;
    }
14987
public function executeRules(Context $context)
    {
        foreach ($this->rules as $rule) {
            $rule->execute($context);
        }
    }
171052
public function createQuery($context = 'list')
    {
        $query = parent::createQuery($context);
        $query->leftJoin($query->getRootAlias().'.article', 'article')->addSelect('article')
              ->leftJoin($query->getRootAlias().'.parent', 'parent')->addSelect('parent')
              ->leftJoin($query->getRootAlias().'.children', 'children')->addSelect('children')
              ->orderBy($query->getRootAlias().'.root, '.$query->getRootAlias().'.lft', 'ASC');

        return $query;
    }
211347
public function get_resourcelink_from_context(Context $context) {
        global $DB;

        $resourcelink = null;
        if ($resourcelinkrecord = $DB->get_record($this->resourcelinktable, ['contextid' => $context->getRecordId()],
            'ltiresourcelinkkey')) {
            $resourcelink = ResourceLink::fromContext($context, $resourcelinkrecord->ltiresourcelinkkey);
        }

        return $resourcelink;
    }
977144
public function context(Context $context = null) : Context
    {
        if (!$this->context) {
            $this->context = $context ?: new SimpleContext;
        }

        return $this->context;
    }
1336847
public function deleteContext($context)
    {

// Delete any outstanding share keys for resource links for this context
        $sql = sprintf('DELETE sk ' .
                       "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_SHARE_KEY_TABLE_NAME . ' sk ' .
                       "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON sk.resource_link_pk = rl.resource_link_pk ' .
                       'WHERE rl.context_pk = %d',
                       $context->getRecordId());
        mysql_query($sql);

// Delete any users in resource links for this context
        $sql = sprintf('DELETE u ' .
                       "FROM {$this->dbTableNamePrefix}" . DataConnector::USER_RESULT_TABLE_NAME . ' u ' .
                       "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON u.resource_link_pk = rl.resource_link_pk ' .
                       'WHERE rl.context_pk = %d',
                       $context->getRecordId());
        mysql_query($sql);

// Update any resource links for which this consumer is acting as a primary resource link
        $sql = sprintf("UPDATE {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' prl ' .
                       "INNER JOIN {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ON prl.primary_resource_link_pk = rl.resource_link_pk ' .
                       'SET prl.primary_resource_link_pk = null, prl.share_approved = null ' .
                       'WHERE rl.context_pk = %d',
                       $context->getRecordId());
        $ok = mysql_query($sql);

// Delete any resource links for this consumer
        $sql = sprintf('DELETE rl ' .
                       "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' rl ' .
                       'WHERE rl.context_pk = %d',
                       $context->getRecordId());
        mysql_query($sql);

// Delete context
        $sql = sprintf('DELETE c ' .
                       "FROM {$this->dbTableNamePrefix}" . DataConnector::CONTEXT_TABLE_NAME . ' c ',
                       'WHERE c.context_pk = %d',
                       $context->getRecordId());
        $ok = mysql_query($sql);
        if ($ok) {
            $context->initialize();
        }

        return $ok;

    }
823128
private function configureContext(Context $context)
    {
        foreach ($this->attributes as $key => $value) {
            $context->setAttribute($key, $value);
        }
        if (!empty($this->groups)) {
            $context->setGroups($this->groups);
        }

        if (($context instanceof SerializationContext) && $this->serializeNulls !== null) {
            $context->setSerializeNull($this->serializeNulls);
        }

        if ($this->enableMaxDepthChecks === true) {
            $context->enableMaxDepthChecks();
        }

        if ($this->version !== null) {
            $context->setVersion($this->version);
        }

        return $context;
    }
103233
protected function _buildQuery(ModelContextDatabase $context)
    {
        //Initialise the query
        $context->query->table(array('tbl' => $this->getTable()->getName()));

        if($context->action == 'fetch')
        {
            $context->query->columns('tbl.*');

            $this->_buildQueryColumns($context->query);
            $this->_buildQueryJoins($context->query);
            $this->_buildQueryWhere($context->query);
            $this->_buildQueryGroup($context->query);
        }

        if($context->action == 'count')
        {
            $context->query->columns('COUNT(*)');

            $this->_buildQueryJoins($context->query);
            $this->_buildQueryWhere($context->query);
        }
    }
694395
protected function getConnection($context)
    {
        $connectionName = null;

        if (!empty($context['options']['db_connection_name'])) {
            $connectionName = $context['options']['db_connection_name'];
        }

        return $this->doctrine->getConnection($connectionName);
    }
533586
public function get_context() : \context {
        if ($this->get('contextid')) {
            return \context::instance_by_id($this->get('contextid'));
        } else if ($this->get('instanceid')) {
            return $this->get_field()->get_handler()->get_instance_context($this->get('instanceid'));
        } else {
            // Context is not yet known (for example, entity is not yet created).
            return \context_system::instance();
        }
    }
1042983
public function getContext(ModelContextInterface $context = null)
    {
        $context = new ModelContextDatabase(parent::getContext());
        $context->setQuery($this->getObject('lib:database.query.select'));
        return $context;
    }
424927
public function saveContext($context) {
        global $DB;
        $now = time();
        $context->updated = $now;
        $settingsvalue = serialize($context->getSettings());
        $id = $context->getRecordId();
        $consumerpk = $context->getConsumer()->getRecordId();

        $isinsert = empty($id);
        if ($isinsert) {
            $context->created = $now;
            $params = [
                'consumerid' => $consumerpk,
                'lticontextkey' => $context->ltiContextId,
                'type' => $context->type,
                'settings' => $settingsvalue,
                'created' => $context->created,
                'updated' => $context->updated,
            ];
            $id = $DB->insert_record($this->contexttable, (object) $params);
            if ($id) {
                $context->setRecordId($id);
                return true;
            }
        } else {
            $data = (object) [
                'id' => $id,
                'contextid' => $consumerpk,
                'lticontextkey' => $context->ltiContextId,
                'type' => $context->type,
                'settings' => $settingsvalue,
                'updated' => $context->updated,
            ];
            return $DB->update_record($this->contexttable, $data);
        }

        return false;
    }
852063
protected static function get_sql_where_from_contexts(array $contexts) {
        global $DB;

        $sorted = array_reduce($contexts, function ($carry, $context) {
            $level = $context->contextlevel;
            if ($level == CONTEXT_MODULE || $level == CONTEXT_COURSE) {
                $carry[$level][] = $context->instanceid;
            } else if ($level == CONTEXT_SYSTEM) {
                $carry[$level] = $context->id;
            }
            return $carry;
        }, [
            CONTEXT_COURSE => [],
            CONTEXT_MODULE => [],
            CONTEXT_SYSTEM => null,
        ]);

        $sqls = [];
        $params = [];

        if (!empty($sorted[CONTEXT_MODULE])) {
            list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_MODULE], SQL_PARAMS_NAMED);
            $sqls[] = "cmid $insql";
            $params = array_merge($params, $inparams);
        }

        if (!empty($sorted[CONTEXT_COURSE])) {
            list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_COURSE], SQL_PARAMS_NAMED);

            $sqls[] = "cmid = 0 AND course $insql";
            $params = array_merge($params, $inparams);
        }

        if (!empty($sorted[CONTEXT_SYSTEM])) {
            $sqls[] = "course <= 0";
        }

        if (empty($sqls)) {
            return [null, null];
        }

        return ['((' . implode(') OR (', $sqls) . '))', $params];
    }
740585
public function createQuery($context = 'list')
    {
        /** @var ProxyQuery $query */
        $query = $this->getModelManager()->createQuery($this->getClass(), 'p');
        $qb = $query->getQueryBuilder();
        $qb->addSelect('c');
        $qb->leftJoin('p.contentRoute', 'c');
        $qb->orderBy('c.path', 'asc');

        return $query;
    }
1027945
protected function processTable($table, $context)
    {
        if (is_string($table)) {
            return $this->processTableName($table, $context);
        } else {
            return $this->processSubQuery($table, $context);
        }
    }