Project

General

Profile

« Previous | Next » 

Revision 917333b5

Added by Andreas Kohlbecker over 8 years ago

harmonizing role names on update and avoiding errors due to missing roles

View differences:

7.x/modules/cdm_dataportal/cdm_dataportal.install
142 142
      $tasks_performed[] = 'migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image[\'show\']';
143 143
    }
144 144

  
145
    $cdm_admin_role = user_role_load_by_name('CDM admin');
146
    $admin_role = user_role_load_by_name("admin");
147
    if(!$admin_role){
148
      $admin_role = user_role_load_by_name("administrator");
149
    }
150
    user_multiple_role_edit(array(1), 'add_role', $admin_role->rid);
151
    $tasks_performed[] = 'admin user (uid=1) added to role ' . $admin_role->name;
152 145

  
153 146
    // CDM web service debug block
154 147
    $cdm_ws_debug_block = array(
......
164 157
        ),
165 158
        'block_role' =>
166 159
            array(
167
                array(
168
                  'module' => 'cdm_api',
169
                  'delta' => 'cdm_ws_debug',
170
                  'rid' => $cdm_admin_role->rid
171
               ),
172
                array(
173
                  'module' => 'cdm_api',
174
                  'delta' => 'cdm_ws_debug',
175
                  'rid' => $admin_role->rid
176
               )
160

  
177 161
        )
178 162
    );
163

  
164
    $admin_user = user_load(1);
165

  
166
    // harmonize cdm admin role names if needed
167
    $cdm_admin_role = user_role_load_by_name('CDM Admin');
168
    if(is_object($cdm_admin_role) && $cdm_admin_role->name !== 'CDM admin'){
169
      $cdm_admin_role->name = 'CDM admin';
170
      user_role_save($cdm_admin_role);
171
      $tasks_performed[] = $cdm_admin_role->name . ' role name harmonized';
172
    }
173
    $cdm_admin_role = user_role_load_by_name('CDM admin');
174

  
175
    if(is_object($cdm_admin_role)) {
176
      // make sure admin is member of role CDM admin
177
      if (!isset($admin_user->roles[$admin_role->rid])) {
178
        user_multiple_role_edit(array(1), 'add_role', $cdm_admin_role->rid);
179
        $tasks_performed[] = 'admin user (uid=1) added to role ' . $cdm_admin_role->name;
180
      }
181
      $cdm_ws_debug_block['block_role'][] =  array(
182
        'module' => 'cdm_api',
183
        'delta' => 'cdm_ws_debug',
184
        'rid' => $cdm_admin_role->rid
185
      );
186
    }
187

  
188
    $admin_role = user_role_load_by_name("admin"); // Drupal 5
189

  
190
    if(is_object($admin_role)){
191
      $admin_role->name == 'administrator';
192
      user_role_save($admin_role);
193
      $tasks_performed[] = 'administrator role name harmonized';
194
    } else {
195
      $admin_role = user_role_load_by_name("administrator"); // Drupal 7
196
    }
197
    if(is_object($admin_role)){
198
      // make sure admin is member of role admin
199
      if (!isset($admin_user->roles[$admin_role->rid])) {
200
        user_multiple_role_edit(array(1), 'add_role', $admin_role->rid);
201
        $tasks_performed[] = 'admin user (uid=1) added to role ' . $admin_role->name;
202
      }
203
      $cdm_ws_debug_block['block_role'][] =  array(
204
          'module' => 'cdm_api',
205
          'delta' => 'cdm_ws_debug',
206
          'rid' => $admin_role->rid
207
      );
208
    }
209

  
179 210
    // clean up existing block configuration which might be set by drupal automatically, we need to override this
180 211
    db_delete('block')->condition('module', 'cdm_api')->execute();
181 212
    db_delete('block_role')->condition('module', 'cdm_api')->execute();

Also available in: Unified diff