-
☆ A M B ☆
- 491 Posts
Hi, I noticed that when a user duplicate a resource, if he doesn't change the title before saving, Modx assigns the same URI.
This causes the error inside the log report:
[2014-01-30 03:14:25] (ERROR @ /index.php) Resource URI path/2013/10/28/alias/ already exists for resource id = 104; skipping duplicate resource URI for resource id = 110
The problem is that with sites with high traffic this cause the error.log grows very fast, as long as the error is repeated several times!
How can I prevent this behaviour? Maybe a plugin that control before saving?
thanks
Hi tillilab,
yes, I think a plugin, which runs on the event OnResourceDuplicate could check for duplicate URIs
There are the allow_duplicate_alias and global_duplicate_uri_check System Settings. I'm not sure how they work when you duplicate a Resource, though.
BTW, SiteCheck is handy to have when the duplicates occur because it will show you the sets of duplicates with links to edit either one.
http://bobsguides.com/sitecheck-tutorial.html
FYI, if it's only attached to the one event, you don't need the test, just this:
$alias = $newResource->get('id').'-'.$newResource->get('alias');
$newResource->set('alias', $alias);
$newResource->save();
This might make it more reliable (or not):
$docId = $newResource->get('id');
$modx->reloadContext('web'); // or whatever context it's in
$obj = $modx->getObject($docId);
$alias = $docId . '-' . $newResource->get('alias');
$obj->set('alias', $alias);
$obj->save();