WHERE rc.constraint_schema = database() AND kcu.table_schema = database() AND rc.table_name = :tableName AND kcu.table_name = :tableName1 SQL; try { $rows = $this->db->createCommand($sql, [':tableName' => $table->name, ':tableName1' => $table->name])->queryAll(); $constraints = []; foreach ($rows as $row) { $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; } $table->foreignKeys = []; foreach ($constraints as $name => $constraint) { $table->foreignKeys[$name] = array_merge( [$constraint['referenced_table_name']], $constraint['columns'] );
{ // Because: https://bugs.php.net/bug.php?id=74980 if (PHP_VERSION_ID >= 70100 && strpos($message, 'Narrowing occurred during type inference. Please file a bug report') !== false) { return null; } return parent::handleError($code, $message, $file, $line); } /** * @inheritdoc */ public function getExceptionName($exception)
try { $rows = $this->db->createCommand($sql, [':tableName' => $table->name, ':tableName1' => $table->name])->queryAll(); $constraints = []; foreach ($rows as $row) { $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; } $table->foreignKeys = []; foreach ($constraints as $name => $constraint) { $table->foreignKeys[$name] = array_merge(
* * @param TableSchema $table the table metadata * @throws Exception */ protected function findConstraints($table) { parent::findConstraints($table); // Modified from parent to get extended FK information. $tableName = $this->quoteValue($table->name); $sql = <<<SQL SELECT
protected function loadTableSchema($name) { $table = new TableSchema; $this->resolveTableNames($table, $name); if ($this->findColumns($table)) { $this->findConstraints($table); return $table; } return null; }
} $rawName = $this->getRawTableName($name); if (!isset($this->_tableMetadata[$rawName])) { $this->loadTableMetadataFromCache($cache, $rawName); } if ($refresh || !array_key_exists($type, $this->_tableMetadata[$rawName])) { $this->_tableMetadata[$rawName][$type] = $this->{'loadTable' . ucfirst($type)}($rawName); $this->saveTableMetadataToCache($cache, $rawName); } return $this->_tableMetadata[$rawName][$type]; }
* @param string $name table name. The table name may contain schema name if any. Do not quote the table name. * @param bool $refresh whether to reload the table schema even if it is found in the cache. * @return TableSchema|null table metadata. `null` if the named table does not exist. */ public function getTableSchema($name, $refresh = false) { return $this->getTableMetadata($name, 'schema', $refresh); } /** * Returns the metadata for all tables in the database. * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema name. * @param bool $refresh whether to fetch the latest available table schemas. If this is `false`,
* @param string $name table name. * @param bool $refresh whether to reload the table schema even if it is found in the cache. * @return TableSchema table schema information. Null if the named table does not exist. */ public function getTableSchema($name, $refresh = false) { return $this->getSchema()->getTableSchema($name, $refresh); } /** * Returns the ID of the last inserted row or sequence value. * @param string $sequenceName name of the sequence object (required by some DBMS) * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object
{ // Default to refreshing the tables if Craft isn't installed yet if ($refresh || ($refresh === null && !Craft::$app->getIsInstalled())) { $this->getSchema()->refresh(); } if (($tableSchema = $this->getTableSchema($table)) === null) { return false; } return ($tableSchema->getColumn($column) !== null); }
* * @return bool * @todo remove schema version condition after next beakpoint */ private static function _supportsRevisionParams(): bool { return Craft::$app->getDb()->columnExists(Table::ELEMENTS, 'draftId'); } /** * @var string|null The name of the [[ElementInterface]] class. */ public $elementType;
/** * Applies draft and revision params to the query being prepared. * @throws QueryAbortedException */ private function _applyRevisionParams() { if (!self::_supportsRevisionParams()) { if ($this->drafts || $this->revisions) { throw new QueryAbortedException(); } return; }
if ($this->enabledForSite) { $this->subQuery->andWhere(['elements_sites.enabled' => true]); } $this->_applyRelatedToParam(); $this->_applyStructureParams($class); $this->_applyRevisionParams(); $this->_applySearchParam($builder->db); $this->_applyOrderByParams($builder->db); $this->_applySelectParam(); $this->_applyJoinParams(); // Give other classes a chance to make changes up front
* @return array the generated SQL statement (the first array element) and the corresponding * parameters to be bound to the SQL statement (the second array element). The parameters returned * include those provided in `$params`. */ public function build($query, $params = []) { $query = $query->prepare($this); $params = empty($params) ? $query->params : array_merge($params, $query->params); $clauses = [ $this->buildSelect($query->select, $params, $query->distinct, $query->selectOption), $this->buildFrom($query->from, $params),
*/ public function createCommand($db = null) { if ($db === null) { $db = Yii::$app->getDb(); } list($sql, $params) = $db->getQueryBuilder()->build($this); $command = $db->createCommand($sql, $params); $this->setCommandCache($command); return $command; }
*/ public function all($db = null) { if ($this->emulateExecution) { return []; } $rows = $this->createCommand($db)->queryAll(); return $this->populate($rows); } /** * Converts the raw query results into the format as specified by this query. * This method is internally used to convert the data fetched from database
/** * @inheritdoc */ public function all($db = null) { try { return parent::all($db); } catch (QueryAbortedException $e) { return []; } } /**
if ($this->with) { Craft::$app->getElements()->eagerLoadElements($this->elementType, $cachedResult, $this->with); } return $cachedResult; } return parent::all($db); } /** * @inheritdoc * @return ElementInterface|array|null the first element. Null is returned if the query * results in nothing.
if ($one) { /** @var Element|null $result */ $result = $query->one(); } else { /** @var Element[] $result */ $result = $query->all(); } return $result; } /**
/** * @inheritdoc */ public static function findAll($criteria = null): array { return static::findByCondition($criteria, false); } /** * @inheritdoc */ public static function sources(string $context = null): array
public function getAllSets(): array { if ($this->_allGlobalSets !== null) { return $this->_allGlobalSets; } $this->_allGlobalSets = GlobalSet::findAll(); $this->_globalSetsById = ArrayHelper::index($this->_allGlobalSets, 'id'); return $this->_allGlobalSets; } /**
$globals['currentSite'] = $site; $globals['siteName'] = $site->name; $globals['siteUrl'] = $site->getBaseUrl(); // Global sets (site templates only) if ($templateMode === View::TEMPLATE_MODE_SITE) { foreach (Craft::$app->getGlobals()->getAllSets() as $globalSet) { $globals[$globalSet->handle] = $globalSet; } } } else { $globals['systemName'] = null; $globals['currentSite'] = null;
$globals = []; foreach ($this->extensions as $extension) { if (!$extension instanceof GlobalsInterface) { continue; } $extGlobals = $extension->getGlobals(); if (!\is_array($extGlobals)) { throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); } $globals = array_merge($globals, $extGlobals); }
* @internal */ public function getGlobals() { if ($this->extensionSet->isInitialized()) { if (null === $this->resolvedGlobals) { $this->resolvedGlobals = array_merge($this->extensionSet->getGlobals(), $this->globals); } return $this->resolvedGlobals; } return array_merge($this->extensionSet->getGlobals(), $this->globals);
* @return array The context merged with the globals */ public function mergeGlobals(array $context) { // we don't use array_merge as the context being generally // bigger than globals, this code is faster. foreach ($this->getGlobals() as $key => $value) { if (!\array_key_exists($key, $context)) { $context[$key] = $value; } } return $context;
{ return $this->blocks; } public function display(array $context, array $blocks = []) { $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } public function render(array $context) { $level = ob_get_level(); if ($this->env->isDebug()) {
if ($this->env->isDebug()) { ob_start(); } else { ob_start(function () { return ''; }); } try { $this->display($context); } catch (\Throwable $e) { while (ob_get_level() > $level) { ob_end_clean(); } throw $e;
* @param array $context An array of parameters to pass to the template */ public function render(array $context = []): string { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code return $this->template->render($context, \func_get_args()[1] ?? []); } /** * Displays the template. * * @param array $context An array of parameters to pass to the template
* @throws LoaderError When the template cannot be found * @throws SyntaxError When an error occurred during compilation * @throws RuntimeError When an error occurred during rendering */ public function render($name, array $context = []) { return $this->load($name)->render($context); } /** * Displays a template. * * @param string|TemplateWrapper $name The template name
// Render and return $renderingTemplate = $this->_renderingTemplate; $this->_renderingTemplate = $template; $e = null; try { $output = $this->getTwig()->render($template, $variables); } catch (\Throwable $e) { // throw it later } $this->_renderingTemplate = $renderingTemplate; $this->setTemplateMode($oldTemplateMode);
$isRenderingPageTemplate = $this->_isRenderingPageTemplate; $this->_isRenderingPageTemplate = true; $e = null; try { $this->beginPage(); echo $this->renderTemplate($template, $variables); $this->endPage(); } catch (\Throwable $e) { // throw it later } $this->_isRenderingPageTemplate = $isRenderingPageTemplate;
} $headers->set('content-type', $mimeType . '; charset=' . $response->charset); } // Render and return the template $response->data = $this->getView()->renderPageTemplate($template, $variables, $templateMode); // Prevent a response formatter from overriding the content-type header $response->format = YiiResponse::FORMAT_RAW; return $response; }
// Merge any additional route params $routeParams = Craft::$app->getUrlManager()->getRouteParams(); unset($routeParams['template'], $routeParams['template']); $variables = array_merge($variables, $routeParams); return $this->renderTemplate($template, $variables); } /** * Shows the 'offline' template. * * @return Response
$args = $this->controller->bindActionParams($this, $params); Yii::debug('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
/** * @inheritdoc */ public function runAction($id, $params = []) { try { return parent::runAction($id, $params); } catch (\Throwable $e) { if (Craft::$app->getRequest()->getAcceptsJson()) { Craft::$app->getErrorHandler()->logException($e); if (!YII_DEBUG && !$e instanceof UserException) { $message = Craft::t('app', 'A server error occurred.'); } else {
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
* @param string $route * @param array $params * @return Response|null The result of the action, normalized into a Response object */ public function runAction($route, $params = []) { $result = parent::runAction($route, $params); if ($result !== null) { if ($result instanceof Response) { return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::debug("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
if (($response = $this->_processActionRequest($request)) !== null) { return $response; } // If we're still here, finally let Yii do it's thing. try { return parent::handleRequest($request); } catch (\Throwable $e) { $this->_unregisterDebugModule(); throw $e; } }
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load(); } // Load and run Craft define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production'); $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php'; $app->run();