|
|
@@ -629,12 +629,17 @@ class SiteController extends ActionController
|
|
|
* with no possibility of undoing anything. In this case, you'll have to confirm your intention
|
|
|
* by creating a file in the Typo3 root directory, named 'DEL####' (#### is the organization id)
|
|
|
*
|
|
|
+ * $redirectTo is the optional organization id to whom requests will be redirected
|
|
|
+ *
|
|
|
* @param int $organizationId
|
|
|
* @param bool $hard
|
|
|
+ * @param int|null $redirectTo
|
|
|
* @return int
|
|
|
- * @throws \Exception
|
|
|
+ * @throws NoSuchWebsiteException
|
|
|
+ * @throws \Doctrine\DBAL\ConnectionException
|
|
|
+ * @throws \Doctrine\DBAL\DBALException
|
|
|
*/
|
|
|
- public function deleteSiteAction(int $organizationId, bool $hard=false) {
|
|
|
+ public function deleteSiteAction(int $organizationId, bool $hard=false, ?int $redirectTo=null) {
|
|
|
$rootUid = $this->findRootUidFor($organizationId);
|
|
|
|
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
@@ -654,6 +659,12 @@ class SiteController extends ActionController
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ // Prepare the redirection
|
|
|
+ if ($redirectTo) {
|
|
|
+ $originUrl = $this->getSiteInfosAction($organizationId)['baseUrl'];
|
|
|
+ $targetUrl = $this->getSiteInfosAction($redirectTo)['baseUrl'];
|
|
|
+ }
|
|
|
+
|
|
|
// start transactions
|
|
|
$this->connectionPool->getConnectionByName('Default')->beginTransaction();
|
|
|
|
|
|
@@ -781,7 +792,12 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Try to commit the result (before any eventual file deletion or renaming)
|
|
|
+ // Add the redirection
|
|
|
+ if ($redirectTo) {
|
|
|
+ $this->addRedirection($originUrl, $targetUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Try to commit the result
|
|
|
$commitSuccess = $this->connectionPool->getConnectionByName('Default')->commit();
|
|
|
if (!$commitSuccess) {
|
|
|
throw new \RuntimeException('Something went wrong while commiting the result');
|
|
|
@@ -933,6 +949,10 @@ class SiteController extends ActionController
|
|
|
$renamed[$initialPath] = $newPath;
|
|
|
}
|
|
|
|
|
|
+ // remove eventual redirection from this site to another
|
|
|
+ $originUrl = $this->getSiteInfosAction($organizationId)['baseUrl'];
|
|
|
+ $this->removeRedirectionsFrom($originUrl);
|
|
|
+
|
|
|
// Try to commit the result
|
|
|
$commitSuccess = $this->connectionPool->getConnectionByName('Default')->commit();
|
|
|
if (!$commitSuccess) {
|
|
|
@@ -1206,9 +1226,17 @@ class SiteController extends ActionController
|
|
|
throw new \InvalidArgumentException("The given domain does not seems to be a valid domain: " . $newDomain);
|
|
|
}
|
|
|
|
|
|
- $rootUid = $this->findRootUidFor($organizationId);
|
|
|
+ $infos = $this->getSiteInfosAction($organizationId);
|
|
|
+ $originUrl = $infos['baseUrl'];
|
|
|
+ $rootUid = $infos['rootUid'];
|
|
|
+
|
|
|
$this->writeConfigFile($organizationId, $rootUid, $newDomain);
|
|
|
|
|
|
+ if ($redirect) {
|
|
|
+ // Add the redirection
|
|
|
+ $this->addRedirection($originUrl, $newDomain);
|
|
|
+ }
|
|
|
+
|
|
|
return $rootUid;
|
|
|
}
|
|
|
|
|
|
@@ -1260,7 +1288,6 @@ class SiteController extends ActionController
|
|
|
|
|
|
/**
|
|
|
* Add a new redirection from $fromDomain to $toDomain.
|
|
|
- * Domains should not contain the http(s):// part
|
|
|
* If this redirection already exists but has been deleted and/or disabled, it will be restored and enabled
|
|
|
* If a redirection already exists but is not deleted and targets another domain, a RuntimeException will be thrown.
|
|
|
*
|
|
|
@@ -1352,6 +1379,11 @@ class SiteController extends ActionController
|
|
|
*/
|
|
|
public function removeRedirectionsFrom($fromDomain, $hard=false): int
|
|
|
{
|
|
|
+ $fromDomain = preg_replace('/https?:\/\//', '', $fromDomain);
|
|
|
+ if (!preg_match(self::RX_DOMAIN, $fromDomain)) {
|
|
|
+ throw new \InvalidArgumentException("The does not seems to be a valid domain: " . $fromDomain);
|
|
|
+ }
|
|
|
+
|
|
|
$existing = $this->getRedirectionsFrom($fromDomain);
|
|
|
$deleted = 0;
|
|
|
foreach ($existing as $redirection) {
|
|
|
@@ -1398,7 +1430,7 @@ class SiteController extends ActionController
|
|
|
if ($rootUid > 0) {
|
|
|
return $rootUid;
|
|
|
}
|
|
|
- throw new NoSuchWebsiteException("The website of this organization can not be found");
|
|
|
+ throw new NoSuchWebsiteException("No website found for organization " . $organizationId);
|
|
|
}
|
|
|
|
|
|
/**
|