|
|
@@ -12,6 +12,7 @@ use Opentalent\OtCore\Controller\ActionController;
|
|
|
use Opentalent\OtCore\Domain\Model\Organization;
|
|
|
use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
|
|
|
use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
+use Opentalent\OtCore\Utility\FileUtility;
|
|
|
use PDO;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
use TYPO3\CMS\Core\Crypto\Random;
|
|
|
@@ -517,15 +518,21 @@ class SiteController extends ActionController
|
|
|
// Create the site config.yaml file
|
|
|
$this->writeConfigFile($organizationId, $rootUid, $domain, true);
|
|
|
|
|
|
- // Create the user_upload directory and update the sys_filemounts table
|
|
|
+ // Create the user_upload and form_definitions directories and update the sys_filemounts table
|
|
|
$uploadRelPath = "/user_upload/" . $organizationId;
|
|
|
- $uploadDir = $_ENV['TYPO3_PATH_APP'] . "/public/fileadmin" . $uploadRelPath;
|
|
|
+ $fileadminDir = $_ENV['TYPO3_PATH_APP'] . "/public/fileadmin";
|
|
|
+ $uploadDir = $fileadminDir . "/" . $uploadRelPath;
|
|
|
if (file_exists($uploadDir)) {
|
|
|
throw new \RuntimeException("A directory or file " . $uploadDir . " already exists. Abort.");
|
|
|
}
|
|
|
-
|
|
|
+ $defaultUploadRelPath = $uploadRelPath . '/images';
|
|
|
$defaultUploadDir = $uploadDir . '/images';
|
|
|
- $formsDir = $uploadDir . '/Forms';
|
|
|
+
|
|
|
+ $formsRelPath = '/form_definitions/' . $organizationId;
|
|
|
+ $formsDir = $fileadminDir . $formsRelPath;
|
|
|
+ if (file_exists($formsDir)) {
|
|
|
+ throw new \RuntimeException("A directory or file " . $formsDir . " already exists. Abort.");
|
|
|
+ }
|
|
|
|
|
|
$this->mkDir($uploadDir);
|
|
|
$this->mkDir($defaultUploadDir);
|
|
|
@@ -536,7 +543,7 @@ class SiteController extends ActionController
|
|
|
$queryBuilder->insert('sys_filemounts')
|
|
|
->values([
|
|
|
'title' => 'Documents',
|
|
|
- 'path' => $defaultUploadDir,
|
|
|
+ 'path' => rtrim($defaultUploadRelPath, '/') . '/',
|
|
|
'base' => 1
|
|
|
])
|
|
|
->execute();
|
|
|
@@ -545,7 +552,7 @@ class SiteController extends ActionController
|
|
|
$queryBuilder->insert('sys_filemounts')
|
|
|
->values([
|
|
|
'title' => 'Forms_' . $organizationId,
|
|
|
- 'path' => $formsDir,
|
|
|
+ 'path' => rtrim($formsRelPath, '/') . '/',
|
|
|
'base' => 1
|
|
|
])
|
|
|
->execute();
|
|
|
@@ -652,15 +659,20 @@ class SiteController extends ActionController
|
|
|
*
|
|
|
* $redirectTo is the optional organization id to whom requests will be redirected
|
|
|
*
|
|
|
+ * The $force parameter, if true, will both bypass the 'DEL###' file confirmation and recursively delete the
|
|
|
+ * user_upload and form_definitions of the website. <!> USE WITH CAUTION
|
|
|
+ *
|
|
|
* @param int $organizationId
|
|
|
* @param bool $hard
|
|
|
* @param int|null $redirectTo
|
|
|
+ * @param bool $force
|
|
|
* @return int
|
|
|
+ * @throws NoSuchRecordException
|
|
|
* @throws NoSuchWebsiteException
|
|
|
- * @throws \Doctrine\DBAL\ConnectionException
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
|
+ * @throws \Throwable
|
|
|
*/
|
|
|
- public function deleteSiteAction(int $organizationId, bool $hard=false, ?int $redirectTo=null) {
|
|
|
+ public function deleteSiteAction(int $organizationId, bool $hard=false, ?int $redirectTo=null, bool $force = false) {
|
|
|
$rootUid = $this->findRootUidFor($organizationId);
|
|
|
|
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
@@ -672,7 +684,7 @@ class SiteController extends ActionController
|
|
|
->fetchColumn(0) == 1;
|
|
|
|
|
|
$confirm_file = $_ENV['TYPO3_PATH_APP'] . "/DEL" . $organizationId;
|
|
|
- if ($hard && !file_exists($confirm_file)) {
|
|
|
+ if ($hard && !file_exists($confirm_file) && !$force) {
|
|
|
throw new \RuntimeException(
|
|
|
"You are going to completely delete the website with root uid " . $rootUid .
|
|
|
", and all of its pages, files, contents...etc. If you are sure, create a file named '" .
|
|
|
@@ -710,16 +722,6 @@ class SiteController extends ActionController
|
|
|
$this->delete('sys_domain', 'pid', $rootUid, $hard);
|
|
|
}
|
|
|
|
|
|
- // remove filemounts
|
|
|
- $this->delete('sys_filemounts',
|
|
|
- 'path',
|
|
|
- "'/user_upload/" . $organizationId . "/images'",
|
|
|
- $hard);
|
|
|
- $this->delete('sys_filemounts',
|
|
|
- 'path',
|
|
|
- "'/user_upload/" . $organizationId . "/Forms'",
|
|
|
- $hard);
|
|
|
-
|
|
|
try {
|
|
|
$adminBeUserUid = $this->findAdminBeUserUid($rootUid);
|
|
|
if ($adminBeUserUid !== null) {
|
|
|
@@ -734,6 +736,19 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
} catch (NoSuchRecordException $e) {}
|
|
|
|
|
|
+ // Delete the filemounts
|
|
|
+ $queryBuilder = $this->connectionPool->getQueryBuilderForTable('sys_filemounts');
|
|
|
+ $queryBuilder
|
|
|
+ ->select('uid')
|
|
|
+ ->from('sys_filemounts')
|
|
|
+ ->where("path LIKE '%user_upload/" . $organizationId . "/%'")
|
|
|
+ ->orWhere("path LIKE '%form_definitions/" . $organizationId . "/%'");
|
|
|
+ $statement = $queryBuilder->execute();
|
|
|
+ $rows = $statement->fetchAll();
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $this->delete('sys_filemounts', 'uid', $row['uid'], $hard);
|
|
|
+ }
|
|
|
+
|
|
|
// Look up for the config.yaml file of the website
|
|
|
$configMainDir = $_ENV['TYPO3_PATH_APP'] . '/config/sites';
|
|
|
$configYamlFile = "";
|
|
|
@@ -755,28 +770,34 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
if (!$isDeleted) {
|
|
|
$uploadDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/user_upload/' . $organizationId . '/';
|
|
|
+ $formsDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/form_definitions/' . $organizationId . '/';
|
|
|
} else {
|
|
|
$uploadDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/user_upload/deleted_' . $organizationId . '/';
|
|
|
+ $formsDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/form_definitions/deleted_' . $organizationId . '/';
|
|
|
}
|
|
|
|
|
|
- // If hard deletion, verify that upload dirs are empty
|
|
|
- if ($hard && is_dir($uploadDir)) {
|
|
|
- foreach (scandir($uploadDir) as $subdir) {
|
|
|
- if ($subdir == '.' or $subdir == '..') {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $subdir = $uploadDir . $subdir;
|
|
|
- if (!is_dir($subdir)) {
|
|
|
- throw new \RuntimeException(
|
|
|
- 'The directory ' . $uploadDir . ' contains non-directory files' .
|
|
|
- ', this humble script prefers not to take care of them automatically. Abort.');
|
|
|
- }
|
|
|
- if (is_readable($subdir)) {
|
|
|
- foreach (scandir($subdir) as $filename) {
|
|
|
- if ($filename != '.' && $filename != '..') {
|
|
|
+ // If hard deletion, verify that dirs are empty
|
|
|
+ if (!$force) {
|
|
|
+ foreach ([$uploadDir, $formsDir] as $dir) {
|
|
|
+ if ($hard && is_dir($dir)) {
|
|
|
+ foreach (scandir($dir) as $subdir) {
|
|
|
+ if ($subdir == '.' or $subdir == '..') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $subdir = $dir . $subdir;
|
|
|
+ if (!is_dir($subdir)) {
|
|
|
throw new \RuntimeException(
|
|
|
- 'The directory ' . $subdir . ' is not empty, ' .
|
|
|
- 'this humble script prefers not to take care of them automatically. Abort.');
|
|
|
+ 'The directory ' . $dir . ' contains non-directory files' .
|
|
|
+ ', this humble script prefers not to take care of them automatically. Abort.');
|
|
|
+ }
|
|
|
+ if (is_readable($subdir)) {
|
|
|
+ foreach (scandir($subdir) as $filename) {
|
|
|
+ if ($filename != '.' && $filename != '..') {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ 'The directory ' . $subdir . ' is not empty, ' .
|
|
|
+ 'this humble script prefers not to take care of them automatically. Abort.');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -809,16 +830,16 @@ class SiteController extends ActionController
|
|
|
unlink($configYamlFile);
|
|
|
}
|
|
|
if (is_dir(dirname($configYamlFile))) {
|
|
|
- rmdir(dirname($configYamlFile));
|
|
|
+ FileUtility::rmdir(dirname($configYamlFile), $force);
|
|
|
}
|
|
|
if (is_dir($uploadDir . 'images')) {
|
|
|
- rmdir($uploadDir . 'images');
|
|
|
- }
|
|
|
- if (is_dir($uploadDir . 'Forms')) {
|
|
|
- rmdir($uploadDir . 'Forms');
|
|
|
+ FileUtility::rmdir($uploadDir . 'images', $force);
|
|
|
}
|
|
|
if (is_dir($uploadDir)) {
|
|
|
- rmdir($uploadDir);
|
|
|
+ FileUtility::rmdir($uploadDir, $force);
|
|
|
+ }
|
|
|
+ if (is_dir($formsDir)) {
|
|
|
+ FileUtility::rmdir($formsDir, $force);
|
|
|
}
|
|
|
} else {
|
|
|
$renamed = [];
|
|
|
@@ -994,6 +1015,7 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
}
|
|
|
$uploadDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/user_upload/deleted_' . $organizationId . '/';
|
|
|
+ $formsDir = $_ENV['TYPO3_PATH_APP'] . '/public/fileadmin/form_definitions/deleted_' . $organizationId . '/';
|
|
|
|
|
|
$toRename = [];
|
|
|
if (is_file($configYamlFile)) {
|
|
|
@@ -1002,6 +1024,9 @@ class SiteController extends ActionController
|
|
|
if (is_dir($uploadDir)) {
|
|
|
$toRename[$uploadDir] = dirname($uploadDir) . '/' . $organizationId;
|
|
|
}
|
|
|
+ if (is_dir($formsDir)) {
|
|
|
+ $toRename[$formsDir] = dirname($formsDir) . '/' . $organizationId;
|
|
|
+ }
|
|
|
|
|
|
foreach ($toRename as $initialPath => $newPath) {
|
|
|
if (is_file($newPath)) {
|
|
|
@@ -2112,7 +2137,6 @@ class SiteController extends ActionController
|
|
|
/**
|
|
|
* Create the BE user for the website, then return its uid
|
|
|
* The user shall be already created in the Opentalent DB
|
|
|
- * This is a minimal creation, that shall be completed by the ot_connect ext
|
|
|
*
|
|
|
* @param int $organizationId
|
|
|
* @param int $rootUid
|
|
|
@@ -2192,7 +2216,8 @@ class SiteController extends ActionController
|
|
|
$queryBuilder
|
|
|
->select('uid')
|
|
|
->from('sys_filemounts')
|
|
|
- ->where("path LIKE '%user_upload/" . $organizationId . "/%'");
|
|
|
+ ->where("path LIKE '%user_upload/" . $organizationId . "/%'")
|
|
|
+ ->orWhere("path LIKE '%form_definitions/" . $organizationId . "/'");
|
|
|
$statement = $queryBuilder->execute();
|
|
|
$rows = $statement->fetchAll(3) ?: [];
|
|
|
$files = [];
|