From 49c1ea06126559d7c68b24e6e121a2f56cda1bb4 Mon Sep 17 00:00:00 2001
From: Emil Stjerneman <emil@stjerneman.com>
Date: Sun, 13 Mar 2011 04:27:47 +0100
Subject: [PATCH] #1050444 by anon: Change permission names.

---
 linkit.install                                     |   28 ++++++++++++++++++++
 linkit.module                                      |    2 +-
 .../linkit_permissions/linkit_permissions.module   |    9 +++---
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/linkit.install b/linkit.install
index 5656a8d..42eee5e 100644
--- a/linkit.install
+++ b/linkit.install
@@ -11,4 +11,32 @@
 function linkit_uninstall() {
   variable_del('linkit_node');
   variable_del('linkit_term');
+}
+
+/**
+ * Update Linkit permission names.
+ */
+function linkit_update_7100() {
+  // See http://drupal.org/node/1050444
+  $plugins = array('file', 'node', 'taxonomy', 'user');
+  
+  foreach($plugins AS $plugin) {
+    db_update('role_permission')
+      ->fields(array('permission' => 'use linkit ' . $plugin . ' plugin'))
+      ->condition('permission', 'create ' . $plugin . ' links')
+      ->condition('module', 'linkit_permissions')
+      ->execute();
+  }
+  
+   db_update('role_permission')
+      ->fields(array('permission' => 'use all linkit plugins'))
+      ->condition('permission', 'create all links')
+      ->condition('module', 'linkit_permissions')
+      ->execute();
+  
+  return t('Linkit permission was successfully updated.');
+
+  // In case of an error, simply throw an exception with an error message.
+  throw new DrupalUpdateException('Something went wrong; Please go to admin/people/permissions and update your Linkit permossions manually.');
+
 }
\ No newline at end of file
diff --git a/linkit.module b/linkit.module
index f53686f..73f8b88 100644
--- a/linkit.module
+++ b/linkit.module
@@ -169,7 +169,7 @@ function linkit_autocomplete($string = NULL) {
     $hook_matches = module_invoke_all('linkit_load_plugins', $string);
     foreach ($hook_matches AS $module => $values) {
       if (module_exists('linkit_permissions')) {
-        if (user_access('create ' . $module . ' links') || user_access('create all links')) {
+        if (user_access('use linkit ' . $module . ' plugin') || user_access('use all linkit plugins')) {
           $matches = array_merge($matches, $hook_matches[$module]);
         }
       } 
diff --git a/plugins/linkit_permissions/linkit_permissions.module b/plugins/linkit_permissions/linkit_permissions.module
index 8863d9a..949ad98 100644
--- a/plugins/linkit_permissions/linkit_permissions.module
+++ b/plugins/linkit_permissions/linkit_permissions.module
@@ -10,14 +10,13 @@
  */
 function linkit_permissions_permission() {
   $perms = array(
-    'create all links' => array(
-      'title' => t('Create all links'), 
-      'description' => t('Can use all Linkt plugins'),
+    'use all linkit plugins' => array(
+      'title' => t('Use all Linkit plguins'), 
     ),
   );
   foreach (module_invoke_all('linkit_info_plugins') as $plugin) {
-    $perms['create ' . check_plain($plugin['type']) . ' links'] = array(
-      'title' => t('Create %type links', array('%type' => $plugin['type'])), 
+    $perms['use linkit ' . check_plain($plugin['type']) . ' plugin'] = array(
+      'title' => t('Use Linkit %type plugin', array('%type' => $plugin['type'])), 
       );
     };
   return $perms;
-- 
1.7.4.msysgit.0

