Skip to content

Commit

Permalink
Merge branch 'bugfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Apr 15, 2022
2 parents 61a90a6 + da96794 commit a1079f5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion redaxo/src/addons/debug/boot.php
@@ -1,6 +1,6 @@
<?php

if (!rex::isDebugMode() || 'debug' === rex_get(rex_api_function::REQ_CALL_PARAM)) {
if (!rex_debug_clockwork::isRexDebugEnabled() || 'debug' === rex_get(rex_api_function::REQ_CALL_PARAM)) {
return;
}

Expand Down
18 changes: 18 additions & 0 deletions redaxo/src/addons/debug/lib/debug_clockwork.php
Expand Up @@ -71,4 +71,22 @@ public static function getStoragePath()
{
return rex_addon::get('debug')->getCachePath('clockwork.db');
}

/**
* We cannot rely on rex::isDebugMode() because it is always true on the console.
* So we have to check the config file itself.
*/
public static function isRexDebugEnabled(): bool
{
if (PHP_SAPI !== 'cli') {
return rex::isDebugMode();
}

$coreConfigCacheFile = rex_path::coreCache('config.yml.cache');
$coreConfigCache = rex_file::getCache($coreConfigCacheFile);
/** @var bool $debugEnabled */
$debugEnabled = $coreConfigCache['debug']['enabled'] ?? false;

return $debugEnabled;
}
}
Expand Up @@ -42,7 +42,7 @@ function rex_mediapool_saveMedia($FILE, $rexFileCategory, $FILEINFOS, $userlogin
if ($FILE) {
$data['file'] = $FILE;

if (!isset($data['file']['path']) && isset($FILE['name'])) {
if (!isset($data['file']['path']) && isset($FILE['name']) && !isset($FILE['tmp_name'])) {
$data['file']['path'] = rex_path::media($FILE['name']);
}
}
Expand Down
16 changes: 15 additions & 1 deletion redaxo/src/core/lib/console/assets_sync.php
Expand Up @@ -62,7 +62,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
$errored += $err;
}

[$ctd, $upd, $err] = $this->sync($io, rex_path::coreAssets(), rex_path::core('assets/'));
$assetsPublicPath = rex_path::coreAssets();
$assetsSrcPath = rex_path::core('assets/');
if (!is_dir($assetsPublicPath)) {
rex_dir::create($assetsPublicPath);
}
if (!is_dir($assetsSrcPath)) {
rex_dir::create($assetsSrcPath);
}

[$ctd, $upd, $err] = $this->sync($io, $assetsPublicPath, $assetsSrcPath);
$created += $ctd;
$updated += $upd;
$errored += $err;

[$ctd, $upd, $err] = $this->sync($io, $assetsSrcPath, $assetsPublicPath);
$created += $ctd;
$updated += $upd;
$errored += $err;
Expand Down
20 changes: 7 additions & 13 deletions redaxo/src/core/lib/form/form_base.php
Expand Up @@ -559,10 +559,11 @@ protected function createElement($tag, $name, $value, array $attributes = [])

// Eigentlichen Feldnamen nochmals speichern
$fieldName = $name;
$fieldset = rex_string::normalize($this->fieldset);
if (true === $attributes['internal::useArraySyntax']) {
$name = $this->fieldset . '[' . $name . ']';
$name = $fieldset . '[' . $name . ']';
} elseif (false === $attributes['internal::useArraySyntax']) {
$name = $this->fieldset . '_' . $name;
$name = $fieldset . '_' . $name;
}
unset($attributes['internal::useArraySyntax']);

Expand Down Expand Up @@ -933,7 +934,8 @@ protected function getElement($fieldsetName, $elementName)
return null;
}

$normalizedName = rex_string::normalize($fieldsetName . '[' . $elementName . ']', '_', '[]');
$normalizedName = rex_string::normalize($fieldsetName);
$normalizedName .= '['.rex_string::normalize($elementName).']';

for ($i = 0; $i < count($this->elements[$fieldsetName]); ++$i) {
if ($this->elements[$fieldsetName][$i]->getAttribute('name') == $normalizedName) {
Expand Down Expand Up @@ -1017,15 +1019,7 @@ protected function preView($fieldsetName, $fieldName, $fieldValue)
*/
public function fieldsetPostValues($fieldsetName)
{
// Name normalisieren, da der gepostete Name auch zuvor normalisiert wurde.
// Da der Feldname als Ganzes normalisiert wurde, hier Array mit angehängtem '[' simulieren
// um das Trimmen von möglichen "_" am Ende durch die normalize-Methode zu vermeiden.
// Anschließend "[" wieder entfernen.
// https://github.com/redaxo/redaxo/issues/2710
$normalizedFieldsetName = rex_string::normalize($fieldsetName.'[', '_', '[]');
$normalizedFieldsetName = substr($normalizedFieldsetName, 0, -1);

return rex_post($normalizedFieldsetName, 'array');
return rex_post(rex_string::normalize($fieldsetName), 'array');
}

/**
Expand All @@ -1040,7 +1034,7 @@ public function elementPostValue($fieldsetName, $fieldName, $default = null)
$fields = $this->fieldsetPostValues($fieldsetName);

// name attributes are normalized
$normalizedFieldName = rex_string::normalize($fieldName, '_', '[]');
$normalizedFieldName = rex_string::normalize($fieldName);

if (isset($fields[$normalizedFieldName])) {
return $fields[$normalizedFieldName];
Expand Down
2 changes: 2 additions & 0 deletions redaxo/src/core/lib/packages/manager.php
Expand Up @@ -381,6 +381,8 @@ protected function _delete($ignoreState = false)
$this->message = $this->i18n('deleted', $this->package->getName());
}

$this->package->clearCache();

return true;
}

Expand Down
28 changes: 22 additions & 6 deletions redaxo/src/core/lib/packages/package.php
Expand Up @@ -17,6 +17,8 @@ abstract class rex_package implements rex_package_interface
public const FILE_UNINSTALL_SQL = 'uninstall.sql';
public const FILE_UPDATE = 'update.php';

private const PROPERTIES_CACHE_FILE = 'packages.cache';

/**
* Name of the package.
*
Expand Down Expand Up @@ -298,7 +300,7 @@ public function loadProperties()

static $cache = null;
if (null === $cache) {
$cache = rex_file::getCache(rex_path::coreCache('packages.cache'));
$cache = rex_file::getCache(rex_path::coreCache(self::PROPERTIES_CACHE_FILE));
}
$id = $this->getPackageId();

Expand All @@ -320,7 +322,7 @@ public function loadProperties()
unset($cache[$package]);
}
}
rex_file::putCache(rex_path::coreCache('packages.cache'), $cache);
rex_file::putCache(rex_path::coreCache(self::PROPERTIES_CACHE_FILE), $cache);
});
}
} catch (rex_yaml_parse_exception $exception) {
Expand Down Expand Up @@ -359,13 +361,27 @@ public function loadProperties()
public function clearCache()
{
$cacheDir = $this->getCachePath();
if (!is_dir($cacheDir)) {
return;
if (!rex_dir::delete($cacheDir)) {
throw new rex_functional_exception($this->i18n('cache_not_writable', $cacheDir));
}
if (rex_dir::delete($cacheDir)) {

$cache = rex_file::getCache($path = rex_path::coreCache(self::PROPERTIES_CACHE_FILE));
if (!$cache) {
return;
}
throw new rex_functional_exception($this->i18n('cache_not_writable', $cacheDir));

unset($cache[$this->getPackageId()]);

if ($this instanceof rex_addon) {
$start = $this->getPackageId().'/';
foreach ($cache as $packageId => $_) {
if (str_starts_with((string) $packageId, $start)) {
unset($cache[$packageId]);
}
}
}

rex_file::putCache($path, $cache);
}

public function enlist()
Expand Down
6 changes: 5 additions & 1 deletion redaxo/src/core/lib/var/var.php
Expand Up @@ -341,12 +341,16 @@ abstract protected function getOutput();
/**
* Quotes the string for php context.
*
* @param string $string
* @param string|null $string
*
* @return string
*/
protected static function quote($string)
{
if (null === $string) {
return 'null';
}

$string = addcslashes($string, "\\'");
$string = preg_replace('/\v+/', '\' . "$0" . \'', $string);
$string = addcslashes($string, "\r\n");
Expand Down

0 comments on commit a1079f5

Please sign in to comment.