Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 23, 2023
1 parent b1b7275 commit 28275e4
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 191 deletions.
5 changes: 3 additions & 2 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
try {
// transaction test.
$testSQL = rex_sql::factory();
$testSQL->beginTransaction();
$testSQL->commit();
$testSQL->transactional(static function (rex_sql $testSQL) {
$testSQL->setQuery('SELECT 1');
});
} catch (Exception $e) {
throw new rex_sql_exception('db does not support transactions', $e);
}
Expand Down
114 changes: 53 additions & 61 deletions plugins/manager/lib/yform/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public function getDataPage()
case 'clone':
case 'collection_edit':
if (
('add' == $func && $this->hasDataPageFunction('add')) ||
(('edit' == $func || 'clone' == $func) && $data_id) ||
('collection_edit' == $func && $this->table->isMassEditAllowed())
('add' == $func && $this->hasDataPageFunction('add'))
|| (('edit' == $func || 'clone' == $func) && $data_id)
|| ('collection_edit' == $func && $this->table->isMassEditAllowed())
) {
if ('collection_edit' === $func) {
$query = $this->table->query()->alias('t0');
Expand Down Expand Up @@ -364,59 +364,59 @@ public function getDataPage()
}
}

$sql_db = rex_sql::factory();
$sql_db->beginTransaction();

$transactionErrorMessage = null;

try {
$afterFieldsExecuted = static function (rex_yform $yform) {
/** @var rex_yform_value_abstract $valueObject */
foreach ($yform->objparams['values'] as $valueObject) {
if ('submit' == $valueObject->getName()) {
if (2 == $valueObject->getValue()) { // apply
$yform->setObjectparams('form_showformafterupdate', 1);
// $yform->executeFields();
$sql_db = rex_sql::factory();
$form = '';
$sql_db->transactional(static function () use (&$form, &$yform, $data, $func) {

$afterFieldsExecuted = static function (rex_yform $yform) {
/** @var rex_yform_value_abstract $valueObject */
foreach ($yform->objparams['values'] as $valueObject) {
if ('submit' == $valueObject->getName()) {
if (2 == $valueObject->getValue()) { // apply
$yform->setObjectparams('form_showformafterupdate', 1);
// $yform->executeFields();
}
}
}
}
};

if ('clone' == $func) {
$afterFieldsExecuted = static function (rex_yform $yform) use ($afterFieldsExecuted) {
$yform->objparams['form_hiddenfields']['func'] = 'add';
unset($yform->objparams['form_hiddenfields']['data_id']);

// In den Feldern Anpassungen vornehmen
foreach ($yform->objparams['values'] as $k => $v) {
// Submit-Buttons von "Edit" auf "Add" zurückstellen
if ($v instanceof rex_yform_value_submit) {
$yform->objparams['form_output'][$k] = str_replace(
[rex_i18n::msg('yform_save') . '</button', rex_i18n::msg('yform_save_apply') . '</button'],
[rex_i18n::msg('yform_add') . '</button', rex_i18n::msg('yform_add_apply') . '</button'],
$yform->objparams['form_output'][$k],
);
continue;
};

if ('clone' == $func) {
$afterFieldsExecuted = static function (rex_yform $yform) use ($afterFieldsExecuted) {
$yform->objparams['form_hiddenfields']['func'] = 'add';
unset($yform->objparams['form_hiddenfields']['data_id']);

// In den Feldern Anpassungen vornehmen
foreach ($yform->objparams['values'] as $k => $v) {
// Submit-Buttons von "Edit" auf "Add" zurückstellen
if ($v instanceof rex_yform_value_submit) {
$yform->objparams['form_output'][$k] = str_replace(
[rex_i18n::msg('yform_save') . '</button', rex_i18n::msg('yform_save_apply') . '</button'],
[rex_i18n::msg('yform_add') . '</button', rex_i18n::msg('yform_add_apply') . '</button'],
$yform->objparams['form_output'][$k],
);
continue;
}

// im Feldtyp be_manager_relation / Typ 5 (inline) ebenfalls die Datensatz-ID der
// verbundenen Sätze entfernen. Nur "inline" ist problematisch
if ($v instanceof rex_yform_value_be_manager_relation && 5 == $v->getElement('type')) {
$fieldName = preg_quote($v->getFieldName());
$pattern = '/<input type="hidden" name="' . $fieldName . '(\[\d+\])*\[id\]" value="\d+" \/>/';
$yform->objparams['form_output'][$k] = preg_replace($pattern, '', $yform->objparams['form_output'][$k]);
}
}

// im Feldtyp be_manager_relation / Typ 5 (inline) ebenfalls die Datensatz-ID der
// verbundenen Sätze entfernen. Nur "inline" ist problematisch
if ($v instanceof rex_yform_value_be_manager_relation && 5 == $v->getElement('type')) {
$fieldName = preg_quote($v->getFieldName());
$pattern = '/<input type="hidden" name="' . $fieldName . '(\[\d+\])*\[id\]" value="\d+" \/>/';
$yform->objparams['form_output'][$k] = preg_replace($pattern, '', $yform->objparams['form_output'][$k]);
if (is_callable($afterFieldsExecuted)) {
$afterFieldsExecuted($yform);
}
}
};
}

if (is_callable($afterFieldsExecuted)) {
$afterFieldsExecuted($yform);
}
};
}
$form = $data->executeForm($yform, $afterFieldsExecuted);

$form = $data->executeForm($yform, $afterFieldsExecuted);
});

$sql_db->commit();
if ($yform->objparams['actions_executed']) {
switch ($func) {
case 'add':
Expand Down Expand Up @@ -502,22 +502,14 @@ public function getDataPage()
];
}
}
} catch (\Throwable $e) {
if ($sql_db->inTransaction()) {
$sql_db->rollBack();
}

$transactionErrorMessage = $e->getMessage();
if ($transactionErrorMessage) {
if (rex::getUser()->isAdmin()) {
// dump($e);
}
$mainMessages[] = [
'type' => 'error',
'message' => rex_i18n::msg('yform_editdata_collection_error_abort', $transactionErrorMessage),
];
}
} catch (\Throwable $e) {
$mainMessages[] = [
'type' => 'error',
'message' => rex_i18n::msg('yform_editdata_collection_error_abort', $e->getMessage()),
];
}

}
break;
}
Expand Down
5 changes: 4 additions & 1 deletion plugins/manager/lib/yform/manager/dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,10 @@ private static function tableToModel(string $table): string
return self::getModelClass($table) ?: __CLASS__;
}

private static function modelToTable(): string
/**
* @internal
*/
final protected static function modelToTable(): string
{
$class = static::class;

Expand Down
Loading

0 comments on commit 28275e4

Please sign in to comment.