|
|
@@ -42,7 +42,7 @@ class OtWebsiteRepository
|
|
|
->execute()
|
|
|
->fetch();
|
|
|
if (!isset($website['uid'])) {
|
|
|
- throw new NoSuchWebsiteException('No website found for organization ' . $organizationId);
|
|
|
+ throw new NoSuchWebsiteException('No website found with uid ' . $uid);
|
|
|
}
|
|
|
return $website;
|
|
|
}
|
|
|
@@ -177,18 +177,16 @@ class OtWebsiteRepository
|
|
|
* Generate an array as it would be loaded from the site.yaml configuration
|
|
|
* file of the given website
|
|
|
*
|
|
|
- * @param int $rootUid
|
|
|
- * @param string $domain
|
|
|
+ * @param array $website
|
|
|
* @return Site
|
|
|
* @throws InvalidWebsiteConfigurationException
|
|
|
- * @throws NoSuchWebsiteException
|
|
|
*/
|
|
|
- public function generateWebsiteConfiguration(int $rootUid, string $domain): Site
|
|
|
+ public function generateWebsiteConfiguration(array $website): Site
|
|
|
{
|
|
|
- $website = $this->getWebsiteByPageUid($rootUid);
|
|
|
+ $rootUid = $this->getWebsiteRootUid($website['uid']);
|
|
|
|
|
|
return new Site(
|
|
|
- $website['uid'],
|
|
|
+ (string)$website['organization_id'],
|
|
|
$rootUid,
|
|
|
[
|
|
|
'base' => $this->resolveWebsiteBaseUri($website),
|
|
|
@@ -228,6 +226,44 @@ class OtWebsiteRepository
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Try to retrieve the website matching the given Uri
|
|
|
+ *
|
|
|
+ * @param \Psr\Http\Message\UriInterface $uri
|
|
|
+ * @param bool $devMode
|
|
|
+ * @return Site
|
|
|
+ * @throws NoSuchWebsiteException
|
|
|
+ */
|
|
|
+ public function matchUriToWebsite(\Psr\Http\Message\UriInterface $uri, bool $devMode=false): Site
|
|
|
+ {
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('ot_websites');
|
|
|
+
|
|
|
+ $q = $queryBuilder
|
|
|
+ ->select('*')
|
|
|
+ ->from('ot_websites');
|
|
|
+
|
|
|
+ if ($devMode) {
|
|
|
+ preg_match("/(\w+)(?:\/.*)?/", $uri->getPath(), $m);
|
|
|
+ $q = $q->where($queryBuilder->expr()->eq('subdomain', $queryBuilder->expr()->literal($m[1])));
|
|
|
+ } else {
|
|
|
+ preg_match("/([\w]+).opentalent.fr/", $uri->getHost(), $m);
|
|
|
+ if (count($m) > 0) {
|
|
|
+ $q = $q->where($queryBuilder->expr()->eq('subdomain', $queryBuilder->expr()->literal($m[1])));
|
|
|
+ } else {
|
|
|
+ $q = $q->where($queryBuilder->expr()->eq('custom_domain', $queryBuilder->expr()->literal($uri->getHost())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $website = $q->execute()
|
|
|
+ ->fetch();
|
|
|
+
|
|
|
+ if (!isset($website['uid'])) {
|
|
|
+ throw new NoSuchWebsiteException('No website found for this URI: ' . $uri);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->generateWebsiteConfiguration($website);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Try to find the config file of the website in the less resource-consuming way
|
|
|
* and parse it.
|