|
|
@@ -3,13 +3,14 @@
|
|
|
namespace Opentalent\OtAdmin\Controller;
|
|
|
|
|
|
use http\Exception\RuntimeException;
|
|
|
+use Opentalent\OtAdmin\Domain\Entity\SiteInfos;
|
|
|
+use Opentalent\OtAdmin\Domain\Entity\SiteStatus;
|
|
|
use Opentalent\OtAdmin\Exception\NoSuchWebsiteException;
|
|
|
use Opentalent\OtCore\Cache\OtCacheManager;
|
|
|
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\Page\OtPageRepository;
|
|
|
use PDO;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
use TYPO3\CMS\Core\Crypto\Random;
|
|
|
@@ -64,21 +65,6 @@ class SiteController extends ActionController
|
|
|
"manager" => 3, // Association writer full
|
|
|
];
|
|
|
|
|
|
- // Websites statuses
|
|
|
- const STATUS_NO_SUCH_WEBSITE = 0;
|
|
|
- const STATUS_EXISTING = 1;
|
|
|
- const STATUS_EXISTING_DELETED = 2;
|
|
|
- const STATUS_EXISTING_HIDDEN = 3;
|
|
|
- const STATUS_EXISTING_WITH_WARNINGS = 4;
|
|
|
-
|
|
|
- const STATUS_LBL = [
|
|
|
- self::STATUS_NO_SUCH_WEBSITE => 'Does not exist',
|
|
|
- self::STATUS_EXISTING => 'Existing',
|
|
|
- self::STATUS_EXISTING_DELETED => 'Existing, deleted',
|
|
|
- self::STATUS_EXISTING_HIDDEN => 'Existing, hidden',
|
|
|
- self::STATUS_EXISTING_WITH_WARNINGS => 'Existing with warnings',
|
|
|
- ];
|
|
|
-
|
|
|
const MODE_PROD = 1;
|
|
|
const MODE_DEV = 1;
|
|
|
|
|
|
@@ -139,27 +125,27 @@ class SiteController extends ActionController
|
|
|
* Return the main informations about the organization's website
|
|
|
*
|
|
|
* @param int $organizationId
|
|
|
- * @return array
|
|
|
+ * @return SiteInfos
|
|
|
* @throws NoSuchWebsiteException
|
|
|
*/
|
|
|
- public function getSiteInfosAction(int $organizationId) {
|
|
|
+ public function getSiteInfosAction(int $organizationId): SiteInfos
|
|
|
+ {
|
|
|
$rootUid = $this->findRootUidFor($organizationId);
|
|
|
$config = $this->findConfigFor($organizationId, $rootUid);
|
|
|
- $extraData = $this->fetchOrganizationExtraData($organizationId);
|
|
|
+ //$extraData = $this->fetchOrganizationExtraData($organizationId);
|
|
|
|
|
|
$rootPage = $this->otPageRepository->getPage($rootUid);
|
|
|
|
|
|
- $site = [
|
|
|
- 'rootUid' => $rootUid,
|
|
|
- 'siteTitle' => $rootPage['title'],
|
|
|
- 'baseUrl' => $config['base'],
|
|
|
- 'template' => $rootPage['tx_opentalent_template'],
|
|
|
- 'preferences' => $rootPage['tx_opentalent_template_preferences'],
|
|
|
- 'matomo_id' => $rootPage['tx_opentalent_matomo_id'],
|
|
|
- 'deleted' => $rootPage['deleted'],
|
|
|
- 'hiddenOrRestricted' => (int)($rootPage['hidden'] || $rootPage['fe_group'] < 0),
|
|
|
- 'mountedForBeUsers' => []
|
|
|
- ];
|
|
|
+ $site = new SiteInfos(
|
|
|
+ $rootUid,
|
|
|
+ $rootPage['title'],
|
|
|
+ $config['base'],
|
|
|
+ $rootPage['tx_opentalent_template'],
|
|
|
+ $rootPage['tx_opentalent_template_preferences'],
|
|
|
+ $rootPage['tx_opentalent_matomo_id'],
|
|
|
+ (bool)$rootPage['deleted'],
|
|
|
+ (bool)($rootPage['hidden'] || $rootPage['fe_group'] < 0)
|
|
|
+ );
|
|
|
|
|
|
// Owners
|
|
|
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
|
|
|
@@ -172,7 +158,7 @@ class SiteController extends ActionController
|
|
|
->fetchAll();
|
|
|
|
|
|
foreach ($beUsers as $beUser) {
|
|
|
- $site['mountedForBeUsers'][] = $beUser;
|
|
|
+ $site->addMountedForBeUser($beUser);
|
|
|
}
|
|
|
|
|
|
return $site;
|
|
|
@@ -664,8 +650,8 @@ class SiteController extends ActionController
|
|
|
if ($redirectTo == $organizationId) {
|
|
|
throw new \InvalidArgumentException('redirectTo value has to be different from the organizationId');
|
|
|
}
|
|
|
- $originUrl = $this->getSiteInfosAction($organizationId)['baseUrl'];
|
|
|
- $targetUrl = $this->getSiteInfosAction($redirectTo)['baseUrl'];
|
|
|
+ $originUrl = $this->getSiteInfosAction($organizationId)->getBaseUrl();
|
|
|
+ $targetUrl = $this->getSiteInfosAction($redirectTo)->getBaseUrl();
|
|
|
}
|
|
|
|
|
|
// start transactions
|
|
|
@@ -953,7 +939,7 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
|
|
|
// remove eventual redirection from this site to another
|
|
|
- $originUrl = $this->getSiteInfosAction($organizationId)['baseUrl'];
|
|
|
+ $originUrl = $this->getSiteInfosAction($organizationId)->getBaseUrl();
|
|
|
$this->removeRedirectionsFrom($originUrl);
|
|
|
|
|
|
// Try to commit the result
|
|
|
@@ -990,55 +976,6 @@ class SiteController extends ActionController
|
|
|
return $rootUid;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Pack the status informations into an array for the getSiteStatusAction method
|
|
|
- *
|
|
|
- * @param int $organizationId
|
|
|
- * @param int $code
|
|
|
- * @param int|null $rootUid
|
|
|
- * @param array|null $warnings
|
|
|
- * @return array
|
|
|
- */
|
|
|
- private function buildStatusResult(
|
|
|
- int $organizationId,
|
|
|
- int $code,
|
|
|
- ?int $rootUid = null,
|
|
|
- ?array $warnings = null): array
|
|
|
- {
|
|
|
- $message = "";
|
|
|
- if($code == self::STATUS_NO_SUCH_WEBSITE) {
|
|
|
- $message = 'No website were found for organization ' . $organizationId;
|
|
|
- } elseif ($code == self::STATUS_EXISTING) {
|
|
|
- $message = 'A website exists for organization ' . $organizationId;
|
|
|
- }
|
|
|
- elseif ($code == self::STATUS_EXISTING_DELETED) {
|
|
|
- $message = 'A website exists for organization ' . $organizationId . ', but has been deleted';
|
|
|
- }
|
|
|
- elseif ($code == self::STATUS_EXISTING_HIDDEN) {
|
|
|
- $message = 'A website exists for organization ' . $organizationId . ', but is hidden or has a restricted access';
|
|
|
- } elseif ($code == self::STATUS_EXISTING_WITH_WARNINGS) {
|
|
|
- $message = 'A website exists for organization ' . $organizationId . ', but warnings were raised';
|
|
|
- }
|
|
|
-
|
|
|
- $title = '';
|
|
|
- if ($rootUid !== null) {
|
|
|
- $title = $this->otPageRepository->getPage($rootUid)['title'];
|
|
|
- }
|
|
|
-
|
|
|
- $status = [
|
|
|
- 'organization_id' => $organizationId,
|
|
|
- 'code' => $code,
|
|
|
- 'status' => self::STATUS_LBL[$code],
|
|
|
- 'message' => $message,
|
|
|
- 'root_uid' => $rootUid,
|
|
|
- 'title' => $title
|
|
|
- ];
|
|
|
- if ($warnings !== null) {
|
|
|
- $status['warnings'] = $warnings;
|
|
|
- }
|
|
|
- return $status;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Perform a full scan of the website and returns a list of warnings
|
|
|
*
|
|
|
@@ -1155,22 +1092,9 @@ class SiteController extends ActionController
|
|
|
|
|
|
/**
|
|
|
* Get the current status of the organization's website
|
|
|
+ * If $fullScan is true, a deeper scan will be performed and warnings may be logged
|
|
|
*
|
|
|
- * The result is an array of the form:
|
|
|
- *
|
|
|
- * [
|
|
|
- * 'organization_id' => int,
|
|
|
- * 'code' => int,
|
|
|
- * 'status' => int,
|
|
|
- * 'message' => string,
|
|
|
- * 'root_uid' => ?int,
|
|
|
- * 'site_title' => ?string,
|
|
|
- * ('warnings' => array)
|
|
|
- * ]
|
|
|
- *
|
|
|
- * If $statusOnly is true, the warnings entry won't be added
|
|
|
- *
|
|
|
- * The code value is among:
|
|
|
+ * The status is among:
|
|
|
*
|
|
|
* - STATUS_NO_SUCH_WEBSITE
|
|
|
* - STATUS_EXISTING
|
|
|
@@ -1181,34 +1105,35 @@ class SiteController extends ActionController
|
|
|
* @param int $organizationId the organization's id whom site cache should be cleared
|
|
|
* @param bool $fullScan If true, a 'warnings' entry will be added to the result, and a full scan of
|
|
|
* the website pages will be performed.
|
|
|
- * @return array
|
|
|
+ * @return SiteStatus
|
|
|
*/
|
|
|
- public function getSiteStatusAction(int $organizationId, bool $fullScan = false): array
|
|
|
+ public function getSiteStatusAction(int $organizationId, bool $fullScan = false): SiteStatus
|
|
|
{
|
|
|
try {
|
|
|
- $rootUid = $this->findRootUidFor($organizationId);
|
|
|
+ $siteInfos = $this->getSiteInfosAction($organizationId);
|
|
|
} catch (NoSuchWebsiteException $e) {
|
|
|
- return $this->buildStatusResult($organizationId, self::STATUS_NO_SUCH_WEBSITE);
|
|
|
+ return new SiteStatus($organizationId, SiteStatus::STATUS_NO_SUCH_WEBSITE);
|
|
|
}
|
|
|
|
|
|
- if ($rootUid['deleted']) {
|
|
|
- return $this->buildStatusResult($organizationId, self::STATUS_EXISTING_DELETED, $rootUid);
|
|
|
+ if ($siteInfos->isDeleted()) {
|
|
|
+ return new SiteStatus($organizationId, SiteStatus::STATUS_EXISTING_DELETED, $siteInfos);
|
|
|
}
|
|
|
- if ($rootUid['hidden'] || ($rootUid['fe_group'] < 0)) {
|
|
|
- return $this->buildStatusResult($organizationId, self::STATUS_EXISTING_HIDDEN, $rootUid);
|
|
|
+ if ($siteInfos->isHiddenOrRestricted()) {
|
|
|
+ return new SiteStatus($organizationId, SiteStatus::STATUS_EXISTING_HIDDEN, $siteInfos);
|
|
|
}
|
|
|
|
|
|
$warnings = null;
|
|
|
if ($fullScan) {
|
|
|
// ** Look for potential issues
|
|
|
- $warnings = $this->scanSite($organizationId, $rootUid);
|
|
|
+ $warnings = $this->scanSite($organizationId, $siteInfos->getRootUid());
|
|
|
}
|
|
|
|
|
|
- return $this->buildStatusResult(
|
|
|
+ return new SiteStatus(
|
|
|
$organizationId,
|
|
|
- $warnings ? self::STATUS_EXISTING_WITH_WARNINGS : self::STATUS_EXISTING,
|
|
|
- $rootUid,
|
|
|
- $warnings);
|
|
|
+ $warnings ? SiteStatus::STATUS_EXISTING_WITH_WARNINGS : SiteStatus::STATUS_EXISTING,
|
|
|
+ $siteInfos,
|
|
|
+ $warnings
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1230,8 +1155,8 @@ class SiteController extends ActionController
|
|
|
}
|
|
|
|
|
|
$infos = $this->getSiteInfosAction($organizationId);
|
|
|
- $originUrl = $infos['baseUrl'];
|
|
|
- $rootUid = $infos['rootUid'];
|
|
|
+ $originUrl = $infos->getBaseUrl();
|
|
|
+ $rootUid = $infos->getRootUid();
|
|
|
|
|
|
if (preg_replace('/https?:\/\//', '', $originUrl) == preg_replace('/https?:\/\//', '', $newDomain) ) {
|
|
|
throw new \RuntimeException('The new domain should be different of the current one');
|