Ver Fonte

https://assistance.opentalent.fr/browse/V8-1928

Olivier Massot há 4 anos atrás
pai
commit
521b1c535a

+ 1 - 3
ot_admin/Classes/Controller/ScanController.php

@@ -1,9 +1,7 @@
 <?php
 
-
 namespace Opentalent\OtAdmin\Controller;
 
-
 use Opentalent\OtAdmin\Domain\Entity\ScanReport;
 use Opentalent\OtCore\Controller\ActionController;
 use Opentalent\OtCore\Domain\Repository\OrganizationRepository;
@@ -11,7 +9,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 
 /**
- * ScanController allows to scan the Typo3 DB to find potential issues
+ * ScanController scan the Typo3 DB to find potential issues
  */
 class ScanController extends ActionController
 {

+ 45 - 21
ot_admin/Classes/Controller/SiteController.php

@@ -65,11 +65,14 @@ class SiteController extends ActionController
         "manager" => 3, // Association writer full
     ];
 
+    // Creation mode
     const MODE_PROD = 1;
     const MODE_DEV = 1;
 
+    // Domain name validation
     const RX_DOMAIN = "/([a-z0-9A-Z]\.)*[a-z0-9-]+\.([a-z0-9]{2,24})+(\.co\.([a-z0-9]{2,24})|\.([a-z0-9]{2,24}))*\/?/";
 
+    // Redirections creation status
     const REDIRECTION_UNKNOWN_STATUS = 0;
     const REDIRECTION_UPDATED = 1;
     const REDIRECTION_CREATED = 2;
@@ -99,19 +102,19 @@ class SiteController extends ActionController
      * >> [slug => uid]
      * @var array
      */
-    private $createdPagesIndex;
+    private array $createdPagesIndex;
 
     /**
      * List of the directories created in the process (for rollback purposes)
      * @var array
      */
-    private $createdDirs;
+    private array $createdDirs;
 
     /**
      * List of the files created in the process (for rollback purposes)
      * @var array
      */
-    private $createdFiles;
+    private array $createdFiles;
 
     public function __construct()
     {
@@ -122,7 +125,7 @@ class SiteController extends ActionController
     }
 
     /**
-     * Return the main informations about the organization's website
+     * Return the SiteInfos object for the organization's website
      *
      * @param int $organizationId
      * @return SiteInfos
@@ -175,8 +178,8 @@ class SiteController extends ActionController
      * @return int Uid of the root page of the newly created website
      * @throws \RuntimeException|\Exception
      */
-    public function createSiteAction(int $organizationId, int $mode=self::MODE_PROD) {
-
+    public function createSiteAction(int $organizationId, int $mode=self::MODE_PROD): int
+    {
         $organization = $this->fetchOrganization($organizationId);
 
         // This extra-data can not be retrieved from the API for now, but
@@ -809,6 +812,10 @@ class SiteController extends ActionController
     }
 
     /**
+     * Delete a record from the typo3 db.
+     * If $hard is true, the record is permanently deleted.
+     * Else, it's just marked as deleted.
+     *
      * @param string $table
      * @param string $whereKey
      * @param $whereValue
@@ -830,7 +837,15 @@ class SiteController extends ActionController
         }
     }
 
-
+    /**
+     * Undo a soft-deletion performed using deleteSiteAction()
+     *
+     * @param int $organizationId
+     * @return int
+     * @throws NoSuchWebsiteException
+     * @throws \Doctrine\DBAL\ConnectionException
+     * @throws \Doctrine\DBAL\DBALException
+     */
     public function undeleteSiteAction(int $organizationId) {
         $rootUid = $this->findRootUidFor($organizationId);
 
@@ -1091,7 +1106,7 @@ class SiteController extends ActionController
     }
 
     /**
-     * Get the current status of the organization's website
+     * Get the current status and informations of the organization's website
      * If $fullScan is true, a deeper scan will be performed and warnings may be logged
      *
      * The status is among:
@@ -1328,10 +1343,12 @@ class SiteController extends ActionController
     /**
      * Retrieve the Organization object from the repository and then,
      * from the Opentalent API
+     *
      * @param $organizationId
      * @return Organization
      */
-    private function fetchOrganization($organizationId) {
+    private function fetchOrganization($organizationId): Organization
+    {
         $organizationRepository = GeneralUtility::makeInstance(ObjectManager::class)->get(OrganizationRepository::class);
         try {
             return $organizationRepository->findById($organizationId);
@@ -1348,7 +1365,8 @@ class SiteController extends ActionController
      * @return int
      * @throws NoSuchWebsiteException
      */
-    private function findRootUidFor($organizationId) {
+    private function findRootUidFor($organizationId): int
+    {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
         $queryBuilder->getRestrictions()->removeAll();
         $rootUid = $queryBuilder
@@ -1371,8 +1389,8 @@ class SiteController extends ActionController
      *
      * @return int
      */
-    private function getParentFolderUid() {
-
+    private function getParentFolderUid(): int
+    {
         $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages');
         $siteCount = $queryBuilder
             ->count('uid')
@@ -1431,8 +1449,8 @@ class SiteController extends ActionController
                                 string $slug,
                                 string $template = '',
                                 array $moreValues = []
-                                ) {
-
+                                ): int
+    {
         $defaultValues = [
             'pid' => $pid,
             'perms_groupid' => 3,
@@ -1471,7 +1489,8 @@ class SiteController extends ActionController
      * @param Organization $organization
      * @return int
      */
-    private function insertRootPage(Organization $organization) {
+    private function insertRootPage(Organization $organization): int
+    {
         return $this->insertPage(
             $organization,
             $this->getParentFolderUid(),
@@ -1588,7 +1607,8 @@ class SiteController extends ActionController
      * @param array $organizationExtraData
      * @return string
      */
-    private function getTemplateConstants(int $organizationId, array $organizationExtraData) {
+    private function getTemplateConstants(int $organizationId, array $organizationExtraData): string
+    {
         return "plugin.tx_ottemplating {\n" .
             "    settings {\n" .
             "        organization {\n" .
@@ -1649,7 +1669,8 @@ class SiteController extends ActionController
      * @param int $rootUid
      * @return array   Path of the configuration file and parsed configuration of the website
      */
-    protected function findConfigFileAndContentFor(int $organizationId, int $rootUid) {
+    protected function findConfigFileAndContentFor(int $organizationId, int $rootUid): array
+    {
 
         $configs_directory = $_ENV['TYPO3_PATH_APP'] . "/config/sites/";
         $candidates = scandir($configs_directory);
@@ -1683,7 +1704,8 @@ class SiteController extends ActionController
      * @param int $rootUid
      * @return array   Configuration of the website
      */
-    protected function findConfigFor(int $organizationId, int $rootUid) {
+    protected function findConfigFor(int $organizationId, int $rootUid): array
+    {
         $pathAndConfig = $this->findConfigFileAndContentFor($organizationId, $rootUid);
         return $pathAndConfig[1];
     }
@@ -1694,7 +1716,8 @@ class SiteController extends ActionController
      * @param int $rootUid
      * @return string   Path of the config file of the given website
      */
-    protected function findConfigFilePathFor(int $organizationId, int $rootUid) {
+    protected function findConfigFilePathFor(int $organizationId, int $rootUid): string
+    {
         $pathAndConfig = $this->findConfigFileAndContentFor($organizationId, $rootUid);
         return $pathAndConfig[0];
     }
@@ -1795,12 +1818,13 @@ class SiteController extends ActionController
      * @param int $rootUid
      * @param string $domain
      * @param array $userData
-     * @return int
+     * @return int The uid of the created be_user
      */
     private function createBeUser(int $organizationId,
                                   int $rootUid,
                                   string $domain,
-                                  array $userData) {
+                                  array $userData): int
+    {
 
         if (!isset($userData['username'])) {
             throw new \RuntimeException('Can not find any user with admin access in the Opentalent DB. Abort.');

+ 0 - 8
ot_admin/Classes/Domain/Entity/SiteInfos.php

@@ -8,21 +8,13 @@ namespace Opentalent\OtAdmin\Domain\Entity;
 class SiteInfos
 {
     protected int $rootUid;
-
     protected string $siteTitle = "";
-
     protected string $baseUrl = "";
-
     protected string $template = "";
-
     protected string $preferences = "";
-
     protected ?int $matomoId = null;
-
     protected bool $deleted = false;
-
     protected bool $hiddenOrRestricted = false;
-
     protected array $mountedForBeUsers = [];
 
     /**

+ 5 - 1
ot_admin/Classes/Http/ApiController.php

@@ -7,12 +7,16 @@ use Opentalent\OtAdmin\Controller\ScanController;
 use Opentalent\OtAdmin\Controller\SiteController;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
-use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 
+/**
+ * Actions for Http API calls
+ *
+ * @package Opentalent\OtAdmin\Http
+ */
 class ApiController implements LoggerAwareInterface
 {
     use LoggerAwareTrait;

+ 9 - 10
ot_admin/Readme.md

@@ -43,13 +43,12 @@ Les adresses IP autorisées sont:
 
 Les commandes disponibles sont:
 
-|||
-|---|---|
-| Create a new organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/create&organization-id=<organization_id>` |
-| Update an organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/update&organization-id=<organization_id>` |
-| Soft-delete an organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/delete&organization-id=<organization_id>` |
-| Restore a soft-deleted organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/undelete&organization-id=<organization_id>` |
-| Clear the website's cache | `<typo3_host>/typo3/index.php?route=/otadmin/site/clear-cache&organization-id=<organization_id>` |
-| Get the current status of the website | `<typo3_host>/typo3/index.php?route=/otadmin/site/status&organization-id=<organization_id>[&full=1]` |
-| Scan the whole Typo3 DB | `<typo3_host>/typo3/index.php?route=/otadmin/scan[&full=1]` |
-
+||||
+|---|---|---|
+| site/create | Create a new organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/create&organization-id=<organization_id>` |
+| site/update | Update an organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/update&organization-id=<organization_id>` |
+| site/delete | Soft-delete an organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/delete&organization-id=<organization_id>` |
+| site/undelete | Restore a soft-deleted organization | `<typo3_host>/typo3/index.php?route=/otadmin/site/undelete&organization-id=<organization_id>` |
+| site/clear-cache | Clear the website's cache | `<typo3_host>/typo3/index.php?route=/otadmin/site/clear-cache&organization-id=<organization_id>` |
+| site/status | Get the current status of the website | `<typo3_host>/typo3/index.php?route=/otadmin/site/status&organization-id=<organization_id>[&full=1]` |
+| scan | Scan the whole Typo3 DB | `<typo3_host>/typo3/index.php?route=/otadmin/scan[&full=1]` |