Skip to content

Commit

Permalink
Continuing improvements to avoid relying on global state, first integ…
Browse files Browse the repository at this point in the history
…ration test passed.
  • Loading branch information
parpalak committed Mar 21, 2024
1 parent 90ff595 commit 962e3e1
Show file tree
Hide file tree
Showing 21 changed files with 384 additions and 270 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test_mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ jobs:
- name: Install dependencies
run: COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction

- name: Run test cases
- name: Run acceptance test cases
run: sh ./test_sh

- name: Run integration test cases
run: php _vendor/bin/codecept run integration

- name: Output logs
if: failure()
run: cat _cache/test/*.log && cat _tests/_output/email/*.txt
5 changes: 4 additions & 1 deletion .github/workflows/test_postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ jobs:
- name: Install dependencies
run: COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction

- name: Run test cases
- name: Run acceptance test cases
run: sh ./test_sh

- name: Run integration test cases
run: php _vendor/bin/codecept run integration

- name: Output logs
if: failure()
run: cat _cache/test/*.log && cat _tests/_output/email/*.txt
5 changes: 4 additions & 1 deletion .github/workflows/test_sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ jobs:
- name: Install dependencies
run: COMPOSER_MEMORY_LIMIT=-1 composer install --prefer-dist --no-interaction

- name: Run test cases
- name: Run acceptance test cases
run: sh ./test_sh

- name: Run integration test cases
run: php _vendor/bin/codecept run integration

- name: Output logs
if: failure()
run: cat _cache/test/*.log && cat _tests/_output/email/*.txt
24 changes: 15 additions & 9 deletions _admin/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/


use S2\Cms\Model\ExtensionCache;
use S2\Cms\Pdo\DbLayer;

if (!defined('S2_ROOT'))
Expand Down Expand Up @@ -359,10 +360,11 @@ function s2_install_extension ($id)
}
}


// Regenerate the hooks cache
S2Cache::clear();
S2Cache::generate_hooks();
/** @var ExtensionCache $cache */
$cache = \Container::get(ExtensionCache::class);
$cache->clear(); // TODO also clear DynamicConfigProvider cache
$cache->generateHooks();

return $messages;
}
Expand Down Expand Up @@ -458,9 +460,11 @@ function s2_flip_extension ($id)
$s2_db->buildAndQuery($query);


// Regenerate the hooks cache
S2Cache::clear();
S2Cache::generate_hooks();
// Regenerate the hooks cache
/** @var ExtensionCache $cache */
$cache = \Container::get(ExtensionCache::class);
$cache->clear(); // TODO also clear DynamicConfigProvider cache
$cache->generateHooks();

($hook = s2_hook('fn_flip_extension_end')) ? eval($hook) : null;

Expand Down Expand Up @@ -539,9 +543,11 @@ function s2_uninstall_extension ($id)
$s2_db->buildAndQuery($query);


// Regenerate the hooks cache
S2Cache::clear();
S2Cache::generate_hooks();
// Regenerate the hooks cache
/** @var ExtensionCache $cache */
$cache = \Container::get(ExtensionCache::class);
$cache->clear(); // TODO also clear DynamicConfigProvider cache
$cache->generateHooks();

($hook = s2_hook('fn_uninstall_extension_end')) ? eval($hook) : null;

Expand Down
2 changes: 1 addition & 1 deletion _admin/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function s2_stat_info ()

$version = array(
'<a href="http://s2cms.ru/" target="_blank">S2 '.S2_VERSION.' &uarr;</a>',
'© 2007–2023 Roman Parpalak',
'© 2007–2024 Roman Parpalak',
);

$environment = array(
Expand Down
37 changes: 21 additions & 16 deletions _admin/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use S2\Cms\CmsExtension;
use S2\Cms\Framework\Application;
use S2\Cms\Logger\Logger;
use S2\Cms\Model\ExtensionCache;
use S2\Cms\Pdo\DbLayer;
use S2\Cms\Pdo\DbLayerException;
use Symfony\Component\ErrorHandler\Debug;
Expand Down Expand Up @@ -68,21 +69,22 @@ function generate_config_file ()
foreach (array('', '/?', '/index.php', '/index.php?') as $prefix) {
$url_prefix = $prefix;
$content = s2_get_remote_file($base_url.$url_prefix.'/this/URL/_DoEs_/_NoT_/_eXiSt', 1, false, 10, true);
if ($content !== null && false !== strpos($content['content'], '<meta name="Generator" content="S2 '.S2_VERSION.'" />')) {
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2" />')) {
break;
}
}

$path = preg_replace('#^[^:/]+://[^/]*#', '', $base_url);

$use_https = false;
if (substr($base_url, 0, 8) == 'https://')
$use_https = true;
else
{
if (str_starts_with($base_url, 'https://')) {
$use_https = true;
}
else {
$content = s2_get_remote_file('https://'.substr($base_url, 7).$url_prefix.'/this/URL/_DoEs_/_NoT_/_eXiSt', 1, false, 10, true);
if ($content !== null && false !== strpos($content['content'], '<meta name="Generator" content="S2 '.S2_VERSION.'" />'))
$use_https = true;
if ($content !== null && str_contains($content['content'], '<meta name="Generator" content="S2" />')) {
$use_https = true;
}
}

return '<?php'."\n\n".'$db_type = \''.$db_type."';\n".
Expand Down Expand Up @@ -448,14 +450,15 @@ function get_preferred_lang ($languages)
$app->boot((static function (): array
{
$result = [
'root_dir' => S2_ROOT,
'cache_dir' => S2_CACHE_DIR,
'log_dir' => defined('S2_LOG_DIR') ? S2_LOG_DIR : S2_CACHE_DIR,
'base_url' => defined('S2_BASE_URL') ? S2_BASE_URL : null,
'base_path' => defined('S2_PATH') ? S2_PATH : null,
'debug' => defined('S2_DEBUG'),
'debug_view' => defined('S2_DEBUG_VIEW'),
'redirect_map' => [],
'root_dir' => S2_ROOT,
'cache_dir' => S2_CACHE_DIR,
'disable_cache' => false,
'log_dir' => defined('S2_LOG_DIR') ? S2_LOG_DIR : S2_CACHE_DIR,
'base_url' => defined('S2_BASE_URL') ? S2_BASE_URL : null,
'base_path' => defined('S2_PATH') ? S2_PATH : null,
'debug' => defined('S2_DEBUG'),
'debug_view' => defined('S2_DEBUG_VIEW'),
'redirect_map' => [],
];

foreach (['db_type', 'db_host', 'db_name', 'db_username', 'db_password', 'db_prefix', 'p_connect'] as $globalVarName) {
Expand Down Expand Up @@ -570,7 +573,9 @@ function get_preferred_lang ($languages)

$s2_db->close();

S2Cache::clear();
/** @var ExtensionCache $cache */
$cache = \Container::get(ExtensionCache::class);
$cache->clear();

$alerts = array();
// Check if the cache directory is writable
Expand Down
10 changes: 6 additions & 4 deletions _admin/site_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

use S2\Cms\Model\Model;
use S2\Cms\Model\ExtensionCache;
use S2\Cms\Pdo\DbLayer;

define('S2_ROOT', '../');
Expand Down Expand Up @@ -766,10 +767,11 @@
($hook = s2_hook('rq_action_refresh_hooks_start')) ? eval($hook) : null;
s2_test_user_rights($is_permission);

S2Cache::generate_hooks();
/** @var DbLayer $s2_db */
$s2_db = \Container::get(DbLayer::class);
S2Cache::generateEnabledExtensionClassNames($s2_db);
// Regenerate the hooks cache
/** @var ExtensionCache $cache */
$cache = \Container::get(ExtensionCache::class);
$cache->generateHooks();
$cache->generateEnabledExtensionClassNames();
}

elseif ($action == 'uninstall_extension')
Expand Down
130 changes: 0 additions & 130 deletions _include/S2Cache.php

This file was deleted.

Loading

0 comments on commit 962e3e1

Please sign in to comment.