Browse Source

fixes for ot_admin commands (cache, file stats...)

Olivier Massot 5 năm trước cách đây
mục cha
commit
e36716e071
1 tập tin đã thay đổi với 29 bổ sung7 xóa
  1. 29 7
      ot_admin/Classes/Controller/SiteController.php

+ 29 - 7
ot_admin/Classes/Controller/SiteController.php

@@ -9,6 +9,7 @@ use Opentalent\OtTemplating\Page\OtPageRepository;
 use PDO;
 use Psr\Log\LoggerAwareInterface;
 use Symfony\Component\Yaml\Yaml;
+use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Crypto\Random;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -412,7 +413,7 @@ class SiteController extends ActionController
                     'sitetitle' => $organization->getName(),
                     'root' => 1,
                     'clear' => 3,
-                    'config' => "config = 'config.frontend_editing = 1",
+                    'config' => "config.frontend_editing = 1",
                     'include_static_file' => $include,
                     'constants' => $constants
                 ])
@@ -633,10 +634,14 @@ class SiteController extends ActionController
                             'The directory ' . $uploadDir . ' contains non-directory files' .
                             ', this humble script prefers not to take care of them automatically. Abort.');
                     }
-                    if (is_readable($subdir) && count(scandir($subdir)) > 0) {
-                        throw new \RuntimeException(
-                            'The directory ' . $subdir . ' is not empty, ' .
-                            '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.');
+                            }
+                        }
                     }
                 }
             }
@@ -1233,12 +1238,28 @@ class SiteController extends ActionController
             'rootPageId'=>$rootUid,
             'routes'=>[]
         ];
-        $yamlConfig = Yaml::dump($config, 4);
+        $yamlConfig = Yaml::dump($config, 99, 2);
 
         if (!file_exists($config_dir)) {
             $this->mkDir($config_dir);
         }
-        $this->writeFile($config_filename, $yamlConfig);
+        GeneralUtility::writeFile($config_filename, $yamlConfig);
+
+        // Set the owner and mods, in case www-data is not the one who run this command
+        // @see https://www.php.net/manual/fr/function.stat.php
+        try {
+            $stats = stat($_ENV['TYPO3_PATH_APP'] . '/public/index.php');
+            chown($config_filename, $stats['4']);
+            chgrp($config_filename, $stats['5']);
+            chmod($config_filename, $stats['2']);
+        } catch (\TYPO3\CMS\Core\Error\Exception $e) {
+        }
+
+        // Flush cache:
+        $cacheSystem = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
+        $cacheSystem->remove('site-configuration');
+        $cacheSystem->remove('pseudo-sites');
+
     }
 
 
@@ -1285,6 +1306,7 @@ class SiteController extends ActionController
             'lang' => 'fr',
             'usergroup' => isset(self::PRODUCT_MAPPING[$user_data['product']]) ? self::PRODUCT_MAPPING[$userData['product']] : 1,
             'db_mountpoints' => $rootUid,
+            'userMods' => 'file_FilelistList',
             'file_mountPoints' => join(',', $files),
             'options' => 2,
             'file_permissions' => 'readFolder,writeFolder,addFolder,renameFolder,moveFolder,deleteFolder,readFile,writeFile,addFile,renameFile,replaceFile,moveFile,copyFile,deleteFile',