Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Error in Redirect Module #22

Open
SicorDev opened this issue Jan 8, 2018 · 3 comments
Open

SQL Error in Redirect Module #22

SicorDev opened this issue Jan 8, 2018 · 3 comments
Assignees
Labels

Comments

@SicorDev
Copy link
Contributor

SicorDev commented Jan 8, 2018

My Environment:
TYPO3 7
PHP 5.6
Nawork: master/3.1.x/3.0.x version

How to reproduce:

  1. Create a new redirect of type "redirect to page" (Insert nothing in the mask)
  2. Close and exit
  3. Create a new redirect of type "redirect to page"
  4. The following error occurs:

2: SQL error: 'Duplicate entry 'd41d8cd98f00b204e9800998ecf8427e' for key 'domain_path'' (tx_naworkuri_uri:NEW5a531fea8a2ff423555363)

It creates an empty redirect, which is not visible in the backend. The normal user has no way of editing or deleting this empty redirect.
I was only able to manually remove the record from the database to resolve this error.

It would make sense to mark the required fields in the backend mask and only save the record if these fields are filled correctly.

@thommyhh thommyhh self-assigned this Feb 13, 2018
@thommyhh thommyhh added the bug label Feb 14, 2018
@thommyhh
Copy link
Collaborator

@SicorDev This one is unfortunately not that easy. The problem is that TYPO3 saves the record on type change. In that cases all validations in the form are skipped, probably because the fields might change with the type change.

I tried to improve the behaviour by removing the empty default option in the domain select, so the redirect would in any case show in in the list and would not disappear. Unfortunately this could also lead to that duplicate key sql error because the url to the homepage has an empty path.

I also made the path required, so this might help the user to understand, that this field must be filled. But as I said, I currently can't find a way to avoid TYPO3 from saving the record in type change.

I update all 3.x branches. Please try the change and let me know what you think.

@SicorDev
Copy link
Contributor Author

@thommyhh
I've tried the current master branch, but I couldn't find any difference in the behaviour.

I've got another idea, how to prevent the error in all cases:
You could add a "afterSaveHook", that sets a default path value, if no value is set.
(Untested example)

ext_tables.php

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:' . $_EXTKEY . '/Classes/Hooks/Hook.php:Hook';

Hook.php

function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, &$pObj) {
  if ($table == 'tx_naworkuri_uri' && $status === 'new') {
    if(!$fieldArray['path']) {
       $fieldArray['path'] = 'default-value' . time();
    }
  }
}

@thommyhh
Copy link
Collaborator

@SicorDev The problem is, that the SQL errors occurs when saving, meaning a default value must be set before. On the other hand, it could theoretically be possible to have an empty path. If I remember correctly, the url for the homepage has an empty path, which doesn't really makes sense.

Maybe the fix is, to not allow empty paths at all, and handle an empty path as the homepage. Adding the default value, if the record was saved by the type change with an empty path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants