I have a use case where the history of the merge actions is needed, but the auto-reuse of rules saved in history causes problems.
To better understand my motivation, I'll provide below an example:
I have a 2 level taxonomy vocabulary, with a preset list of terms by site admins, but users can suggest new terms.
1. At start we have a term called "ExistingTerm" on the first level of the vocabulary with TID 1234.
2. Then some user suggests "UserSuggestedTerm" as a another first level term.
3. Admins moderate the vocabulary and decide to merge "UserSuggestedTerm" into "ExistingTerm".
4. The module will record in the history this merge for string "UserSuggestedTerm" into term ID 1234.
5. some other user suggests the same "UserSuggestedTerm" later on for level 1, but on hook_term_presave, the term gets altered by the module with a name and TID 1234, thus no new term gets created (but 1234 will be updated)
all good so far
6. some other user, later down the line, suggest "UserSuggestedTerm" again, but this time as a child term for "ExistingTerm", so on the second level.
things go crazy at this stage
before the new term would get saved it overwrites it's name with "ExistingTerm" and sets the TID of 1234 for it
but we already have a parent TID 1234 set on the term, since the user suggested it as a second level term under "ExistingTerm"
and then instead of a term insert a term update is interpreted by the core taxonomy module
this way, term "ExistingTerm" ends up being and it's own parent and disappears form the UI completely
It would be really nice, if these two features could be controlled separately as permissions maybe.
One could define the roles who can access the history of merge actions, but also separately define who's actions can be overwritten automatically and who's don't.
/**
* Implements hook_permission().
*/
function term_merge_manager_permission() {
return array(
'manage term merge actions' => array(
'title' => t('Manage Term Merge Actions'),
'description' => t('Access Term Merge Actions GUI.'),
),
'execute term merge actions' => array(
'title' => t('Execute Term Merge Actions'),
'description' => t('Execute Term Merge Actions from history.'),
),
);
}
/**
* Implements hook_taxonomy_term_presave().
*/
function term_merge_manager_taxonomy_term_presave($term) {
if (user_access('execute term merge actions')) {
// Check if name has a rule.
$merge = term_merge_manager_get_merge_action_item($term->vid, $term->name);
if (!empty($merge)) {
// Get action.
$action = term_merge_manager_get_merge_action_by_tmmid($merge['tmmid']);
if (!empty($action)) {
// Apply term merge rule.
$actionterm = taxonomy_term_load($action['tid']);
if (!empty($actionterm)) {
$term->name = $actionterm->name;
$term->tid = $actionterm->tid;
}
}
}
}
}
Comments
Comment #3
mfrosch commentedI've added your suggestion as also a little permission update.
By default the execute permissions are granted to everyone.
That's because as far as I know the most usecase for this module is for usage with hook_cron.
Comment #4
mfrosch commented