Merge pull request #6991 from fabrixxm/fix/invalid-storage-on-legacy

Allow set empty string storage class for legacy
This commit is contained in:
Hypolite Petovan 2019-04-11 09:04:48 -04:00 committed by GitHub
commit 75387ea171
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 31 deletions

View file

@ -1152,16 +1152,14 @@ function admin_page_site_post(App $a)
* @var $storagebackend \Friendica\Model\Storage\IStorage
*/
$storagebackend = Strings::escapeTags(trim(defaults($_POST, 'storagebackend', '')));
if (!StorageManager::setBackend($storagebackend)) {
info(L10n::t('Invalid storage backend setting value.'));
}
// save storage backend form
if (!is_null($storagebackend) && $storagebackend != "") {
if (StorageManager::setBackend($storagebackend)) {
$storage_opts = $storagebackend::getOptions();
$storage_form_prefix=preg_replace('|[^a-zA-Z0-9]|' ,'', $storagebackend);
$storage_form_prefix = preg_replace('|[^a-zA-Z0-9]|', '', $storagebackend);
$storage_opts_data = [];
foreach($storage_opts as $name => $info) {
foreach ($storage_opts as $name => $info) {
$fieldname = $storage_form_prefix . '_' . $name;
switch ($info[0]) { // type
case 'checkbox':
@ -1178,11 +1176,14 @@ function admin_page_site_post(App $a)
$storage_form_errors = $storagebackend::saveOptions($storage_opts_data);
if (count($storage_form_errors)) {
foreach($storage_form_errors as $name => $err) {
foreach ($storage_form_errors as $name => $err) {
notice('Storage backend, ' . $storage_opts[$name][1] . ': ' . $err);
}
$a->internalRedirect('admin/site' . $active_panel);
}
} else {
info(L10n::t('Invalid storage backend setting value.'));
}
}
@ -1497,10 +1498,15 @@ function admin_page_site(App $a)
*/
$storage_current_backend = StorageManager::getBackend();
$storage_backends_choices = [
'' => L10n::t('Database (legacy)')
];
foreach($storage_backends as $name=>$class) {
$storage_backends_choices = [];
// show legacy option only if it is the current backend:
// once changed can't be selected anymore
if ($storage_current_backend == '') {
$storage_backends_choices[''] = L10n::t('Database (legacy)');
};
foreach ($storage_backends as $name => $class) {
$storage_backends_choices[$class] = $name;
}
unset($storage_backends);

View file

@ -30,6 +30,7 @@ class StorageManager
/**
* @brief Return current storage backend class
*
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/